mongoid 7.0.3 → 7.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +1 -0
  4. data/LICENSE +1 -0
  5. data/README.md +3 -2
  6. data/Rakefile +12 -0
  7. data/lib/mongoid.rb +2 -1
  8. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  9. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  10. data/lib/mongoid/association/proxy.rb +1 -1
  11. data/lib/mongoid/association/relatable.rb +23 -21
  12. data/lib/mongoid/atomic.rb +13 -3
  13. data/lib/mongoid/atomic/paths/embedded.rb +1 -1
  14. data/lib/mongoid/attributes.rb +28 -20
  15. data/lib/mongoid/attributes/dynamic.rb +15 -14
  16. data/lib/mongoid/config/environment.rb +21 -8
  17. data/lib/mongoid/copyable.rb +5 -1
  18. data/lib/mongoid/criteria.rb +7 -1
  19. data/lib/mongoid/criteria/modifiable.rb +13 -2
  20. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  21. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  22. data/lib/mongoid/criteria/queryable/key.rb +67 -8
  23. data/lib/mongoid/criteria/queryable/mergeable.rb +5 -4
  24. data/lib/mongoid/criteria/queryable/selectable.rb +3 -4
  25. data/lib/mongoid/criteria/queryable/selector.rb +9 -31
  26. data/lib/mongoid/extensions/hash.rb +4 -2
  27. data/lib/mongoid/extensions/regexp.rb +1 -1
  28. data/lib/mongoid/extensions/string.rb +5 -3
  29. data/lib/mongoid/fields.rb +2 -1
  30. data/lib/mongoid/matchable.rb +14 -15
  31. data/lib/mongoid/matchable/all.rb +4 -3
  32. data/lib/mongoid/matchable/default.rb +71 -24
  33. data/lib/mongoid/matchable/regexp.rb +2 -2
  34. data/lib/mongoid/persistable/pushable.rb +11 -2
  35. data/lib/mongoid/persistence_context.rb +6 -6
  36. data/lib/mongoid/positional.rb +1 -1
  37. data/lib/mongoid/query_cache.rb +3 -2
  38. data/lib/mongoid/validatable/macros.rb +1 -1
  39. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  40. data/lib/mongoid/version.rb +2 -1
  41. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  42. data/spec/README.md +18 -0
  43. data/spec/app/models/delegating_patient.rb +16 -0
  44. data/spec/app/models/other_owner_object.rb +2 -0
  45. data/spec/integration/app_spec.rb +192 -0
  46. data/spec/integration/associations/embedded_spec.rb +62 -0
  47. data/spec/integration/criteria/time_with_zone_spec.rb +32 -0
  48. data/spec/integration/document_spec.rb +22 -0
  49. data/spec/integration/matchable_spec.rb +680 -0
  50. data/spec/lite_spec_helper.rb +15 -5
  51. data/spec/mongoid/association/embedded/embedded_in_spec.rb +58 -0
  52. data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
  53. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  54. data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +6 -0
  55. data/spec/mongoid/association/embedded/embeds_one_models.rb +51 -0
  56. data/spec/mongoid/association/embedded/embeds_one_spec.rb +46 -0
  57. data/spec/mongoid/association/referenced/belongs_to_spec.rb +23 -6
  58. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +2 -1
  59. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  60. data/spec/mongoid/association/referenced/has_one_spec.rb +12 -2
  61. data/spec/mongoid/attributes/dynamic_spec.rb +153 -0
  62. data/spec/mongoid/attributes_spec.rb +19 -7
  63. data/spec/mongoid/clients/factory_spec.rb +2 -2
  64. data/spec/mongoid/clients/options_spec.rb +4 -4
  65. data/spec/mongoid/clients/sessions_spec.rb +20 -7
  66. data/spec/mongoid/clients/transactions_spec.rb +36 -15
  67. data/spec/mongoid/clients_spec.rb +2 -2
  68. data/spec/mongoid/contextual/atomic_spec.rb +20 -10
  69. data/spec/mongoid/contextual/geo_near_spec.rb +1 -0
  70. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  71. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  72. data/spec/mongoid/criteria/modifiable_spec.rb +59 -10
  73. data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +54 -0
  74. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  75. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  76. data/spec/mongoid/criteria/queryable/key_spec.rb +48 -6
  77. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +762 -0
  78. data/spec/mongoid/criteria/queryable/selectable_spec.rb +5 -224
  79. data/spec/mongoid/criteria/queryable/selector_spec.rb +37 -0
  80. data/spec/mongoid/criteria_spec.rb +7 -2
  81. data/spec/mongoid/document_fields_spec.rb +88 -0
  82. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  83. data/spec/mongoid/extensions/string_spec.rb +35 -7
  84. data/spec/mongoid/indexable_spec.rb +6 -4
  85. data/spec/mongoid/matchable/default_spec.rb +10 -3
  86. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  87. data/spec/mongoid/matchable_spec.rb +2 -2
  88. data/spec/mongoid/persistable/pushable_spec.rb +55 -1
  89. data/spec/mongoid/query_cache_spec.rb +2 -1
  90. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  91. data/spec/mongoid/scopable_spec.rb +2 -1
  92. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  93. data/spec/mongoid/tasks/database_spec.rb +1 -1
  94. data/spec/mongoid/validatable/uniqueness_spec.rb +33 -6
  95. data/spec/spec_helper.rb +4 -37
  96. data/spec/support/child_process_helper.rb +76 -0
  97. data/spec/support/cluster_config.rb +158 -0
  98. data/spec/support/constraints.rb +29 -19
  99. data/spec/support/expectations.rb +17 -3
  100. data/spec/support/spec_config.rb +12 -4
  101. metadata +525 -464
  102. metadata.gz.sig +2 -0
