mongoid 7.1.0 → 7.1.6

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 (131) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +6 -6
  5. data/README.md +1 -1
  6. data/Rakefile +14 -5
  7. data/lib/config/locales/en.yml +5 -5
  8. data/lib/mongoid/association/accessors.rb +37 -2
  9. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  10. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  11. data/lib/mongoid/association/proxy.rb +1 -1
  12. data/lib/mongoid/association/referenced/belongs_to/binding.rb +1 -1
  13. data/lib/mongoid/association/referenced/belongs_to/eager.rb +38 -2
  14. data/lib/mongoid/association/referenced/eager.rb +29 -9
  15. data/lib/mongoid/association/referenced/has_one/proxy.rb +6 -1
  16. data/lib/mongoid/atomic.rb +13 -3
  17. data/lib/mongoid/clients/factory.rb +2 -2
  18. data/lib/mongoid/clients/options.rb +8 -8
  19. data/lib/mongoid/clients/sessions.rb +20 -4
  20. data/lib/mongoid/clients/storage_options.rb +5 -5
  21. data/lib/mongoid/config.rb +39 -9
  22. data/lib/mongoid/criteria.rb +23 -4
  23. data/lib/mongoid/criteria/modifiable.rb +2 -1
  24. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  25. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +6 -6
  26. data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
  27. data/lib/mongoid/criteria/queryable/mergeable.rb +75 -8
  28. data/lib/mongoid/criteria/queryable/pipeline.rb +3 -2
  29. data/lib/mongoid/criteria/queryable/selectable.rb +120 -13
  30. data/lib/mongoid/criteria/queryable/storable.rb +104 -99
  31. data/lib/mongoid/errors/eager_load.rb +2 -0
  32. data/lib/mongoid/errors/no_client_config.rb +2 -2
  33. data/lib/mongoid/errors/no_default_client.rb +1 -1
  34. data/lib/mongoid/extensions/hash.rb +4 -2
  35. data/lib/mongoid/extensions/regexp.rb +1 -1
  36. data/lib/mongoid/fields.rb +2 -1
  37. data/lib/mongoid/fields/validators/macro.rb +4 -1
  38. data/lib/mongoid/matchable/regexp.rb +2 -2
  39. data/lib/mongoid/persistable/pushable.rb +11 -2
  40. data/lib/mongoid/persistence_context.rb +6 -6
  41. data/lib/mongoid/query_cache.rb +61 -18
  42. data/lib/mongoid/serializable.rb +9 -3
  43. data/lib/mongoid/tasks/database.rb +38 -3
  44. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  45. data/lib/mongoid/version.rb +1 -1
  46. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +32 -23
  47. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  48. data/spec/app/models/coding.rb +4 -0
  49. data/spec/app/models/coding/pull_request.rb +12 -0
  50. data/spec/app/models/delegating_patient.rb +16 -0
  51. data/spec/app/models/passport.rb +1 -0
  52. data/spec/app/models/person.rb +2 -0
  53. data/spec/app/models/phone.rb +1 -0
  54. data/spec/app/models/publication.rb +5 -0
  55. data/spec/app/models/publication/encyclopedia.rb +12 -0
  56. data/spec/app/models/publication/review.rb +14 -0
  57. data/spec/app/models/series.rb +1 -0
  58. data/spec/app/models/wiki_page.rb +1 -0
  59. data/spec/integration/app_spec.rb +254 -0
  60. data/spec/integration/associations/embedded_spec.rb +54 -0
  61. data/spec/integration/associations/embeds_many_spec.rb +24 -0
  62. data/spec/integration/associations/embeds_one_spec.rb +24 -0
  63. data/spec/integration/associations/has_many_spec.rb +76 -0
  64. data/spec/integration/associations/has_one_spec.rb +76 -0
  65. data/spec/integration/bson_regexp_raw_spec.rb +20 -0
  66. data/spec/integration/criteria/date_field_spec.rb +41 -0
  67. data/spec/integration/criteria/logical_spec.rb +13 -0
  68. data/spec/integration/document_spec.rb +22 -0
  69. data/spec/integration/shardable_spec.rb +20 -4
  70. data/spec/lite_spec_helper.rb +12 -4
  71. data/spec/mongoid/association/accessors_spec.rb +238 -63
  72. data/spec/mongoid/association/embedded/embeds_many_models.rb +19 -0
  73. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  74. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  75. data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +193 -10
  76. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
  77. data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
  78. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  79. data/spec/mongoid/clients/factory_spec.rb +8 -8
  80. data/spec/mongoid/clients/options_spec.rb +11 -11
  81. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  82. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  83. data/spec/mongoid/clients_spec.rb +2 -2
  84. data/spec/mongoid/contextual/atomic_spec.rb +22 -11
  85. data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
  86. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  87. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  88. data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +1 -1
  89. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  90. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  91. data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
  92. data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
  93. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +45 -12
  94. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1051 -392
  95. data/spec/mongoid/criteria/queryable/selectable_spec.rb +52 -0
  96. data/spec/mongoid/criteria/queryable/storable_spec.rb +80 -2
  97. data/spec/mongoid/criteria_spec.rb +36 -2
  98. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  99. data/spec/mongoid/errors/no_client_config_spec.rb +2 -2
  100. data/spec/mongoid/errors/no_client_database_spec.rb +3 -3
  101. data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -3
  102. data/spec/mongoid/fields_spec.rb +24 -1
  103. data/spec/mongoid/indexable_spec.rb +6 -4
  104. data/spec/mongoid/matchable/default_spec.rb +1 -1
  105. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  106. data/spec/mongoid/matchable_spec.rb +2 -2
  107. data/spec/mongoid/persistable/pushable_spec.rb +55 -1
  108. data/spec/mongoid/query_cache_spec.rb +77 -9
  109. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  110. data/spec/mongoid/scopable_spec.rb +2 -1
  111. data/spec/mongoid/serializable_spec.rb +129 -18
  112. data/spec/mongoid/shardable_models.rb +1 -1
  113. data/spec/mongoid/shardable_spec.rb +2 -2
  114. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  115. data/spec/mongoid/tasks/database_spec.rb +1 -1
  116. data/spec/shared/LICENSE +20 -0
  117. data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
  118. data/spec/shared/lib/mrss/cluster_config.rb +211 -0
  119. data/spec/shared/lib/mrss/constraints.rb +312 -0
  120. data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
  121. data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
  122. data/spec/spec_helper.rb +2 -31
  123. data/spec/support/child_process_helper.rb +76 -0
  124. data/spec/support/cluster_config.rb +3 -3
  125. data/spec/support/constraints.rb +26 -10
  126. data/spec/support/expectations.rb +3 -1
  127. data/spec/support/helpers.rb +11 -0
  128. data/spec/support/session_registry.rb +50 -0
  129. data/spec/support/spec_config.rb +12 -4
  130. metadata +520 -473
  131. metadata.gz.sig +0 -0
