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,12 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
require 'support/models/canvas'
|
|
6
|
-
require_relative '../belongs_to_models
|
|
5
|
+
require_relative '../belongs_to_models'
|
|
7
6
|
|
|
8
7
|
describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
9
|
-
|
|
10
8
|
before(:all) do
|
|
11
9
|
Person.reset_callbacks(:validate)
|
|
12
10
|
end
|
|
@@ -15,89 +13,80 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
15
13
|
Person.create!
|
|
16
14
|
end
|
|
17
15
|
|
|
18
|
-
describe
|
|
19
|
-
|
|
20
|
-
context "when the relation is named target" do
|
|
21
|
-
|
|
16
|
+
describe '#=' do
|
|
17
|
+
context 'when the relation is named target' do
|
|
22
18
|
let(:target) do
|
|
23
19
|
User.new
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
context
|
|
27
|
-
|
|
28
|
-
context "when setting via create" do
|
|
29
|
-
|
|
22
|
+
context 'when the relation is referenced from an embeds many' do
|
|
23
|
+
context 'when setting via create' do
|
|
30
24
|
let(:service) do
|
|
31
25
|
person.services.create(target: target)
|
|
32
26
|
end
|
|
33
27
|
|
|
34
|
-
it
|
|
28
|
+
it 'sets the target relation' do
|
|
35
29
|
expect(service.target).to eq(target)
|
|
36
30
|
end
|
|
37
31
|
end
|
|
38
32
|
end
|
|
39
33
|
end
|
|
40
34
|
|
|
41
|
-
context
|
|
42
|
-
|
|
35
|
+
context 'when the inverse relation has no reference defined' do
|
|
43
36
|
let(:agent) do
|
|
44
|
-
Agent.new(title:
|
|
37
|
+
Agent.new(title: '007')
|
|
45
38
|
end
|
|
46
39
|
|
|
47
40
|
let(:game) do
|
|
48
|
-
Game.new(name:
|
|
41
|
+
Game.new(name: 'Donkey Kong')
|
|
49
42
|
end
|
|
50
43
|
|
|
51
44
|
before do
|
|
52
45
|
agent.game = game
|
|
53
46
|
end
|
|
54
47
|
|
|
55
|
-
it
|
|
48
|
+
it 'sets the relation' do
|
|
56
49
|
expect(agent.game).to eq(game)
|
|
57
50
|
end
|
|
58
51
|
|
|
59
|
-
it
|
|
52
|
+
it 'sets the foreign_key' do
|
|
60
53
|
expect(agent.game_id).to eq(game.id)
|
|
61
54
|
end
|
|
62
55
|
end
|
|
63
56
|
|
|
64
|
-
context
|
|
65
|
-
|
|
57
|
+
context 'when referencing a document from an embedded document' do
|
|
66
58
|
let(:person) do
|
|
67
59
|
Person.create!
|
|
68
60
|
end
|
|
69
61
|
|
|
70
62
|
let(:address) do
|
|
71
|
-
person.addresses.create!(street:
|
|
63
|
+
person.addresses.create!(street: 'Wienerstr')
|
|
72
64
|
end
|
|
73
65
|
|
|
74
66
|
let(:account) do
|
|
75
|
-
Account.create!(name:
|
|
67
|
+
Account.create!(name: '1', number: 1_000_000)
|
|
76
68
|
end
|
|
77
69
|
|
|
78
70
|
before do
|
|
79
71
|
address.account = account
|
|
80
72
|
end
|
|
81
73
|
|
|
82
|
-
it
|
|
74
|
+
it 'sets the relation' do
|
|
83
75
|
expect(address.account).to eq(account)
|
|
84
76
|
end
|
|
85
77
|
|
|
86
|
-
it
|
|
87
|
-
expect(address._association).
|
|
78
|
+
it 'does not erase the association metadata' do
|
|
79
|
+
expect(address._association).not_to be_nil
|
|
88
80
|
end
|
|
89
81
|
|
|
90
|
-
it
|
|
82
|
+
it 'allows saving of the embedded document' do
|
|
91
83
|
expect(address.save!).to be true
|
|
92
84
|
end
|
|
93
85
|
end
|
|
94
86
|
|
|
95
|
-
context
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
context "when the child is a new record" do
|
|
100
|
-
|
|
87
|
+
context 'when the parent is a references one' do
|
|
88
|
+
context 'when the relation is not polymorphic' do
|
|
89
|
+
context 'when the child is a new record' do
|
|
101
90
|
let(:person) do
|
|
102
91
|
Person.new
|
|
103
92
|
end
|
|
@@ -110,46 +99,45 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
110
99
|
game.person = person
|
|
111
100
|
end
|
|
112
101
|
|
|
113
|
-
it
|
|
102
|
+
it 'sets the target of the relation' do
|
|
114
103
|
expect(game.person._target).to eq(person)
|
|
115
104
|
end
|
|
116
105
|
|
|
117
|
-
it
|
|
106
|
+
it 'sets the foreign key on the relation' do
|
|
118
107
|
expect(game.person_id).to eq(person.id)
|
|
119
108
|
end
|
|
120
109
|
|
|
121
|
-
it
|
|
110
|
+
it 'sets the base on the inverse relation' do
|
|
122
111
|
expect(person.game).to eq(game)
|
|
123
112
|
end
|
|
124
113
|
|
|
125
|
-
it
|
|
114
|
+
it 'sets the same instance on the inverse relation' do
|
|
126
115
|
expect(person.game).to eql(game)
|
|
127
116
|
end
|
|
128
117
|
|
|
129
|
-
it
|
|
130
|
-
expect(person).
|
|
118
|
+
it 'does not save the target' do
|
|
119
|
+
expect(person).not_to be_persisted
|
|
131
120
|
end
|
|
132
121
|
|
|
133
|
-
it
|
|
122
|
+
it 'drops private visibility from private methods' do
|
|
134
123
|
# This is unfortunate but it appears that Ruby does not
|
|
135
124
|
# have a way to distinguish how method_missing was invoked
|
|
136
125
|
# (i.e. via an explicit send or method call).
|
|
137
126
|
# See https://jira.mongodb.org/browse/MONGOID-5009
|
|
138
|
-
game.person.secret_name.should
|
|
127
|
+
game.person.secret_name.should eq 'secret'
|
|
139
128
|
end
|
|
140
129
|
|
|
141
|
-
it
|
|
142
|
-
game.person.send(:secret_name).should
|
|
130
|
+
it 'allows private methods to be invoked' do
|
|
131
|
+
game.person.send(:secret_name).should eq 'secret'
|
|
143
132
|
end
|
|
144
133
|
|
|
145
|
-
it
|
|
146
|
-
expect(defined?(game.person.id)).to eq(
|
|
134
|
+
it 'properly exposes delegated methods visibility' do
|
|
135
|
+
expect(defined?(game.person.id)).to eq('method')
|
|
147
136
|
expect(defined?(game.person.secret_name)).to be_nil
|
|
148
137
|
end
|
|
149
138
|
end
|
|
150
139
|
|
|
151
|
-
context
|
|
152
|
-
|
|
140
|
+
context 'when the child is not a new record' do
|
|
153
141
|
let(:person) do
|
|
154
142
|
Person.new
|
|
155
143
|
end
|
|
@@ -162,38 +150,36 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
162
150
|
game.person = person
|
|
163
151
|
end
|
|
164
152
|
|
|
165
|
-
it
|
|
153
|
+
it 'sets the target of the relation' do
|
|
166
154
|
expect(game.person._target).to eq(person)
|
|
167
155
|
end
|
|
168
156
|
|
|
169
|
-
it
|
|
157
|
+
it 'sets the foreign key of the relation' do
|
|
170
158
|
expect(game.person_id).to eq(person.id)
|
|
171
159
|
end
|
|
172
160
|
|
|
173
|
-
it
|
|
161
|
+
it 'sets the base on the inverse relation' do
|
|
174
162
|
expect(person.game).to eq(game)
|
|
175
163
|
end
|
|
176
164
|
|
|
177
|
-
it
|
|
165
|
+
it 'sets the same instance on the inverse relation' do
|
|
178
166
|
expect(person.game).to eql(game)
|
|
179
167
|
end
|
|
180
168
|
|
|
181
|
-
it
|
|
182
|
-
expect(person).
|
|
169
|
+
it 'does not saves the target' do
|
|
170
|
+
expect(person).not_to be_persisted
|
|
183
171
|
end
|
|
184
172
|
end
|
|
185
173
|
end
|
|
186
174
|
|
|
187
|
-
context
|
|
188
|
-
|
|
189
|
-
context "when the parent is a subclass" do
|
|
190
|
-
|
|
175
|
+
context 'when the relation is polymorphic' do
|
|
176
|
+
context 'when the parent is a subclass' do
|
|
191
177
|
let(:canvas) do
|
|
192
178
|
Canvas::Test.create!
|
|
193
179
|
end
|
|
194
180
|
|
|
195
181
|
let(:comment) do
|
|
196
|
-
Comment.create!(title:
|
|
182
|
+
Comment.create!(title: 'test')
|
|
197
183
|
end
|
|
198
184
|
|
|
199
185
|
before do
|
|
@@ -201,17 +187,16 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
201
187
|
comment.save!
|
|
202
188
|
end
|
|
203
189
|
|
|
204
|
-
it
|
|
205
|
-
expect(comment.commentable_type).to eq(
|
|
190
|
+
it 'sets the correct value in the type field' do
|
|
191
|
+
expect(comment.commentable_type).to eq('Canvas::Test')
|
|
206
192
|
end
|
|
207
193
|
|
|
208
|
-
it
|
|
194
|
+
it 'can retrieve the document from the database' do
|
|
209
195
|
expect(comment.reload.commentable).to eq(canvas)
|
|
210
196
|
end
|
|
211
197
|
end
|
|
212
198
|
|
|
213
|
-
context
|
|
214
|
-
|
|
199
|
+
context 'when the child is a new record' do
|
|
215
200
|
let(:bar) do
|
|
216
201
|
Bar.new
|
|
217
202
|
end
|
|
@@ -224,29 +209,28 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
224
209
|
rating.ratable = bar
|
|
225
210
|
end
|
|
226
211
|
|
|
227
|
-
it
|
|
212
|
+
it 'sets the target of the relation' do
|
|
228
213
|
expect(rating.ratable._target).to eq(bar)
|
|
229
214
|
end
|
|
230
215
|
|
|
231
|
-
it
|
|
216
|
+
it 'sets the foreign key on the relation' do
|
|
232
217
|
expect(rating.ratable_id).to eq(bar.id)
|
|
233
218
|
end
|
|
234
219
|
|
|
235
|
-
it
|
|
220
|
+
it 'sets the base on the inverse relation' do
|
|
236
221
|
expect(bar.rating).to eq(rating)
|
|
237
222
|
end
|
|
238
223
|
|
|
239
|
-
it
|
|
224
|
+
it 'sets the same instance on the inverse relation' do
|
|
240
225
|
expect(bar.rating).to eql(rating)
|
|
241
226
|
end
|
|
242
227
|
|
|
243
|
-
it
|
|
244
|
-
expect(bar).
|
|
228
|
+
it 'does not save the target' do
|
|
229
|
+
expect(bar).not_to be_persisted
|
|
245
230
|
end
|
|
246
231
|
end
|
|
247
232
|
|
|
248
|
-
context
|
|
249
|
-
|
|
233
|
+
context 'when the child is not a new record' do
|
|
250
234
|
let(:bar) do
|
|
251
235
|
Bar.new
|
|
252
236
|
end
|
|
@@ -259,49 +243,35 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
259
243
|
rating.ratable = bar
|
|
260
244
|
end
|
|
261
245
|
|
|
262
|
-
it
|
|
246
|
+
it 'sets the target of the relation' do
|
|
263
247
|
expect(rating.ratable._target).to eq(bar)
|
|
264
248
|
end
|
|
265
249
|
|
|
266
|
-
it
|
|
250
|
+
it 'sets the foreign key of the relation' do
|
|
267
251
|
expect(rating.ratable_id).to eq(bar.id)
|
|
268
252
|
end
|
|
269
253
|
|
|
270
|
-
it
|
|
254
|
+
it 'sets the base on the inverse relation' do
|
|
271
255
|
expect(bar.rating).to eq(rating)
|
|
272
256
|
end
|
|
273
257
|
|
|
274
|
-
it
|
|
258
|
+
it 'sets the same instance on the inverse relation' do
|
|
275
259
|
expect(bar.rating).to eql(rating)
|
|
276
260
|
end
|
|
277
261
|
|
|
278
|
-
it
|
|
279
|
-
expect(bar).
|
|
262
|
+
it 'does not saves the target' do
|
|
263
|
+
expect(bar).not_to be_persisted
|
|
280
264
|
end
|
|
281
265
|
end
|
|
282
266
|
end
|
|
283
267
|
end
|
|
284
268
|
|
|
285
|
-
context
|
|
286
|
-
|
|
287
|
-
context "when the relation is not polymorphic" do
|
|
288
|
-
|
|
269
|
+
context 'when the parent is a references many' do
|
|
270
|
+
context 'when the relation is not polymorphic' do
|
|
289
271
|
context 'when the child has persistence options set' do
|
|
290
|
-
|
|
291
272
|
before do
|
|
292
273
|
Person.collection.client['other-posts'].delete_many
|
|
293
274
|
Person.collection.client['other-people'].delete_many
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
let(:person) do
|
|
297
|
-
Person.new
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
let(:post) do
|
|
301
|
-
Post.new
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
before do
|
|
305
275
|
post.with(collection: 'other-posts') do |post|
|
|
306
276
|
person.with(collection: 'other-people') do |person|
|
|
307
277
|
post.person = person
|
|
@@ -311,26 +281,31 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
311
281
|
end
|
|
312
282
|
end
|
|
313
283
|
|
|
284
|
+
let(:person) do
|
|
285
|
+
Person.new
|
|
286
|
+
end
|
|
314
287
|
let(:other_people_count) do
|
|
315
288
|
Person.with(collection: 'other-people') do |person_class|
|
|
316
289
|
person_class.count
|
|
317
290
|
end
|
|
318
291
|
end
|
|
319
|
-
|
|
320
292
|
let(:other_posts_count) do
|
|
321
293
|
Post.with(collection: 'other-posts') do |post_class|
|
|
322
294
|
post_class.count
|
|
323
295
|
end
|
|
324
296
|
end
|
|
325
297
|
|
|
298
|
+
let(:post) do
|
|
299
|
+
Post.new
|
|
300
|
+
end
|
|
301
|
+
|
|
326
302
|
it 'applies the persistence options when saving the child' do
|
|
327
303
|
expect(other_people_count).to eq(1)
|
|
328
304
|
expect(other_posts_count).to eq(1)
|
|
329
305
|
end
|
|
330
306
|
end
|
|
331
307
|
|
|
332
|
-
context
|
|
333
|
-
|
|
308
|
+
context 'when the child is a new record' do
|
|
334
309
|
let(:person) do
|
|
335
310
|
Person.new
|
|
336
311
|
end
|
|
@@ -343,21 +318,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
343
318
|
post.person = person
|
|
344
319
|
end
|
|
345
320
|
|
|
346
|
-
it
|
|
321
|
+
it 'sets the target of the relation' do
|
|
347
322
|
expect(post.person._target).to eq(person)
|
|
348
323
|
end
|
|
349
324
|
|
|
350
|
-
it
|
|
325
|
+
it 'sets the foreign key on the relation' do
|
|
351
326
|
expect(post.person_id).to eq(person.id)
|
|
352
327
|
end
|
|
353
328
|
|
|
354
|
-
it
|
|
355
|
-
expect(person).
|
|
329
|
+
it 'does not save the target' do
|
|
330
|
+
expect(person).not_to be_persisted
|
|
356
331
|
end
|
|
357
332
|
end
|
|
358
333
|
|
|
359
|
-
context
|
|
360
|
-
|
|
334
|
+
context 'when the child is not a new record' do
|
|
361
335
|
let(:person) do
|
|
362
336
|
Person.new
|
|
363
337
|
end
|
|
@@ -370,24 +344,22 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
370
344
|
post.person = person
|
|
371
345
|
end
|
|
372
346
|
|
|
373
|
-
it
|
|
347
|
+
it 'sets the target of the relation' do
|
|
374
348
|
expect(post.person._target).to eq(person)
|
|
375
349
|
end
|
|
376
350
|
|
|
377
|
-
it
|
|
351
|
+
it 'sets the foreign key of the relation' do
|
|
378
352
|
expect(post.person_id).to eq(person.id)
|
|
379
353
|
end
|
|
380
354
|
|
|
381
|
-
it
|
|
382
|
-
expect(person).
|
|
355
|
+
it 'does not saves the target' do
|
|
356
|
+
expect(person).not_to be_persisted
|
|
383
357
|
end
|
|
384
358
|
end
|
|
385
359
|
end
|
|
386
360
|
|
|
387
|
-
context
|
|
388
|
-
|
|
389
|
-
context "when multiple relations against the same class exist" do
|
|
390
|
-
|
|
361
|
+
context 'when the relation is polymorphic' do
|
|
362
|
+
context 'when multiple relations against the same class exist' do
|
|
391
363
|
let(:face) do
|
|
392
364
|
Face.new
|
|
393
365
|
end
|
|
@@ -396,15 +368,14 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
396
368
|
Eye.new
|
|
397
369
|
end
|
|
398
370
|
|
|
399
|
-
it
|
|
400
|
-
expect
|
|
371
|
+
it 'raises an error' do
|
|
372
|
+
expect do
|
|
401
373
|
eye.eyeable = face
|
|
402
|
-
|
|
374
|
+
end.to raise_error(Mongoid::Errors::InvalidSetPolymorphicRelation)
|
|
403
375
|
end
|
|
404
376
|
end
|
|
405
377
|
|
|
406
|
-
context
|
|
407
|
-
|
|
378
|
+
context 'when multiple relations of the same name but different class exist' do
|
|
408
379
|
let(:eye) do
|
|
409
380
|
Eye.new
|
|
410
381
|
end
|
|
@@ -413,16 +384,14 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
413
384
|
EyeBowl.new
|
|
414
385
|
end
|
|
415
386
|
|
|
416
|
-
it
|
|
387
|
+
it 'assigns as expected' do
|
|
417
388
|
eye.suspended_in = eye_bowl
|
|
418
389
|
expect(eye.suspended_in._target).to eq(eye_bowl)
|
|
419
390
|
end
|
|
420
391
|
end
|
|
421
392
|
|
|
422
|
-
context
|
|
423
|
-
|
|
424
|
-
context "when the child is a new record" do
|
|
425
|
-
|
|
393
|
+
context 'when one relation against the same class exists' do
|
|
394
|
+
context 'when the child is a new record' do
|
|
426
395
|
let(:movie) do
|
|
427
396
|
Movie.new
|
|
428
397
|
end
|
|
@@ -435,21 +404,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
435
404
|
rating.ratable = movie
|
|
436
405
|
end
|
|
437
406
|
|
|
438
|
-
it
|
|
407
|
+
it 'sets the target of the relation' do
|
|
439
408
|
expect(rating.ratable._target).to eq(movie)
|
|
440
409
|
end
|
|
441
410
|
|
|
442
|
-
it
|
|
411
|
+
it 'sets the foreign key on the relation' do
|
|
443
412
|
expect(rating.ratable_id).to eq(movie.id)
|
|
444
413
|
end
|
|
445
414
|
|
|
446
|
-
it
|
|
447
|
-
expect(movie).
|
|
415
|
+
it 'does not save the target' do
|
|
416
|
+
expect(movie).not_to be_persisted
|
|
448
417
|
end
|
|
449
418
|
end
|
|
450
419
|
|
|
451
|
-
context
|
|
452
|
-
|
|
420
|
+
context 'when the child is not a new record' do
|
|
453
421
|
let(:movie) do
|
|
454
422
|
Movie.new
|
|
455
423
|
end
|
|
@@ -462,16 +430,16 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
462
430
|
rating.ratable = movie
|
|
463
431
|
end
|
|
464
432
|
|
|
465
|
-
it
|
|
433
|
+
it 'sets the target of the relation' do
|
|
466
434
|
expect(rating.ratable._target).to eq(movie)
|
|
467
435
|
end
|
|
468
436
|
|
|
469
|
-
it
|
|
437
|
+
it 'sets the foreign key of the relation' do
|
|
470
438
|
expect(rating.ratable_id).to eq(movie.id)
|
|
471
439
|
end
|
|
472
440
|
|
|
473
|
-
it
|
|
474
|
-
expect(movie).
|
|
441
|
+
it 'does not saves the target' do
|
|
442
|
+
expect(movie).not_to be_persisted
|
|
475
443
|
end
|
|
476
444
|
end
|
|
477
445
|
end
|
|
@@ -479,10 +447,8 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
479
447
|
end
|
|
480
448
|
end
|
|
481
449
|
|
|
482
|
-
describe
|
|
483
|
-
|
|
484
|
-
context "when dependent is destroy" do
|
|
485
|
-
|
|
450
|
+
describe '#= nil' do
|
|
451
|
+
context 'when dependent is destroy' do
|
|
486
452
|
let(:account) do
|
|
487
453
|
Account.create!(name: 'checkings')
|
|
488
454
|
end
|
|
@@ -495,9 +461,8 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
495
461
|
Person.create!
|
|
496
462
|
end
|
|
497
463
|
|
|
498
|
-
context
|
|
499
|
-
|
|
500
|
-
around(:each) do |example|
|
|
464
|
+
context 'when relation is has_one' do
|
|
465
|
+
around do |example|
|
|
501
466
|
original_account_dependents = Account.dependents
|
|
502
467
|
Account.dependents = []
|
|
503
468
|
example.run
|
|
@@ -516,39 +481,35 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
516
481
|
Person.has_one :account, validate: false
|
|
517
482
|
end
|
|
518
483
|
|
|
519
|
-
context
|
|
520
|
-
|
|
521
|
-
context "when child touch the parent" do
|
|
522
|
-
|
|
484
|
+
context 'when parent exists' do
|
|
485
|
+
context 'when child touch the parent' do
|
|
523
486
|
let!(:account_from_db) { account.reload }
|
|
524
487
|
|
|
525
|
-
it
|
|
488
|
+
it 'queries only the parent' do
|
|
526
489
|
expect_query(1) do
|
|
527
490
|
expect(account_from_db.person.id).to eq(person.id)
|
|
528
491
|
end
|
|
529
492
|
end
|
|
530
493
|
end
|
|
531
494
|
|
|
532
|
-
context
|
|
533
|
-
|
|
495
|
+
context 'when child is destroyed' do
|
|
534
496
|
before do
|
|
535
497
|
account.destroy
|
|
536
498
|
end
|
|
537
499
|
|
|
538
|
-
it
|
|
500
|
+
it 'deletes child' do
|
|
539
501
|
expect(account).to be_destroyed
|
|
540
502
|
end
|
|
541
503
|
|
|
542
|
-
it
|
|
504
|
+
it 'deletes parent' do
|
|
543
505
|
expect(person).to be_destroyed
|
|
544
506
|
end
|
|
545
507
|
end
|
|
546
508
|
end
|
|
547
509
|
end
|
|
548
510
|
|
|
549
|
-
context
|
|
550
|
-
|
|
551
|
-
around(:each) do |example|
|
|
511
|
+
context 'when relation is has_many' do
|
|
512
|
+
around do |example|
|
|
552
513
|
original_drug_dependents = Drug.dependents
|
|
553
514
|
Drug.dependents = []
|
|
554
515
|
example.run
|
|
@@ -558,7 +519,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
558
519
|
before do
|
|
559
520
|
Drug.belongs_to :person, dependent: :destroy
|
|
560
521
|
Person.has_many :drugs
|
|
561
|
-
person.drugs = [drug]
|
|
522
|
+
person.drugs = [ drug ]
|
|
562
523
|
person.save!
|
|
563
524
|
end
|
|
564
525
|
|
|
@@ -567,19 +528,17 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
567
528
|
Person.has_many :drugs, validate: false
|
|
568
529
|
end
|
|
569
530
|
|
|
570
|
-
context
|
|
571
|
-
|
|
572
|
-
context "when child is destroyed" do
|
|
573
|
-
|
|
531
|
+
context 'when parent exists' do
|
|
532
|
+
context 'when child is destroyed' do
|
|
574
533
|
before do
|
|
575
534
|
drug.destroy
|
|
576
535
|
end
|
|
577
536
|
|
|
578
|
-
it
|
|
537
|
+
it 'deletes child' do
|
|
579
538
|
expect(drug).to be_destroyed
|
|
580
539
|
end
|
|
581
540
|
|
|
582
|
-
it
|
|
541
|
+
it 'deletes parent' do
|
|
583
542
|
expect(person).to be_destroyed
|
|
584
543
|
end
|
|
585
544
|
end
|
|
@@ -587,8 +546,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
587
546
|
end
|
|
588
547
|
end
|
|
589
548
|
|
|
590
|
-
context
|
|
591
|
-
|
|
549
|
+
context 'when dependent is delete' do
|
|
592
550
|
let(:account) do
|
|
593
551
|
Account.create!(name: 'Foobar')
|
|
594
552
|
end
|
|
@@ -601,9 +559,8 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
601
559
|
Person.create!
|
|
602
560
|
end
|
|
603
561
|
|
|
604
|
-
context
|
|
605
|
-
|
|
606
|
-
around(:each) do |example|
|
|
562
|
+
context 'when relation is has_one' do
|
|
563
|
+
around do |example|
|
|
607
564
|
original_account_dependents = Account.dependents
|
|
608
565
|
Account.dependents = []
|
|
609
566
|
example.run
|
|
@@ -622,28 +579,25 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
622
579
|
Person.has_one :account, validate: false
|
|
623
580
|
end
|
|
624
581
|
|
|
625
|
-
context
|
|
626
|
-
|
|
627
|
-
context "when child is destroyed" do
|
|
628
|
-
|
|
582
|
+
context 'when parent is persisted' do
|
|
583
|
+
context 'when child is destroyed' do
|
|
629
584
|
before do
|
|
630
585
|
account.destroy
|
|
631
586
|
end
|
|
632
587
|
|
|
633
|
-
it
|
|
588
|
+
it 'deletes child' do
|
|
634
589
|
expect(account).to be_destroyed
|
|
635
590
|
end
|
|
636
591
|
|
|
637
|
-
it
|
|
592
|
+
it 'deletes parent' do
|
|
638
593
|
expect(person).to be_destroyed
|
|
639
594
|
end
|
|
640
595
|
end
|
|
641
596
|
end
|
|
642
597
|
end
|
|
643
598
|
|
|
644
|
-
context
|
|
645
|
-
|
|
646
|
-
around(:each) do |example|
|
|
599
|
+
context 'when relation is has_many' do
|
|
600
|
+
around do |example|
|
|
647
601
|
original_drug_dependents = Drug.dependents
|
|
648
602
|
Drug.dependents = []
|
|
649
603
|
example.run
|
|
@@ -653,7 +607,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
653
607
|
before do
|
|
654
608
|
Drug.belongs_to :person, dependent: :delete_all
|
|
655
609
|
Person.has_many :drugs
|
|
656
|
-
person.drugs = [drug]
|
|
610
|
+
person.drugs = [ drug ]
|
|
657
611
|
person.save!
|
|
658
612
|
end
|
|
659
613
|
|
|
@@ -662,19 +616,17 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
662
616
|
Person.has_many :drugs, validate: false
|
|
663
617
|
end
|
|
664
618
|
|
|
665
|
-
context
|
|
666
|
-
|
|
667
|
-
context "when child is destroyed" do
|
|
668
|
-
|
|
619
|
+
context 'when parent exists' do
|
|
620
|
+
context 'when child is destroyed' do
|
|
669
621
|
before do
|
|
670
622
|
drug.destroy
|
|
671
623
|
end
|
|
672
624
|
|
|
673
|
-
it
|
|
625
|
+
it 'deletes child' do
|
|
674
626
|
expect(drug).to be_destroyed
|
|
675
627
|
end
|
|
676
628
|
|
|
677
|
-
it
|
|
629
|
+
it 'deletes parent' do
|
|
678
630
|
expect(person).to be_destroyed
|
|
679
631
|
end
|
|
680
632
|
end
|
|
@@ -682,8 +634,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
682
634
|
end
|
|
683
635
|
end
|
|
684
636
|
|
|
685
|
-
context
|
|
686
|
-
|
|
637
|
+
context 'when dependent is nullify' do
|
|
687
638
|
let(:account) do
|
|
688
639
|
Account.create!(name: 'Foobar')
|
|
689
640
|
end
|
|
@@ -696,9 +647,8 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
696
647
|
Person.create!
|
|
697
648
|
end
|
|
698
649
|
|
|
699
|
-
context
|
|
700
|
-
|
|
701
|
-
around(:each) do |example|
|
|
650
|
+
context 'when relation is has_one' do
|
|
651
|
+
around do |example|
|
|
702
652
|
original_account_dependents = Account.dependents
|
|
703
653
|
Account.dependents = []
|
|
704
654
|
example.run
|
|
@@ -712,32 +662,29 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
712
662
|
person.save!
|
|
713
663
|
end
|
|
714
664
|
|
|
715
|
-
context
|
|
716
|
-
|
|
717
|
-
context "when child is destroyed" do
|
|
718
|
-
|
|
665
|
+
context 'when parent is persisted' do
|
|
666
|
+
context 'when child is destroyed' do
|
|
719
667
|
before do
|
|
720
668
|
account.destroy
|
|
721
669
|
end
|
|
722
670
|
|
|
723
|
-
it
|
|
671
|
+
it 'deletes child' do
|
|
724
672
|
expect(account).to be_destroyed
|
|
725
673
|
end
|
|
726
674
|
|
|
727
675
|
it "doesn't delete parent" do
|
|
728
|
-
expect(person).
|
|
676
|
+
expect(person).not_to be_destroyed
|
|
729
677
|
end
|
|
730
678
|
|
|
731
|
-
it
|
|
679
|
+
it 'removes the link' do
|
|
732
680
|
expect(person.account).to be_nil
|
|
733
681
|
end
|
|
734
682
|
end
|
|
735
683
|
end
|
|
736
684
|
end
|
|
737
685
|
|
|
738
|
-
context
|
|
739
|
-
|
|
740
|
-
around(:each) do |example|
|
|
686
|
+
context 'when relation is has_many' do
|
|
687
|
+
around do |example|
|
|
741
688
|
original_drug_dependents = Drug.dependents
|
|
742
689
|
Drug.dependents = []
|
|
743
690
|
example.run
|
|
@@ -747,7 +694,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
747
694
|
before do
|
|
748
695
|
Drug.belongs_to :person, dependent: :nullify
|
|
749
696
|
Person.has_many :drugs
|
|
750
|
-
person.drugs = [drug]
|
|
697
|
+
person.drugs = [ drug ]
|
|
751
698
|
person.save!
|
|
752
699
|
end
|
|
753
700
|
|
|
@@ -755,23 +702,21 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
755
702
|
# file. If auto_save_spec.rb runs before this, the following specs fail
|
|
756
703
|
# with "undefined method `nullify' for an instance of Person".
|
|
757
704
|
|
|
758
|
-
context
|
|
759
|
-
|
|
760
|
-
context "when child is destroyed" do
|
|
761
|
-
|
|
705
|
+
context 'when parent exists' do
|
|
706
|
+
context 'when child is destroyed' do
|
|
762
707
|
before do
|
|
763
708
|
drug.destroy
|
|
764
709
|
end
|
|
765
710
|
|
|
766
|
-
it
|
|
711
|
+
it 'deletes child' do
|
|
767
712
|
expect(drug).to be_destroyed
|
|
768
713
|
end
|
|
769
714
|
|
|
770
715
|
it "doesn't deletes parent" do
|
|
771
|
-
expect(person).
|
|
716
|
+
expect(person).not_to be_destroyed
|
|
772
717
|
end
|
|
773
718
|
|
|
774
|
-
it
|
|
719
|
+
it 'removes the link' do
|
|
775
720
|
expect(person.drugs).to eq([])
|
|
776
721
|
end
|
|
777
722
|
end
|
|
@@ -779,14 +724,13 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
779
724
|
end
|
|
780
725
|
end
|
|
781
726
|
|
|
782
|
-
context
|
|
783
|
-
|
|
727
|
+
context 'when the inverse relation has no reference defined' do
|
|
784
728
|
let(:agent) do
|
|
785
|
-
Agent.new(title:
|
|
729
|
+
Agent.new(title: '007')
|
|
786
730
|
end
|
|
787
731
|
|
|
788
732
|
let(:game) do
|
|
789
|
-
Game.new(name:
|
|
733
|
+
Game.new(name: 'Donkey Kong')
|
|
790
734
|
end
|
|
791
735
|
|
|
792
736
|
before do
|
|
@@ -794,21 +738,18 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
794
738
|
agent.game = nil
|
|
795
739
|
end
|
|
796
740
|
|
|
797
|
-
it
|
|
741
|
+
it 'removes the relation' do
|
|
798
742
|
expect(agent.game).to be_nil
|
|
799
743
|
end
|
|
800
744
|
|
|
801
|
-
it
|
|
745
|
+
it 'removes the foreign_key' do
|
|
802
746
|
expect(agent.game_id).to be_nil
|
|
803
747
|
end
|
|
804
748
|
end
|
|
805
749
|
|
|
806
|
-
context
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
context "when the parent is a new record" do
|
|
811
|
-
|
|
750
|
+
context 'when the parent is a references one' do
|
|
751
|
+
context 'when the relation is not polymorphic' do
|
|
752
|
+
context 'when the parent is a new record' do
|
|
812
753
|
let(:person) do
|
|
813
754
|
Person.new
|
|
814
755
|
end
|
|
@@ -822,21 +763,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
822
763
|
game.person = nil
|
|
823
764
|
end
|
|
824
765
|
|
|
825
|
-
it
|
|
766
|
+
it 'sets the relation to nil' do
|
|
826
767
|
expect(game.person).to be_nil
|
|
827
768
|
end
|
|
828
769
|
|
|
829
|
-
it
|
|
770
|
+
it 'removed the inverse relation' do
|
|
830
771
|
expect(person.game).to be_nil
|
|
831
772
|
end
|
|
832
773
|
|
|
833
|
-
it
|
|
774
|
+
it 'removes the foreign key value' do
|
|
834
775
|
expect(game.person_id).to be_nil
|
|
835
776
|
end
|
|
836
777
|
end
|
|
837
778
|
|
|
838
|
-
context
|
|
839
|
-
|
|
779
|
+
context 'when the parent is not a new record' do
|
|
840
780
|
let(:person) do
|
|
841
781
|
Person.create!
|
|
842
782
|
end
|
|
@@ -850,30 +790,27 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
850
790
|
game.person = nil
|
|
851
791
|
end
|
|
852
792
|
|
|
853
|
-
it
|
|
793
|
+
it 'sets the relation to nil' do
|
|
854
794
|
expect(game.person).to be_nil
|
|
855
795
|
end
|
|
856
796
|
|
|
857
|
-
it
|
|
797
|
+
it 'removed the inverse relation' do
|
|
858
798
|
expect(person.game).to be_nil
|
|
859
799
|
end
|
|
860
800
|
|
|
861
|
-
it
|
|
801
|
+
it 'removes the foreign key value' do
|
|
862
802
|
expect(game.person_id).to be_nil
|
|
863
803
|
end
|
|
864
804
|
|
|
865
|
-
it
|
|
866
|
-
expect(game).
|
|
805
|
+
it 'does not delete the child' do
|
|
806
|
+
expect(game).not_to be_destroyed
|
|
867
807
|
end
|
|
868
808
|
end
|
|
869
809
|
end
|
|
870
810
|
|
|
871
|
-
context
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
context "when the parent is a new record" do
|
|
876
|
-
|
|
811
|
+
context 'when the relation is polymorphic' do
|
|
812
|
+
context 'when one relation against the same class exists' do
|
|
813
|
+
context 'when the parent is a new record' do
|
|
877
814
|
let(:bar) do
|
|
878
815
|
Bar.new
|
|
879
816
|
end
|
|
@@ -887,21 +824,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
887
824
|
rating.ratable = nil
|
|
888
825
|
end
|
|
889
826
|
|
|
890
|
-
it
|
|
827
|
+
it 'sets the relation to nil' do
|
|
891
828
|
expect(rating.ratable).to be_nil
|
|
892
829
|
end
|
|
893
830
|
|
|
894
|
-
it
|
|
831
|
+
it 'removed the inverse relation' do
|
|
895
832
|
expect(bar.rating).to be_nil
|
|
896
833
|
end
|
|
897
834
|
|
|
898
|
-
it
|
|
835
|
+
it 'removes the foreign key value' do
|
|
899
836
|
expect(rating.ratable_id).to be_nil
|
|
900
837
|
end
|
|
901
838
|
end
|
|
902
839
|
|
|
903
|
-
context
|
|
904
|
-
|
|
840
|
+
context 'when the parent is not a new record' do
|
|
905
841
|
let(:bar) do
|
|
906
842
|
Bar.new
|
|
907
843
|
end
|
|
@@ -915,15 +851,15 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
915
851
|
rating.ratable = nil
|
|
916
852
|
end
|
|
917
853
|
|
|
918
|
-
it
|
|
854
|
+
it 'sets the relation to nil' do
|
|
919
855
|
expect(rating.ratable).to be_nil
|
|
920
856
|
end
|
|
921
857
|
|
|
922
|
-
it
|
|
858
|
+
it 'removed the inverse relation' do
|
|
923
859
|
expect(bar.rating).to be_nil
|
|
924
860
|
end
|
|
925
861
|
|
|
926
|
-
it
|
|
862
|
+
it 'removes the foreign key value' do
|
|
927
863
|
expect(rating.ratable_id).to be_nil
|
|
928
864
|
end
|
|
929
865
|
end
|
|
@@ -931,12 +867,9 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
931
867
|
end
|
|
932
868
|
end
|
|
933
869
|
|
|
934
|
-
context
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
context "when the parent is a new record" do
|
|
939
|
-
|
|
870
|
+
context 'when the parent is a references many' do
|
|
871
|
+
context 'when the relation is not polymorphic' do
|
|
872
|
+
context 'when the parent is a new record' do
|
|
940
873
|
let(:person) do
|
|
941
874
|
Person.new
|
|
942
875
|
end
|
|
@@ -950,21 +883,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
950
883
|
post.person = nil
|
|
951
884
|
end
|
|
952
885
|
|
|
953
|
-
it
|
|
886
|
+
it 'sets the relation to nil' do
|
|
954
887
|
expect(post.person).to be_nil
|
|
955
888
|
end
|
|
956
889
|
|
|
957
|
-
it
|
|
890
|
+
it 'removed the inverse relation' do
|
|
958
891
|
expect(person.posts).to be_empty
|
|
959
892
|
end
|
|
960
893
|
|
|
961
|
-
it
|
|
894
|
+
it 'removes the foreign key value' do
|
|
962
895
|
expect(post.person_id).to be_nil
|
|
963
896
|
end
|
|
964
897
|
end
|
|
965
898
|
|
|
966
|
-
context
|
|
967
|
-
|
|
899
|
+
context 'when the parent is not a new record' do
|
|
968
900
|
let(:person) do
|
|
969
901
|
Person.new
|
|
970
902
|
end
|
|
@@ -978,24 +910,22 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
978
910
|
post.person = nil
|
|
979
911
|
end
|
|
980
912
|
|
|
981
|
-
it
|
|
913
|
+
it 'sets the relation to nil' do
|
|
982
914
|
expect(post.person).to be_nil
|
|
983
915
|
end
|
|
984
916
|
|
|
985
|
-
it
|
|
917
|
+
it 'removed the inverse relation' do
|
|
986
918
|
expect(person.posts).to be_empty
|
|
987
919
|
end
|
|
988
920
|
|
|
989
|
-
it
|
|
921
|
+
it 'removes the foreign key value' do
|
|
990
922
|
expect(post.person_id).to be_nil
|
|
991
923
|
end
|
|
992
924
|
end
|
|
993
925
|
end
|
|
994
926
|
|
|
995
|
-
context
|
|
996
|
-
|
|
997
|
-
context "when the parent is a new record" do
|
|
998
|
-
|
|
927
|
+
context 'when the relation is polymorphic' do
|
|
928
|
+
context 'when the parent is a new record' do
|
|
999
929
|
let(:movie) do
|
|
1000
930
|
Movie.new
|
|
1001
931
|
end
|
|
@@ -1009,21 +939,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1009
939
|
rating.ratable = nil
|
|
1010
940
|
end
|
|
1011
941
|
|
|
1012
|
-
it
|
|
942
|
+
it 'sets the relation to nil' do
|
|
1013
943
|
expect(rating.ratable).to be_nil
|
|
1014
944
|
end
|
|
1015
945
|
|
|
1016
|
-
it
|
|
946
|
+
it 'removed the inverse relation' do
|
|
1017
947
|
expect(movie.ratings).to be_empty
|
|
1018
948
|
end
|
|
1019
949
|
|
|
1020
|
-
it
|
|
950
|
+
it 'removes the foreign key value' do
|
|
1021
951
|
expect(rating.ratable_id).to be_nil
|
|
1022
952
|
end
|
|
1023
953
|
end
|
|
1024
954
|
|
|
1025
|
-
context
|
|
1026
|
-
|
|
955
|
+
context 'when the parent is not a new record' do
|
|
1027
956
|
let(:movie) do
|
|
1028
957
|
Movie.new
|
|
1029
958
|
end
|
|
@@ -1037,15 +966,15 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1037
966
|
rating.ratable = nil
|
|
1038
967
|
end
|
|
1039
968
|
|
|
1040
|
-
it
|
|
969
|
+
it 'sets the relation to nil' do
|
|
1041
970
|
expect(rating.ratable).to be_nil
|
|
1042
971
|
end
|
|
1043
972
|
|
|
1044
|
-
it
|
|
973
|
+
it 'removed the inverse relation' do
|
|
1045
974
|
expect(movie.ratings).to be_empty
|
|
1046
975
|
end
|
|
1047
976
|
|
|
1048
|
-
it
|
|
977
|
+
it 'removes the foreign key value' do
|
|
1049
978
|
expect(rating.ratable_id).to be_nil
|
|
1050
979
|
end
|
|
1051
980
|
end
|
|
@@ -1053,14 +982,13 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1053
982
|
end
|
|
1054
983
|
end
|
|
1055
984
|
|
|
1056
|
-
describe
|
|
1057
|
-
|
|
985
|
+
describe '#respond_to?' do
|
|
1058
986
|
let(:person) do
|
|
1059
987
|
Person.new
|
|
1060
988
|
end
|
|
1061
989
|
|
|
1062
990
|
let(:game) do
|
|
1063
|
-
person.build_game(name:
|
|
991
|
+
person.build_game(name: 'Tron')
|
|
1064
992
|
end
|
|
1065
993
|
|
|
1066
994
|
let(:document) do
|
|
@@ -1068,58 +996,56 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1068
996
|
end
|
|
1069
997
|
|
|
1070
998
|
Mongoid::Document.public_instance_methods(true).each do |method|
|
|
1071
|
-
|
|
1072
999
|
context "when checking #{method}" do
|
|
1073
|
-
|
|
1074
|
-
it "returns true" do
|
|
1000
|
+
it 'returns true' do
|
|
1075
1001
|
expect(document.respond_to?(method)).to be true
|
|
1076
1002
|
end
|
|
1077
1003
|
end
|
|
1078
1004
|
end
|
|
1079
1005
|
end
|
|
1080
1006
|
|
|
1081
|
-
context
|
|
1082
|
-
|
|
1007
|
+
context 'when the relation is self referencing' do
|
|
1083
1008
|
let(:game_one) do
|
|
1084
|
-
Game.new(name:
|
|
1009
|
+
Game.new(name: 'Diablo')
|
|
1085
1010
|
end
|
|
1086
1011
|
|
|
1087
1012
|
let(:game_two) do
|
|
1088
|
-
Game.new(name:
|
|
1013
|
+
Game.new(name: 'Warcraft')
|
|
1089
1014
|
end
|
|
1090
1015
|
|
|
1091
|
-
context
|
|
1092
|
-
|
|
1016
|
+
context 'when setting the parent' do
|
|
1093
1017
|
before do
|
|
1094
1018
|
game_one.parent = game_two
|
|
1095
1019
|
end
|
|
1096
1020
|
|
|
1097
|
-
it
|
|
1021
|
+
it 'sets the parent' do
|
|
1098
1022
|
expect(game_one.parent).to eq(game_two)
|
|
1099
1023
|
end
|
|
1100
1024
|
|
|
1101
|
-
it
|
|
1025
|
+
it 'does not set the parent recursively' do
|
|
1102
1026
|
expect(game_two.parent).to be_nil
|
|
1103
1027
|
end
|
|
1104
1028
|
end
|
|
1105
1029
|
end
|
|
1106
1030
|
|
|
1107
|
-
context
|
|
1108
|
-
|
|
1031
|
+
context 'when the relation belongs to a has many and has one' do
|
|
1109
1032
|
before(:all) do
|
|
1110
1033
|
class A
|
|
1111
1034
|
include Mongoid::Document
|
|
1035
|
+
|
|
1112
1036
|
has_many :bs, inverse_of: :a
|
|
1113
1037
|
end
|
|
1114
1038
|
|
|
1115
1039
|
class B
|
|
1116
1040
|
include Mongoid::Document
|
|
1041
|
+
|
|
1117
1042
|
belongs_to :a, inverse_of: :bs
|
|
1118
1043
|
belongs_to :c, inverse_of: :b
|
|
1119
1044
|
end
|
|
1120
1045
|
|
|
1121
1046
|
class C
|
|
1122
1047
|
include Mongoid::Document
|
|
1048
|
+
|
|
1123
1049
|
has_one :b, inverse_of: :c
|
|
1124
1050
|
end
|
|
1125
1051
|
end
|
|
@@ -1130,8 +1056,7 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1130
1056
|
Object.send(:remove_const, :C)
|
|
1131
1057
|
end
|
|
1132
1058
|
|
|
1133
|
-
context
|
|
1134
|
-
|
|
1059
|
+
context 'when setting the has one' do
|
|
1135
1060
|
let(:a) do
|
|
1136
1061
|
A.new
|
|
1137
1062
|
end
|
|
@@ -1148,19 +1073,17 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1148
1073
|
b.c = c
|
|
1149
1074
|
end
|
|
1150
1075
|
|
|
1151
|
-
context
|
|
1152
|
-
|
|
1076
|
+
context 'when subsequently setting the has many' do
|
|
1153
1077
|
before do
|
|
1154
1078
|
b.a = a
|
|
1155
1079
|
end
|
|
1156
1080
|
|
|
1157
|
-
context
|
|
1158
|
-
|
|
1081
|
+
context 'when setting the has one again' do
|
|
1159
1082
|
before do
|
|
1160
1083
|
b.c = c
|
|
1161
1084
|
end
|
|
1162
1085
|
|
|
1163
|
-
it
|
|
1086
|
+
it 'allows the reset of the has one' do
|
|
1164
1087
|
expect(b.c).to eq(c)
|
|
1165
1088
|
end
|
|
1166
1089
|
end
|
|
@@ -1168,18 +1091,17 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1168
1091
|
end
|
|
1169
1092
|
end
|
|
1170
1093
|
|
|
1171
|
-
context
|
|
1172
|
-
|
|
1094
|
+
context 'when replacing the relation with another' do
|
|
1173
1095
|
let!(:person) do
|
|
1174
1096
|
Person.create!
|
|
1175
1097
|
end
|
|
1176
1098
|
|
|
1177
1099
|
let!(:post) do
|
|
1178
|
-
Post.create!(title:
|
|
1100
|
+
Post.create!(title: 'test')
|
|
1179
1101
|
end
|
|
1180
1102
|
|
|
1181
1103
|
let!(:game) do
|
|
1182
|
-
person.create_game(name:
|
|
1104
|
+
person.create_game(name: 'Tron')
|
|
1183
1105
|
end
|
|
1184
1106
|
|
|
1185
1107
|
before do
|
|
@@ -1187,85 +1109,81 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1187
1109
|
post.save!
|
|
1188
1110
|
end
|
|
1189
1111
|
|
|
1190
|
-
it
|
|
1112
|
+
it 'clones the relation' do
|
|
1191
1113
|
expect(post.person).to eq(person)
|
|
1192
1114
|
end
|
|
1193
1115
|
|
|
1194
|
-
it
|
|
1116
|
+
it 'sets the foreign key' do
|
|
1195
1117
|
expect(post.person_id).to eq(person.id)
|
|
1196
1118
|
end
|
|
1197
1119
|
|
|
1198
|
-
it
|
|
1120
|
+
it 'does not remove the previous relation' do
|
|
1199
1121
|
expect(game.person).to eq(person)
|
|
1200
1122
|
end
|
|
1201
1123
|
|
|
1202
|
-
it
|
|
1124
|
+
it 'does not remove the previous foreign key' do
|
|
1203
1125
|
expect(game.person_id).to eq(person.id)
|
|
1204
1126
|
end
|
|
1205
1127
|
|
|
1206
|
-
context
|
|
1207
|
-
|
|
1128
|
+
context 'when reloading' do
|
|
1208
1129
|
before do
|
|
1209
1130
|
post.reload
|
|
1210
1131
|
game.reload
|
|
1211
1132
|
end
|
|
1212
1133
|
|
|
1213
|
-
it
|
|
1134
|
+
it 'persists the relation' do
|
|
1214
1135
|
expect(post.reload.person).to eq(person)
|
|
1215
1136
|
end
|
|
1216
1137
|
|
|
1217
|
-
it
|
|
1138
|
+
it 'persists the foreign key' do
|
|
1218
1139
|
expect(post.reload.person_id).to eq(game.person_id)
|
|
1219
1140
|
end
|
|
1220
1141
|
|
|
1221
|
-
it
|
|
1142
|
+
it 'does not remove the previous relation' do
|
|
1222
1143
|
expect(game.person).to eq(person)
|
|
1223
1144
|
end
|
|
1224
1145
|
|
|
1225
|
-
it
|
|
1146
|
+
it 'does not remove the previous foreign key' do
|
|
1226
1147
|
expect(game.person_id).to eq(person.id)
|
|
1227
1148
|
end
|
|
1228
1149
|
end
|
|
1229
1150
|
end
|
|
1230
1151
|
|
|
1231
|
-
context
|
|
1232
|
-
|
|
1152
|
+
context 'when the document belongs to a has one and has many' do
|
|
1233
1153
|
let(:movie) do
|
|
1234
|
-
Movie.create!(name:
|
|
1154
|
+
Movie.create!(name: 'Infernal Affairs')
|
|
1235
1155
|
end
|
|
1236
1156
|
|
|
1237
1157
|
let(:account) do
|
|
1238
|
-
Account.create!(name:
|
|
1158
|
+
Account.create!(name: 'Leung')
|
|
1239
1159
|
end
|
|
1240
1160
|
|
|
1241
|
-
context
|
|
1242
|
-
|
|
1161
|
+
context 'when creating the document' do
|
|
1243
1162
|
let(:comment) do
|
|
1244
1163
|
Comment.create!(title: 'My Title', movie: movie, account: account)
|
|
1245
1164
|
end
|
|
1246
1165
|
|
|
1247
|
-
it
|
|
1166
|
+
it 'sets the correct has one' do
|
|
1248
1167
|
expect(comment.account).to eq(account)
|
|
1249
1168
|
end
|
|
1250
1169
|
|
|
1251
|
-
it
|
|
1170
|
+
it 'sets the correct has many' do
|
|
1252
1171
|
expect(comment.movie).to eq(movie)
|
|
1253
1172
|
end
|
|
1254
1173
|
end
|
|
1255
1174
|
end
|
|
1256
1175
|
|
|
1257
|
-
context
|
|
1258
|
-
|
|
1176
|
+
context 'when reloading the relation' do
|
|
1259
1177
|
let!(:person_one) do
|
|
1260
1178
|
Person.create!
|
|
1261
1179
|
end
|
|
1262
1180
|
|
|
1263
1181
|
let!(:person_two) do
|
|
1264
|
-
Person.create!(title:
|
|
1182
|
+
Person.create!(title: 'Sir')
|
|
1265
1183
|
end
|
|
1266
1184
|
|
|
1267
1185
|
let!(:game) do
|
|
1268
|
-
Game.create!(name:
|
|
1186
|
+
Game.create!(name: 'Starcraft 2')
|
|
1269
1187
|
end
|
|
1270
1188
|
|
|
1271
1189
|
before do
|
|
@@ -1273,28 +1191,26 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1273
1191
|
game.save!
|
|
1274
1192
|
end
|
|
1275
1193
|
|
|
1276
|
-
context
|
|
1277
|
-
|
|
1194
|
+
context 'when the relation references the same document' do
|
|
1278
1195
|
before do
|
|
1279
|
-
Person.collection.find({ _id: person_one.id })
|
|
1280
|
-
|
|
1196
|
+
Person.collection.find({ _id: person_one.id })
|
|
1197
|
+
.update_one({ '$set' => { title: 'Madam' } })
|
|
1281
1198
|
end
|
|
1282
1199
|
|
|
1283
1200
|
let(:reloaded) do
|
|
1284
1201
|
game.person(true)
|
|
1285
1202
|
end
|
|
1286
1203
|
|
|
1287
|
-
it
|
|
1288
|
-
expect(reloaded.title).to eq(
|
|
1204
|
+
it 'reloads the document from the database' do
|
|
1205
|
+
expect(reloaded.title).to eq('Madam')
|
|
1289
1206
|
end
|
|
1290
1207
|
|
|
1291
|
-
it
|
|
1292
|
-
expect(reloaded).
|
|
1208
|
+
it 'sets a new document instance' do
|
|
1209
|
+
expect(reloaded).not_to equal(person_one)
|
|
1293
1210
|
end
|
|
1294
1211
|
end
|
|
1295
1212
|
|
|
1296
|
-
context
|
|
1297
|
-
|
|
1213
|
+
context 'when the relation references a different document' do
|
|
1298
1214
|
before do
|
|
1299
1215
|
game.person_id = person_two.id
|
|
1300
1216
|
game.save!
|
|
@@ -1304,18 +1220,17 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1304
1220
|
game.person(true)
|
|
1305
1221
|
end
|
|
1306
1222
|
|
|
1307
|
-
it
|
|
1308
|
-
expect(reloaded.title).to eq(
|
|
1223
|
+
it 'reloads the new document from the database' do
|
|
1224
|
+
expect(reloaded.title).to eq('Sir')
|
|
1309
1225
|
end
|
|
1310
1226
|
|
|
1311
|
-
it
|
|
1312
|
-
expect(reloaded).
|
|
1227
|
+
it 'sets a new document instance' do
|
|
1228
|
+
expect(reloaded).not_to equal(person_one)
|
|
1313
1229
|
end
|
|
1314
1230
|
end
|
|
1315
1231
|
end
|
|
1316
1232
|
|
|
1317
|
-
context
|
|
1318
|
-
|
|
1233
|
+
context 'when creating with a reference to an integer id parent' do
|
|
1319
1234
|
let!(:jar) do
|
|
1320
1235
|
Jar.create! do |doc|
|
|
1321
1236
|
doc._id = 1
|
|
@@ -1323,22 +1238,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1323
1238
|
end
|
|
1324
1239
|
|
|
1325
1240
|
let(:cookie) do
|
|
1326
|
-
Cookie.create!(jar_id:
|
|
1241
|
+
Cookie.create!(jar_id: '1')
|
|
1327
1242
|
end
|
|
1328
1243
|
|
|
1329
|
-
it
|
|
1244
|
+
it 'allows strings to be passed as the id' do
|
|
1330
1245
|
expect(cookie.jar).to eq(jar)
|
|
1331
1246
|
end
|
|
1332
1247
|
|
|
1333
|
-
it
|
|
1248
|
+
it 'persists the relation' do
|
|
1334
1249
|
expect(cookie.reload.jar).to eq(jar)
|
|
1335
1250
|
end
|
|
1336
1251
|
end
|
|
1337
1252
|
|
|
1338
|
-
context
|
|
1339
|
-
|
|
1340
|
-
context "when the relation exists" do
|
|
1341
|
-
|
|
1253
|
+
context 'when setting the relation via the foreign key' do
|
|
1254
|
+
context 'when the relation exists' do
|
|
1342
1255
|
let!(:person_one) do
|
|
1343
1256
|
Person.create!
|
|
1344
1257
|
end
|
|
@@ -1355,20 +1268,20 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1355
1268
|
game.person_id = person_two.id
|
|
1356
1269
|
end
|
|
1357
1270
|
|
|
1358
|
-
it
|
|
1271
|
+
it 'sets the new document on the relation' do
|
|
1359
1272
|
expect(game.person).to eq(person_two)
|
|
1360
1273
|
end
|
|
1361
1274
|
end
|
|
1362
1275
|
end
|
|
1363
1276
|
|
|
1364
|
-
describe
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1277
|
+
describe '#method_missing' do
|
|
1278
|
+
let!(:person) do
|
|
1279
|
+
Person.create!
|
|
1280
|
+
end
|
|
1368
1281
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1282
|
+
let!(:game) do
|
|
1283
|
+
Game.create!(person: person)
|
|
1284
|
+
end
|
|
1372
1285
|
|
|
1373
1286
|
it 'handles keyword args' do
|
|
1374
1287
|
expect do
|
|
@@ -1378,16 +1291,16 @@ describe Mongoid::Association::Referenced::BelongsTo::Proxy do
|
|
|
1378
1291
|
end
|
|
1379
1292
|
|
|
1380
1293
|
# This is a very specific case, see MONGOID-5089 for more details.
|
|
1381
|
-
context
|
|
1294
|
+
context 'when required is false, child is an orphan, and parent has explicit _id' do
|
|
1382
1295
|
let(:comment) { BTMComment.create! }
|
|
1383
1296
|
let(:article) do
|
|
1384
1297
|
BTMArticle.new(
|
|
1385
|
-
comment_ids: [comment.id],
|
|
1298
|
+
comment_ids: [ comment.id ],
|
|
1386
1299
|
id: 1
|
|
1387
1300
|
)
|
|
1388
1301
|
end
|
|
1389
1302
|
|
|
1390
|
-
it
|
|
1303
|
+
it 'uses the correct explicit id' do
|
|
1391
1304
|
expect(article.comments.first.article_id).to eq(1)
|
|
1392
1305
|
end
|
|
1393
1306
|
end
|