Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed bug with cursors paginated by ids

  • Loading branch information...
commit 487a6bae331c588407d84c01e129d28f76e7001c 1 parent 69a7215
@mislav authored
Showing with 16 additions and 2 deletions.
  1. +1 −1  lib/mingo/cursor.rb
  2. +15 −1 spec/mingo_spec.rb
View
2  lib/mingo/cursor.rb
@@ -70,7 +70,7 @@ def limit_ids
if @limit > 0 || @skip > 0
ids = selector[:_id]["$in"]
old_skip = @skip
- selector[:_id]["$in"] = ids[@skip, @limit > 0 ? @limit : ids.size]
+ selector[:_id]["$in"] = Array(ids[@skip, @limit > 0 ? @limit : ids.size])
@skip = 0
begin
yield
View
16 spec/mingo_spec.rb
@@ -200,11 +200,25 @@ def age=(value)
cursor.to_a.should == [@doc2]
end
+ it "doesn't die when offset is out of bounds" do
+ cursor = described_class.find([@doc3.id, @doc1.id, @doc2.id]).skip(4)
+ cursor.to_a.should be_empty
+ end
+
it "returns correct count" do
cursor = described_class.find([@doc3.id, @doc1.id, @doc2.id]).limit(1).skip(2)
- cursor.next_document
cursor.count.should == 3
end
+
+ it "works with empty ID list" do
+ results = described_class.find([]).to_a
+ results.should be_empty
+ end
+
+ it "works with nonexistent ID" do
+ results = described_class.find([BSON::ObjectId.new]).to_a
+ results.should be_empty
+ end
end
def build(*args)
Please sign in to comment.
Something went wrong with that request. Please try again.