Sha256: 02af955e90ea9961fa5e1d1c14cc32d88f60a9ecad237f2991ab633210e8e0db

Contents?: true

Size: 1.15 KB

Versions: 32

Compression:

Stored size: 1.15 KB

Contents

require "spec_helper"

describe Mongoid::Commands::Destroy do

  describe "#execute" do

    before do
      @collection = stub_everything
      @document = stub(:run_callbacks => true,
                       :collection => @collection,
                       :id => "1",
                       :_parent => false)
    end

    it "runs the before and after destroy callbacks" do
      @document.expects(:run_callbacks).with(:before_destroy)
      @document.expects(:run_callbacks).with(:after_destroy)
      Mongoid::Commands::Destroy.execute(@document)
    end

    it "removes the document from its collection" do
      @collection.expects(:remove).with({ :_id => @document.id })
      Mongoid::Commands::Destroy.execute(@document)
    end

    context "when the document is embedded" do

      before do
        @parent = Person.new
        @address = Address.new(:street => "Genoa Pl")
        @parent.addresses << @address
      end

      it "removes the document from the parent attributes" do
        @parent.addresses.should == [@address]
        Mongoid::Commands::Destroy.execute(@address)
        @parent.addresses.should be_empty
      end

    end

  end

end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
mongoid-1.2.8 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.7 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.6 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.5 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.4 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.3 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.2 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.1 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.2.0 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.1.4 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.1.3 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.1.2 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.1.1 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.1.0 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.6 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.5 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.4 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.3 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.2 spec/unit/mongoid/commands/destroy_spec.rb
mongoid-1.0.1 spec/unit/mongoid/commands/destroy_spec.rb