mongo 2.3.1 → 2.4.0.rc0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -3
- data/lib/mongo/bulk_write.rb +8 -7
- data/lib/mongo/bulk_write/combineable.rb +4 -0
- data/lib/mongo/bulk_write/transformable.rb +17 -5
- data/lib/mongo/bulk_write/validatable.rb +1 -0
- data/lib/mongo/client.rb +3 -0
- data/lib/mongo/cluster.rb +8 -0
- data/lib/mongo/cluster/app_metadata.rb +135 -0
- data/lib/mongo/collection.rb +42 -10
- data/lib/mongo/collection/view.rb +15 -1
- data/lib/mongo/collection/view/aggregation.rb +5 -0
- data/lib/mongo/collection/view/builder/aggregation.rb +13 -3
- data/lib/mongo/collection/view/builder/find_command.rb +7 -21
- data/lib/mongo/collection/view/builder/map_reduce.rb +22 -5
- data/lib/mongo/collection/view/iterable.rb +1 -0
- data/lib/mongo/collection/view/map_reduce.rb +5 -0
- data/lib/mongo/collection/view/readable.rb +35 -14
- data/lib/mongo/collection/view/writable.rb +54 -23
- data/lib/mongo/cursor/builder/get_more_command.rb +2 -3
- data/lib/mongo/database.rb +10 -2
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/error/invalid_application_name.rb +38 -0
- data/lib/mongo/error/invalid_server_preference.rb +24 -3
- data/lib/mongo/error/unsupported_collation.rb +51 -0
- data/lib/mongo/index/view.rb +28 -15
- data/lib/mongo/operation.rb +6 -0
- data/lib/mongo/operation/commands.rb +3 -0
- data/lib/mongo/operation/commands/aggregate.rb +10 -10
- data/lib/mongo/operation/commands/create.rb +45 -0
- data/lib/mongo/operation/commands/drop.rb +45 -0
- data/lib/mongo/operation/commands/drop_database.rb +45 -0
- data/lib/mongo/operation/commands/map_reduce.rb +12 -1
- data/lib/mongo/operation/commands/parallel_scan.rb +1 -0
- data/lib/mongo/operation/read_preference.rb +9 -9
- data/lib/mongo/operation/specifiable.rb +34 -0
- data/lib/mongo/operation/takes_write_concern.rb +35 -0
- data/lib/mongo/operation/write/bulk/bulkable.rb +1 -1
- data/lib/mongo/operation/write/command/create_index.rb +6 -0
- data/lib/mongo/operation/write/command/drop_index.rb +6 -0
- data/lib/mongo/operation/write/command/insert.rb +1 -1
- data/lib/mongo/operation/write/command/update.rb +1 -0
- data/lib/mongo/operation/write/command/writable.rb +2 -2
- data/lib/mongo/operation/write/create_index.rb +2 -2
- data/lib/mongo/operation/write/create_user.rb +1 -1
- data/lib/mongo/operation/write/delete.rb +5 -1
- data/lib/mongo/operation/write/gle.rb +1 -1
- data/lib/mongo/operation/write/insert.rb +2 -2
- data/lib/mongo/operation/write/remove_user.rb +1 -1
- data/lib/mongo/operation/write/update.rb +5 -1
- data/lib/mongo/operation/write/update_user.rb +1 -1
- data/lib/mongo/operation/write/write_command_enabled.rb +10 -2
- data/lib/mongo/protocol/insert.rb +1 -2
- data/lib/mongo/protocol/query.rb +3 -7
- data/lib/mongo/server.rb +8 -3
- data/lib/mongo/server/connection.rb +17 -11
- data/lib/mongo/server/description.rb +22 -0
- data/lib/mongo/server/description/features.rb +2 -0
- data/lib/mongo/server/monitor.rb +5 -0
- data/lib/mongo/server/monitor/connection.rb +11 -0
- data/lib/mongo/server_selector/nearest.rb +9 -6
- data/lib/mongo/server_selector/primary.rb +4 -0
- data/lib/mongo/server_selector/primary_preferred.rb +7 -1
- data/lib/mongo/server_selector/secondary.rb +5 -0
- data/lib/mongo/server_selector/secondary_preferred.rb +7 -2
- data/lib/mongo/server_selector/selectable.rb +57 -10
- data/lib/mongo/socket/ssl.rb +1 -0
- data/lib/mongo/uri.rb +4 -0
- data/lib/mongo/version.rb +1 -1
- data/lib/mongo/write_concern.rb +1 -0
- data/mongo.gemspec +1 -1
- data/spec/mongo/auth/cr_spec.rb +7 -1
- data/spec/mongo/auth/ldap_spec.rb +7 -1
- data/spec/mongo/auth/scram_spec.rb +7 -1
- data/spec/mongo/auth/x509_spec.rb +7 -1
- data/spec/mongo/bulk_write_spec.rb +598 -5
- data/spec/mongo/client_spec.rb +47 -1
- data/spec/mongo/cluster/app_metadata_spec.rb +104 -0
- data/spec/mongo/cluster/topology/replica_set_spec.rb +14 -8
- data/spec/mongo/cluster/topology/sharded_spec.rb +9 -3
- data/spec/mongo/cluster/topology/single_spec.rb +10 -4
- data/spec/mongo/cluster_spec.rb +29 -0
- data/spec/mongo/collection/view/aggregation_spec.rb +139 -0
- data/spec/mongo/collection/view/builder/find_command_spec.rb +6 -243
- data/spec/mongo/collection/view/map_reduce_spec.rb +104 -0
- data/spec/mongo/collection/view/readable_spec.rb +83 -0
- data/spec/mongo/collection/view/writable_spec.rb +447 -1
- data/spec/mongo/collection/view_spec.rb +57 -0
- data/spec/mongo/collection_spec.rb +926 -101
- data/spec/mongo/crud_spec.rb +4 -5
- data/spec/mongo/database_spec.rb +99 -1
- data/spec/mongo/index/view_spec.rb +360 -31
- data/spec/mongo/max_staleness_spec.rb +108 -0
- data/spec/mongo/operation/read_preference_spec.rb +8 -8
- data/spec/mongo/operation/write/command/delete_spec.rb +1 -1
- data/spec/mongo/operation/write/command/insert_spec.rb +1 -1
- data/spec/mongo/operation/write/command/update_spec.rb +1 -1
- data/spec/mongo/server/connection_pool_spec.rb +3 -1
- data/spec/mongo/server/connection_spec.rb +17 -7
- data/spec/mongo/server/description/features_spec.rb +50 -0
- data/spec/mongo/server/description_spec.rb +9 -3
- data/spec/mongo/server_selection_spec.rb +5 -3
- data/spec/mongo/server_selector/nearest_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/primary_spec.rb +36 -0
- data/spec/mongo/server_selector/secondary_preferred_spec.rb +73 -0
- data/spec/mongo/server_selector/secondary_spec.rb +73 -0
- data/spec/mongo/server_selector_spec.rb +53 -0
- data/spec/mongo/server_spec.rb +3 -1
- data/spec/mongo/uri_spec.rb +54 -0
- data/spec/mongo/write_concern_spec.rb +18 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/authorization.rb +8 -1
- data/spec/support/crud.rb +15 -0
- data/spec/support/crud/read.rb +27 -19
- data/spec/support/crud/write.rb +28 -3
- data/spec/support/crud_tests/read/aggregate.yml +15 -3
- data/spec/support/crud_tests/read/count.yml +14 -3
- data/spec/support/crud_tests/read/distinct.yml +13 -1
- data/spec/support/crud_tests/read/find.yml +12 -2
- data/spec/support/crud_tests/write/deleteMany.yml +22 -1
- data/spec/support/crud_tests/write/deleteOne.yml +20 -1
- data/spec/support/crud_tests/write/findOneAndDelete.yml +27 -2
- data/spec/support/crud_tests/write/findOneAndReplace.yml +43 -14
- data/spec/support/crud_tests/write/findOneAndUpdate.yml +50 -8
- data/spec/support/crud_tests/write/replaceOne.yml +34 -10
- data/spec/support/crud_tests/write/updateMany.yml +42 -11
- data/spec/support/crud_tests/write/updateOne.yml +32 -7
- data/spec/support/max_staleness/ReplicaSetNoPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/LastUpdateTime.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/PrimaryPreferred_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/Secondary.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetNoPrimary/SecondaryPreferred_tags.yml +51 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/DefaultNoMaxStaleness.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Incompatible.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/LastUpdateTime.yml +35 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessTooSmall.yml +25 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/MaxStalenessWithModePrimary.yml +23 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest2.yml +33 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Nearest_tags.yml +36 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/PrimaryPreferred_incompatible.yml +27 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred.yml +26 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/SecondaryPreferred_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags.yml +59 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/Secondary_tags2.yml +43 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ShortHeartbeartShortMaxStaleness2.yml +29 -0
- data/spec/support/max_staleness/ReplicaSetWithPrimary/ZeroMaxStaleness.yml +27 -0
- data/spec/support/max_staleness/Sharded/Incompatible.yml +25 -0
- data/spec/support/max_staleness/Sharded/SmallMaxStaleness.yml +20 -0
- data/spec/support/max_staleness/Single/Incompatible.yml +18 -0
- data/spec/support/max_staleness/Single/SmallMaxStaleness.yml +20 -0
- data/spec/support/server_selection.rb +25 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Nearest_multiple.yml +27 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetNoPrimary/read/Secondary_multi_tags2.yml +31 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/Nearest_multiple.yml +34 -0
- data/spec/support/server_selection/selection/ReplicaSetWithPrimary/read/SecondaryPreferred_tags.yml +28 -0
- data/spec/support/shared/server_selector.rb +4 -3
- metadata +91 -6
- metadata.gz.sig +0 -0
@@ -75,6 +75,60 @@ describe Mongo::Collection::View::Writable do
|
|
75
75
|
expect(document['field']).to eq('test1')
|
76
76
|
end
|
77
77
|
end
|
78
|
+
|
79
|
+
context 'when collation is specified' do
|
80
|
+
|
81
|
+
let(:selector) do
|
82
|
+
{ name: 'BANG' }
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:result) do
|
86
|
+
view.find_one_and_delete
|
87
|
+
end
|
88
|
+
|
89
|
+
before do
|
90
|
+
authorized_collection.insert_one(name: 'bang')
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:options) do
|
94
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
98
|
+
|
99
|
+
it 'applies the collation' do
|
100
|
+
expect(result['name']).to eq('bang')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
105
|
+
|
106
|
+
it 'raises an exception' do
|
107
|
+
expect {
|
108
|
+
result
|
109
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when collation is not specified' do
|
115
|
+
|
116
|
+
let(:selector) do
|
117
|
+
{ name: 'BANG' }
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:result) do
|
121
|
+
view.find_one_and_delete
|
122
|
+
end
|
123
|
+
|
124
|
+
before do
|
125
|
+
authorized_collection.insert_one(name: 'bang')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'does not apply the collation' do
|
129
|
+
expect(result).to be_nil
|
130
|
+
end
|
131
|
+
end
|
78
132
|
end
|
79
133
|
|
80
134
|
context 'when no matching document is found' do
|
@@ -153,6 +207,61 @@ describe Mongo::Collection::View::Writable do
|
|
153
207
|
expect(document['field']).to eq('test1')
|
154
208
|
end
|
155
209
|
end
|
210
|
+
|
211
|
+
context 'when collation is provided' do
|
212
|
+
|
213
|
+
let(:selector) do
|
214
|
+
{ name: 'BANG' }
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:result) do
|
218
|
+
view.find_one_and_replace(name: 'doink')
|
219
|
+
end
|
220
|
+
|
221
|
+
before do
|
222
|
+
authorized_collection.insert_one(name: 'bang')
|
223
|
+
end
|
224
|
+
|
225
|
+
let(:options) do
|
226
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
230
|
+
|
231
|
+
it 'applies the collation' do
|
232
|
+
expect(result['name']).to eq('bang')
|
233
|
+
expect(authorized_collection.find({ name: 'doink' }, limit: -1).first['name']).to eq('doink')
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
238
|
+
|
239
|
+
it 'raises an exception' do
|
240
|
+
expect {
|
241
|
+
result
|
242
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when collation is not provided' do
|
248
|
+
|
249
|
+
let(:selector) do
|
250
|
+
{ name: 'BANG' }
|
251
|
+
end
|
252
|
+
|
253
|
+
let(:result) do
|
254
|
+
view.find_one_and_replace(name: 'doink')
|
255
|
+
end
|
256
|
+
|
257
|
+
before do
|
258
|
+
authorized_collection.insert_one(name: 'bang')
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'does not apply the collation' do
|
262
|
+
expect(result).to be_nil
|
263
|
+
end
|
264
|
+
end
|
156
265
|
end
|
157
266
|
|
158
267
|
context 'when no matching document is found' do
|
@@ -238,7 +347,7 @@ describe Mongo::Collection::View::Writable do
|
|
238
347
|
context 'when a sort is provided' do
|
239
348
|
|
240
349
|
let(:document) do
|
241
|
-
view.sort(field: 1).find_one_and_update({ '$set' => { field: 'testing' }})
|
350
|
+
view.sort(field: 1).find_one_and_update({ '$set' => { field: 'testing' } })
|
242
351
|
end
|
243
352
|
|
244
353
|
it 'returns the original document' do
|
@@ -247,6 +356,61 @@ describe Mongo::Collection::View::Writable do
|
|
247
356
|
end
|
248
357
|
end
|
249
358
|
|
359
|
+
context 'when a collation is specified' do
|
360
|
+
|
361
|
+
let(:selector) do
|
362
|
+
{ name: 'BANG' }
|
363
|
+
end
|
364
|
+
|
365
|
+
let(:result) do
|
366
|
+
view.find_one_and_update({ '$set' => { other: 'doink' } })
|
367
|
+
end
|
368
|
+
|
369
|
+
before do
|
370
|
+
authorized_collection.insert_one(name: 'bang')
|
371
|
+
end
|
372
|
+
|
373
|
+
let(:options) do
|
374
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
375
|
+
end
|
376
|
+
|
377
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
378
|
+
|
379
|
+
it 'applies the collation' do
|
380
|
+
expect(result['name']).to eq('bang')
|
381
|
+
expect(authorized_collection.find({ name: 'bang' }, limit: -1).first['other']).to eq('doink')
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
386
|
+
|
387
|
+
it 'raises an exception' do
|
388
|
+
expect {
|
389
|
+
result
|
390
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
context 'when no collation is specified' do
|
396
|
+
|
397
|
+
let(:selector) do
|
398
|
+
{ name: 'BANG' }
|
399
|
+
end
|
400
|
+
|
401
|
+
let(:result) do
|
402
|
+
view.find_one_and_update({ '$set' => { other: 'doink' } })
|
403
|
+
end
|
404
|
+
|
405
|
+
before do
|
406
|
+
authorized_collection.insert_one(name: 'bang')
|
407
|
+
end
|
408
|
+
|
409
|
+
it 'does not apply the collation' do
|
410
|
+
expect(result).to be_nil
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
250
414
|
context 'when no matching document is found' do
|
251
415
|
|
252
416
|
let(:selector) do
|
@@ -298,6 +462,64 @@ describe Mongo::Collection::View::Writable do
|
|
298
462
|
expect(response.written_count).to eq(2)
|
299
463
|
end
|
300
464
|
end
|
465
|
+
|
466
|
+
context 'when a collation is specified' do
|
467
|
+
|
468
|
+
let(:selector) do
|
469
|
+
{ name: 'BANG' }
|
470
|
+
end
|
471
|
+
|
472
|
+
let(:result) do
|
473
|
+
view.delete_many(options)
|
474
|
+
end
|
475
|
+
|
476
|
+
before do
|
477
|
+
authorized_collection.insert_one(name: 'bang')
|
478
|
+
authorized_collection.insert_one(name: 'bang')
|
479
|
+
end
|
480
|
+
|
481
|
+
let(:options) do
|
482
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
483
|
+
end
|
484
|
+
|
485
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
486
|
+
|
487
|
+
it 'applies the collation' do
|
488
|
+
expect(result.written_count).to eq(2)
|
489
|
+
expect(authorized_collection.find(name: 'bang').to_a.size).to eq(0)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
494
|
+
|
495
|
+
it 'raises an exception' do
|
496
|
+
expect {
|
497
|
+
result
|
498
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
context 'when a collation is not specified' do
|
504
|
+
|
505
|
+
let(:selector) do
|
506
|
+
{ name: 'BANG' }
|
507
|
+
end
|
508
|
+
|
509
|
+
let(:result) do
|
510
|
+
view.delete_many
|
511
|
+
end
|
512
|
+
|
513
|
+
before do
|
514
|
+
authorized_collection.insert_one(name: 'bang')
|
515
|
+
authorized_collection.insert_one(name: 'bang')
|
516
|
+
end
|
517
|
+
|
518
|
+
it 'does not apply the collation' do
|
519
|
+
expect(result.written_count).to eq(0)
|
520
|
+
expect(authorized_collection.find(name: 'bang').to_a.size).to eq(2)
|
521
|
+
end
|
522
|
+
end
|
301
523
|
end
|
302
524
|
|
303
525
|
describe '#delete_one' do
|
@@ -339,6 +561,62 @@ describe Mongo::Collection::View::Writable do
|
|
339
561
|
expect(response.written_count).to eq(1)
|
340
562
|
end
|
341
563
|
end
|
564
|
+
|
565
|
+
context 'when a collation is provided' do
|
566
|
+
|
567
|
+
let(:selector) do
|
568
|
+
{ name: 'BANG' }
|
569
|
+
end
|
570
|
+
|
571
|
+
let(:result) do
|
572
|
+
view.delete_one(options)
|
573
|
+
end
|
574
|
+
|
575
|
+
before do
|
576
|
+
authorized_collection.insert_one(name: 'bang')
|
577
|
+
end
|
578
|
+
|
579
|
+
let(:options) do
|
580
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
581
|
+
end
|
582
|
+
|
583
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
584
|
+
|
585
|
+
it 'applies the collation' do
|
586
|
+
expect(result.written_count).to eq(1)
|
587
|
+
expect(authorized_collection.find(name: 'bang').to_a.size).to eq(0)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
592
|
+
|
593
|
+
it 'raises an exception' do
|
594
|
+
expect {
|
595
|
+
result
|
596
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
597
|
+
end
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
context 'when a collation is not specified' do
|
602
|
+
|
603
|
+
let(:selector) do
|
604
|
+
{name: 'BANG'}
|
605
|
+
end
|
606
|
+
|
607
|
+
let(:result) do
|
608
|
+
view.delete_one
|
609
|
+
end
|
610
|
+
|
611
|
+
before do
|
612
|
+
authorized_collection.insert_one(name: 'bang')
|
613
|
+
end
|
614
|
+
|
615
|
+
it 'does not apply the collation' do
|
616
|
+
expect(result.written_count).to eq(0)
|
617
|
+
expect(authorized_collection.find(name: 'bang').to_a.size).to eq(1)
|
618
|
+
end
|
619
|
+
end
|
342
620
|
end
|
343
621
|
|
344
622
|
describe '#replace_one' do
|
@@ -449,6 +727,62 @@ describe Mongo::Collection::View::Writable do
|
|
449
727
|
expect(updated).to be_empty
|
450
728
|
end
|
451
729
|
end
|
730
|
+
|
731
|
+
context 'when a collation is specified' do
|
732
|
+
|
733
|
+
let(:selector) do
|
734
|
+
{ name: 'BANG' }
|
735
|
+
end
|
736
|
+
|
737
|
+
let(:result) do
|
738
|
+
view.replace_one({ name: 'doink' }, options)
|
739
|
+
end
|
740
|
+
|
741
|
+
before do
|
742
|
+
authorized_collection.insert_one(name: 'bang')
|
743
|
+
end
|
744
|
+
|
745
|
+
let(:options) do
|
746
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
747
|
+
end
|
748
|
+
|
749
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
750
|
+
|
751
|
+
it 'applies the collation' do
|
752
|
+
expect(result.written_count).to eq(1)
|
753
|
+
expect(authorized_collection.find(name: 'doink').to_a.size).to eq(1)
|
754
|
+
end
|
755
|
+
end
|
756
|
+
|
757
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
758
|
+
|
759
|
+
it 'raises an exception' do
|
760
|
+
expect {
|
761
|
+
result
|
762
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
763
|
+
end
|
764
|
+
end
|
765
|
+
end
|
766
|
+
|
767
|
+
context 'when a collation is not specified' do
|
768
|
+
|
769
|
+
let(:selector) do
|
770
|
+
{ name: 'BANG' }
|
771
|
+
end
|
772
|
+
|
773
|
+
let(:result) do
|
774
|
+
view.replace_one(name: 'doink')
|
775
|
+
end
|
776
|
+
|
777
|
+
before do
|
778
|
+
authorized_collection.insert_one(name: 'bang')
|
779
|
+
end
|
780
|
+
|
781
|
+
it 'does not apply the collation' do
|
782
|
+
expect(result.written_count).to eq(0)
|
783
|
+
expect(authorized_collection.find(name: 'bang').to_a.size).to eq(1)
|
784
|
+
end
|
785
|
+
end
|
452
786
|
end
|
453
787
|
|
454
788
|
describe '#update_many' do
|
@@ -563,6 +897,63 @@ describe Mongo::Collection::View::Writable do
|
|
563
897
|
expect(updated).to be_empty
|
564
898
|
end
|
565
899
|
end
|
900
|
+
|
901
|
+
context 'when a collation is specified' do
|
902
|
+
|
903
|
+
let(:selector) do
|
904
|
+
{ name: 'BANG' }
|
905
|
+
end
|
906
|
+
|
907
|
+
let(:result) do
|
908
|
+
view.update_many({ '$set' => { other: 'doink' } }, options)
|
909
|
+
end
|
910
|
+
|
911
|
+
before do
|
912
|
+
authorized_collection.insert_one(name: 'bang')
|
913
|
+
authorized_collection.insert_one(name: 'baNG')
|
914
|
+
end
|
915
|
+
|
916
|
+
let(:options) do
|
917
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
918
|
+
end
|
919
|
+
|
920
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
921
|
+
|
922
|
+
it 'applies the collation' do
|
923
|
+
expect(result.written_count).to eq(2)
|
924
|
+
expect(authorized_collection.find(other: 'doink').to_a.size).to eq(2)
|
925
|
+
end
|
926
|
+
end
|
927
|
+
|
928
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
929
|
+
|
930
|
+
it 'raises an exception' do
|
931
|
+
expect {
|
932
|
+
result
|
933
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
934
|
+
end
|
935
|
+
end
|
936
|
+
end
|
937
|
+
|
938
|
+
context 'when collation is not specified' do
|
939
|
+
|
940
|
+
let(:selector) do
|
941
|
+
{name: 'BANG'}
|
942
|
+
end
|
943
|
+
|
944
|
+
let(:result) do
|
945
|
+
view.update_many('$set' => {other: 'doink'})
|
946
|
+
end
|
947
|
+
|
948
|
+
before do
|
949
|
+
authorized_collection.insert_one(name: 'bang')
|
950
|
+
authorized_collection.insert_one(name: 'baNG')
|
951
|
+
end
|
952
|
+
|
953
|
+
it 'does not apply the collation' do
|
954
|
+
expect(result.written_count).to eq(0)
|
955
|
+
end
|
956
|
+
end
|
566
957
|
end
|
567
958
|
|
568
959
|
describe '#update_one' do
|
@@ -675,5 +1066,60 @@ describe Mongo::Collection::View::Writable do
|
|
675
1066
|
expect(updated).to be_empty
|
676
1067
|
end
|
677
1068
|
end
|
1069
|
+
|
1070
|
+
context 'when there is a collation specified' do
|
1071
|
+
|
1072
|
+
let(:selector) do
|
1073
|
+
{ name: 'BANG' }
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
let(:result) do
|
1077
|
+
view.update_one({ '$set' => { other: 'doink' } }, options)
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
before do
|
1081
|
+
authorized_collection.insert_one(name: 'bang')
|
1082
|
+
end
|
1083
|
+
|
1084
|
+
let(:options) do
|
1085
|
+
{ collation: { locale: 'en_US', strength: 2 } }
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
context 'when the server selected supports collations', if: collation_enabled? do
|
1089
|
+
|
1090
|
+
it 'applies the collation' do
|
1091
|
+
expect(result.written_count).to eq(1)
|
1092
|
+
expect(authorized_collection.find(other: 'doink').to_a.size).to eq(1)
|
1093
|
+
end
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
context 'when the server selected does not support collations', unless: collation_enabled? do
|
1097
|
+
|
1098
|
+
it 'raises an exception' do
|
1099
|
+
expect {
|
1100
|
+
result
|
1101
|
+
}.to raise_exception(Mongo::Error::UnsupportedCollation)
|
1102
|
+
end
|
1103
|
+
end
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
context 'when a collation is not specified' do
|
1107
|
+
|
1108
|
+
let(:selector) do
|
1109
|
+
{ name: 'BANG' }
|
1110
|
+
end
|
1111
|
+
|
1112
|
+
let(:result) do
|
1113
|
+
view.update_one('$set' => { other: 'doink' })
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
before do
|
1117
|
+
authorized_collection.insert_one(name: 'bang')
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
it 'does not apply the collation' do
|
1121
|
+
expect(result.written_count).to eq(0)
|
1122
|
+
end
|
1123
|
+
end
|
678
1124
|
end
|
679
1125
|
end
|