mongo 2.4.0.rc0 → 2.4.0.rc1

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.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -2
  4. data/lib/mongo/bulk_write/validatable.rb +3 -1
  5. data/lib/mongo/client.rb +30 -3
  6. data/lib/mongo/cluster/app_metadata.rb +7 -2
  7. data/lib/mongo/collection.rb +3 -1
  8. data/lib/mongo/collection/view.rb +3 -1
  9. data/lib/mongo/collection/view/aggregation.rb +3 -1
  10. data/lib/mongo/collection/view/builder/find_command.rb +20 -5
  11. data/lib/mongo/collection/view/map_reduce.rb +3 -1
  12. data/lib/mongo/collection/view/writable.rb +12 -2
  13. data/lib/mongo/cursor/builder/get_more_command.rb +3 -2
  14. data/lib/mongo/error/closed_stream.rb +1 -1
  15. data/lib/mongo/error/invalid_server_preference.rb +1 -1
  16. data/lib/mongo/index/view.rb +3 -1
  17. data/lib/mongo/operation/write/bulk/mergable.rb +1 -1
  18. data/lib/mongo/operation/write/create_index.rb +1 -1
  19. data/lib/mongo/operation/write/delete.rb +1 -1
  20. data/lib/mongo/operation/write/update.rb +1 -1
  21. data/lib/mongo/protocol/delete.rb +4 -1
  22. data/lib/mongo/protocol/get_more.rb +4 -1
  23. data/lib/mongo/protocol/insert.rb +7 -3
  24. data/lib/mongo/protocol/kill_cursors.rb +4 -1
  25. data/lib/mongo/protocol/message.rb +5 -1
  26. data/lib/mongo/protocol/query.rb +11 -4
  27. data/lib/mongo/protocol/update.rb +4 -1
  28. data/lib/mongo/server/connectable.rb +8 -2
  29. data/lib/mongo/server/connection_pool.rb +3 -1
  30. data/lib/mongo/server/monitor.rb +1 -0
  31. data/lib/mongo/socket.rb +16 -8
  32. data/lib/mongo/socket/ssl.rb +24 -9
  33. data/lib/mongo/uri.rb +6 -6
  34. data/lib/mongo/version.rb +1 -1
  35. data/mongo.gemspec +1 -1
  36. data/spec/mongo/bulk_write_spec.rb +117 -0
  37. data/spec/mongo/collection/view/aggregation_spec.rb +26 -0
  38. data/spec/mongo/collection/view/builder/find_command_spec.rb +244 -2
  39. data/spec/mongo/collection/view/map_reduce_spec.rb +13 -0
  40. data/spec/mongo/collection/view/readable_spec.rb +26 -0
  41. data/spec/mongo/collection/view/writable_spec.rb +104 -0
  42. data/spec/mongo/collection/view_spec.rb +13 -0
  43. data/spec/mongo/collection_spec.rb +226 -7
  44. data/spec/mongo/crud_spec.rb +5 -5
  45. data/spec/mongo/index/view_spec.rb +53 -0
  46. data/spec/mongo/server/connection_spec.rb +45 -26
  47. data/spec/mongo/socket/ssl_spec.rb +358 -22
  48. data/spec/spec_helper.rb +4 -0
  49. data/spec/support/authorization.rb +3 -3
  50. data/spec/support/certificates/client_cert.pem +21 -0
  51. data/spec/support/certificates/client_key.pem +28 -0
  52. data/spec/support/certificates/client_key_encrypted.pem +30 -0
  53. data/spec/support/crud.rb +67 -22
  54. data/spec/support/crud/read.rb +18 -36
  55. data/spec/support/crud/write.rb +0 -44
  56. data/spec/support/crud_tests/read/aggregate-collation.yml +17 -0
  57. data/spec/support/crud_tests/read/aggregate-out.yml +28 -0
  58. data/spec/support/crud_tests/read/aggregate.yml +1 -35
  59. data/spec/support/crud_tests/read/count-collation.yml +15 -0
  60. data/spec/support/crud_tests/read/count.yml +3 -15
  61. data/spec/support/crud_tests/read/distinct-collation.yml +17 -0
  62. data/spec/support/crud_tests/read/distinct.yml +1 -14
  63. data/spec/support/crud_tests/read/find-collation.yml +15 -0
  64. data/spec/support/crud_tests/read/find.yml +1 -12
  65. data/spec/support/crud_tests/write/deleteMany-collation.yml +22 -0
  66. data/spec/support/crud_tests/write/deleteMany.yml +1 -23
  67. data/spec/support/crud_tests/write/deleteOne-collation.yml +22 -0
  68. data/spec/support/crud_tests/write/deleteOne.yml +1 -21
  69. data/spec/support/crud_tests/write/findOneAndDelete-collation.yml +23 -0
  70. data/spec/support/crud_tests/write/findOneAndDelete.yml +2 -28
  71. data/spec/support/crud_tests/write/findOneAndReplace-collation.yml +24 -0
  72. data/spec/support/crud_tests/write/findOneAndReplace-upsert.yml +47 -0
  73. data/spec/support/crud_tests/write/findOneAndReplace.yml +13 -53
  74. data/spec/support/crud_tests/write/findOneAndUpdate-collation.yml +27 -0
  75. data/spec/support/crud_tests/write/findOneAndUpdate.yml +8 -51
  76. data/spec/support/crud_tests/write/insertMany.yml +1 -2
  77. data/spec/support/crud_tests/write/insertOne.yml +1 -2
  78. data/spec/support/crud_tests/write/replaceOne-collation.yml +23 -0
  79. data/spec/support/crud_tests/write/replaceOne-upsert.yml +48 -0
  80. data/spec/support/crud_tests/write/replaceOne.yml +11 -45
  81. data/spec/support/crud_tests/write/updateMany-collation.yml +27 -0
  82. data/spec/support/crud_tests/write/updateMany.yml +10 -42
  83. data/spec/support/crud_tests/write/updateOne-collation.yml +24 -0
  84. data/spec/support/crud_tests/write/updateOne.yml +7 -33
  85. data/spec/support/sdam/rs/new_primary_new_setversion.yml +1 -1
  86. data/spec/support/sdam/rs/null_election_id.yml +1 -0
  87. data/spec/support/sdam/rs/primary_disconnect_electionid.yml +2 -3
  88. data/spec/support/sdam/rs/primary_disconnect_setversion.yml +1 -2
  89. data/spec/support/sdam/single/direct_connection_rsarbiter.yml +1 -1
  90. data/spec/support/sdam/single/direct_connection_rsprimary.yml +1 -1
  91. data/spec/support/sdam/single/direct_connection_rssecondary.yml +1 -1
  92. metadata +40 -4
  93. metadata.gz.sig +0 -0
