Skip to content

Commit

Permalink
Reimplement Collection#drop.
Browse files Browse the repository at this point in the history
Fixes #1919. The collection now sets @master to nil if collection is
dropped.
  • Loading branch information
hanshasselberg committed Apr 16, 2012
1 parent 9fe9b69 commit 4a4b2b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mongoid/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,9 @@ def update(selector, document, options = {})
master(options).update(selector, document, options)
end
end

def drop(*args)
@master = nil if master.drop
end
end
end
26 changes: 26 additions & 0 deletions spec/unit/mongoid/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,30 @@
end
end
end

describe "#drop" do

it "delegates drop to master" do
master.expects(:drop).returns(true)
collection.drop
end

context "drop succeeds" do

it "sets @master to nil" do
master.expects(:drop).returns(true)
collection.drop
collection.instance_variable_get(:@master).should be_nil
end
end

context "drop fails" do

it "leaves master unchanged" do
master.expects(:drop).returns(false)
collection.drop
collection.instance_variable_get(:@master).should_not be_nil
end
end
end
end

0 comments on commit 4a4b2b6

Please sign in to comment.