Merge pull request #47 from karlseguin/master
Fix minor bug bug in batch_size when limit isn't set.
This commit is contained in:
commit
e1463cdce2
|
@ -220,12 +220,13 @@ module Mongo
|
||||||
# the server will determine the batch size.
|
# the server will determine the batch size.
|
||||||
#
|
#
|
||||||
# @return [Cursor]
|
# @return [Cursor]
|
||||||
def batch_size(size=0)
|
def batch_size(size=nil)
|
||||||
|
return @batch_size unless size
|
||||||
check_modifiable
|
check_modifiable
|
||||||
if size < 0 || size == 1
|
if size < 0 || size == 1
|
||||||
raise ArgumentError, "Invalid value for batch_size #{size}; must be 0 or > 1."
|
raise ArgumentError, "Invalid value for batch_size #{size}; must be 0 or > 1."
|
||||||
else
|
else
|
||||||
@batch_size = size > @limit ? @limit : size
|
@batch_size = @limit != 0 && size > @limit ? @limit : size
|
||||||
end
|
end
|
||||||
|
|
||||||
self
|
self
|
||||||
|
|
|
@ -76,6 +76,24 @@ class CursorTest < Test::Unit::TestCase
|
||||||
should "cache full collection name" do
|
should "cache full collection name" do
|
||||||
assert_equal "testing.items", @cursor.full_collection_name
|
assert_equal "testing.items", @cursor.full_collection_name
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "Query fields" do
|
context "Query fields" do
|
||||||
|
|
Loading…
Reference in New Issue