@@ -902,6 +902,66 @@ def test_save_symbol_find_string
902
902
# assert_equal :mike, @@test.find_one("foo" => "mike")["foo"]
903
903
end
904
904
905
+ def test_batch_size
906
+ n_docs = 6
907
+ batch_size = n_docs /2
908
+ n_docs . times do |i |
909
+ @@test . save ( :foo => i )
910
+ end
911
+
912
+ doc_count = 0
913
+ cursor = @@test . find ( { } , :batch_size => batch_size )
914
+ cursor . next
915
+ assert_equal batch_size , cursor . instance_variable_get ( :@returned )
916
+ doc_count += batch_size
917
+ batch_size . times { cursor . next }
918
+ assert_equal doc_count + batch_size , cursor . instance_variable_get ( :@returned )
919
+ doc_count += batch_size
920
+ assert_equal n_docs , doc_count
921
+ end
922
+
923
+ def test_batch_size_with_smaller_limit
924
+ n_docs = 6
925
+ batch_size = n_docs /2
926
+ n_docs . times do |i |
927
+ @@test . insert ( :foo => i )
928
+ end
929
+
930
+ cursor = @@test . find ( { } , :batch_size => batch_size , :limit => 2 )
931
+ cursor . next
932
+ assert_equal 2 , cursor . instance_variable_get ( :@returned )
933
+ end
934
+
935
+ def test_batch_size_with_larger_limit
936
+ n_docs = 6
937
+ batch_size = n_docs /2
938
+ n_docs . times do |i |
939
+ @@test . insert ( :foo => i )
940
+ end
941
+
942
+ doc_count = 0
943
+ cursor = @@test . find ( { } , :batch_size => batch_size , :limit => n_docs + 5 )
944
+ cursor . next
945
+ assert_equal batch_size , cursor . instance_variable_get ( :@returned )
946
+ doc_count += batch_size
947
+ batch_size . times { cursor . next }
948
+ assert_equal doc_count + batch_size , cursor . instance_variable_get ( :@returned )
949
+ doc_count += batch_size
950
+ assert_equal n_docs , doc_count
951
+ end
952
+
953
+ def test_batch_size_with_negative_limit
954
+ n_docs = 6
955
+ batch_size = n_docs /2
956
+ n_docs . times do |i |
957
+ @@test . insert ( :foo => i )
958
+ end
959
+
960
+ cursor = @@test . find ( { } , :batch_size => batch_size , :limit => -7 )
961
+ cursor . next
962
+ assert_equal n_docs , cursor . instance_variable_get ( :@returned )
963
+ end
964
+
905
965
def test_limit_and_skip
906
966
10 . times do |i |
907
967
@@test . save ( :foo => i )
0 commit comments