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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe Mongoid::Matchable::Eq do
|
|
6
|
+
|
|
7
|
+
let(:matcher) do
|
|
8
|
+
described_class.new("first")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#_matches?" do
|
|
12
|
+
|
|
13
|
+
context "when the values are equal" do
|
|
14
|
+
|
|
15
|
+
it "returns true" do
|
|
16
|
+
expect(matcher._matches?("$eq" => "first")).to be true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "when the values are not equal" do
|
|
21
|
+
|
|
22
|
+
it "returns false" do
|
|
23
|
+
expect(matcher._matches?("$eq" => "second")).to be false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when the value is an array" do
|
|
28
|
+
|
|
29
|
+
let(:array_matcher) do
|
|
30
|
+
described_class.new([ "first" ])
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "when the value is in the array" do
|
|
34
|
+
|
|
35
|
+
it "returns true" do
|
|
36
|
+
expect(array_matcher._matches?("$eq" => "first")).to be true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when the value is not in the array" do
|
|
41
|
+
|
|
42
|
+
it "returns false" do
|
|
43
|
+
expect(array_matcher._matches?("$eq" => "second")).to be false
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -15,7 +15,7 @@ describe Mongoid::Matchable::Regexp do
|
|
|
15
15
|
context 'when a BSON::Regexp::Raw object is passed' do
|
|
16
16
|
|
|
17
17
|
let(:regexp) do
|
|
18
|
-
BSON::Regexp::Raw.new(
|
|
18
|
+
BSON::Regexp::Raw.new("\\AEm")
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'compiles the regexp object to a native regexp for the matching' do
|
|
@@ -37,7 +37,7 @@ describe Mongoid::Matchable::Regexp do
|
|
|
37
37
|
context 'when a native Regexp object is passed' do
|
|
38
38
|
|
|
39
39
|
let(:regexp) do
|
|
40
|
-
|
|
40
|
+
/\AEm/
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it 'calls super with the native regexp' do
|
|
@@ -293,7 +293,7 @@ describe Mongoid::Matchable do
|
|
|
293
293
|
context 'when a BSON::Regexp::Raw object is used' do
|
|
294
294
|
|
|
295
295
|
let(:selector) do
|
|
296
|
-
{ street: BSON::Regexp::Raw.new("
|
|
296
|
+
{ street: BSON::Regexp::Raw.new("\\AClarkenwell") }
|
|
297
297
|
end
|
|
298
298
|
|
|
299
299
|
it "returns true" do
|
|
@@ -304,7 +304,7 @@ describe Mongoid::Matchable do
|
|
|
304
304
|
context 'when a native Regexp object is used' do
|
|
305
305
|
|
|
306
306
|
let(:selector) do
|
|
307
|
-
{ street:
|
|
307
|
+
{ street: /\AClarkenwell/ }
|
|
308
308
|
end
|
|
309
309
|
|
|
310
310
|
it "returns true" do
|
|
@@ -4,7 +4,7 @@ describe Mongoid::Persistable::Pushable do
|
|
|
4
4
|
|
|
5
5
|
describe "#add_to_set" do
|
|
6
6
|
|
|
7
|
-
context "when the document is a
|
|
7
|
+
context "when the document is a top level document" do
|
|
8
8
|
|
|
9
9
|
shared_examples_for "a unique pushable root document" do
|
|
10
10
|
|
|
@@ -62,6 +62,60 @@ describe Mongoid::Persistable::Pushable do
|
|
|
62
62
|
|
|
63
63
|
it_behaves_like "a unique pushable root document"
|
|
64
64
|
end
|
|
65
|
+
|
|
66
|
+
context 'when the host model is not saved' do
|
|
67
|
+
context 'when attribute exists' do
|
|
68
|
+
let(:person) do
|
|
69
|
+
Person.new(aliases: [2])
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it 'records the change' do
|
|
73
|
+
person.add_to_set({aliases: 1})
|
|
74
|
+
|
|
75
|
+
expect(person.aliases).to eq([2, 1])
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'when attribute does not exist' do
|
|
80
|
+
let(:person) do
|
|
81
|
+
Person.new
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'records the change' do
|
|
85
|
+
person.add_to_set({aliases: 1})
|
|
86
|
+
|
|
87
|
+
expect(person.aliases).to eq([1])
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context 'when the host model is loaded from database' do
|
|
93
|
+
context 'when attribute exists' do
|
|
94
|
+
let(:person) do
|
|
95
|
+
Person.create!(aliases: [2])
|
|
96
|
+
person = Person.last
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'records the change' do
|
|
100
|
+
person.add_to_set({aliases: 1})
|
|
101
|
+
|
|
102
|
+
expect(person.aliases).to eq([2, 1])
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'when attribute does not exist' do
|
|
107
|
+
let(:person) do
|
|
108
|
+
Person.create!
|
|
109
|
+
person = Person.last
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it 'records the change' do
|
|
113
|
+
person.add_to_set({aliases: 1})
|
|
114
|
+
|
|
115
|
+
expect(person.aliases).to eq([1])
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
65
119
|
end
|
|
66
120
|
|
|
67
121
|
context "when the document is embedded" do
|
|
@@ -166,8 +166,8 @@ describe Mongoid::Persistable::Savable do
|
|
|
166
166
|
Person.create(title: "Blah")
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
-
let!(:
|
|
170
|
-
person.
|
|
169
|
+
let!(:symptom) do
|
|
170
|
+
person.symptoms.build(name: "Headache")
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
let!(:name) do
|
|
@@ -190,7 +190,7 @@ describe Mongoid::Persistable::Savable do
|
|
|
190
190
|
"name.first_name" => "Ryan"
|
|
191
191
|
},
|
|
192
192
|
"$push"=> {
|
|
193
|
-
"
|
|
193
|
+
"symptoms" => { '$each' => [ { "_id" => symptom.id, "name" => "Headache" } ] }
|
|
194
194
|
}
|
|
195
195
|
})
|
|
196
196
|
end
|
|
@@ -202,7 +202,7 @@ describe Mongoid::Persistable::Savable do
|
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
it "saves embedded many relations" do
|
|
205
|
-
expect(person.
|
|
205
|
+
expect(person.symptoms.first.name).to eq("Headache")
|
|
206
206
|
end
|
|
207
207
|
|
|
208
208
|
it "saves embedded one relations" do
|
|
@@ -309,7 +309,7 @@ describe Mongoid::Persistable::Savable do
|
|
|
309
309
|
expect {
|
|
310
310
|
person.username = 'unloaded-attribute'
|
|
311
311
|
person.save
|
|
312
|
-
}.to raise_error(
|
|
312
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
313
313
|
end
|
|
314
314
|
|
|
315
315
|
context 'when the changed attribute is aliased' do
|
|
@@ -211,7 +211,7 @@ describe Mongoid::Persistable::Settable do
|
|
|
211
211
|
Church.new.tap do |a|
|
|
212
212
|
a.location = { 'city' => 'Berlin' }
|
|
213
213
|
a.name = 'Church1'
|
|
214
|
-
a.save
|
|
214
|
+
a.save!
|
|
215
215
|
end
|
|
216
216
|
end
|
|
217
217
|
|
|
@@ -280,7 +280,7 @@ describe Mongoid::Persistable::Settable do
|
|
|
280
280
|
|
|
281
281
|
context 'when the field is a nested hash' do
|
|
282
282
|
|
|
283
|
-
context 'when the field is
|
|
283
|
+
context 'when the field is set to an empty hash' do
|
|
284
284
|
|
|
285
285
|
before do
|
|
286
286
|
church.set('location' => {})
|
|
@@ -301,7 +301,7 @@ describe Mongoid::Persistable::Settable do
|
|
|
301
301
|
Church.new.tap do |a|
|
|
302
302
|
a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
|
|
303
303
|
a.name = 'Church1'
|
|
304
|
-
a.save
|
|
304
|
+
a.save!
|
|
305
305
|
end
|
|
306
306
|
end
|
|
307
307
|
|
|
@@ -321,7 +321,7 @@ describe Mongoid::Persistable::Settable do
|
|
|
321
321
|
Church.new.tap do |a|
|
|
322
322
|
a.location = {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}
|
|
323
323
|
a.name = 'Church1'
|
|
324
|
-
a.save
|
|
324
|
+
a.save!
|
|
325
325
|
end
|
|
326
326
|
end
|
|
327
327
|
|
|
@@ -341,20 +341,105 @@ describe Mongoid::Persistable::Settable do
|
|
|
341
341
|
Church.new.tap do |a|
|
|
342
342
|
a.location = {'address' => {'state' => {'address' => {'city' => 'Berlin', 'street' => 'Yorckstr'}}}}
|
|
343
343
|
a.name = 'Church1'
|
|
344
|
-
a.save
|
|
344
|
+
a.save!
|
|
345
345
|
end
|
|
346
346
|
end
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
context 'setting value to a string' do
|
|
349
|
+
it 'keeps peer attributes of the nested hash' do
|
|
350
|
+
church.set('location.address.state.address.city' => 'Munich')
|
|
351
|
+
|
|
352
|
+
expect(church.name).to eq('Church1')
|
|
353
|
+
expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => 'Munich', 'street' => 'Yorckstr'}}}})
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
it 'removes lower level attributes of the nested hash' do
|
|
357
|
+
church.set('location.address.state.address' => 'hello')
|
|
358
|
+
|
|
359
|
+
expect(church.name).to eq('Church1')
|
|
360
|
+
expect(church.location).to eql({'address' => {'state' => {'address' => 'hello'}}})
|
|
361
|
+
end
|
|
350
362
|
end
|
|
351
363
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
364
|
+
context 'setting value to a hash' do
|
|
365
|
+
it 'keeps peer attributes of the nested hash' do
|
|
366
|
+
church.set('location.address.state.address.city' => {'hello' => 'world'})
|
|
367
|
+
|
|
368
|
+
expect(church.name).to eq('Church1')
|
|
369
|
+
expect(church.location).to eql({'address' => {'state' => {'address' => {'city' => {'hello' => 'world'}, 'street' => 'Yorckstr'}}}})
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
it 'removes lower level attributes of the nested hash' do
|
|
373
|
+
church.set('location.address.state.address' => {'hello' => 'world'})
|
|
374
|
+
|
|
375
|
+
expect(church.name).to eq('Church1')
|
|
376
|
+
expect(church.location).to eql({'address' => {'state' => {'address' => {'hello' => 'world'}}}})
|
|
377
|
+
end
|
|
355
378
|
end
|
|
356
379
|
end
|
|
357
380
|
end
|
|
381
|
+
|
|
382
|
+
context 'when nested field is an array' do
|
|
383
|
+
let(:church) do
|
|
384
|
+
Church.create!(
|
|
385
|
+
location: {'address' => ['one', 'two']}
|
|
386
|
+
)
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
context 'setting to a different array' do
|
|
390
|
+
it 'sets values to new array discarding old values' do
|
|
391
|
+
church.set('location.address' => ['three'])
|
|
392
|
+
|
|
393
|
+
expect(church.location).to eq('address' => ['three'])
|
|
394
|
+
church.reload
|
|
395
|
+
expect(church.location).to eq('address' => ['three'])
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
context 'changing from an array to a number' do
|
|
400
|
+
it 'sets value to the number' do
|
|
401
|
+
church.set('location.address' => 5)
|
|
402
|
+
|
|
403
|
+
expect(church.location).to eq('address' => 5)
|
|
404
|
+
church.reload
|
|
405
|
+
expect(church.location).to eq('address' => 5)
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
context 'when nested field is not an array' do
|
|
411
|
+
let(:church) do
|
|
412
|
+
Church.create!(
|
|
413
|
+
location: {'address' => 5}
|
|
414
|
+
)
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
context 'setting to an array' do
|
|
418
|
+
it 'sets values to the array' do
|
|
419
|
+
church.set('location.address' => ['three'])
|
|
420
|
+
|
|
421
|
+
expect(church.location).to eq('address' => ['three'])
|
|
422
|
+
church.reload
|
|
423
|
+
expect(church.location).to eq('address' => ['three'])
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
context 'when nesting into a field that is not a hash' do
|
|
429
|
+
let(:church) do
|
|
430
|
+
Church.create!(
|
|
431
|
+
location: {'address' => 5}
|
|
432
|
+
)
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
it 'sets field to new hash value discarding original value' do
|
|
436
|
+
church.set('location.address.a' => 'test')
|
|
437
|
+
|
|
438
|
+
expect(church.location).to eq('address' => {'a' => 'test'})
|
|
439
|
+
church.reload
|
|
440
|
+
expect(church.location).to eq('address' => {'a' => 'test'})
|
|
441
|
+
end
|
|
442
|
+
end
|
|
358
443
|
end
|
|
359
444
|
|
|
360
445
|
context 'when the field is not already set locally' do
|
|
@@ -410,4 +495,34 @@ describe Mongoid::Persistable::Settable do
|
|
|
410
495
|
end
|
|
411
496
|
end
|
|
412
497
|
end
|
|
498
|
+
|
|
499
|
+
context "when the field being set was projected out" do
|
|
500
|
+
let(:full_agent) do
|
|
501
|
+
Agent.create!(title: "Double-Oh Eight")
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
let(:agent) do
|
|
505
|
+
Agent.where(_id: full_agent.id).only(:dob).first
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
context 'field exists in database' do
|
|
509
|
+
it "raises MissingAttributeError" do
|
|
510
|
+
lambda do
|
|
511
|
+
agent.set(title: '008')
|
|
512
|
+
end.should raise_error(ActiveModel::MissingAttributeError)
|
|
513
|
+
|
|
514
|
+
expect(agent.reload.title).to eq 'Double-Oh Eight'
|
|
515
|
+
end
|
|
516
|
+
end
|
|
517
|
+
|
|
518
|
+
context 'field does not exist in database' do
|
|
519
|
+
it "raises MissingAttributeError" do
|
|
520
|
+
lambda do
|
|
521
|
+
agent.set(number: '008')
|
|
522
|
+
end.should raise_error(ActiveModel::MissingAttributeError)
|
|
523
|
+
|
|
524
|
+
expect(agent.reload.read_attribute(:number)).to be nil
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
end
|
|
413
528
|
end
|
|
@@ -57,7 +57,7 @@ describe Mongoid::Persistable do
|
|
|
57
57
|
"$bit" => { "likes" => { :and => 13 }},
|
|
58
58
|
"$set" => { "name" => "Placebo" },
|
|
59
59
|
"$unset" => { "origin" => true }},
|
|
60
|
-
|
|
60
|
+
{ :session => nil } ]
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
before do
|
|
@@ -83,8 +83,8 @@ describe Mongoid::Persistable do
|
|
|
83
83
|
"$inc" => { "member_count" => 10 },
|
|
84
84
|
"$bit" => { "likes" => { :and => 13 }},
|
|
85
85
|
"$set" => { "name" => "Placebo" },
|
|
86
|
-
"$unset" => { "origin" => true }},
|
|
87
|
-
|
|
86
|
+
"$unset" => { "origin" => true } },
|
|
87
|
+
{ :session => nil } ]
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
before do
|
|
@@ -107,12 +107,12 @@ describe Mongoid::Persistable do
|
|
|
107
107
|
context "when given multiple operations of the same type" do
|
|
108
108
|
|
|
109
109
|
let(:operations) do
|
|
110
|
-
|
|
110
|
+
[{
|
|
111
111
|
"$inc" => { "member_count" => 10, "other_count" => 10 },
|
|
112
112
|
"$bit" => { "likes" => { :and => 13 }},
|
|
113
113
|
"$set" => { "name" => "Placebo" },
|
|
114
114
|
"$unset" => { "origin" => true }},
|
|
115
|
-
{ session
|
|
115
|
+
{ :session => nil } ]
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
before do
|
|
@@ -149,7 +149,7 @@ describe Mongoid::Persistable do
|
|
|
149
149
|
"$bit" => { "likes" => { :and => 13 }},
|
|
150
150
|
"$set" => { "name" => "Placebo" },
|
|
151
151
|
"$unset" => { "origin" => true }},
|
|
152
|
-
{ session
|
|
152
|
+
{ :session => nil } ]
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
before do
|
|
@@ -200,6 +200,21 @@ describe Mongoid::Persistable do
|
|
|
200
200
|
expect(document.atomically).to be true
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
|
+
|
|
204
|
+
context "when the block has no operations" do
|
|
205
|
+
before do
|
|
206
|
+
expect_any_instance_of(Mongo::Collection::View).to_not receive(:update_one)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
let!(:update) do
|
|
210
|
+
document.atomically do
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it "doesn't update the document" do
|
|
215
|
+
expect(document.reload.origin).to eq("London")
|
|
216
|
+
end
|
|
217
|
+
end
|
|
203
218
|
end
|
|
204
219
|
|
|
205
220
|
describe "#fail_due_to_valiation!" do
|
|
@@ -536,7 +536,7 @@ describe Mongoid::PersistenceContext do
|
|
|
536
536
|
end
|
|
537
537
|
|
|
538
538
|
before do
|
|
539
|
-
Mongoid.clients[:alternative] = { database: :mongoid_test, hosts:
|
|
539
|
+
Mongoid.clients[:alternative] = { database: :mongoid_test, hosts: SpecConfig.instance.addresses }
|
|
540
540
|
end
|
|
541
541
|
|
|
542
542
|
after do
|
|
@@ -45,32 +45,16 @@ describe Mongoid::QueryCache do
|
|
|
45
45
|
:posts
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
context '
|
|
48
|
+
context 'does not query for the relation and instead sets the base' do
|
|
49
49
|
|
|
50
50
|
before do
|
|
51
51
|
Mongoid::QueryCache.enabled = false
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
it 'queries for each access to the base' do
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'when query cache is enabled' do
|
|
64
|
-
|
|
65
|
-
before do
|
|
66
|
-
Mongoid::QueryCache.enabled = true
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'queries only once for the base' do
|
|
70
|
-
expect_query(1) do
|
|
71
|
-
relations.each do |object|
|
|
72
|
-
object.person
|
|
73
|
-
end
|
|
55
|
+
expect(server).to receive(:with_connection).exactly(0).times.and_call_original
|
|
56
|
+
relations.each do |object|
|
|
57
|
+
object.person
|
|
74
58
|
end
|
|
75
59
|
end
|
|
76
60
|
end
|
|
@@ -153,6 +137,36 @@ describe Mongoid::QueryCache do
|
|
|
153
137
|
end
|
|
154
138
|
end
|
|
155
139
|
|
|
140
|
+
context 'querying all documents after a single document' do
|
|
141
|
+
before do
|
|
142
|
+
3.times do
|
|
143
|
+
Person.create
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'returns all documents' do
|
|
148
|
+
expect(Person.all.to_a.count).to eq(3)
|
|
149
|
+
Person.first
|
|
150
|
+
expect(Person.all.to_a.count).to eq(3)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
context 'with conditions specified' do
|
|
154
|
+
it 'returns all documents' do
|
|
155
|
+
expect(Person.gt(age: 0).to_a.count).to eq(3)
|
|
156
|
+
Person.gt(age: 0).first
|
|
157
|
+
expect(Person.gt(age: 0).to_a.count).to eq(3)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context 'with order specified' do
|
|
162
|
+
it 'returns all documents' do
|
|
163
|
+
expect(Person.order_by(name: 1).to_a.count).to eq(3)
|
|
164
|
+
Person.order_by(name: 1).first
|
|
165
|
+
expect(Person.order_by(name: 1).to_a.count).to eq(3)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
156
170
|
context "when querying in the same collection" do
|
|
157
171
|
|
|
158
172
|
before do
|
|
@@ -180,7 +194,8 @@ describe Mongoid::QueryCache do
|
|
|
180
194
|
end
|
|
181
195
|
end
|
|
182
196
|
|
|
183
|
-
context 'when the first query has a collation'
|
|
197
|
+
context 'when the first query has a collation' do
|
|
198
|
+
min_server_version '3.4'
|
|
184
199
|
|
|
185
200
|
before do
|
|
186
201
|
Band.where(name: 'DEPECHE MODE').collation(locale: 'en_US', strength: 2).to_a
|
|
@@ -494,18 +509,18 @@ describe Mongoid::QueryCache do
|
|
|
494
509
|
end
|
|
495
510
|
end
|
|
496
511
|
|
|
497
|
-
context "when querying
|
|
512
|
+
context "when querying collection smaller than the batch size" do
|
|
498
513
|
|
|
499
514
|
before do
|
|
500
|
-
|
|
515
|
+
99.times { Band.create! }
|
|
501
516
|
end
|
|
502
517
|
|
|
503
518
|
it "returns the right number of records" do
|
|
504
|
-
expect(Band.all.to_a.length).to eq(
|
|
519
|
+
expect(Band.all.to_a.length).to eq(99)
|
|
505
520
|
end
|
|
506
521
|
|
|
507
522
|
it "#pluck returns the same count of objects" do
|
|
508
|
-
expect(Band.pluck(:name).length).to eq(
|
|
523
|
+
expect(Band.pluck(:name).length).to eq(99)
|
|
509
524
|
end
|
|
510
525
|
|
|
511
526
|
context "when loading all the documents" do
|
|
@@ -516,12 +531,12 @@ describe Mongoid::QueryCache do
|
|
|
516
531
|
|
|
517
532
|
it "caches the complete result of the query" do
|
|
518
533
|
expect_no_queries do
|
|
519
|
-
expect(Band.all.to_a.length).to eq(
|
|
534
|
+
expect(Band.all.to_a.length).to eq(99)
|
|
520
535
|
end
|
|
521
536
|
end
|
|
522
537
|
|
|
523
538
|
it "returns the same count of objects when using #pluck" do
|
|
524
|
-
expect(Band.pluck(:name).length).to eq(
|
|
539
|
+
expect(Band.pluck(:name).length).to eq(99)
|
|
525
540
|
end
|
|
526
541
|
end
|
|
527
542
|
end
|
|
@@ -533,6 +548,29 @@ describe Mongoid::QueryCache do
|
|
|
533
548
|
Band.collection.indexes.create_one(name: 1)
|
|
534
549
|
end
|
|
535
550
|
end
|
|
551
|
+
|
|
552
|
+
context 'when the initial query does not exhaust the results' do
|
|
553
|
+
before do
|
|
554
|
+
Mongoid::QueryCache.enabled = true
|
|
555
|
+
10.times { Band.create! }
|
|
556
|
+
|
|
557
|
+
Band.batch_size(4).all.to_a
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
it 'does not cache the result' do
|
|
561
|
+
expect(Band.all.map(&:id).size).to eq(10)
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
context 'when a batch size smaller than the result set is specified' do
|
|
565
|
+
let(:batch_size) do
|
|
566
|
+
4
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
it 'does not cache the result' do
|
|
570
|
+
expect(Band.batch_size(batch_size).all.map(&:id).size).to eq(10)
|
|
571
|
+
end
|
|
572
|
+
end
|
|
573
|
+
end
|
|
536
574
|
end
|
|
537
575
|
|
|
538
576
|
describe Mongoid::QueryCache::Middleware do
|