mongoid 6.4.2 → 7.0.3
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
- data/README.md +1 -1
- data/lib/config/locales/en.yml +17 -0
- data/lib/mongoid/association/accessors.rb +339 -0
- data/lib/mongoid/{relations/binding.rb → association/bindable.rb} +32 -52
- data/lib/mongoid/association/builders.rb +92 -0
- data/lib/mongoid/{relations/constraint.rb → association/constrainable.rb} +11 -22
- data/lib/mongoid/association/depending.rb +137 -0
- data/lib/mongoid/{relations/eager.rb → association/eager_loadable.rb} +11 -11
- data/lib/mongoid/{relations → association}/embedded/batchable.rb +19 -19
- data/lib/mongoid/association/embedded/cyclic.rb +109 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +56 -0
- data/lib/mongoid/{relations/builders/embedded/in.rb → association/embedded/embedded_in/buildable.rb} +12 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +121 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +154 -0
- data/lib/mongoid/{relations/bindings/embedded/many.rb → association/embedded/embeds_many/binding.rb} +11 -9
- data/lib/mongoid/{relations/builders/embedded/many.rb → association/embedded/embeds_many/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +552 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +210 -0
- data/lib/mongoid/{relations/bindings/embedded/one.rb → association/embedded/embeds_one/binding.rb} +12 -10
- data/lib/mongoid/{relations/builders/embedded/one.rb → association/embedded/embeds_one/buildable.rb} +13 -7
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +130 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +173 -0
- data/lib/mongoid/association/embedded.rb +4 -0
- data/lib/mongoid/association/macros.rb +204 -0
- data/lib/mongoid/{relations → association}/many.rb +19 -49
- data/lib/mongoid/{relations → association}/marshalable.rb +6 -4
- data/lib/mongoid/association/nested/many.rb +200 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +72 -0
- data/lib/mongoid/association/nested/one.rb +127 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/{relations → association}/one.rb +6 -6
- data/lib/mongoid/association/options.rb +152 -0
- data/lib/mongoid/{relations → association}/proxy.rb +31 -58
- data/lib/mongoid/association/referenced/auto_save.rb +79 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +87 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +46 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +36 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +136 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +248 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +163 -0
- data/lib/mongoid/association/referenced/eager.rb +162 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +71 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +52 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +312 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +290 -0
- data/lib/mongoid/{relations/bindings/referenced/many.rb → association/referenced/has_many/binding.rb} +6 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +43 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +510 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +578 -0
- data/lib/mongoid/association/referenced/has_many.rb +275 -0
- data/lib/mongoid/{relations/bindings/referenced/one.rb → association/referenced/has_one/binding.rb} +11 -8
- data/lib/mongoid/association/referenced/has_one/buildable.rb +60 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +35 -0
- data/lib/mongoid/{relations/builders/nested_attributes/one.rb → association/referenced/has_one/nested_builder.rb} +9 -9
- data/lib/mongoid/association/referenced/has_one/proxy.rb +113 -0
- data/lib/mongoid/association/referenced/has_one.rb +204 -0
- data/lib/mongoid/association/referenced/syncable.rb +170 -0
- data/lib/mongoid/association/referenced.rb +7 -0
- data/lib/mongoid/{relations → association}/reflections.rb +21 -17
- data/lib/mongoid/association/relatable.rb +509 -0
- data/lib/mongoid/{relations.rb → association.rb} +57 -56
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic.rb +4 -4
- data/lib/mongoid/attributes/dynamic.rb +2 -2
- data/lib/mongoid/attributes/nested.rb +22 -11
- data/lib/mongoid/attributes/processing.rb +2 -2
- data/lib/mongoid/attributes/readonly.rb +2 -4
- data/lib/mongoid/attributes.rb +22 -13
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config.rb +1 -0
- data/lib/mongoid/contextual/atomic.rb +1 -1
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +21 -3
- data/lib/mongoid/contextual/mongo.rb +10 -8
- data/lib/mongoid/copyable.rb +7 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -14
- data/lib/mongoid/criteria/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +37 -7
- data/lib/mongoid/criteria.rb +2 -2
- data/lib/mongoid/document.rb +15 -6
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +32 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +29 -0
- data/lib/mongoid/errors/unknown_model.rb +25 -0
- data/lib/mongoid/errors.rb +3 -0
- data/lib/mongoid/extensions/array.rb +5 -5
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/hash.rb +5 -2
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -0
- data/lib/mongoid/extensions.rb +0 -4
- data/lib/mongoid/factory.rb +13 -3
- data/lib/mongoid/fields/foreign_key.rb +5 -5
- data/lib/mongoid/fields/standard.rb +2 -14
- data/lib/mongoid/fields/validators/macro.rb +1 -1
- data/lib/mongoid/fields.rb +3 -3
- data/lib/mongoid/indexable.rb +4 -1
- data/lib/mongoid/interceptable.rb +5 -5
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/elem_match.rb +9 -3
- data/lib/mongoid/matchable/eq.rb +22 -0
- data/lib/mongoid/matchable/ne.rb +1 -1
- data/lib/mongoid/matchable.rb +3 -1
- data/lib/mongoid/persistable/deletable.rb +7 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -1
- data/lib/mongoid/persistable/logical.rb +1 -1
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +20 -5
- data/lib/mongoid/query_cache.rb +8 -4
- data/lib/mongoid/railtie.rb +17 -0
- data/lib/mongoid/railties/controller_runtime.rb +86 -0
- data/lib/mongoid/scopable.rb +3 -3
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/threaded.rb +36 -0
- data/lib/mongoid/touchable.rb +102 -0
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +4 -4
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/minim.rb +7 -0
- data/spec/app/models/person.rb +5 -2
- data/spec/app/models/shipment_address.rb +1 -0
- data/spec/app/models/store_as_dup_test3.rb +7 -0
- data/spec/app/models/store_as_dup_test4.rb +7 -0
- data/spec/app/models/updatable.rb +7 -0
- data/spec/app/models/vertex.rb +6 -0
- data/spec/app/models/wiki_page.rb +1 -1
- data/spec/config/mongoid.yml +13 -3
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/lite_spec_helper.rb +56 -0
- data/spec/mongoid/{relations → association}/accessors_spec.rb +40 -1
- data/spec/mongoid/{relations → association}/auto_save_spec.rb +60 -12
- data/spec/mongoid/{relations → association}/builders_spec.rb +1 -1
- data/spec/mongoid/association/constrainable_spec.rb +115 -0
- data/spec/mongoid/{relations → association}/counter_cache_spec.rb +1 -1
- data/spec/mongoid/association/depending_spec.rb +866 -0
- data/spec/mongoid/{relations → association}/eager_spec.rb +12 -12
- data/spec/mongoid/{relations → association/embedded}/cyclic_spec.rb +1 -1
- data/spec/mongoid/{relations/bindings/embedded/in_spec.rb → association/embedded/embedded_in/binding_spec.rb} +13 -13
- data/spec/mongoid/{relations/builders/embedded/in_spec.rb → association/embedded/embedded_in/buildable_spec.rb} +9 -9
- data/spec/mongoid/{relations/embedded/in_spec.rb → association/embedded/embedded_in/proxy_spec.rb} +5 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +843 -0
- data/spec/mongoid/{relations/bindings/embedded/many_spec.rb → association/embedded/embeds_many/binding_spec.rb} +3 -3
- data/spec/mongoid/{relations/builders/embedded/many_spec.rb → association/embedded/embeds_many/buildable_spec.rb} +17 -45
- data/spec/mongoid/{relations/embedded/many_spec.rb → association/embedded/embeds_many/proxy_spec.rb} +124 -182
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +852 -0
- data/spec/mongoid/{relations/bindings/embedded/one_spec.rb → association/embedded/embeds_one/binding_spec.rb} +4 -4
- data/spec/mongoid/{relations/builders/embedded/one_spec.rb → association/embedded/embeds_one/buildable_spec.rb} +14 -34
- data/spec/mongoid/{relations/embedded/one_spec.rb → association/embedded/embeds_one/proxy_spec.rb} +39 -84
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +908 -0
- data/spec/mongoid/{relations → association}/macros_spec.rb +148 -73
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/many_spec.rb +16 -19
- data/spec/mongoid/{relations/builders/nested_attributes → association/nested}/one_spec.rb +17 -20
- data/spec/mongoid/association/options_spec.rb +1321 -0
- data/spec/mongoid/{relations → association}/polymorphic_spec.rb +66 -34
- data/spec/mongoid/{relations/bindings/referenced/in_spec.rb → association/referenced/belongs_to/binding_spec.rb} +7 -7
- data/spec/mongoid/{relations/builders/referenced/in_spec.rb → association/referenced/belongs_to/buildable_spec.rb} +46 -79
- data/spec/mongoid/{relations/eager/belongs_to_spec.rb → association/referenced/belongs_to/eager_spec.rb} +33 -14
- data/spec/mongoid/{relations/referenced/in_spec.rb → association/referenced/belongs_to/proxy_spec.rb} +57 -91
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2006 -0
- data/spec/mongoid/{relations/bindings/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +121 -0
- data/spec/mongoid/{relations/eager/has_and_belongs_to_many_spec.rb → association/referenced/has_and_belongs_to_many/eager_spec.rb} +26 -7
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +56 -0
- data/spec/mongoid/{relations/referenced/many_to_many_spec.rb → association/referenced/has_and_belongs_to_many/proxy_spec.rb} +107 -98
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +26 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +1027 -0
- data/spec/mongoid/{relations/bindings/referenced/many_spec.rb → association/referenced/has_many/binding_spec.rb} +5 -5
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +119 -0
- data/spec/mongoid/{relations/eager/has_many_spec.rb → association/referenced/has_many/eager_spec.rb} +26 -11
- data/spec/mongoid/{relations/targets → association/referenced/has_many}/enumerable_spec.rb +122 -1
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/{relations/referenced/many_spec.rb → association/referenced/has_many/proxy_spec.rb} +28 -93
- data/spec/mongoid/association/referenced/has_many_models.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +1225 -0
- data/spec/mongoid/{relations/bindings/referenced/one_spec.rb → association/referenced/has_one/binding_spec.rb} +4 -4
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +113 -0
- data/spec/mongoid/{relations/eager/has_one_spec.rb → association/referenced/has_one/eager_spec.rb} +10 -10
- data/spec/mongoid/{relations/referenced/one_spec.rb → association/referenced/has_one/proxy_spec.rb} +9 -109
- data/spec/mongoid/association/referenced/has_one_models.rb +48 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1350 -0
- data/spec/mongoid/{relations → association}/reflections_spec.rb +1 -12
- data/spec/mongoid/{relations/synchronization_spec.rb → association/syncable_spec.rb} +4 -2
- data/spec/mongoid/{relations_spec.rb → association_spec.rb} +1 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +2 -2
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +38 -2
- data/spec/mongoid/clients/factory_spec.rb +24 -18
- data/spec/mongoid/clients/options_spec.rb +58 -44
- data/spec/mongoid/clients/sessions_spec.rb +1 -1
- data/spec/mongoid/clients/transactions_spec.rb +369 -0
- data/spec/mongoid/clients_spec.rb +68 -8
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +33 -5
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +183 -60
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -3
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +43 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +42 -3
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -2
- data/spec/mongoid/criteria/scopable_spec.rb +81 -0
- data/spec/mongoid/criteria_spec.rb +33 -18
- data/spec/mongoid/document_spec.rb +83 -4
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- data/spec/mongoid/extensions/big_decimal_spec.rb +9 -9
- data/spec/mongoid/extensions/hash_spec.rb +18 -1
- data/spec/mongoid/extensions/object_spec.rb +7 -11
- data/spec/mongoid/extensions/range_spec.rb +7 -0
- data/spec/mongoid/extensions/regexp_spec.rb +23 -0
- data/spec/mongoid/factory_spec.rb +19 -1
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +2 -2
- data/spec/mongoid/findable_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +18 -8
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable/eq_spec.rb +48 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +6 -6
- data/spec/mongoid/persistable/savable_spec.rb +2 -2
- data/spec/mongoid/persistable/settable_spec.rb +95 -10
- data/spec/mongoid/persistable_spec.rb +21 -6
- data/spec/mongoid/persistence_context_spec.rb +1 -1
- data/spec/mongoid/query_cache_spec.rb +61 -22
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +13 -0
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/threaded_spec.rb +68 -0
- data/spec/mongoid/{relations/touchable_spec.rb → touchable_spec.rb} +40 -1
- data/spec/mongoid/validatable/associated_spec.rb +1 -1
- data/spec/mongoid/validatable/presence_spec.rb +7 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/rails/controller_extension/controller_runtime_spec.rb +110 -0
- data/spec/spec_helper.rb +51 -25
- data/spec/support/constraints.rb +101 -0
- data/spec/support/macros.rb +20 -0
- data/spec/support/spec_config.rb +39 -0
- metadata +602 -582
- checksums.yaml.gz.sig +0 -2
- data/lib/mongoid/relations/accessors.rb +0 -267
- data/lib/mongoid/relations/auto_save.rb +0 -94
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -59
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -65
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -70
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -199
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -39
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -106
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -56
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -160
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/eager/base.rb +0 -153
- data/lib/mongoid/relations/eager/belongs_to.rb +0 -31
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +0 -47
- data/lib/mongoid/relations/eager/has_many.rb +0 -38
- data/lib/mongoid/relations/eager/has_one.rb +0 -30
- data/lib/mongoid/relations/embedded/in.rb +0 -241
- data/lib/mongoid/relations/embedded/many.rb +0 -683
- data/lib/mongoid/relations/embedded/one.rb +0 -235
- data/lib/mongoid/relations/macros.rb +0 -367
- data/lib/mongoid/relations/metadata.rb +0 -1179
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/options.rb +0 -49
- data/lib/mongoid/relations/polymorphic.rb +0 -39
- data/lib/mongoid/relations/referenced/in.rb +0 -304
- data/lib/mongoid/relations/referenced/many.rb +0 -812
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -479
- data/lib/mongoid/relations/referenced/one.rb +0 -290
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -493
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -97
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -111
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -75
- data/spec/mongoid/relations/conversions_spec.rb +0 -128
- data/spec/mongoid/relations/metadata_spec.rb +0 -1985
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
- /data/spec/mongoid/{relations → association}/embedded/dirty_spec.rb +0 -0
|
@@ -388,4 +388,85 @@ describe Mongoid::Criteria::Scopable do
|
|
|
388
388
|
end
|
|
389
389
|
end
|
|
390
390
|
end
|
|
391
|
+
|
|
392
|
+
describe 'scope and where' do
|
|
393
|
+
class ScopeWhereModel
|
|
394
|
+
include Mongoid::Document
|
|
395
|
+
|
|
396
|
+
scope :foo, -> { where(foo: true) }
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
shared_examples_for 'restricts to both' do
|
|
400
|
+
it 'restricts to both' do
|
|
401
|
+
expect(result.selector['foo']).to eq(true)
|
|
402
|
+
expect(result.selector['hello']).to eq('world')
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
context 'scope is given first' do
|
|
407
|
+
let(:result) { ScopeWhereModel.foo.where(hello: 'world') }
|
|
408
|
+
|
|
409
|
+
it_behaves_like 'restricts to both'
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
context 'where is given first' do
|
|
413
|
+
let(:result) { ScopeWhereModel.where(hello: 'world').foo }
|
|
414
|
+
|
|
415
|
+
it_behaves_like 'restricts to both'
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
describe 'scope with argument and where' do
|
|
420
|
+
class ArgumentScopeWhereModel
|
|
421
|
+
include Mongoid::Document
|
|
422
|
+
|
|
423
|
+
scope :my_text_search, ->(search) { where('$text' => {'$search' => search}) }
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
shared_examples_for 'restricts to both' do
|
|
427
|
+
it 'restricts to both' do
|
|
428
|
+
expect(result.selector['$text']).to eq({'$search' => 'bar'})
|
|
429
|
+
expect(result.selector['hello']).to eq('world')
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
context 'scope is given first' do
|
|
434
|
+
let(:result) { ArgumentScopeWhereModel.my_text_search('bar').where(hello: 'world') }
|
|
435
|
+
|
|
436
|
+
it_behaves_like 'restricts to both'
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
context 'where is given first' do
|
|
440
|
+
let(:result) { ArgumentScopeWhereModel.where(hello: 'world').my_text_search('bar') }
|
|
441
|
+
|
|
442
|
+
it_behaves_like 'restricts to both'
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
describe 'built in text search scope and where' do
|
|
447
|
+
class TextSearchScopeWhereModel
|
|
448
|
+
include Mongoid::Document
|
|
449
|
+
|
|
450
|
+
# using the default text_search scope
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
shared_examples_for 'restricts to both' do
|
|
454
|
+
it 'restricts to both' do
|
|
455
|
+
expect(result.selector['$text']).to eq({'$search' => 'bar'})
|
|
456
|
+
expect(result.selector['hello']).to eq('world')
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
context 'scope is given first' do
|
|
461
|
+
let(:result) { TextSearchScopeWhereModel.text_search('bar').where(hello: 'world') }
|
|
462
|
+
|
|
463
|
+
it_behaves_like 'restricts to both'
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
context 'where is given first' do
|
|
467
|
+
let(:result) { TextSearchScopeWhereModel.where(hello: 'world').text_search('bar') }
|
|
468
|
+
|
|
469
|
+
it_behaves_like 'restricts to both'
|
|
470
|
+
end
|
|
471
|
+
end
|
|
391
472
|
end
|
|
@@ -285,8 +285,23 @@ describe Mongoid::Criteria do
|
|
|
285
285
|
Band.where(name: "Depeche Mode")
|
|
286
286
|
end
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
|
|
288
|
+
# as_json changed in rails 6 to call as_json on serializable_hash.
|
|
289
|
+
# https://github.com/rails/rails/commit/2e5cb980a448e7f4ab00df6e9ad4c1cc456616aa
|
|
290
|
+
|
|
291
|
+
context 'rails < 6' do
|
|
292
|
+
max_rails_version '5.2'
|
|
293
|
+
|
|
294
|
+
it "returns the criteria as a json hash" do
|
|
295
|
+
expect(criteria.as_json).to eq([ band.serializable_hash ])
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
context 'rails >= 6' do
|
|
300
|
+
min_rails_version '6.0'
|
|
301
|
+
|
|
302
|
+
it "returns the criteria as a json hash" do
|
|
303
|
+
expect(criteria.as_json).to eq([ band.serializable_hash.as_json ])
|
|
304
|
+
end
|
|
290
305
|
end
|
|
291
306
|
end
|
|
292
307
|
|
|
@@ -1444,18 +1459,18 @@ describe Mongoid::Criteria do
|
|
|
1444
1459
|
end
|
|
1445
1460
|
end
|
|
1446
1461
|
|
|
1447
|
-
context "when including the same
|
|
1462
|
+
context "when including the same association multiple times" do
|
|
1448
1463
|
|
|
1449
1464
|
let(:criteria) do
|
|
1450
1465
|
Person.all.includes(:posts, :posts).includes(:posts)
|
|
1451
1466
|
end
|
|
1452
1467
|
|
|
1453
|
-
let(:
|
|
1468
|
+
let(:association) do
|
|
1454
1469
|
Person.reflect_on_association(:posts)
|
|
1455
1470
|
end
|
|
1456
1471
|
|
|
1457
|
-
it "does not duplicate the
|
|
1458
|
-
expect(criteria.inclusions).to eq([
|
|
1472
|
+
it "does not duplicate the association in the inclusions" do
|
|
1473
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
1459
1474
|
end
|
|
1460
1475
|
end
|
|
1461
1476
|
|
|
@@ -2217,12 +2232,12 @@ describe Mongoid::Criteria do
|
|
|
2217
2232
|
Band.includes(:records)
|
|
2218
2233
|
end
|
|
2219
2234
|
|
|
2220
|
-
let(:
|
|
2235
|
+
let(:association) do
|
|
2221
2236
|
Band.relations["records"]
|
|
2222
2237
|
end
|
|
2223
2238
|
|
|
2224
2239
|
it "returns the inclusions" do
|
|
2225
|
-
expect(criteria.inclusions).to eq([
|
|
2240
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2226
2241
|
end
|
|
2227
2242
|
end
|
|
2228
2243
|
|
|
@@ -2232,16 +2247,16 @@ describe Mongoid::Criteria do
|
|
|
2232
2247
|
Band.all
|
|
2233
2248
|
end
|
|
2234
2249
|
|
|
2235
|
-
let(:
|
|
2250
|
+
let(:association) do
|
|
2236
2251
|
Band.relations["records"]
|
|
2237
2252
|
end
|
|
2238
2253
|
|
|
2239
2254
|
before do
|
|
2240
|
-
criteria.inclusions = [
|
|
2255
|
+
criteria.inclusions = [ association ]
|
|
2241
2256
|
end
|
|
2242
2257
|
|
|
2243
2258
|
it "sets the inclusions" do
|
|
2244
|
-
expect(criteria.inclusions).to eq([
|
|
2259
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2245
2260
|
end
|
|
2246
2261
|
end
|
|
2247
2262
|
|
|
@@ -2409,7 +2424,7 @@ describe Mongoid::Criteria do
|
|
|
2409
2424
|
end
|
|
2410
2425
|
end
|
|
2411
2426
|
|
|
2412
|
-
let(:
|
|
2427
|
+
let(:association) do
|
|
2413
2428
|
Band.relations["records"]
|
|
2414
2429
|
end
|
|
2415
2430
|
|
|
@@ -2434,7 +2449,7 @@ describe Mongoid::Criteria do
|
|
|
2434
2449
|
end
|
|
2435
2450
|
|
|
2436
2451
|
it "merges the inclusions" do
|
|
2437
|
-
expect(merged.inclusions).to eq([
|
|
2452
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2438
2453
|
end
|
|
2439
2454
|
|
|
2440
2455
|
it "returns a new criteria" do
|
|
@@ -2448,7 +2463,7 @@ describe Mongoid::Criteria do
|
|
|
2448
2463
|
{ klass: Band, includes: [ :records ] }
|
|
2449
2464
|
end
|
|
2450
2465
|
|
|
2451
|
-
let(:
|
|
2466
|
+
let(:association) do
|
|
2452
2467
|
Band.relations["records"]
|
|
2453
2468
|
end
|
|
2454
2469
|
|
|
@@ -2469,7 +2484,7 @@ describe Mongoid::Criteria do
|
|
|
2469
2484
|
end
|
|
2470
2485
|
|
|
2471
2486
|
it "merges the inclusions" do
|
|
2472
|
-
expect(merged.inclusions).to eq([
|
|
2487
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2473
2488
|
end
|
|
2474
2489
|
|
|
2475
2490
|
it "returns a new criteria" do
|
|
@@ -2494,7 +2509,7 @@ describe Mongoid::Criteria do
|
|
|
2494
2509
|
end
|
|
2495
2510
|
end
|
|
2496
2511
|
|
|
2497
|
-
let(:
|
|
2512
|
+
let(:association) do
|
|
2498
2513
|
Band.relations["records"]
|
|
2499
2514
|
end
|
|
2500
2515
|
|
|
@@ -2519,7 +2534,7 @@ describe Mongoid::Criteria do
|
|
|
2519
2534
|
end
|
|
2520
2535
|
|
|
2521
2536
|
it "merges the inclusions" do
|
|
2522
|
-
expect(merged.inclusions).to eq([
|
|
2537
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2523
2538
|
end
|
|
2524
2539
|
|
|
2525
2540
|
it "returns the same criteria" do
|
|
@@ -3465,7 +3480,7 @@ describe Mongoid::Criteria do
|
|
|
3465
3480
|
context "when querying on a big decimal" do
|
|
3466
3481
|
|
|
3467
3482
|
let(:sales) do
|
|
3468
|
-
BigDecimal
|
|
3483
|
+
BigDecimal('0.1')
|
|
3469
3484
|
end
|
|
3470
3485
|
|
|
3471
3486
|
let!(:band) do
|
|
@@ -15,12 +15,12 @@ describe Mongoid::Document do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
describe "#_destroy" do
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
it "default to false" do
|
|
20
20
|
expect(Person.new._destroy).to be false
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
describe ".included" do
|
|
25
25
|
|
|
26
26
|
let(:models) do
|
|
@@ -94,11 +94,11 @@ describe Mongoid::Document do
|
|
|
94
94
|
context "when the document is not subclassed" do
|
|
95
95
|
|
|
96
96
|
let(:types) do
|
|
97
|
-
|
|
97
|
+
Kangaroo._types
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "returns the document" do
|
|
101
|
-
expect(types).to eq([ "
|
|
101
|
+
expect(types).to eq([ "Kangaroo" ])
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
|
|
@@ -385,6 +385,27 @@ describe Mongoid::Document do
|
|
|
385
385
|
Person.new(title: "Sir")
|
|
386
386
|
end
|
|
387
387
|
|
|
388
|
+
describe 'id' do
|
|
389
|
+
context 'rails < 6' do
|
|
390
|
+
max_rails_version '5.2'
|
|
391
|
+
|
|
392
|
+
it 'is a BSON::ObjectId' do
|
|
393
|
+
id = person.as_json['_id']
|
|
394
|
+
expect(id).to be_a(BSON::ObjectId)
|
|
395
|
+
end
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
context 'rails >= 6' do
|
|
399
|
+
min_rails_version '6.0'
|
|
400
|
+
|
|
401
|
+
it 'is a hash with $oid' do
|
|
402
|
+
id = person.as_json['_id']
|
|
403
|
+
expect(id).to be_a(Hash)
|
|
404
|
+
expect(id['$oid']).to be_a(String)
|
|
405
|
+
end
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
|
|
388
409
|
context "when no options are provided" do
|
|
389
410
|
|
|
390
411
|
it "does not apply any options" do
|
|
@@ -433,6 +454,64 @@ describe Mongoid::Document do
|
|
|
433
454
|
end
|
|
434
455
|
end
|
|
435
456
|
end
|
|
457
|
+
|
|
458
|
+
context ':compact option' do
|
|
459
|
+
# Since rails 6 differs in how it treats id fields,
|
|
460
|
+
# run this test on one version of rails. Currently rails 6 is in beta,
|
|
461
|
+
# when it is released this version should be changed to 6.
|
|
462
|
+
max_rails_version '5.2'
|
|
463
|
+
|
|
464
|
+
before do
|
|
465
|
+
# These tests require a specific set of defined attributes
|
|
466
|
+
# on the model
|
|
467
|
+
expect(church.as_json.keys.sort).to eq(%w(_id location name))
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
context 'there is a nil valued attribute' do
|
|
471
|
+
let(:church) do
|
|
472
|
+
Church.create!(name: 'St. Basil')
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
it 'returns non-nil fields and _id only' do
|
|
476
|
+
actual = church.as_json(compact: true)
|
|
477
|
+
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
context 'all attrbutes are nil valued' do
|
|
482
|
+
let(:church) do
|
|
483
|
+
Church.create!
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
it 'returns a hash with _id only' do
|
|
487
|
+
actual = church.as_json(compact: true)
|
|
488
|
+
expect(actual).to eq('_id' => church.id)
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
context 'there are no nil valued attributes' do
|
|
493
|
+
let(:church) do
|
|
494
|
+
Church.create!(name: 'St. Basil', location: {})
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
it 'returns all fields and _id' do
|
|
498
|
+
actual = church.as_json(compact: true)
|
|
499
|
+
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil',
|
|
500
|
+
'location' => {})
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
context 'when option is specified as a truthy value' do
|
|
505
|
+
let(:church) do
|
|
506
|
+
Church.create!(name: 'St. Basil')
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
it 'returns non-nil fields and _id only' do
|
|
510
|
+
actual = church.as_json(compact: 1)
|
|
511
|
+
expect(actual).to eq('_id' => church.id, 'name' => 'St. Basil')
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
end
|
|
436
515
|
end
|
|
437
516
|
|
|
438
517
|
describe "#as_document" do
|
|
@@ -204,14 +204,10 @@ describe Mongoid::Extensions::Array do
|
|
|
204
204
|
|
|
205
205
|
context "when the related model uses object ids" do
|
|
206
206
|
|
|
207
|
-
let(:
|
|
207
|
+
let(:association) do
|
|
208
208
|
Person.relations["preferences"]
|
|
209
209
|
end
|
|
210
210
|
|
|
211
|
-
let(:constraint) do
|
|
212
|
-
metadata.constraint
|
|
213
|
-
end
|
|
214
|
-
|
|
215
211
|
context "when provided an object id" do
|
|
216
212
|
|
|
217
213
|
let(:object_id) do
|
|
@@ -219,7 +215,7 @@ describe Mongoid::Extensions::Array do
|
|
|
219
215
|
end
|
|
220
216
|
|
|
221
217
|
let(:fk) do
|
|
222
|
-
Array.__mongoize_fk__(
|
|
218
|
+
Array.__mongoize_fk__(association, object_id)
|
|
223
219
|
end
|
|
224
220
|
|
|
225
221
|
it "returns the object id as an array" do
|
|
@@ -234,7 +230,7 @@ describe Mongoid::Extensions::Array do
|
|
|
234
230
|
end
|
|
235
231
|
|
|
236
232
|
let(:fk) do
|
|
237
|
-
Array.__mongoize_fk__(
|
|
233
|
+
Array.__mongoize_fk__(association, [ object_id ])
|
|
238
234
|
end
|
|
239
235
|
|
|
240
236
|
it "returns the object ids" do
|
|
@@ -251,7 +247,7 @@ describe Mongoid::Extensions::Array do
|
|
|
251
247
|
end
|
|
252
248
|
|
|
253
249
|
let(:fk) do
|
|
254
|
-
Array.__mongoize_fk__(
|
|
250
|
+
Array.__mongoize_fk__(association, object_id.to_s)
|
|
255
251
|
end
|
|
256
252
|
|
|
257
253
|
it "returns the object id in an array" do
|
|
@@ -266,7 +262,7 @@ describe Mongoid::Extensions::Array do
|
|
|
266
262
|
end
|
|
267
263
|
|
|
268
264
|
let(:fk) do
|
|
269
|
-
Array.__mongoize_fk__(
|
|
265
|
+
Array.__mongoize_fk__(association, string)
|
|
270
266
|
end
|
|
271
267
|
|
|
272
268
|
it "returns the string in an array" do
|
|
@@ -277,7 +273,7 @@ describe Mongoid::Extensions::Array do
|
|
|
277
273
|
context "when the string is blank" do
|
|
278
274
|
|
|
279
275
|
let(:fk) do
|
|
280
|
-
Array.__mongoize_fk__(
|
|
276
|
+
Array.__mongoize_fk__(association, "")
|
|
281
277
|
end
|
|
282
278
|
|
|
283
279
|
it "returns an empty array" do
|
|
@@ -289,7 +285,7 @@ describe Mongoid::Extensions::Array do
|
|
|
289
285
|
context "when provided nil" do
|
|
290
286
|
|
|
291
287
|
let(:fk) do
|
|
292
|
-
Array.__mongoize_fk__(
|
|
288
|
+
Array.__mongoize_fk__(association, nil)
|
|
293
289
|
end
|
|
294
290
|
|
|
295
291
|
it "returns an empty array" do
|
|
@@ -306,7 +302,7 @@ describe Mongoid::Extensions::Array do
|
|
|
306
302
|
end
|
|
307
303
|
|
|
308
304
|
let(:fk) do
|
|
309
|
-
Array.__mongoize_fk__(
|
|
305
|
+
Array.__mongoize_fk__(association, [ object_id.to_s ])
|
|
310
306
|
end
|
|
311
307
|
|
|
312
308
|
it "returns the object id in an array" do
|
|
@@ -321,7 +317,7 @@ describe Mongoid::Extensions::Array do
|
|
|
321
317
|
end
|
|
322
318
|
|
|
323
319
|
let(:fk) do
|
|
324
|
-
Array.__mongoize_fk__(
|
|
320
|
+
Array.__mongoize_fk__(association, [ string ])
|
|
325
321
|
end
|
|
326
322
|
|
|
327
323
|
it "returns the string in an array" do
|
|
@@ -332,7 +328,7 @@ describe Mongoid::Extensions::Array do
|
|
|
332
328
|
context "when the strings are blank" do
|
|
333
329
|
|
|
334
330
|
let(:fk) do
|
|
335
|
-
Array.__mongoize_fk__(
|
|
331
|
+
Array.__mongoize_fk__(association, [ "", "" ])
|
|
336
332
|
end
|
|
337
333
|
|
|
338
334
|
it "returns an empty array" do
|
|
@@ -344,7 +340,7 @@ describe Mongoid::Extensions::Array do
|
|
|
344
340
|
context "when provided nils" do
|
|
345
341
|
|
|
346
342
|
let(:fk) do
|
|
347
|
-
Array.__mongoize_fk__(
|
|
343
|
+
Array.__mongoize_fk__(association, [ nil, nil, nil ])
|
|
348
344
|
end
|
|
349
345
|
|
|
350
346
|
it "returns an empty array" do
|
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
|
3
3
|
describe Mongoid::Extensions::BigDecimal do
|
|
4
4
|
|
|
5
5
|
let(:big_decimal) do
|
|
6
|
-
BigDecimal
|
|
6
|
+
BigDecimal("123456.789")
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
describe ".demongoize" do
|
|
@@ -26,7 +26,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "returns a BigDecimal" do
|
|
29
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal
|
|
29
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "returns a BigDecimal" do
|
|
40
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal
|
|
40
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
@@ -48,7 +48,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
it "returns a BigDecimal" do
|
|
51
|
-
expect(BigDecimal.demongoize(string)).to eq(BigDecimal
|
|
51
|
+
expect(BigDecimal.demongoize(string)).to eq(BigDecimal(string))
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -184,7 +184,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
184
184
|
context "when the value is the BigDecimal zero" do
|
|
185
185
|
|
|
186
186
|
let(:big_decimal) do
|
|
187
|
-
BigDecimal
|
|
187
|
+
BigDecimal("0.0")
|
|
188
188
|
end
|
|
189
189
|
|
|
190
190
|
it "returns a BigDecimal" do
|
|
@@ -195,7 +195,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
195
195
|
context "when the value is the BigDecimal negative zero" do
|
|
196
196
|
|
|
197
197
|
let(:big_decimal) do
|
|
198
|
-
BigDecimal
|
|
198
|
+
BigDecimal("-0.0")
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
it "returns a BigDecimal" do
|
|
@@ -326,7 +326,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
326
326
|
context "when the value is BigDecimal NaN" do
|
|
327
327
|
|
|
328
328
|
let(:nan) do
|
|
329
|
-
BigDecimal
|
|
329
|
+
BigDecimal("NaN")
|
|
330
330
|
end
|
|
331
331
|
|
|
332
332
|
it "returns a String" do
|
|
@@ -337,7 +337,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
337
337
|
context "when the value is BigDecimal Infinity" do
|
|
338
338
|
|
|
339
339
|
let(:infinity) do
|
|
340
|
-
BigDecimal
|
|
340
|
+
BigDecimal("Infinity")
|
|
341
341
|
end
|
|
342
342
|
|
|
343
343
|
it "returns a String" do
|
|
@@ -348,7 +348,7 @@ describe Mongoid::Extensions::BigDecimal do
|
|
|
348
348
|
context "when the value is BigDecimal negative Infinity" do
|
|
349
349
|
|
|
350
350
|
let(:neg_infinity) do
|
|
351
|
-
BigDecimal
|
|
351
|
+
BigDecimal("-Infinity")
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
it "returns a String" do
|
|
@@ -230,10 +230,27 @@ describe Mongoid::Extensions::Hash do
|
|
|
230
230
|
it "should retrieve a nested value under the provided key" do
|
|
231
231
|
expect(nested).to eq "hundred"
|
|
232
232
|
end
|
|
233
|
+
|
|
234
|
+
context 'and the value is falsey' do
|
|
235
|
+
let(:hash) do
|
|
236
|
+
{ "100" => { "name" => false } }
|
|
237
|
+
end
|
|
238
|
+
it "should retrieve the falsey nested value under the provided key" do
|
|
239
|
+
expect(nested).to eq false
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
context 'and the value is nil' do
|
|
244
|
+
let(:hash) do
|
|
245
|
+
{ "100" => { 0 => "Please don't return this value!" } }
|
|
246
|
+
end
|
|
247
|
+
it "should retrieve the nil nested value under the provided key" do
|
|
248
|
+
expect(nested).to eq nil
|
|
249
|
+
end
|
|
250
|
+
end
|
|
233
251
|
end
|
|
234
252
|
|
|
235
253
|
context "when the hash key is an integer" do
|
|
236
|
-
|
|
237
254
|
let(:hash) do
|
|
238
255
|
{ 100 => { "name" => "hundred" } }
|
|
239
256
|
end
|
|
@@ -39,14 +39,10 @@ describe Mongoid::Extensions::Object do
|
|
|
39
39
|
|
|
40
40
|
context "when the related model uses object ids" do
|
|
41
41
|
|
|
42
|
-
let(:
|
|
42
|
+
let(:association) do
|
|
43
43
|
Game.relations["person"]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
let(:constraint) do
|
|
47
|
-
metadata.constraint
|
|
48
|
-
end
|
|
49
|
-
|
|
50
46
|
context "when provided an object id" do
|
|
51
47
|
|
|
52
48
|
let(:object_id) do
|
|
@@ -54,7 +50,7 @@ describe Mongoid::Extensions::Object do
|
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
let(:fk) do
|
|
57
|
-
Object.__mongoize_fk__(
|
|
53
|
+
Object.__mongoize_fk__(association, object_id)
|
|
58
54
|
end
|
|
59
55
|
|
|
60
56
|
it "returns the object id" do
|
|
@@ -71,7 +67,7 @@ describe Mongoid::Extensions::Object do
|
|
|
71
67
|
end
|
|
72
68
|
|
|
73
69
|
let(:fk) do
|
|
74
|
-
Object.__mongoize_fk__(
|
|
70
|
+
Object.__mongoize_fk__(association, object_id.to_s)
|
|
75
71
|
end
|
|
76
72
|
|
|
77
73
|
it "returns the object id" do
|
|
@@ -86,7 +82,7 @@ describe Mongoid::Extensions::Object do
|
|
|
86
82
|
end
|
|
87
83
|
|
|
88
84
|
let(:fk) do
|
|
89
|
-
Object.__mongoize_fk__(
|
|
85
|
+
Object.__mongoize_fk__(association, string)
|
|
90
86
|
end
|
|
91
87
|
|
|
92
88
|
it "returns the string" do
|
|
@@ -97,7 +93,7 @@ describe Mongoid::Extensions::Object do
|
|
|
97
93
|
context "when the string is blank" do
|
|
98
94
|
|
|
99
95
|
let(:fk) do
|
|
100
|
-
Object.__mongoize_fk__(
|
|
96
|
+
Object.__mongoize_fk__(association, "")
|
|
101
97
|
end
|
|
102
98
|
|
|
103
99
|
it "returns nil" do
|
|
@@ -109,7 +105,7 @@ describe Mongoid::Extensions::Object do
|
|
|
109
105
|
context "when provided nil" do
|
|
110
106
|
|
|
111
107
|
let(:fk) do
|
|
112
|
-
Object.__mongoize_fk__(
|
|
108
|
+
Object.__mongoize_fk__(association, nil)
|
|
113
109
|
end
|
|
114
110
|
|
|
115
111
|
it "returns nil" do
|
|
@@ -120,7 +116,7 @@ describe Mongoid::Extensions::Object do
|
|
|
120
116
|
context "when provided an empty array" do
|
|
121
117
|
|
|
122
118
|
let(:fk) do
|
|
123
|
-
Object.__mongoize_fk__(
|
|
119
|
+
Object.__mongoize_fk__(association, [])
|
|
124
120
|
end
|
|
125
121
|
|
|
126
122
|
it "returns an empty array" do
|
|
@@ -139,6 +139,13 @@ describe Mongoid::Extensions::Range do
|
|
|
139
139
|
expect(("a".."z").mongoize).to eq({ "min" => "a", "max" => "z" })
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
|
+
|
|
143
|
+
context 'when the value is a string' do
|
|
144
|
+
|
|
145
|
+
it 'returns a string' do
|
|
146
|
+
expect(Range.mongoize('3')).to eq('3')
|
|
147
|
+
end
|
|
148
|
+
end
|
|
142
149
|
end
|
|
143
150
|
|
|
144
151
|
describe "#resizable?" do
|
|
@@ -35,6 +35,29 @@ describe Mongoid::Extensions::Regexp do
|
|
|
35
35
|
it "returns the provided value as a regex" do
|
|
36
36
|
expect(value).to eq(/[^abc]/)
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
context "when the string is empty" do
|
|
41
|
+
|
|
42
|
+
let(:value) do
|
|
43
|
+
Regexp.mongoize("")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "returns an empty regex" do
|
|
47
|
+
expect(value).to eq(//)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context "when the value is nil" do
|
|
53
|
+
|
|
54
|
+
let(:value) do
|
|
55
|
+
Regexp.mongoize(nil)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "returns the nil" do
|
|
59
|
+
expect(value).to be_nil
|
|
60
|
+
end
|
|
38
61
|
end
|
|
39
62
|
end
|
|
40
63
|
|