mongo 2.4.0.rc0 → 2.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -187,6 +187,19 @@ describe Mongo::Collection::View do
187
187
  result
188
188
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
189
189
  end
190
+
191
+ context 'when a String key is used' do
192
+
193
+ let(:options) do
194
+ { 'collation' => { locale: 'en_US', strength: 2 } }
195
+ end
196
+
197
+ it 'raises an exception' do
198
+ expect {
199
+ result
200
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
201
+ end
202
+ end
190
203
  end
191
204
  end
192
205
 
@@ -451,7 +451,7 @@ describe Mongo::Collection do
451
451
 
452
452
  shared_examples 'a collection command with a collation option' do
453
453
 
454
- let!(:response) do
454
+ let(:response) do
455
455
  collection.create
456
456
  end
457
457
 
@@ -474,10 +474,12 @@ describe Mongo::Collection do
474
474
  end
475
475
 
476
476
  it 'sets the collection with a collation' do
477
+ response
477
478
  expect(collection_info['options']['collation']['locale']).to eq('fr')
478
479
  end
479
480
 
480
481
  it 'creates the collection in the database' do
482
+ response
481
483
  expect(database.collection_names).to include('specs')
482
484
  end
483
485
  end
@@ -489,6 +491,19 @@ describe Mongo::Collection do
489
491
  response
490
492
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
491
493
  end
494
+
495
+ context 'when a String key is used' do
496
+
497
+ let(:options) do
498
+ { 'collation' => { locale: 'fr' } }
499
+ end
500
+
501
+ it 'raises an exception' do
502
+ expect {
503
+ response
504
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
505
+ end
506
+ end
492
507
  end
493
508
  end
494
509
 
@@ -498,9 +513,7 @@ describe Mongo::Collection do
498
513
  described_class.new(database, :specs, options)
499
514
  end
500
515
 
501
- context 'when the server supports collation', if: collation_enabled? do
502
- it_behaves_like 'a collection command with a collation option'
503
- end
516
+ it_behaves_like 'a collection command with a collation option'
504
517
  end
505
518
 
506
519
  context 'when instantiating a collection through the database' do
@@ -509,9 +522,7 @@ describe Mongo::Collection do
509
522
  authorized_client[:specs, options]
510
523
  end
511
524
 
512
- context 'when the server supports collation', if: collation_enabled? do
513
- it_behaves_like 'a collection command with a collation option'
514
- end
525
+ it_behaves_like 'a collection command with a collation option'
515
526
  end
516
527
  end
517
528
  end
@@ -1182,6 +1193,19 @@ describe Mongo::Collection do
1182
1193
  result
1183
1194
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1184
1195
  end
1196
+
1197
+ context 'when a String key is used' do
1198
+
1199
+ let(:options) do
1200
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1201
+ end
1202
+
1203
+ it 'raises an exception' do
1204
+ expect {
1205
+ result
1206
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1207
+ end
1208
+ end
1185
1209
  end
1186
1210
  end
1187
1211
  end
@@ -1239,6 +1263,19 @@ describe Mongo::Collection do
1239
1263
  result
1240
1264
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1241
1265
  end
1266
+
1267
+ context 'when a String key is used' do
1268
+
1269
+ let(:options) do
1270
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1271
+ end
1272
+
1273
+ it 'raises an exception' do
1274
+ expect {
1275
+ result
1276
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1277
+ end
1278
+ end
1242
1279
  end
1243
1280
  end
1244
1281
  end
@@ -1301,6 +1338,19 @@ describe Mongo::Collection do
1301
1338
  result
1302
1339
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1303
1340
  end
1341
+
1342
+ context 'when a String key is used' do
1343
+
1344
+ let(:options) do
1345
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1346
+ end
1347
+
1348
+ it 'raises an exception' do
1349
+ expect {
1350
+ result
1351
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1352
+ end
1353
+ end
1304
1354
  end
1305
1355
  end
1306
1356
 
@@ -1414,6 +1464,19 @@ describe Mongo::Collection do
1414
1464
  result
1415
1465
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1416
1466
  end
1467
+
1468
+ context 'when a String key is used' do
1469
+
1470
+ let(:options) do
1471
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1472
+ end
1473
+
1474
+ it 'raises an exception' do
1475
+ expect {
1476
+ result
1477
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1478
+ end
1479
+ end
1417
1480
  end
1418
1481
  end
1419
1482
 
@@ -1424,6 +1487,19 @@ describe Mongo::Collection do
1424
1487
  result
1425
1488
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1426
1489
  end
1490
+
1491
+ context 'when a String key is used' do
1492
+
1493
+ let(:options) do
1494
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1495
+ end
1496
+
1497
+ it 'raises an exception' do
1498
+ expect {
1499
+ result
1500
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1501
+ end
1502
+ end
1427
1503
  end
1428
1504
  end
1429
1505
 
@@ -1526,6 +1602,19 @@ describe Mongo::Collection do
1526
1602
  result
1527
1603
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1528
1604
  end
1605
+
1606
+ context 'when a String key is used' do
1607
+
1608
+ let(:options) do
1609
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1610
+ end
1611
+
1612
+ it 'raises an exception' do
1613
+ expect {
1614
+ result
1615
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1616
+ end
1617
+ end
1529
1618
  end
1530
1619
  end
1531
1620
 
@@ -1536,6 +1625,19 @@ describe Mongo::Collection do
1536
1625
  result
1537
1626
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1538
1627
  end
1628
+
1629
+ context 'when a String key is used' do
1630
+
1631
+ let(:options) do
1632
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1633
+ end
1634
+
1635
+ it 'raises an exception' do
1636
+ expect {
1637
+ result
1638
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1639
+ end
1640
+ end
1539
1641
  end
1540
1642
  end
1541
1643
 
@@ -1882,6 +1984,19 @@ describe Mongo::Collection do
1882
1984
  result
1883
1985
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1884
1986
  end
1987
+
1988
+ context 'when a String key is used' do
1989
+
1990
+ let(:options) do
1991
+ { 'collation' => { locale: 'en_US', strength: 2 } }
1992
+ end
1993
+
1994
+ it 'raises an exception' do
1995
+ expect {
1996
+ result
1997
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
1998
+ end
1999
+ end
1885
2000
  end
1886
2001
  end
1887
2002
 
@@ -1892,6 +2007,19 @@ describe Mongo::Collection do
1892
2007
  result
1893
2008
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
1894
2009
  end
2010
+
2011
+ context 'when a String key is used' do
2012
+
2013
+ let(:options) do
2014
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2015
+ end
2016
+
2017
+ it 'raises an exception' do
2018
+ expect {
2019
+ result
2020
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2021
+ end
2022
+ end
1895
2023
  end
1896
2024
  end
1897
2025
 
@@ -2116,6 +2244,19 @@ describe Mongo::Collection do
2116
2244
  result
2117
2245
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2118
2246
  end
2247
+
2248
+ context 'when a String key is used' do
2249
+
2250
+ let(:options) do
2251
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2252
+ end
2253
+
2254
+ it 'raises an exception' do
2255
+ expect {
2256
+ result
2257
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2258
+ end
2259
+ end
2119
2260
  end
2120
2261
  end
2121
2262
 
@@ -2126,6 +2267,19 @@ describe Mongo::Collection do
2126
2267
  result
2127
2268
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2128
2269
  end
2270
+
2271
+ context 'when a String key is used' do
2272
+
2273
+ let(:options) do
2274
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2275
+ end
2276
+
2277
+ it 'raises an exception' do
2278
+ expect {
2279
+ result
2280
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2281
+ end
2282
+ end
2129
2283
  end
2130
2284
  end
2131
2285
 
@@ -2349,6 +2503,19 @@ describe Mongo::Collection do
2349
2503
  result
2350
2504
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2351
2505
  end
2506
+
2507
+ context 'when a String key is used' do
2508
+
2509
+ let(:options) do
2510
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2511
+ end
2512
+
2513
+ it 'raises an exception' do
2514
+ expect {
2515
+ result
2516
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2517
+ end
2518
+ end
2352
2519
  end
2353
2520
  end
2354
2521
 
@@ -2359,6 +2526,19 @@ describe Mongo::Collection do
2359
2526
  result
2360
2527
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2361
2528
  end
2529
+
2530
+ context 'when a String key is used' do
2531
+
2532
+ let(:options) do
2533
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2534
+ end
2535
+
2536
+ it 'raises an exception' do
2537
+ expect {
2538
+ result
2539
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2540
+ end
2541
+ end
2362
2542
  end
2363
2543
  end
2364
2544
 
@@ -2535,6 +2715,19 @@ describe Mongo::Collection do
2535
2715
  result
2536
2716
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2537
2717
  end
2718
+
2719
+ context 'when a String key is used' do
2720
+
2721
+ let(:options) do
2722
+ { 'collation' => { locale: 'en_US', strength: 2 } }
2723
+ end
2724
+
2725
+ it 'raises an exception' do
2726
+ expect {
2727
+ result
2728
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
2729
+ end
2730
+ end
2538
2731
  end
2539
2732
  end
2540
2733
 
@@ -2831,6 +3024,19 @@ describe Mongo::Collection do
2831
3024
  result
2832
3025
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
2833
3026
  end
3027
+
3028
+ context 'when a String key is used' do
3029
+
3030
+ let(:options) do
3031
+ { 'collation' => { locale: 'en_US', strength: 2 } }
3032
+ end
3033
+
3034
+ it 'raises an exception' do
3035
+ expect {
3036
+ result
3037
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
3038
+ end
3039
+ end
2834
3040
  end
2835
3041
  end
2836
3042
 
@@ -3101,6 +3307,19 @@ describe Mongo::Collection do
3101
3307
  result
3102
3308
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
3103
3309
  end
3310
+
3311
+ context 'when a String key is used' do
3312
+
3313
+ let(:options) do
3314
+ { 'collation' => { locale: 'en_US', strength: 2 } }
3315
+ end
3316
+
3317
+ it 'raises an exception' do
3318
+ expect {
3319
+ result
3320
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
3321
+ end
3322
+ end
3104
3323
  end
3105
3324
  end
3106
3325
 
@@ -24,13 +24,13 @@ describe 'CRUD' do
24
24
  test.run(authorized_collection)
25
25
  end
26
26
 
27
- it "returns the correct result" do
28
- skip 'Test cannot be run on this server version' unless test.feature_enabled?(authorized_collection)
29
- expect(results).to eq(test.result)
27
+ it 'returns the correct result' do
28
+ skip 'Test cannot be run on this server version' unless spec.server_version_satisfied?(authorized_client)
29
+ expect(results).to match_operation_result(test)
30
30
  end
31
31
 
32
- it 'has the correct data in the collection' do
33
- skip 'Test cannot be run on this server version' unless test.feature_enabled?(authorized_collection)
32
+ it 'has the correct data in the collection', if: test.outcome_collection_data do
33
+ skip 'Test cannot be run on this server version' unless spec.server_version_satisfied?(authorized_client)
34
34
  results
35
35
  expect(authorized_collection.find.to_a).to match_collection_data(test)
36
36
  end
@@ -224,6 +224,23 @@ describe Mongo::Index::View do
224
224
  result
225
225
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
226
226
  end
227
+
228
+ context 'when a String key is used' do
229
+
230
+ let(:result) do
231
+ view.create_many(
232
+ { key: { random: 1 },
233
+ unique: true,
234
+ 'collation' => { locale: 'en_US', strength: 2 } }
235
+ )
236
+ end
237
+
238
+ it 'raises an exception' do
239
+ expect {
240
+ result
241
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
242
+ end
243
+ end
227
244
  end
228
245
  end
229
246
 
@@ -337,6 +354,23 @@ describe Mongo::Index::View do
337
354
  result
338
355
  }.to raise_exception(Mongo::Error::UnsupportedCollation)
339
356
  end
357
+
358
+ context 'when a String key is used' do
359
+
360
+ let(:result) do
361
+ view.create_many([
362
+ { key: { random: 1 },
363
+ unique: true,
364
+ 'collation' => { locale: 'en_US', strength: 2 }},
365
+ ])
366
+ end
367
+
368
+ it 'raises an exception' do
369
+ expect {
370
+ result
371
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
372
+ end
373
+ end
340
374
  end
341
375
  end
342
376
 
@@ -477,6 +511,25 @@ describe Mongo::Index::View do
477
511
  end
478
512
  end
479
513
  end
514
+
515
+ context 'when the index is created on an subdocument field' do
516
+
517
+ let(:spec) do
518
+ { 'sub_document.random' => 1 }
519
+ end
520
+
521
+ let(:result) do
522
+ view.create_one(spec, unique: true)
523
+ end
524
+
525
+ after do
526
+ begin; view.drop_one('sub_document.random_1'); rescue; end
527
+ end
528
+
529
+ it 'returns ok' do
530
+ expect(result).to be_successful
531
+ end
532
+ end
480
533
  end
481
534
 
482
535
  context 'when index creation fails' do