mongo 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,6 +133,23 @@ describe Mongo::Collection::View::MapReduce do
133
133
  it 'fetches the results from the collection' do
134
134
  expect(new_map_reduce.count).to eq(2)
135
135
  end
136
+
137
+ context 'when another db is specified', if: (!auth_enabled? && list_command_enabled?) do
138
+
139
+ let(:new_map_reduce) do
140
+ map_reduce.out(db: 'another-db', replace: 'output_collection')
141
+ end
142
+
143
+ it 'iterates over the documents in the result' do
144
+ new_map_reduce.each do |document|
145
+ expect(document[:value]).to_not be_nil
146
+ end
147
+ end
148
+
149
+ it 'fetches the results from the collection' do
150
+ expect(new_map_reduce.count).to eq(2)
151
+ end
152
+ end
136
153
  end
137
154
 
138
155
  context 'when the option is to merge' do
@@ -150,6 +167,23 @@ describe Mongo::Collection::View::MapReduce do
150
167
  it 'fetches the results from the collection' do
151
168
  expect(new_map_reduce.count).to eq(2)
152
169
  end
170
+
171
+ context 'when another db is specified', if: (!auth_enabled? && list_command_enabled?) do
172
+
173
+ let(:new_map_reduce) do
174
+ map_reduce.out(db: 'another-db', merge: 'output_collection')
175
+ end
176
+
177
+ it 'iterates over the documents in the result' do
178
+ new_map_reduce.each do |document|
179
+ expect(document[:value]).to_not be_nil
180
+ end
181
+ end
182
+
183
+ it 'fetches the results from the collection' do
184
+ expect(new_map_reduce.count).to eq(2)
185
+ end
186
+ end
153
187
  end
154
188
 
155
189
  context 'when the option is to reduce' do
@@ -167,6 +201,23 @@ describe Mongo::Collection::View::MapReduce do
167
201
  it 'fetches the results from the collection' do
168
202
  expect(new_map_reduce.count).to eq(2)
169
203
  end
204
+
205
+ context 'when another db is specified', if: (!auth_enabled? && list_command_enabled?) do
206
+
207
+ let(:new_map_reduce) do
208
+ map_reduce.out(db: 'another-db', reduce: 'output_collection')
209
+ end
210
+
211
+ it 'iterates over the documents in the result' do
212
+ new_map_reduce.each do |document|
213
+ expect(document[:value]).to_not be_nil
214
+ end
215
+ end
216
+
217
+ it 'fetches the results from the collection' do
218
+ expect(new_map_reduce.count).to eq(2)
219
+ end
220
+ end
170
221
  end
171
222
 
172
223
  context 'when the option is a collection name' do
@@ -506,33 +557,67 @@ describe Mongo::Collection::View::MapReduce do
506
557
  authorized_collection.insert_many([ { name: 'bang' }, { name: 'bang' }])
507
558
  end
508
559
 
509
- let(:options) do
510
- { collation: { locale: 'en_US', strength: 2 } }
511
- end
512
-
513
560
  let(:selector) do
514
561
  { name: 'BANG' }
515
562
  end
516
563
 
517
564
  context 'when the server selected supports collations', if: collation_enabled? do
518
565
 
519
- it 'applies the collation' do
520
- expect(map_reduce.first['value']).to eq(2)
566
+ context 'when the collation key is a String' do
567
+
568
+ let(:options) do
569
+ { 'collation' => { locale: 'en_US', strength: 2 } }
570
+ end
571
+
572
+ it 'applies the collation' do
573
+ expect(map_reduce.first['value']).to eq(2)
574
+ end
575
+ end
576
+
577
+ context 'when the collation key is a Symbol' do
578
+
579
+ let(:options) do
580
+ { collation: { locale: 'en_US', strength: 2 } }
581
+ end
582
+
583
+ it 'applies the collation' do
584
+ expect(map_reduce.first['value']).to eq(2)
585
+ end
521
586
  end
522
587
  end
523
588
 
524
589
  context 'when the server selected does not support collations', unless: collation_enabled? do
