Skip to content

Commit

Permalink
Added more tests for _type scoped finding and deleting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Oct 22, 2009
1 parent 32c454d commit 5f5e7b0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo_mapper/document.rb
Expand Up @@ -147,7 +147,7 @@ def destroy(*ids)
end

def destroy_all(conditions={})
find(:all, :conditions => conditions).each(&:destroy)
all(conditions).each(&:destroy)
end

def connection(mongo_connection=nil)
Expand Down
51 changes: 51 additions & 0 deletions test/functional/test_document.rb
Expand Up @@ -1010,6 +1010,21 @@ class ::DocGrandSon < ::DocSon; end
DocParent.all(:order => 'name').should == [carrie, john, steph, steve]
end

should "raise error if not found scoped to class" do
john = DocSon.create(:name => 'John')
steph = DocDaughter.create(:name => 'Steph')

lambda {
DocSon.find(steph.id)
}.should raise_error(MongoMapper::DocumentNotFound)
end

should "not raise error for find with parent" do
john = DocSon.create(:name => 'John')

DocParent.find(john.id).should == john
end

should "count scoped to class" do
john = DocSon.create(:name => 'John')
steve = DocSon.create(:name => 'Steve')
Expand All @@ -1036,6 +1051,42 @@ class ::DocGrandSon < ::DocSon; end
DocSon.single_collection_inherited_superclass?.should be_true
DocGrandSon.single_collection_inherited_superclass?.should be_true
end

should "not be able to destroy each other" do
john = DocSon.create(:name => 'John')
steph = DocDaughter.create(:name => 'Steph')

lambda {
DocSon.destroy(steph.id)
}.should raise_error(MongoMapper::DocumentNotFound)
end

should "not be able to delete each other" do
john = DocSon.create(:name => 'John')
steph = DocDaughter.create(:name => 'Steph')

lambda {
DocSon.delete(steph.id)
}.should_not change { DocParent.count }
end

should "be able to destroy using parent" do
john = DocSon.create(:name => 'John')
steph = DocDaughter.create(:name => 'Steph')

lambda {
DocParent.destroy_all
}.should change { DocParent.count }.by(-2)
end

should "be able to delete using parent" do
john = DocSon.create(:name => 'John')
steph = DocDaughter.create(:name => 'Steph')

lambda {
DocParent.delete_all
}.should change { DocParent.count }.by(-2)
end
end

context "timestamping" do
Expand Down

0 comments on commit 5f5e7b0

Please sign in to comment.