Skip to content

Commit

Permalink
Added destroyed? to embedded documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Mar 26, 2010
1 parent 734a243 commit ab7ca25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mongo_mapper/embedded_document.rb
Expand Up @@ -38,6 +38,10 @@ def embedded_in(owner_name)
end

module InstanceMethods
def destroyed?
_root_document.destroyed?
end

def save(options={})
if result = _root_document.try(:save, options)
@new = false
Expand Down
17 changes: 17 additions & 0 deletions test/functional/test_embedded_document.rb
Expand Up @@ -81,6 +81,23 @@ def setup
end
end

context "#destroyed?" do
setup do
@doc = @klass.create(:pets => [@pet_klass.new(:name => 'sparky')])
end

should "be false if root document is not destroyed" do
@doc.should_not be_destroyed
@doc.pets.first.should_not be_destroyed
end

should "be true if root document is destroyed" do
@doc.destroy
@doc.should be_destroyed
@doc.pets.first.should be_destroyed
end
end

should "be able to save" do
person = @klass.create

Expand Down

0 comments on commit ab7ca25

Please sign in to comment.