mongoid 7.0.6 → 7.0.12

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 (91) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +1 -1
  5. data/Rakefile +14 -5
  6. data/lib/mongoid.rb +1 -1
  7. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  8. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  9. data/lib/mongoid/association/proxy.rb +1 -1
  10. data/lib/mongoid/atomic.rb +13 -3
  11. data/lib/mongoid/clients/sessions.rb +20 -4
  12. data/lib/mongoid/criteria.rb +7 -1
  13. data/lib/mongoid/criteria/modifiable.rb +2 -1
  14. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  15. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  16. data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
  17. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  18. data/lib/mongoid/document.rb +3 -2
  19. data/lib/mongoid/extensions/hash.rb +4 -2
  20. data/lib/mongoid/extensions/regexp.rb +1 -1
  21. data/lib/mongoid/fields.rb +2 -1
  22. data/lib/mongoid/interceptable.rb +3 -1
  23. data/lib/mongoid/matchable/regexp.rb +2 -2
  24. data/lib/mongoid/persistable/pushable.rb +11 -2
  25. data/lib/mongoid/persistence_context.rb +6 -6
  26. data/lib/mongoid/query_cache.rb +61 -18
  27. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  28. data/lib/mongoid/version.rb +1 -1
  29. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  30. data/spec/app/models/customer.rb +11 -0
  31. data/spec/app/models/customer_address.rb +12 -0
  32. data/spec/app/models/delegating_patient.rb +16 -0
  33. data/spec/integration/app_spec.rb +192 -0
  34. data/spec/integration/associations/embedded_spec.rb +62 -0
  35. data/spec/integration/callbacks_models.rb +49 -0
  36. data/spec/integration/callbacks_spec.rb +216 -0
  37. data/spec/integration/criteria/date_field_spec.rb +41 -0
  38. data/spec/integration/document_spec.rb +22 -0
  39. data/spec/lite_spec_helper.rb +12 -4
  40. data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +50 -0
  41. data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
  42. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  43. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  44. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
  45. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  46. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  47. data/spec/mongoid/atomic/paths_spec.rb +41 -0
  48. data/spec/mongoid/clients/options_spec.rb +4 -4
  49. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  50. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  51. data/spec/mongoid/clients_spec.rb +2 -2
  52. data/spec/mongoid/contextual/atomic_spec.rb +20 -10
  53. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  54. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  55. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  56. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  57. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  58. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  59. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  60. data/spec/mongoid/criteria_spec.rb +4 -2
  61. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  62. data/spec/mongoid/indexable_spec.rb +6 -4
  63. data/spec/mongoid/matchable/default_spec.rb +1 -1
  64. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  65. data/spec/mongoid/matchable_spec.rb +2 -2
  66. data/spec/mongoid/persistable/pushable_spec.rb +55 -1
  67. data/spec/mongoid/query_cache_spec.rb +77 -9
  68. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  69. data/spec/mongoid/scopable_spec.rb +2 -1
  70. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  71. data/spec/mongoid/tasks/database_spec.rb +1 -1
  72. data/spec/shared/LICENSE +20 -0
  73. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  74. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  75. data/spec/shared/lib/mrss/constraints.rb +330 -0
  76. data/spec/shared/lib/mrss/docker_runner.rb +262 -0
  77. data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
  78. data/spec/shared/lib/mrss/server_version_registry.rb +69 -0
  79. data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
  80. data/spec/shared/share/Dockerfile.erb +229 -0
  81. data/spec/shared/shlib/distro.sh +73 -0
  82. data/spec/shared/shlib/server.sh +270 -0
  83. data/spec/shared/shlib/set_env.sh +128 -0
  84. data/spec/spec_helper.rb +0 -31
  85. data/spec/support/child_process_helper.rb +76 -0
  86. data/spec/support/cluster_config.rb +3 -3
  87. data/spec/support/constraints.rb +201 -30
  88. data/spec/support/session_registry.rb +50 -0
  89. data/spec/support/spec_config.rb +12 -4
  90. metadata +510 -461
  91. metadata.gz.sig +2 -2
@@ -2904,7 +2904,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2904
2904
  expect(posts).to eq([ post_one ])
2905
2905
  end
2906
2906
 
2907
- context 'when providing a collation', if: collation_supported? do
2907
+ context 'when providing a collation' do
2908
+ min_server_version '3.4'
2908
2909
 
