Merge pull request #93 from crx/persisted_behavior

#persisted? should be false after a document has been destroyed
master
Sam Lown 2011-06-17 17:14:57 -07:00
commit dca47ac3b2
3 changed files with 12 additions and 4 deletions

View File

@ -82,7 +82,7 @@ module CouchRest
end
def persisted?
!new?
!new? && !destroyed?
end
def to_key

View File

@ -44,7 +44,7 @@ module CouchRest::Model
alias :new_record? :new?
def persisted?
!new?
!new? && !destroyed?
end
# The to_param method is needed for rails to generate resourceful routes.

View File

@ -110,14 +110,22 @@ describe "Model Base" do
describe "#persisted?" do
context "when the document is new" do
it "returns false" do
@obj.persisted?.should == false
@obj.persisted?.should be_false
end
end
context "when the document is not new" do
it "returns id" do
@obj.save
@obj.persisted?.should == true
@obj.persisted?.should be_true
end
end
context "when the document is destroyed" do
it "returns false" do
@obj.save
@obj.destroy
@obj.persisted?.should be_false
end
end
end