@@ -150,14 +150,256 @@ describe Mongo::Collection::View::Builder::FindCommand do
150
150
  end
151
151
  end
152
152
 
153
- context 'when limit is negative' do
153
+
154
+ context 'when there is a limit' do
155
+
156
+ let(:filter) do
157
+ { 'name' => 'test' }
158
+ end
159
+
160
+ context 'when limit is 0' do
161
+
162
+ context 'when batch_size is also 0' do
163
+
164
+ let(:options) do
165
+ { limit: 0, batch_size: 0 }
166
+ end
167
+
168
+ it 'does not set the singleBatch' do
169
+ expect(selector['singleBatch']).to be nil
170
+ end
171
+
172
+ it 'does not set the limit' do
173
+ expect(selector['limit']).to be nil
174
+ end
175
+
176
+ it 'does not set the batch size' do
177
+ expect(selector['batchSize']).to be nil
178
+ end
179
+ end
180
+
181
+ context 'when batch_size is not set' do
182
+
183
+ let(:options) do
184
+ { limit: 0 }
185
+ end
186
+
187
+ it 'does not set the singleBatch' do
188
+ expect(selector['singleBatch']).to be nil
189
+ end
190
+
191
+ it 'does not set the limit' do
192
+ expect(selector['limit']).to be nil
193
+ end
194
+
195
+ it 'does not set the batch size' do
196
+ expect(selector['batchSize']).to be nil
197
+ end
198
+ end
199
+ end
200
+
201
+ context 'when the limit is negative' do
202
+
203
+ context 'when there is a batch_size' do
204
+
205
+ context 'when the batch_size is positive' do
206
+
207
+ let(:options) do
208
+ { limit: -1, batch_size: 3 }
209
+ end
210
+
211
+ it 'sets single batch to true' do
212
+ expect(selector['singleBatch']).to be true
213
+ end
214
+
215
+ it 'converts the limit to a positive value' do
216
+ expect(selector['limit']).to be(options[:limit].abs)
217
+ end
218
+
219
+ it 'sets the batch size' do
220
+ expect(selector['batchSize']).to be(options[:batch_size])
221
+ end
222
+ end
223
+
224
+ context 'when the batch_size is negative' do
225
+
226
+ let(:options) do
227
+ { limit: -1, batch_size: -3 }
228
+ end
229
+
230
+ it 'sets single batch to true' do
231
+ expect(selector['singleBatch']).to be true
232
+ end
233
+
234
+ it 'converts the limit to a positive value' do
235
+ expect(selector['limit']).to be(options[:limit].abs)
236
+ end
237
+
238
+ it 'sets the batch size to the limit' do
239
+ expect(selector['batchSize']).to be(options[:limit].abs)
240
+ end
241
+ end
242
+ end
243
+
244
+ context 'when there is not a batch_size' do
245
+
246
+ let(:options) do
247
+ { limit: -5 }
248
+ end
249
+
250
+ it 'sets single batch to true' do
251
+ expect(selector['singleBatch']).to be true
252
+ end
253
+
254
+ it 'converts the limit to a positive value' do
255
+ expect(selector['limit']).to be(options[:limit].abs)
256
+ end
257
+
258
+ it 'does not set the batch size' do
259
+ expect(selector['batchSize']).to be_nil
260
+ end
261
+ end
262
+ end
263
+
264
+ context 'when the limit is positive' do
265
+
266
+ context 'when there is a batch_size' do
267
+
268
+ context 'when the batch_size is positive' do
269
+
270
+ let(:options) do
271
+ { limit: 5, batch_size: 3 }
272
+ end
273
+
274
+ it 'does not set singleBatch' do
275
+ expect(selector['singleBatch']).to be nil
276
+ end
277
+
278
+ it 'sets the limit' do
279
+ expect(selector['limit']).to be(options[:limit])
280
+ end
281
+
282
+ it 'sets the batch size' do
283
+ expect(selector['batchSize']).to be(options[:batch_size])
284
+ end
285
+ end
286
+
287
+ context 'when the batch_size is negative' do
288
+
289
+ let(:options) do
290
+ { limit: 5, batch_size: -3 }
291
+ end
292
+
293
+ it 'sets the singleBatch' do
294
+ expect(selector['singleBatch']).to be true
295
+ end
296
+
297
+ it 'sets the limit' do
298
+ expect(selector['limit']).to be(options[:limit])
299
+ end
300
+
301
+ it 'sets the batch size to a positive value' do
302
+ expect(selector['batchSize']).to be(options[:batch_size].abs)
303
+ end
304
+ end
305
+ end
306
+
307
+ context 'when there is not a batch_size' do
308
+
309
+ let(:options) do
310
+ { limit: 5 }
311
+ end
312
+
313
+ it 'does not set the singleBatch' do
314
+ expect(selector['singleBatch']).to be nil
315
+ end
316
+
317
+ it 'sets the limit' do
318
+ expect(selector['limit']).to be(options[:limit])
319
+ end
320
+
321
+ it 'does not set the batch size' do
322
+ expect(selector['batchSize']).to be nil
323
+ end
324
+ end
325
+ end
326
+ end
327
+
328
+ context 'when there is a batch_size' do
329
+
330
+ let(:filter) do
331
+ { 'name' => 'test' }
332
+ end
333
+
334
+ context 'when there is no limit' do
335
+
336
+ context 'when the batch_size is positive' do
337
+
338
+ let(:options) do
339
+ { batch_size: 3 }
340
+ end
341
+
342
+ it 'does not set the singleBatch' do
343
+ expect(selector['singleBatch']).to be nil
344
+ end
345
+
346
+ it 'does not set the limit' do
347
+ expect(selector['limit']).to be nil
348
+ end
349
+
350
+ it 'sets the batch size' do
351
+ expect(selector['batchSize']).to be(options[:batch_size])
352
+ end
353
+ end
354
+
355
+ context 'when the batch_size is negative' do
356
+
357
+ let(:options) do
358
+ { batch_size: -3 }
359
+ end
360
+
361
+ it 'sets the singleBatch' do
362
+ expect(selector['singleBatch']).to be true
363
+ end
364
+
365
+ it 'does not set the limit' do
366
+ expect(selector['limit']).to be nil
367
+ end
368
+
369
+ it 'sets the batch size to a positive value' do
370
+ expect(selector['batchSize']).to be(options[:batch_size].abs)
371
+ end
372
+ end
373
+
374
+ context 'when batch_size is 0' do
375
+
376
+ let(:options) do
377
+ { batch_size: 0 }
378
+ end
379
+
380
+ it 'does not set the singleBatch' do
381
+ expect(selector['singleBatch']).to be nil
382
+ end
383
+
384
+ it 'does not set the limit' do
385
+ expect(selector['limit']).to be nil
386
+ end
387
+
388
+ it 'does not set the batch size' do
389
+ expect(selector['batchSize']).to be nil
390
+ end
391
+ end
392
+ end
393
+ end
394
+
395
+ context 'when limit and batch_size are negative' do
154
396
 
