Merge branch 'master' of github.com:couchrest/couchrest_model into adv_design
This commit is contained in:
commit
f58482553c
29
Gemfile.lock
29
Gemfile.lock
|
@ -12,21 +12,21 @@ GEM
|
|||
remote: http://rubygems.org/
|
||||
specs:
|
||||
abstract (1.0.0)
|
||||
actionpack (3.0.3)
|
||||
activemodel (= 3.0.3)
|
||||
activesupport (= 3.0.3)
|
||||
actionpack (3.0.4)
|
||||
activemodel (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
builder (~> 2.1.2)
|
||||
erubis (~> 2.6.6)
|
||||
i18n (~> 0.4)
|
||||
rack (~> 1.2.1)
|
||||
rack-mount (~> 0.6.13)
|
||||
rack-test (~> 0.5.6)
|
||||
rack-test (~> 0.5.7)
|
||||
tzinfo (~> 0.3.23)
|
||||
activemodel (3.0.3)
|
||||
activesupport (= 3.0.3)
|
||||
activemodel (3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
builder (~> 2.1.2)
|
||||
i18n (~> 0.4)
|
||||
activesupport (3.0.3)
|
||||
activesupport (3.0.4)
|
||||
builder (2.1.2)
|
||||
couchrest (1.0.1)
|
||||
json (>= 1.4.6)
|
||||
|
@ -36,16 +36,16 @@ GEM
|
|||
erubis (2.6.6)
|
||||
abstract (>= 1.0.0)
|
||||
i18n (0.5.0)
|
||||
json (1.4.6)
|
||||
json (1.5.1)
|
||||
mime-types (1.16)
|
||||
rack (1.2.1)
|
||||
rack-mount (0.6.13)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (0.5.7)
|
||||
rack (>= 1.0)
|
||||
railties (3.0.3)
|
||||
actionpack (= 3.0.3)
|
||||
activesupport (= 3.0.3)
|
||||
railties (3.0.4)
|
||||
actionpack (= 3.0.4)
|
||||
activesupport (= 3.0.4)
|
||||
rake (>= 0.8.7)
|
||||
thor (~> 0.14.4)
|
||||
rake (0.8.7)
|
||||
|
@ -60,17 +60,12 @@ GEM
|
|||
diff-lcs (~> 1.1.2)
|
||||
rspec-mocks (2.3.0)
|
||||
thor (0.14.6)
|
||||
tzinfo (0.3.23)
|
||||
tzinfo (0.3.24)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel (~> 3.0.0)
|
||||
couchrest (~> 1.0.1)
|
||||
couchrest_model!
|
||||
mime-types (~> 1.15)
|
||||
rack-test (>= 0.5.7)
|
||||
railties (~> 3.0.0)
|
||||
rspec (>= 2.0.0)
|
||||
tzinfo (~> 0.3.22)
|
||||
|
|
|
@ -221,7 +221,7 @@ you'd like to use. For example:
|
|||
property :toys, [CatToy]
|
||||
end
|
||||
|
||||
@cat = Cat.new(:name => 'Felix', :toys => [{:name => 'mouse', :purchases => 1.month.ago}])
|
||||
@cat = Cat.new(:name => 'Felix', :toys => [{:name => 'mouse', :purchased => 1.month.ago}])
|
||||
@cat.toys.first.class == CatToy
|
||||
@cat.toys.first.name == 'mouse'
|
||||
|
||||
|
@ -387,7 +387,7 @@ Two types at the moment:
|
|||
|
||||
collection_of :tags
|
||||
|
||||
This is a somewhat controvesial feature of CouchRest Model that some document database purists may fringe at. CouchDB does not yet povide many features to support relationships between documents but the fact of that matter is that its a very useful paradigm for modelling data systems.
|
||||
This is a somewhat controvesial feature of CouchRest Model that some document database purists may cringe at. CouchDB does not yet povide many features to support relationships between documents but the fact of that matter is that its a very useful paradigm for modelling data systems.
|
||||
|
||||
In the near future we hope to add support for a `has_many` relationship that takes of the _Linked Documents_ feature that arrived in CouchDB 0.11.
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
* Minor enhancements:
|
||||
* A yield parameter in an anonymous casted model property block is no longer required (@samlown)
|
||||
* Narrow the rescued exception to avoid catching class evaluation errors that has nothing to to with the association (thanks Simone Carletti)
|
||||
* Fix validate uniqueness test that was never executed (thanks Simone Carletti)
|
||||
* Adds a #reload method to reload document attributes (thanks Simone Carletti)
|
||||
|
||||
== CouchRest Model 1.0.0
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ module CouchRest
|
|||
|
||||
begin
|
||||
opts[:class] = opts[:class_name].constantize
|
||||
rescue
|
||||
raise "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
||||
rescue NameError
|
||||
raise NameError, "Unable to convert class name into Constant for #{self.name}##{attrib}"
|
||||
end
|
||||
|
||||
prop = property(opts[:foreign_key], opts)
|
||||
|
|
|
@ -65,7 +65,6 @@ module CouchRest
|
|||
# Update the document's attributes and save. For example:
|
||||
#
|
||||
# doc.update_attributes :name => "Fred"
|
||||
#
|
||||
# Is the equivilent of doing the following:
|
||||
#
|
||||
# doc.attributes = { :name => "Fred" }
|
||||
|
@ -76,7 +75,17 @@ module CouchRest
|
|||
save
|
||||
end
|
||||
|
||||
protected
|
||||
# Reloads the attributes of this object from the database.
|
||||
# It doesn't override custom instance variables.
|
||||
#
|
||||
# Returns self.
|
||||
def reload
|
||||
merge!(self.class.get(id))
|
||||
self
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def perform_validations(options = {})
|
||||
perform_validation = case options
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
en:
|
||||
errors:
|
||||
messages:
|
||||
taken: "is already taken"
|
||||
taken: "has already been taken"
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ module CouchRest
|
|||
end
|
||||
|
||||
if docs.length > 0
|
||||
document.errors.add(attribute, :taken, :default => options[:message], :value => value)
|
||||
document.errors.add(attribute, :taken, options.merge(:value => value))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,11 +44,11 @@ describe "Assocations" do
|
|||
end
|
||||
|
||||
it "should raise error if class name does not exist" do
|
||||
lambda {
|
||||
lambda do
|
||||
class TestBadAssoc < CouchRest::Model::Base
|
||||
belongs_to :test_bad_item
|
||||
end
|
||||
}.should raise_error
|
||||
end.should raise_error(NameError, /TestBadAssoc#test_bad_item/)
|
||||
end
|
||||
|
||||
it "should allow override of foreign key" do
|
||||
|
|
|
@ -412,4 +412,33 @@ describe "Model Persistence" do
|
|||
end
|
||||
|
||||
|
||||
describe "#reload" do
|
||||
it "reloads defined attributes" do
|
||||
i = Article.create!(:title => "Reload when changed")
|
||||
i.title.should == "Reload when changed"
|
||||
|
||||
i.title = "..."
|
||||
i.title.should == "..."
|
||||
|
||||
i.reload
|
||||
i.title.should == "Reload when changed"
|
||||
end
|
||||
|
||||
it "reloads defined attributes set to nil" do
|
||||
i = Article.create!(:title => "Reload when nil")
|
||||
i.title.should == "Reload when nil"
|
||||
|
||||
i.title = nil
|
||||
i.title.should be_nil
|
||||
|
||||
i.reload
|
||||
i.title.should == "Reload when nil"
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
i = Article.create!(:title => "Reload return self")
|
||||
i.reload.should be(i)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ describe "Validations" do
|
|||
it "should not validate a non-unique document" do
|
||||
@obj = WithUniqueValidation.create(:title => 'title 1')
|
||||
@obj.should_not be_valid
|
||||
@obj.errors[:title].should eql(['is already taken'])
|
||||
@obj.errors[:title].should == ["has already been taken"]
|
||||
end
|
||||
|
||||
it "should save already created document" do
|
||||
|
@ -57,7 +57,6 @@ describe "Validations" do
|
|||
@obj.class.should_receive('view').and_return({'rows' => [ ]})
|
||||
@obj.valid?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with a proxy parameter" do
|
||||
|
@ -76,7 +75,6 @@ describe "Validations" do
|
|||
proxy.should_receive('view').and_return({'rows' => [ ]})
|
||||
@obj.valid?
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
Loading…
Reference in a new issue