2909
2910
  let(:posts) do
2910
2911
  person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
@@ -265,5 +265,46 @@ describe Mongoid::Atomic::Paths do
265
265
  end
266
266
  end
267
267
  end
268
+
269
+ context "when the same class is embedded in multiple associations" do
270
+
271
+ let(:customer) do
272
+ Customer.new
273
+ end
274
+
275
+ context "assignment after saving" do
276
+
277
+ it "correctly sets the association for the embedded class" do
278
+ pending 'MONGOID-5039'
279
+
280
+ customer.home_address = CustomerAddress.new
281
+ customer.work_address = CustomerAddress.new
282
+
283
+ expect(customer.home_address.atomic_path).to eq("home_address")
284
+ expect(customer.work_address.atomic_path).to eq("work_address")
285
+
286
+ customer.save!
287
+
288
+ customer.home_address = CustomerAddress.new
289
+ customer.work_address = CustomerAddress.new
290
+
291
+ expect(customer.home_address.atomic_path).to eq("home_address")
292
+ expect(customer.work_address.atomic_path).to eq("work_address")
293
+ end
294
+ end
295
+
296
+ context "inverse assignment" do
297
+
298
+ it "correctly returns the path for each embedded class" do
299
+ pending 'MONGOID-5039'
300
+
301
+ customer.work_address = CustomerAddress.new
302
+ customer.work_address.addressable = customer
303
+
304
+ expect(customer.home_address.atomic_path).to eq("home_address")
305
+ expect(customer.work_address.atomic_path).to eq("work_address")
306
+ end
307
+ end
308
+ end
268
309
  end
269
310
  end
@@ -11,7 +11,7 @@ describe Mongoid::Clients::Options do
11
11
  Mongoid::Clients.clients.clear
12
12
  end
13
13
 
14
- describe '#with', if: non_legacy_server? do
14
+ describe '#with' do
15
15
 
16
16
  context 'when passing some options' do
17
17
 
@@ -72,7 +72,7 @@ describe Mongoid::Clients::Options do
72
72
  end
73
73
  end
74
74
 
75
- context 'when passing a block', if: testing_locally? do
75
+ context 'when passing a block' do
76
76
 
77
77
  let!(:connections_before) do
78
78
  Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
@@ -284,7 +284,7 @@ describe Mongoid::Clients::Options do
284
284
  end
285
285
  end
286
286
 
287
- describe '.with', if: non_legacy_server? do
287
+ describe '.with' do
288
288
 
289
289
  context 'when passing some options' do
290
290
 
@@ -362,7 +362,7 @@ describe Mongoid::Clients::Options do
362
362
  end
363
363
  end
364
364
 
365
- context 'when passing a block', if: testing_locally? do
365
+ context 'when passing a block' do
366
366
 
367
367
  let!(:connections_before) do
368
368
  test_model.mongo_client.database.command(serverStatus: 1).first['connections']['current']
@@ -40,7 +40,8 @@ describe Mongoid::Clients::Sessions do
40
40
 
41
41
  context 'when a session is used on a model class' do
42
42
 
43
- context 'when sessions are supported', if: sessions_supported? do
43
+ context 'when sessions are supported' do
44
+ min_server_version '3.6'
44
45
 
45
46
  around do |example|
46
47
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -169,7 +170,8 @@ describe Mongoid::Clients::Sessions do
169
170
  end
170
171
  end
171
172
 
172
- context 'when sessions are not supported', unless: sessions_supported? do
173
+ context 'when sessions are not supported' do
174
+ max_server_version '3.4'
173
175
 
174
176
  let!(:error) do
175
177
  e = nil
@@ -196,7 +198,8 @@ describe Mongoid::Clients::Sessions do
196
198
  end
197
199
  end
198
200
 
199
- context 'when sessions are supported', if: sessions_supported? do
201
+ context 'when sessions are supported' do
202
+ min_server_version '3.6'
200
203
 
201
204
  around do |example|
202
205
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -313,7 +316,8 @@ describe Mongoid::Clients::Sessions do
313
316
  end
314
317
  end
315
318
 
316
- context 'when sessions are not supported', unless: sessions_supported? do
319
+ context 'when sessions are not supported' do
320
+ max_server_version '3.4'
317
321
 
