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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +6 -6
- data/README.md +1 -1
- data/Rakefile +14 -5
- data/lib/config/locales/en.yml +5 -5
- data/lib/mongoid/association/accessors.rb +37 -2
- 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/association/referenced/belongs_to/binding.rb +1 -1
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +38 -2
- data/lib/mongoid/association/referenced/eager.rb +29 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +6 -1
- data/lib/mongoid/atomic.rb +13 -3
- data/lib/mongoid/clients/factory.rb +2 -2
- data/lib/mongoid/clients/options.rb +8 -8
- data/lib/mongoid/clients/sessions.rb +20 -4
- data/lib/mongoid/clients/storage_options.rb +5 -5
- data/lib/mongoid/config.rb +39 -9
- data/lib/mongoid/criteria.rb +23 -4
- 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 +6 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +75 -8
- data/lib/mongoid/criteria/queryable/pipeline.rb +3 -2
- data/lib/mongoid/criteria/queryable/selectable.rb +120 -13
- data/lib/mongoid/criteria/queryable/storable.rb +104 -99
- data/lib/mongoid/errors/eager_load.rb +2 -0
- data/lib/mongoid/errors/no_client_config.rb +2 -2
- data/lib/mongoid/errors/no_default_client.rb +1 -1
- 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/fields/validators/macro.rb +4 -1
- data/lib/mongoid/matchable/regexp.rb +2 -2
- data/lib/mongoid/persistable/pushable.rb +11 -2
- data/lib/mongoid/persistence_context.rb +6 -6
- data/lib/mongoid/query_cache.rb +61 -18
- data/lib/mongoid/serializable.rb +9 -3
- data/lib/mongoid/tasks/database.rb +38 -3
- data/lib/mongoid/validatable/uniqueness.rb +1 -1
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +32 -23
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/app/models/coding.rb +4 -0
- data/spec/app/models/coding/pull_request.rb +12 -0
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/app/models/passport.rb +1 -0
- data/spec/app/models/person.rb +2 -0
- data/spec/app/models/phone.rb +1 -0
- data/spec/app/models/publication.rb +5 -0
- data/spec/app/models/publication/encyclopedia.rb +12 -0
- data/spec/app/models/publication/review.rb +14 -0
- data/spec/app/models/series.rb +1 -0
- data/spec/app/models/wiki_page.rb +1 -0
- data/spec/integration/app_spec.rb +254 -0
- data/spec/integration/associations/embedded_spec.rb +54 -0
- data/spec/integration/associations/embeds_many_spec.rb +24 -0
- data/spec/integration/associations/embeds_one_spec.rb +24 -0
- data/spec/integration/associations/has_many_spec.rb +76 -0
- data/spec/integration/associations/has_one_spec.rb +76 -0
- data/spec/integration/bson_regexp_raw_spec.rb +20 -0
- data/spec/integration/criteria/date_field_spec.rb +41 -0
- data/spec/integration/criteria/logical_spec.rb +13 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/integration/shardable_spec.rb +20 -4
- data/spec/lite_spec_helper.rb +12 -4
- data/spec/mongoid/association/accessors_spec.rb +238 -63
- data/spec/mongoid/association/embedded/embeds_many_models.rb +19 -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/belongs_to/eager_spec.rb +193 -10
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +140 -1
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +105 -0
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +2 -1
- data/spec/mongoid/clients/factory_spec.rb +8 -8
- data/spec/mongoid/clients/options_spec.rb +11 -11
- 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 +22 -11
- data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
- 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_raw_spec.rb +1 -1
- 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/queryable/extensions/time_spec.rb +19 -7
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +45 -12
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1051 -392
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +80 -2
- data/spec/mongoid/criteria_spec.rb +36 -2
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/errors/no_client_config_spec.rb +2 -2
- data/spec/mongoid/errors/no_client_database_spec.rb +3 -3
- data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -3
- data/spec/mongoid/fields_spec.rb +24 -1
- 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/persistable/pushable_spec.rb +55 -1
- data/spec/mongoid/query_cache_spec.rb +77 -9
- data/spec/mongoid/relations/proxy_spec.rb +1 -1
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/serializable_spec.rb +129 -18
- data/spec/mongoid/shardable_models.rb +1 -1
- data/spec/mongoid/shardable_spec.rb +2 -2
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +211 -0
- data/spec/shared/lib/mrss/constraints.rb +312 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +175 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +149 -0
- data/spec/spec_helper.rb +2 -31
- data/spec/support/child_process_helper.rb +76 -0
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +26 -10
- data/spec/support/expectations.rb +3 -1
- data/spec/support/helpers.rb +11 -0
- data/spec/support/session_registry.rb +50 -0
- data/spec/support/spec_config.rb +12 -4
- metadata +520 -473
- metadata.gz.sig +0 -0
|
@@ -171,7 +171,8 @@ describe Mongoid::Contextual::Mongo do
|
|
|
171
171
|
end
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
-
context 'when a collation is specified'
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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'
|
|
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(
|
|
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
|
-
|
|
1597
|
-
|
|
1598
|
-
end
|
|
1609
|
+
context 'when statistics are available' do
|
|
1610
|
+
max_server_version '4.2'
|
|
1599
1611
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
})
|
|
1604
|
-
end
|
|
1612
|
+
it "contains the execution time" do
|
|
1613
|
+
expect(results.time).to_not be_nil
|
|
1614
|
+
end
|
|
1605
1615
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
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
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1622
|
+
it "contains the input count" do
|
|
1623
|
+
expect(results.input).to eq(2)
|
|
1624
|
+
end
|
|
1613
1625
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1626
|
+
it "contains the emitted count" do
|
|
1627
|
+
expect(results.emitted).to eq(2)
|
|
1628
|
+
end
|
|
1617
1629
|
|
|
1618
|
-
|
|
1619
|
-
|
|
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(
|
|
1665
|
+
expect(ordered_results).to eq([
|
|
1649
1666
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }}
|
|
1650
1667
|
])
|
|
1651
1668
|
end
|
|
1652
1669
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
end
|
|
1670
|
+
context 'when statistics are available' do
|
|
1671
|
+
max_server_version '4.2'
|
|
1656
1672
|
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
})
|
|
1661
|
-
end
|
|
1673
|
+
it "contains the execution time" do
|
|
1674
|
+
expect(results.time).to_not be_nil
|
|
1675
|
+
end
|
|
1662
1676
|
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
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
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1683
|
+
it "contains the input count" do
|
|
1684
|
+
expect(results.input).to eq(1)
|
|
1685
|
+
end
|
|
1670
1686
|
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1687
|
+
it "contains the emitted count" do
|
|
1688
|
+
expect(results.emitted).to eq(1)
|
|
1689
|
+
end
|
|
1674
1690
|
|
|
1675
|
-
|
|
1676
|
-
|
|
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(
|
|
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'
|
|
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'
|
|
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'
|
|
2402
|
+
context 'when the criteria has a selector' do
|
|
2380
2403
|
|
|
2381
2404
|
before do
|
|
2382
2405
|
Artist.index(name: "text")
|
|
@@ -11,7 +11,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
11
11
|
context "when provided a regexp" do
|
|
12
12
|
|
|
13
13
|
let(:regexp) do
|
|
14
|
-
|
|
14
|
+
/\A[123]/
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
let(:evolved) do
|
|
@@ -26,7 +26,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
26
26
|
context "when provided a string" do
|
|
27
27
|
|
|
28
28
|
let(:regexp) do
|
|
29
|
-
"
|
|
29
|
+
"\\A[123]"
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
let(:evolved) do
|
|
@@ -34,7 +34,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "returns the converted regexp" do
|
|
37
|
-
expect(evolved).to eq(
|
|
37
|
+
expect(evolved).to eq(/\A[123]/)
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
43
43
|
context "when the elements are regexps" do
|
|
44
44
|
|
|
45
45
|
let(:regexp) do
|
|
46
|
-
|
|
46
|
+
/\A[123]/
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
let(:array) do
|
|
@@ -66,7 +66,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
66
66
|
context "when the elements are strings" do
|
|
67
67
|
|
|
68
68
|
let(:regexp) do
|
|
69
|
-
"
|
|
69
|
+
"\\A[123]"
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
let(:evolved) do
|
|
@@ -74,7 +74,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "returns the regexps" do
|
|
77
|
-
expect(evolved).to eq([
|
|
77
|
+
expect(evolved).to eq([ /\A[123]/ ])
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
end
|
|
@@ -83,7 +83,7 @@ describe Mongoid::Criteria::Queryable::Extensions::Regexp do
|
|
|
83
83
|
describe "#regexp?" do
|
|
84
84
|
|
|
85
85
|
let(:regexp) do
|
|
86
|
-
|
|
86
|
+
/\A[123]/
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
it "returns true" do
|
|
@@ -354,23 +354,35 @@ describe Time do
|
|
|
354
354
|
|
|
355
355
|
describe "#__evolve_date__" do
|
|
356
356
|
|
|
357
|
-
let(:time) do
|
|
358
|
-
Time.new(2010, 1, 1, 12, 0, 0)
|
|
359
|
-
end
|
|
360
|
-
|
|
361
357
|
let(:evolved) do
|
|
362
358
|
time.__evolve_date__
|
|
363
359
|
end
|
|
364
360
|
|
|
365
|
-
|
|
366
|
-
|
|
361
|
+
context 'beginning of day' do
|
|
362
|
+
let(:time) do
|
|
363
|
+
Time.new(2010, 1, 1, 0, 0, 1).freeze
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it "returns midnight utc" do
|
|
367
|
+
expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
|
|
371
|
+
context 'end of day' do
|
|
372
|
+
let(:time) do
|
|
373
|
+
Time.new(2010, 1, 1, 23, 59, 59).freeze
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
it "returns midnight utc" do
|
|
377
|
+
expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
|
|
378
|
+
end
|
|
367
379
|
end
|
|
368
380
|
end
|
|
369
381
|
|
|
370
382
|
describe "#__evolve_time__" do
|
|
371
383
|
|
|
372
384
|
let(:time) do
|
|
373
|
-
Time.new(2010, 1, 1, 12, 0, 0)
|
|
385
|
+
Time.new(2010, 1, 1, 12, 0, 0).freeze
|
|
374
386
|
end
|
|
375
387
|
|
|
376
388
|
let(:evolved) do
|
|
@@ -325,10 +325,37 @@ describe ActiveSupport::TimeWithZone do
|
|
|
325
325
|
end
|
|
326
326
|
end
|
|
327
327
|
|
|
328
|
+
describe "#__evolve_date__" do
|
|
329
|
+
|
|
330
|
+
let(:evolved) do
|
|
331
|
+
time.__evolve_date__
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
context 'beginning of day' do
|
|
335
|
+
let(:time) do
|
|
336
|
+
time_zone.local(2010, 1, 1, 0, 0, 1).freeze
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
it "returns midnight utc" do
|
|
340
|
+
expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
context 'end of day' do
|
|
345
|
+
let(:time) do
|
|
346
|
+
time_zone.local(2010, 1, 1, 23, 59, 59).freeze
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
it "returns midnight utc" do
|
|
350
|
+
expect(evolved).to eq(Time.utc(2010, 1, 1, 0, 0, 0))
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
328
355
|
describe "#__evolve_time__" do
|
|
329
356
|
|
|
330
357
|
let(:date) do
|
|
331
|
-
time_zone.local(2010, 1, 1, 12, 0, 0)
|
|
358
|
+
time_zone.local(2010, 1, 1, 12, 0, 0).freeze
|
|
332
359
|
end
|
|
333
360
|
|
|
334
361
|
let(:evolved) do
|
|
@@ -5,11 +5,11 @@ require "spec_helper"
|
|
|
5
5
|
|
|
6
6
|
describe Mongoid::Criteria::Queryable::Mergeable do
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let(:query) do
|
|
9
|
+
Mongoid::Query.new
|
|
10
|
+
end
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
Mongoid::Query.new
|
|
12
|
-
end
|
|
12
|
+
describe "#intersect" do
|
|
13
13
|
|
|
14
14
|
before do
|
|
15
15
|
query.intersect
|
|
@@ -22,10 +22,6 @@ describe Mongoid::Criteria::Queryable::Mergeable do
|
|
|
22
22
|
|
|
23
23
|
describe "#override" do
|
|
24
24
|
|
|
25
|
-
let(:query) do
|
|
26
|
-
Mongoid::Query.new
|
|
27
|
-
end
|
|
28
|
-
|
|
29
25
|
before do
|
|
30
26
|
query.override
|
|
31
27
|
end
|
|
@@ -37,10 +33,6 @@ describe Mongoid::Criteria::Queryable::Mergeable do
|
|
|
37
33
|
|
|
38
34
|
describe "#union" do
|
|
39
35
|
|
|
40
|
-
let(:query) do
|
|
41
|
-
Mongoid::Query.new
|
|
42
|
-
end
|
|
43
|
-
|
|
44
36
|
before do
|
|
45
37
|
query.union
|
|
46
38
|
end
|
|
@@ -49,4 +41,45 @@ describe Mongoid::Criteria::Queryable::Mergeable do
|
|
|
49
41
|
expect(query.strategy).to eq(:__union__)
|
|
50
42
|
end
|
|
51
43
|
end
|
|
44
|
+
|
|
45
|
+
describe '#_mongoid_expand_keys' do
|
|
46
|
+
it 'expands simple keys' do
|
|
47
|
+
query.send(:_mongoid_expand_keys, {a: 1}).should == {a: 1}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
let(:gt) do
|
|
51
|
+
Mongoid::Criteria::Queryable::Key.new("age", :__override__, "$gt")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
let(:gtp) do
|
|
55
|
+
Mongoid::Criteria::Queryable::Key.new("age", :__override__, "$gt")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
let(:lt) do
|
|
59
|
+
Mongoid::Criteria::Queryable::Key.new("age", :__override__, "$lt")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'expands Key instances' do
|
|
63
|
+
query.send(:_mongoid_expand_keys, {gt => 42}).should == {'age' => {'$gt' => 42}}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'expands multiple Key instances on the same field' do
|
|
67
|
+
query.send(:_mongoid_expand_keys, {gt => 42, lt => 50}).should == {
|
|
68
|
+
'age' => {'$gt' => 42, '$lt' => 50}}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'expands simple and Key instances on the same field' do
|
|
72
|
+
query.send(:_mongoid_expand_keys, {'age' => 42, lt => 50}).should == {
|
|
73
|
+
'age' => {'$eq' => 42, '$lt' => 50}}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'expands Key and simple instances on the same field' do
|
|
77
|
+
query.send(:_mongoid_expand_keys, {gt => 42, 'age' => 50}).should == {
|
|
78
|
+
'age' => {'$gt' => 42, '$eq' => 50}}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'Ruby does not allow same symbol operator with different values' do
|
|
82
|
+
{gt => 42, gtp => 50}.should == {gtp => 50}
|
|
83
|
+
end
|
|
84
|
+
end
|
|
52
85
|
end
|