batch_size is taken into account when limit is 0/not set
This commit is contained in:
parent
fbf7b754ac
commit
7783cebfdf
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue