Merge commit '9399b27f3f58c1e333b6dd5f20bbcd3531fa4b5e'
This commit is contained in:
commit
64d71d3ac4
2 changed files with 20 additions and 5 deletions
|
@ -440,15 +440,22 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
# Takes a hash as argument, and applies the values by using writer methods
|
# Takes a hash as argument, and applies the values by using writer methods
|
||||||
# for each key. Raises a NoMethodError if the corresponding methods are
|
# for each key. It doesn't save the document at the end. Raises a NoMethodError if the corresponding methods are
|
||||||
# missing. In case of error, no attributes are changed.
|
# missing. In case of error, no attributes are changed.
|
||||||
def update_attributes hash
|
def update_attributes_without_saving hash
|
||||||
hash.each do |k, v|
|
hash.each do |k, v|
|
||||||
raise NoMethodError, "#{k}= method not available, use key_accessor or key_writer :#{k}" unless self.respond_to?("#{k}=")
|
raise NoMethodError, "#{k}= method not available, use key_accessor or key_writer :#{k}" unless self.respond_to?("#{k}=")
|
||||||
end
|
end
|
||||||
hash.each do |k, v|
|
hash.each do |k, v|
|
||||||
self.send("#{k}=",v)
|
self.send("#{k}=",v)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Takes a hash as argument, and applies the values by using writer methods
|
||||||
|
# for each key. Raises a NoMethodError if the corresponding methods are
|
||||||
|
# missing. In case of error, no attributes are changed.
|
||||||
|
def update_attributes hash
|
||||||
|
update_attributes_without_saving hash
|
||||||
save
|
save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ describe CouchRest::Model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "update attributes" do
|
describe "update attributes without saving" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
a = Article.get "big-bad-danger" rescue nil
|
a = Article.get "big-bad-danger" rescue nil
|
||||||
a.destroy if a
|
a.destroy if a
|
||||||
|
@ -161,13 +161,21 @@ describe CouchRest::Model do
|
||||||
@art['title'].should == "big bad danger"
|
@art['title'].should == "big bad danger"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update attributes" do
|
||||||
|
before(:each) do
|
||||||
|
a = Article.get "big-bad-danger" rescue nil
|
||||||
|
a.destroy if a
|
||||||
|
@art = Article.new(:title => "big bad danger")
|
||||||
|
@art.save
|
||||||
|
end
|
||||||
it "should save" do
|
it "should save" do
|
||||||
@art['title'].should == "big bad danger"
|
@art['title'].should == "big bad danger"
|
||||||
@art.update_attributes('date' => Time.now, :title => "super danger")
|
@art.update_attributes('date' => Time.now, :title => "super danger")
|
||||||
loaded = Article.get @art.id
|
loaded = Article.get @art.id
|
||||||
loaded['title'].should == "super danger"
|
loaded['title'].should == "super danger"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "a model with template values" do
|
describe "a model with template values" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue