Skip to content

Commit

Permalink
Adding destroy_all to document
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Oct 2, 2009
1 parent 5aed6ae commit 501f902
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/mongoid/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def create(attributes = {})
new(attributes).save(true)
end

# Deletes all records from the collection. Will actually call drop on the
# Mongo::Collection for efficiency.
def destroy_all
collection.drop
end

# Defines all the fields that are accessable on the Document
# For each field that is defined, a getter and setter will be
# added as an instance method to the Document.
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/mongoid/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@

end

describe "#destroy_all" do

it "deletes all documents from the collection" do
@collection.expects(:drop)
Person.destroy_all
end

end

describe "#fields" do

before do
Expand Down

0 comments on commit 501f902

Please sign in to comment.