Permalink
Browse files

Merge branch 'master' of github.com:jnunemaker/mongomapper

  • Loading branch information...
2 parents 175a4be + 2edd0ef commit b4aefa9281923cc78c3aaf610b3ffc6221f6ed0f @jnunemaker jnunemaker committed Jan 23, 2010
Showing with 19 additions and 0 deletions.
  1. +7 −0 lib/mongo_mapper/document.rb
  2. +12 −0 test/functional/test_document.rb
@@ -90,6 +90,13 @@ def count(options={})
collection.find(to_criteria(options)).count
end
+ def find_each(options={})
+ criteria, options = to_finder_options(options)
+ collection.find(criteria, options).each do |doc|
+ yield load(doc)
+ end
+ end
+
def exists?(options={})
!count(options).zero?
end
@@ -338,6 +338,18 @@ def setup
end
end
+ context "#find_each" do
+ should "yield all documents found, based on criteria" do
+ yield_documents = []
+ @document.find_each(:order => "first_name") {|doc| yield_documents << doc }
+ yield_documents.should == [@doc1, @doc3, @doc2]
+
+ yield_documents = []
+ @document.find_each(:last_name => 'Nunemaker', :order => 'age desc') {|doc| yield_documents << doc }
+ yield_documents.should == [@doc1, @doc3]
+ end
+ end
+
context "dynamic finders" do
should "find document based on all arguments" do
@document.find_by_first_name_and_last_name_and_age('John', 'Nunemaker', 27).should == @doc1

0 comments on commit b4aefa9

Please sign in to comment.