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,390 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Mongoid::Clients::Sessions do
|
|
4
|
+
before(:all) do
|
|
5
|
+
unless Mongo::VERSION >= '2.6'
|
|
6
|
+
skip 'Driver does not support transactions'
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
before(:all) do
|
|
11
|
+
if Mongo::VERSION >= '2.6'
|
|
12
|
+
CONFIG[:clients][:other] = CONFIG[:clients][:default].dup
|
|
13
|
+
CONFIG[:clients][:other][:database] = 'other'
|
|
14
|
+
Mongoid::Clients.clients.values.each(&:close)
|
|
15
|
+
Mongoid::Config.send(:clients=, CONFIG[:clients])
|
|
16
|
+
Mongoid::Clients.with_name(:other).subscribe(Mongo::Monitoring::COMMAND, EventSubscriber.new)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
after(:all) do
|
|
21
|
+
if Mongo::VERSION >= '2.6'
|
|
22
|
+
Mongoid::Clients.with_name(:other).close
|
|
23
|
+
Mongoid::Clients.clients.delete(:other)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:subscriber) do
|
|
28
|
+
Mongoid::Clients.with_name(:other).send(:monitoring).subscribers['Command'].find do |s|
|
|
29
|
+
s.is_a?(EventSubscriber)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
let(:insert_events) do
|
|
34
|
+
subscriber.started_events.select { |event| event.command_name == 'insert' }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
let(:insert_events_txn_numbers) do
|
|
38
|
+
insert_events.map { |i| i.instance_variable_get(:@integer) }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
let(:update_events) do
|
|
42
|
+
subscriber.started_events.select { |event| event.command_name == 'update' }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
let(:update_events_txn_numbers) do
|
|
46
|
+
update_events.map { |i| i.instance_variable_get(:@integer) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
let(:other_events) do
|
|
50
|
+
subscriber.started_events.reject { |event| ['insert', 'update'].include?(event.command_name) }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'when a transaction is used on a model class' do
|
|
54
|
+
|
|
55
|
+
context 'when transactions are supported' do
|
|
56
|
+
require_transaction_support
|
|
57
|
+
|
|
58
|
+
around do |example|
|
|
59
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
60
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
61
|
+
Mongoid::Clients.with_name(:other).command(create: :posts)
|
|
62
|
+
subscriber.clear_events!
|
|
63
|
+
Person.with(client: :other) do
|
|
64
|
+
example.run
|
|
65
|
+
end
|
|
66
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
context 'when another thread is started' do
|
|
70
|
+
|
|
71
|
+
let!(:last_use_diff) do
|
|
72
|
+
Person.with_session do |s|
|
|
73
|
+
s.start_transaction
|
|
74
|
+
Person.create
|
|
75
|
+
Person.create
|
|
76
|
+
Thread.new { Person.create }.value
|
|
77
|
+
s.commit_transaction
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'does not use the transaction for that thread' do
|
|
82
|
+
expect(Person.count).to be(2)
|
|
83
|
+
expect(Person.with(client: :default) { Person.count }).to be(1)
|
|
84
|
+
expect(insert_events.count { |e| e.command['startTransaction'] }).to be(1)
|
|
85
|
+
expect(other_events.count { |e| e.command_name == 'commitTransaction' }).to be(1)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'when the operations in the transactions block are all on the class' do
|
|
90
|
+
|
|
91
|
+
before do
|
|
92
|
+
Person.with_session do |s|
|
|
93
|
+
s.start_transaction
|
|
94
|
+
Person.create
|
|
95
|
+
Person.create
|
|
96
|
+
s.commit_transaction
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
101
|
+
expect(Person.count).to be(2)
|
|
102
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
103
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'when the operations in the transactions block are also on another class' do
|
|
108
|
+
|
|
109
|
+
context 'when the other class uses the same client' do
|
|
110
|
+
|
|
111
|
+
before do
|
|
112
|
+
Post.with(client: :other) do
|
|
113
|
+
Person.with_session do |s|
|
|
114
|
+
s.start_transaction
|
|
115
|
+
Person.create
|
|
116
|
+
Person.create
|
|
117
|
+
Post.create
|
|
118
|
+
s.commit_transaction
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
124
|
+
expect(Post.with(client: :other) { |klass| klass.count }).to be(1)
|
|
125
|
+
expect(insert_events_txn_numbers.size).to eq(3)
|
|
126
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context 'when the other class uses a different client' do
|
|
131
|
+
|
|
132
|
+
let!(:error) do
|
|
133
|
+
e = nil
|
|
134
|
+
begin
|
|
135
|
+
Person.with_session do |s|
|
|
136
|
+
s.start_transaction
|
|
137
|
+
Person.create
|
|
138
|
+
Person.create
|
|
139
|
+
Post.create
|
|
140
|
+
s.commit_transaction
|
|
141
|
+
end
|
|
142
|
+
rescue => ex
|
|
143
|
+
e = ex
|
|
144
|
+
end
|
|
145
|
+
e
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it 'raises an error' do
|
|
149
|
+
expect(error).to be_a(Mongoid::Errors::InvalidSessionUse)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'aborted the transaction' do
|
|
153
|
+
expect(Person.count).to be(0)
|
|
154
|
+
expect(Post.count).to be(0)
|
|
155
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
156
|
+
expect(other_events.count { |e| e.command_name == 'abortTransaction'}).to be(1)
|
|
157
|
+
expect(other_events.count { |e| e.command_name == 'commitTransaction'}).to be(0)
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context 'when transactions are nested' do
|
|
162
|
+
|
|
163
|
+
let!(:error) do
|
|
164
|
+
e = nil
|
|
165
|
+
begin
|
|
166
|
+
Person.with_session do |s|
|
|
167
|
+
s.start_transaction
|
|
168
|
+
s.start_transaction
|
|
169
|
+
Person.create
|
|
170
|
+
Post.create
|
|
171
|
+
s.commit_transaction
|
|
172
|
+
end
|
|
173
|
+
rescue => ex
|
|
174
|
+
e = ex
|
|
175
|
+
end
|
|
176
|
+
e
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'raises an error' do
|
|
180
|
+
expect(error).to be_a(Mongo::Error::InvalidTransactionOperation)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it 'does not execute any operations' do
|
|
184
|
+
expect(Person.count).to be(0)
|
|
185
|
+
expect(Post.count).to be(0)
|
|
186
|
+
expect(insert_events).to be_empty
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
context 'when sessions are supported but transactions are not' do
|
|
193
|
+
min_server_version '3.6'
|
|
194
|
+
# Could also test 4.0 in sharded cluster
|
|
195
|
+
max_server_version '3.6'
|
|
196
|
+
|
|
197
|
+
let!(:error) do
|
|
198
|
+
e = nil
|
|
199
|
+
begin
|
|
200
|
+
Person.with_session do |s|
|
|
201
|
+
s.start_transaction
|
|
202
|
+
Person.create
|
|
203
|
+
s.commit_transaction
|
|
204
|
+
end
|
|
205
|
+
rescue => ex
|
|
206
|
+
e = ex
|
|
207
|
+
end
|
|
208
|
+
e
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
it 'raises a transactions not supported error' do
|
|
212
|
+
expect(Person.count).to eq(0)
|
|
213
|
+
expect(error).to be_a(Mongo::Error::OperationFailure)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
context 'when a transaction is used on a model instance' do
|
|
219
|
+
|
|
220
|
+
let!(:person) do
|
|
221
|
+
Person.with(client: :other) do |klass|
|
|
222
|
+
klass.create
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
context 'when transactions are supported' do
|
|
227
|
+
require_transaction_support
|
|
228
|
+
|
|
229
|
+
around do |example|
|
|
230
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
231
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
232
|
+
Mongoid::Clients.with_name(:other).command(create: :posts)
|
|
233
|
+
subscriber.clear_events!
|
|
234
|
+
person.with(client: :other) do
|
|
235
|
+
example.run
|
|
236
|
+
end
|
|
237
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
context 'when the operations in the transaction block are all on the instance' do
|
|
241
|
+
|
|
242
|
+
before do
|
|
243
|
+
person.with_session do |s|
|
|
244
|
+
s.start_transaction
|
|
245
|
+
person.username = 'Emily'
|
|
246
|
+
person.save
|
|
247
|
+
person.age = 80
|
|
248
|
+
person.save
|
|
249
|
+
s.commit_transaction
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
254
|
+
expect(person.reload.username).to eq('Emily')
|
|
255
|
+
expect(person.reload.age).to eq(80)
|
|
256
|
+
expect(update_events_txn_numbers.size).to eq(2)
|
|
257
|
+
expect(update_events_txn_numbers.uniq.size).to eq(1)
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
context 'when the operations in the transaction block are also on another class' do
|
|
262
|
+
|
|
263
|
+
context 'when the other class uses the same client' do
|
|
264
|
+
|
|
265
|
+
before do
|
|
266
|
+
Post.with(client: :other) do
|
|
267
|
+
person.with_session do |s|
|
|
268
|
+
s.start_transaction
|
|
269
|
+
person.username = 'Emily'
|
|
270
|
+
person.save
|
|
271
|
+
person.posts << Post.create
|
|
272
|
+
s.commit_transaction
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it 'uses a single transaction number for all operations on the class' do
|
|
278
|
+
expect(person.reload.username).to eq('Emily')
|
|
279
|
+
expect(Post.with(client: :other) { Post.count }).to be(1)
|
|
280
|
+
expect(update_events_txn_numbers.size).to eq(3) # person update, counter cache, post assignment
|
|
281
|
+
expect(update_events_txn_numbers.uniq.size).to eq(1) # person update, counter cache, post assignment
|
|
282
|
+
expect(insert_events_txn_numbers.size).to eq(2)
|
|
283
|
+
expect(insert_events_txn_numbers.uniq.size).to eq(1)
|
|
284
|
+
expect(update_events_txn_numbers.uniq).to eq(insert_events_txn_numbers.uniq)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
context 'when the other class uses a different client' do
|
|
289
|
+
|
|
290
|
+
let!(:error) do
|
|
291
|
+
e = nil
|
|
292
|
+
begin
|
|
293
|
+
person.with_session do |s|
|
|
294
|
+
s.start_transaction
|
|
295
|
+
person.username = 'Emily'
|
|
296
|
+
person.save
|
|
297
|
+
person.posts << Post.create
|
|
298
|
+
s.commit_transaction
|
|
299
|
+
end
|
|
300
|
+
rescue => ex
|
|
301
|
+
e = ex
|
|
302
|
+
end
|
|
303
|
+
e
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
it 'raises an error' do
|
|
307
|
+
expect(error).to be_a(Mongoid::Errors::InvalidSessionUse)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
it 'aborted the transction' do
|
|
311
|
+
expect(person.reload.username).not_to eq('Emily')
|
|
312
|
+
expect(Post.count).to be(0)
|
|
313
|
+
expect(update_events_txn_numbers.size).to eq(1)
|
|
314
|
+
expect(insert_events_txn_numbers.size).to eq(1)
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
context 'when transactions are nested' do
|
|
319
|
+
|
|
320
|
+
let!(:error) do
|
|
321
|
+
e = nil
|
|
322
|
+
begin
|
|
323
|
+
person.with_session do |s|
|
|
324
|
+
s.start_transaction
|
|
325
|
+
s.start_transaction
|
|
326
|
+
person.username = 'Emily'
|
|
327
|
+
person.save
|
|
328
|
+
person.posts << Post.create
|
|
329
|
+
s.commit_transaction
|
|
330
|
+
end
|
|
331
|
+
rescue => ex
|
|
332
|
+
e = ex
|
|
333
|
+
end
|
|
334
|
+
e
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
it 'raises an error' do
|
|
338
|
+
expect(error).to be_a(Mongo::Error::InvalidTransactionOperation)
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
it 'does not execute any operations' do
|
|
342
|
+
expect(person.reload.username).not_to eq('Emily')
|
|
343
|
+
expect(Post.count).to be(0)
|
|
344
|
+
expect(update_events).to be_empty
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
context 'when sessions are supported but transactions are not' do
|
|
351
|
+
min_server_version '3.6'
|
|
352
|
+
# Could also test 4.0 in sharded cluster
|
|
353
|
+
max_server_version '3.6'
|
|
354
|
+
|
|
355
|
+
around do |example|
|
|
356
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
357
|
+
Mongoid::Clients.with_name(:other).command(create: :people)
|
|
358
|
+
|
|
359
|
+
begin
|
|
360
|
+
subscriber.clear_events!
|
|
361
|
+
person.with(client: :other) do
|
|
362
|
+
example.run
|
|
363
|
+
end
|
|
364
|
+
ensure
|
|
365
|
+
Mongoid::Clients.with_name(:other).database.collections.each(&:drop)
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
let!(:error) do
|
|
370
|
+
e = nil
|
|
371
|
+
begin
|
|
372
|
+
person.with_session do |s|
|
|
373
|
+
s.start_transaction
|
|
374
|
+
person.username = 'Emily'
|
|
375
|
+
person.save
|
|
376
|
+
s.commit_transaction
|
|
377
|
+
end
|
|
378
|
+
rescue => ex
|
|
379
|
+
e = ex
|
|
380
|
+
end
|
|
381
|
+
e
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
it 'raises a sessions not supported error' do
|
|
385
|
+
expect(person.reload.username).not_to be('Emily')
|
|
386
|
+
expect(error).to be_a(Mongo::Error::OperationFailure)
|
|
387
|
+
end
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
end
|
|
@@ -208,6 +208,72 @@ describe Mongoid::Clients do
|
|
|
208
208
|
end
|
|
209
209
|
|
|
210
210
|
it_behaves_like "an overridden collection name at the class level"
|
|
211
|
+
|
|
212
|
+
context 'when nesting #with calls' do
|
|
213
|
+
let(:instance_collection_name) do
|
|
214
|
+
Band.with(collection: "ignore") do |klass|
|
|
215
|
+
Band.with(collection: "artists") do |klass|
|
|
216
|
+
klass.new.collection_name
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
let(:class_collection_name) do
|
|
222
|
+
Band.with(collection: "ignore") do |klass|
|
|
223
|
+
Band.with(collection: "artists") do |klass|
|
|
224
|
+
klass.collection_name
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
context 'when outer #with call specifies the collection' do
|
|
233
|
+
use_spec_mongoid_config
|
|
234
|
+
|
|
235
|
+
let(:instance_collection_name) do
|
|
236
|
+
Band.with(collection: "artists") do |klass|
|
|
237
|
+
Band.with(client: :reports) do |klass|
|
|
238
|
+
klass.new.collection_name
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
let(:class_collection_name) do
|
|
244
|
+
Band.with(collection: "artists") do |klass|
|
|
245
|
+
Band.with(client: :reports) do |klass|
|
|
246
|
+
klass.collection_name
|
|
247
|
+
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context 'restores outer context in outer block' do
|
|
255
|
+
use_spec_mongoid_config
|
|
256
|
+
|
|
257
|
+
let(:instance_collection_name) do
|
|
258
|
+
Band.with(collection: "artists") do |klass|
|
|
259
|
+
Band.with(collection: "scratch") do |klass|
|
|
260
|
+
# nothing
|
|
261
|
+
end
|
|
262
|
+
klass.new.collection_name
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
let(:class_collection_name) do
|
|
267
|
+
Band.with(collection: "artists") do |klass|
|
|
268
|
+
Band.with(collection: "scratch") do |klass|
|
|
269
|
+
# nothing
|
|
270
|
+
end
|
|
271
|
+
klass.collection_name
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it_behaves_like "an overridden collection name at the class level"
|
|
276
|
+
end
|
|
211
277
|
end
|
|
212
278
|
|
|
213
279
|
context "when overriding store_in and persistence options" do
|
|
@@ -427,7 +493,7 @@ describe Mongoid::Clients do
|
|
|
427
493
|
let(:client_name) { :alternative }
|
|
428
494
|
|
|
429
495
|
before do
|
|
430
|
-
Mongoid.clients[client_name] = { database: database_id_alt, hosts:
|
|
496
|
+
Mongoid.clients[client_name] = { database: database_id_alt, hosts: SpecConfig.instance.addresses }
|
|
431
497
|
end
|
|
432
498
|
|
|
433
499
|
after do
|
|
@@ -552,20 +618,14 @@ describe Mongoid::Clients do
|
|
|
552
618
|
end
|
|
553
619
|
|
|
554
620
|
context "when getting a client by name" do
|
|
555
|
-
|
|
556
|
-
let(:file) do
|
|
557
|
-
File.join(File.dirname(__FILE__), "..", "config", "mongoid.yml")
|
|
558
|
-
end
|
|
621
|
+
use_spec_mongoid_config
|
|
559
622
|
|
|
560
623
|
before do
|
|
561
|
-
described_class.clear
|
|
562
|
-
Mongoid.load!(file, :test)
|
|
563
624
|
Band.store_in(client: :reports)
|
|
564
625
|
end
|
|
565
626
|
|
|
566
627
|
after do
|
|
567
628
|
mongo_client.close
|
|
568
|
-
Mongoid::Config.reset
|
|
569
629
|
Band.reset_storage_options!
|
|
570
630
|
end
|
|
571
631
|
|
|
@@ -665,7 +725,7 @@ describe Mongoid::Clients do
|
|
|
665
725
|
end
|
|
666
726
|
end
|
|
667
727
|
|
|
668
|
-
describe ".store_in"
|
|
728
|
+
describe ".store_in" do
|
|
669
729
|
|
|
670
730
|
context "when provided a non hash" do
|
|
671
731
|
|
|
@@ -702,7 +762,7 @@ describe Mongoid::Clients do
|
|
|
702
762
|
end
|
|
703
763
|
end
|
|
704
764
|
|
|
705
|
-
describe ".with"
|
|
765
|
+
describe ".with" do
|
|
706
766
|
|
|
707
767
|
context "when changing write concern options" do
|
|
708
768
|
|
data/spec/mongoid/config_spec.rb
CHANGED
|
@@ -88,6 +88,30 @@ describe Mongoid::Config do
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
+
context 'when background_indexing option' do
|
|
92
|
+
context 'is not set in the config' do
|
|
93
|
+
it 'sets the value to false by default' do
|
|
94
|
+
Mongoid::Config.reset
|
|
95
|
+
configuration = CONFIG.merge(options: {})
|
|
96
|
+
|
|
97
|
+
Mongoid.configure { |config| config.load_configuration(configuration) }
|
|
98
|
+
|
|
99
|
+
expect(Mongoid::Config.background_indexing).to be(false)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context 'is set in the config' do
|
|
104
|
+
it 'sets the value' do
|
|
105
|
+
Mongoid::Config.reset
|
|
106
|
+
configuration = CONFIG.merge(options: {background_indexing: true})
|
|
107
|
+
|
|
108
|
+
Mongoid.configure { |config| config.load_configuration(configuration) }
|
|
109
|
+
|
|
110
|
+
expect(Mongoid::Config.background_indexing).to be(true)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
91
115
|
context 'when the belongs_to_required_by_default option is not set in the config' do
|
|
92
116
|
|
|
93
117
|
before do
|
|
@@ -346,7 +370,9 @@ describe Mongoid::Config do
|
|
|
346
370
|
end
|
|
347
371
|
|
|
348
372
|
it "sets the default hosts" do
|
|
349
|
-
expect(default[:hosts]).to eq(
|
|
373
|
+
expect(default[:hosts]).to eq(SpecConfig.instance.addresses)
|
|
374
|
+
# and make sure the value is not empty
|
|
375
|
+
expect(default[:hosts].first).to include(':')
|
|
350
376
|
end
|
|
351
377
|
|
|
352
378
|
context "when the default has options" do
|
|
@@ -74,7 +74,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
74
74
|
end
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
-
context 'when the criteria has a collation'
|
|
77
|
+
context 'when the criteria has a collation' do
|
|
78
|
+
min_server_version '3.4'
|
|
78
79
|
|
|
79
80
|
let(:criteria) do
|
|
80
81
|
Band.where(members: [ "DAVE" ]).collation(locale: 'en_US', strength: 2)
|
|
@@ -145,7 +146,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
145
146
|
end
|
|
146
147
|
end
|
|
147
148
|
|
|
148
|
-
context 'when the criteria has a collation'
|
|
149
|
+
context 'when the criteria has a collation' do
|
|
150
|
+
min_server_version '3.4'
|
|
149
151
|
|
|
150
152
|
let!(:depeche_mode) do
|
|
151
153
|
Band.create(members: [ "Dave" ], likes: 60)
|
|
@@ -224,7 +226,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
224
226
|
end
|
|
225
227
|
end
|
|
226
228
|
|
|
227
|
-
context 'when the criteria has a collation'
|
|
229
|
+
context 'when the criteria has a collation' do
|
|
230
|
+
min_server_version '3.4'
|
|
228
231
|
|
|
229
232
|
let!(:depeche_mode) do
|
|
230
233
|
Band.create(members: [ "Dave" ])
|
|
@@ -296,7 +299,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
296
299
|
end
|
|
297
300
|
end
|
|
298
301
|
|
|
299
|
-
context 'when the criteria has a collation'
|
|
302
|
+
context 'when the criteria has a collation' do
|
|
303
|
+
min_server_version '3.4'
|
|
300
304
|
|
|
301
305
|
let!(:depeche_mode) do
|
|
302
306
|
Band.create(members: [ "Dave" ])
|
|
@@ -350,7 +354,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
350
354
|
expect(smiths.reload.members).to be_nil
|
|
351
355
|
end
|
|
352
356
|
|
|
353
|
-
context 'when the criteria has a collation'
|
|
357
|
+
context 'when the criteria has a collation' do
|
|
358
|
+
min_server_version '3.4'
|
|
354
359
|
|
|
355
360
|
let!(:depeche_mode) do
|
|
356
361
|
Band.create(members: [ "Dave" ])
|
|
@@ -407,7 +412,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
407
412
|
end
|
|
408
413
|
end
|
|
409
414
|
|
|
410
|
-
context 'when the criteria has a collation'
|
|
415
|
+
context 'when the criteria has a collation' do
|
|
416
|
+
min_server_version '3.4'
|
|
411
417
|
|
|
412
418
|
let!(:depeche_mode) do
|
|
413
419
|
Band.create(members: [ "Dave", "Alan", "Fletch" ])
|
|
@@ -464,7 +470,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
464
470
|
end
|
|
465
471
|
end
|
|
466
472
|
|
|
467
|
-
context 'when the criteria has a collation'
|
|
473
|
+
context 'when the criteria has a collation' do
|
|
474
|
+
min_server_version '3.4'
|
|
468
475
|
|
|
469
476
|
let!(:depeche_mode) do
|
|
470
477
|
Band.create(members: [ "Dave" ])
|
|
@@ -529,7 +536,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
529
536
|
end
|
|
530
537
|
end
|
|
531
538
|
|
|
532
|
-
context 'when the criteria has a collation'
|
|
539
|
+
context 'when the criteria has a collation' do
|
|
540
|
+
min_server_version '3.4'
|
|
533
541
|
|
|
534
542
|
let!(:depeche_mode) do
|
|
535
543
|
Band.create(members: [ "Dave" ])
|
|
@@ -590,7 +598,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
590
598
|
end
|
|
591
599
|
end
|
|
592
600
|
|
|
593
|
-
context 'when the criteria has a collation'
|
|
601
|
+
context 'when the criteria has a collation' do
|
|
602
|
+
min_server_version '3.4'
|
|
594
603
|
|
|
595
604
|
let!(:depeche_mode) do
|
|
596
605
|
Band.create(members: [ "Dave" ])
|
|
@@ -644,12 +653,25 @@ describe Mongoid::Contextual::Atomic do
|
|
|
644
653
|
context.set(name: "Recoil")
|
|
645
654
|
end
|
|
646
655
|
|
|
647
|
-
|
|
648
|
-
|
|
656
|
+
shared_examples 'writes as expected' do
|
|
657
|
+
it "sets existing fields" do
|
|
658
|
+
expect(depeche_mode.reload.name).to eq("Recoil")
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
it "sets non existent fields" do
|
|
662
|
+
expect(smiths.reload.name).to eq("Recoil")
|
|
663
|
+
end
|
|
649
664
|
end
|
|
650
665
|
|
|
651
|
-
|
|
652
|
-
|
|
666
|
+
include_examples 'writes as expected'
|
|
667
|
+
|
|
668
|
+
context 'when fields being set have been projected out' do
|
|
669
|
+
|
|
670
|
+
let(:criteria) do
|
|
671
|
+
Band.only(:genres)
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
include_examples 'writes as expected'
|
|
653
675
|
end
|
|
654
676
|
end
|
|
655
677
|
|
|
@@ -749,7 +771,8 @@ describe Mongoid::Contextual::Atomic do
|
|
|
749
771
|
end
|
|
750
772
|
end
|
|
751
773
|
|
|
752
|
-
context 'when the criteria has a collation'
|
|
774
|
+
context 'when the criteria has a collation' do
|
|
775
|
+
min_server_version '3.4'
|
|
753
776
|
|
|
754
777
|
let!(:depeche_mode) do
|
|
755
778
|
Band.create(name: "Depeche Mode", years: 10)
|
|
@@ -46,8 +46,17 @@ describe Mongoid::Contextual::GeoNear do
|
|
|
46
46
|
described_class.new(collection, criteria, [ 52, 13 ])
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
let(:expected_value) do
|
|
50
|
+
if ClusterConfig.instance.fcv_ish == '4.0' && ClusterConfig.instance.topology == :sharded
|
|
51
|
+
# https://jira.mongodb.org/browse/SERVER-50074
|
|
52
|
+
0.0
|
|
53
|
+
else
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "is nil except for 4.0 sharded when it is 0" do
|
|
59
|
+
expect(geo_near.average_distance).to be expected_value
|
|
51
60
|
end
|
|
52
61
|
end
|
|
53
62
|
end
|