155
397
  let(:filter) do
156
398
  { 'name' => 'test' }
157
399
  end
158
400
 
159
401
  let(:options) do
160
- { limit: -1 }
402
+ { limit: -1, batch_size: -3 }
161
403
  end
162
404
 
163
405
  it 'sets single batch to true' do
@@ -528,6 +528,19 @@ describe Mongo::Collection::View::MapReduce do
528
528
  map_reduce.to_a
529
529
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
530
530
  end
531
+
532
+ context 'when a String key is used' do
533
+
534
+ let(:options) do
535
+ { 'collation' => { locale: 'en_US', strength: 2 } }
536
+ end
537
+
538
+ it 'raises an exception' do
539
+ expect {
540
+ map_reduce.to_a
541
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
542
+ end
543
+ end
531
544
  end
532
545
  end
533
546
  end
@@ -438,6 +438,19 @@ describe Mongo::Collection::View::Readable do
438
438
  result
439
439
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
440
440
  end
441
+
442
+ context 'when a String key is used' do
443
+
444
+ let(:count_options) do
445
+ { 'collation' => { locale: 'en_US', strength: 2 } }
446
+ end
447
+
448
+ it 'raises an exception' do
449
+ expect {
450
+ result
451
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
452
+ end
453
+ end
441
454
  end
442
455
  end
443
456
  end
@@ -713,6 +726,19 @@ describe Mongo::Collection::View::Readable do
713
726
  result
714
727
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
715
728
  end
729
+
730
+ context 'when a String key is used' do
731
+
732
+ let(:distinct_options) do
733
+ { 'collation' => { locale: 'en_US', strength: 2 } }
734
+ end
735
+
736
+ it 'raises an exception' do
737
+ expect {
738
+ result
739
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
740
+ end
741
+ end
716
742
  end
717
743
  end
718
744
 
@@ -108,6 +108,19 @@ describe Mongo::Collection::View::Writable do
108
108
  result
109
109
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
110
110
  end
111
+
112
+ context 'when a String key is used' do
113
+
114
+ let(:options) do
115
+ { 'collation' => { locale: 'en_US', strength: 2 } }
116
+ end
117
+
118
+ it 'raises an exception' do
119
+ expect {
120
+ result
121
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
122
+ end
123
+ end
111
124
  end
112
125
  end
113
126
 
@@ -241,6 +254,19 @@ describe Mongo::Collection::View::Writable do
241
254
  result
242
255
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
243
256
  end
257
+
258
+ context 'when a String key is used' do
259
+
260
+ let(:options) do
261
+ { 'collation' => { locale: 'en_US', strength: 2 } }
262
+ end
263
+
264
+ it 'raises an exception' do
265
+ expect {
266
+ result
267
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
268
+ end
269
+ end
244
270
  end
245
271
  end
246
272
 
@@ -389,6 +415,19 @@ describe Mongo::Collection::View::Writable do
389
415
  result
390
416
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
391
417
  end
418
+
419
+ context 'when a String key is used' do
420
+
421
+ let(:options) do
422
+ { 'collation' => { locale: 'en_US', strength: 2 } }
423
+ end
424
+
425
+ it 'raises an exception' do
426
+ expect {
427
+ result
428
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
429
+ end
430
+ end
392
431
  end
393
432
  end
394
433
 
@@ -497,6 +536,19 @@ describe Mongo::Collection::View::Writable do
497
536
  result
498
537
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
499
538
  end
539
+
540
+ context 'when a String key is used' do
541
+
542
+ let(:options) do
543
+ { 'collation' => { locale: 'en_US', strength: 2 } }
544
+ end
545
+
546
+ it 'raises an exception' do
547
+ expect {
548
+ result
549
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
550
+ end
551
+ end
500
552
  end
501
553
  end
502
554
 
@@ -595,6 +647,19 @@ describe Mongo::Collection::View::Writable do
595
647
  result
596
648
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
597
649
  end
650
+
651
+ context 'when a String key is used' do
652
+
653
+ let(:options) do
654
+ { 'collation' => { locale: 'en_US', strength: 2 } }
655
+ end
656
+
657
+ it 'raises an exception' do
658
+ expect {
659
+ result
660
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
661
+ end
662
+ end
598
663
  end
599
664
  end
600
665
 
@@ -761,6 +826,19 @@ describe Mongo::Collection::View::Writable do
761
826
  result
762
827
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
763
828
  end
829
+
830
+ context 'when a String key is used' do
831
+
832
+ let(:options) do
833
+ { 'collation' => { locale: 'en_US', strength: 2 } }
834
+ end
835
+
836
+ it 'raises an exception' do
837
+ expect {
838
+ result
839
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
840
+ end
841
+ end
764
842
  end
765
843
  end
766
844
 
@@ -932,6 +1010,19 @@ describe Mongo::Collection::View::Writable do
932
1010
  result
933
1011
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
934
1012
  end
1013
+
1014
+ context 'when a String key is used' do
1015
+
1016
+ let(:options) do
1017
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1018
+ end
1019
+
1020
+ it 'raises an exception' do
1021
+ expect {
1022
+ result
1023
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1024
+ end
1025
+ end
935
1026
  end
936
1027
  end
937
1028
 
@@ -1100,6 +1191,19 @@ describe Mongo::Collection::View::Writable do
1100
1191
  result
1101
1192
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1102
1193
  end
1194
+
1195
+ context 'when a String key is used' do
1196
+
1197
+ let(:options) do
1198
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1199
+ end
1200
+
1201
+ it 'raises an exception' do
1202
+ expect {
1203
+ result
1204
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1205
+ end
1206
+ end
1103
1207
  end
1104
1208
  end
1105
1209