@@ -2907,7 +2907,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
2907
2907
  expect(posts).to eq([ post_one ])
2908
2908
  end
2909
2909
 
2910
- context 'when providing a collation', if: collation_supported? do
2910
+ context 'when providing a collation' do
2911
+ min_server_version '3.4'
2911
2912
 
2912
2913
  let(:posts) do
2913
2914
  person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
@@ -41,7 +41,7 @@ describe Mongoid::Clients::Factory do
41
41
  let(:config) do
42
42
  {
43
43
  default: { hosts: SpecConfig.instance.addresses, database: database_id },
44
- secondary: { hosts: SpecConfig.instance.addresses, database: database_id }
44
+ analytics: { hosts: SpecConfig.instance.addresses, database: database_id }
45
45
  }
46
46
  end
47
47
 
@@ -54,7 +54,7 @@ describe Mongoid::Clients::Factory do
54
54
  end
55
55
 
56
56
  let(:client) do
57
- described_class.create(:secondary)
57
+ described_class.create(:analytics)
58
58
  end
59
59
 
60
60
  let(:cluster) do
@@ -81,7 +81,7 @@ describe Mongoid::Clients::Factory do
81
81
  let(:config) do
82
82
  {
83
83
  default: { hosts: [ "127.0.0.1" ], database: database_id },
84
- secondary: { hosts: [ "127.0.0.1" ], database: database_id }
84
+ analytics: { hosts: [ "127.0.0.1" ], database: database_id }
85
85
  }
