Ensuring update_attributes cannot be called in CastedModel as per issue #9
This commit is contained in:
parent
c32992c21b
commit
fafbfff474
3 changed files with 19 additions and 7 deletions
|
@ -29,13 +29,6 @@ module CouchRest
|
|||
end
|
||||
alias :attributes= :update_attributes_without_saving
|
||||
|
||||
# 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
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -62,6 +62,20 @@ module CouchRest
|
|||
end
|
||||
end
|
||||
|
||||
# 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" }
|
||||
# doc.save
|
||||
#
|
||||
def update_attributes(hash)
|
||||
update_attributes_without_saving hash
|
||||
save
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def perform_validations(options = {})
|
||||
|
|
|
@ -179,6 +179,11 @@ describe CouchRest::Model::CastedModel do
|
|||
@question.q.should == "What is your quest?"
|
||||
@question.a.should == "To seek the Holy Grail"
|
||||
end
|
||||
|
||||
it "should raise an error if save or update_attributes called" do
|
||||
expect { @question.save }.to raise_error
|
||||
expect { @question.update_attributes(:q => "Fubar?") }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "saved document with casted models" do
|
||||
|
|
Loading…
Reference in a new issue