318
322
  let!(:error) do
319
323
  e = nil
@@ -52,7 +52,8 @@ describe Mongoid::Clients::Sessions do
52
52
 
53
53
  context 'when a transaction is used on a model class' do
54
54
 
55
- context 'when transactions are supported', if: testing_transactions? do
55
+ context 'when transactions are supported' do
56
+ require_transaction_support
56
57
 
57
58
  around do |example|
58
59
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -188,7 +189,10 @@ describe Mongoid::Clients::Sessions do
188
189
  end
189
190
  end
190
191
 
191
- context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
192
+ context 'when sessions are supported but transactions are not' do
193
+ min_server_version '3.6'
194
+ # Could also test 4.0 in sharded cluster
195
+ max_server_version '3.6'
192
196
 
193
197
  let!(:error) do
194
198
  e = nil
@@ -219,7 +223,8 @@ describe Mongoid::Clients::Sessions do
219
223
  end
220
224
  end
221
225
 
222
- context 'when transactions are supported', if: testing_transactions? do
226
+ context 'when transactions are supported' do
227
+ require_transaction_support
223
228
 
224
229
  around do |example|
225
230
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -342,16 +347,23 @@ describe Mongoid::Clients::Sessions do
342
347
  end
343
348
  end
344
349
 
345
- context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
350
+ context 'when sessions are supported but transactions are not' do
351
+ min_server_version '3.6'
352
+ # Could also test 4.0 in sharded cluster
353
+ max_server_version '3.6'
346
354
 
347
355
  around do |example|
348
356
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
349
357
  Mongoid::Clients.with_name(:other).command(create: :people)
350
- subscriber.clear_events!
351
- person.with(client: :other) do
352
- example.run
358
+
359
+ begin
360
+ subscriber.clear_events!
361
+ person.with(client: :other) do
362
+ example.run
363
+ end
364
+ ensure
365
+ Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
353
366
  end
354
- Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
355
367
  end
356
368
 
357
369
  let!(:error) do
@@ -725,7 +725,7 @@ describe Mongoid::Clients do
725
725
  end
726
726
  end
727
727
 
728
- describe ".store_in", if: non_legacy_server? do
728
+ describe ".store_in" do
729
729
 
730
730
  context "when provided a non hash" do
731
731
 
@@ -762,7 +762,7 @@ describe Mongoid::Clients do
762
762
  end
763
763
  end
764
764
 
765
- describe ".with", if: non_legacy_server? do
765
+ describe ".with" do
766
766
 
767
767
  context "when changing write concern options" do
768
768
 
@@ -74,7 +74,8 @@ describe Mongoid::Contextual::Atomic do
74
74
  end
75
75
  end
76
76
 
77
- context 'when the criteria has a collation', if: collation_supported? do
77
+ context 'when the criteria has a collation' do
78
+ min_server_version '3.4'
78
79
 
79
80
  let(:criteria) do
80
81
  Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
@@ -145,7 +146,8 @@ describe Mongoid::Contextual::Atomic do
145
146
  end
146
147
  end
147
148
 
148
- context 'when the criteria has a collation', if: collation_supported? do
149
+ context 'when the criteria has a collation' do
150
+ min_server_version '3.4'
149
151
 
150
152
  let!(:depeche_mode) do
151
153
  Band.create(members: [ "Dave" ], likes: 60)
@@ -224,7 +226,8 @@ describe Mongoid::Contextual::Atomic do
224
226
  end
225
227
  end
226
228
 
227
- context 'when the criteria has a collation', if: collation_supported? do
229
+ context 'when the criteria has a collation' do
230
+ min_server_version '3.4'
228
231
 
229
232
  let!(:depeche_mode) do
230
233
  Band.create(members: [ "Dave" ])
@@ -296,7 +299,8 @@ describe Mongoid::Contextual::Atomic do
296
299
  end
297
300
  end
298
301
 
299
- context 'when the criteria has a collation', if: collation_supported? do
302
+ context 'when the criteria has a collation' do
303
+ min_server_version '3.4'
300
304
 
301
305
  let!(:depeche_mode) do
302
306
  Band.create(members: [ "Dave" ])
@@ -350,7 +354,8 @@ describe Mongoid::Contextual::Atomic do
350
354
  expect(smiths.reload.members).to be_nil
