mongoid 5.4.1 → 6.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/config/locales/en.yml +23 -16
- data/lib/mongoid.rb +4 -9
- data/lib/mongoid/atomic.rb +1 -1
- data/lib/mongoid/atomic/modifiers.rb +8 -12
- data/lib/mongoid/attributes.rb +9 -11
- data/lib/mongoid/attributes/dynamic.rb +5 -6
- data/lib/mongoid/attributes/nested.rb +1 -1
- data/lib/mongoid/attributes/processing.rb +4 -0
- data/lib/mongoid/attributes/readonly.rb +22 -0
- data/lib/mongoid/cacheable.rb +36 -0
- data/lib/mongoid/changeable.rb +37 -1
- data/lib/mongoid/clients.rb +0 -63
- data/lib/mongoid/clients/factory.rb +0 -2
- data/lib/mongoid/clients/options.rb +54 -249
- data/lib/mongoid/clients/storage_options.rb +1 -69
- data/lib/mongoid/composable.rb +26 -2
- data/lib/mongoid/config.rb +1 -1
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +6 -9
- data/lib/mongoid/contextual/geo_near.rb +2 -3
- data/lib/mongoid/contextual/map_reduce.rb +97 -24
- data/lib/mongoid/contextual/memory.rb +7 -4
- data/lib/mongoid/contextual/mongo.rb +63 -54
- data/lib/mongoid/contextual/none.rb +2 -2
- data/lib/mongoid/copyable.rb +19 -19
- data/lib/mongoid/criteria.rb +5 -4
- data/lib/mongoid/criteria/findable.rb +2 -3
- data/lib/mongoid/criteria/includable.rb +63 -16
- data/lib/mongoid/criteria/marshalable.rb +2 -2
- data/lib/mongoid/criteria/modifiable.rb +17 -1
- data/lib/mongoid/criteria/options.rb +25 -0
- data/lib/mongoid/criteria/queryable.rb +86 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +120 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +28 -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 +45 -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/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 +271 -0
- data/lib/mongoid/criteria/queryable/optional.rb +411 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +111 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +662 -0
- data/lib/mongoid/criteria/queryable/selector.rb +196 -0
- data/lib/mongoid/criteria/queryable/smash.rb +103 -0
- data/lib/mongoid/document.rb +9 -23
- data/lib/mongoid/errors.rb +2 -1
- data/lib/mongoid/errors/ambiguous_relationship.rb +1 -1
- data/lib/mongoid/errors/delete_restriction.rb +2 -2
- 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/inverse_not_found.rb +1 -1
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/evolvable.rb +1 -1
- data/lib/mongoid/extensions.rb +0 -5
- data/lib/mongoid/extensions/big_decimal.rb +17 -8
- data/lib/mongoid/extensions/date.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -3
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/string.rb +4 -3
- data/lib/mongoid/extensions/time.rb +5 -2
- data/lib/mongoid/factory.rb +1 -0
- data/lib/mongoid/fields/foreign_key.rb +2 -2
- data/lib/mongoid/fields/localized.rb +3 -8
- data/lib/mongoid/fields/validators/macro.rb +18 -0
- data/lib/mongoid/findable.rb +3 -3
- data/lib/mongoid/indexable.rb +17 -16
- data/lib/mongoid/indexable/specification.rb +1 -1
- data/lib/mongoid/indexable/validators/options.rb +1 -2
- data/lib/mongoid/interceptable.rb +6 -17
- data/lib/mongoid/loggable.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -10
- data/lib/mongoid/matchable/gt.rb +2 -0
- data/lib/mongoid/matchable/gte.rb +2 -0
- data/lib/mongoid/matchable/lt.rb +2 -0
- data/lib/mongoid/matchable/lte.rb +2 -0
- data/lib/mongoid/persistable.rb +6 -5
- data/lib/mongoid/persistable/creatable.rb +2 -0
- data/lib/mongoid/persistable/deletable.rb +7 -3
- data/lib/mongoid/persistable/settable.rb +3 -16
- data/lib/mongoid/persistable/updatable.rb +10 -12
- data/lib/mongoid/persistence_context.rb +216 -0
- data/lib/mongoid/query_cache.rb +5 -30
- data/lib/mongoid/relations/accessors.rb +6 -2
- data/lib/mongoid/relations/auto_save.rb +12 -4
- data/lib/mongoid/relations/bindings/embedded/in.rb +4 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +8 -1
- data/lib/mongoid/relations/bindings/embedded/one.rb +10 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +4 -0
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +28 -18
- data/lib/mongoid/relations/eager.rb +19 -7
- data/lib/mongoid/relations/eager/base.rb +5 -5
- data/lib/mongoid/relations/embedded/batchable.rb +9 -33
- data/lib/mongoid/relations/embedded/in.rb +16 -2
- data/lib/mongoid/relations/embedded/many.rb +23 -8
- data/lib/mongoid/relations/embedded/one.rb +17 -2
- data/lib/mongoid/relations/macros.rb +9 -2
- data/lib/mongoid/relations/metadata.rb +3 -3
- data/lib/mongoid/relations/nested_builder.rb +1 -1
- data/lib/mongoid/relations/options.rb +2 -2
- data/lib/mongoid/relations/proxy.rb +2 -33
- data/lib/mongoid/relations/referenced/in.rb +23 -11
- data/lib/mongoid/relations/referenced/many.rb +24 -16
- data/lib/mongoid/relations/referenced/many_to_many.rb +20 -13
- data/lib/mongoid/relations/referenced/one.rb +17 -1
- data/lib/mongoid/relations/reflections.rb +3 -5
- data/lib/mongoid/relations/touchable.rb +1 -1
- data/lib/mongoid/reloadable.rb +1 -1
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +2 -3
- data/lib/mongoid/tasks/database.rb +1 -2
- data/lib/mongoid/threaded.rb +4 -4
- data/lib/mongoid/traversable.rb +1 -1
- data/lib/mongoid/validatable.rb +1 -1
- data/lib/mongoid/validatable/macros.rb +2 -4
- data/lib/mongoid/validatable/uniqueness.rb +1 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +4 -7
- data/spec/app/models/album.rb +5 -1
- data/spec/app/models/artist.rb +21 -0
- data/spec/app/models/band.rb +0 -1
- data/spec/app/models/church.rb +0 -2
- data/spec/app/models/ordered_post.rb +5 -0
- data/spec/app/models/oscar.rb +1 -2
- data/spec/app/models/person.rb +3 -1
- data/spec/app/models/post.rb +0 -1
- data/spec/app/models/princess.rb +2 -0
- data/spec/app/models/record.rb +1 -0
- data/spec/app/models/thing.rb +1 -1
- data/spec/config/mongoid.yml +1 -5
- data/spec/mongoid/atomic/modifiers_spec.rb +17 -17
- data/spec/mongoid/atomic_spec.rb +17 -17
- data/spec/mongoid/attributes/nested_spec.rb +14 -14
- data/spec/mongoid/attributes/readonly_spec.rb +87 -44
- data/spec/mongoid/attributes_spec.rb +63 -0
- data/spec/mongoid/cacheable_spec.rb +112 -0
- data/spec/mongoid/changeable_spec.rb +58 -0
- data/spec/mongoid/clients/factory_spec.rb +3 -11
- data/spec/mongoid/clients/options_spec.rb +378 -96
- data/spec/mongoid/clients_spec.rb +207 -170
- data/spec/mongoid/composable_spec.rb +7 -0
- data/spec/mongoid/config_spec.rb +41 -21
- data/spec/mongoid/contextual/atomic_spec.rb +77 -343
- data/spec/mongoid/contextual/map_reduce_spec.rb +119 -111
- data/spec/mongoid/contextual/memory_spec.rb +56 -316
- data/spec/mongoid/contextual/mongo_spec.rb +104 -378
- data/spec/mongoid/copyable_spec.rb +8 -15
- data/spec/mongoid/criteria/modifiable_spec.rb +239 -7
- 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/regexp_raw_spec.rb → criteria/queryable/extensions/regexp_spec.rb} +21 -20
- 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 +1786 -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 +4159 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +778 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +30 -0
- data/spec/mongoid/criteria_spec.rb +45 -63
- data/spec/mongoid/document_spec.rb +21 -88
- 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 +320 -18
- data/spec/mongoid/extensions/date_spec.rb +2 -6
- data/spec/mongoid/extensions/date_time_spec.rb +2 -6
- data/spec/mongoid/extensions/float_spec.rb +8 -1
- data/spec/mongoid/extensions/integer_spec.rb +8 -1
- data/spec/mongoid/extensions/object_spec.rb +11 -0
- data/spec/mongoid/extensions/string_spec.rb +21 -0
- data/spec/mongoid/extensions/time_spec.rb +4 -8
- data/spec/mongoid/extensions/time_with_zone_spec.rb +2 -6
- data/spec/mongoid/fields/localized_spec.rb +0 -91
- data/spec/mongoid/findable_spec.rb +46 -1
- data/spec/mongoid/indexable_spec.rb +6 -46
- data/spec/mongoid/interceptable_spec.rb +49 -10
- data/spec/mongoid/matchable/gt_spec.rb +11 -0
- data/spec/mongoid/matchable/gte_spec.rb +10 -0
- data/spec/mongoid/matchable/lt_spec.rb +11 -0
- data/spec/mongoid/matchable/lte_spec.rb +11 -0
- data/spec/mongoid/matchable_spec.rb +1 -51
- data/spec/mongoid/persistable/creatable_spec.rb +2 -2
- data/spec/mongoid/persistable/deletable_spec.rb +1 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +6 -2
- data/spec/mongoid/persistable/savable_spec.rb +30 -30
- data/spec/mongoid/persistable/settable_spec.rb +0 -185
- data/spec/mongoid/persistable/updatable_spec.rb +166 -5
- data/spec/mongoid/persistence_context_spec.rb +654 -0
- data/spec/mongoid/positional_spec.rb +10 -10
- data/spec/mongoid/query_cache_spec.rb +89 -65
- data/spec/mongoid/relations/accessors_spec.rb +1 -1
- data/spec/mongoid/relations/auto_save_spec.rb +39 -6
- data/spec/mongoid/relations/builders_spec.rb +37 -10
- data/spec/mongoid/relations/counter_cache_spec.rb +64 -15
- data/spec/mongoid/relations/cyclic_spec.rb +0 -22
- data/spec/mongoid/relations/embedded/many_spec.rb +9 -41
- data/spec/mongoid/relations/embedded/one_spec.rb +2 -1
- data/spec/mongoid/relations/macros_spec.rb +395 -7
- data/spec/mongoid/relations/proxy_spec.rb +3 -1
- data/spec/mongoid/relations/referenced/in_spec.rb +41 -1
- data/spec/mongoid/relations/referenced/many_spec.rb +6 -29
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +6 -29
- data/spec/mongoid/relations/reflections_spec.rb +9 -9
- data/spec/mongoid/reloadable_spec.rb +51 -0
- data/spec/mongoid/scopable_spec.rb +0 -12
- data/spec/mongoid/serializable_spec.rb +0 -50
- data/spec/mongoid/validatable/presence_spec.rb +1 -1
- data/spec/mongoid/validatable/uniqueness_spec.rb +16 -9
- data/spec/mongoid/validatable_spec.rb +16 -0
- data/spec/spec_helper.rb +10 -10
- metadata +536 -479
- metadata.gz.sig +0 -0
- data/lib/mongoid/clients/thread_options.rb +0 -19
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -20
- data/lib/mongoid/extensions/decimal128.rb +0 -39
- data/lib/mongoid/extensions/origin/regexp_raw.rb +0 -43
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -44
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
@@ -71,5 +71,16 @@ describe Mongoid::Matchable::Gt do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
75
|
+
context "when the value is not numeric" do
|
76
|
+
|
77
|
+
let(:matcher) do
|
78
|
+
described_class.new(5)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "returns false" do
|
82
|
+
expect(matcher.matches?("$gt" => '4.9')).to be false
|
83
|
+
end
|
84
|
+
end
|
74
85
|
end
|
75
86
|
end
|
@@ -67,7 +67,17 @@ describe Mongoid::Matchable::Gte do
|
|
67
67
|
it "returns false" do
|
68
68
|
expect(matcher.matches?("$gte" => 5)).to be false
|
69
69
|
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when the value is not numeric" do
|
74
|
+
|
75
|
+
let(:matcher) do
|
76
|
+
described_class.new(5)
|
77
|
+
end
|
70
78
|
|
79
|
+
it "returns false" do
|
80
|
+
expect(matcher.matches?("$gte" => '4.9')).to be false
|
71
81
|
end
|
72
82
|
end
|
73
83
|
end
|
@@ -70,5 +70,16 @@ describe Mongoid::Matchable::Lt do
|
|
70
70
|
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context "when the value is not numeric" do
|
75
|
+
|
76
|
+
let(:matcher) do
|
77
|
+
described_class.new(5)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns false" do
|
81
|
+
expect(matcher.matches?("$lt" => '5.1')).to be false
|
82
|
+
end
|
83
|
+
end
|
73
84
|
end
|
74
85
|
end
|
@@ -49,6 +49,7 @@ describe Mongoid::Matchable::Lte do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
context "when the value is an array" do
|
52
|
+
|
52
53
|
context "there are value valid" do
|
53
54
|
let(:matcher) do
|
54
55
|
described_class.new([3, 4])
|
@@ -67,7 +68,17 @@ describe Mongoid::Matchable::Lte do
|
|
67
68
|
it "returns false" do
|
68
69
|
expect(matcher.matches?("$lte" => 5)).to be false
|
69
70
|
end
|
71
|
+
end
|
72
|
+
end
|
70
73
|
|
74
|
+
context "when the value is not numeric" do
|
75
|
+
|
76
|
+
let(:matcher) do
|
77
|
+
described_class.new(5)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns false" do
|
81
|
+
expect(matcher.matches?("$lte" => '5.1')).to be false
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
@@ -9,13 +9,12 @@ describe Mongoid::Matchable do
|
|
9
9
|
let(:document) do
|
10
10
|
Address.new(street: "Clarkenwell Road")
|
11
11
|
end
|
12
|
-
let(:occupants){[{'name' => 'Tim'}]}
|
13
12
|
|
14
13
|
before do
|
15
14
|
document.locations << Location.new(
|
16
15
|
name: 'No.1',
|
17
16
|
info: { 'door' => 'Red'},
|
18
|
-
occupants:
|
17
|
+
occupants: [{'name' => 'Tim'}]
|
19
18
|
)
|
20
19
|
end
|
21
20
|
|
@@ -77,33 +76,6 @@ describe Mongoid::Matchable do
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
|
-
context "when matching index of an array" do
|
81
|
-
|
82
|
-
let(:occupants){["Tim","Logan"]}
|
83
|
-
|
84
|
-
context "when the contents match" do
|
85
|
-
|
86
|
-
let(:selector) do
|
87
|
-
{ "occupants.0" => "Tim" }
|
88
|
-
end
|
89
|
-
|
90
|
-
it "returns true" do
|
91
|
-
expect(document.locations.first.matches?(selector)).to be true
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "when the contents do not match" do
|
96
|
-
|
97
|
-
let(:selector) do
|
98
|
-
{ "occupants.0" => "Logan" }
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns false" do
|
102
|
-
expect(document.locations.first.matches?(selector)).to be false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
79
|
context "when matching values of multiple embedded hashes" do
|
108
80
|
|
109
81
|
context "when the contents match" do
|
@@ -169,28 +141,6 @@ describe Mongoid::Matchable do
|
|
169
141
|
expect(document.matches?(selector)).to be false
|
170
142
|
end
|
171
143
|
end
|
172
|
-
|
173
|
-
context 'when a BSON::Regexp::Raw object is used' do
|
174
|
-
|
175
|
-
let(:selector) do
|
176
|
-
{ street: BSON::Regexp::Raw.new("^Clarkenwell") }
|
177
|
-
end
|
178
|
-
|
179
|
-
it "returns true" do
|
180
|
-
expect(document.matches?(selector)).to be true
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
context 'when a native Regexp object is used' do
|
185
|
-
|
186
|
-
let(:selector) do
|
187
|
-
{ street: /^Clarkenwell/ }
|
188
|
-
end
|
189
|
-
|
190
|
-
it "returns true" do
|
191
|
-
expect(document.matches?(selector)).to be true
|
192
|
-
end
|
193
|
-
end
|
194
144
|
end
|
195
145
|
|
196
146
|
context "when performing complex matching" do
|
@@ -529,7 +529,7 @@ describe Mongoid::Persistable::Creatable do
|
|
529
529
|
it "raises an error" do
|
530
530
|
expect {
|
531
531
|
4.times { Person.create!(ssn: "555-55-1029") }
|
532
|
-
}.to raise_error
|
532
|
+
}.to raise_error(Mongo::Error::OperationFailure)
|
533
533
|
end
|
534
534
|
end
|
535
535
|
end
|
@@ -562,7 +562,7 @@ describe Mongoid::Persistable::Creatable do
|
|
562
562
|
end
|
563
563
|
end
|
564
564
|
|
565
|
-
context "when a callback
|
565
|
+
context "when a callback aborts the chain" do
|
566
566
|
|
567
567
|
it "raises a callback error" do
|
568
568
|
expect { Oscar.create! }.to raise_error(Mongoid::Errors::Callback)
|
@@ -30,7 +30,7 @@ describe Mongoid::Persistable::Destroyable do
|
|
30
30
|
it "destroys the document from the collection" do
|
31
31
|
expect {
|
32
32
|
Person.find(person.id)
|
33
|
-
}.to raise_error
|
33
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "returns true" do
|
@@ -164,7 +164,11 @@ describe Mongoid::Persistable::Destroyable do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
before do
|
167
|
-
|
167
|
+
Album.before_destroy(:set_parent_name_fail)
|
168
|
+
end
|
169
|
+
|
170
|
+
after do
|
171
|
+
Album.reset_callbacks(:destroy)
|
168
172
|
end
|
169
173
|
|
170
174
|
it "raises an exception" do
|
@@ -189,8 +189,8 @@ describe Mongoid::Persistable::Savable do
|
|
189
189
|
"title" => "King",
|
190
190
|
"name.first_name" => "Ryan"
|
191
191
|
},
|
192
|
-
"$
|
193
|
-
"addresses" =>
|
192
|
+
"$pushAll"=> {
|
193
|
+
"addresses" => [ { "_id" => address.id, "street" => "Bond St" } ]
|
194
194
|
}
|
195
195
|
})
|
196
196
|
end
|
@@ -295,20 +295,37 @@ describe Mongoid::Persistable::Savable do
|
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
|
-
context "when the
|
299
|
-
|
300
|
-
let(:person) do
|
301
|
-
Person.only(:title).first
|
302
|
-
end
|
298
|
+
context "when the changed attribute is not writable" do
|
303
299
|
|
304
300
|
before do
|
305
301
|
Person.create(title: "sir")
|
306
302
|
end
|
307
303
|
|
304
|
+
let(:person) do
|
305
|
+
Person.only(:title).first
|
306
|
+
end
|
307
|
+
|
308
308
|
it "raises an error" do
|
309
309
|
expect {
|
310
|
+
person.username = 'unloaded-attribute'
|
310
311
|
person.save
|
311
|
-
}.to raise_error(Mongoid::Errors::
|
312
|
+
}.to raise_error(Mongoid::Errors::ReadonlyAttribute)
|
313
|
+
end
|
314
|
+
|
315
|
+
context 'when the changed attribute is aliased' do
|
316
|
+
|
317
|
+
before do
|
318
|
+
Person.create(at: Time.now)
|
319
|
+
end
|
320
|
+
|
321
|
+
let(:person) do
|
322
|
+
Person.only(:at).first
|
323
|
+
end
|
324
|
+
|
325
|
+
it "saves the document" do
|
326
|
+
person.aliased_timestamp = Time.now
|
327
|
+
expect(person.save(validate: false)).to be true
|
328
|
+
end
|
312
329
|
end
|
313
330
|
end
|
314
331
|
|
@@ -357,8 +374,8 @@ describe Mongoid::Persistable::Savable do
|
|
357
374
|
Person.create!(ssn: "555-55-9999")
|
358
375
|
end
|
359
376
|
|
360
|
-
it "raises an
|
361
|
-
expect { person.save! }.to raise_error
|
377
|
+
it "raises an OperationFailure" do
|
378
|
+
expect { person.save! }.to raise_error(Mongo::Error::OperationFailure)
|
362
379
|
end
|
363
380
|
end
|
364
381
|
end
|
@@ -374,12 +391,12 @@ describe Mongoid::Persistable::Savable do
|
|
374
391
|
end
|
375
392
|
|
376
393
|
it "raises an error with multiple save attempts" do
|
377
|
-
expect {
|
378
|
-
expect {
|
394
|
+
expect { service.save! }.to raise_error(Mongoid::Errors::Validations)
|
395
|
+
expect { service.save! }.to raise_error(Mongoid::Errors::Validations)
|
379
396
|
end
|
380
397
|
end
|
381
398
|
|
382
|
-
context "when a callback
|
399
|
+
context "when a callback aborts the callback chain" do
|
383
400
|
|
384
401
|
let(:oscar) do
|
385
402
|
Oscar.new
|
@@ -495,22 +512,5 @@ describe Mongoid::Persistable::Savable do
|
|
495
512
|
expect(from_db.shapes.first.canvas).to eq(firefox)
|
496
513
|
end
|
497
514
|
end
|
498
|
-
|
499
|
-
context "when the document is readonly" do
|
500
|
-
|
501
|
-
let(:person) do
|
502
|
-
Person.only(:title).first
|
503
|
-
end
|
504
|
-
|
505
|
-
before do
|
506
|
-
Person.create(title: "sir")
|
507
|
-
end
|
508
|
-
|
509
|
-
it "raises an error" do
|
510
|
-
expect {
|
511
|
-
person.save!
|
512
|
-
}.to raise_error(Mongoid::Errors::ReadonlyDocument)
|
513
|
-
end
|
514
|
-
end
|
515
515
|
end
|
516
516
|
end
|
@@ -134,35 +134,6 @@ describe Mongoid::Persistable::Settable do
|
|
134
134
|
|
135
135
|
it_behaves_like "a settable embedded document"
|
136
136
|
end
|
137
|
-
|
138
|
-
context 'when the field is a relation' do
|
139
|
-
|
140
|
-
let(:person) do
|
141
|
-
Person.create
|
142
|
-
end
|
143
|
-
|
144
|
-
let(:pet) do
|
145
|
-
Animal.new(name: "somepet")
|
146
|
-
end
|
147
|
-
|
148
|
-
let(:home_phone) do
|
149
|
-
Phone.new(number: "555-555-5555")
|
150
|
-
end
|
151
|
-
|
152
|
-
let(:office_phone) do
|
153
|
-
Phone.new(number: "666-666-6666")
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should persist changes of embeds_one field" do
|
157
|
-
person.set(pet: pet)
|
158
|
-
expect(person.reload.pet).to eq(pet)
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should persist changes of embeds_many fields" do
|
162
|
-
person.set({ phone_numbers: [home_phone, office_phone].map { |p| p.as_document} })
|
163
|
-
expect(person.reload.phone_numbers).to eq([home_phone, office_phone])
|
164
|
-
end
|
165
|
-
end
|
166
137
|
end
|
167
138
|
end
|
168
139
|
|
@@ -204,160 +175,4 @@ describe Mongoid::Persistable::Settable do
|
|
204
175
|
expect(agent.reload.title).to eq title
|
205
176
|
end
|
206
177
|
end
|
207
|
-
|
208
|
-
context 'when the field is already set locally' do
|
209
|
-
|
210
|
-
let(:church) do
|
211
|
-
Church.new.tap do |a|
|
212
|
-
a.location = { 'city' => 'Berlin' }
|
213
|
-
a.name = 'Church1'
|
214
|
-
a.save
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
context 'when the field is a Hash type' do
|
219
|
-
|
220
|
-
before do
|
221
|
-
church.set('location.neighborhood' => 'Kreuzberg')
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'updates the hash while keeping existing key and values locally' do
|
225
|
-
expect(church.location).to eq({ 'city' => 'Berlin', 'neighborhood' => 'Kreuzberg'})
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'updates the hash in the database' do
|
229
|
-
expect(church.reload.location).to eq({ 'city' => 'Berlin', 'neighborhood' => 'Kreuzberg'})
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'when the field type is String' do
|
234
|
-
|
235
|
-
before do
|
236
|
-
church.set('name' => 'Church2')
|
237
|
-
end
|
238
|
-
|
239
|
-
it 'updates the field locally' do
|
240
|
-
expect(church.name).to eq('Church2')
|
241
|
-
end
|
242
|
-
|
243
|
-
it 'updates the field in the database' do
|
244
|
-
expect(church.reload.name).to eq('Church2')
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
context 'when there are two fields of type Hash and String' do
|
249
|
-
|
250
|
-
before do
|
251
|
-
church.set('name' => 'Church2', 'location.street' => 'Yorckstr.')
|
252
|
-
end
|
253
|
-
|
254
|
-
it 'updates the fields locally' do
|
255
|
-
expect(church.name).to eq('Church2')
|
256
|
-
expect(church.location).to eq({ 'city' => 'Berlin', 'street' => 'Yorckstr.'})
|
257
|
-
end
|
258
|
-
|
259
|
-
it 'updates the fields in the database' do
|
260
|
-
expect(church.reload.name).to eq('Church2')
|
261
|
-
expect(church.reload.location).to eq({ 'city' => 'Berlin', 'street' => 'Yorckstr.'})
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
context 'when the field is a nested hash' do
|
267
|
-
|
268
|
-
context 'when a leaf value in the nested hash is updated' do
|
269
|
-
|
270
|
-
let(:church) do
|
271
|
-
Church.new.tap do |a|
|
272
|
-
a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
|
273
|
-
a.name = 'Church1'
|
274
|
-
a.save
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
before do
|
279
|
-
church.set('location.address.city' => 'Munich')
|
280
|
-
end
|
281
|
-
|
282
|
-
it 'does not reset the nested hash' do
|
283
|
-
expect(church.name).to eq('Church1')
|
284
|
-
expect(church.location).to eql({'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}})
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
|
289
|
-
context 'when the nested hash is many levels deep' do
|
290
|
-
|
291
|
-
let(:church) do
|
292
|
-
Church.new.tap do |a|
|
293
|
-
a.location = {'address' => {'state' => {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}}}
|
294
|
-
a.name = 'Church1'
|
295
|
-
a.save
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
before do
|
300
|
-
church.set('location.address.state.address.city' => 'Munich')
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'does not reset the nested hash' do
|
304
|
-
expect(church.name).to eq('Church1')
|
305
|
-
expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}}}})
|
306
|
-
end
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'when the field is not already set locally' do
|
311
|
-
|
312
|
-
let(:church) do
|
313
|
-
Church.create
|
314
|
-
end
|
315
|
-
|
316
|
-
context 'when the field is a Hash type' do
|
317
|
-
|
318
|
-
before do
|
319
|
-
church.set('location.neighborhood' => 'Kreuzberg')
|
320
|
-
end
|
321
|
-
|
322
|
-
it 'sets the hash locally' do
|
323
|
-
expect(church.location).to eq({ 'neighborhood' => 'Kreuzberg'})
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'sets the hash in the database' do
|
327
|
-
expect(church.reload.location).to eq({ 'neighborhood' => 'Kreuzberg'})
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
context 'when the field type is String' do
|
332
|
-
|
333
|
-
before do
|
334
|
-
church.set('name' => 'Church2')
|
335
|
-
end
|
336
|
-
|
337
|
-
it 'sets the field locally' do
|
338
|
-
expect(church.name).to eq('Church2')
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'sets the field in the database' do
|
342
|
-
expect(church.reload.name).to eq('Church2')
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
context 'when there are two fields of type Hash and String' do
|
347
|
-
|
348
|
-
before do
|
349
|
-
church.set('name' => 'Church2', 'location.street' => 'Yorckstr.')
|
350
|
-
end
|
351
|
-
|
352
|
-
it 'sets the fields locally' do
|
353
|
-
expect(church.name).to eq('Church2')
|
354
|
-
expect(church.location).to eq({ 'street' => 'Yorckstr.'})
|
355
|
-
end
|
356
|
-
|
357
|
-
it 'sets the fields in the database' do
|
358
|
-
expect(church.reload.name).to eq('Church2')
|
359
|
-
expect(church.reload.location).to eq({ 'street' => 'Yorckstr.'})
|
360
|
-
end
|
361
|
-
end
|
362
|
-
end
|
363
178
|
end
|