@@ -1346,10 +1346,16 @@ describe Mongoid::Attributes do
1346
1346
  context "when attribute is a Hash" do
1347
1347
  let(:person) { Person.new map: { somekey: "somevalue" } }
1348
1348
 
1349
- it "raises an error when try to set an invalid value" do
1350
- expect {
1349
+ it "raises an error when trying to set a value of invalid type - array" do
1350
+ expect do
1351
1351
  person.map = []
1352
- }.to raise_error(Mongoid::Errors::InvalidValue)
1352
+ end.to raise_error(Mongoid::Errors::InvalidValue, /Value of type Array cannot be written to a field of type Hash/)
1353
+ end
1354
+
1355
+ it "raises an error when trying to set a value of invalid type - boolean" do
1356
+ expect do
1357
+ person.map = false
1358
+ end.to raise_error(Mongoid::Errors::InvalidValue, /Value of type FalseClass cannot be written to a field of type Hash/)
1353
1359
  end
1354
1360
 
1355
1361
  it "can set a Hash value" do
@@ -1364,10 +1370,16 @@ describe Mongoid::Attributes do
1364
1370
  expect(person.aliases).to eq([ :alias_1 ])
1365
1371
  end
1366
1372
 
1367
- it "raises an error when try to set an invalid value" do
1368
- expect {
1373
+ it "raises an error when trying to set a value of invalid type - hash" do
1374
+ expect do
1369
1375
  person.aliases = {}
1370
- }.to raise_error(Mongoid::Errors::InvalidValue)
1376
+ end.to raise_error(Mongoid::Errors::InvalidValue, /Value of type Hash cannot be written to a field of type Array/)
1377
+ end
1378
+
1379
+ it "raises an error when trying to set a value of invalid type - boolean" do
1380
+ expect do
1381
+ person.aliases = false
1382
+ end.to raise_error(Mongoid::Errors::InvalidValue, /Value of type FalseClass cannot be written to a field of type Array/)
1371
1383
  end
1372
1384
  end
1373
1385
 
@@ -1422,7 +1434,7 @@ describe Mongoid::Attributes do
1422
1434
  end
1423
1435
 
1424
1436
  describe "#typed_attributes" do
1425
-
1437
+
1426
1438
  let(:date_time) do
1427
1439
  DateTime.current
1428
1440
  end
@@ -132,8 +132,8 @@ describe Mongoid::Clients::Factory do
132
132
 
133
133
  let(:config) do
134
134
  {
135
- default: { hosts: [ "127.0.0.1:1234" ], database: database_id },
136
- secondary: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test" }
135
+ default: { hosts: [ "127.0.0.1:1234" ], database: database_id, server_selection_timeout: 1 },
136
+ secondary: { uri: "mongodb://127.0.0.1:1234,127.0.0.1:5678/mongoid_test?serverSelectionTimeoutMS=1000" }
137
137
  }
138
138
  end
139
139
 
@@ -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']
@@ -16,22 +16,32 @@ describe Mongoid::Clients::Sessions do
16
16
  end
17
17
 
18
18
  let(:subscriber) do
19
- Mongoid::Clients.with_name(:other).send(:monitoring).subscribers['Command'].find do |s|
19
+ client = Mongoid::Clients.with_name(:other)
20
+ monitoring = if client.respond_to?(:monitoring, true)
21
+ client.send(:monitoring)
22
+ else
23
+ # driver 2.5
24
+ client.instance_variable_get('@monitoring')
25
+ end
26
+ monitoring.subscribers['Command'].find do |s|
20
27
  s.is_a?(EventSubscriber)
21
28
  end
22
29
  end
23
30
 
24
31
  let(:insert_events) do
