Skip to content

Commit

Permalink
Merge pull request mongodb#47 from karlseguin/master
Browse files Browse the repository at this point in the history
Fix minor bug bug in batch_size when limit isn't set.
  • Loading branch information
banker committed Jul 11, 2011
2 parents 88daaa0 + 7783ceb commit e1463cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/mongo/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ def skip(number_to_skip=nil)
# the server will determine the batch size.
#
# @return [Cursor]
def batch_size(size=0)
def batch_size(size=nil)
return @batch_size unless size
check_modifiable
if size < 0 || size == 1
raise ArgumentError, "Invalid value for batch_size #{size}; must be 0 or > 1."
else
@batch_size = size > @limit ? @limit : size
@batch_size = @limit != 0 && size > @limit ? @limit : size
end

self
Expand Down
18 changes: 18 additions & 0 deletions test/unit/cursor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ class CursorTest < Test::Unit::TestCase
should "cache full collection name" do
assert_equal "testing.items", @cursor.full_collection_name
end

should "raise error when batch_size is 1" do
e = assert_raise ArgumentError do
@cursor.batch_size(1)
end
assert_equal "Invalid value for batch_size 1; must be 0 or > 1.", e.message
end

should "use the limit for batch size when it's smaller than the specified batch_size" do
@cursor.limit(99)
@cursor.batch_size(100)
assert_equal 99, @cursor.batch_size
end

should "use the specified batch_size" do
@cursor.batch_size(100)
assert_equal 100, @cursor.batch_size
end
end

context "Query fields" do
Expand Down

0 comments on commit e1463cd

Please sign in to comment.