File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,12 @@ def try_next
253
253
#
254
254
# @since 2.2.0
255
255
def batch_size
256
- @view . batch_size && @view . batch_size > 0 ? @view . batch_size : limit
256
+ value = @view . batch_size && @view . batch_size > 0 ? @view . batch_size : limit
257
+ if value == 0
258
+ nil
259
+ else
260
+ value
261
+ end
257
262
end
258
263
259
264
# Is the cursor closed?
Original file line number Diff line number Diff line change 698
698
end
699
699
end
700
700
end
701
+
702
+ describe '#batch_size' do
703
+ let ( :subscriber ) { Mrss ::EventSubscriber . new }
704
+
705
+ let ( :subscribed_client ) do
706
+ authorized_client . tap do |client |
707
+ client . subscribe ( Mongo ::Monitoring ::COMMAND , subscriber )
708
+ end
709
+ end
710
+
711
+ let ( :collection ) do
712
+ subscribed_client [ TEST_COLL ]
713
+ end
714
+
715
+ let ( :view ) do
716
+ collection . find ( { } , limit : limit )
717
+ end
718
+
719
+ before do
720
+ collection . drop
721
+ collection . insert_many ( [ ] . fill ( { "bar" : "baz" } , 0 , 102 ) )
722
+ end
723
+
724
+ context 'when limit is 0 and batch_size is not set' do
725
+ let ( :limit ) do
726
+ 0
727
+ end
728
+
729
+ it 'does not set batch_size' do
730
+ view . to_a
731
+ get_more_commands = subscriber . started_events . select { |e | e . command_name == 'getMore' }
732
+ expect ( get_more_commands . length ) . to eq ( 1 )
733
+ expect ( get_more_commands . first . command . keys ) . not_to include ( 'batchSize' )
734
+ end
735
+ end
736
+
737
+ context 'when limit is not zero and batch_size is not set' do
738
+ let ( :limit ) do
739
+ 1000
740
+ end
741
+
742
+ it 'sets batch_size' do
743
+ view . to_a
744
+ get_more_commands = subscriber . started_events . select { |e | e . command_name == 'getMore' }
745
+
746
+ expect ( get_more_commands . length ) . to eq ( 1 )
747
+ expect ( get_more_commands . first . command . keys ) . to include ( 'batchSize' )
748
+ end
749
+ end
750
+ end
701
751
end
You can’t perform that action at this time.
0 commit comments