525
590
 
526
- it 'raises an exception' do
527
- expect {
528
- map_reduce.to_a
529
- }.to raise_exception(Mongo::Error::UnsupportedCollation)
591
+ context 'when the map reduce has collation specified in its options' do
592
+
593
+ let(:options) do
594
+ { collation: { locale: 'en_US', strength: 2 } }
595
+ end
596
+
597
+ it 'raises an exception' do
598
+ expect {
599
+ map_reduce.to_a
600
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
601
+ end
602
+
603
+ context 'when a String key is used' do
604
+
605
+ let(:options) do
606
+ { 'collation' => { locale: 'en_US', strength: 2 } }
607
+ end
608
+
609
+ it 'raises an exception' do
610
+ expect {
611
+ map_reduce.to_a
612
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
613
+ end
614
+ end
530
615
  end
531
616
 
532
- context 'when a String key is used' do
617
+ context 'when the view has collation specified in its options' do
533
618
 
534
- let(:options) do
535
- { 'collation' => { locale: 'en_US', strength: 2 } }
619
+ let(:view_options) do
620
+ { collation: { locale: 'en_US', strength: 2 } }
536
621
  end
537
622
 
538
623
  it 'raises an exception' do
@@ -540,6 +625,19 @@ describe Mongo::Collection::View::MapReduce do
540
625
  map_reduce.to_a
541
626
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
542
627
  end
628
+
629
+ context 'when a String key is used' do
630
+
631
+ let(:options) do
632
+ { 'collation' => { locale: 'en_US', strength: 2 } }
633
+ end
634
+
635
+ it 'raises an exception' do
636
+ expect {
637
+ map_reduce.to_a
638
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
639
+ end
640
+ end
543
641
  end
544
642
  end
545
643
  end
@@ -309,6 +309,40 @@ describe Mongo::Collection::View::Readable do
309
309
  expect(view.count(read: { mode: :secondary })).to eq(10)
310
310
  end
311
311
 
312
+ context 'when a read preference is set on the view', unless: sharded? do
313
+
314
+ let(:client) do
315
+ # Set a timeout otherwise, the test will hang for 30 seconds.
316
+ authorized_client.with(server_selection_timeout: 1)
317
+ end
318
+
319
+ let(:collection) do
320
+ client[authorized_collection.name]
321
+ end
322
+
323
+ before do
324
+ allow(client.cluster).to receive(:single?).and_return(false)
325
+ end
326
+
327
+ let(:view) do
328
+ Mongo::Collection::View.new(collection, selector, options)
329
+ end
330
+
331
+ let(:view_with_read_pref) do
332
+ view.read(:mode => :secondary, :tag_sets => [{ 'non' => 'existent' }])
333
+ end
334
+
335
+ let(:result) do
336
+ view_with_read_pref.count
337
+ end
338
+
339
+ it 'uses the read preference setting on the view' do
340
+ expect {
341
+ result
342
+ }.to raise_exception(Mongo::Error::NoServerAvailable)
343
+ end
344
+ end
345
+
312
346
  context 'when the collection has a read preference set' do
313
347
 
314
348
  after do
@@ -344,6 +378,21 @@ describe Mongo::Collection::View::Readable do
344
378
  end
345
379
  end
346
380
 
381
+ context 'when a read preference is set on the view' do
382
+
383
+ let(:view_with_read_pref) do
384
+ view.read(mode: :primary)
385
+ end
386
+
387
+ let(:result) do
388
+ view_with_read_pref.count
389
+ end
390
+
391
+ it 'uses the read preference of the view' do
392
+ expect(result).to eq(10)
393
+ end
394
+ end
395
+
347
396
  context 'when no read preference argument is provided', unless: sharded? do
348
397
 
349
398
  before do
@@ -394,6 +443,21 @@ describe Mongo::Collection::View::Readable do
394
443
  }.to raise_exception(Mongo::Error::NoServerAvailable)
395
444
  end
396
445
  end
446
+
447
+ context 'when a read preference is set on the view' do
448
+
449
+ let(:view_with_read_pref) do
450
+ view.read(:mode => :primary)
451
+ end
452
+
453
+ let(:result) do
454
+ view_with_read_pref.count
455
+ end
456
+
457
+ it 'uses the read preference passed to the method' do
458
+ expect(result).to eq(10)
459
+ end
460
+ end
397
461
  end
398
462
 
399
463
  it 'takes a max_time_ms option', if: write_command_enabled? do
@@ -412,6 +476,54 @@ describe Mongo::Collection::View::Readable do
412
476
  { name: 'BANG' }
413
477
  end
414
478
 
479
+ let(:result) do
480
+ view.count
481
+ end
482
+
483
+ before do
484
+ authorized_collection.insert_one(name: 'bang')
485
+ end
486
+
487
+ let(:options) do
488
+ { collation: { locale: 'en_US', strength: 2 } }
489
+ end
490
+
491
+ context 'when the server selected supports collations', if: collation_enabled? do
492
+
493
+ it 'applies the collation to the count' do
494
+ expect(result).to eq(1)
495
+ end
496
+ end
497
+
498
+ context 'when the server selected does not support collations', unless: collation_enabled? do
499
+
500
+ it 'raises an exception' do
501
+ expect {
502
+ result
503
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
504
+ end
505
+
506
+ context 'when a String key is used' do
507
+
508
+ let(:options) do
509
+ { 'collation' => { locale: 'en_US', strength: 2 } }
510
+ end
511
+
512
+ it 'raises an exception' do
513
+ expect {
514
+ result
515
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
516
+ end
517
+ end
518
+ end
519
+ end
520
+
521
+ context 'when a collation is specified in the method options' do
522
+
523
+ let(:selector) do
524
+ { name: 'BANG' }
525
+ end
526
+
415
527
  let(:result) do
416
528
  view.count(count_options)
417
529
  end
@@ -569,6 +681,40 @@ describe Mongo::Collection::View::Readable do
569
681
  end
570
682
  end
571
683
 
684
+ context 'when a read preference is set on the view', unless: sharded? do
685
+
686
+ let(:client) do
687
+ # Set a timeout otherwise, the test will hang for 30 seconds.
688
+ authorized_client.with(server_selection_timeout: 1)
689
+ end
690
+
691
+ let(:collection) do
692
+ client[authorized_collection.name]
693
+ end
694
+
695
+ before do
696
+ allow(client.cluster).to receive(:single?).and_return(false)
697
+ end
698
+
699
+ let(:view) do
700
+ Mongo::Collection::View.new(collection, selector, options)
701
+ end
702
+
703
+ let(:view_with_read_pref) do
704
+ view.read(:mode => :secondary, :tag_sets => [{ 'non' => 'existent' }])
705
+ end
706
+
707
+ let(:result) do
708
+ view_with_read_pref.distinct(:field)
709
+ end
710
+
711
+ it 'uses the read preference setting on the view' do
712
+ expect {
713
+ result
714
+ }.to raise_exception(Mongo::Error::NoServerAvailable)
715
+ end
716
+ end
717
+
572
718
  context 'when the collection has a read preference set' do
573
719
 
574
720
  let(:documents) do
@@ -667,6 +813,21 @@ describe Mongo::Collection::View::Readable do
667
813
  }.to raise_exception(Mongo::Error::NoServerAvailable)
668
814
  end
669
815
  end
816
+
817
+ context 'when a read preference is set on the view' do
818
+
819
+ let(:view_with_read_pref) do
820
+ view.read(:mode => :secondary, :tag_sets => [{ 'non' => 'existent' }])
821
+ end
822
+
823
+ let(:distinct) do
824
+ view_with_read_pref.distinct(:field, read: { mode: :primary })
825
+ end
826
+
827
+ it 'uses the read preference passed to the method' do
828
+ expect(distinct.sort).to eq([ 'test1', 'test2', 'test3' ])
829
+ end
830
+ end
670
831
  end
671
832
 
672
833
  context 'when a max_time_ms is specified', if: write_command_enabled? do
@@ -697,7 +858,52 @@ describe Mongo::Collection::View::Readable do
697
858
  end
698
859
  end
699
860
 
700
- context 'when a collation is specified' do
861
+ context 'when a collation is specified on the view' do
862
+
863
+ let(:result) do
864
+ view.distinct(:name)
865
+ end
866
+
867
+ before do
868
+ authorized_collection.insert_one(name: 'bang')
869
+ authorized_collection.insert_one(name: 'BANG')
870
+ end
871
+
872
+ let(:options) do
873
+ { collation: { locale: 'en_US', strength: 2 } }
874
+ end
875
+
876
+ context 'when the server selected supports collations', if: collation_enabled? do
877
+
878
+ it 'applies the collation to the distinct' do
879
+ expect(result).to eq(['bang'])
880
+ end
881
+ end
882
+
883
+ context 'when the server selected does not support collations', unless: collation_enabled? do
884
+
885
+ it 'raises an exception' do
886
+ expect {
887
+ result
888
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
889
+ end
890
+
891
+ context 'when a String key is used' do
892
+
893
+ let(:options) do
894
+ { 'collation' => { locale: 'en_US', strength: 2 } }
895
+ end
896
+
897
+ it 'raises an exception' do
898
+ expect {
899
+ result
900
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
901
+ end
902
+ end
903
+ end
904
+ end
905
+
906
+ context 'when a collation is specified in the method options' do
701
907
 
702
908
  let(:result) do
703
909
  view.distinct(:name, distinct_options)
@@ -142,6 +142,54 @@ describe Mongo::Collection::View::Writable do
142
142
  expect(result).to be_nil
143
143
  end
144
144
  end
145
+
146
+ context 'when collation is specified as a method option' do
147
+
148
+ let(:selector) do
149
+ { name: 'BANG' }
150
+ end
151
+
152
+ let(:result) do
153
+ view.find_one_and_delete(method_options)
154
+ end
155
+
156
+ before do
157
+ authorized_collection.insert_one(name: 'bang')
158
+ end
159
+
160
+ let(:method_options) do
161
+ { collation: { locale: 'en_US', strength: 2 } }
162
+ end
163
+
164
+ context 'when the server selected supports collations', if: collation_enabled? do
165
+
166
+ it 'applies the collation' do
167
+ expect(result['name']).to eq('bang')
168
+ end
169
+ end
170
+
171
+ context 'when the server selected does not support collations', unless: collation_enabled? do
172
+
173
+ it 'raises an exception' do
174
+ expect {
175
+ result
176
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
177
+ end
178
+
179
+ context 'when a String key is used' do
180
+
181
+ let(:method_options) do
182
+ { 'collation' => { locale: 'en_US', strength: 2 } }
183
+ end
184
+
185
+ it 'raises an exception' do
186
+ expect {
187
+ result
188
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
189
+ end
190
+ end
191
+ end
192
+ end
145
193
  end
146
194
 
147
195
  context 'when no matching document is found' do
@@ -270,6 +318,55 @@ describe Mongo::Collection::View::Writable do
270
318
  end
271
319
  end
272
320
 
321
+ context 'when collation is provided as a method option' do
322
+
323
+ let(:selector) do
324
+ { name: 'BANG' }
325
+ end
326
+
327
+ let(:result) do
328
+ view.find_one_and_replace({ name: 'doink' }, method_options)
329
+ end
330
+
331
+ before do
332
+ authorized_collection.insert_one(name: 'bang')
333
+ end
334
+
335
+ let(:method_options) do
336
+ { collation: { locale: 'en_US', strength: 2 } }
337
+ end
338
+
339
+ context 'when the server selected supports collations', if: collation_enabled? do
340
+
341
+ it 'applies the collation' do
342
+ expect(result['name']).to eq('bang')
343
+ expect(authorized_collection.find({ name: 'doink' }, limit: -1).first['name']).to eq('doink')
344
+ end
345
+ end
346
+
347
+ context 'when the server selected does not support collations', unless: collation_enabled? do
348
+
349
+ it 'raises an exception' do
350
+ expect {
351
+ result
352
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
353
+ end
354
+
355
+ context 'when a String key is used' do
356
+
357
+ let(:method_options) do
358
+ { 'collation' => { locale: 'en_US', strength: 2 } }
359
+ end
360
+
361
+ it 'raises an exception' do
362
+ expect {
363
+ result
364
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
365
+ end
366
+ end
367
+ end
368
+ end
369
+
273
370
  context 'when collation is not provided' do
274
371
 
275
372
  let(:selector) do
@@ -431,6 +528,55 @@ describe Mongo::Collection::View::Writable do
431
528
  end
432
529
  end
433
530
 
531
+ context 'when a collation is specified as a method option' do
532
+
533
+ let(:selector) do
534
+ { name: 'BANG' }
535
+ end
536
+
537
+ let(:result) do
538
+ view.find_one_and_update({ '$set' => { other: 'doink' } }, method_options)
539
+ end
540
+
541
+ before do
542
+ authorized_collection.insert_one(name: 'bang')
543
+ end
544
+
545
+ let(:method_options) do
546
+ { collation: { locale: 'en_US', strength: 2 } }
547
+ end
548
+
549
+ context 'when the server selected supports collations', if: collation_enabled? do
550
+
551
+ it 'applies the collation' do
552
+ expect(result['name']).to eq('bang')
553
+ expect(authorized_collection.find({ name: 'bang' }, limit: -1).first['other']).to eq('doink')
554
+ end
555
+ end
556
+
557
+ context 'when the server selected does not support collations', unless: collation_enabled? do
558
+
559
+ it 'raises an exception' do
560
+ expect {
561
+ result
562
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
563
+ end
564
+
565
+ context 'when a String key is used' do
566
+
567
+ let(:method_options) do
568
+ { 'collation' => { locale: 'en_US', strength: 2 } }
569
+ end
570
+
571
+ it 'raises an exception' do
572
+ expect {
573
+ result
574
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
575
+ end
576
+ end
577
+ end
578
+ end
579
+
434
580
  context 'when no collation is specified' do
435
581
 
436
582
  let(:selector) do
@@ -509,7 +655,7 @@ describe Mongo::Collection::View::Writable do
509
655
  end
510
656
 
511
657
  let(:result) do
512
- view.delete_many(options)
658
+ view.delete_many
513
659
  end
514
660
 
515
661
  before do
@@ -552,6 +698,56 @@ describe Mongo::Collection::View::Writable do
552
698
  end
553
699
  end
554
700
 
701
+ context 'when a collation is specified as a method option' do
702
+
703
+ let(:selector) do
704
+ { name: 'BANG' }
705
+ end
706
+
707
+ let(:result) do
708
+ view.delete_many(method_options)
709
+ end
710
+
711
+ before do
712
+ authorized_collection.insert_one(name: 'bang')
713
+ authorized_collection.insert_one(name: 'bang')
714
+ end
715
+
716
+ let(:method_options) do
717
+ { collation: { locale: 'en_US', strength: 2 } }
718
+ end
719
+
720
+ context 'when the server selected supports collations', if: collation_enabled? do
721
+
722
+ it 'applies the collation' do
723
+ expect(result.written_count).to eq(2)
724
+ expect(authorized_collection.find(name: 'bang').to_a.size).to eq(0)
725
+ end
726
+ end
727
+
728
+ context 'when the server selected does not support collations', unless: collation_enabled? do
729
+
730
+ it 'raises an exception' do
731
+ expect {
732
+ result
733
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
734
+ end
735
+
736
+ context 'when a String key is used' do
737
+
738
+ let(:method_options) do
739
+ { 'collation' => { locale: 'en_US', strength: 2 } }
740
+ end
741
+
742
+ it 'raises an exception' do
743
+ expect {
744
+ result
745
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
746
+ end
747
+ end
748
+ end
749
+ end
750
+
555
751
  context 'when a collation is not specified' do
556
752
 
557
753
  let(:selector) do
@@ -621,7 +817,7 @@ describe Mongo::Collection::View::Writable do
621
817
  end
622
818
 
623
819
  let(:result) do
624
- view.delete_one(options)
820
+ view.delete_one
625
821
  end
626
822
 
627
823
  before do
@@ -663,6 +859,55 @@ describe Mongo::Collection::View::Writable do
663
859
  end
664
860
  end
665
861
 
862
+ context 'when a collation is provided as a method_option' do
863
+
864
+ let(:selector) do
865
+ { name: 'BANG' }
866
+ end
867
+
868
+ let(:result) do
869
+ view.delete_one(method_options)
870
+ end
871
+
872
+ before do
873
+ authorized_collection.insert_one(name: 'bang')
874
+ end
875
+
876
+ let(:method_options) do
877
+ { collation: { locale: 'en_US', strength: 2 } }
878
+ end
879
+
880
+ context 'when the server selected supports collations', if: collation_enabled? do
881
+
882
+ it 'applies the collation' do
883
+ expect(result.written_count).to eq(1)
884
+ expect(authorized_collection.find(name: 'bang').to_a.size).to eq(0)
885
+ end
886
+ end
887
+
888
+ context 'when the server selected does not support collations', unless: collation_enabled? do
889
+
890
+ it 'raises an exception' do
891
+ expect {
892
+ result
893
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
894
+ end
895
+
896
+ context 'when a String key is used' do
897
+
898
+ let(:method_options) do
899
+ { 'collation' => { locale: 'en_US', strength: 2 } }
900
+ end
901
+
902
+ it 'raises an exception' do
903
+ expect {
904
+ result
905
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
906
+ end
907
+ end
908
+ end
909
+ end
910
+
666
911
  context 'when a collation is not specified' do
667
912
 
668
913
  let(:selector) do
@@ -800,7 +1045,7 @@ describe Mongo::Collection::View::Writable do
800
1045
  end
801
1046
 
802
1047
  let(:result) do
803
- view.replace_one({ name: 'doink' }, options)
1048
+ view.replace_one({ name: 'doink' })
804
1049
  end
805
1050
 
806
1051
  before do
@@ -842,6 +1087,55 @@ describe Mongo::Collection::View::Writable do
842
1087
  end
843
1088
  end
844
1089
 
1090
+ context 'when a collation is specified as method option' do
1091
+
1092
+ let(:selector) do
1093
+ { name: 'BANG' }
1094
+ end
1095
+
1096
+ let(:result) do
1097
+ view.replace_one({ name: 'doink' }, method_options)
1098
+ end
1099
+
1100
+ before do
1101
+ authorized_collection.insert_one(name: 'bang')
1102
+ end
1103
+
1104
+ let(:method_options) do
1105
+ { collation: { locale: 'en_US', strength: 2 } }
1106
+ end
1107
+
1108
+ context 'when the server selected supports collations', if: collation_enabled? do
1109
+
1110
+ it 'applies the collation' do
1111
+ expect(result.written_count).to eq(1)
1112
+ expect(authorized_collection.find(name: 'doink').to_a.size).to eq(1)
1113
+ end
1114
+ end
1115
+
1116
+ context 'when the server selected does not support collations', unless: collation_enabled? do
1117
+
1118
+ it 'raises an exception' do
1119
+ expect {
1120
+ result
1121
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1122
+ end
1123
+
1124
+ context 'when a String key is used' do
1125
+
1126
+ let(:method_options) do
1127
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1128
+ end
1129
+
1130
+ it 'raises an exception' do
1131
+ expect {
1132
+ result
1133
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1134
+ end
1135
+ end
1136
+ end
1137
+ end
1138
+
845
1139
  context 'when a collation is not specified' do
846
1140
 
847
1141
  let(:selector) do
@@ -983,7 +1277,7 @@ describe Mongo::Collection::View::Writable do
983
1277
  end
984
1278
 
985
1279
  let(:result) do
986
- view.update_many({ '$set' => { other: 'doink' } }, options)
1280
+ view.update_many({ '$set' => { other: 'doink' } })
987
1281
  end
988
1282
 
989
1283
  before do
@@ -1026,6 +1320,56 @@ describe Mongo::Collection::View::Writable do
1026
1320
  end
1027
1321
  end
1028
1322
 
1323
+ context 'when a collation is specified as a method option' do
1324
+
1325
+ let(:selector) do
1326
+ { name: 'BANG' }
1327
+ end
1328
+
1329
+ let(:result) do
1330
+ view.update_many({ '$set' => { other: 'doink' } }, method_options)
1331
+ end
1332
+
1333
+ before do
1334
+ authorized_collection.insert_one(name: 'bang')
1335
+ authorized_collection.insert_one(name: 'baNG')
1336
+ end
1337
+
1338
+ let(:method_options) do
1339
+ { collation: { locale: 'en_US', strength: 2 } }
1340
+ end
1341
+
1342
+ context 'when the server selected supports collations', if: collation_enabled? do
1343
+
1344
+ it 'applies the collation' do
1345
+ expect(result.written_count).to eq(2)
1346
+ expect(authorized_collection.find(other: 'doink').to_a.size).to eq(2)
1347
+ end
1348
+ end
1349
+
1350
+ context 'when the server selected does not support collations', unless: collation_enabled? do
1351
+
1352
+ it 'raises an exception' do
1353
+ expect {
1354
+ result
1355
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1356
+ end
1357
+
1358
+ context 'when a String key is used' do
1359
+
1360
+ let(:method_options) do
1361
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1362
+ end
1363
+
1364
+ it 'raises an exception' do
1365
+ expect {
1366
+ result
1367
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1368
+ end
1369
+ end
1370
+ end
1371
+ end
1372
+
1029
1373
  context 'when collation is not specified' do
1030
1374
 
1031
1375
  let(:selector) do
@@ -1165,7 +1509,7 @@ describe Mongo::Collection::View::Writable do
1165
1509
  end
1166
1510
 
1167
1511
  let(:result) do
1168
- view.update_one({ '$set' => { other: 'doink' } }, options)
1512
+ view.update_one({ '$set' => { other: 'doink' } })
1169
1513
  end
1170
1514
 
1171
1515
  before do
@@ -1207,6 +1551,55 @@ describe Mongo::Collection::View::Writable do
1207
1551
  end
1208
1552
  end
1209
1553
 
1554
+ context 'when there is a collation specified as a method option' do
1555
+
1556
+ let(:selector) do
1557
+ { name: 'BANG' }
1558
+ end
1559
+
1560
+ let(:result) do
1561
+ view.update_one({ '$set' => { other: 'doink' } }, method_options)
1562
+ end
1563
+
1564
+ before do
1565
+ authorized_collection.insert_one(name: 'bang')
1566
+ end
1567
+
1568
+ let(:method_options) do
1569
+ { collation: { locale: 'en_US', strength: 2 } }
1570
+ end
1571
+
1572
+ context 'when the server selected supports collations', if: collation_enabled? do
1573
+
1574
+ it 'applies the collation' do
1575
+ expect(result.written_count).to eq(1)
1576
+ expect(authorized_collection.find(other: 'doink').to_a.size).to eq(1)
1577
+ end
1578
+ end
1579
+
1580
+ context 'when the server selected does not support collations', unless: collation_enabled? do
1581
+
1582
+ it 'raises an exception' do
1583
+ expect {
1584
+ result
1585
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1586
+ end
1587
+
1588
+ context 'when a String key is used' do
1589
+
1590
+ let(:method_options) do
1591
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1592
+ end
1593
+
1594
+ it 'raises an exception' do
1595
+ expect {
1596
+ result
1597
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1598
+ end
1599
+ end
1600
+ end
1601
+ end
1602
+
1210
1603
  context 'when a collation is not specified' do
1211
1604
 
1212
1605
  let(:selector) do