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
@@ -277,28 +277,77 @@ describe Mongoid::Extensions::String do
|
|
277
277
|
context "when the string is an integer" do
|
278
278
|
|
279
279
|
it "returns true" do
|
280
|
-
expect("1234").to
|
280
|
+
expect("1234".numeric?).to eq(true)
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
284
|
context "when string is a float" do
|
285
285
|
|
286
286
|
it "returns true" do
|
287
|
-
expect("1234.123").to
|
287
|
+
expect("1234.123".numeric?).to eq(true)
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
context "when the string is has exponents" do
|
292
292
|
|
293
293
|
it "returns true" do
|
294
|
-
expect("1234.123123E4").to
|
294
|
+
expect("1234.123123E4".numeric?).to eq(true)
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
298
298
|
context "when the string is non numeric" do
|
299
299
|
|
300
300
|
it "returns false" do
|
301
|
-
expect("blah").
|
301
|
+
expect("blah".numeric?).to eq(false)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "when the string is NaN" do
|
306
|
+
|
307
|
+
it "returns true" do
|
308
|
+
expect("NaN".numeric?).to eq(true)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context "when the string is NaN and junk in front" do
|
313
|
+
|
314
|
+
it "returns false" do
|
315
|
+
expect("a\nNaN".numeric?).to eq(false)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "when the string is NaN and whitespace at end" do
|
320
|
+
|
321
|
+
it "returns false" do
|
322
|
+
expect("NaN\n".numeric?).to eq(false)
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context "when the string is Infinity" do
|
327
|
+
|
328
|
+
it "returns true" do
|
329
|
+
expect("Infinity".numeric?).to eq(true)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when the string contains Infinity and junk in front" do
|
334
|
+
|
335
|
+
it "returns false" do
|
336
|
+
expect("a\nInfinity".numeric?).to eq(false)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
context "when the string contains Infinity and whitespace at end" do
|
341
|
+
|
342
|
+
it "returns false" do
|
343
|
+
expect("Infinity\n".numeric?).to eq(false)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
context "when the string is -Infinity" do
|
348
|
+
|
349
|
+
it "returns true" do
|
350
|
+
expect("-Infinity".numeric?).to eq(true)
|
302
351
|
end
|
303
352
|
end
|
304
353
|
end
|
@@ -204,12 +204,8 @@ describe Mongoid::Extensions::Time do
|
|
204
204
|
|
205
205
|
context "when the string is an invalid time" do
|
206
206
|
|
207
|
-
|
208
|
-
Time.
|
209
|
-
end
|
210
|
-
|
211
|
-
it "converts the time to epoch" do
|
212
|
-
expect(Time.mongoize("time")).to eq(epoch)
|
207
|
+
it "converts the time to nil" do
|
208
|
+
expect(Time.mongoize("time")).to eq(nil)
|
213
209
|
end
|
214
210
|
end
|
215
211
|
|
@@ -204,12 +204,8 @@ describe Mongoid::Extensions::TimeWithZone do
|
|
204
204
|
|
205
205
|
context "when the string is an invalid time" do
|
206
206
|
|
207
|
-
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
it "returns epoch" do
|
212
|
-
expect(ActiveSupport::TimeWithZone.mongoize("time")).to eq(epoch)
|
207
|
+
it "returns nil" do
|
208
|
+
expect(ActiveSupport::TimeWithZone.mongoize("time")).to eq(nil)
|
213
209
|
end
|
214
210
|
end
|
215
211
|
|
@@ -88,6 +88,17 @@ describe Mongoid::Factory do
|
|
88
88
|
expect(person.title).to eq("Sir")
|
89
89
|
end
|
90
90
|
end
|
91
|
+
|
92
|
+
context "when the type is a symbol" do
|
93
|
+
|
94
|
+
let(:person) do
|
95
|
+
described_class.build(Person, {:_type => "Doctor"})
|
96
|
+
end
|
97
|
+
|
98
|
+
it "instantiates the subclass" do
|
99
|
+
expect(person.class).to eq(Doctor)
|
100
|
+
end
|
101
|
+
end
|
91
102
|
end
|
92
103
|
|
93
104
|
describe ".from_db" do
|
data/spec/mongoid/fields_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Mongoid::Findable do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "returns the distinct values for the field" do
|
13
|
-
expect(Band.distinct(:name)).to eq([ "
|
13
|
+
expect(Band.distinct(:name).sort).to eq([ "Photek", "Tool" ])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -476,7 +476,7 @@ describe Mongoid::Findable do
|
|
476
476
|
end
|
477
477
|
end
|
478
478
|
|
479
|
-
|
479
|
+
Mongoid::Criteria::Queryable::Selectable.forwardables.each do |method|
|
480
480
|
|
481
481
|
describe "##{method}" do
|
482
482
|
|
@@ -485,4 +485,49 @@ describe Mongoid::Findable do
|
|
485
485
|
end
|
486
486
|
end
|
487
487
|
end
|
488
|
+
|
489
|
+
context 'when Mongoid is configured to use activesupport time zone' do
|
490
|
+
|
491
|
+
before do
|
492
|
+
Mongoid.use_utc = false
|
493
|
+
Mongoid.use_activesupport_time_zone = true
|
494
|
+
Time.zone = "Asia/Kolkata"
|
495
|
+
end
|
496
|
+
|
497
|
+
let!(:time) do
|
498
|
+
Time.zone.now.tap do |t|
|
499
|
+
User.create(last_login: t, name: 'Tom')
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
it 'uses activesupport time zone' do
|
504
|
+
expect(User.distinct(:last_login).first.to_s).to eql(time.in_time_zone('Asia/Kolkata').to_s)
|
505
|
+
end
|
506
|
+
|
507
|
+
it 'loads other fields accurately' do
|
508
|
+
expect(User.distinct(:name)).to match_array(['Tom'])
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context 'when Mongoid is not configured to use activesupport time zone' do
|
513
|
+
|
514
|
+
before do
|
515
|
+
Mongoid.use_utc = true
|
516
|
+
Mongoid.use_activesupport_time_zone = false
|
517
|
+
end
|
518
|
+
|
519
|
+
let!(:time) do
|
520
|
+
Time.now.tap do |t|
|
521
|
+
User.create(last_login: t, name: 'Tom')
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
it 'uses utc' do
|
526
|
+
expect(User.distinct(:last_login).first.to_s).to eql(time.utc.to_s)
|
527
|
+
end
|
528
|
+
|
529
|
+
it 'loads other fields accurately' do
|
530
|
+
expect(User.distinct(:name)).to match_array(['Tom'])
|
531
|
+
end
|
532
|
+
end
|
488
533
|
end
|
@@ -2,6 +2,10 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::Indexable do
|
4
4
|
|
5
|
+
after do
|
6
|
+
Person.collection.drop
|
7
|
+
end
|
8
|
+
|
5
9
|
describe ".included" do
|
6
10
|
|
7
11
|
let(:klass) do
|
@@ -58,7 +62,9 @@ describe Mongoid::Indexable do
|
|
58
62
|
end
|
59
63
|
|
60
64
|
let(:indexes) do
|
61
|
-
klass.with(database: "mongoid_optional")
|
65
|
+
klass.with(database: "mongoid_optional") do |klass|
|
66
|
+
klass.collection.indexes
|
67
|
+
end
|
62
68
|
end
|
63
69
|
|
64
70
|
it "creates the indexes" do
|
@@ -107,7 +113,9 @@ describe Mongoid::Indexable do
|
|
107
113
|
end
|
108
114
|
|
109
115
|
let(:indexes) do
|
110
|
-
klass.with(database: "mongoid_optional")
|
116
|
+
klass.with(database: "mongoid_optional") do |klass|
|
117
|
+
klass.collection.indexes
|
118
|
+
end
|
111
119
|
end
|
112
120
|
|
113
121
|
it "creates the indexes" do
|
@@ -121,7 +129,7 @@ describe Mongoid::Indexable do
|
|
121
129
|
Class.new do
|
122
130
|
include Mongoid::Document
|
123
131
|
store_in collection: "test_db_indexes"
|
124
|
-
index({name: 1}, {collation: {locale: 'en_US', strength: 2}})
|
132
|
+
index({ name: 1 }, { collation: { locale: 'en_US', strength: 2 }})
|
125
133
|
end
|
126
134
|
end
|
127
135
|
|
@@ -181,6 +189,10 @@ describe Mongoid::Indexable do
|
|
181
189
|
end
|
182
190
|
end
|
183
191
|
|
192
|
+
after do
|
193
|
+
klass.collection.drop
|
194
|
+
end
|
195
|
+
|
184
196
|
context "when indexing a field that is aliased" do
|
185
197
|
|
186
198
|
before do
|
@@ -280,13 +280,18 @@ describe Mongoid::Interceptable do
|
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
|
-
context "callback
|
283
|
+
context "callback aborts the callback chain" do
|
284
284
|
|
285
285
|
before do
|
286
|
-
|
286
|
+
Artist.before_create(:before_create_fail_stub)
|
287
|
+
expect(artist).to receive(:before_create_fail_stub).once.and_call_original
|
287
288
|
artist.save
|
288
289
|
end
|
289
290
|
|
291
|
+
after do
|
292
|
+
Artist.reset_callbacks(:create)
|
293
|
+
end
|
294
|
+
|
290
295
|
it "does not get saved" do
|
291
296
|
expect(artist.persisted?).to be false
|
292
297
|
end
|
@@ -316,13 +321,18 @@ describe Mongoid::Interceptable do
|
|
316
321
|
end
|
317
322
|
end
|
318
323
|
|
319
|
-
context "when callback
|
324
|
+
context "when callback halts the callback chain" do
|
320
325
|
|
321
326
|
before do
|
322
|
-
|
327
|
+
Artist.before_save(:before_save_fail_stub)
|
328
|
+
end
|
329
|
+
|
330
|
+
after do
|
331
|
+
Artist.reset_callbacks(:save)
|
323
332
|
end
|
324
333
|
|
325
334
|
it "the save returns false" do
|
335
|
+
expect(artist).to receive(:before_save_fail_stub).once.and_call_original
|
326
336
|
expect(artist.save).to be false
|
327
337
|
end
|
328
338
|
end
|
@@ -343,7 +353,7 @@ describe Mongoid::Interceptable do
|
|
343
353
|
context "when the callback returns true" do
|
344
354
|
|
345
355
|
before do
|
346
|
-
expect(artist).to receive(:
|
356
|
+
expect(artist).to receive(:before_update_stub).once.and_return(true)
|
347
357
|
end
|
348
358
|
|
349
359
|
it "the save returns true" do
|
@@ -351,13 +361,18 @@ describe Mongoid::Interceptable do
|
|
351
361
|
end
|
352
362
|
end
|
353
363
|
|
354
|
-
context "when the callback
|
364
|
+
context "when the callback halts the callback chain" do
|
355
365
|
|
356
366
|
before do
|
357
|
-
|
367
|
+
Artist.before_update(:before_update_fail_stub)
|
368
|
+
end
|
369
|
+
|
370
|
+
after do
|
371
|
+
Artist.reset_callbacks(:update)
|
358
372
|
end
|
359
373
|
|
360
374
|
it "the save returns false" do
|
375
|
+
expect(artist).to receive(:before_update_fail_stub).once.and_call_original
|
361
376
|
expect(artist.save).to be false
|
362
377
|
end
|
363
378
|
end
|
@@ -389,13 +404,18 @@ describe Mongoid::Interceptable do
|
|
389
404
|
end
|
390
405
|
end
|
391
406
|
|
392
|
-
context "when the callback
|
407
|
+
context "when the callback halts the callback chain" do
|
393
408
|
|
394
409
|
before do
|
395
|
-
|
410
|
+
Artist.before_destroy(:before_destroy_fail_stub)
|
411
|
+
end
|
412
|
+
|
413
|
+
after do
|
414
|
+
Artist.reset_callbacks(:destroy)
|
396
415
|
end
|
397
416
|
|
398
417
|
it "the destroy returns false" do
|
418
|
+
expect(artist).to receive(:before_destroy_fail_stub).once.and_call_original
|
399
419
|
expect(artist.destroy).to be false
|
400
420
|
end
|
401
421
|
end
|
@@ -464,32 +484,40 @@ describe Mongoid::Interceptable do
|
|
464
484
|
|
465
485
|
context "when the child does not have the same callback defined" do
|
466
486
|
|
467
|
-
let(:
|
468
|
-
|
487
|
+
let(:exhibition) do
|
488
|
+
Exhibition.new
|
469
489
|
end
|
470
490
|
|
471
|
-
let!(:
|
472
|
-
|
491
|
+
let!(:exhibitor) do
|
492
|
+
exhibition.exhibitors.build
|
473
493
|
end
|
474
494
|
|
475
495
|
context "when running the callbacks directly" do
|
476
496
|
|
477
497
|
before(:all) do
|
478
|
-
|
479
|
-
|
498
|
+
Exhibition.define_model_callbacks(:rearrange)
|
499
|
+
Exhibition.after_rearrange { }
|
480
500
|
end
|
481
501
|
|
482
502
|
after(:all) do
|
483
|
-
|
503
|
+
Exhibition.reset_callbacks(:rearrange)
|
484
504
|
end
|
485
505
|
|
486
506
|
it "does not cascade to the child" do
|
487
|
-
expect(
|
507
|
+
expect(exhibition.run_callbacks(:rearrange)).to be true
|
488
508
|
end
|
489
509
|
end
|
490
510
|
|
491
511
|
context "when the callbacks get triggered by a destroy" do
|
492
512
|
|
513
|
+
let(:band) do
|
514
|
+
Band.new
|
515
|
+
end
|
516
|
+
|
517
|
+
let!(:record) do
|
518
|
+
band.records.build
|
519
|
+
end
|
520
|
+
|
493
521
|
before(:all) do
|
494
522
|
Band.define_model_callbacks(:rearrange)
|
495
523
|
Band.set_callback(:validation, :before) do
|
@@ -498,7 +526,7 @@ describe Mongoid::Interceptable do
|
|
498
526
|
end
|
499
527
|
|
500
528
|
after(:all) do
|
501
|
-
Band.reset_callbacks(:rearrange)
|
529
|
+
begin; Band.reset_callbacks(:rearrange); rescue; end
|
502
530
|
end
|
503
531
|
|
504
532
|
let(:attributes) do
|
@@ -1132,6 +1160,25 @@ describe Mongoid::Interceptable do
|
|
1132
1160
|
expect(band.reload.records.first.before_validation_called).to be true
|
1133
1161
|
end
|
1134
1162
|
end
|
1163
|
+
|
1164
|
+
context 'when the parent is updated' do
|
1165
|
+
|
1166
|
+
let(:band) do
|
1167
|
+
Band.create(name: "Moderat")
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
before do
|
1171
|
+
band.update(records: [ { name: 'Black on Both Sides' }])
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
it 'executes the callback' do
|
1175
|
+
expect(band.records.first.before_validation_called).to be true
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
it 'persists the change' do
|
1179
|
+
expect(band.reload.records.first.before_validation_called).to be true
|
1180
|
+
end
|
1181
|
+
end
|
1135
1182
|
end
|
1136
1183
|
|
1137
1184
|
context "when the child is persisted" do
|
@@ -1434,6 +1481,25 @@ describe Mongoid::Interceptable do
|
|
1434
1481
|
end
|
1435
1482
|
end
|
1436
1483
|
|
1484
|
+
describe '#after_destroy' do
|
1485
|
+
|
1486
|
+
context 'when the parent is updated in a child after_destroy callback' do
|
1487
|
+
|
1488
|
+
let!(:person) do
|
1489
|
+
Person.create!(ordered_posts: [OrderedPost.new])
|
1490
|
+
end
|
1491
|
+
|
1492
|
+
before do
|
1493
|
+
post = OrderedPost.first
|
1494
|
+
post.destroy
|
1495
|
+
end
|
1496
|
+
|
1497
|
+
it 'updates the parent' do
|
1498
|
+
expect(person.reload.title).to eq('Minus one ordered post.')
|
1499
|
+
end
|
1500
|
+
end
|
1501
|
+
end
|
1502
|
+
|
1437
1503
|
describe "#before_validation" do
|
1438
1504
|
|
1439
1505
|
context "when the child is new" do
|
@@ -1544,7 +1610,7 @@ describe Mongoid::Interceptable do
|
|
1544
1610
|
|
1545
1611
|
before(:all) do
|
1546
1612
|
Person.before_save do |doc|
|
1547
|
-
doc.mode
|
1613
|
+
throw(:abort) if doc.mode == :prevent_save
|
1548
1614
|
end
|
1549
1615
|
end
|
1550
1616
|
|
@@ -6,25 +6,25 @@ describe Mongoid::Matchable::All do
|
|
6
6
|
described_class.new(["first", "second", "third"])
|
7
7
|
end
|
8
8
|
|
9
|
-
describe "#
|
9
|
+
describe "#_matches?" do
|
10
10
|
|
11
11
|
context "when the attribute includes all of the values" do
|
12
12
|
|
13
13
|
it "returns true" do
|
14
|
-
expect(matcher.
|
14
|
+
expect(matcher._matches?("$all" => ["first", /\Asec.*\z/])).to be true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "when the attributes doesn't include all of the values" do
|
19
19
|
|
20
20
|
it "returns false" do
|
21
|
-
expect(matcher.
|
21
|
+
expect(matcher._matches?("$all" => ["second", "third", "fourth"])).to be false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when the value is empty" do
|
26
26
|
it "returns false" do
|
27
|
-
expect(matcher.
|
27
|
+
expect(matcher._matches?("$all" => [])).to be false
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -10,7 +10,7 @@ describe Mongoid::Matchable::And do
|
|
10
10
|
described_class.new("value", person)
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "#
|
13
|
+
describe "#_matches?" do
|
14
14
|
|
15
15
|
context "when provided a simple expression" do
|
16
16
|
|
@@ -19,7 +19,7 @@ describe Mongoid::Matchable::And do
|
|
19
19
|
context "when the value matches" do
|
20
20
|
|
21
21
|
let(:matches) do
|
22
|
-
matcher.
|
22
|
+
matcher._matches?([ { title: "Sir" } ])
|
23
23
|
end
|
24
24
|
|
25
25
|
before do
|
@@ -34,7 +34,7 @@ describe Mongoid::Matchable::And do
|
|
34
34
|
context "when the expression is a $not" do
|
35
35
|
|
36
36
|
let(:matches) do
|
37
|
-
matcher.
|
37
|
+
matcher._matches?([ { title: {:$not => /Foobar/ } }])
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when the value matches" do
|
@@ -59,7 +59,7 @@ describe Mongoid::Matchable::And do
|
|
59
59
|
context "when the value does not match" do
|
60
60
|
|
61
61
|
let(:matches) do
|
62
|
-
matcher.
|
62
|
+
matcher._matches?([ { title: "Sir" } ])
|
63
63
|
end
|
64
64
|
|
65
65
|
it "returns false" do
|
@@ -73,7 +73,7 @@ describe Mongoid::Matchable::And do
|
|
73
73
|
context "when all of the values are equal" do
|
74
74
|
|
75
75
|
let(:matches) do
|
76
|
-
matcher.
|
76
|
+
matcher._matches?(
|
77
77
|
[ { title: "Sir" }, { _id: person.id } ]
|
78
78
|
)
|
79
79
|
end
|
@@ -90,7 +90,7 @@ describe Mongoid::Matchable::And do
|
|
90
90
|
context "when one of the values does not match" do
|
91
91
|
|
92
92
|
let(:matches) do
|
93
|
-
matcher.
|
93
|
+
matcher._matches?(
|
94
94
|
[ { title: "Sir" }, { _id: BSON::ObjectId.new } ]
|
95
95
|
)
|
96
96
|
end
|
@@ -107,7 +107,7 @@ describe Mongoid::Matchable::And do
|
|
107
107
|
context "when provided no expressions" do
|
108
108
|
|
109
109
|
let(:matches) do
|
110
|
-
matcher.
|
110
|
+
matcher._matches?([])
|
111
111
|
end
|
112
112
|
|
113
113
|
it "returns true" do
|
@@ -122,7 +122,7 @@ describe Mongoid::Matchable::And do
|
|
122
122
|
context "when all of the values are equal" do
|
123
123
|
|
124
124
|
let(:matches) do
|
125
|
-
matcher.
|
125
|
+
matcher._matches?(
|
126
126
|
[
|
127
127
|
{ title: { "$in" => [ "Sir", "Madam" ] } },
|
128
128
|
{ _id: person.id }
|
@@ -142,7 +142,7 @@ describe Mongoid::Matchable::And do
|
|
142
142
|
context "when one of the values does not match" do
|
143
143
|
|
144
144
|
let(:matches) do
|
145
|
-
matcher.
|
145
|
+
matcher._matches?(
|
146
146
|
[
|
147
147
|
{ title: { "$in" => [ "Prince", "Madam" ] } },
|
148
148
|
{ _id: BSON::ObjectId.new }
|
@@ -164,7 +164,7 @@ describe Mongoid::Matchable::And do
|
|
164
164
|
context "when all the expressions match" do
|
165
165
|
|
166
166
|
let(:matches) do
|
167
|
-
matcher.
|
167
|
+
matcher._matches?(
|
168
168
|
[
|
169
169
|
{ title: "Sir", age: 23 },
|
170
170
|
{ _id: person.id }
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Mongoid::Matchable::Default do
|
4
4
|
|
5
|
-
describe "#
|
5
|
+
describe "#_matches?" do
|
6
6
|
|
7
7
|
context "when comparing strings" do
|
8
8
|
|
@@ -13,14 +13,14 @@ describe Mongoid::Matchable::Default do
|
|
13
13
|
context "when the values are equal" do
|
14
14
|
|
15
15
|
it "returns true" do
|
16
|
-
expect(matcher.
|
16
|
+
expect(matcher._matches?("Testing")).to be true
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context "when the values are not equal" do
|
21
21
|
|
22
22
|
it "returns false" do
|
23
|
-
expect(matcher.
|
23
|
+
expect(matcher._matches?("Other")).to be false
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -38,14 +38,14 @@ describe Mongoid::Matchable::Default do
|
|
38
38
|
context "when the values are equal" do
|
39
39
|
|
40
40
|
it "returns true" do
|
41
|
-
expect(matcher.
|
41
|
+
expect(matcher._matches?(object_id)).to be true
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
context "when the values are not equal" do
|
46
46
|
|
47
47
|
it "returns false" do
|
48
|
-
expect(matcher.
|
48
|
+
expect(matcher._matches?(BSON::ObjectId.new)).to be false
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -61,14 +61,14 @@ describe Mongoid::Matchable::Default do
|
|
61
61
|
context "when the value is a string" do
|
62
62
|
|
63
63
|
it "returns true" do
|
64
|
-
expect(matcher.
|
64
|
+
expect(matcher._matches?("Test1")).to be true
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
context "when the value is a regexp" do
|
69
69
|
|
70
70
|
it "returns true" do
|
71
|
-
expect(matcher.
|
71
|
+
expect(matcher._matches?(/^Test[3-5]$/)).to be true
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -76,7 +76,7 @@ describe Mongoid::Matchable::Default do
|
|
76
76
|
context "when the attribute does not contain the value" do
|
77
77
|
|
78
78
|
it "returns false" do
|
79
|
-
expect(matcher.
|
79
|
+
expect(matcher._matches?("Test4")).to be false
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
@@ -94,14 +94,14 @@ describe Mongoid::Matchable::Default do
|
|
94
94
|
context "when the attribute contains the value" do
|
95
95
|
|
96
96
|
it "returns true" do
|
97
|
-
expect(matcher.
|
97
|
+
expect(matcher._matches?(object_id)).to be true
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
context "when the attribute does not contain the value" do
|
102
102
|
|
103
103
|
it "returns false" do
|
104
|
-
expect(matcher.
|
104
|
+
expect(matcher._matches?(BSON::ObjectId.new)).to be false
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -115,14 +115,14 @@ describe Mongoid::Matchable::Default do
|
|
115
115
|
context "when the attribute contains the value" do
|
116
116
|
|
117
117
|
it "returns true" do
|
118
|
-
expect(matcher.
|
118
|
+
expect(matcher._matches?(["Test1", "Test2", "Test3"])).to be true
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
context "when the attribute does not contain the value" do
|
123
123
|
|
124
124
|
it "returns false" do
|
125
|
-
expect(matcher.
|
125
|
+
expect(matcher._matches?(["Test1", "Test2"])).to be false
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|