mongoid 7.1.1 → 7.1.2

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 (63) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
  5. data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
  6. data/lib/mongoid/association/proxy.rb +1 -1
  7. data/lib/mongoid/atomic.rb +13 -3
  8. data/lib/mongoid/criteria.rb +7 -1
  9. data/lib/mongoid/criteria/modifiable.rb +2 -1
  10. data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
  11. data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
  12. data/lib/mongoid/criteria/queryable/mergeable.rb +75 -8
  13. data/lib/mongoid/criteria/queryable/selectable.rb +28 -8
  14. data/lib/mongoid/extensions/hash.rb +4 -2
  15. data/lib/mongoid/extensions/regexp.rb +1 -1
  16. data/lib/mongoid/fields.rb +2 -1
  17. data/lib/mongoid/matchable/regexp.rb +2 -2
  18. data/lib/mongoid/persistable/pushable.rb +4 -1
  19. data/lib/mongoid/persistence_context.rb +6 -6
  20. data/lib/mongoid/query_cache.rb +2 -1
  21. data/lib/mongoid/validatable/uniqueness.rb +1 -1
  22. data/lib/mongoid/version.rb +1 -1
  23. data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
  24. data/spec/integration/app_spec.rb +192 -0
  25. data/spec/integration/associations/embedded_spec.rb +54 -0
  26. data/spec/integration/criteria/logical_spec.rb +13 -0
  27. data/spec/lite_spec_helper.rb +11 -4
  28. data/spec/mongoid/association/embedded/embeds_many_models.rb +19 -0
  29. data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
  30. data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
  31. data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +2 -1
  32. data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
  33. data/spec/mongoid/clients/options_spec.rb +2 -2
  34. data/spec/mongoid/clients/sessions_spec.rb +8 -4
  35. data/spec/mongoid/clients/transactions_spec.rb +20 -8
  36. data/spec/mongoid/clients_spec.rb +2 -2
  37. data/spec/mongoid/contextual/atomic_spec.rb +22 -11
  38. data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
  39. data/spec/mongoid/contextual/mongo_spec.rb +76 -53
  40. data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
  41. data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
  42. data/spec/mongoid/criteria/queryable/mergeable_spec.rb +45 -12
  43. data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +480 -198
  44. data/spec/mongoid/criteria_spec.rb +4 -2
  45. data/spec/mongoid/document_persistence_context_spec.rb +33 -0
  46. data/spec/mongoid/indexable_spec.rb +6 -4
  47. data/spec/mongoid/matchable/default_spec.rb +1 -1
  48. data/spec/mongoid/matchable/regexp_spec.rb +2 -2
  49. data/spec/mongoid/matchable_spec.rb +2 -2
  50. data/spec/mongoid/query_cache_spec.rb +2 -1
  51. data/spec/mongoid/relations/proxy_spec.rb +1 -1
  52. data/spec/mongoid/scopable_spec.rb +2 -1
  53. data/spec/mongoid/shardable_models.rb +1 -1
  54. data/spec/mongoid/shardable_spec.rb +2 -2
  55. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  56. data/spec/mongoid/tasks/database_spec.rb +1 -1
  57. data/spec/spec_helper.rb +0 -31
  58. data/spec/support/child_process_helper.rb +76 -0
  59. data/spec/support/cluster_config.rb +3 -3
  60. data/spec/support/constraints.rb +26 -10
  61. data/spec/support/spec_config.rb +12 -4
  62. metadata +8 -2
  63. metadata.gz.sig +0 -0
@@ -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)
@@ -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
@@ -171,7 +171,8 @@ describe Mongoid::Contextual::Mongo do
171
171
  end
172
172
  end
173
173
 
174
- context 'when a collation is specified', if: collation_supported? do
174
+ context 'when a collation is specified' do
175
+ min_server_version '3.4'
175
176
 
176
177
  let(:context) do
177
178
  described_class.new(criteria)
@@ -232,7 +233,8 @@ describe Mongoid::Contextual::Mongo do
232
233
  expect(deleted).to eq(1)
233
234
  end
234
235
 
235
- context 'when the criteria has a collation', if: collation_supported? do
236
+ context 'when the criteria has a collation' do
237
+ min_server_version '3.4'
236
238
 
237
239
  let(:criteria) do
238
240
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -336,7 +338,8 @@ describe Mongoid::Contextual::Mongo do
336
338
  expect(destroyed).to eq(1)
337
339
  end
338
340
 
