mongoid 9.0.11 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -0
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +34 -38
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +18 -13
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -66
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -14
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +1 -3
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +132 -42
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +72 -65
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -2
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -72
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +26 -25
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +0 -2
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +11 -14
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -15
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -41
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +330 -0
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +28 -30
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -32
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -178
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +104 -119
- data/spec/integration/encryption_spec.rb +8 -11
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -31
- data/spec/mongoid/config/encryption_spec.rb +54 -57
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -854
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -950
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -80
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -8
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -2
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
5
|
-
require_relative '
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require_relative 'has_one_models'
|
|
6
5
|
|
|
7
6
|
BELONGS_TO_RESOLVER_ID__ = :__belongs_to_resolver_id
|
|
8
7
|
BELONGS_TO_RESOLVER = Mongoid::ModelResolver.new
|
|
9
8
|
Mongoid::ModelResolver.register_resolver BELONGS_TO_RESOLVER, BELONGS_TO_RESOLVER_ID__
|
|
10
9
|
|
|
11
10
|
describe Mongoid::Association::Referenced::BelongsTo do
|
|
12
|
-
|
|
13
11
|
before do
|
|
14
12
|
class OwnerObject; include Mongoid::Document; end
|
|
15
13
|
class BelongingObject; include Mongoid::Document; end
|
|
@@ -33,15 +31,14 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
let(:options) do
|
|
36
|
-
{
|
|
34
|
+
{}
|
|
37
35
|
end
|
|
38
36
|
|
|
39
37
|
describe '#relation_complements' do
|
|
40
|
-
|
|
41
38
|
let(:expected_complements) do
|
|
42
39
|
[
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
Mongoid::Association::Referenced::HasMany,
|
|
41
|
+
Mongoid::Association::Referenced::HasOne
|
|
45
42
|
]
|
|
46
43
|
end
|
|
47
44
|
|
|
@@ -51,7 +48,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
51
48
|
end
|
|
52
49
|
|
|
53
50
|
describe '#setup!' do
|
|
54
|
-
|
|
55
51
|
it 'sets up a getter for the relation' do
|
|
56
52
|
expect(Mongoid::Association::Accessors).to receive(:define_getter!).with(association)
|
|
57
53
|
association.setup!
|
|
@@ -78,12 +74,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
78
74
|
end
|
|
79
75
|
|
|
80
76
|
context 'autosave' do
|
|
81
|
-
|
|
82
77
|
context 'when the :autosave option is true' do
|
|
83
|
-
|
|
84
78
|
let(:options) do
|
|
85
79
|
{
|
|
86
|
-
|
|
80
|
+
autosave: true
|
|
87
81
|
}
|
|
88
82
|
end
|
|
89
83
|
|
|
@@ -100,10 +94,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
100
94
|
end
|
|
101
95
|
|
|
102
96
|
context 'when the :autosave option is false' do
|
|
103
|
-
|
|
104
97
|
let(:options) do
|
|
105
98
|
{
|
|
106
|
-
|
|
99
|
+
autosave: false
|
|
107
100
|
}
|
|
108
101
|
end
|
|
109
102
|
|
|
@@ -114,7 +107,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
114
107
|
end
|
|
115
108
|
|
|
116
109
|
context 'when the :autosave option is not provided' do
|
|
117
|
-
|
|
118
110
|
let(:association) do
|
|
119
111
|
# Note that it is necessary to create the association directly, otherwise the
|
|
120
112
|
# setup!! method will be called by the :embeds_many macro
|
|
@@ -129,12 +121,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
129
121
|
end
|
|
130
122
|
|
|
131
123
|
context 'counter cache callbacks' do
|
|
132
|
-
|
|
133
124
|
context 'when the :counter_cache option is true' do
|
|
134
|
-
|
|
135
125
|
let(:options) do
|
|
136
126
|
{
|
|
137
|
-
|
|
127
|
+
counter_cache: true
|
|
138
128
|
}
|
|
139
129
|
end
|
|
140
130
|
|
|
@@ -151,10 +141,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
151
141
|
end
|
|
152
142
|
|
|
153
143
|
context 'when the :counter_cache option is a String' do
|
|
154
|
-
|
|
155
144
|
let(:options) do
|
|
156
145
|
{
|
|
157
|
-
|
|
146
|
+
counter_cache: 'counts_field'
|
|
158
147
|
}
|
|
159
148
|
end
|
|
160
149
|
|
|
@@ -171,10 +160,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
171
160
|
end
|
|
172
161
|
|
|
173
162
|
context 'when the :counter_cache option is false' do
|
|
174
|
-
|
|
175
163
|
let(:options) do
|
|
176
164
|
{
|
|
177
|
-
|
|
165
|
+
counter_cache: false
|
|
178
166
|
}
|
|
179
167
|
end
|
|
180
168
|
|
|
@@ -185,7 +173,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
185
173
|
end
|
|
186
174
|
|
|
187
175
|
context 'when the :counter_cache option is not provided' do
|
|
188
|
-
|
|
189
176
|
let(:association) do
|
|
190
177
|
# Note that it is necessary to create the association directly, otherwise the
|
|
191
178
|
# setup! method will be called by the :embeds_many macro
|
|
@@ -200,12 +187,11 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
200
187
|
end
|
|
201
188
|
|
|
202
189
|
context 'polymorphic' do
|
|
203
|
-
|
|
204
190
|
context 'when the polymorphic option is provided' do
|
|
205
|
-
|
|
206
191
|
[ true, :default ].each do |opt|
|
|
207
192
|
context "when the polymorphic option is #{opt.inspect}" do
|
|
208
193
|
let(:options) { { polymorphic: opt } }
|
|
194
|
+
|
|
209
195
|
before { association }
|
|
210
196
|
|
|
211
197
|
it 'set the polymorphic attribute on the owner class' do
|
|
@@ -217,7 +203,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
217
203
|
end
|
|
218
204
|
|
|
219
205
|
it 'uses the default resolver' do
|
|
220
|
-
expect(association.resolver).to
|
|
206
|
+
expect(association.resolver).to eq Mongoid::ModelResolver.instance
|
|
221
207
|
end
|
|
222
208
|
end
|
|
223
209
|
end
|
|
@@ -256,6 +242,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
256
242
|
|
|
257
243
|
context 'when the polymorphic option is set to a registered id' do
|
|
258
244
|
let(:options) { { polymorphic: BELONGS_TO_RESOLVER_ID__ } }
|
|
245
|
+
|
|
259
246
|
before { association }
|
|
260
247
|
|
|
261
248
|
it 'set the polymorphic attribute on the owner class' do
|
|
@@ -267,7 +254,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
267
254
|
end
|
|
268
255
|
|
|
269
256
|
it 'connects the association to the corresponding resolver' do
|
|
270
|
-
expect(association.resolver).to
|
|
257
|
+
expect(association.resolver).to eq BELONGS_TO_RESOLVER
|
|
271
258
|
end
|
|
272
259
|
end
|
|
273
260
|
end
|
|
@@ -288,11 +275,8 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
288
275
|
end
|
|
289
276
|
|
|
290
277
|
context 'dependent' do
|
|
291
|
-
|
|
292
278
|
context 'when the dependent option is provided' do
|
|
293
|
-
|
|
294
279
|
context 'when the dependent option is :delete_all' do
|
|
295
|
-
|
|
296
280
|
let(:options) do
|
|
297
281
|
{
|
|
298
282
|
dependent: :delete_all
|
|
@@ -312,10 +296,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
312
296
|
end
|
|
313
297
|
|
|
314
298
|
context 'when the dependent option is :destroy' do
|
|
315
|
-
|
|
316
299
|
let(:options) do
|
|
317
300
|
{
|
|
318
|
-
|
|
301
|
+
dependent: :destroy
|
|
319
302
|
}
|
|
320
303
|
end
|
|
321
304
|
|
|
@@ -332,10 +315,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
332
315
|
end
|
|
333
316
|
|
|
334
317
|
context 'when the dependent option is :nullify' do
|
|
335
|
-
|
|
336
318
|
let(:options) do
|
|
337
319
|
{
|
|
338
|
-
|
|
320
|
+
dependent: :nullify
|
|
339
321
|
}
|
|
340
322
|
end
|
|
341
323
|
|
|
@@ -352,10 +334,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
352
334
|
end
|
|
353
335
|
|
|
354
336
|
context 'when the dependent option is :restrict_with_exception' do
|
|
355
|
-
|
|
356
337
|
let(:options) do
|
|
357
338
|
{
|
|
358
|
-
|
|
339
|
+
dependent: :restrict_with_exception
|
|
359
340
|
}
|
|
360
341
|
end
|
|
361
342
|
|
|
@@ -372,10 +353,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
372
353
|
end
|
|
373
354
|
|
|
374
355
|
context 'when the dependent option is :restrict_with_error' do
|
|
375
|
-
|
|
376
356
|
let(:options) do
|
|
377
357
|
{
|
|
378
|
-
|
|
358
|
+
dependent: :restrict_with_error
|
|
379
359
|
}
|
|
380
360
|
end
|
|
381
361
|
|
|
@@ -393,7 +373,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
393
373
|
end
|
|
394
374
|
|
|
395
375
|
context 'when the dependent option is not provided' do
|
|
396
|
-
|
|
397
376
|
it 'does not set up the dependency' do
|
|
398
377
|
expect(Mongoid::Association::Depending).not_to receive(:define_dependency!)
|
|
399
378
|
association.setup!
|
|
@@ -402,7 +381,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
402
381
|
end
|
|
403
382
|
|
|
404
383
|
context 'foreign key field' do
|
|
405
|
-
|
|
406
384
|
before do
|
|
407
385
|
association
|
|
408
386
|
end
|
|
@@ -413,73 +391,64 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
413
391
|
end
|
|
414
392
|
|
|
415
393
|
context 'index' do
|
|
416
|
-
|
|
417
394
|
before do
|
|
418
395
|
association
|
|
419
396
|
end
|
|
420
397
|
|
|
421
398
|
context 'when index is true' do
|
|
422
|
-
|
|
423
399
|
context 'when polymorphic' do
|
|
424
|
-
|
|
425
400
|
let(:options) do
|
|
426
401
|
{
|
|
427
|
-
|
|
428
|
-
|
|
402
|
+
polymorphic: true,
|
|
403
|
+
index: true
|
|
429
404
|
}
|
|
430
405
|
end
|
|
431
406
|
|
|
432
407
|
it 'sets up the index with the key and inverse type' do
|
|
433
|
-
expect(belonging_class.index_specifications.first.fields).to
|
|
434
|
-
|
|
408
|
+
expect(belonging_class.index_specifications.first.fields).to contain_exactly(association.key.to_sym,
|
|
409
|
+
association.inverse_type.to_sym)
|
|
435
410
|
end
|
|
436
411
|
end
|
|
437
412
|
|
|
438
413
|
context 'when not polymorphic' do
|
|
439
|
-
|
|
440
414
|
let(:options) do
|
|
441
415
|
{
|
|
442
|
-
|
|
416
|
+
index: true
|
|
443
417
|
}
|
|
444
418
|
end
|
|
445
419
|
|
|
446
420
|
it 'sets up the index with the key' do
|
|
447
|
-
expect(belonging_class.index_specifications.first.fields).to
|
|
421
|
+
expect(belonging_class.index_specifications.first.fields).to contain_exactly(association.key.to_sym)
|
|
448
422
|
end
|
|
449
423
|
end
|
|
450
424
|
end
|
|
451
425
|
|
|
452
426
|
context 'when index is false' do
|
|
453
|
-
|
|
454
427
|
context 'when polymorphic' do
|
|
455
|
-
|
|
456
428
|
let(:options) do
|
|
457
429
|
{
|
|
458
|
-
|
|
430
|
+
polymorphic: true
|
|
459
431
|
}
|
|
460
432
|
end
|
|
461
433
|
|
|
462
434
|
it 'does not set up an index' do
|
|
463
|
-
expect(belonging_class.index_specifications).to eq([
|
|
435
|
+
expect(belonging_class.index_specifications).to eq([])
|
|
464
436
|
end
|
|
465
437
|
end
|
|
466
438
|
|
|
467
439
|
context 'when not polymorphic' do
|
|
468
|
-
|
|
469
440
|
it 'does not set up an index' do
|
|
470
|
-
expect(belonging_class.index_specifications).to eq([
|
|
441
|
+
expect(belonging_class.index_specifications).to eq([])
|
|
471
442
|
end
|
|
472
443
|
end
|
|
473
444
|
end
|
|
474
445
|
end
|
|
475
446
|
|
|
476
447
|
context 'touchable' do
|
|
477
|
-
|
|
478
448
|
context 'when the :touch option is true' do
|
|
479
|
-
|
|
480
449
|
let(:options) do
|
|
481
450
|
{
|
|
482
|
-
|
|
451
|
+
touch: true
|
|
483
452
|
}
|
|
484
453
|
end
|
|
485
454
|
|
|
@@ -496,10 +465,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
496
465
|
end
|
|
497
466
|
|
|
498
467
|
context 'when the :touch option is false' do
|
|
499
|
-
|
|
500
468
|
let(:options) do
|
|
501
469
|
{
|
|
502
|
-
|
|
470
|
+
touch: false
|
|
503
471
|
}
|
|
504
472
|
end
|
|
505
473
|
|
|
@@ -510,7 +478,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
510
478
|
end
|
|
511
479
|
|
|
512
480
|
context 'when the :touch option is not provided' do
|
|
513
|
-
|
|
514
481
|
let(:association) do
|
|
515
482
|
# Note that it is necessary to create the association directly, otherwise the
|
|
516
483
|
# setup! method will be called by the :embeds_many macro
|
|
@@ -525,12 +492,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
525
492
|
end
|
|
526
493
|
|
|
527
494
|
context 'validate' do
|
|
528
|
-
|
|
529
495
|
context 'when the :validate option is true' do
|
|
530
|
-
|
|
531
496
|
let(:options) do
|
|
532
497
|
{
|
|
533
|
-
|
|
498
|
+
validate: true
|
|
534
499
|
}
|
|
535
500
|
end
|
|
536
501
|
|
|
@@ -547,10 +512,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
547
512
|
end
|
|
548
513
|
|
|
549
514
|
context 'when the :validate option is false' do
|
|
550
|
-
|
|
551
515
|
let(:options) do
|
|
552
516
|
{
|
|
553
|
-
|
|
517
|
+
validate: false
|
|
554
518
|
}
|
|
555
519
|
end
|
|
556
520
|
|
|
@@ -561,7 +525,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
561
525
|
end
|
|
562
526
|
|
|
563
527
|
context 'when the :validate option is not provided' do
|
|
564
|
-
|
|
565
528
|
let(:association) do
|
|
566
529
|
# Note that it is necessary to create the association directly, otherwise the
|
|
567
530
|
# setup! method will be called by the :belongs_to macro
|
|
@@ -576,7 +539,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
576
539
|
end
|
|
577
540
|
|
|
578
541
|
context 'presence of validation' do
|
|
579
|
-
|
|
580
542
|
let(:association) do
|
|
581
543
|
# Note that it is necessary to create the association directly, otherwise the
|
|
582
544
|
# setup! method will be called by the :belongs_to macro
|
|
@@ -587,10 +549,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
587
549
|
config_override :belongs_to_required_by_default, true
|
|
588
550
|
|
|
589
551
|
context 'when the required option is true' do
|
|
590
|
-
|
|
591
552
|
let(:options) do
|
|
592
553
|
{
|
|
593
|
-
|
|
554
|
+
required: true
|
|
594
555
|
}
|
|
595
556
|
end
|
|
596
557
|
|
|
@@ -600,11 +561,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
600
561
|
end
|
|
601
562
|
|
|
602
563
|
context 'when the optional option is true' do
|
|
603
|
-
|
|
604
564
|
let(:options) do
|
|
605
565
|
{
|
|
606
|
-
|
|
607
|
-
|
|
566
|
+
required: true,
|
|
567
|
+
optional: true
|
|
608
568
|
}
|
|
609
569
|
end
|
|
610
570
|
|
|
@@ -615,11 +575,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
615
575
|
end
|
|
616
576
|
|
|
617
577
|
context 'when the optional option is false' do
|
|
618
|
-
|
|
619
578
|
let(:options) do
|
|
620
579
|
{
|
|
621
|
-
|
|
622
|
-
|
|
580
|
+
required: true,
|
|
581
|
+
optional: false
|
|
623
582
|
}
|
|
624
583
|
end
|
|
625
584
|
|
|
@@ -631,10 +590,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
631
590
|
end
|
|
632
591
|
|
|
633
592
|
context 'when the required option is false' do
|
|
634
|
-
|
|
635
593
|
let(:options) do
|
|
636
594
|
{
|
|
637
|
-
|
|
595
|
+
required: false
|
|
638
596
|
}
|
|
639
597
|
end
|
|
640
598
|
|
|
@@ -644,11 +602,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
644
602
|
end
|
|
645
603
|
|
|
646
604
|
context 'when the optional option is true' do
|
|
647
|
-
|
|
648
605
|
let(:options) do
|
|
649
606
|
{
|
|
650
|
-
|
|
651
|
-
|
|
607
|
+
required: false,
|
|
608
|
+
optional: true
|
|
652
609
|
}
|
|
653
610
|
end
|
|
654
611
|
|
|
@@ -659,11 +616,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
659
616
|
end
|
|
660
617
|
|
|
661
618
|
context 'when the optional option is false' do
|
|
662
|
-
|
|
663
619
|
let(:options) do
|
|
664
620
|
{
|
|
665
|
-
|
|
666
|
-
|
|
621
|
+
required: false,
|
|
622
|
+
optional: false
|
|
667
623
|
}
|
|
668
624
|
end
|
|
669
625
|
|
|
@@ -675,17 +631,15 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
675
631
|
end
|
|
676
632
|
|
|
677
633
|
context 'when the required option is not provided' do
|
|
678
|
-
|
|
679
634
|
it 'uses the default and sets up the presence of validation' do
|
|
680
635
|
expect(belonging_class).to receive(:validates).with(name, { presence: true }).and_call_original
|
|
681
636
|
association.setup!
|
|
682
637
|
end
|
|
683
638
|
|
|
684
639
|
context 'when the optional option is true' do
|
|
685
|
-
|
|
686
640
|
let(:options) do
|
|
687
641
|
{
|
|
688
|
-
|
|
642
|
+
optional: true
|
|
689
643
|
}
|
|
690
644
|
end
|
|
691
645
|
|
|
@@ -696,10 +650,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
696
650
|
end
|
|
697
651
|
|
|
698
652
|
context 'when the optional option is false' do
|
|
699
|
-
|
|
700
653
|
let(:options) do
|
|
701
654
|
{
|
|
702
|
-
|
|
655
|
+
optional: false
|
|
703
656
|
}
|
|
704
657
|
end
|
|
705
658
|
|
|
@@ -715,10 +668,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
715
668
|
config_override :belongs_to_required_by_default, false
|
|
716
669
|
|
|
717
670
|
context 'when the required option is true' do
|
|
718
|
-
|
|
719
671
|
let(:options) do
|
|
720
672
|
{
|
|
721
|
-
|
|
673
|
+
required: true
|
|
722
674
|
}
|
|
723
675
|
end
|
|
724
676
|
|
|
@@ -728,11 +680,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
728
680
|
end
|
|
729
681
|
|
|
730
682
|
context 'when the optional option is true' do
|
|
731
|
-
|
|
732
683
|
let(:options) do
|
|
733
684
|
{
|
|
734
|
-
|
|
735
|
-
|
|
685
|
+
required: true,
|
|
686
|
+
optional: true
|
|
736
687
|
}
|
|
737
688
|
end
|
|
738
689
|
|
|
@@ -743,11 +694,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
743
694
|
end
|
|
744
695
|
|
|
745
696
|
context 'when the optional option is false' do
|
|
746
|
-
|
|
747
697
|
let(:options) do
|
|
748
698
|
{
|
|
749
|
-
|
|
750
|
-
|
|
699
|
+
required: true,
|
|
700
|
+
optional: false
|
|
751
701
|
}
|
|
752
702
|
end
|
|
753
703
|
|
|
@@ -759,10 +709,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
759
709
|
end
|
|
760
710
|
|
|
761
711
|
context 'when the required option is false' do
|
|
762
|
-
|
|
763
712
|
let(:options) do
|
|
764
713
|
{
|
|
765
|
-
|
|
714
|
+
required: false
|
|
766
715
|
}
|
|
767
716
|
end
|
|
768
717
|
|
|
@@ -772,11 +721,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
772
721
|
end
|
|
773
722
|
|
|
774
723
|
context 'when the optional option is true' do
|
|
775
|
-
|
|
776
724
|
let(:options) do
|
|
777
725
|
{
|
|
778
|
-
|
|
779
|
-
|
|
726
|
+
required: false,
|
|
727
|
+
optional: true
|
|
780
728
|
}
|
|
781
729
|
end
|
|
782
730
|
|
|
@@ -787,11 +735,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
787
735
|
end
|
|
788
736
|
|
|
789
737
|
context 'when the optional option is false' do
|
|
790
|
-
|
|
791
738
|
let(:options) do
|
|
792
739
|
{
|
|
793
|
-
|
|
794
|
-
|
|
740
|
+
required: false,
|
|
741
|
+
optional: false
|
|
795
742
|
}
|
|
796
743
|
end
|
|
797
744
|
|
|
@@ -803,17 +750,15 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
803
750
|
end
|
|
804
751
|
|
|
805
752
|
context 'when the required option is not provided' do
|
|
806
|
-
|
|
807
753
|
it 'uses the default and does not set up the presence of validation' do
|
|
808
754
|
expect(belonging_class).not_to receive(:validates)
|
|
809
755
|
association.setup!
|
|
810
756
|
end
|
|
811
757
|
|
|
812
758
|
context 'when the optional option is true' do
|
|
813
|
-
|
|
814
759
|
let(:options) do
|
|
815
760
|
{
|
|
816
|
-
|
|
761
|
+
optional: true
|
|
817
762
|
}
|
|
818
763
|
end
|
|
819
764
|
|
|
@@ -824,10 +769,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
824
769
|
end
|
|
825
770
|
|
|
826
771
|
context 'when the optional option is false' do
|
|
827
|
-
|
|
828
772
|
let(:options) do
|
|
829
773
|
{
|
|
830
|
-
|
|
774
|
+
optional: false
|
|
831
775
|
}
|
|
832
776
|
end
|
|
833
777
|
|
|
@@ -842,9 +786,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
842
786
|
end
|
|
843
787
|
|
|
844
788
|
describe '#type' do
|
|
845
|
-
|
|
846
789
|
context 'when polymorphic' do
|
|
847
|
-
|
|
848
790
|
let(:options) do
|
|
849
791
|
{ polymorphic: true }
|
|
850
792
|
end
|
|
@@ -855,7 +797,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
855
797
|
end
|
|
856
798
|
|
|
857
799
|
context 'when not polymorphic' do
|
|
858
|
-
|
|
859
800
|
it 'returns nil' do
|
|
860
801
|
expect(association.type).to be_nil
|
|
861
802
|
end
|
|
@@ -863,9 +804,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
863
804
|
end
|
|
864
805
|
|
|
865
806
|
describe '#inverse_type' do
|
|
866
|
-
|
|
867
807
|
context 'when polymorphic' do
|
|
868
|
-
|
|
869
808
|
let(:options) do
|
|
870
809
|
{ polymorphic: true }
|
|
871
810
|
end
|
|
@@ -876,7 +815,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
876
815
|
end
|
|
877
816
|
|
|
878
817
|
context 'when not polymorphic' do
|
|
879
|
-
|
|
880
818
|
it 'returns nil' do
|
|
881
819
|
expect(association.inverse_type).to be_nil
|
|
882
820
|
end
|
|
@@ -884,9 +822,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
884
822
|
end
|
|
885
823
|
|
|
886
824
|
describe '#inverse_type_setter' do
|
|
887
|
-
|
|
888
825
|
context 'when polymorphic' do
|
|
889
|
-
|
|
890
826
|
let(:options) do
|
|
891
827
|
{ polymorphic: true }
|
|
892
828
|
end
|
|
@@ -897,7 +833,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
897
833
|
end
|
|
898
834
|
|
|
899
835
|
context 'when not polymorphic' do
|
|
900
|
-
|
|
901
836
|
it 'returns nil' do
|
|
902
837
|
expect(association.inverse_type_setter).to be_nil
|
|
903
838
|
end
|
|
@@ -905,9 +840,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
905
840
|
end
|
|
906
841
|
|
|
907
842
|
describe '#foreign_key' do
|
|
908
|
-
|
|
909
843
|
context 'when options has foreign_key specified' do
|
|
910
|
-
|
|
911
844
|
let(:options) do
|
|
912
845
|
{ foreign_key: :other_object_id }
|
|
913
846
|
end
|
|
@@ -918,7 +851,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
918
851
|
end
|
|
919
852
|
|
|
920
853
|
context 'when options does not have foreign_key specified' do
|
|
921
|
-
|
|
922
854
|
it 'returns the ame followed by "_id"' do
|
|
923
855
|
expect(association.foreign_key).to eq("#{name}_id")
|
|
924
856
|
end
|
|
@@ -926,21 +858,17 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
926
858
|
end
|
|
927
859
|
|
|
928
860
|
describe '#embedded?' do
|
|
929
|
-
|
|
930
861
|
it 'returns false' do
|
|
931
862
|
expect(association.embedded?).to be(false)
|
|
932
863
|
end
|
|
933
864
|
end
|
|
934
865
|
|
|
935
866
|
describe '#primary_key' do
|
|
936
|
-
|
|
937
867
|
context 'when the :primary_key option is specified' do
|
|
938
|
-
|
|
939
868
|
context 'when the :primary_key option is true' do
|
|
940
|
-
|
|
941
869
|
let(:options) do
|
|
942
870
|
{
|
|
943
|
-
|
|
871
|
+
primary_key: :other_primary_key
|
|
944
872
|
}
|
|
945
873
|
end
|
|
946
874
|
|
|
@@ -951,7 +879,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
951
879
|
end
|
|
952
880
|
|
|
953
881
|
context 'when the :primary_key option is not specified' do
|
|
954
|
-
|
|
955
882
|
it 'returns the default primary key' do
|
|
956
883
|
expect(association.primary_key).to eq(Mongoid::Association::Relatable::PRIMARY_KEY_DEFAULT)
|
|
957
884
|
end
|
|
@@ -959,14 +886,11 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
959
886
|
end
|
|
960
887
|
|
|
961
888
|
describe '#indexed?' do
|
|
962
|
-
|
|
963
889
|
context 'when :index is specified in the options' do
|
|
964
|
-
|
|
965
890
|
context 'when :index is true' do
|
|
966
|
-
|
|
967
891
|
let(:options) do
|
|
968
892
|
{
|
|
969
|
-
|
|
893
|
+
index: true
|
|
970
894
|
}
|
|
971
895
|
end
|
|
972
896
|
|
|
@@ -976,10 +900,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
976
900
|
end
|
|
977
901
|
|
|
978
902
|
context 'when :index is false' do
|
|
979
|
-
|
|
980
903
|
let(:options) do
|
|
981
904
|
{
|
|
982
|
-
|
|
905
|
+
index: false
|
|
983
906
|
}
|
|
984
907
|
end
|
|
985
908
|
|
|
@@ -990,7 +913,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
990
913
|
end
|
|
991
914
|
|
|
992
915
|
context 'when :index is not specified in the options' do
|
|
993
|
-
|
|
994
916
|
it 'returns nil' do
|
|
995
917
|
expect(association.indexed?).to be(false)
|
|
996
918
|
end
|
|
@@ -998,57 +920,48 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
998
920
|
end
|
|
999
921
|
|
|
1000
922
|
describe '#relation' do
|
|
1001
|
-
|
|
1002
923
|
it 'returns Mongoid::Association::Referenced::BelongsTo::Proxy' do
|
|
1003
924
|
expect(association.relation).to be(Mongoid::Association::Referenced::BelongsTo::Proxy)
|
|
1004
925
|
end
|
|
1005
926
|
end
|
|
1006
927
|
|
|
1007
928
|
describe '#validation_default' do
|
|
1008
|
-
|
|
1009
929
|
it 'returns false' do
|
|
1010
930
|
expect(association.validation_default).to be(false)
|
|
1011
931
|
end
|
|
1012
932
|
end
|
|
1013
933
|
|
|
1014
934
|
describe '#name' do
|
|
1015
|
-
|
|
1016
935
|
it 'returns the name of the relation' do
|
|
1017
936
|
expect(association.name).to be(name)
|
|
1018
937
|
end
|
|
1019
938
|
end
|
|
1020
939
|
|
|
1021
940
|
describe '#options' do
|
|
1022
|
-
|
|
1023
941
|
it 'returns the options' do
|
|
1024
942
|
expect(association.options).to be(options)
|
|
1025
943
|
end
|
|
1026
944
|
end
|
|
1027
945
|
|
|
1028
946
|
describe '#cyclic?' do
|
|
1029
|
-
|
|
1030
947
|
it 'returns false' do
|
|
1031
948
|
expect(association.cyclic?).to be(false)
|
|
1032
949
|
end
|
|
1033
950
|
end
|
|
1034
951
|
|
|
1035
952
|
describe '#merge!' do
|
|
1036
|
-
|
|
1037
953
|
end
|
|
1038
954
|
|
|
1039
955
|
describe '#store_as' do
|
|
1040
|
-
|
|
1041
956
|
it 'returns nil' do
|
|
1042
957
|
expect(association.store_as).to be_nil
|
|
1043
958
|
end
|
|
1044
959
|
end
|
|
1045
960
|
|
|
1046
961
|
describe '#touchable?' do
|
|
1047
|
-
|
|
1048
962
|
context 'when :touch is in the options' do
|
|
1049
|
-
|
|
1050
963
|
let(:options) do
|
|
1051
|
-
{ touch: true}
|
|
964
|
+
{ touch: true }
|
|
1052
965
|
end
|
|
1053
966
|
|
|
1054
967
|
it 'returns true' do
|
|
@@ -1057,7 +970,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1057
970
|
end
|
|
1058
971
|
|
|
1059
972
|
context 'when :touch is not in the options' do
|
|
1060
|
-
|
|
1061
973
|
it 'return false' do
|
|
1062
974
|
expect(association.send(:touchable?)).to be(false)
|
|
1063
975
|
end
|
|
@@ -1065,16 +977,13 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1065
977
|
end
|
|
1066
978
|
|
|
1067
979
|
describe '#order' do
|
|
1068
|
-
|
|
1069
980
|
it 'returns nil' do
|
|
1070
981
|
expect(association.order).to be_nil
|
|
1071
982
|
end
|
|
1072
983
|
end
|
|
1073
984
|
|
|
1074
985
|
describe '#scope' do
|
|
1075
|
-
|
|
1076
986
|
context 'when scope is specified in the options' do
|
|
1077
|
-
|
|
1078
987
|
let(:options) do
|
|
1079
988
|
{ scope: -> { unscoped.where(foo: :bar) } }
|
|
1080
989
|
end
|
|
@@ -1085,7 +994,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1085
994
|
end
|
|
1086
995
|
|
|
1087
996
|
context 'when scope is not specified in the options' do
|
|
1088
|
-
|
|
1089
997
|
it 'returns nil' do
|
|
1090
998
|
expect(association.scope).to be_nil
|
|
1091
999
|
end
|
|
@@ -1093,16 +1001,13 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1093
1001
|
end
|
|
1094
1002
|
|
|
1095
1003
|
describe '#as' do
|
|
1096
|
-
|
|
1097
1004
|
it 'returns nil' do
|
|
1098
1005
|
expect(association.as).to be_nil
|
|
1099
1006
|
end
|
|
1100
1007
|
end
|
|
1101
1008
|
|
|
1102
1009
|
describe '#polymorphic?' do
|
|
1103
|
-
|
|
1104
1010
|
context 'when :polymorphic is specified in the options as true' do
|
|
1105
|
-
|
|
1106
1011
|
let(:options) do
|
|
1107
1012
|
{ polymorphic: true }
|
|
1108
1013
|
end
|
|
@@ -1113,7 +1018,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1113
1018
|
end
|
|
1114
1019
|
|
|
1115
1020
|
context 'when :polymorphic is specified in the options as false' do
|
|
1116
|
-
|
|
1117
1021
|
let(:options) do
|
|
1118
1022
|
{ polymorphic: false }
|
|
1119
1023
|
end
|
|
@@ -1124,7 +1028,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1124
1028
|
end
|
|
1125
1029
|
|
|
1126
1030
|
context 'when :polymorphic is not specified in the options' do
|
|
1127
|
-
|
|
1128
1031
|
it 'returns false' do
|
|
1129
1032
|
expect(association.polymorphic?).to be(false)
|
|
1130
1033
|
end
|
|
@@ -1132,14 +1035,11 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1132
1035
|
end
|
|
1133
1036
|
|
|
1134
1037
|
describe '#dependent' do
|
|
1135
|
-
|
|
1136
1038
|
context 'when the dependent option is provided' do
|
|
1137
|
-
|
|
1138
1039
|
context 'when the dependent option is :delete_all' do
|
|
1139
|
-
|
|
1140
1040
|
let(:options) do
|
|
1141
1041
|
{
|
|
1142
|
-
|
|
1042
|
+
dependent: :delete_all
|
|
1143
1043
|
}
|
|
1144
1044
|
end
|
|
1145
1045
|
|
|
@@ -1149,10 +1049,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1149
1049
|
end
|
|
1150
1050
|
|
|
1151
1051
|
context 'when the dependent option is :destroy' do
|
|
1152
|
-
|
|
1153
1052
|
let(:options) do
|
|
1154
1053
|
{
|
|
1155
|
-
|
|
1054
|
+
dependent: :destroy
|
|
1156
1055
|
}
|
|
1157
1056
|
end
|
|
1158
1057
|
|
|
@@ -1162,10 +1061,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1162
1061
|
end
|
|
1163
1062
|
|
|
1164
1063
|
context 'when the dependent option is :nullify' do
|
|
1165
|
-
|
|
1166
1064
|
let(:options) do
|
|
1167
1065
|
{
|
|
1168
|
-
|
|
1066
|
+
dependent: :nullify
|
|
1169
1067
|
}
|
|
1170
1068
|
end
|
|
1171
1069
|
|
|
@@ -1175,10 +1073,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1175
1073
|
end
|
|
1176
1074
|
|
|
1177
1075
|
context 'when the dependent option is :restrict_with_exception' do
|
|
1178
|
-
|
|
1179
1076
|
let(:options) do
|
|
1180
1077
|
{
|
|
1181
|
-
|
|
1078
|
+
dependent: :restrict_with_exception
|
|
1182
1079
|
}
|
|
1183
1080
|
end
|
|
1184
1081
|
|
|
@@ -1188,10 +1085,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1188
1085
|
end
|
|
1189
1086
|
|
|
1190
1087
|
context 'when the dependent option is :restrict_with_error' do
|
|
1191
|
-
|
|
1192
1088
|
let(:options) do
|
|
1193
1089
|
{
|
|
1194
|
-
|
|
1090
|
+
dependent: :restrict_with_error
|
|
1195
1091
|
}
|
|
1196
1092
|
end
|
|
1197
1093
|
|
|
@@ -1202,7 +1098,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1202
1098
|
end
|
|
1203
1099
|
|
|
1204
1100
|
context 'when the dependent option is not provided' do
|
|
1205
|
-
|
|
1206
1101
|
it 'returns nil' do
|
|
1207
1102
|
expect(association.dependent).to be_nil
|
|
1208
1103
|
end
|
|
@@ -1210,19 +1105,16 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1210
1105
|
end
|
|
1211
1106
|
|
|
1212
1107
|
describe '#bindable?' do
|
|
1213
|
-
|
|
1214
1108
|
it 'returns false' do
|
|
1215
1109
|
expect(association.bindable?(Person.new)).to be(false)
|
|
1216
1110
|
end
|
|
1217
1111
|
end
|
|
1218
1112
|
|
|
1219
1113
|
describe '#inverses' do
|
|
1220
|
-
|
|
1221
1114
|
context 'when polymorphic' do
|
|
1222
|
-
|
|
1223
1115
|
let(:options) do
|
|
1224
1116
|
{
|
|
1225
|
-
|
|
1117
|
+
polymorphic: true
|
|
1226
1118
|
}
|
|
1227
1119
|
end
|
|
1228
1120
|
|
|
@@ -1231,19 +1123,16 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1231
1123
|
end
|
|
1232
1124
|
|
|
1233
1125
|
context 'when another object is passed to the method' do
|
|
1234
|
-
|
|
1235
1126
|
let(:instance_of_other_class) do
|
|
1236
1127
|
OwnerObject.new
|
|
1237
1128
|
end
|
|
1238
1129
|
|
|
1239
1130
|
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
1240
|
-
|
|
1241
1131
|
before do
|
|
1242
1132
|
OwnerObject.has_one :belonging_object, as: :containable
|
|
1243
1133
|
end
|
|
1244
1134
|
|
|
1245
1135
|
context 'when :inverse_of is specified' do
|
|
1246
|
-
|
|
1247
1136
|
before do
|
|
1248
1137
|
options.merge!(inverse_of: :inverse_name)
|
|
1249
1138
|
end
|
|
@@ -1254,22 +1143,19 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1254
1143
|
end
|
|
1255
1144
|
|
|
1256
1145
|
context 'when inverse_of is not specified' do
|
|
1257
|
-
|
|
1258
1146
|
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
1259
|
-
expect(association.inverses(instance_of_other_class)).to
|
|
1147
|
+
expect(association.inverses(instance_of_other_class)).to contain_exactly(:belonging_object)
|
|
1260
1148
|
end
|
|
1261
1149
|
end
|
|
1262
1150
|
end
|
|
1263
1151
|
|
|
1264
1152
|
context 'when the relation class has more than one relation whose class matches the owning class' do
|
|
1265
|
-
|
|
1266
1153
|
before do
|
|
1267
1154
|
OwnerObject.has_one :other_belonging_object, as: :containable, class_name: 'BelongingObject'
|
|
1268
1155
|
OwnerObject.has_one :belonging_object, as: :containable
|
|
1269
1156
|
end
|
|
1270
1157
|
|
|
1271
1158
|
context 'when :inverse_of is specified' do
|
|
1272
|
-
|
|
1273
1159
|
before do
|
|
1274
1160
|
options.merge!(inverse_of: :inverse_name)
|
|
1275
1161
|
end
|
|
@@ -1280,21 +1166,19 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1280
1166
|
end
|
|
1281
1167
|
|
|
1282
1168
|
context 'when inverse_of is not specified' do
|
|
1283
|
-
|
|
1284
1169
|
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
1285
|
-
expect(association.inverses(instance_of_other_class)).to match_array([
|
|
1286
|
-
|
|
1170
|
+
expect(association.inverses(instance_of_other_class)).to match_array(%i[other_belonging_object
|
|
1171
|
+
belonging_object])
|
|
1287
1172
|
end
|
|
1288
1173
|
|
|
1289
1174
|
context 'when the relation class has two associations with the same name' do
|
|
1290
|
-
|
|
1291
1175
|
before do
|
|
1292
1176
|
OwnerObject.has_one :belonging_object, as: :containable
|
|
1293
1177
|
OwnerObject.has_one :other_belonging_object, as: :containable
|
|
1294
1178
|
end
|
|
1295
1179
|
|
|
1296
1180
|
it 'returns only the relations whose :as attribute and class match' do
|
|
1297
|
-
expect(association.inverses(instance_of_other_class)).to
|
|
1181
|
+
expect(association.inverses(instance_of_other_class)).to contain_exactly(:belonging_object)
|
|
1298
1182
|
end
|
|
1299
1183
|
end
|
|
1300
1184
|
end
|
|
@@ -1302,9 +1186,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1302
1186
|
end
|
|
1303
1187
|
|
|
1304
1188
|
context 'when another object is not passed to the method' do
|
|
1305
|
-
|
|
1306
1189
|
context 'when inverse_of is specified' do
|
|
1307
|
-
|
|
1308
1190
|
before do
|
|
1309
1191
|
options.merge!(inverse_of: :inverse_name)
|
|
1310
1192
|
end
|
|
@@ -1315,7 +1197,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1315
1197
|
end
|
|
1316
1198
|
|
|
1317
1199
|
context 'when inverse_of is not specified' do
|
|
1318
|
-
|
|
1319
1200
|
it 'returns nil' do
|
|
1320
1201
|
expect(association.inverses).to eq(nil)
|
|
1321
1202
|
end
|
|
@@ -1324,9 +1205,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1324
1205
|
end
|
|
1325
1206
|
|
|
1326
1207
|
context 'when not polymorphic' do
|
|
1327
|
-
|
|
1328
1208
|
context 'when inverse_of is specified' do
|
|
1329
|
-
|
|
1330
1209
|
before do
|
|
1331
1210
|
options.merge!(inverse_of: :inverse_name)
|
|
1332
1211
|
end
|
|
@@ -1337,7 +1216,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1337
1216
|
end
|
|
1338
1217
|
|
|
1339
1218
|
context 'when inverse_of is not specified' do
|
|
1340
|
-
|
|
1341
1219
|
before do
|
|
1342
1220
|
OwnerObject.has_many :belonging_objects
|
|
1343
1221
|
end
|
|
@@ -1348,28 +1226,24 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1348
1226
|
end
|
|
1349
1227
|
|
|
1350
1228
|
context 'when :cyclic is specified' do
|
|
1351
|
-
|
|
1352
1229
|
it 'returns the cyclic inverse name' do
|
|
1353
|
-
|
|
1354
1230
|
end
|
|
1355
1231
|
end
|
|
1356
1232
|
|
|
1357
1233
|
context 'when the inverse class has more than one relation with objects of the owner class' do
|
|
1358
|
-
|
|
1359
1234
|
before do
|
|
1360
1235
|
OwnerObject.has_many :belonging_objects
|
|
1361
1236
|
OwnerObject.has_one :other_belonging_object, class_name: 'BelongingObject'
|
|
1362
1237
|
end
|
|
1363
1238
|
|
|
1364
1239
|
it 'raises a Mongoid::Errors::AmbiguousRelationship exception' do
|
|
1365
|
-
expect
|
|
1240
|
+
expect do
|
|
1366
1241
|
association.inverses
|
|
1367
|
-
|
|
1242
|
+
end.to raise_exception(Mongoid::Errors::AmbiguousRelationship)
|
|
1368
1243
|
end
|
|
1369
1244
|
end
|
|
1370
1245
|
|
|
1371
1246
|
context 'when the inverse class only has one relation with objects of the owner class' do
|
|
1372
|
-
|
|
1373
1247
|
before do
|
|
1374
1248
|
OwnerObject.has_many :belonging_objects
|
|
1375
1249
|
end
|
|
@@ -1382,12 +1256,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1382
1256
|
end
|
|
1383
1257
|
|
|
1384
1258
|
describe '#inverse' do
|
|
1385
|
-
|
|
1386
1259
|
context 'when polymorphic' do
|
|
1387
|
-
|
|
1388
1260
|
let(:options) do
|
|
1389
1261
|
{
|
|
1390
|
-
|
|
1262
|
+
polymorphic: true
|
|
1391
1263
|
}
|
|
1392
1264
|
end
|
|
1393
1265
|
|
|
@@ -1396,19 +1268,16 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1396
1268
|
end
|
|
1397
1269
|
|
|
1398
1270
|
context 'when another object is passed to the method' do
|
|
1399
|
-
|
|
1400
1271
|
let(:instance_of_other_class) do
|
|
1401
1272
|
OwnerObject.new
|
|
1402
1273
|
end
|
|
1403
1274
|
|
|
1404
1275
|
context 'when the relation class has only one relation whose class matches the owning class' do
|
|
1405
|
-
|
|
1406
1276
|
before do
|
|
1407
1277
|
OwnerObject.has_many :belonging_objects, as: :containable
|
|
1408
1278
|
end
|
|
1409
1279
|
|
|
1410
1280
|
context 'when :inverse_of is specified' do
|
|
1411
|
-
|
|
1412
1281
|
before do
|
|
1413
1282
|
options.merge!(inverse_of: :inverse_name)
|
|
1414
1283
|
end
|
|
@@ -1419,7 +1288,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1419
1288
|
end
|
|
1420
1289
|
|
|
1421
1290
|
context 'when inverse_of is not specified' do
|
|
1422
|
-
|
|
1423
1291
|
it 'returns the list of relations whose :as attribute matches the name of this association' do
|
|
1424
1292
|
expect(association.inverse(instance_of_other_class)).to eq(:belonging_objects)
|
|
1425
1293
|
end
|
|
@@ -1427,14 +1295,12 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1427
1295
|
end
|
|
1428
1296
|
|
|
1429
1297
|
context 'when the relation class has more than one relation whose class matches the owning class' do
|
|
1430
|
-
|
|
1431
1298
|
before do
|
|
1432
1299
|
OwnerObject.has_one :other_belonging_object, as: :containable, class_name: 'BelongingObject'
|
|
1433
1300
|
OwnerObject.has_one :belonging_object, as: :containable
|
|
1434
1301
|
end
|
|
1435
1302
|
|
|
1436
1303
|
context 'when :inverse_of is specified' do
|
|
1437
|
-
|
|
1438
1304
|
before do
|
|
1439
1305
|
options.merge!(inverse_of: :inverse_name)
|
|
1440
1306
|
end
|
|
@@ -1445,7 +1311,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1445
1311
|
end
|
|
1446
1312
|
|
|
1447
1313
|
context 'when inverse_of is not specified' do
|
|
1448
|
-
|
|
1449
1314
|
it 'returns the first candidate whose :as attribute matches the name of this association' do
|
|
1450
1315
|
expect(association.inverse(instance_of_other_class)).to eq(:other_belonging_object)
|
|
1451
1316
|
end
|
|
@@ -1454,9 +1319,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1454
1319
|
end
|
|
1455
1320
|
|
|
1456
1321
|
context 'when another object is not passed to the method' do
|
|
1457
|
-
|
|
1458
1322
|
context 'when inverse_of is specified' do
|
|
1459
|
-
|
|
1460
1323
|
before do
|
|
1461
1324
|
options.merge!(inverse_of: :inverse_name)
|
|
1462
1325
|
end
|
|
@@ -1467,7 +1330,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1467
1330
|
end
|
|
1468
1331
|
|
|
1469
1332
|
context 'when inverse_of is not specified' do
|
|
1470
|
-
|
|
1471
1333
|
it 'returns nil' do
|
|
1472
1334
|
expect(association.inverse).to eq(nil)
|
|
1473
1335
|
end
|
|
@@ -1476,9 +1338,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1476
1338
|
end
|
|
1477
1339
|
|
|
1478
1340
|
context 'when not polymorphic' do
|
|
1479
|
-
|
|
1480
1341
|
context 'when inverse_of is specified' do
|
|
1481
|
-
|
|
1482
1342
|
before do
|
|
1483
1343
|
options.merge!(inverse_of: :inverse_name)
|
|
1484
1344
|
end
|
|
@@ -1489,7 +1349,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1489
1349
|
end
|
|
1490
1350
|
|
|
1491
1351
|
context 'when inverse_of is not specified' do
|
|
1492
|
-
|
|
1493
1352
|
before do
|
|
1494
1353
|
OwnerObject.has_many :belonging_objects
|
|
1495
1354
|
end
|
|
@@ -1500,28 +1359,24 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1500
1359
|
end
|
|
1501
1360
|
|
|
1502
1361
|
context 'when :cyclic is specified' do
|
|
1503
|
-
|
|
1504
1362
|
it 'returns the cyclic inverse name' do
|
|
1505
|
-
|
|
1506
1363
|
end
|
|
1507
1364
|
end
|
|
1508
1365
|
|
|
1509
1366
|
context 'when the inverse class has more than one relation with objects of the owner class' do
|
|
1510
|
-
|
|
1511
1367
|
before do
|
|
1512
1368
|
OwnerObject.has_many :belonging_objects
|
|
1513
1369
|
OwnerObject.has_many :other_belonging_objects, class_name: 'BelongingObject'
|
|
1514
1370
|
end
|
|
1515
1371
|
|
|
1516
1372
|
it 'raises a Mongoid::Errors::AmbiguousRelationship exception' do
|
|
1517
|
-
expect
|
|
1373
|
+
expect do
|
|
1518
1374
|
association.inverse
|
|
1519
|
-
|
|
1375
|
+
end.to raise_exception(Mongoid::Errors::AmbiguousRelationship)
|
|
1520
1376
|
end
|
|
1521
1377
|
end
|
|
1522
1378
|
|
|
1523
1379
|
context 'when the inverse class only has one relation with objects of the owner class' do
|
|
1524
|
-
|
|
1525
1380
|
before do
|
|
1526
1381
|
OwnerObject.has_many :belonging_objects
|
|
1527
1382
|
end
|
|
@@ -1534,18 +1389,14 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1534
1389
|
end
|
|
1535
1390
|
|
|
1536
1391
|
describe '#inverse_association' do
|
|
1537
|
-
|
|
1538
1392
|
end
|
|
1539
1393
|
|
|
1540
1394
|
describe '#autosave' do
|
|
1541
|
-
|
|
1542
1395
|
context 'when the :autosave option is specified' do
|
|
1543
|
-
|
|
1544
1396
|
context 'when the :autosave option is true' do
|
|
1545
|
-
|
|
1546
1397
|
let(:options) do
|
|
1547
1398
|
{
|
|
1548
|
-
|
|
1399
|
+
autosave: true
|
|
1549
1400
|
}
|
|
1550
1401
|
end
|
|
1551
1402
|
|
|
@@ -1555,10 +1406,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1555
1406
|
end
|
|
1556
1407
|
|
|
1557
1408
|
context 'when the :autosave option is false' do
|
|
1558
|
-
|
|
1559
1409
|
let(:options) do
|
|
1560
1410
|
{
|
|
1561
|
-
|
|
1411
|
+
autosave: false
|
|
1562
1412
|
}
|
|
1563
1413
|
end
|
|
1564
1414
|
|
|
@@ -1569,7 +1419,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1569
1419
|
end
|
|
1570
1420
|
|
|
1571
1421
|
context 'when the :autosave option is not specified' do
|
|
1572
|
-
|
|
1573
1422
|
it 'returns nil' do
|
|
1574
1423
|
expect(association.autosave).to be(false)
|
|
1575
1424
|
end
|
|
@@ -1577,12 +1426,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1577
1426
|
end
|
|
1578
1427
|
|
|
1579
1428
|
describe '#counter_cached?' do
|
|
1580
|
-
|
|
1581
1429
|
context 'when the :counter_cache option is true' do
|
|
1582
|
-
|
|
1583
1430
|
let(:options) do
|
|
1584
1431
|
{
|
|
1585
|
-
|
|
1432
|
+
counter_cache: true
|
|
1586
1433
|
}
|
|
1587
1434
|
end
|
|
1588
1435
|
|
|
@@ -1592,10 +1439,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1592
1439
|
end
|
|
1593
1440
|
|
|
1594
1441
|
context 'when the :counter_cache option is a String' do
|
|
1595
|
-
|
|
1596
1442
|
let(:options) do
|
|
1597
1443
|
{
|
|
1598
|
-
|
|
1444
|
+
counter_cache: 'counts_field'
|
|
1599
1445
|
}
|
|
1600
1446
|
end
|
|
1601
1447
|
|
|
@@ -1605,10 +1451,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1605
1451
|
end
|
|
1606
1452
|
|
|
1607
1453
|
context 'when the :counter_cache option is false' do
|
|
1608
|
-
|
|
1609
1454
|
let(:options) do
|
|
1610
1455
|
{
|
|
1611
|
-
|
|
1456
|
+
counter_cache: false
|
|
1612
1457
|
}
|
|
1613
1458
|
end
|
|
1614
1459
|
|
|
@@ -1618,7 +1463,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1618
1463
|
end
|
|
1619
1464
|
|
|
1620
1465
|
context 'when the :counter_cache option is not provided' do
|
|
1621
|
-
|
|
1622
1466
|
it 'returns false' do
|
|
1623
1467
|
expect(association.counter_cached?).to be(false)
|
|
1624
1468
|
end
|
|
@@ -1626,12 +1470,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1626
1470
|
end
|
|
1627
1471
|
|
|
1628
1472
|
describe '#counter_cache_column_name' do
|
|
1629
|
-
|
|
1630
1473
|
context 'when the :counter_cache option is true' do
|
|
1631
|
-
|
|
1632
1474
|
let(:options) do
|
|
1633
1475
|
{
|
|
1634
|
-
|
|
1476
|
+
counter_cache: true
|
|
1635
1477
|
}
|
|
1636
1478
|
end
|
|
1637
1479
|
|
|
@@ -1641,10 +1483,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1641
1483
|
end
|
|
1642
1484
|
|
|
1643
1485
|
context 'when the :counter_cache option is a String' do
|
|
1644
|
-
|
|
1645
1486
|
let(:options) do
|
|
1646
1487
|
{
|
|
1647
|
-
|
|
1488
|
+
counter_cache: 'counts_field'
|
|
1648
1489
|
}
|
|
1649
1490
|
end
|
|
1650
1491
|
|
|
@@ -1655,9 +1496,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1655
1496
|
end
|
|
1656
1497
|
|
|
1657
1498
|
describe '#relation_class_name' do
|
|
1658
|
-
|
|
1659
1499
|
context 'when the :class_name option is specified' do
|
|
1660
|
-
|
|
1661
1500
|
let(:options) do
|
|
1662
1501
|
{ class_name: 'OtherOwnerObject' }
|
|
1663
1502
|
end
|
|
@@ -1668,7 +1507,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1668
1507
|
end
|
|
1669
1508
|
|
|
1670
1509
|
context 'when the :class_name option is scoped with ::' do
|
|
1671
|
-
|
|
1672
1510
|
let(:options) do
|
|
1673
1511
|
{ class_name: '::OtherOwnerObject' }
|
|
1674
1512
|
end
|
|
@@ -1679,7 +1517,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1679
1517
|
end
|
|
1680
1518
|
|
|
1681
1519
|
context 'when the class_name option is not specified' do
|
|
1682
|
-
|
|
1683
1520
|
it 'uses the name of the relation to deduce the class name' do
|
|
1684
1521
|
expect(association.relation_class_name).to eq('OwnerObject')
|
|
1685
1522
|
end
|
|
@@ -1697,9 +1534,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1697
1534
|
end
|
|
1698
1535
|
|
|
1699
1536
|
describe '#relation_class' do
|
|
1700
|
-
|
|
1701
1537
|
context 'when the :class_name option is specified' do
|
|
1702
|
-
|
|
1703
1538
|
let(:options) do
|
|
1704
1539
|
{ class_name: 'OtherOwnerObject' }
|
|
1705
1540
|
end
|
|
@@ -1710,7 +1545,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1710
1545
|
end
|
|
1711
1546
|
|
|
1712
1547
|
context 'when the :class_name option is scoped with ::' do
|
|
1713
|
-
|
|
1714
1548
|
let(:options) do
|
|
1715
1549
|
{ class_name: '::OtherOwnerObject' }
|
|
1716
1550
|
end
|
|
@@ -1721,7 +1555,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1721
1555
|
end
|
|
1722
1556
|
|
|
1723
1557
|
context 'when the class_name option is not specified' do
|
|
1724
|
-
|
|
1725
1558
|
it 'uses the name of the relation to deduce the class name' do
|
|
1726
1559
|
expect(association.relation_class).to eq(OwnerObject)
|
|
1727
1560
|
end
|
|
@@ -1741,7 +1574,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1741
1574
|
end
|
|
1742
1575
|
|
|
1743
1576
|
describe '#inverse_class_name' do
|
|
1744
|
-
|
|
1745
1577
|
it 'returns the name of the owner class' do
|
|
1746
1578
|
expect(association.inverse_class_name).to eq(belonging_class.name)
|
|
1747
1579
|
end
|
|
@@ -1758,7 +1590,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1758
1590
|
end
|
|
1759
1591
|
|
|
1760
1592
|
describe '#inverse_class' do
|
|
1761
|
-
|
|
1762
1593
|
it 'returns the owner class' do
|
|
1763
1594
|
expect(association.inverse_class).to be(belonging_class)
|
|
1764
1595
|
end
|
|
@@ -1775,9 +1606,7 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1775
1606
|
end
|
|
1776
1607
|
|
|
1777
1608
|
describe '#inverse_of' do
|
|
1778
|
-
|
|
1779
1609
|
context 'when :inverse_of is specified in the options' do
|
|
1780
|
-
|
|
1781
1610
|
let(:options) do
|
|
1782
1611
|
{ inverse_of: :a_belonging_object }
|
|
1783
1612
|
end
|
|
@@ -1788,7 +1617,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1788
1617
|
end
|
|
1789
1618
|
|
|
1790
1619
|
context 'when :inverse_of is not specified in the options' do
|
|
1791
|
-
|
|
1792
1620
|
it 'returns nil' do
|
|
1793
1621
|
expect(association.inverse_of).to be_nil
|
|
1794
1622
|
end
|
|
@@ -1796,25 +1624,20 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1796
1624
|
end
|
|
1797
1625
|
|
|
1798
1626
|
describe '#key' do
|
|
1799
|
-
|
|
1800
1627
|
it 'returns the name of the foreign_key as a string' do
|
|
1801
1628
|
expect(association.key).to eq(association.foreign_key.to_s)
|
|
1802
1629
|
end
|
|
1803
1630
|
end
|
|
1804
1631
|
|
|
1805
1632
|
describe '#setter' do
|
|
1806
|
-
|
|
1807
1633
|
it 'returns a string of the name followed by =' do
|
|
1808
1634
|
expect(association.setter).to eq("#{name}=")
|
|
1809
1635
|
end
|
|
1810
1636
|
end
|
|
1811
1637
|
|
|
1812
1638
|
describe '#validate?' do
|
|
1813
|
-
|
|
1814
1639
|
context 'when :validate is specified in the options' do
|
|
1815
|
-
|
|
1816
1640
|
context 'when validate is true' do
|
|
1817
|
-
|
|
1818
1641
|
let(:options) do
|
|
1819
1642
|
{ validate: true }
|
|
1820
1643
|
end
|
|
@@ -1825,7 +1648,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1825
1648
|
end
|
|
1826
1649
|
|
|
1827
1650
|
context 'when validate is false' do
|
|
1828
|
-
|
|
1829
1651
|
let(:options) do
|
|
1830
1652
|
{ validate: false }
|
|
1831
1653
|
end
|
|
@@ -1837,7 +1659,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1837
1659
|
end
|
|
1838
1660
|
|
|
1839
1661
|
context 'when :validate is not specified in the options' do
|
|
1840
|
-
|
|
1841
1662
|
it 'returns the validation_default' do
|
|
1842
1663
|
expect(association.send(:validate?)).to eq(association.validation_default)
|
|
1843
1664
|
end
|
|
@@ -1845,11 +1666,8 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1845
1666
|
end
|
|
1846
1667
|
|
|
1847
1668
|
describe '#autobuilding?' do
|
|
1848
|
-
|
|
1849
1669
|
context 'when :autobuild is specified in the options' do
|
|
1850
|
-
|
|
1851
1670
|
context 'when autobuild is true' do
|
|
1852
|
-
|
|
1853
1671
|
let(:options) do
|
|
1854
1672
|
{ autobuild: true }
|
|
1855
1673
|
end
|
|
@@ -1860,7 +1678,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1860
1678
|
end
|
|
1861
1679
|
|
|
1862
1680
|
context 'when autobuild is false' do
|
|
1863
|
-
|
|
1864
1681
|
let(:options) do
|
|
1865
1682
|
{ autobuild: false }
|
|
1866
1683
|
end
|
|
@@ -1872,7 +1689,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1872
1689
|
end
|
|
1873
1690
|
|
|
1874
1691
|
context 'when :validate is not specified in the options' do
|
|
1875
|
-
|
|
1876
1692
|
it 'returns false' do
|
|
1877
1693
|
expect(association.autobuilding?).to be(false)
|
|
1878
1694
|
end
|
|
@@ -1880,23 +1696,19 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1880
1696
|
end
|
|
1881
1697
|
|
|
1882
1698
|
describe '#forced_nil_inverse?' do
|
|
1883
|
-
|
|
1884
1699
|
it 'returns false' do
|
|
1885
1700
|
expect(association.forced_nil_inverse?).to be(false)
|
|
1886
1701
|
end
|
|
1887
1702
|
end
|
|
1888
1703
|
|
|
1889
1704
|
describe '#stores_foreign_key?' do
|
|
1890
|
-
|
|
1891
1705
|
it 'returns true' do
|
|
1892
1706
|
expect(association.stores_foreign_key?).to be(true)
|
|
1893
1707
|
end
|
|
1894
1708
|
end
|
|
1895
1709
|
|
|
1896
1710
|
describe '#inverse_setter' do
|
|
1897
|
-
|
|
1898
1711
|
context 'when an inverse can be determined' do
|
|
1899
|
-
|
|
1900
1712
|
before do
|
|
1901
1713
|
OwnerObject.has_many :belonging_objects
|
|
1902
1714
|
end
|
|
@@ -1907,7 +1719,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1907
1719
|
end
|
|
1908
1720
|
|
|
1909
1721
|
context 'when an inverse cannot be determined' do
|
|
1910
|
-
|
|
1911
1722
|
it 'returns nil' do
|
|
1912
1723
|
expect(association.inverse_setter).to be_nil
|
|
1913
1724
|
end
|
|
@@ -1915,11 +1726,10 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1915
1726
|
end
|
|
1916
1727
|
|
|
1917
1728
|
describe '#extension' do
|
|
1918
|
-
|
|
1919
1729
|
context 'when a block is passed' do
|
|
1920
|
-
|
|
1921
1730
|
let(:association) do
|
|
1922
|
-
belonging_class.belongs_to name, options do
|
|
1731
|
+
belonging_class.belongs_to name, options do
|
|
1732
|
+
end
|
|
1923
1733
|
end
|
|
1924
1734
|
|
|
1925
1735
|
it 'defines an extension module' do
|
|
@@ -1928,12 +1738,12 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1928
1738
|
|
|
1929
1739
|
it 'returns the extension' do
|
|
1930
1740
|
expect(association.extension).to eq(
|
|
1931
|
-
"#{belonging_class.name}::#{belonging_class.name}#{name.to_s.camelize}RelationExtension".constantize
|
|
1741
|
+
"#{belonging_class.name}::#{belonging_class.name}#{name.to_s.camelize}RelationExtension".constantize
|
|
1742
|
+
)
|
|
1932
1743
|
end
|
|
1933
1744
|
end
|
|
1934
1745
|
|
|
1935
1746
|
context 'when an :extension is not specified in the options' do
|
|
1936
|
-
|
|
1937
1747
|
it 'returns false' do
|
|
1938
1748
|
expect(association.extension).to be_nil
|
|
1939
1749
|
end
|
|
@@ -1941,21 +1751,17 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1941
1751
|
end
|
|
1942
1752
|
|
|
1943
1753
|
describe '#foreign_key_setter' do
|
|
1944
|
-
|
|
1945
1754
|
it 'returns the foreign key field followed by "="' do
|
|
1946
|
-
expect(association.foreign_key_setter).to eq(
|
|
1755
|
+
expect(association.foreign_key_setter).to eq('owner_object_id=')
|
|
1947
1756
|
end
|
|
1948
1757
|
end
|
|
1949
1758
|
|
|
1950
1759
|
describe '#destructive?' do
|
|
1951
|
-
|
|
1952
1760
|
context 'when the dependent option is provided' do
|
|
1953
|
-
|
|
1954
1761
|
context 'when the dependent option is :delete_all' do
|
|
1955
|
-
|
|
1956
1762
|
let(:options) do
|
|
1957
1763
|
{
|
|
1958
|
-
|
|
1764
|
+
dependent: :delete_all
|
|
1959
1765
|
}
|
|
1960
1766
|
end
|
|
1961
1767
|
|
|
@@ -1965,10 +1771,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1965
1771
|
end
|
|
1966
1772
|
|
|
1967
1773
|
context 'when the dependent option is :destroy' do
|
|
1968
|
-
|
|
1969
1774
|
let(:options) do
|
|
1970
1775
|
{
|
|
1971
|
-
|
|
1776
|
+
dependent: :destroy
|
|
1972
1777
|
}
|
|
1973
1778
|
end
|
|
1974
1779
|
|
|
@@ -1978,10 +1783,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1978
1783
|
end
|
|
1979
1784
|
|
|
1980
1785
|
context 'when the dependent option is :nullify' do
|
|
1981
|
-
|
|
1982
1786
|
let(:options) do
|
|
1983
1787
|
{
|
|
1984
|
-
|
|
1788
|
+
dependent: :nullify
|
|
1985
1789
|
}
|
|
1986
1790
|
end
|
|
1987
1791
|
|
|
@@ -1991,10 +1795,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
1991
1795
|
end
|
|
1992
1796
|
|
|
1993
1797
|
context 'when the dependent option is :restrict_with_exception' do
|
|
1994
|
-
|
|
1995
1798
|
let(:options) do
|
|
1996
1799
|
{
|
|
1997
|
-
|
|
1800
|
+
dependent: :restrict_with_exception
|
|
1998
1801
|
}
|
|
1999
1802
|
end
|
|
2000
1803
|
|
|
@@ -2004,10 +1807,9 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
2004
1807
|
end
|
|
2005
1808
|
|
|
2006
1809
|
context 'when the dependent option is :restrict_with_error' do
|
|
2007
|
-
|
|
2008
1810
|
let(:options) do
|
|
2009
1811
|
{
|
|
2010
|
-
|
|
1812
|
+
dependent: :restrict_with_error
|
|
2011
1813
|
}
|
|
2012
1814
|
end
|
|
2013
1815
|
|
|
@@ -2018,7 +1820,6 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
2018
1820
|
end
|
|
2019
1821
|
|
|
2020
1822
|
context 'when the dependent option is not provided' do
|
|
2021
|
-
|
|
2022
1823
|
it 'returns false' do
|
|
2023
1824
|
expect(association.destructive?).to be(false)
|
|
2024
1825
|
end
|
|
@@ -2026,28 +1827,24 @@ describe Mongoid::Association::Referenced::BelongsTo do
|
|
|
2026
1827
|
end
|
|
2027
1828
|
|
|
2028
1829
|
describe '#nested_builder' do
|
|
2029
|
-
|
|
2030
1830
|
it 'returns an instance of Association::Nested::One' do
|
|
2031
1831
|
expect(association.nested_builder({}, {})).to be_a(Mongoid::Association::Nested::One)
|
|
2032
1832
|
end
|
|
2033
1833
|
end
|
|
2034
1834
|
|
|
2035
1835
|
describe '#path' do
|
|
2036
|
-
|
|
2037
1836
|
it 'returns an instance of Mongoid::Atomic::Paths::Root' do
|
|
2038
1837
|
expect(association.path({})).to be_a(Mongoid::Atomic::Paths::Root)
|
|
2039
1838
|
end
|
|
2040
1839
|
end
|
|
2041
1840
|
|
|
2042
1841
|
describe '#foreign_key_check' do
|
|
2043
|
-
|
|
2044
1842
|
it 'returns the foreign_key followed by "_previously_changed?"' do
|
|
2045
1843
|
expect(association.foreign_key_check).to eq('owner_object_id_previously_changed?')
|
|
2046
1844
|
end
|
|
2047
1845
|
end
|
|
2048
1846
|
|
|
2049
1847
|
describe '#create_relation' do
|
|
2050
|
-
|
|
2051
1848
|
let(:owner) do
|
|
2052
1849
|
BelongingObject.new
|
|
2053
1850
|
end
|