diff --git a/lib/couchrest/model/base.rb b/lib/couchrest/model/base.rb index 7b6255a..82b6561 100644 --- a/lib/couchrest/model/base.rb +++ b/lib/couchrest/model/base.rb @@ -82,7 +82,7 @@ module CouchRest end def persisted? - !new? + !new? && !destroyed? end def to_key diff --git a/lib/couchrest/model/casted_model.rb b/lib/couchrest/model/casted_model.rb index 0074e18..614c410 100644 --- a/lib/couchrest/model/casted_model.rb +++ b/lib/couchrest/model/casted_model.rb @@ -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. diff --git a/spec/unit/base_spec.rb b/spec/unit/base_spec.rb index fb17f0a..59ed673 100644 --- a/spec/unit/base_spec.rb +++ b/spec/unit/base_spec.rb @@ -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