Permalink
Browse files

Merge pull request #997 from AndreyChernyh/legacy_find_one_fix

Legacy find one fix
  • Loading branch information...
2 parents acc4e63 + b067856 commit 7b3cfd92c5aba0b985ed1b9c1018a9b9982d3823 @TomK32 TomK32 committed Jun 21, 2011
Showing with 10 additions and 1 deletion.
  1. +5 −1 lib/mongoid/criterion/optional.rb
  2. +5 −0 spec/integration/mongoid/finders_spec.rb
@@ -70,7 +70,11 @@ def extras(extras)
#
# Returns: <tt>self</tt>
def id(*args)
- (args.flatten.size > 1) ? self.in(:_id => args.flatten) : (@selector[:_id] = args.first)
+ if args.flatten.size > 1 or args.first.is_a?(Array)
+ self.in(:_id => args.flatten)
+ else
+ @selector[:_id] = args.first
+ end
self
end
@@ -99,6 +99,11 @@
context "when the documents are found" do
+ it "returns an array of the documents even if the array of one id is given" do
+ @people = Person.find([@documents.map(&:id).first])
+ @people.should == [@documents.first]
+ end
+
it "returns an array of the documents" do
@people = Person.find(@documents.map(&:id))
@people.should == @documents

0 comments on commit 7b3cfd9

Please sign in to comment.