86
86
  end
87
87
 
@@ -94,7 +94,7 @@ describe Mongoid::Clients::Factory do
94
94
  end
95
95
 
96
96
  let(:client) do
97
- described_class.create(:secondary)
97
+ described_class.create(:analytics)
98
98
  end
99
99
 
100
100
  let(:default) do
@@ -125,7 +125,7 @@ describe Mongoid::Clients::Factory do
125
125
  let(:config) do
126
126
  {
127
127
  default: { hosts: [ "127.0.0.1:27017" ], database: database_id },
128
- secondary: { uri: "mongodb://127.0.0.1:27017/mongoid_test" }
128
+ analytics: { uri: "mongodb://127.0.0.1:27017/mongoid_test" }
129
129
  }
130
130
  end
131
131
 
@@ -138,7 +138,7 @@ describe Mongoid::Clients::Factory do
138
138
  end
139
139
 
140
140
  let(:client) do
141
- described_class.create(:secondary)
141
+ described_class.create(:analytics)
142
142
  end
143
143
 
144
144
  let(:cluster) do
@@ -163,7 +163,7 @@ describe Mongoid::Clients::Factory do
163
163
  let(:config) do
164
164
  {
165
165
  default: { hosts: [ "127.0.0.1:1234" ], database: database_id, server_selection_timeout: 1 },
166
- secondary: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test?serverSelectionTimeoutMS=1000" }
166
+ analytics: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test?serverSelectionTimeoutMS=1000" }
167
167
  }
168
168
  end
169
169
 
@@ -176,7 +176,7 @@ describe Mongoid::Clients::Factory do
176
176
  end
177
177
 
178
178
  let(:client) do
179
- described_class.create(:secondary)
179
+ described_class.create(:analytics)
180
180
  end
181
181
 
182
182
  let(:cluster) do
@@ -14,7 +14,7 @@ describe Mongoid::Clients::Options, retry: 3 do
14
14
  Mongoid::Clients.clients.clear
15
15
  end
16
16
 
17
- describe '#with', if: non_legacy_server? do
17
+ describe '#with' do
18
18
 
19
19
  context 'when passing some options' do
20
20
 
@@ -151,7 +151,7 @@ describe Mongoid::Clients::Options, retry: 3 do
151
151
  let(:config) do
152
152
  {
153
153
  default: { hosts: SpecConfig.instance.addresses, database: database_id },
154
- secondary: { uri: "mongodb://#{SpecConfig.instance.addresses.first}/secondary-db?connectTimeoutMS=3000" }
154
+ analytics: { uri: "mongodb://#{SpecConfig.instance.addresses.first}/analytics-db?connectTimeoutMS=3000" }
155
155
  }
156
156
  end
157
157
 
@@ -164,14 +164,14 @@ describe Mongoid::Clients::Options, retry: 3 do
164
164
  end
165
165
 
166
166
  let(:persistence_context) do
167
- Minim.with(client: :secondary) do |klass|
167
+ Minim.with(client: :analytics) do |klass|
168
168
  klass.persistence_context
169
169
  end
170
170
  end
171
171
 
172
172
  it 'uses the database specified in the uri' do