351
355
  end
352
356
 
353
- context 'when the criteria has a collation', if: collation_supported? do
357
+ context 'when the criteria has a collation' do
358
+ min_server_version '3.4'
354
359
 
355
360
  let!(:depeche_mode) do
356
361
  Band.create(members: [ "Dave" ])
@@ -407,7 +412,8 @@ describe Mongoid::Contextual::Atomic do
407
412
  end
408
413
  end
409
414
 
410
- context 'when the criteria has a collation', if: collation_supported? do
415
+ context 'when the criteria has a collation' do
416
+ min_server_version '3.4'
411
417
 
412
418
  let!(:depeche_mode) do
413
419
  Band.create(members: [ "Dave", "Alan", "Fletch" ])
@@ -464,7 +470,8 @@ describe Mongoid::Contextual::Atomic do
464
470
  end
465
471
  end
466
472
 
467
- context 'when the criteria has a collation', if: collation_supported? do
473
+ context 'when the criteria has a collation' do
474
+ min_server_version '3.4'
468
475
 
469
476
  let!(:depeche_mode) do
470
477
  Band.create(members: [ "Dave" ])
@@ -529,7 +536,8 @@ describe Mongoid::Contextual::Atomic do
529
536
  end
530
537
  end
531
538
 
532
- context 'when the criteria has a collation', if: collation_supported? do
539
+ context 'when the criteria has a collation' do
540
+ min_server_version '3.4'
533
541
 
534
542
  let!(:depeche_mode) do
535
543
  Band.create(members: [ "Dave" ])
@@ -590,7 +598,8 @@ describe Mongoid::Contextual::Atomic do
590
598
  end
591
599
  end
592
600
 
593
- context 'when the criteria has a collation', if: collation_supported? do
601
+ context 'when the criteria has a collation' do
602
+ min_server_version '3.4'
594
603
 
595
604
  let!(:depeche_mode) do
596
605
  Band.create(members: [ "Dave" ])
@@ -749,7 +758,8 @@ describe Mongoid::Contextual::Atomic do
749
758
  end
750
759
  end
751
760
 
752
- context 'when the criteria has a collation', if: collation_supported? do
761
+ context 'when the criteria has a collation' do
762
+ min_server_version '3.4'
753
763
 
754
764
  let!(:depeche_mode) do
755
765
  Band.create(name: "Depeche Mode", years: 10)
@@ -46,8 +46,17 @@ describe Mongoid::Contextual::GeoNear do
46
46
  described_class.new(collection, criteria, [ 52, 13 ])
47
47
  end
48
48
 
49
- it "returns 0.0" do
50
- expect(geo_near.average_distance).to be_nil
49
+ let(:expected_value) do
50
+ if ClusterConfig.instance.fcv_ish == '4.0' && ClusterConfig.instance.topology == :sharded
51
+ # https://jira.mongodb.org/browse/SERVER-50074
52
+ 0.0
53
+ else
54
+ nil
55
+ end
56
+ end
57
+
58
+ it "is nil except for 4.0 sharded when it is 0" do
59
+ expect(geo_near.average_distance).to be expected_value
51
60
  end
52
61
  end
53
62
  end
@@ -75,6 +75,7 @@ describe Mongoid::Contextual::MapReduce do
75
75
  end
76
76
 
77
77
  describe "#counts" do
78
+ max_server_version '4.2'
78
79
 
79
80
  let(:criteria) do
80
81
  Band.all
@@ -103,7 +104,8 @@ describe Mongoid::Contextual::MapReduce do
103
104
  end
104
105
 
105
106
  it "iterates over the results" do
