Merge pull request #47 from karlseguin/master

Fix minor bug bug in batch_size when limit isn't set.
This commit is contained in:
Kyle Banker 2011-07-11 06:45:44 -07:00
commit e1463cdce2
2 changed files with 21 additions and 2 deletions

View File

@ -220,12 +220,13 @@ module Mongo
# 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

View File

@ -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