173
- expect(persistence_context.database_name).to eq('secondary-db')
174
- expect(persistence_context.client.database.name).to eq('secondary-db')
173
+ expect(persistence_context.database_name).to eq('analytics-db')
174
+ expect(persistence_context.client.database.name).to eq('analytics-db')
175
175
  end
176
176
 
177
177
  it 'uses the options specified in the uri' do
@@ -291,7 +291,7 @@ describe Mongoid::Clients::Options, retry: 3 do
291
291
  end
292
292
  end
293
293
 
294
- describe '.with', if: non_legacy_server? do
294
+ describe '.with' do
295
295
 
296
296
  context 'when passing some options' do
297
297
 
@@ -344,8 +344,8 @@ describe Mongoid::Clients::Options, retry: 3 do
344
344
  let(:config) do
345
345
  {
346
346
  default: { hosts: SpecConfig.instance.addresses, database: database_id },
347
- secondary: {
348
- uri: "mongodb://#{SpecConfig.instance.addresses.first}/secondary-db",
347
+ analytics: {
348
+ uri: "mongodb://#{SpecConfig.instance.addresses.first}/analytics-db",
349
349
  options: {
350
350
  server_selection_timeout: 0.5,
351
351
  },
@@ -358,14 +358,14 @@ describe Mongoid::Clients::Options, retry: 3 do
358
358
  end
359
359
 
360
360
  let(:persistence_context) do
361
- test_model.with(client: :secondary) do |object|
361
+ test_model.with(client: :analytics) do |object|
362
362
  object.persistence_context
363
363
  end
364
364
  end
365
365
 
366
366
  it 'uses the database specified in the uri' do
367
- expect(persistence_context.database_name).to eq('secondary-db')
368
- expect(persistence_context.client.database.name).to eq('secondary-db')
367
+ expect(persistence_context.database_name).to eq('analytics-db')
368
+ expect(persistence_context.client.database.name).to eq('analytics-db')
369
369
  end
370
370
  end
371
371
 
@@ -43,7 +43,8 @@ describe Mongoid::Clients::Sessions do
43
43
 
44
44
  context 'when a session is used on a model class' do
45
45
 
46
- context 'when sessions are supported', if: sessions_supported? do
46
+ context 'when sessions are supported' do
47
+ min_server_version '3.6'
47
48
 
48
49
  around do |example|
49
50
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -172,7 +173,8 @@ describe Mongoid::Clients::Sessions do
172
173
  end
173
174
  end
174
175
 
175
- context 'when sessions are not supported', unless: sessions_supported? do
176
+ context 'when sessions are not supported' do
177
+ max_server_version '3.4'
176
178
 
177
179
  let!(:error) do
178
180
  e = nil
@@ -199,7 +201,8 @@ describe Mongoid::Clients::Sessions do
199
201
  end
200
202
  end
201
203
 
202
- context 'when sessions are supported', if: sessions_supported? do
204
+ context 'when sessions are supported' do
205
+ min_server_version '3.6'
203
206
 
204
207
  around do |example|
205
208
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -316,7 +319,8 @@ describe Mongoid::Clients::Sessions do
316
319
  end
317
320
  end
318
321
 
319
- context 'when sessions are not supported', unless: sessions_supported? do
322
+ context 'when sessions are not supported' do
323
+ max_server_version '3.4'
320
324
 
321
325
  let!(:error) do
322
326
  e = nil
@@ -55,7 +55,8 @@ describe Mongoid::Clients::Sessions do
55
55
 
56
56
  context 'when a transaction is used on a model class' do
57
57
 
58
- context 'when transactions are supported', if: testing_transactions? do
58
+ context 'when transactions are supported' do
59
+ require_transaction_support
59
60
 
60
61
  around do |example|
61
62
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -191,7 +192,10 @@ describe Mongoid::Clients::Sessions do
191
192
  end
192
193
  end
193
194
 
194
- context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
195
+ context 'when sessions are supported but transactions are not' do
196
+ min_server_version '3.6'
197
+ # Could also test 4.0 in sharded cluster
198
+ max_server_version '3.6'
195
199
 
196
200
  let!(:error) do
197
201
  e = nil
@@ -222,7 +226,8 @@ describe Mongoid::Clients::Sessions do
222
226
  end
223
227
  end
224
228
 
225
- context 'when transactions are supported', if: testing_transactions? do
229
+ context 'when transactions are supported' do
230
+ require_transaction_support
226
231
 
227
232
  around do |example|
228
233
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -345,16 +350,23 @@ describe Mongoid::Clients::Sessions do
345
350
  end
346
351
  end
347
352
 
348
- context 'when sessions are supported but transactions are not', if: sessions_supported? && !testing_transactions? do
353
+ context 'when sessions are supported but transactions are not' do
354
+ min_server_version '3.6'
355
+ # Could also test 4.0 in sharded cluster
356
+ max_server_version '3.6'
349
357
 
350
358
  around do |example|
351
359
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
352
360
  Mongoid::Clients.with_name(:other).command(create: :people)
353
- subscriber.clear_events!
354
- person.with(client: :other) do
355
- example.run
361
+
362
+ begin
363
+ subscriber.clear_events!
364
+ person.with(client: :other) do
365
+ example.run
366
+ end
367
+ ensure
368
+ Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
356
369
  end
357
- Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
358
370
  end
359
371
 
360
372
  let!(:error) do
@@ -728,7 +728,7 @@ describe Mongoid::Clients do
728
728
  end
729
729
  end
730
730
 
731
- describe ".store_in", if: non_legacy_server? do
731
+ describe ".store_in" do
732
732
 
733
733
  context "when provided a non hash" do
734
734
 
@@ -765,7 +765,7 @@ describe Mongoid::Clients do
765
765
  end
766
766
  end
767
767
 
768
- describe ".with", if: non_legacy_server? do
768
+ describe ".with" do
769
769
 
770
770
  context "when changing write concern options" do
771
771
 
@@ -77,7 +77,8 @@ describe Mongoid::Contextual::Atomic do
77
77
  end
78
78
  end
79
79
 
80
- context 'when the criteria has a collation', if: collation_supported? do
80
+ context 'when the criteria has a collation' do
81
+ min_server_version '3.4'
81
82
 
82
83
  let(:criteria) do
83
84
  Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
@@ -173,7 +174,8 @@ describe Mongoid::Contextual::Atomic do
173
174
  end
174
175
  end
175
176
 
176
- context 'when the criteria has a collation', if: collation_supported? do
177
+ context 'when the criteria has a collation' do
178
+ min_server_version '3.4'
177
179
 
178
180
  let(:criteria) do
179
181
  Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
@@ -244,7 +246,8 @@ describe Mongoid::Contextual::Atomic do
244
246
  end
245
247
  end
246
248
 
247
- context 'when the criteria has a collation', if: collation_supported? do
249
+ context 'when the criteria has a collation' do
250
+ min_server_version '3.4'
248
251
 
249
252
  let!(:depeche_mode) do
250
253
  Band.create(members: [ "Dave" ], likes: 60)
@@ -323,7 +326,8 @@ describe Mongoid::Contextual::Atomic do
323
326
  end
324
327
  end
325
328
 
326
- context 'when the criteria has a collation', if: collation_supported? do
329
+ context 'when the criteria has a collation' do
330
+ min_server_version '3.4'
327
331
 
328
332
  let!(:depeche_mode) do
329
333
  Band.create(members: [ "Dave" ])
@@ -395,7 +399,8 @@ describe Mongoid::Contextual::Atomic do
395
399
  end
396
400
  end
397
401
 
398
- context 'when the criteria has a collation', if: collation_supported? do
402
+ context 'when the criteria has a collation' do
403
+ min_server_version '3.4'
399
404
 
400
405
  let!(:depeche_mode) do
401
406
  Band.create(members: [ "Dave" ])
@@ -449,7 +454,8 @@ describe Mongoid::Contextual::Atomic do
449
454
  expect(smiths.reload.members).to be_nil
450
455
  end
451
456
 
452
- context 'when the criteria has a collation', if: collation_supported? do
457
+ context 'when the criteria has a collation' do
458
+ min_server_version '3.4'
453
459
 
454
460
  let!(:depeche_mode) do
455
461
  Band.create(members: [ "Dave" ])
@@ -506,7 +512,8 @@ describe Mongoid::Contextual::Atomic do
506
512
  end
507
513
  end
508
514
 
509
- context 'when the criteria has a collation', if: collation_supported? do
515
+ context 'when the criteria has a collation' do
516
+ min_server_version '3.4'
510
517
 
511
518
  let!(:depeche_mode) do
512
519
  Band.create(members: [ "Dave", "Alan", "Fletch" ])
@@ -563,7 +570,8 @@ describe Mongoid::Contextual::Atomic do
563
570
  end
564
571
  end
565
572
 
566
- context 'when the criteria has a collation', if: collation_supported? do
573
+ context 'when the criteria has a collation' do
574
+ min_server_version '3.4'
567
575
 
568
576
  let!(:depeche_mode) do
569
577
  Band.create(members: [ "Dave" ])
@@ -628,7 +636,8 @@ describe Mongoid::Contextual::Atomic do
628
636
  end
629
637
  end
630
638
 
631
- context 'when the criteria has a collation', if: collation_supported? do
639
+ context 'when the criteria has a collation' do
640
+ min_server_version '3.4'
632
641
 
633
642
  let!(:depeche_mode) do
634
643
  Band.create(members: [ "Dave" ])
@@ -689,7 +698,8 @@ describe Mongoid::Contextual::Atomic do
689
698
  end
690
699
  end
691
700
 
692
- context 'when the criteria has a collation', if: collation_supported? do
701
+ context 'when the criteria has a collation' do
702
+ min_server_version '3.4'
693
703
 
694
704
  let!(:depeche_mode) do
695
705
  Band.create(members: [ "Dave" ])
@@ -848,7 +858,8 @@ describe Mongoid::Contextual::Atomic do
848
858
  end
849
859
  end
850
860
 
851
- context 'when the criteria has a collation', if: collation_supported? do
861
+ context 'when the criteria has a collation' do
862
+ min_server_version '3.4'
852
863
 
853
864
  let!(:depeche_mode) do
854
865
  Band.create(name: "Depeche Mode", years: 10)
@@ -49,8 +49,17 @@ describe Mongoid::Contextual::GeoNear do
49
49
  described_class.new(collection, criteria, [ 52, 13 ])
50
50
  end
51
51
 
52
- it "returns 0.0" do
53
- expect(geo_near.average_distance).to be_nil
52
+ let(:expected_value) do
53
+ if ClusterConfig.instance.fcv_ish == '4.0' && ClusterConfig.instance.topology == :sharded
54
+ # https://jira.mongodb.org/browse/SERVER-50074
55
+ 0.0
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
61
+ it "is nil except for 4.0 sharded when it is 0" do
62
+ expect(geo_near.average_distance).to be expected_value
54
63
  end
55
64
  end
56
65
  end
@@ -78,6 +78,7 @@ describe Mongoid::Contextual::MapReduce do
78
78
  end
79
79
 
80
80
  describe "#counts" do
81
+ max_server_version '4.2'
81
82
 
82
83
  let(:criteria) do
83
84
  Band.all
@@ -106,7 +107,8 @@ describe Mongoid::Contextual::MapReduce do
106
107
  end
107
108
 
108
109
  it "iterates over the results" do
109
- expect(results.entries).to eq([
110
+ ordered_results = results.entries.sort_by { |doc| doc['_id'] }
111
+ expect(ordered_results.entries).to eq([
110
112
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
111
113
  { "_id" => "Tool", "value" => { "likes" => 100 }}
112
114
  ])
@@ -127,7 +129,8 @@ describe Mongoid::Contextual::MapReduce do
127
129
  end
128
130
 
129
131
  it "iterates over the results" do
130
- expect(results.entries).to eq(expected_results)
132
+ ordered_results = results.entries.sort_by { |doc| doc['_id'] }
133
+ expect(ordered_results).to eq(expected_results)
131
134
  end
132
135
 
133
136
  it 'outputs to the collection' do
@@ -147,6 +150,7 @@ describe Mongoid::Contextual::MapReduce do
147
150
  end
148
151
 
149
152
  context "when the statstics are requested" do
153
+ max_server_version '4.2'
150
154
 
151
155
  it "raises an error" do
152
156
  expect {
@@ -191,14 +195,16 @@ describe Mongoid::Contextual::MapReduce do
191
195
  Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2)
192
196
  end
193
197
 
194
- context 'when the server supports collations', if: collation_supported? do
198
+ context 'when the server supports collations' do
199
+ min_server_version '3.4'
195
200
 
196
201
  it 'applies the collation' do
197
202
  expect(map_reduce.out(inline: 1).count).to eq(1)
198
203
  end
199
204
  end
200
205
 
201
- context 'when the server does not support collations', unless: collation_supported? do
206
+ context 'when the server does not support collations' do
207
+ max_server_version '3.2'
202
208
 
203
209
  it 'raises an exception' do
204
210
  expect {
@@ -210,6 +216,7 @@ describe Mongoid::Contextual::MapReduce do
210
216
  end
211
217
 
212
218
  describe "#emitted" do
219
+ max_server_version '4.2'
213
220
 
214
221
  let(:emitted) do
215
222
  map_reduce.out(inline: 1).emitted
@@ -261,6 +268,7 @@ describe Mongoid::Contextual::MapReduce do
261
268
  end
262
269
 
263
270
  describe "#input" do
271
+ max_server_version '4.2'
264
272
 
265
273
  let(:input) do
266
274
  map_reduce.out(inline: 1).input
@@ -311,6 +319,7 @@ describe Mongoid::Contextual::MapReduce do
311
319
  end
312
320
 
313
321
  describe "#output" do
322
+ max_server_version '4.2'
314
323
 
315
324
  let(:output) do
316
325
  map_reduce.out(inline: 1).output
@@ -343,12 +352,16 @@ describe Mongoid::Contextual::MapReduce do
343
352
  end
344
353
 
345
354
  context 'when a read preference is defined' do
355
+ require_topology :replica_set
356
+ # On 4.4 it seems the server inserts on the primary, not on the server
357
+ # that executed the map/reduce.
358
+ max_server_version '4.2'
346
359
 
347
360
  let(:criteria) do
348
361
  Band.all.read(mode: :secondary)
349
362
  end
350
363
 
351
- it "uses the read preference", if: testing_replica_set? do
364
+ it "uses the read preference" do
352
365
 
353
366
  expect {
354
367
  replace_map_reduce.raw
@@ -359,6 +372,7 @@ describe Mongoid::Contextual::MapReduce do
359
372
  end
360
373
 
361
374
  describe "#reduced" do
375
+ max_server_version '4.2'
362
376
 
363
377
  let(:reduced) do
364
378
  map_reduce.out(inline: 1).reduced
@@ -389,6 +403,7 @@ describe Mongoid::Contextual::MapReduce do
389
403
  end
390
404
 
391
405
  describe "#time" do
406
+ max_server_version '4.2'
392
407
 
393
408
  let(:time) do
394
409
  map_reduce.out(inline: 1).time