25
- subscriber.started_events.select { |event| event.command_name == 'insert' }
32
+ # Driver 2.5 sends command_name as a symbol
33
+ subscriber.started_events.select { |event| event.command_name.to_s == 'insert' }
26
34
  end
27
35
 
28
36
  let(:update_events) do
29
- subscriber.started_events.select { |event| event.command_name == 'update' }
37
+ # Driver 2.5 sends command_name as a symbol
38
+ subscriber.started_events.select { |event| event.command_name.to_s == 'update' }
30
39
  end
31
40
 
32
41
  context 'when a session is used on a model class' do
33
42
 
34
- context 'when sessions are supported', if: sessions_supported? do
43
+ context 'when sessions are supported' do
44
+ min_server_version '3.6'
35
45
 
36
46
  around do |example|
37
47
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -160,7 +170,8 @@ describe Mongoid::Clients::Sessions do
160
170
  end
161
171
  end
162
172
 
163
- context 'when sessions are not supported', unless: sessions_supported? do
173
+ context 'when sessions are not supported' do
174
+ max_server_version '3.4'
164
175
 
165
176
  let!(:error) do
166
177
  e = nil
@@ -187,7 +198,8 @@ describe Mongoid::Clients::Sessions do
187
198
  end
188
199
  end
189
200
 
190
- context 'when sessions are supported', if: sessions_supported? do
201
+ context 'when sessions are supported' do
202
+ min_server_version '3.6'
191
203
 
192
204
  around do |example|
193
205
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -304,7 +316,8 @@ describe Mongoid::Clients::Sessions do
304
316
  end
305
317
  end
306
318
 
307
- context 'when sessions are not supported', unless: sessions_supported? do
319
+ context 'when sessions are not supported' do
320
+ max_server_version '3.4'
308
321
 
309
322
  let!(:error) do
310
323
  e = nil
@@ -1,18 +1,27 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Mongoid::Clients::Sessions do
4
+ before(:all) do
5
+ unless Mongo::VERSION >= '2.6'
6
+ skip 'Driver does not support transactions'
7
+ end
8
+ end
4
9
 
5
10
  before(:all) do
6
- CONFIG[:clients][:other] = CONFIG[:clients][:default].dup
7
- CONFIG[:clients][:other][:database] = 'other'
8
- Mongoid::Clients.clients.values.each(&:close)
9
- Mongoid::Config.send(:clients=, CONFIG[:clients])
10
- Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new)
11
+ if Mongo::VERSION >= '2.6'
12
+ CONFIG[:clients][:other] = CONFIG[:clients][:default].dup
13
+ CONFIG[:clients][:other][:database] = 'other'
14
+ Mongoid::Clients.clients.values.each(&:close)
15
+ Mongoid::Config.send(:clients=, CONFIG[:clients])
16
+ Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new)
17
+ end
11
18
  end
12
19
 
13
20
  after(:all) do
14
- Mongoid::Clients.with_name(:other).close
15
- Mongoid::Clients.clients.delete(:other)
21
+ if Mongo::VERSION >= '2.6'
22
+ Mongoid::Clients.with_name(:other).close
23
+ Mongoid::Clients.clients.delete(:other)
24
+ end
16
25
  end
17
26
 
18
27
  let(:subscriber) do
@@ -43,7 +52,8 @@ describe Mongoid::Clients::Sessions do
43
52
 
44
53
  context 'when a transaction is used on a model class' do
45
54
 
46
- context 'when transactions are supported', if: testing_transactions? do
55
+ context 'when transactions are supported' do
56
+ require_transaction_support
47
57
 
48
58
  around do |example|
49
59
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -179,7 +189,10 @@ describe Mongoid::Clients::Sessions do
179
189
  end
180
190
  end
181
191
 
182
- 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'
183
196
 
184
197
  let!(:error) do
185
198
  e = nil
@@ -210,7 +223,8 @@ describe Mongoid::Clients::Sessions do
210
223
  end
211
224
  end
212
225
 
213
- context 'when transactions are supported', if: testing_transactions? do
226
+ context 'when transactions are supported' do
227
+ require_transaction_support
214
228
 
215
229
  around do |example|
216
230
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
@@ -333,16 +347,23 @@ describe Mongoid::Clients::Sessions do
333
347
  end
334
348
  end
335
349
 
336
- 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'
337
354
 
338
355
  around do |example|
339
356
  Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
340
357
  Mongoid::Clients.with_name(:other).command(create: :people)
341
- subscriber.clear_events!
342
- person.with(client: :other) do
343
- 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)
344
366
  end
345
- Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
346
367
  end
347
368
 
348
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)
@@ -1,6 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Mongoid::Contextual::GeoNear do
4
+ max_server_version '4.0'
4
5
 
5
6
  describe "#average_distance" do
6
7
 
@@ -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