339
- context 'when the criteria has a collation', if: collation_supported? do
341
+ context 'when the criteria has a collation' do
342
+ min_server_version '3.4'
340
343
 
341
344
  let(:criteria) do
342
345
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -458,7 +461,8 @@ describe Mongoid::Contextual::Mongo do
458
461
  end
459
462
  end
460
463
 
461
- context 'when a collation is specified', if: collation_supported? do
464
+ context 'when a collation is specified' do
465
+ min_server_version '3.4'
462
466
 
463
467
  before do
464
468
  Band.create(name: 'DEPECHE MODE')
@@ -496,7 +500,8 @@ describe Mongoid::Contextual::Mongo do
496
500
  described_class.new(criteria)
497
501
  end
498
502
 
499
- context 'when the criteria has a collation', if: collation_supported? do
503
+ context 'when the criteria has a collation' do
504
+ min_server_version '3.4'
500
505
 
501
506
  let(:criteria) do
502
507
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -853,7 +858,8 @@ describe Mongoid::Contextual::Mongo do
853
858
  end
854
859
  end
855
860
 
856
- context 'when a collation is specified on the criteria', if: collation_supported? do
861
+ context 'when a collation is specified on the criteria' do
862
+ min_server_version '3.4'
857
863
 
858
864
  let(:criteria) do
859
865
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1006,7 +1012,8 @@ describe Mongoid::Contextual::Mongo do
1006
1012
  end
1007
1013
  end
1008
1014
 
1009
- context 'when a collation is specified on the criteria', if: collation_supported? do
1015
+ context 'when a collation is specified on the criteria' do
1016
+ min_server_version '3.4'
1010
1017
 
1011
1018
  let(:criteria) do
1012
1019
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1080,7 +1087,8 @@ describe Mongoid::Contextual::Mongo do
1080
1087
  }.to raise_error(Mongoid::Errors::DocumentNotFound)
1081
1088
  end
1082
1089
 
1083
- context 'when a collation is specified on the criteria', if: collation_supported? do
1090
+ context 'when a collation is specified on the criteria' do
1091
+ min_server_version '3.4'
1084
1092
 
1085
1093
  let(:criteria) do
1086
1094
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1152,7 +1160,8 @@ describe Mongoid::Contextual::Mongo do
1152
1160
  expect(context.send(method)).to eq(depeche_mode)
1153
1161
  end
1154
1162
 
1155
- context 'when the criteria has a collation', if: collation_supported? do
1163
+ context 'when the criteria has a collation' do
1164
+ min_server_version '3.4'
1156
1165
 
1157
1166
  let(:criteria) do
1158
1167
  Band.where(name: "DEPECHE MODE").collation(locale: 'en_US', strength: 2)
@@ -1556,6 +1565,10 @@ describe Mongoid::Contextual::Mongo do
1556
1565
  }}
1557
1566
  end
1558
1567
 
1568
+ let(:ordered_results) do
1569
+ results['results'].sort_by { |doc| doc['_id'] }
1570
+ end
1571
+
1559
1572
  context "when no selection is provided" do
1560
1573
 
1561
1574
  let(:criteria) do
@@ -1587,36 +1600,40 @@ describe Mongoid::Contextual::Mongo do
1587
1600
  end
1588
1601
 
1589
1602
  it "contains the entire raw results" do
