mongoid 6.4.8 → 7.0.13
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/LICENSE +1 -0
- data/README.md +4 -3
- data/Rakefile +33 -7
- 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 +211 -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 +174 -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 +45 -59
- 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 +511 -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/paths/embedded.rb +1 -1
- data/lib/mongoid/atomic.rb +14 -4
- data/lib/mongoid/attributes/dynamic.rb +16 -15
- 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 +55 -31
- data/lib/mongoid/changeable.rb +1 -1
- data/lib/mongoid/clients/options.rb +7 -5
- data/lib/mongoid/clients/sessions.rb +20 -4
- data/lib/mongoid/composable.rb +4 -4
- data/lib/mongoid/config/environment.rb +21 -8
- 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 +11 -6
- data/lib/mongoid/criteria/includable.rb +14 -14
- data/lib/mongoid/criteria/modifiable.rb +8 -3
- data/lib/mongoid/criteria/options.rb +2 -2
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +3 -3
- data/lib/mongoid/criteria/queryable/extensions/string.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +1 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -0
- data/lib/mongoid/criteria/queryable/key.rb +67 -8
- data/lib/mongoid/criteria/queryable/mergeable.rb +5 -4
- data/lib/mongoid/criteria/queryable/pipeline.rb +10 -5
- data/lib/mongoid/criteria/queryable/selectable.rb +5 -3
- data/lib/mongoid/criteria/queryable/selector.rb +9 -31
- data/lib/mongoid/criteria.rb +9 -3
- data/lib/mongoid/document.rb +14 -4
- 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/hash.rb +9 -4
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/range.rb +1 -0
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/string.rb +2 -2
- 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 +5 -4
- data/lib/mongoid/indexable.rb +4 -1
- data/lib/mongoid/interceptable.rb +8 -6
- data/lib/mongoid/matchable/all.rb +4 -3
- data/lib/mongoid/matchable/and.rb +1 -1
- data/lib/mongoid/matchable/default.rb +71 -24
- 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/regexp.rb +2 -2
- data/lib/mongoid/matchable.rb +17 -16
- 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/pushable.rb +11 -2
- data/lib/mongoid/persistable/settable.rb +57 -12
- data/lib/mongoid/persistable.rb +4 -5
- data/lib/mongoid/persistence_context.rb +26 -11
- data/lib/mongoid/positional.rb +1 -1
- data/lib/mongoid/query_cache.rb +4 -2
- data/lib/mongoid/serializable.rb +4 -4
- data/lib/mongoid/shardable.rb +1 -1
- data/lib/mongoid/touchable.rb +102 -0
- data/lib/mongoid/traversable.rb +3 -3
- data/lib/mongoid/validatable/macros.rb +1 -1
- data/lib/mongoid/validatable/presence.rb +2 -2
- data/lib/mongoid/validatable/uniqueness.rb +5 -5
- data/lib/mongoid/validatable.rb +8 -8
- data/lib/mongoid/version.rb +2 -1
- data/lib/mongoid.rb +1 -0
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +3 -0
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/spec/README.md +18 -0
- data/spec/app/models/animal.rb +2 -1
- data/spec/app/models/bomb.rb +1 -1
- data/spec/app/models/customer.rb +11 -0
- data/spec/app/models/customer_address.rb +12 -0
- data/spec/app/models/message.rb +1 -1
- data/spec/app/models/minim.rb +7 -0
- data/spec/app/models/other_owner_object.rb +2 -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/app_spec.rb +341 -0
- data/spec/integration/associations/belongs_to_spec.rb +13 -0
- data/spec/integration/associations/embedded_spec.rb +176 -0
- data/spec/integration/callbacks_models.rb +49 -0
- data/spec/integration/callbacks_spec.rb +216 -0
- data/spec/integration/criteria/date_field_spec.rb +41 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +32 -0
- data/spec/integration/matchable_spec.rb +680 -0
- data/spec/lite_spec_helper.rb +71 -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 → association}/embedded/dirty_spec.rb +0 -0
- 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} +55 -77
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +901 -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_models.rb +53 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +862 -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_dnl_models.rb +6 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +51 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +954 -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 +2023 -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} +247 -99
- 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 +227 -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} +30 -94
- 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 +1360 -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/paths_spec.rb +41 -0
- data/spec/mongoid/atomic_spec.rb +4 -4
- data/spec/mongoid/attributes/dynamic_spec.rb +153 -0
- data/spec/mongoid/attributes/nested_spec.rb +29 -11
- data/spec/mongoid/attributes/readonly_spec.rb +80 -125
- data/spec/mongoid/attributes_spec.rb +298 -9
- data/spec/mongoid/clients/factory_spec.rb +20 -38
- data/spec/mongoid/clients/options_spec.rb +64 -50
- data/spec/mongoid/clients/sessions_spec.rb +9 -5
- data/spec/mongoid/clients/transactions_spec.rb +390 -0
- data/spec/mongoid/clients_spec.rb +70 -10
- data/spec/mongoid/config_spec.rb +27 -1
- data/spec/mongoid/contextual/atomic_spec.rb +37 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +11 -2
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -5
- data/spec/mongoid/contextual/memory_spec.rb +19 -0
- data/spec/mongoid/contextual/mongo_spec.rb +107 -56
- data/spec/mongoid/copyable_spec.rb +90 -6
- data/spec/mongoid/copyable_spec_models.rb +17 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +173 -1
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +54 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -7
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +44 -1
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +19 -7
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +28 -1
- data/spec/mongoid/criteria/queryable/key_spec.rb +48 -6
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +12 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +762 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +5 -224
- data/spec/mongoid/criteria/queryable/selector_spec.rb +37 -0
- data/spec/mongoid/criteria_spec.rb +36 -19
- data/spec/mongoid/document_fields_spec.rb +88 -0
- data/spec/mongoid/document_persistence_context_spec.rb +33 -0
- data/spec/mongoid/document_spec.rb +29 -4
- data/spec/mongoid/extensions/array_spec.rb +11 -15
- 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/factory_spec.rb +21 -3
- data/spec/mongoid/fields/foreign_key_spec.rb +24 -32
- data/spec/mongoid/fields_spec.rb +1 -1
- data/spec/mongoid/indexable_spec.rb +24 -12
- data/spec/mongoid/interceptable_spec.rb +22 -1
- data/spec/mongoid/matchable/default_spec.rb +10 -3
- data/spec/mongoid/matchable/elem_match_spec.rb +20 -0
- data/spec/mongoid/matchable/eq_spec.rb +48 -0
- data/spec/mongoid/matchable/regexp_spec.rb +2 -2
- data/spec/mongoid/matchable_spec.rb +2 -2
- data/spec/mongoid/persistable/pushable_spec.rb +55 -1
- data/spec/mongoid/persistable/savable_spec.rb +5 -5
- data/spec/mongoid/persistable/settable_spec.rb +125 -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 +65 -27
- data/spec/mongoid/relations/proxy_spec.rb +124 -124
- data/spec/mongoid/scopable_spec.rb +2 -1
- data/spec/mongoid/shardable_spec.rb +32 -12
- data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
- data/spec/mongoid/tasks/database_spec.rb +1 -1
- 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/uniqueness_spec.rb +33 -6
- data/spec/mongoid/validatable_spec.rb +1 -1
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +221 -0
- data/spec/shared/lib/mrss/constraints.rb +354 -0
- data/spec/shared/lib/mrss/docker_runner.rb +265 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +191 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +115 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +162 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +231 -0
- data/spec/shared/shlib/distro.sh +73 -0
- data/spec/shared/shlib/server.sh +290 -0
- data/spec/shared/shlib/set_env.sh +128 -0
- data/spec/spec_helper.rb +34 -49
- data/spec/support/cluster_config.rb +3 -3
- data/spec/support/constraints.rb +21 -76
- data/spec/support/expectations.rb +17 -3
- data/spec/support/spec_config.rb +20 -7
- data.tar.gz.sig +0 -0
- metadata +646 -541
- metadata.gz.sig +1 -5
- 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
|
@@ -1079,7 +1079,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1079
1079
|
:location.within_box => [[ 1, 10 ], [ 2, 10 ]]
|
|
1080
1080
|
)
|
|
1081
1081
|
end
|
|
1082
|
-
|
|
1082
|
+
|
|
1083
1083
|
it "adds the $geoIntersects expression" do
|
|
1084
1084
|
expect(selection.selector).to eq({
|
|
1085
1085
|
"location" => {
|
|
@@ -2428,7 +2428,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2428
2428
|
end
|
|
2429
2429
|
end
|
|
2430
2430
|
|
|
2431
|
-
context "when
|
|
2431
|
+
context "when chaining the criterion" do
|
|
2432
2432
|
|
|
2433
2433
|
context "when the criterion are for different fields" do
|
|
2434
2434
|
|
|
@@ -2665,225 +2665,6 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2665
2665
|
end
|
|
2666
2666
|
end
|
|
2667
2667
|
|
|
2668
|
-
describe "#not" do
|
|
2669
|
-
|
|
2670
|
-
context "when provided no criterion" do
|
|
2671
|
-
|
|
2672
|
-
let(:selection) do
|
|
2673
|
-
query.not
|
|
2674
|
-
end
|
|
2675
|
-
|
|
2676
|
-
it "does not add any criterion" do
|
|
2677
|
-
expect(selection.selector).to eq({})
|
|
2678
|
-
end
|
|
2679
|
-
|
|
2680
|
-
it "returns the query" do
|
|
2681
|
-
expect(selection).to eq(query)
|
|
2682
|
-
end
|
|
2683
|
-
|
|
2684
|
-
it "returns a non cloned query" do
|
|
2685
|
-
expect(selection).to equal(query)
|
|
2686
|
-
end
|
|
2687
|
-
|
|
2688
|
-
context "when the following criteria is a query method" do
|
|
2689
|
-
|
|
2690
|
-
let(:selection) do
|
|
2691
|
-
query.not.all(field: [ 1, 2 ])
|
|
2692
|
-
end
|
|
2693
|
-
|
|
2694
|
-
it "negates the all selection" do
|
|
2695
|
-
expect(selection.selector).to eq(
|
|
2696
|
-
{ "field" => { "$not" => { "$all" => [ 1, 2 ] }}}
|
|
2697
|
-
)
|
|
2698
|
-
end
|
|
2699
|
-
|
|
2700
|
-
it "returns a cloned query" do
|
|
2701
|
-
expect(selection).to_not equal(query)
|
|
2702
|
-
end
|
|
2703
|
-
|
|
2704
|
-
it "removes the negation on the clone" do
|
|
2705
|
-
expect(selection).to_not be_negating
|
|
2706
|
-
end
|
|
2707
|
-
end
|
|
2708
|
-
|
|
2709
|
-
context "when the following criteria is a gt method" do
|
|
2710
|
-
|
|
2711
|
-
let(:selection) do
|
|
2712
|
-
query.not.gt(age: 50)
|
|
2713
|
-
end
|
|
2714
|
-
|
|
2715
|
-
it "negates the gt selection" do
|
|
2716
|
-
expect(selection.selector).to eq(
|
|
2717
|
-
{ "age" => { "$not" => { "$gt" => 50 }}}
|
|
2718
|
-
)
|
|
2719
|
-
end
|
|
2720
|
-
|
|
2721
|
-
it "returns a coned query" do
|
|
2722
|
-
expect(selection).to_not eq(query)
|
|
2723
|
-
end
|
|
2724
|
-
|
|
2725
|
-
it "removes the negation on the clone" do
|
|
2726
|
-
expect(selection).to_not be_negating
|
|
2727
|
-
end
|
|
2728
|
-
end
|
|
2729
|
-
|
|
2730
|
-
context "when the following criteria is a where" do
|
|
2731
|
-
|
|
2732
|
-
let(:selection) do
|
|
2733
|
-
query.not.where(field: 1, :other.in => [ 1, 2 ])
|
|
2734
|
-
end
|
|
2735
|
-
|
|
2736
|
-
it "negates the selection with an operator" do
|
|
2737
|
-
expect(selection.selector).to eq(
|
|
2738
|
-
{ "field" => { "$ne" => 1 }, "other" => { "$not" => { "$in" => [ 1, 2 ] }}}
|
|
2739
|
-
)
|
|
2740
|
-
end
|
|
2741
|
-
|
|
2742
|
-
it "returns a cloned query" do
|
|
2743
|
-
expect(selection).to_not equal(query)
|
|
2744
|
-
end
|
|
2745
|
-
|
|
2746
|
-
it "removes the negation on the clone" do
|
|
2747
|
-
expect(selection).to_not be_negating
|
|
2748
|
-
end
|
|
2749
|
-
end
|
|
2750
|
-
|
|
2751
|
-
context "when the following criteria is a where with a regexp" do
|
|
2752
|
-
|
|
2753
|
-
let(:selection) do
|
|
2754
|
-
query.not.where(field: 1, other: /test/)
|
|
2755
|
-
end
|
|
2756
|
-
|
|
2757
|
-
it "negates the selection with an operator" do
|
|
2758
|
-
expect(selection.selector).to eq(
|
|
2759
|
-
{ "field" => { "$ne" => 1 }, "other" => { "$not" => /test/ } }
|
|
2760
|
-
)
|
|
2761
|
-
end
|
|
2762
|
-
|
|
2763
|
-
it "returns a cloned query" do
|
|
2764
|
-
expect(selection).to_not equal(query)
|
|
2765
|
-
end
|
|
2766
|
-
|
|
2767
|
-
it "removes the negation on the clone" do
|
|
2768
|
-
expect(selection).to_not be_negating
|
|
2769
|
-
end
|
|
2770
|
-
|
|
2771
|
-
end
|
|
2772
|
-
end
|
|
2773
|
-
|
|
2774
|
-
context "when provided nil" do
|
|
2775
|
-
|
|
2776
|
-
let(:selection) do
|
|
2777
|
-
query.not(nil)
|
|
2778
|
-
end
|
|
2779
|
-
|
|
2780
|
-
it "does not add any criterion" do
|
|
2781
|
-
expect(selection.selector).to eq({})
|
|
2782
|
-
end
|
|
2783
|
-
|
|
2784
|
-
it "returns the query" do
|
|
2785
|
-
expect(selection).to eq(query)
|
|
2786
|
-
end
|
|
2787
|
-
|
|
2788
|
-
it "returns a cloned query" do
|
|
2789
|
-
expect(selection).to_not equal(query)
|
|
2790
|
-
end
|
|
2791
|
-
end
|
|
2792
|
-
|
|
2793
|
-
context "when provided a single criterion" do
|
|
2794
|
-
|
|
2795
|
-
let(:selection) do
|
|
2796
|
-
query.not(field: /test/)
|
|
2797
|
-
end
|
|
2798
|
-
|
|
2799
|
-
it "adds the $not selector" do
|
|
2800
|
-
expect(selection.selector).to eq({
|
|
2801
|
-
"field" => { "$not" => /test/ }
|
|
2802
|
-
})
|
|
2803
|
-
end
|
|
2804
|
-
|
|
2805
|
-
it "returns a cloned query" do
|
|
2806
|
-
expect(selection).to_not equal(query)
|
|
2807
|
-
end
|
|
2808
|
-
end
|
|
2809
|
-
|
|
2810
|
-
context "when provided multiple criterion" do
|
|
2811
|
-
|
|
2812
|
-
context "when the criterion are for different fields" do
|
|
2813
|
-
|
|
2814
|
-
let(:selection) do
|
|
2815
|
-
query.not(first: /1/, second: /2/)
|
|
2816
|
-
end
|
|
2817
|
-
|
|
2818
|
-
it "adds the $not selectors" do
|
|
2819
|
-
expect(selection.selector).to eq({
|
|
2820
|
-
"first" => { "$not" => /1/ },
|
|
2821
|
-
"second" => { "$not" => /2/ }
|
|
2822
|
-
})
|
|
2823
|
-
end
|
|
2824
|
-
|
|
2825
|
-
it "returns a cloned query" do
|
|
2826
|
-
expect(selection).to_not equal(query)
|
|
2827
|
-
end
|
|
2828
|
-
end
|
|
2829
|
-
end
|
|
2830
|
-
|
|
2831
|
-
context "when chaining the criterion" do
|
|
2832
|
-
|
|
2833
|
-
context "when the criterion are for different fields" do
|
|
2834
|
-
|
|
2835
|
-
let(:selection) do
|
|
2836
|
-
query.not(first: /1/).not(second: /2/)
|
|
2837
|
-
end
|
|
2838
|
-
|
|
2839
|
-
it "adds the $not selectors" do
|
|
2840
|
-
expect(selection.selector).to eq({
|
|
2841
|
-
"first" => { "$not" => /1/ },
|
|
2842
|
-
"second" => { "$not" => /2/ }
|
|
2843
|
-
})
|
|
2844
|
-
end
|
|
2845
|
-
|
|
2846
|
-
it "returns a cloned query" do
|
|
2847
|
-
expect(selection).to_not equal(query)
|
|
2848
|
-
end
|
|
2849
|
-
end
|
|
2850
|
-
|
|
2851
|
-
context "when the criterion are on the same field" do
|
|
2852
|
-
|
|
2853
|
-
let(:selection) do
|
|
2854
|
-
query.not(first: /1/).not(first: /2/)
|
|
2855
|
-
end
|
|
2856
|
-
|
|
2857
|
-
it "overwrites the first $not selector" do
|
|
2858
|
-
expect(selection.selector).to eq({
|
|
2859
|
-
"first" => { "$not" => /2/ }
|
|
2860
|
-
})
|
|
2861
|
-
end
|
|
2862
|
-
|
|
2863
|
-
it "returns a cloned query" do
|
|
2864
|
-
expect(selection).to_not equal(query)
|
|
2865
|
-
end
|
|
2866
|
-
end
|
|
2867
|
-
|
|
2868
|
-
context "when the criterion are a double negative" do
|
|
2869
|
-
|
|
2870
|
-
let(:selection) do
|
|
2871
|
-
query.not.where(:first.not => /1/)
|
|
2872
|
-
end
|
|
2873
|
-
|
|
2874
|
-
it "does not double the $not selector" do
|
|
2875
|
-
expect(selection.selector).to eq({
|
|
2876
|
-
"first" => { "$not" => /1/ }
|
|
2877
|
-
})
|
|
2878
|
-
end
|
|
2879
|
-
|
|
2880
|
-
it "returns a cloned query" do
|
|
2881
|
-
expect(selection).to_not equal(query)
|
|
2882
|
-
end
|
|
2883
|
-
end
|
|
2884
|
-
end
|
|
2885
|
-
end
|
|
2886
|
-
|
|
2887
2668
|
describe "#or" do
|
|
2888
2669
|
|
|
2889
2670
|
context "when provided no criterion" do
|
|
@@ -4198,7 +3979,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
4198
3979
|
|
|
4199
3980
|
context "when using the strategies via methods" do
|
|
4200
3981
|
|
|
4201
|
-
context "when
|
|
3982
|
+
context "when different operators are specified" do
|
|
4202
3983
|
|
|
4203
3984
|
let(:selection) do
|
|
4204
3985
|
query.gt(field: 5).lt(field: 10).ne(field: 7)
|
|
@@ -4211,7 +3992,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
4211
3992
|
end
|
|
4212
3993
|
end
|
|
4213
3994
|
|
|
4214
|
-
context "when the
|
|
3995
|
+
context "when the same operator is specified" do
|
|
4215
3996
|
|
|
4216
3997
|
let(:selection) do
|
|
4217
3998
|
query.where(field: 5).where(field: 10)
|
|
@@ -4225,7 +4006,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
4225
4006
|
|
|
4226
4007
|
context "when using the strategies via #where" do
|
|
4227
4008
|
|
|
4228
|
-
context "when
|
|
4009
|
+
context "when using complex keys with different operators" do
|
|
4229
4010
|
|
|
4230
4011
|
let(:selection) do
|
|
4231
4012
|
query.where(:field.gt => 5, :field.lt => 10, :field.ne => 7)
|
|
@@ -841,4 +841,41 @@ describe Mongoid::Criteria::Queryable::Selector do
|
|
|
841
841
|
end
|
|
842
842
|
end
|
|
843
843
|
end
|
|
844
|
+
|
|
845
|
+
describe '#multi_selection?' do
|
|
846
|
+
|
|
847
|
+
let(:selector) do
|
|
848
|
+
described_class.new
|
|
849
|
+
end
|
|
850
|
+
|
|
851
|
+
context 'when key is $and' do
|
|
852
|
+
it 'returns true' do
|
|
853
|
+
expect(selector.send(:multi_selection?, '$and')).to be true
|
|
854
|
+
end
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
context 'when key is $or' do
|
|
858
|
+
it 'returns true' do
|
|
859
|
+
expect(selector.send(:multi_selection?, '$or')).to be true
|
|
860
|
+
end
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
context 'when key is $nor' do
|
|
864
|
+
it 'returns true' do
|
|
865
|
+
expect(selector.send(:multi_selection?, '$nor')).to be true
|
|
866
|
+
end
|
|
867
|
+
end
|
|
868
|
+
|
|
869
|
+
context 'when key includes $or but is not $or' do
|
|
870
|
+
it 'returns false' do
|
|
871
|
+
expect(selector.send(:multi_selection?, '$ore')).to be false
|
|
872
|
+
end
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
context 'when key is some other ey' do
|
|
876
|
+
it 'returns false' do
|
|
877
|
+
expect(selector.send(:multi_selection?, 'foo')).to be false
|
|
878
|
+
end
|
|
879
|
+
end
|
|
880
|
+
end
|
|
844
881
|
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
|
|
|
@@ -1445,18 +1460,18 @@ describe Mongoid::Criteria do
|
|
|
1445
1460
|
end
|
|
1446
1461
|
end
|
|
1447
1462
|
|
|
1448
|
-
context "when including the same
|
|
1463
|
+
context "when including the same association multiple times" do
|
|
1449
1464
|
|
|
1450
1465
|
let(:criteria) do
|
|
1451
1466
|
Person.all.includes(:posts, :posts).includes(:posts)
|
|
1452
1467
|
end
|
|
1453
1468
|
|
|
1454
|
-
let(:
|
|
1469
|
+
let(:association) do
|
|
1455
1470
|
Person.reflect_on_association(:posts)
|
|
1456
1471
|
end
|
|
1457
1472
|
|
|
1458
|
-
it "does not duplicate the
|
|
1459
|
-
expect(criteria.inclusions).to eq([
|
|
1473
|
+
it "does not duplicate the association in the inclusions" do
|
|
1474
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
1460
1475
|
end
|
|
1461
1476
|
end
|
|
1462
1477
|
|
|
@@ -2218,12 +2233,12 @@ describe Mongoid::Criteria do
|
|
|
2218
2233
|
Band.includes(:records)
|
|
2219
2234
|
end
|
|
2220
2235
|
|
|
2221
|
-
let(:
|
|
2236
|
+
let(:association) do
|
|
2222
2237
|
Band.relations["records"]
|
|
2223
2238
|
end
|
|
2224
2239
|
|
|
2225
2240
|
it "returns the inclusions" do
|
|
2226
|
-
expect(criteria.inclusions).to eq([
|
|
2241
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2227
2242
|
end
|
|
2228
2243
|
end
|
|
2229
2244
|
|
|
@@ -2233,16 +2248,16 @@ describe Mongoid::Criteria do
|
|
|
2233
2248
|
Band.all
|
|
2234
2249
|
end
|
|
2235
2250
|
|
|
2236
|
-
let(:
|
|
2251
|
+
let(:association) do
|
|
2237
2252
|
Band.relations["records"]
|
|
2238
2253
|
end
|
|
2239
2254
|
|
|
2240
2255
|
before do
|
|
2241
|
-
criteria.inclusions = [
|
|
2256
|
+
criteria.inclusions = [ association ]
|
|
2242
2257
|
end
|
|
2243
2258
|
|
|
2244
2259
|
it "sets the inclusions" do
|
|
2245
|
-
expect(criteria.inclusions).to eq([
|
|
2260
|
+
expect(criteria.inclusions).to eq([ association ])
|
|
2246
2261
|
end
|
|
2247
2262
|
end
|
|
2248
2263
|
|
|
@@ -2319,7 +2334,7 @@ describe Mongoid::Criteria do
|
|
|
2319
2334
|
end
|
|
2320
2335
|
|
|
2321
2336
|
it "returns the map/reduce results" do
|
|
2322
|
-
expect(map_reduce).to eq([
|
|
2337
|
+
expect(map_reduce.sort_by { |doc| doc['_id'] }).to eq([
|
|
2323
2338
|
{ "_id" => "Depeche Mode", "value" => { "likes" => 200 }},
|
|
2324
2339
|
{ "_id" => "Tool", "value" => { "likes" => 100 }}
|
|
2325
2340
|
])
|
|
@@ -2410,7 +2425,7 @@ describe Mongoid::Criteria do
|
|
|
2410
2425
|
end
|
|
2411
2426
|
end
|
|
2412
2427
|
|
|
2413
|
-
let(:
|
|
2428
|
+
let(:association) do
|
|
2414
2429
|
Band.relations["records"]
|
|
2415
2430
|
end
|
|
2416
2431
|
|
|
@@ -2435,7 +2450,7 @@ describe Mongoid::Criteria do
|
|
|
2435
2450
|
end
|
|
2436
2451
|
|
|
2437
2452
|
it "merges the inclusions" do
|
|
2438
|
-
expect(merged.inclusions).to eq([
|
|
2453
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2439
2454
|
end
|
|
2440
2455
|
|
|
2441
2456
|
it "returns a new criteria" do
|
|
@@ -2449,7 +2464,7 @@ describe Mongoid::Criteria do
|
|
|
2449
2464
|
{ klass: Band, includes: [ :records ] }
|
|
2450
2465
|
end
|
|
2451
2466
|
|
|
2452
|
-
let(:
|
|
2467
|
+
let(:association) do
|
|
2453
2468
|
Band.relations["records"]
|
|
2454
2469
|
end
|
|
2455
2470
|
|
|
@@ -2470,7 +2485,7 @@ describe Mongoid::Criteria do
|
|
|
2470
2485
|
end
|
|
2471
2486
|
|
|
2472
2487
|
it "merges the inclusions" do
|
|
2473
|
-
expect(merged.inclusions).to eq([
|
|
2488
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2474
2489
|
end
|
|
2475
2490
|
|
|
2476
2491
|
it "returns a new criteria" do
|
|
@@ -2495,7 +2510,7 @@ describe Mongoid::Criteria do
|
|
|
2495
2510
|
end
|
|
2496
2511
|
end
|
|
2497
2512
|
|
|
2498
|
-
let(:
|
|
2513
|
+
let(:association) do
|
|
2499
2514
|
Band.relations["records"]
|
|
2500
2515
|
end
|
|
2501
2516
|
|
|
@@ -2520,7 +2535,7 @@ describe Mongoid::Criteria do
|
|
|
2520
2535
|
end
|
|
2521
2536
|
|
|
2522
2537
|
it "merges the inclusions" do
|
|
2523
|
-
expect(merged.inclusions).to eq([
|
|
2538
|
+
expect(merged.inclusions).to eq([ association ])
|
|
2524
2539
|
end
|
|
2525
2540
|
|
|
2526
2541
|
it "returns the same criteria" do
|
|
@@ -3484,7 +3499,8 @@ describe Mongoid::Criteria do
|
|
|
3484
3499
|
end
|
|
3485
3500
|
end
|
|
3486
3501
|
|
|
3487
|
-
context "when querying on a BSON::Decimal128"
|
|
3502
|
+
context "when querying on a BSON::Decimal128" do
|
|
3503
|
+
min_server_version '3.4'
|
|
3488
3504
|
|
|
3489
3505
|
let(:decimal) do
|
|
3490
3506
|
BSON::Decimal128.new("0.0005")
|
|
@@ -3538,6 +3554,7 @@ describe Mongoid::Criteria do
|
|
|
3538
3554
|
end
|
|
3539
3555
|
|
|
3540
3556
|
context "when the code has scope" do
|
|
3557
|
+
max_server_version '4.2'
|
|
3541
3558
|
|
|
3542
3559
|
let(:criteria) do
|
|
3543
3560
|
Band.for_js("this.name == param", param: "Depeche Mode")
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
require "spec_helper"
|
|
5
|
+
|
|
6
|
+
describe Mongoid::Document do
|
|
7
|
+
|
|
8
|
+
describe 'BSON::Binary field' do
|
|
9
|
+
context 'when assigned a BSON::Binary instance' do
|
|
10
|
+
let(:data) do
|
|
11
|
+
BSON::Binary.new("hello world")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let(:registry) do
|
|
15
|
+
Registry.new(data: data)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'does not freeze the specified data' do
|
|
19
|
+
registry
|
|
20
|
+
|
|
21
|
+
data.should_not be_frozen
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'persists' do
|
|
25
|
+
registry.save!
|
|
26
|
+
|
|
27
|
+
_registry = Registry.find(registry.id)
|
|
28
|
+
_registry.data.should == data
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'when assigned a binary string' do
|
|
33
|
+
let(:data) do
|
|
34
|
+
# Frozen string literals do not allow setting encoding on a string
|
|
35
|
+
# literal - work around by composing the string at runtime
|
|
36
|
+
([0, 253, 254] * 2).map(&:chr).join.force_encoding('BINARY')
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
let(:registry) do
|
|
40
|
+
Registry.new(data: data)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'assigns as a BSON::Binary object' do
|
|
44
|
+
pending 'https://jira.mongodb.org/browse/MONGOID-4823'
|
|
45
|
+
|
|
46
|
+
registry.data.should be_a(BSON::Binary)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'persists' do
|
|
50
|
+
pending 'https://jira.mongodb.org/browse/MONGOID-4823'
|
|
51
|
+
|
|
52
|
+
registry.save!
|
|
53
|
+
|
|
54
|
+
_registry = Registry.find(registry.id)
|
|
55
|
+
_registry.data.should == BSON::Binary.new(data)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe 'Hash field' do
|
|
61
|
+
context 'with symbol key and value' do
|
|
62
|
+
let(:church) do
|
|
63
|
+
Church.create!(location: {state: :ny})
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
let(:found_church) do
|
|
67
|
+
Church.find(church.id)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'round-trips the value' do
|
|
71
|
+
found_church.location[:state].should == :ny
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'stringifies the key' do
|
|
75
|
+
found_church.location.keys.should == %w(state)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'retrieves value as symbol via driver' do
|
|
79
|
+
Church.delete_all
|
|
80
|
+
|
|
81
|
+
church
|
|
82
|
+
|
|
83
|
+
v = Church.collection.find.first
|
|
84
|
+
v['location'].should == {'state' => :ny}
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
require "spec_helper"
|
|
5
|
+
|
|
6
|
+
describe Mongoid::Document do
|
|
7
|
+
|
|
8
|
+
let(:klass) do
|
|
9
|
+
Person
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:person) do
|
|
13
|
+
Person.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '.client_name' do
|
|
17
|
+
it 'returns client name' do
|
|
18
|
+
Person.client_name.should == :default
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe '.database_name' do
|
|
23
|
+
it 'returns database name' do
|
|
24
|
+
Person.database_name.should == 'mongoid_test'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '.collection_name' do
|
|
29
|
+
it 'returns collection name' do
|
|
30
|
+
Person.collection_name.should == :people
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -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
|
|
@@ -435,6 +456,10 @@ describe Mongoid::Document do
|
|
|
435
456
|
end
|
|
436
457
|
|
|
437
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'
|
|
438
463
|
|
|
439
464
|
before do
|
|
440
465
|
# These tests require a specific set of defined attributes
|