Permalink
Browse files

Fixes issue with find! not throwing doc missing error if ids in array…

…. Fixes #468
  • Loading branch information...
1 parent d1eb6bc commit dc8a97683c5154f4086a52b15b24d8a7f5e52936 @jmchambers committed Oct 19, 2012
Showing with 10 additions and 4 deletions.
  1. +4 −4 lib/mongo_mapper/plugins/querying/decorator.rb
  2. +6 −0 test/functional/test_querying.rb
@@ -14,11 +14,11 @@ def model(model=nil)
end
def find!(*ids)
- raise DocumentNotFound, "Couldn't find without an ID" if ids.size == 0
-
+ norm_ids = ids.flatten.compact.uniq
+ raise DocumentNotFound, "Couldn't find without an ID" if norm_ids.size == 0
find(*ids).tap do |result|
- if result.nil? || ids.size != Array(result).size
- raise DocumentNotFound, "Couldn't find all of the ids (#{ids.join(',')}). Found #{Array(result).size}, but was expecting #{ids.size}"
+ if result.nil? || norm_ids.size != Array(result).size
+ raise DocumentNotFound, "Couldn't find all of the ids (#{norm_ids.join(',')}). Found #{Array(result).size}, but was expecting #{norm_ids.size}"
end
end
end
@@ -216,6 +216,12 @@ def setup
end
end
+ should "raise error if not all found when using find! with an array" do
+ assert_raises(MongoMapper::DocumentNotFound) do
+ @document.find!([@doc1._id, BSON::ObjectId.new.to_s])
+ end
+ end
+
should "return array if array with one element" do
@document.find([@doc1._id]).should == [@doc1]
end

0 comments on commit dc8a976

Please sign in to comment.