1590
- expect(results["results"]).to eq([
1603
+ expect(ordered_results).to eq([
1591
1604
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
1592
1605
  { "_id" => "Tool", "value" => { "likes" => 100 }}
1593
1606
  ])
1594
1607
  end
1595
1608
 
1596
- it "contains the execution time" do
1597
- expect(results.time).to_not be_nil
1598
- end
1609
+ context 'when statistics are available' do
1610
+ max_server_version '4.2'
1599
1611
 
1600
- it "contains the count statistics" do
1601
- expect(results["counts"]).to eq({
1602
- "input" => 2, "emit" => 2, "reduce" => 0, "output" => 2
1603
- })
1604
- end
1612
+ it "contains the execution time" do
1613
+ expect(results.time).to_not be_nil
1614
+ end
1605
1615
 
1606
- it "contains the input count" do
1607
- expect(results.input).to eq(2)
1608
- end
1616
+ it "contains the count statistics" do
1617
+ expect(results["counts"]).to eq({
1618
+ "input" => 2, "emit" => 2, "reduce" => 0, "output" => 2
1619
+ })
1620
+ end
1609
1621
 
1610
- it "contains the emitted count" do
1611
- expect(results.emitted).to eq(2)
1612
- end
1622
+ it "contains the input count" do
1623
+ expect(results.input).to eq(2)
1624
+ end
1613
1625
 
1614
- it "contains the reduced count" do
1615
- expect(results.reduced).to eq(0)
1616
- end
1626
+ it "contains the emitted count" do
1627
+ expect(results.emitted).to eq(2)
1628
+ end
1617
1629
 
1618
- it "contains the output count" do
1619
- expect(results.output).to eq(2)
1630
+ it "contains the reduced count" do
1631
+ expect(results.reduced).to eq(0)
1632
+ end
1633
+
1634
+ it "contains the output count" do
1635
+ expect(results.output).to eq(2)
1636
+ end
1620
1637
  end
1621
1638
  end
1622
1639
 
@@ -1645,35 +1662,39 @@ describe Mongoid::Contextual::Mongo do
1645
1662
  end
1646
1663
 
1647
1664
  it "contains the entire raw results" do
1648
- expect(results["results"]).to eq([
1665
+ expect(ordered_results).to eq([
1649
1666
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }}
1650
1667
  ])
1651
1668
  end
1652
1669
 
1653
- it "contains the execution time" do
1654
- expect(results.time).to_not be_nil
1655
- end
1670
+ context 'when statistics are available' do
1671
+ max_server_version '4.2'
1656
1672
 
1657
- it "contains the count statistics" do
1658
- expect(results["counts"]).to eq({
1659
- "input" => 1, "emit" => 1, "reduce" => 0, "output" => 1
1660
- })
1661
- end
1673
+ it "contains the execution time" do
1674
+ expect(results.time).to_not be_nil
1675
+ end
1662
1676
 
1663
- it "contains the input count" do
1664
- expect(results.input).to eq(1)
1665
- end
1677
+ it "contains the count statistics" do
1678
+ expect(results["counts"]).to eq({
1679
+ "input" => 1, "emit" => 1, "reduce" => 0, "output" => 1
1680
+ })
1681
+ end
1666
1682
 
1667
- it "contains the emitted count" do
1668
- expect(results.emitted).to eq(1)
1669
- end
1683
+ it "contains the input count" do
1684
+ expect(results.input).to eq(1)
1685
+ end
1670
1686
 
1671
- it "contains the reduced count" do
1672
- expect(results.reduced).to eq(0)
1673
- end
1687
+ it "contains the emitted count" do
1688
+ expect(results.emitted).to eq(1)
1689
+ end
1674
1690
 
1675
- it "contains the output count" do
1676
- expect(results.output).to eq(1)
1691
+ it "contains the reduced count" do
1692
+ expect(results.reduced).to eq(0)
1693
+ end
1694
+
1695
+ it "contains the output count" do
1696
+ expect(results.output).to eq(1)
1697
+ end
1677
1698
  end
1678
1699
  end
1679
1700
 
@@ -1713,7 +1734,7 @@ describe Mongoid::Contextual::Mongo do
1713
1734
  end
1714
1735
 
1715
1736
  it "contains the entire raw results" do
1716
- expect(results["results"]).to eq([
1737
+ expect(ordered_results).to eq([
1717
1738
  { "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
1718
1739
  { "_id" => "Tool", "value" => { "likes" => 100 }}
1719
1740
  ])
@@ -2166,7 +2187,8 @@ describe Mongoid::Contextual::Mongo do
2166
2187
  end
2167
2188
  end
2168
2189
 
2169
- context 'when provided array filters', if: array_filters_supported? do
2190
+ context 'when provided array filters' do
2191
+ min_server_version '3.6'
2170
2192
 
2171
2193
  before do
2172
2194
  Band.delete_all
@@ -2338,7 +2360,8 @@ describe Mongoid::Contextual::Mongo do
2338
2360
  end
2339
2361
  end
2340
2362
 
2341
- context 'when provided array filters', if: array_filters_supported? do
2363
+ context 'when provided array filters' do
2364
+ min_server_version '3.6'
2342
2365
 
2343
2366
  before do
2344
2367
  Band.delete_all
@@ -2376,7 +2399,7 @@ describe Mongoid::Contextual::Mongo do
2376
2399
 
2377
2400
  describe '#pipeline' do
2378
2401
 
2379
- context 'when the criteria has a selector', if: non_legacy_server? do
2402
+ context 'when the criteria has a selector' do
2380
2403
 
2381
2404
  before do
2382
2405
  Artist.index(name: "text")