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