mongoid 8.0.10 → 8.1.0
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/CHANGELOG.md +3 -3
- data/README.md +3 -3
- data/Rakefile +18 -67
- data/lib/config/locales/en.yml +46 -14
- data/lib/mongoid/association/accessors.rb +3 -7
- data/lib/mongoid/association/builders.rb +1 -1
- data/lib/mongoid/association/eager_loadable.rb +0 -3
- data/lib/mongoid/association/embedded/batchable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -1
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +3 -2
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +6 -6
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +1 -1
- data/lib/mongoid/association/macros.rb +0 -6
- data/lib/mongoid/association/nested/one.rb +40 -2
- data/lib/mongoid/association/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +1 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +6 -23
- data/lib/mongoid/association/referenced/has_many/proxy.rb +3 -3
- data/lib/mongoid/association/reflections.rb +2 -2
- data/lib/mongoid/atomic.rb +7 -16
- data/lib/mongoid/attributes/dynamic.rb +1 -1
- data/lib/mongoid/attributes/nested.rb +2 -2
- data/lib/mongoid/attributes/processing.rb +5 -29
- data/lib/mongoid/attributes/projector.rb +1 -1
- data/lib/mongoid/attributes/readonly.rb +1 -1
- data/lib/mongoid/attributes.rb +8 -2
- data/lib/mongoid/changeable.rb +107 -5
- data/lib/mongoid/clients/storage_options.rb +2 -5
- data/lib/mongoid/clients/validators/storage.rb +1 -13
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +2 -0
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/options.rb +0 -3
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators.rb +1 -0
- data/lib/mongoid/config.rb +88 -27
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +233 -33
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +370 -133
- data/lib/mongoid/contextual/none.rb +162 -7
- data/lib/mongoid/contextual.rb +12 -0
- data/lib/mongoid/criteria/findable.rb +2 -2
- data/lib/mongoid/criteria/includable.rb +4 -3
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -15
- data/lib/mongoid/criteria/queryable/key.rb +1 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +1 -1
- data/lib/mongoid/criteria/queryable/optional.rb +8 -8
- data/lib/mongoid/criteria/queryable/selectable.rb +43 -12
- data/lib/mongoid/criteria/queryable/selector.rb +1 -1
- data/lib/mongoid/criteria/queryable/storable.rb +1 -1
- data/lib/mongoid/criteria.rb +6 -5
- data/lib/mongoid/deprecable.rb +1 -2
- data/lib/mongoid/deprecation.rb +3 -3
- data/lib/mongoid/document.rb +1 -8
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/extensions/hash.rb +2 -24
- data/lib/mongoid/extensions/object.rb +2 -2
- data/lib/mongoid/extensions/time.rb +2 -0
- data/lib/mongoid/fields/localized.rb +10 -0
- data/lib/mongoid/fields/standard.rb +10 -0
- data/lib/mongoid/fields.rb +59 -35
- data/lib/mongoid/findable.rb +27 -3
- data/lib/mongoid/interceptable.rb +6 -116
- data/lib/mongoid/matcher/eq_impl.rb +1 -1
- data/lib/mongoid/matcher/type.rb +1 -1
- data/lib/mongoid/persistable/creatable.rb +1 -0
- data/lib/mongoid/persistable/deletable.rb +1 -1
- data/lib/mongoid/persistable/savable.rb +13 -1
- data/lib/mongoid/persistable/unsettable.rb +2 -2
- data/lib/mongoid/persistable/updatable.rb +51 -1
- data/lib/mongoid/persistable/upsertable.rb +20 -1
- data/lib/mongoid/persistable.rb +3 -0
- data/lib/mongoid/query_cache.rb +5 -1
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +5 -3
- data/lib/mongoid/stateful.rb +22 -1
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +20 -0
- data/lib/mongoid/timestamps/created.rb +1 -8
- data/lib/mongoid/traversable.rb +0 -12
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +17 -98
- data/lib/mongoid/validatable/macros.rb +5 -5
- data/lib/mongoid/validatable.rb +4 -9
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +17 -1
- data/lib/mongoid.rb +16 -3
- data/spec/integration/app_spec.rb +2 -6
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +0 -40
- data/spec/integration/callbacks_spec.rb +99 -12
- data/spec/integration/discriminator_key_spec.rb +4 -5
- data/spec/integration/i18n_fallbacks_spec.rb +3 -2
- data/spec/mongoid/association/eager_spec.rb +2 -24
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +20 -25
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +0 -4
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +15 -2
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2 -18
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +42 -55
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +9 -50
- data/spec/mongoid/association/syncable_spec.rb +1 -1
- data/spec/mongoid/association_spec.rb +0 -60
- data/spec/mongoid/attributes_spec.rb +3 -33
- data/spec/mongoid/changeable_spec.rb +299 -24
- data/spec/mongoid/clients_spec.rb +122 -13
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config_spec.rb +154 -27
- data/spec/mongoid/contextual/memory_spec.rb +332 -76
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +1009 -125
- data/spec/mongoid/contextual/none_spec.rb +49 -2
- data/spec/mongoid/copyable_spec.rb +2 -10
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +4 -10
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +419 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1 -1
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -76
- data/spec/mongoid/criteria/queryable/storable_spec.rb +0 -72
- data/spec/mongoid/criteria_projection_spec.rb +1 -4
- data/spec/mongoid/criteria_spec.rb +5 -9
- data/spec/mongoid/document_spec.rb +0 -27
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -2
- data/spec/mongoid/extensions/hash_spec.rb +3 -3
- data/spec/mongoid/extensions/time_spec.rb +8 -43
- data/spec/mongoid/extensions/time_with_zone_spec.rb +7 -52
- data/spec/mongoid/fields/localized_spec.rb +46 -28
- data/spec/mongoid/fields_spec.rb +136 -77
- data/spec/mongoid/findable_spec.rb +391 -34
- data/spec/mongoid/indexable_spec.rb +16 -10
- data/spec/mongoid/interceptable_spec.rb +153 -442
- data/spec/mongoid/interceptable_spec_models.rb +111 -51
- data/spec/mongoid/persistable/deletable_spec.rb +26 -6
- data/spec/mongoid/persistable/destroyable_spec.rb +26 -6
- data/spec/mongoid/persistable/incrementable_spec.rb +37 -0
- data/spec/mongoid/persistable/logical_spec.rb +37 -0
- data/spec/mongoid/persistable/poppable_spec.rb +36 -0
- data/spec/mongoid/persistable/pullable_spec.rb +72 -0
- data/spec/mongoid/persistable/pushable_spec.rb +72 -0
- data/spec/mongoid/persistable/renamable_spec.rb +36 -0
- data/spec/mongoid/persistable/savable_spec.rb +96 -0
- data/spec/mongoid/persistable/settable_spec.rb +37 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +36 -0
- data/spec/mongoid/persistable/updatable_spec.rb +20 -28
- data/spec/mongoid/persistable/upsertable_spec.rb +80 -6
- data/spec/mongoid/persistence_context_spec.rb +7 -57
- data/spec/mongoid/query_cache_spec.rb +56 -61
- data/spec/mongoid/reloadable_spec.rb +24 -28
- data/spec/mongoid/scopable_spec.rb +70 -0
- data/spec/mongoid/serializable_spec.rb +23 -44
- data/spec/mongoid/stateful_spec.rb +122 -8
- data/spec/mongoid/tasks/database_rake_spec.rb +74 -0
- data/spec/mongoid/tasks/database_spec.rb +127 -0
- data/spec/mongoid/timestamps/created_spec.rb +0 -23
- data/spec/mongoid/timestamps_spec.rb +9 -11
- data/spec/mongoid/touchable_spec.rb +277 -5
- data/spec/mongoid/touchable_spec_models.rb +3 -1
- data/spec/mongoid/traversable_spec.rb +9 -24
- data/spec/mongoid/validatable/associated_spec.rb +34 -27
- data/spec/mongoid/validatable/uniqueness_spec.rb +2 -3
- data/spec/mongoid_spec.rb +36 -10
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/share/Dockerfile.erb +321 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +416 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +47 -15
- data/spec/support/models/artist.rb +0 -1
- data/spec/support/models/band.rb +1 -0
- data/spec/support/models/building.rb +2 -0
- data/spec/support/models/name.rb +0 -10
- data/spec/support/models/person.rb +0 -1
- data/spec/support/models/product.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +745 -637
- metadata.gz.sig +2 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -60
- data/spec/support/models/purse.rb +0 -9
@@ -44,7 +44,7 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
context "when selector contains a $nin
|
47
|
+
context "when selector contains a $nin" do
|
48
48
|
|
49
49
|
let(:initial) do
|
50
50
|
{ "$nin" => ["foo"] }
|
@@ -72,35 +72,7 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
context "when selector contains a $
|
76
|
-
|
77
|
-
let(:initial) do
|
78
|
-
{ :$nin => ["foo"] }
|
79
|
-
end
|
80
|
-
|
81
|
-
before do
|
82
|
-
selector["field"] = initial
|
83
|
-
end
|
84
|
-
|
85
|
-
context "when merging in a new $nin" do
|
86
|
-
|
87
|
-
let(:other) do
|
88
|
-
{ "field" => { :$nin => ["bar"] } }
|
89
|
-
end
|
90
|
-
|
91
|
-
before do
|
92
|
-
selector.merge!(other)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "combines the two $nin queries into one" do
|
96
|
-
expect(selector).to eq({
|
97
|
-
"field" => { :$nin => ["foo", "bar"] }
|
98
|
-
})
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context "when selector contains a $in string" do
|
75
|
+
context "when selector contains a $in" do
|
104
76
|
|
105
77
|
let(:initial) do
|
106
78
|
{ "$in" => [1, 2] }
|
@@ -145,51 +117,6 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
145
117
|
end
|
146
118
|
end
|
147
119
|
|
148
|
-
context "when selector contains a $in symbol" do
|
149
|
-
|
150
|
-
let(:initial) do
|
151
|
-
{ :$in => [1, 2] }
|
152
|
-
end
|
153
|
-
|
154
|
-
before do
|
155
|
-
selector["field"] = initial
|
156
|
-
end
|
157
|
-
|
158
|
-
context "when merging in a new $in with an intersecting value" do
|
159
|
-
|
160
|
-
let(:other) do
|
161
|
-
{ "field" => { :$in => [1] } }
|
162
|
-
end
|
163
|
-
|
164
|
-
before do
|
165
|
-
selector.merge!(other)
|
166
|
-
end
|
167
|
-
|
168
|
-
it "intersects the $in values" do
|
169
|
-
expect(selector).to eq({
|
170
|
-
"field" => { :$in => [1] }
|
171
|
-
})
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
context "when merging in a new $in with no intersecting values" do
|
176
|
-
|
177
|
-
let(:other) do
|
178
|
-
{ "field" => { :$in => [3] } }
|
179
|
-
end
|
180
|
-
|
181
|
-
before do
|
182
|
-
selector.merge!(other)
|
183
|
-
end
|
184
|
-
|
185
|
-
it "intersects the $in values" do
|
186
|
-
expect(selector).to eq({
|
187
|
-
"field" => { :$in => [] }
|
188
|
-
})
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
120
|
context "when selector is not nested" do
|
194
121
|
|
195
122
|
before do
|
@@ -681,6 +608,7 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
681
608
|
end
|
682
609
|
|
683
610
|
context "when the serializer is localized" do
|
611
|
+
with_default_i18n_configs
|
684
612
|
|
685
613
|
before(:all) do
|
686
614
|
class Field
|
@@ -696,7 +624,6 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
696
624
|
|
697
625
|
after(:all) do
|
698
626
|
Object.send(:remove_const, :Field)
|
699
|
-
::I18n.locale = :en
|
700
627
|
end
|
701
628
|
|
702
629
|
let(:selector) do
|
@@ -210,79 +210,7 @@ describe Mongoid::Criteria::Queryable::Storable do
|
|
210
210
|
}
|
211
211
|
end
|
212
212
|
end
|
213
|
-
|
214
|
-
context 'when value is a hash combine values with different operator keys' do
|
215
|
-
let(:base) do
|
216
|
-
query.add_field_expression('foo', {'$in' => ['bar']})
|
217
|
-
end
|
218
|
-
|
219
|
-
let(:modified) do
|
220
|
-
base.add_field_expression('foo', {'$nin' => ['zoom']})
|
221
|
-
end
|
222
|
-
|
223
|
-
it 'combines the conditions using $and' do
|
224
|
-
modified.selector.should == {
|
225
|
-
'foo' => {
|
226
|
-
'$in' => ['bar'],
|
227
|
-
'$nin' => ['zoom']
|
228
|
-
}
|
229
|
-
}
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'when value is a hash with symbol operator key combine values with different operator keys' do
|
234
|
-
let(:base) do
|
235
|
-
query.add_field_expression('foo', {:$in => ['bar']})
|
236
|
-
end
|
237
|
-
|
238
|
-
let(:modified) do
|
239
|
-
base.add_field_expression('foo', {:$nin => ['zoom']})
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'combines the conditions using $and' do
|
243
|
-
modified.selector.should == {
|
244
|
-
'foo' => {
|
245
|
-
:$in => ['bar'],
|
246
|
-
:$nin => ['zoom']
|
247
|
-
}
|
248
|
-
}
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
context 'when value is a hash add values with same operator keys using $and' do
|
253
|
-
let(:base) do
|
254
|
-
query.add_field_expression('foo', {'$in' => ['bar']})
|
255
|
-
end
|
256
|
-
|
257
|
-
let(:modified) do
|
258
|
-
base.add_field_expression('foo', {'$in' => ['zoom']})
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'adds the new condition using $and' do
|
262
|
-
modified.selector.should == {
|
263
|
-
'foo' => {'$in' => ['bar']},
|
264
|
-
'$and' => ['foo' => {'$in' => ['zoom']}]
|
265
|
-
}
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context 'when value is a hash with symbol operator key add values with same operator keys using $and' do
|
270
|
-
let(:base) do
|
271
|
-
query.add_field_expression('foo', {:$in => ['bar']})
|
272
|
-
end
|
273
|
-
|
274
|
-
let(:modified) do
|
275
|
-
base.add_field_expression('foo', {:$in => ['zoom']})
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'adds the new condition using $and' do
|
279
|
-
modified.selector.should == {
|
280
|
-
'foo' => {:$in => ['bar']},
|
281
|
-
'$and' => ['foo' => {:$in => ['zoom']}]
|
282
|
-
}
|
283
|
-
end
|
284
213
|
end
|
285
|
-
end
|
286
214
|
|
287
215
|
describe '#add_operator_expression' do
|
288
216
|
let(:query_method) { :add_operator_expression }
|
@@ -154,6 +154,7 @@ describe Mongoid::Criteria do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
context 'when the field is localized' do
|
157
|
+
with_default_i18n_configs
|
157
158
|
|
158
159
|
before do
|
159
160
|
I18n.locale = :en
|
@@ -163,10 +164,6 @@ describe Mongoid::Criteria do
|
|
163
164
|
d.save!
|
164
165
|
end
|
165
166
|
|
166
|
-
after do
|
167
|
-
I18n.locale = :en
|
168
|
-
end
|
169
|
-
|
170
167
|
context 'when entire field is included' do
|
171
168
|
|
172
169
|
let(:dictionary) do
|
@@ -1953,6 +1953,7 @@ describe Mongoid::Criteria do
|
|
1953
1953
|
end
|
1954
1954
|
|
1955
1955
|
context 'when plucking a localized field' do
|
1956
|
+
with_default_i18n_configs
|
1956
1957
|
|
1957
1958
|
before do
|
1958
1959
|
I18n.locale = :en
|
@@ -1962,10 +1963,6 @@ describe Mongoid::Criteria do
|
|
1962
1963
|
d.save!
|
1963
1964
|
end
|
1964
1965
|
|
1965
|
-
after do
|
1966
|
-
I18n.locale = :en
|
1967
|
-
end
|
1968
|
-
|
1969
1966
|
context 'when plucking the entire field' do
|
1970
1967
|
let(:plucked) do
|
1971
1968
|
Dictionary.all.pluck(:description)
|
@@ -2059,13 +2056,10 @@ describe Mongoid::Criteria do
|
|
2059
2056
|
end
|
2060
2057
|
|
2061
2058
|
context 'when fallbacks are enabled with a locale list' do
|
2062
|
-
|
2059
|
+
require_fallbacks
|
2063
2060
|
|
2064
|
-
|
2065
|
-
prev_fallbacks = I18n.fallbacks.dup
|
2061
|
+
before do
|
2066
2062
|
I18n.fallbacks[:he] = [ :en ]
|
2067
|
-
example.run
|
2068
|
-
I18n.fallbacks = prev_fallbacks
|
2069
2063
|
end
|
2070
2064
|
|
2071
2065
|
let(:plucked) do
|
@@ -2093,6 +2087,8 @@ describe Mongoid::Criteria do
|
|
2093
2087
|
end
|
2094
2088
|
|
2095
2089
|
context "when the localized field is embedded" do
|
2090
|
+
with_default_i18n_configs
|
2091
|
+
|
2096
2092
|
before do
|
2097
2093
|
p = Passport.new
|
2098
2094
|
I18n.locale = :en
|
@@ -591,33 +591,6 @@ describe Mongoid::Document do
|
|
591
591
|
expect(person.as_document["addresses"].first).to have_key(:locations)
|
592
592
|
end
|
593
593
|
|
594
|
-
context 'when modifying the returned object' do
|
595
|
-
let(:record) do
|
596
|
-
RootCategory.create(categories: [{ name: 'tests' }]).reload
|
597
|
-
end
|
598
|
-
|
599
|
-
shared_examples_for 'an object with protected internal state' do
|
600
|
-
it 'does not expose internal state' do
|
601
|
-
before_change = record.as_document.dup
|
602
|
-
record.categories.first.name = 'things'
|
603
|
-
after_change = record.as_document
|
604
|
-
expect(before_change['categories'].first['name']).not_to eq('things')
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
context 'when legacy_attributes is true' do
|
609
|
-
config_override :legacy_attributes, true
|
610
|
-
|
611
|
-
it_behaves_like 'an object with protected internal state'
|
612
|
-
end
|
613
|
-
|
614
|
-
context 'when legacy_attributes is false' do
|
615
|
-
config_override :legacy_attributes, false
|
616
|
-
|
617
|
-
it_behaves_like 'an object with protected internal state'
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
594
|
context "with relation define store_as option in embeded_many" do
|
622
595
|
|
623
596
|
let!(:phone) do
|
@@ -12,13 +12,13 @@ describe Mongoid::Errors::ReadonlyDocument do
|
|
12
12
|
|
13
13
|
it "contains the problem in the message" do
|
14
14
|
expect(error.message).to include(
|
15
|
-
"Attempted to persist
|
15
|
+
"Attempted to persist a readonly document of class 'Band'."
|
16
16
|
)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "contains the summary in the message" do
|
20
20
|
expect(error.message).to include(
|
21
|
-
"Documents
|
21
|
+
"Documents that are marked readonly cannot be persisted"
|
22
22
|
)
|
23
23
|
end
|
24
24
|
|
@@ -178,7 +178,7 @@ describe Mongoid::Extensions::Hash do
|
|
178
178
|
|
179
179
|
it "moves the non hash values under the provided key" do
|
180
180
|
expect(consolidated).to eq({
|
181
|
-
"$set" => {
|
181
|
+
"$set" => { name: "Tool", likes: 10 }, "$inc" => { plays: 1 }
|
182
182
|
})
|
183
183
|
end
|
184
184
|
end
|
@@ -195,7 +195,7 @@ describe Mongoid::Extensions::Hash do
|
|
195
195
|
|
196
196
|
it "moves the non hash values under the provided key" do
|
197
197
|
expect(consolidated).to eq({
|
198
|
-
"$set" => { likes: 10,
|
198
|
+
"$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
|
199
199
|
})
|
200
200
|
end
|
201
201
|
end
|
@@ -213,7 +213,7 @@ describe Mongoid::Extensions::Hash do
|
|
213
213
|
|
214
214
|
it "moves the non hash values under the provided key" do
|
215
215
|
expect(consolidated).to eq({
|
216
|
-
"$set" => { likes: 10, name: "Tool" }, "$inc" => {
|
216
|
+
"$set" => { likes: 10, name: "Tool" }, "$inc" => { plays: 1 }
|
217
217
|
})
|
218
218
|
end
|
219
219
|
end
|
@@ -50,14 +50,7 @@ describe Mongoid::Extensions::Time do
|
|
50
50
|
|
51
51
|
context "when using the ActiveSupport time zone" do
|
52
52
|
config_override :use_activesupport_time_zone, true
|
53
|
-
|
54
|
-
before do
|
55
|
-
Time.zone = "Stockholm"
|
56
|
-
end
|
57
|
-
|
58
|
-
after do
|
59
|
-
Time.zone = nil
|
60
|
-
end
|
53
|
+
time_zone_override "Stockholm"
|
61
54
|
|
62
55
|
context "when demongoizing a Time" do
|
63
56
|
|
@@ -123,19 +116,12 @@ describe Mongoid::Extensions::Time do
|
|
123
116
|
|
124
117
|
context "when using the ActiveSupport time zone" do
|
125
118
|
config_override :use_activesupport_time_zone, true
|
119
|
+
time_zone_override "Stockholm"
|
126
120
|
|
127
121
|
let(:time) do
|
128
122
|
Time.utc(2010, 11, 19, 0, 30)
|
129
123
|
end
|
130
124
|
|
131
|
-
before do
|
132
|
-
Time.zone = "Stockholm"
|
133
|
-
end
|
134
|
-
|
135
|
-
after do
|
136
|
-
Time.zone = nil
|
137
|
-
end
|
138
|
-
|
139
125
|
it "returns utc" do
|
140
126
|
expect(Time.demongoize(time)).to eq(
|
141
127
|
ActiveSupport::TimeZone['UTC'].local(2010, 11, 19, 0, 30)
|
@@ -855,20 +841,13 @@ describe Mongoid::Extensions::Time do
|
|
855
841
|
|
856
842
|
context "when using the ActiveSupport time zone" do
|
857
843
|
config_override :use_activesupport_time_zone, true
|
844
|
+
# if this is actually your time zone, the following tests are useless
|
845
|
+
time_zone_override "Stockholm"
|
858
846
|
|
859
847
|
let(:datetime) do
|
860
848
|
DateTime.new(2010, 11, 19)
|
861
849
|
end
|
862
850
|
|
863
|
-
before do
|
864
|
-
# if this is actually your time zone, the following tests are useless
|
865
|
-
Time.zone = "Stockholm"
|
866
|
-
end
|
867
|
-
|
868
|
-
after do
|
869
|
-
Time.zone = nil
|
870
|
-
end
|
871
|
-
|
872
851
|
it "assumes the given time is local" do
|
873
852
|
expect(Time.mongoize(datetime)).to eq(
|
874
853
|
Time.utc(2010, 11, 19)
|
@@ -945,20 +924,13 @@ describe Mongoid::Extensions::Time do
|
|
945
924
|
|
946
925
|
context "when using the ActiveSupport time zone" do
|
947
926
|
config_override :use_activesupport_time_zone, true
|
927
|
+
# if this is actually your time zone, the following tests are useless
|
928
|
+
time_zone_override "Stockholm"
|
948
929
|
|
949
930
|
let(:date) do
|
950
931
|
Date.new(2010, 11, 19)
|
951
932
|
end
|
952
933
|
|
953
|
-
before do
|
954
|
-
# if this is actually your time zone, the following tests are useless
|
955
|
-
Time.zone = "Stockholm"
|
956
|
-
end
|
957
|
-
|
958
|
-
after do
|
959
|
-
Time.zone = nil
|
960
|
-
end
|
961
|
-
|
962
934
|
it "assumes the given time is local" do
|
963
935
|
expect(Time.mongoize(date)).to eq(Time.utc(2010, 11, 18, 23))
|
964
936
|
end
|
@@ -977,15 +949,8 @@ describe Mongoid::Extensions::Time do
|
|
977
949
|
|
978
950
|
context "when using the ActiveSupport time zone" do
|
979
951
|
config_override :use_activesupport_time_zone, true
|
980
|
-
|
981
|
-
|
982
|
-
# if this is actually your time zone, the following tests are useless
|
983
|
-
Time.zone = "Stockholm"
|
984
|
-
end
|
985
|
-
|
986
|
-
after do
|
987
|
-
Time.zone = nil
|
988
|
-
end
|
952
|
+
# if this is actually your time zone, the following tests are useless
|
953
|
+
time_zone_override "Stockholm"
|
989
954
|
|
990
955
|
it "assumes the given time is local" do
|
991
956
|
expect(Time.mongoize(array)).to eq(
|
@@ -50,14 +50,7 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
50
50
|
|
51
51
|
context "when using the ActiveSupport time zone" do
|
52
52
|
config_override :use_activesupport_time_zone, true
|
53
|
-
|
54
|
-
before do
|
55
|
-
Time.zone = "Stockholm"
|
56
|
-
end
|
57
|
-
|
58
|
-
after do
|
59
|
-
Time.zone = nil
|
60
|
-
end
|
53
|
+
time_zone_override "Stockholm"
|
61
54
|
|
62
55
|
it "returns an ActiveSupport::TimeWithZone" do
|
63
56
|
expect(ActiveSupport::TimeWithZone.demongoize(time).class).to eq(ActiveSupport::TimeWithZone)
|
@@ -113,19 +106,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
113
106
|
|
114
107
|
context "when using the ActiveSupport time zone" do
|
115
108
|
config_override :use_activesupport_time_zone, true
|
109
|
+
time_zone_override "Stockholm"
|
116
110
|
|
117
111
|
let(:time) do
|
118
112
|
Time.utc(2010, 11, 19, 0, 30)
|
119
113
|
end
|
120
114
|
|
121
|
-
before do
|
122
|
-
Time.zone = "Stockholm"
|
123
|
-
end
|
124
|
-
|
125
|
-
after do
|
126
|
-
Time.zone = nil
|
127
|
-
end
|
128
|
-
|
129
115
|
it "returns utc" do
|
130
116
|
expect(ActiveSupport::TimeWithZone.demongoize(time)).to eq(
|
131
117
|
ActiveSupport::TimeZone['UTC'].local(2010, 11, 19, 0, 30)
|
@@ -203,15 +189,8 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
203
189
|
|
204
190
|
context "when using the ActiveSupport time zone" do
|
205
191
|
config_override :use_activesupport_time_zone, true
|
206
|
-
|
207
|
-
|
208
|
-
# if this is actually your time zone, the following tests are useless
|
209
|
-
Time.zone = "Stockholm"
|
210
|
-
end
|
211
|
-
|
212
|
-
after do
|
213
|
-
Time.zone = nil
|
214
|
-
end
|
192
|
+
# if this is actually your time zone, the following tests are useless
|
193
|
+
time_zone_override "Stockholm"
|
215
194
|
|
216
195
|
context "when the local time is not observing daylight saving" do
|
217
196
|
|
@@ -247,20 +226,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
247
226
|
|
248
227
|
context "when using the ActiveSupport time zone" do
|
249
228
|
config_override :use_activesupport_time_zone, true
|
229
|
+
time_zone_override "Stockholm"
|
250
230
|
|
251
231
|
let(:datetime) do
|
252
232
|
DateTime.new(2010, 11, 19)
|
253
233
|
end
|
254
234
|
|
255
|
-
before do
|
256
|
-
# if this is actually your time zone, the following tests are useless
|
257
|
-
Time.zone = "Stockholm"
|
258
|
-
end
|
259
|
-
|
260
|
-
after do
|
261
|
-
Time.zone = nil
|
262
|
-
end
|
263
|
-
|
264
235
|
it "assumes the given time is local" do
|
265
236
|
expect(ActiveSupport::TimeWithZone.mongoize(datetime)).to eq(
|
266
237
|
Time.utc(2010, 11, 19)
|
@@ -317,20 +288,12 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
317
288
|
|
318
289
|
context "when using the ActiveSupport time zone" do
|
319
290
|
config_override :use_activesupport_time_zone, true
|
291
|
+
time_zone_override "Stockholm"
|
320
292
|
|
321
293
|
let(:date) do
|
322
294
|
Date.new(2010, 11, 19)
|
323
295
|
end
|
324
296
|
|
325
|
-
before do
|
326
|
-
# if this is actually your time zone, the following tests are useless
|
327
|
-
Time.zone = "Stockholm"
|
328
|
-
end
|
329
|
-
|
330
|
-
after do
|
331
|
-
Time.zone = nil
|
332
|
-
end
|
333
|
-
|
334
297
|
it "assumes the given time is local" do
|
335
298
|
expect(ActiveSupport::TimeWithZone.mongoize(date)).to eq(Time.utc(2010, 11, 18, 23))
|
336
299
|
end
|
@@ -349,15 +312,7 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
349
312
|
|
350
313
|
context "when using the ActiveSupport time zone" do
|
351
314
|
config_override :use_activesupport_time_zone, true
|
352
|
-
|
353
|
-
before do
|
354
|
-
# if this is actually your time zone, the following tests are useless
|
355
|
-
Time.zone = "Stockholm"
|
356
|
-
end
|
357
|
-
|
358
|
-
after do
|
359
|
-
Time.zone = nil
|
360
|
-
end
|
315
|
+
time_zone_override "Stockholm"
|
361
316
|
|
362
317
|
it "assumes the given time is local" do
|
363
318
|
expect(ActiveSupport::TimeWithZone.mongoize(array)).to eq(
|