Merge branch 'master' of git://github.com/tapajos/couchrest_model

Conflicts:
	Rakefile
	couchrest_model.gemspec
	history.txt
	lib/couchrest_model.rb
	spec/couchrest/attribute_protection_spec.rb
bundler
Sam Lown 2010-08-24 11:45:37 +02:00
commit c32992c21b
12 changed files with 84 additions and 10 deletions

View File

@ -31,7 +31,12 @@ but no guarantees!
gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
## Generators
### Model
$ rails generate model person --orm=couchrest_model
## General Usage
require 'couchrest_model'

View File

@ -29,9 +29,9 @@ begin
gemspec.has_rdoc = true
gemspec.add_dependency("couchrest", "~> 1.0.0")
gemspec.add_dependency("mime-types", "~> 1.15")
gemspec.add_dependency("activesupport", "~> 3.0.0.rc")
gemspec.add_dependency("activemodel", "~> 3.0.0.rc")
gemspec.add_dependency("tzinfo", "~> 0.3.22")
gemspec.add_dependency('railties', "~> 3.0.0.rc")
gemspec.add_development_dependency('rspec', '~> 2.0.0.beta.19')
gemspec.version = CouchRest::Model::VERSION
gemspec.date = Time.now.strftime("%Y-%m-%d")

View File

@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{couchrest_model}
s.version = "1.0.0.beta7"
s.version = "1.0.0.beta8"
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"]
s.date = %q{2010-08-23}
s.date = %q{2010-08-24}
s.description = %q{CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.}
s.email = %q{jchris@apache.org}
s.extra_rdoc_files = [
@ -48,7 +48,11 @@ Gem::Specification.new do |s|
"lib/couchrest/model/validations/locale/en.yml",
"lib/couchrest/model/validations/uniqueness.rb",
"lib/couchrest/model/views.rb",
"lib/couchrest/railtie.rb",
"lib/couchrest_model.rb",
"lib/rails/generators/couchrest_model.rb",
"lib/rails/generators/couchrest_model/model/model_generator.rb",
"lib/rails/generators/couchrest_model/model/templates/model.rb",
"spec/couchrest/assocations_spec.rb",
"spec/couchrest/attachment_spec.rb",
"spec/couchrest/attribute_protection_spec.rb",
@ -129,24 +133,24 @@ Gem::Specification.new do |s|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<couchrest>, ["~> 1.0.0"])
s.add_runtime_dependency(%q<mime-types>, ["~> 1.15"])
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0.0.rc"])
s.add_runtime_dependency(%q<tzinfo>, ["~> 0.3.22"])
s.add_runtime_dependency(%q<railties>, ["~> 3.0.0.rc"])
s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
else
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
s.add_dependency(%q<mime-types>, ["~> 1.15"])
s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
s.add_dependency(%q<activemodel>, ["~> 3.0.0.rc"])
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
end
else
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
s.add_dependency(%q<mime-types>, ["~> 1.15"])
s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
s.add_dependency(%q<activemodel>, ["~> 3.0.0.rc"])
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.19"])
end
end

View File

@ -1,6 +1,7 @@
== Next Version
== CouchRest Model 1.0.0.beta8
* Major enhancements
* Added model generator
* Minor enhancements
* Raise error on adding objects to "collection_of" without an id

View File

@ -3,7 +3,7 @@ module CouchRest
module Model
VERSION = "1.0.0.beta7"
VERSION = "1.0.0.beta8"
end

View File

@ -54,7 +54,7 @@ module CouchRest
attributes.reject! do |property_name, property_value|
protected_names.include?(property_name.to_s)
end
end if attributes
attributes || {}
end

12
lib/couchrest/railtie.rb Normal file
View File

@ -0,0 +1,12 @@
require "rails"
require "active_model/railtie"
module CouchrestModel
# = Active Record Railtie
class Railtie < Rails::Railtie
config.generators.orm :couchrest
config.generators.test_framework :test_unit, :fixture => false
end
end

View File

@ -3,7 +3,9 @@ require 'couchrest'
gem "tzinfo", ">= 0.3.22"
gem 'railties', ">= 3.0.0.rc"
gem "activesupport", ">= 3.0.0.rc"
require 'active_support/core_ext'
require 'active_support/json'
@ -57,3 +59,4 @@ require "couchrest/model/base"
# Add rails support *after* everything has loaded
require "couchrest/railtie"

View File

@ -0,0 +1,16 @@
require 'rails/generators/named_base'
require 'rails/generators/active_model'
require 'couchrest_model'
module CouchrestModel
module Generators
class Base < Rails::Generators::NamedBase #:nodoc:
# Set the current directory as base for the inherited generators.
def self.base_root
File.dirname(__FILE__)
end
end
end
end

View File

@ -0,0 +1,27 @@
require 'rails/generators/couchrest_model'
module CouchrestModel
module Generators
class ModelGenerator < Base
check_class_collision
def create_model_file
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
end
def create_module_file
return if class_path.empty?
template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
end
hook_for :test_framework
protected
def parent_class_name
"CouchRest::Model::Base"
end
end
end
end

View File

@ -0,0 +1,2 @@
class <%= class_name %> < <%= parent_class_name.classify %>
end

View File

@ -43,6 +43,8 @@ describe "Model Attributes" do
property :admin, :default => false
end
it { expect { WithAccessible.new(nil) }.to_not raise_error }
it "should recognize accessible properties" do
props = WithAccessible.accessible_properties.map { |prop| prop.name}
props.should include("name")
@ -72,6 +74,8 @@ describe "Model Attributes" do
property :admin, :default => false, :protected => true
end
it { expect { WithProtected.new(nil) }.to_not raise_error }
it "should recognize protected properties" do
props = WithProtected.protected_properties.map { |prop| prop.name}
props.should_not include("name")