mongoid 5.4.0 → 6.4.8
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/README.md +3 -3
- data/Rakefile +26 -0
- data/lib/config/locales/en.yml +40 -0
- data/lib/mongoid/atomic/modifiers.rb +2 -2
- data/lib/mongoid/atomic.rb +5 -5
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/attributes.rb +22 -21
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +36 -0
- data/lib/mongoid/clients/options.rb +55 -250
- data/lib/mongoid/clients/sessions.rb +113 -0
- data/lib/mongoid/clients/storage_options.rb +2 -69
- data/lib/mongoid/clients.rb +10 -63
- data/lib/mongoid/composable.rb +29 -2
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
- data/lib/mongoid/contextual/atomic.rb +4 -4
- data/lib/mongoid/contextual/map_reduce.rb +7 -3
- data/lib/mongoid/contextual/memory.rb +9 -4
- data/lib/mongoid/contextual/mongo.rb +65 -30
- data/lib/mongoid/contextual/none.rb +12 -0
- data/lib/mongoid/copyable.rb +13 -6
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +29 -3
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +185 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +37 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +53 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +200 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +86 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +90 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +206 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +70 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +34 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +137 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +79 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +54 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +65 -0
- data/lib/mongoid/criteria/queryable/key.rb +103 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +27 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +273 -0
- data/lib/mongoid/criteria/queryable/optional.rb +429 -0
- data/lib/mongoid/criteria/queryable/options.rb +153 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +689 -0
- data/lib/mongoid/criteria/queryable/selector.rb +212 -0
- data/lib/mongoid/criteria/queryable/smash.rb +104 -0
- data/lib/mongoid/criteria/queryable.rb +87 -0
- data/lib/mongoid/criteria.rb +6 -2
- data/lib/mongoid/document.rb +34 -41
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -1
- data/lib/mongoid/errors/invalid_field.rb +2 -2
- data/lib/mongoid/errors/invalid_persistence_option.rb +29 -0
- data/lib/mongoid/errors/invalid_relation.rb +66 -0
- data/lib/mongoid/errors/invalid_session_use.rb +24 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/decimal128.rb +3 -3
- data/lib/mongoid/extensions/hash.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -0
- data/lib/mongoid/extensions/string.rb +6 -3
- data/lib/mongoid/extensions/time.rb +4 -1
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +2 -1
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +2 -2
- data/lib/mongoid/indexable.rb +16 -14
- data/lib/mongoid/interceptable.rb +9 -22
- data/lib/mongoid/matchable/all.rb +2 -2
- data/lib/mongoid/matchable/and.rb +3 -3
- data/lib/mongoid/matchable/default.rb +2 -2
- data/lib/mongoid/matchable/elem_match.rb +28 -0
- data/lib/mongoid/matchable/exists.rb +2 -2
- data/lib/mongoid/matchable/gt.rb +4 -2
- data/lib/mongoid/matchable/gte.rb +4 -2
- data/lib/mongoid/matchable/in.rb +2 -2
- data/lib/mongoid/matchable/lt.rb +4 -2
- data/lib/mongoid/matchable/lte.rb +4 -2
- data/lib/mongoid/matchable/ne.rb +2 -2
- data/lib/mongoid/matchable/nin.rb +2 -2
- data/lib/mongoid/matchable/nor.rb +37 -0
- data/lib/mongoid/matchable/or.rb +3 -3
- data/lib/mongoid/matchable/regexp.rb +3 -3
- data/lib/mongoid/matchable/size.rb +2 -2
- data/lib/mongoid/matchable.rb +16 -7
- data/lib/mongoid/persistable/creatable.rb +5 -3
- data/lib/mongoid/persistable/deletable.rb +5 -3
- data/lib/mongoid/persistable/destroyable.rb +1 -5
- data/lib/mongoid/persistable/settable.rb +5 -5
- data/lib/mongoid/persistable/updatable.rb +7 -14
- data/lib/mongoid/persistable/upsertable.rb +2 -1
- data/lib/mongoid/persistable.rb +4 -6
- data/lib/mongoid/persistence_context.rb +220 -0
- data/lib/mongoid/query_cache.rb +67 -23
- data/lib/mongoid/railtie.rb +17 -1
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/relations/accessors.rb +3 -0
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -4
- data/lib/mongoid/relations/counter_cache.rb +15 -5
- data/lib/mongoid/relations/eager/base.rb +3 -3
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +2 -2
- data/lib/mongoid/relations/eager/has_many.rb +1 -1
- data/lib/mongoid/relations/eager.rb +6 -11
- data/lib/mongoid/relations/embedded/batchable.rb +20 -18
- data/lib/mongoid/relations/embedded/in.rb +13 -1
- data/lib/mongoid/relations/embedded/many.rb +51 -10
- data/lib/mongoid/relations/embedded/one.rb +14 -1
- data/lib/mongoid/relations/macros.rb +9 -1
- data/lib/mongoid/relations/many.rb +4 -0
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +1 -31
- data/lib/mongoid/relations/referenced/in.rb +19 -10
- data/lib/mongoid/relations/referenced/many.rb +30 -26
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +15 -1
- data/lib/mongoid/relations/synchronization.rb +12 -12
- data/lib/mongoid/relations/targets/enumerable.rb +24 -4
- data/lib/mongoid/relations/touchable.rb +7 -4
- data/lib/mongoid/reloadable.rb +2 -2
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +1 -1
- data/lib/mongoid/stateful.rb +1 -0
- data/lib/mongoid/tasks/database.rb +3 -2
- data/lib/mongoid/threaded.rb +74 -0
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +6 -6
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +18 -3
- data/spec/app/models/agent.rb +2 -0
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/array_field.rb +7 -0
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +3 -0
- data/spec/app/models/book.rb +2 -1
- data/spec/app/models/delegating_patient.rb +16 -0
- data/spec/app/models/dokument.rb +1 -0
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/page.rb +1 -1
- data/spec/app/models/person.rb +3 -3
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/subscription.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +15 -0
- data/spec/integration/document_spec.rb +22 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +3 -3
- data/spec/mongoid/atomic_spec.rb +5 -5
- data/spec/mongoid/attributes/nested_spec.rb +18 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +90 -5
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +80 -28
- data/spec/mongoid/clients/options_spec.rb +396 -95
- data/spec/mongoid/clients/sessions_spec.rb +334 -0
- data/spec/mongoid/clients_spec.rb +243 -101
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +67 -11
- data/spec/mongoid/contextual/atomic_spec.rb +3 -3
- data/spec/mongoid/contextual/geo_near_spec.rb +1 -0
- data/spec/mongoid/contextual/mongo_spec.rb +275 -22
- data/spec/mongoid/contextual/none_spec.rb +15 -0
- data/spec/mongoid/copyable_spec.rb +13 -4
- data/spec/mongoid/criteria/modifiable_spec.rb +297 -16
- data/spec/mongoid/criteria/options_spec.rb +29 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +523 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +213 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +330 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +405 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +58 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +327 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +65 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +77 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +108 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +309 -0
- data/spec/mongoid/{extensions/origin → criteria/queryable/extensions}/regexp_raw_spec.rb +2 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +90 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +39 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +302 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +167 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +376 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +87 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +52 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +49 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1799 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +360 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +200 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +137 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +4242 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +844 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +156 -22
- data/spec/mongoid/document_spec.rb +100 -90
- data/spec/mongoid/errors/invalid_relation_spec.rb +37 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +6 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +321 -19
- data/spec/mongoid/extensions/boolean_spec.rb +14 -0
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +1 -1
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/hash_spec.rb +15 -0
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/regexp_spec.rb +23 -0
- data/spec/mongoid/extensions/string_spec.rb +53 -4
- data/spec/mongoid/extensions/time_spec.rb +2 -6
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/factory_spec.rb +11 -0
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/findable_spec.rb +47 -2
- data/spec/mongoid/indexable_spec.rb +15 -3
- data/spec/mongoid/interceptable_spec.rb +85 -19
- data/spec/mongoid/matchable/all_spec.rb +4 -4
- data/spec/mongoid/matchable/and_spec.rb +10 -10
- data/spec/mongoid/matchable/default_spec.rb +12 -12
- data/spec/mongoid/matchable/elem_match_spec.rb +86 -0
- data/spec/mongoid/matchable/exists_spec.rb +5 -5
- data/spec/mongoid/matchable/gt_spec.rb +18 -7
- data/spec/mongoid/matchable/gte_spec.rb +17 -7
- data/spec/mongoid/matchable/in_spec.rb +5 -5
- data/spec/mongoid/matchable/lt_spec.rb +18 -7
- data/spec/mongoid/matchable/lte_spec.rb +18 -7
- data/spec/mongoid/matchable/ne_spec.rb +5 -5
- data/spec/mongoid/matchable/nin_spec.rb +5 -5
- data/spec/mongoid/matchable/nor_spec.rb +209 -0
- data/spec/mongoid/matchable/or_spec.rb +7 -7
- data/spec/mongoid/matchable/regexp_spec.rb +5 -5
- data/spec/mongoid/matchable/size_spec.rb +3 -3
- data/spec/mongoid/matchable_spec.rb +199 -54
- data/spec/mongoid/persistable/creatable_spec.rb +7 -2
- data/spec/mongoid/persistable/deletable_spec.rb +35 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +25 -2
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +34 -29
- data/spec/mongoid/persistable/settable_spec.rb +77 -27
- data/spec/mongoid/persistable/updatable_spec.rb +182 -3
- data/spec/mongoid/persistable_spec.rb +16 -16
- data/spec/mongoid/persistence_context_spec.rb +694 -0
- data/spec/mongoid/positional_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +170 -12
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +4 -4
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -3
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +16 -0
- data/spec/mongoid/relations/eager_spec.rb +40 -0
- data/spec/mongoid/relations/embedded/many_spec.rb +305 -59
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +415 -7
- data/spec/mongoid/relations/metadata_spec.rb +15 -1
- data/spec/mongoid/relations/proxy_spec.rb +27 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +35 -25
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +14 -26
- data/spec/mongoid/relations/synchronization_spec.rb +48 -2
- data/spec/mongoid/relations/targets/enumerable_spec.rb +108 -0
- data/spec/mongoid/relations/touchable_spec.rb +40 -0
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +18 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +101 -8
- data/spec/support/cluster_config.rb +158 -0
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/session_registry.rb +50 -0
- data/spec/support/spec_config.rb +42 -0
- data.tar.gz.sig +0 -0
- metadata +163 -61
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/railties/document.rb +0 -12
- data/spec/mongoid/railties/document_spec.rb +0 -24
@@ -0,0 +1,327 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
describe "#__add__" do
|
6
|
+
|
7
|
+
context "when the other object is a hash" do
|
8
|
+
|
9
|
+
context "when a key matches" do
|
10
|
+
|
11
|
+
context "when the existing value is a non-enumerable" do
|
12
|
+
|
13
|
+
context "when the added value is non-enumerable" do
|
14
|
+
|
15
|
+
context "when the values are unique" do
|
16
|
+
|
17
|
+
let(:hash) do
|
18
|
+
{ "$in" => 5 }
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
hash.__add__({ "$in" => 6 })
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the new array" do
|
26
|
+
expect(hash).to eq({ "$in" => [ 5, 6 ] })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when the values are not unique" do
|
31
|
+
|
32
|
+
let(:hash) do
|
33
|
+
{ "$in" => 5 }
|
34
|
+
end
|
35
|
+
|
36
|
+
before do
|
37
|
+
hash.__add__({ "$in" => 5 })
|
38
|
+
end
|
39
|
+
|
40
|
+
it "keeps the old value" do
|
41
|
+
expect(hash).to eq({ "$in" => 5 })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the existing value is an array" do
|
48
|
+
|
49
|
+
context "when the values are unique" do
|
50
|
+
|
51
|
+
let(:hash) do
|
52
|
+
{ "$in" => [ 5, 6 ] }
|
53
|
+
end
|
54
|
+
|
55
|
+
before do
|
56
|
+
hash.__add__({ "$in" => [ 7, 8 ] })
|
57
|
+
end
|
58
|
+
|
59
|
+
it "sets the new array" do
|
60
|
+
expect(hash).to eq({ "$in" => [ 5, 6, 7, 8 ] })
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when the values are not unique" do
|
65
|
+
|
66
|
+
let(:hash) do
|
67
|
+
{ "$in" => [ 5, 6 ] }
|
68
|
+
end
|
69
|
+
|
70
|
+
before do
|
71
|
+
hash.__add__({ "$in" => [ 6, 7 ] })
|
72
|
+
end
|
73
|
+
|
74
|
+
it "sets a new unique array" do
|
75
|
+
expect(hash).to eq({ "$in" => [ 5, 6, 7 ] })
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when a key does not match" do
|
82
|
+
|
83
|
+
let(:hash) do
|
84
|
+
{ "$all" => [ 1, 2, 3 ] }
|
85
|
+
end
|
86
|
+
|
87
|
+
before do
|
88
|
+
hash.__add__({ "$in" => [ 1, 2 ] })
|
89
|
+
end
|
90
|
+
|
91
|
+
it "merges in the new hash" do
|
92
|
+
expect(hash).to eq({
|
93
|
+
"$all" => [ 1, 2, 3 ],
|
94
|
+
"$in" => [ 1, 2 ]
|
95
|
+
})
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#__expand_complex" do
|
102
|
+
|
103
|
+
let(:hash) do
|
104
|
+
{
|
105
|
+
:test1.elem_match => {
|
106
|
+
:test2.elem_match => {
|
107
|
+
:test3.in => ["value1"]
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when the hash is nested multiple levels" do
|
114
|
+
|
115
|
+
let(:expanded) do
|
116
|
+
hash.__expand_complex__
|
117
|
+
end
|
118
|
+
|
119
|
+
let(:expected) do
|
120
|
+
{
|
121
|
+
"test1"=> {
|
122
|
+
"$elemMatch"=> {
|
123
|
+
"test2"=> {
|
124
|
+
"$elemMatch"=> {
|
125
|
+
"test3"=> { "$in"=> ["value1"] }
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
it "expands the nested values" do
|
134
|
+
expect(expanded).to eq(expected)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#__intersect__" do
|
140
|
+
|
141
|
+
context "when the other object is a hash" do
|
142
|
+
|
143
|
+
context "when a key matches" do
|
144
|
+
|
145
|
+
context "when the existing value is a non-enumerable" do
|
146
|
+
|
147
|
+
context "when the intersected value is non-enumerable" do
|
148
|
+
|
149
|
+
context "when the values intersect" do
|
150
|
+
|
151
|
+
let(:hash) do
|
152
|
+
{ "$in" => 5 }
|
153
|
+
end
|
154
|
+
|
155
|
+
before do
|
156
|
+
hash.__intersect__({ "$in" => 5 })
|
157
|
+
end
|
158
|
+
|
159
|
+
it "sets the intersected array" do
|
160
|
+
expect(hash).to eq({ "$in" => [ 5 ] })
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when the values do not intersect" do
|
165
|
+
|
166
|
+
let(:hash) do
|
167
|
+
{ "$in" => 5 }
|
168
|
+
end
|
169
|
+
|
170
|
+
before do
|
171
|
+
hash.__intersect__({ "$in" => 6 })
|
172
|
+
end
|
173
|
+
|
174
|
+
it "sets the empty array" do
|
175
|
+
expect(hash).to eq({ "$in" => [] })
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "when the existing value is an array" do
|
182
|
+
|
183
|
+
context "when the values intersect" do
|
184
|
+
|
185
|
+
let(:hash) do
|
186
|
+
{ "$in" => [ 5, 6 ] }
|
187
|
+
end
|
188
|
+
|
189
|
+
before do
|
190
|
+
hash.__intersect__({ "$in" => [ 6, 7 ] })
|
191
|
+
end
|
192
|
+
|
193
|
+
it "sets the intersected array" do
|
194
|
+
expect(hash).to eq({ "$in" => [ 6 ] })
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "when the values do not intersect" do
|
199
|
+
|
200
|
+
let(:hash) do
|
201
|
+
{ "$in" => [ 5, 6 ] }
|
202
|
+
end
|
203
|
+
|
204
|
+
before do
|
205
|
+
hash.__intersect__({ "$in" => [ 7, 8 ] })
|
206
|
+
end
|
207
|
+
|
208
|
+
it "sets the empty array" do
|
209
|
+
expect(hash).to eq({ "$in" => [] })
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context "when a key does not match" do
|
216
|
+
|
217
|
+
let(:hash) do
|
218
|
+
{ "$all" => [ 1, 2, 3 ] }
|
219
|
+
end
|
220
|
+
|
221
|
+
before do
|
222
|
+
hash.__intersect__({ "$in" => [ 1, 2 ] })
|
223
|
+
end
|
224
|
+
|
225
|
+
it "merges in the new hash" do
|
226
|
+
expect(hash).to eq({
|
227
|
+
"$all" => [ 1, 2, 3 ],
|
228
|
+
"$in" => [ 1, 2 ]
|
229
|
+
})
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe "#__union__" do
|
236
|
+
|
237
|
+
context "when the other object is a hash" do
|
238
|
+
|
239
|
+
context "when a key matches" do
|
240
|
+
|
241
|
+
context "when the existing value is a non-enumerable" do
|
242
|
+
|
243
|
+
context "when the unioned value is non-enumerable" do
|
244
|
+
|
245
|
+
context "when the values are the same" do
|
246
|
+
|
247
|
+
let(:hash) do
|
248
|
+
{ "$in" => 5 }
|
249
|
+
end
|
250
|
+
|
251
|
+
before do
|
252
|
+
hash.__union__({ "$in" => 5 })
|
253
|
+
end
|
254
|
+
|
255
|
+
it "sets the unioned array" do
|
256
|
+
expect(hash).to eq({ "$in" => [ 5 ] })
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "when the values are different" do
|
261
|
+
|
262
|
+
let(:hash) do
|
263
|
+
{ "$in" => 5 }
|
264
|
+
end
|
265
|
+
|
266
|
+
before do
|
267
|
+
hash.__union__({ "$in" => 6 })
|
268
|
+
end
|
269
|
+
|
270
|
+
it "sets the empty array" do
|
271
|
+
expect(hash).to eq({ "$in" => [ 5, 6 ] })
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when the existing value is an array" do
|
278
|
+
|
279
|
+
let(:hash) do
|
280
|
+
{ "$in" => [ 5, 6 ] }
|
281
|
+
end
|
282
|
+
|
283
|
+
before do
|
284
|
+
hash.__union__({ "$in" => [ 6, 7 ] })
|
285
|
+
end
|
286
|
+
|
287
|
+
it "sets the unioned array" do
|
288
|
+
expect(hash).to eq({ "$in" => [ 5, 6, 7 ] })
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
context "when a key does not match" do
|
294
|
+
|
295
|
+
let(:hash) do
|
296
|
+
{ "$all" => [ 1, 2, 3 ] }
|
297
|
+
end
|
298
|
+
|
299
|
+
before do
|
300
|
+
hash.__union__({ "$in" => [ 1, 2 ] })
|
301
|
+
end
|
302
|
+
|
303
|
+
it "merges in the new hash" do
|
304
|
+
expect(hash).to eq({
|
305
|
+
"$all" => [ 1, 2, 3 ],
|
306
|
+
"$in" => [ 1, 2 ]
|
307
|
+
})
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "#update_values" do
|
314
|
+
|
315
|
+
let(:hash) do
|
316
|
+
{ field: "1" }
|
317
|
+
end
|
318
|
+
|
319
|
+
before do
|
320
|
+
hash.update_values(&:to_i)
|
321
|
+
end
|
322
|
+
|
323
|
+
it "updates each value in the hash" do
|
324
|
+
expect(hash).to eq({ field: 1 })
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Integer do
|
4
|
+
|
5
|
+
describe ".evolve" do
|
6
|
+
|
7
|
+
context "when provided a string" do
|
8
|
+
|
9
|
+
context "when the string is a number" do
|
10
|
+
|
11
|
+
context "when the string is an integer" do
|
12
|
+
|
13
|
+
it "returns an integer" do
|
14
|
+
expect(described_class.evolve("1")).to eq(1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when the string is a float" do
|
19
|
+
|
20
|
+
it "converts it to a float" do
|
21
|
+
expect(described_class.evolve("2.23")).to eq(2.23)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when the string ends in ." do
|
26
|
+
|
27
|
+
it "returns an integer" do
|
28
|
+
expect(described_class.evolve("2.")).to eq(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the string is not a number" do
|
34
|
+
|
35
|
+
it "returns the string" do
|
36
|
+
expect(described_class.evolve("testing")).to eq("testing")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when provided a number" do
|
43
|
+
|
44
|
+
context "when the number is an integer" do
|
45
|
+
|
46
|
+
it "returns an integer" do
|
47
|
+
expect(described_class.evolve(1)).to eq(1)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when the number is a float" do
|
52
|
+
|
53
|
+
it "returns the float" do
|
54
|
+
expect(described_class.evolve(2.23)).to eq(2.23)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when provided nil" do
|
60
|
+
|
61
|
+
it "returns nil" do
|
62
|
+
expect(described_class.evolve(nil)).to be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NilClass do
|
4
|
+
|
5
|
+
describe "#__add__" do
|
6
|
+
|
7
|
+
it "returns the object" do
|
8
|
+
expect(nil.__add__(1)).to eq(1)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#__evolve_date__" do
|
13
|
+
|
14
|
+
it "returns nil" do
|
15
|
+
expect(nil.__evolve_date__).to be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#__evolve_time__" do
|
20
|
+
|
21
|
+
it "returns nil" do
|
22
|
+
expect(nil.__evolve_time__).to be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#__intersect__" do
|
27
|
+
|
28
|
+
context "when provided a non enumerable" do
|
29
|
+
|
30
|
+
it "returns the object" do
|
31
|
+
expect(nil.__intersect__(1)).to eq(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when provided an array" do
|
36
|
+
|
37
|
+
it "returns the array" do
|
38
|
+
expect(nil.__intersect__([ 1, 2 ])).to eq([ 1, 2 ])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when provided a hash" do
|
43
|
+
|
44
|
+
it "returns the hash" do
|
45
|
+
expect(nil.__intersect__({ "$in" => [ 1, 2 ] })).to eq(
|
46
|
+
{ "$in" => [ 1, 2 ] }
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#__union__" do
|
53
|
+
|
54
|
+
context "when provided a non enumerable" do
|
55
|
+
|
56
|
+
it "returns the object" do
|
57
|
+
expect(nil.__union__(1)).to eq(1)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when provided an array" do
|
62
|
+
|
63
|
+
it "returns the array" do
|
64
|
+
expect(nil.__union__([ 1, 2 ])).to eq([ 1, 2 ])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when provided a hash" do
|
69
|
+
|
70
|
+
it "returns the hash" do
|
71
|
+
expect(nil.__union__({ "$in" => [ 1, 2 ] })).to eq(
|
72
|
+
{ "$in" => [ 1, 2 ] }
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
|
5
|
+
describe "#__add__" do
|
6
|
+
|
7
|
+
context "when the other object is a non-enumerable" do
|
8
|
+
|
9
|
+
context "when the values are unique" do
|
10
|
+
|
11
|
+
it "returns an array of both" do
|
12
|
+
expect(5.__add__(6)).to eq([ 5, 6 ])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when the values are not unique" do
|
17
|
+
|
18
|
+
it "returns the original value" do
|
19
|
+
expect(5.__add__(5)).to eq(5)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the other object is an array" do
|
25
|
+
|
26
|
+
context "when the values are unique" do
|
27
|
+
|
28
|
+
it "returns an array of both" do
|
29
|
+
expect(5.__add__([ 6, 7 ])).to eq([ 5, 6, 7 ])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the values are not unique" do
|
34
|
+
|
35
|
+
it "returns a unique array of both" do
|
36
|
+
expect(5.__add__([ 5, 6, 7 ])).to eq([ 5, 6, 7 ])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#__intersect__" do
|
43
|
+
|
44
|
+
context "when the other object is a non-enumerable" do
|
45
|
+
|
46
|
+
context "when the values intersect" do
|
47
|
+
|
48
|
+
it "returns an intersected array" do
|
49
|
+
expect(5.__intersect__(5)).to eq([ 5 ])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when the values do not intersect" do
|
54
|
+
|
55
|
+
it "returns an empty array" do
|
56
|
+
expect(5.__intersect__(6)).to be_empty
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when the other object is an array" do
|
62
|
+
|
63
|
+
context "when the values intersect" do
|
64
|
+
|
65
|
+
it "returns an intersected array" do
|
66
|
+
expect(5.__intersect__([ 5, 6 ])).to eq([ 5 ])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the values do not intersect" do
|
71
|
+
|
72
|
+
it "returns an empty array " do
|
73
|
+
expect(5.__intersect__([ 6, 7 ])).to be_empty
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#__union__" do
|
80
|
+
|
81
|
+
context "when the other object is a non-enumerable" do
|
82
|
+
|
83
|
+
context "when the values are the same" do
|
84
|
+
|
85
|
+
it "returns an unioned array" do
|
86
|
+
expect(5.__union__(5)).to eq([ 5 ])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when the values are not the same" do
|
91
|
+
|
92
|
+
it "returns an empty array" do
|
93
|
+
expect(5.__union__(6)).to eq([ 5, 6 ])
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when the other object is an array" do
|
99
|
+
|
100
|
+
context "when the values are not the same" do
|
101
|
+
|
102
|
+
it "returns an unioned array" do
|
103
|
+
expect(5.__union__([ 5, 6 ])).to eq([ 5, 6 ])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|