mongoid 7.0.7 → 7.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/mongoid.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_one.rb +2 -1
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/atomic.rb +13 -3
- data/lib/mongoid/criteria.rb +7 -1
- data/lib/mongoid/criteria/modifiable.rb +2 -1
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +4 -2
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/fields.rb +2 -1
- data/lib/mongoid/matchable/regexp.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +4 -1
- data/lib/mongoid/persistence_context.rb +6 -6
- data/lib/mongoid/query_cache.rb +2 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/integration/app_spec.rb +192 -0
- data/spec/integration/associations/embedded_spec.rb +62 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/lite_spec_helper.rb +11 -4
- data/spec/mongoid/association/embedded/embeds_many_models.rb +53 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +10 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +0 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +2 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
- data/spec/mongoid/clients/options_spec.rb +4 -4
- data/spec/mongoid/clients/sessions_spec.rb +8 -4
- data/spec/mongoid/clients/transactions_spec.rb +20 -8
- data/spec/mongoid/clients_spec.rb +2 -2
- data/spec/mongoid/contextual/atomic_spec.rb +20 -10
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
- data/spec/mongoid/contextual/mongo_spec.rb +76 -53
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +1 -1
- data/spec/mongoid/criteria_spec.rb +4 -2
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/indexable_spec.rb +6 -4
- data/spec/mongoid/matchable/default_spec.rb +1 -1
- data/spec/mongoid/matchable/regexp_spec.rb +2 -2
- data/spec/mongoid/matchable_spec.rb +2 -2
- data/spec/mongoid/query_cache_spec.rb +2 -1
- data/spec/mongoid/relations/proxy_spec.rb +1 -1
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -31
- data/spec/support/child_process_helper.rb +76 -0
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +29 -19
- data/spec/support/spec_config.rb +12 -4
- metadata +16 -2
- metadata.gz.sig +2 -2
@@ -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
|
-
|
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
|
-
|
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'
|
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'
|
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"
|
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'
|
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'
|
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'
|
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'
|
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'
|
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'
|
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'
|
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'
|
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'
|
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(
|
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
|
-
|
1594
|
-
|
1595
|
-
end
|
1606
|
+
context 'when statistics are available' do
|
1607
|
+
max_server_version '4.2'
|
1596
1608
|
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
})
|
1601
|
-
end
|
1609
|
+
it "contains the execution time" do
|
1610
|
+
expect(results.time).to_not be_nil
|
1611
|
+
end
|
1602
1612
|
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
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
|
-
|
1608
|
-
|
1609
|
-
|
1619
|
+
it "contains the input count" do
|
1620
|
+
expect(results.input).to eq(2)
|
1621
|
+
end
|
1610
1622
|
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1623
|
+
it "contains the emitted count" do
|
1624
|
+
expect(results.emitted).to eq(2)
|
1625
|
+
end
|
1614
1626
|
|
1615
|
-
|
1616
|
-
|
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(
|
1662
|
+
expect(ordered_results).to eq([
|
1646
1663
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }}
|
1647
1664
|
])
|
1648
1665
|
end
|
1649
1666
|
|
1650
|
-
|
1651
|
-
|
1652
|
-
end
|
1667
|
+
context 'when statistics are available' do
|
1668
|
+
max_server_version '4.2'
|
1653
1669
|
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
})
|
1658
|
-
end
|
1670
|
+
it "contains the execution time" do
|
1671
|
+
expect(results.time).to_not be_nil
|
1672
|
+
end
|
1659
1673
|
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
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
|
-
|
1665
|
-
|
1666
|
-
|
1680
|
+
it "contains the input count" do
|
1681
|
+
expect(results.input).to eq(1)
|
1682
|
+
end
|
1667
1683
|
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1684
|
+
it "contains the emitted count" do
|
1685
|
+
expect(results.emitted).to eq(1)
|
1686
|
+
end
|
1671
1687
|
|
1672
|
-
|
1673
|
-
|
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(
|
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'
|
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'
|
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'
|
2397
|
+
context 'when the criteria has a selector' do
|
2375
2398
|
|
2376
2399
|
before do
|
2377
2400
|
Artist.index(name: "text")
|
@@ -8,7 +8,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
8
8
|
context "when provided a regexp" do
|
9
9
|
|
10
10
|
let(:regexp) do
|
11
|
-
|
11
|
+
/\A[123]/
|
12
12
|
end
|
13
13
|
|
14
14
|
let(:evolved) do
|
@@ -23,7 +23,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
23
23
|
context "when provided a string" do
|
24
24
|
|
25
25
|
let(:regexp) do
|
26
|
-
"
|
26
|
+
"\\A[123]"
|
27
27
|
end
|
28
28
|
|
29
29
|
let(:evolved) do
|
@@ -31,7 +31,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns the converted regexp" do
|
34
|
-
expect(evolved).to eq(
|
34
|
+
expect(evolved).to eq(/\A[123]/)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -40,7 +40,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
40
40
|
context "when the elements are regexps" do
|
41
41
|
|
42
42
|
let(:regexp) do
|
43
|
-
|
43
|
+
/\A[123]/
|
44
44
|
end
|
45
45
|
|
46
46
|
let(:array) do
|
@@ -63,7 +63,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
63
63
|
context "when the elements are strings" do
|
64
64
|
|
65
65
|
let(:regexp) do
|
66
|
-
"
|
66
|
+
"\\A[123]"
|
67
67
|
end
|
68
68
|
|
69
69
|
let(:evolved) do
|
@@ -71,7 +71,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it "returns the regexps" do
|
74
|
-
expect(evolved).to eq([
|
74
|
+
expect(evolved).to eq([ /\A[123]/ ])
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -80,7 +80,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
80
80
|
describe "#regexp?" do
|
81
81
|
|
82
82
|
let(:regexp) do
|
83
|
-
|
83
|
+
/\A[123]/
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns true" do
|
@@ -2334,7 +2334,7 @@ describe Mongoid::Criteria do
|
|
2334
2334
|
end
|
2335
2335
|
|
2336
2336
|
it "returns the map/reduce results" do
|
2337
|
-
expect(map_reduce).to eq([
|
2337
|
+
expect(map_reduce.sort_by { |doc| doc['_id'] }).to eq([
|
2338
2338
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
|
2339
2339
|
{ "_id" => "Tool", "value" => { "likes" => 100 }}
|
2340
2340
|
])
|
@@ -3499,7 +3499,8 @@ describe Mongoid::Criteria do
|
|
3499
3499
|
end
|
3500
3500
|
end
|
3501
3501
|
|
3502
|
-
context "when querying on a BSON::Decimal128"
|
3502
|
+
context "when querying on a BSON::Decimal128" do
|
3503
|
+
min_server_version '3.4'
|
3503
3504
|
|
3504
3505
|
let(:decimal) do
|
3505
3506
|
BSON::Decimal128.new("0.0005")
|
@@ -3553,6 +3554,7 @@ describe Mongoid::Criteria do
|
|
3553
3554
|
end
|
3554
3555
|
|
3555
3556
|
context "when the code has scope" do
|
3557
|
+
max_server_version '4.2'
|
3556
3558
|
|
3557
3559
|
let(:criteria) do
|
3558
3560
|
Band.for_js("this.name == param", param: "Depeche Mode")
|