File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -220,12 +220,13 @@ def skip(number_to_skip=nil)
220
220
# the server will determine the batch size.
221
221
#
222
222
# @return [Cursor]
223
- def batch_size ( size = 0 )
223
+ def batch_size ( size = nil )
224
+ return @batch_size unless size
224
225
check_modifiable
225
226
if size < 0 || size == 1
226
227
raise ArgumentError , "Invalid value for batch_size #{ size } ; must be 0 or > 1."
227
228
else
228
- @batch_size = size > @limit ? @limit : size
229
+ @batch_size = @limit != 0 && size > @limit ? @limit : size
229
230
end
230
231
231
232
self
Original file line number Diff line number Diff line change @@ -76,6 +76,24 @@ class CursorTest < Test::Unit::TestCase
76
76
should "cache full collection name" do
77
77
assert_equal "testing.items" , @cursor . full_collection_name
78
78
end
79
+
80
+ should "raise error when batch_size is 1" do
81
+ e = assert_raise ArgumentError do
82
+ @cursor . batch_size ( 1 )
83
+ end
84
+ assert_equal "Invalid value for batch_size 1; must be 0 or > 1." , e . message
85
+ end
86
+
87
+ should "use the limit for batch size when it's smaller than the specified batch_size" do
88
+ @cursor . limit ( 99 )
89
+ @cursor . batch_size ( 100 )
90
+ assert_equal 99 , @cursor . batch_size
91
+ end
92
+
93
+ should "use the specified batch_size" do
94
+ @cursor . batch_size ( 100 )
95
+ assert_equal 100 , @cursor . batch_size
96
+ end
79
97
end
80
98
81
99
context "Query fields" do
You can’t perform that action at this time.
0 commit comments