106
- expect(results.entries).to eq([
107
+ ordered_results = results.entries.sort_by { |doc| doc['_id'] }
108
+ expect(ordered_results.entries).to eq([
107
109
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
108
110
  { "_id" => "Tool", "value" => { "likes" => 100 }}
109
111
  ])
@@ -124,7 +126,8 @@ describe Mongoid::Contextual::MapReduce do
124
126
  end
125
127
 
126
128
  it "iterates over the results" do
127
- expect(results.entries).to eq(expected_results)
129
+ ordered_results = results.entries.sort_by { |doc| doc['_id'] }
130
+ expect(ordered_results).to eq(expected_results)
128
131
  end
129
132
 
130
133
  it 'outputs to the collection' do
@@ -144,6 +147,7 @@ describe Mongoid::Contextual::MapReduce do
144
147
  end
145
148
 
146
149
  context "when the statstics are requested" do
150
+ max_server_version '4.2'
147
151
 
148
152
  it "raises an error" do
149
153
  expect {
@@ -188,14 +192,16 @@ describe Mongoid::Contextual::MapReduce do
188
192
  Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
189
193
  end
190
194
 
191
- context 'when the server supports collations', if: collation_supported? do
195
+ context 'when the server supports collations' do
196
+ min_server_version '3.4'
192
197
 
193
198
  it 'applies the collation' do
194
199
  expect(map_reduce.out(inline: 1).count).to eq(1)
195
200
  end
196
201
  end
197
202
 
198
- context 'when the server does not support collations', unless: collation_supported? do
203
+ context 'when the server does not support collations' do
204
+ max_server_version '3.2'
199
205
 
200
206
  it 'raises an exception' do
201
207
  expect {
@@ -207,6 +213,7 @@ describe Mongoid::Contextual::MapReduce do
207
213
  end
208
214
 
209
215
  describe "#emitted" do
216
+ max_server_version '4.2'
210
217
 
211
218
  let(:emitted) do
212
219
  map_reduce.out(inline: 1).emitted
@@ -258,6 +265,7 @@ describe Mongoid::Contextual::MapReduce do
258
265
  end
259
266
 
260
267
  describe "#input" do
268
+ max_server_version '4.2'
261
269
 
262
270
  let(:input) do
263
271
  map_reduce.out(inline: 1).input
@@ -308,6 +316,7 @@ describe Mongoid::Contextual::MapReduce do
308
316
  end
309
317
 
310
318
  describe "#output" do
319
+ max_server_version '4.2'
311
320
 
312
321
  let(:output) do
313
322
  map_reduce.out(inline: 1).output
@@ -340,12 +349,16 @@ describe Mongoid::Contextual::MapReduce do
340
349
  end
341
350
 
342
351
  context 'when a read preference is defined' do
352
+ require_topology :replica_set
353
+ # On 4.4 it seems the server inserts on the primary, not on the server
354
+ # that executed the map/reduce.
355
+ max_server_version '4.2'
343
356
 
344
357
  let(:criteria) do
345
358
  Band.all.read(mode: :secondary)
346
359
  end
347
360
 
348
- it "uses the read preference", if: testing_replica_set? do
361
+ it "uses the read preference" do
349
362
 
350
363
  expect {
351
364
  replace_map_reduce.raw
@@ -356,6 +369,7 @@ describe Mongoid::Contextual::MapReduce do
356
369
  end
357
370
 
358
371
  describe "#reduced" do
372
+ max_server_version '4.2'
359
373
 
360
374
  let(:reduced) do
361
375
  map_reduce.out(inline: 1).reduced
@@ -386,6 +400,7 @@ describe Mongoid::Contextual::MapReduce do
386
400
  end
387
401
 
388
402
  describe "#time" do
403
+ max_server_version '4.2'
389
404
 
390
405
  let(:time) do
391
406
  map_reduce.out(inline: 1).time
@@ -168,7 +168,8 @@ describe Mongoid::Contextual::Mongo do
168
168
  end
169
169
  end
170
170
 
171
- context 'when a collation is specified', if: collation_supported? do
171
+ context 'when a collation is specified' do
172
+ min_server_version '3.4'
172
173
 
173
174
  let(:context) do
174
175
  described_class.new(criteria)
@@ -229,7 +230,8 @@ describe Mongoid::Contextual::Mongo do
229
230
  expect(deleted).to eq(1)
230
231
  end
231
232
 
232
- context 'when the criteria has a collation', if: collation_supported? do
233
+ context 'when the criteria has a collation' do
234
+ min_server_version '3.4'
233
235
 
234
236
  let(:criteria) do
235
237
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -333,7 +335,8 @@ describe Mongoid::Contextual::Mongo do
333
335
  expect(destroyed).to eq(1)
334
336
  end
335
337
 
336
- context 'when the criteria has a collation', if: collation_supported? do
338
+ context 'when the criteria has a collation' do
339
+ min_server_version '3.4'
337
340
 
338
341
  let(:criteria) do
339
342
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -455,7 +458,8 @@ describe Mongoid::Contextual::Mongo do
455
458
  end
456
459
  end
457
460
 
458
- context 'when a collation is specified', if: collation_supported? do
461
+ context 'when a collation is specified' do
462
+ min_server_version '3.4'
459
463
 
460
464
  before do
461
465
  Band.create(name: 'DEPECHE MODE')
@@ -493,7 +497,8 @@ describe Mongoid::Contextual::Mongo do
493
497
  described_class.new(criteria)
494
498
  end
495
499
 
496
- context 'when the criteria has a collation', if: collation_supported? do
500
+ context 'when the criteria has a collation' do
501
+ min_server_version '3.4'
497
502
 
498
503
  let(:criteria) do
499
504
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -850,7 +855,8 @@ describe Mongoid::Contextual::Mongo do
850
855
  end
851
856
  end
852
857
 
853
- context 'when a collation is specified on the criteria', if: collation_supported? do
858
+ context 'when a collation is specified on the criteria' do
859
+ min_server_version '3.4'
854
860
 
855
861
  let(:criteria) do
856
862
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1003,7 +1009,8 @@ describe Mongoid::Contextual::Mongo do
1003
1009
  end
1004
1010
  end
1005
1011
 
1006
- context 'when a collation is specified on the criteria', if: collation_supported? do
1012
+ context 'when a collation is specified on the criteria' do
1013
+ min_server_version '3.4'
1007
1014
 
1008
1015
  let(:criteria) do
1009
1016
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1077,7 +1084,8 @@ describe Mongoid::Contextual::Mongo do
1077
1084
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
1078
1085
  end
1079
1086
 
1080
- context 'when a collation is specified on the criteria', if: collation_supported? do
1087
+ context 'when a collation is specified on the criteria' do
1088
+ min_server_version '3.4'
1081
1089
 
1082
1090
  let(:criteria) do
1083
1091
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1149,7 +1157,8 @@ describe Mongoid::Contextual::Mongo do
1149
1157
  expect(context.send(method)).to eq(depeche_mode)
1150
1158
  end
1151
1159
 
1152
- context 'when the criteria has a collation', if: collation_supported? do
1160
+ context 'when the criteria has a collation' do
1161
+ min_server_version '3.4'
1153
1162
 
1154
1163
  let(:criteria) do
1155
1164
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1553,6 +1562,10 @@ describe Mongoid::Contextual::Mongo do
1553
1562
  }}
1554
1563
  end
1555
1564
 
1565
+ let(:ordered_results) do
1566
+ results['results'].sort_by { |doc| doc['_id'] }
1567
+ end
1568
+
1556
1569
  context "when no selection is provided" do
1557
1570
 
1558
1571
  let(:criteria) do
@@ -1584,36 +1597,40 @@ describe Mongoid::Contextual::Mongo do
1584
1597
  end
1585
1598
 
1586
1599
  it "contains the entire raw results" do
1587
- expect(results["results"]).to eq([
1600
+ expect(ordered_results).to eq([
1588
1601
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
1589
1602
  { "_id" => "Tool", "value" => { "likes" => 100 }}
1590
1603
  ])
1591
1604
  end
1592
1605
 
1593
- it "contains the execution time" do
1594
- expect(results.time).to_not be_nil
1595
- end
1606
+ context 'when statistics are available' do
1607
+ max_server_version '4.2'
1596
1608
 
1597
- it "contains the count statistics" do
1598
- expect(results["counts"]).to eq({
1599
- "input" => 2, "emit" => 2, "reduce" => 0, "output" => 2
1600
- })
1601
- end
1609
+ it "contains the execution time" do
1610
+ expect(results.time).to_not be_nil
1611
+ end
1602
1612
 
1603
- it "contains the input count" do
1604
- expect(results.input).to eq(2)
1605
- end
1613
+ it "contains the count statistics" do
1614
+ expect(results["counts"]).to eq({
1615
+ "input" => 2, "emit" => 2, "reduce" => 0, "output" => 2
1616
+ })
1617
+ end
1606
1618
 
1607
- it "contains the emitted count" do
1608
- expect(results.emitted).to eq(2)
1609
- end
1619
+ it "contains the input count" do
1620
+ expect(results.input).to eq(2)
1621
+ end
1610
1622
 
1611
- it "contains the reduced count" do
1612
- expect(results.reduced).to eq(0)
1613
- end
1623
+ it "contains the emitted count" do
1624
+ expect(results.emitted).to eq(2)
1625
+ end
1614
1626
 
1615
- it "contains the output count" do
1616
- expect(results.output).to eq(2)
1627
+ it "contains the reduced count" do
1628
+ expect(results.reduced).to eq(0)
1629
+ end
1630
+
1631
+ it "contains the output count" do
1632
+ expect(results.output).to eq(2)
1633
+ end
1617
1634
  end
1618
1635
  end
1619
1636
 
@@ -1642,35 +1659,39 @@ describe Mongoid::Contextual::Mongo do
1642
1659
  end
1643
1660
 
1644
1661
  it "contains the entire raw results" do
1645
- expect(results["results"]).to eq([
1662
+ expect(ordered_results).to eq([
1646
1663
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }}
1647
1664
  ])
1648
1665
  end
1649
1666
 
1650
- it "contains the execution time" do
1651
- expect(results.time).to_not be_nil
1652
- end
1667
+ context 'when statistics are available' do
1668
+ max_server_version '4.2'
1653
1669
 
1654
- it "contains the count statistics" do
1655
- expect(results["counts"]).to eq({
1656
- "input" => 1, "emit" => 1, "reduce" => 0, "output" => 1
1657
- })
1658
- end
1670
+ it "contains the execution time" do
1671
+ expect(results.time).to_not be_nil
1672
+ end
1659
1673
 
1660
- it "contains the input count" do
1661
- expect(results.input).to eq(1)
1662
- end
1674
+ it "contains the count statistics" do
1675
+ expect(results["counts"]).to eq({
1676
+ "input" => 1, "emit" => 1, "reduce" => 0, "output" => 1
1677
+ })
1678
+ end
1663
1679
 
1664
- it "contains the emitted count" do
1665
- expect(results.emitted).to eq(1)
1666
- end
1680
+ it "contains the input count" do
1681
+ expect(results.input).to eq(1)
1682
+ end
1667
1683
 
1668
- it "contains the reduced count" do
1669
- expect(results.reduced).to eq(0)
1670
- end
1684
+ it "contains the emitted count" do
1685
+ expect(results.emitted).to eq(1)
1686
+ end
1671
1687
 
1672
- it "contains the output count" do
1673
- expect(results.output).to eq(1)
1688
+ it "contains the reduced count" do
1689
+ expect(results.reduced).to eq(0)
1690
+ end
1691
+
1692
+ it "contains the output count" do
1693
+ expect(results.output).to eq(1)
1694
+ end
1674
1695
  end
1675
1696
  end
1676
1697
 
@@ -1710,7 +1731,7 @@ describe Mongoid::Contextual::Mongo do
1710
1731
  end
1711
1732
 
1712
1733
  it "contains the entire raw results" do
1713
- expect(results["results"]).to eq([
1734
+ expect(ordered_results).to eq([
1714
1735
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
1715
1736
  { "_id" => "Tool", "value" => { "likes" => 100 }}
1716
1737
  ])
@@ -2161,7 +2182,8 @@ describe Mongoid::Contextual::Mongo do
2161
2182
  end
2162
2183
  end
2163
2184
 
2164
- context 'when provided array filters', if: array_filters_supported? do
2185
+ context 'when provided array filters' do
2186
+ min_server_version '3.6'
2165
2187
 
2166
2188
  before do
2167
2189
  Band.delete_all
@@ -2333,7 +2355,8 @@ describe Mongoid::Contextual::Mongo do
2333
2355
  end
2334
2356
  end
2335
2357
 
2336
- context 'when provided array filters', if: array_filters_supported? do
2358
+ context 'when provided array filters' do
2359
+ min_server_version '3.6'
2337
2360
 
2338
2361
  before do
2339
2362
  Band.delete_all
@@ -2371,7 +2394,7 @@ describe Mongoid::Contextual::Mongo do
2371
2394
 
2372
2395
  describe '#pipeline' do
2373
2396
 
2374
- context 'when the criteria has a selector', if: non_legacy_server? do
2397
+ context 'when the criteria has a selector' do
2375
2398
 
2376
2399
  before do
2377
2400
  Artist.index(name: "text")