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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0182a5e78d9fecbf490a537bd4dcf5aba640683c566b400ff7c70b189201372f'
|
|
4
|
+
data.tar.gz: d194627c4d001e4b420652d52a8612e6f4c4209948259f3d1f4b33de4257920b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0e2447ca53e3ac80aee5a4a29dc9fe45110ded5f35a6e25569b9aca9e34a1f48060ef17a2dc9257f4d4d5ec3d07d725679a1f83e6850fa24edb32099b471ff2
|
|
7
|
+
data.tar.gz: b41c4d87a55e8ba10c90b1998f36280021793c6c4816d54259642a29a23f39201afb5c272cf473545f0b14a47ea609e6be8b8b35e68ee5e39076c1f2ceaa64f1
|
data/CHANGELOG.md
CHANGED
|
@@ -105,7 +105,7 @@ For instructions on upgrading to newer versions, visit
|
|
|
105
105
|
|
|
106
106
|
* \#4005 Fixed inclusion of mongoid with Rails components that don't have the Rails environment.
|
|
107
107
|
|
|
108
|
-
* \#3993 Fixes issue where `dup`/`clone` fails for embedded documents that use store_as without using Mongoid::
|
|
108
|
+
* \#3993 Fixes issue where `dup`/`clone` fails for embedded documents that use store_as without using Mongoid::Attributes::Dynamic
|
|
109
109
|
|
|
110
110
|
* \#3991 Fixed embedded documents not flagging as changed after calling #changed? and modifying the
|
|
111
111
|
child elements.
|
|
@@ -798,7 +798,7 @@ child elements.
|
|
|
798
798
|
Band.where(name: "Placebo").unset(:members, :origin)
|
|
799
799
|
|
|
800
800
|
* \#2669 Passing a block to `Criteria#new` now properly sends the
|
|
801
|
-
block through to the model's
|
|
801
|
+
block through to the model's constructor. (Arthur Neves)
|
|
802
802
|
|
|
803
803
|
* \#2667 `exists?` no longer hits the database in cases where we have
|
|
804
804
|
the necessary information in memory.
|
|
@@ -1200,7 +1200,7 @@ child elements.
|
|
|
1200
1200
|
|
|
1201
1201
|
* \#2571 Remove blank error message from locales. (Jordan Elver)
|
|
1202
1202
|
|
|
1203
|
-
* \#2568 Fix uniqueness validation for
|
|
1203
|
+
* \#2568 Fix uniqueness validation for localized fields when a scope is also
|
|
1204
1204
|
provided.
|
|
1205
1205
|
|
|
1206
1206
|
* \#2552 Ensure `InvalidPath` errors are raised when embedded documents try to
|
|
@@ -1609,7 +1609,7 @@ child elements.
|
|
|
1609
1609
|
|
|
1610
1610
|
Band.first.touch
|
|
1611
1611
|
|
|
1612
|
-
Update a specific time field along with the
|
|
1612
|
+
Update a specific time field along with the updated_at.
|
|
1613
1613
|
|
|
1614
1614
|
Band.first.touch(:founded)
|
|
1615
1615
|
|
|
@@ -1728,7 +1728,7 @@ child elements.
|
|
|
1728
1728
|
# { "name" => "foo", "my_preferences" => [{ "value" => "ok" }]}
|
|
1729
1729
|
|
|
1730
1730
|
* \#1806 `Model.find_or_create_by` and `Model.find_or_initialize_by` can now
|
|
1731
|
-
take documents as
|
|
1731
|
+
take documents as parameters for belongs_to relations.
|
|
1732
1732
|
|
|
1733
1733
|
person = Person.first
|
|
1734
1734
|
Game.find_or_create_by(person: person)
|
|
@@ -2506,7 +2506,7 @@ child elements.
|
|
|
2506
2506
|
* \#2038 Allow inverse relations to be determined by foreign keys alone
|
|
2507
2507
|
if defined on both sides, not just an inverse_of declaration.
|
|
2508
2508
|
|
|
2509
|
-
* \#2023 Allow
|
|
2509
|
+
* \#2023 Allow serialization of dynamic types that conflict with core
|
|
2510
2510
|
Ruby methods to still be serialized.
|
|
2511
2511
|
|
|
2512
2512
|
* \#2008 Presence validation should hit the db to check validity if the
|
|
@@ -2611,7 +2611,7 @@ child elements.
|
|
|
2611
2611
|
had the foreign key link persisted.
|
|
2612
2612
|
|
|
2613
2613
|
* \#1820 Destroying embedded documents in an embeds_many should also
|
|
2614
|
-
removed the document from the underlying
|
|
2614
|
+
removed the document from the underlying _unscoped target and reindex
|
|
2615
2615
|
the relation.
|
|
2616
2616
|
|
|
2617
2617
|
* \#1814 Don't cascade callbacks on after_initialize.
|
|
@@ -3059,7 +3059,7 @@ child elements.
|
|
|
3059
3059
|
key without error.
|
|
3060
3060
|
|
|
3061
3061
|
* \#1350, \#1351 Fixed errors in the string conversions of double quotes and
|
|
3062
|
-
tilde when
|
|
3062
|
+
tilde when parametrizing keys.
|
|
3063
3063
|
|
|
3064
3064
|
* \#1349 Mongoid documents should not blow up when including Enumerable.
|
|
3065
3065
|
(Jonas Nicklas)
|
data/README.md
CHANGED
|
@@ -8,13 +8,9 @@ Mongoid is an ODM (Object-Document Mapper) framework for MongoDB in Ruby.
|
|
|
8
8
|
Documentation
|
|
9
9
|
-------------
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
[API documentation](https://www.mongodb.com/docs/mongoid/current/api/)
|
|
13
|
-
|
|
14
|
-
Mongoid is built on top of the MongoDB Ruby driver which has
|
|
15
|
-
[its own user documentation](https://www.mongodb.com/docs/ruby-driver/current/).
|
|
16
|
-
|
|
17
|
-
High-level Mongoid documentation including tutorials and the reference that were in the docs folder can now be found at the docs-mongoid repository, [here](https://github.com/mongodb/docs-mongoid).
|
|
11
|
+
* [User documentation](https://www.mongodb.com/docs/mongoid/current/)
|
|
12
|
+
* [API documentation](https://www.mongodb.com/docs/mongoid/current/api/)
|
|
13
|
+
* [Ruby driver documentation](https://www.mongodb.com/docs/ruby-driver/current/) (which Mongoid is built on top of)
|
|
18
14
|
|
|
19
15
|
Compatibility
|
|
20
16
|
-------------
|
|
@@ -28,20 +24,18 @@ Mongoid supports and is tested against:
|
|
|
28
24
|
Issues
|
|
29
25
|
------
|
|
30
26
|
|
|
31
|
-
Please use the [MONGOID project](https://jira.mongodb.org/browse/MONGOID/)
|
|
32
|
-
in MongoDB JIRA to report issues with Mongoid.
|
|
27
|
+
Please use the [MONGOID project](https://jira.mongodb.org/browse/MONGOID/) in MongoDB JIRA to report issues with Mongoid.
|
|
33
28
|
|
|
34
29
|
Support
|
|
35
30
|
-------
|
|
36
31
|
|
|
37
32
|
* [Stack Overflow](http://stackoverflow.com/questions/tagged/mongoid)
|
|
38
33
|
* [MongoDB Community Forum](https://developer.mongodb.com/community/forums/tags/c/drivers-odms-connectors/7/mongoid-odm)
|
|
39
|
-
* [#mongoid](http://webchat.freenode.net/?channels=mongoid) on Freenode IRC
|
|
40
34
|
|
|
41
35
|
License
|
|
42
36
|
-------
|
|
43
37
|
|
|
44
|
-
Copyright (c) 2015-Present MongoDB Inc.
|
|
38
|
+
Copyright (c) 2015-Present MongoDB Inc. \
|
|
45
39
|
Copyright (c) 2009-2016 Durran Jordan
|
|
46
40
|
|
|
47
41
|
Permission is hereby granted, free of charge, to any person obtaining
|
data/Rakefile
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'bundler'
|
|
5
4
|
Bundler.setup
|
|
6
5
|
|
|
7
6
|
ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
|
|
8
7
|
|
|
9
8
|
$: << File.join(ROOT, 'spec/shared/lib')
|
|
10
9
|
|
|
11
|
-
require
|
|
12
|
-
require
|
|
10
|
+
require 'rake'
|
|
11
|
+
require 'rspec/core/rake_task'
|
|
13
12
|
|
|
14
|
-
if File.exist?('./spec/shared/lib/tasks/candidate.rake')
|
|
15
|
-
load 'spec/shared/lib/tasks/candidate.rake'
|
|
16
|
-
end
|
|
13
|
+
load 'spec/shared/lib/tasks/candidate.rake' if File.exist?('./spec/shared/lib/tasks/candidate.rake')
|
|
17
14
|
|
|
18
15
|
desc 'Build the gem'
|
|
19
16
|
task :build do
|
|
@@ -26,9 +23,9 @@ end
|
|
|
26
23
|
# `rake version` is used by the deployment system so get the release version
|
|
27
24
|
# of the product beng deployed. It must do nothing more than just print the
|
|
28
25
|
# product version number.
|
|
29
|
-
#
|
|
26
|
+
#
|
|
30
27
|
# See the mongodb-labs/driver-github-tools/ruby/publish Github action.
|
|
31
|
-
desc
|
|
28
|
+
desc 'Print the current value of Mongoid::VERSION'
|
|
32
29
|
task :version do
|
|
33
30
|
require 'mongoid/version'
|
|
34
31
|
|
|
@@ -59,13 +56,13 @@ task :release do
|
|
|
59
56
|
system 'gem', 'push', "mongoid-#{Mongoid::VERSION}.gem"
|
|
60
57
|
end
|
|
61
58
|
|
|
62
|
-
RSpec::Core::RakeTask.new(
|
|
63
|
-
spec.pattern =
|
|
59
|
+
RSpec::Core::RakeTask.new('spec') do |spec|
|
|
60
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
64
61
|
end
|
|
65
62
|
|
|
66
63
|
RSpec::Core::RakeTask.new('spec:progress') do |spec|
|
|
67
|
-
spec.rspec_opts = %w
|
|
68
|
-
spec.pattern =
|
|
64
|
+
spec.rspec_opts = %w[--format progress]
|
|
65
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
69
66
|
end
|
|
70
67
|
|
|
71
68
|
RUBOCOPABLE = %w[ examples gemfiles perf lib spec mongoid.gemspec Gemfile Rakefile upload-api-docs ].freeze
|
|
@@ -140,18 +137,18 @@ namespace :generate do
|
|
|
140
137
|
end
|
|
141
138
|
|
|
142
139
|
CLASSIFIERS = [
|
|
143
|
-
[%r
|
|
144
|
-
[%r
|
|
145
|
-
[%r
|
|
146
|
-
[
|
|
147
|
-
[
|
|
148
|
-
[
|
|
140
|
+
[ %r{^mongoid/attribute}, :attributes ],
|
|
141
|
+
[ %r{^mongoid/association/[or]}, :associations_referenced ],
|
|
142
|
+
[ %r{^mongoid/association}, :associations ],
|
|
143
|
+
[ /^mongoid/, :unit ],
|
|
144
|
+
[ /^integration/, :integration ],
|
|
145
|
+
[ /^rails/, :rails ]
|
|
149
146
|
]
|
|
150
147
|
|
|
151
|
-
RUN_PRIORITY = %i
|
|
148
|
+
RUN_PRIORITY = %i[
|
|
152
149
|
unit attributes associations_referenced associations
|
|
153
150
|
integration rails
|
|
154
|
-
|
|
151
|
+
]
|
|
155
152
|
|
|
156
153
|
def spec_organizer
|
|
157
154
|
require 'mrss/spec_organizer'
|
|
@@ -159,7 +156,7 @@ def spec_organizer
|
|
|
159
156
|
Mrss::SpecOrganizer.new(
|
|
160
157
|
root: ROOT,
|
|
161
158
|
classifiers: CLASSIFIERS,
|
|
162
|
-
priority_order: RUN_PRIORITY
|
|
159
|
+
priority_order: RUN_PRIORITY
|
|
163
160
|
)
|
|
164
161
|
end
|
|
165
162
|
|
|
@@ -167,31 +164,31 @@ task :ci do
|
|
|
167
164
|
spec_organizer.run
|
|
168
165
|
end
|
|
169
166
|
|
|
170
|
-
task :bucket, %i
|
|
167
|
+
task :bucket, %i[buckets] do |_task, args|
|
|
171
168
|
buckets = args[:buckets]
|
|
172
169
|
buckets = if buckets.nil? || buckets.empty?
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
170
|
+
[ nil ]
|
|
171
|
+
else
|
|
172
|
+
buckets.split(':').map do |bucket|
|
|
173
|
+
if bucket.empty?
|
|
174
|
+
nil
|
|
175
|
+
else
|
|
176
|
+
bucket.to_sym
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
183
180
|
spec_organizer.run_buckets(*buckets)
|
|
184
181
|
end
|
|
185
182
|
|
|
186
|
-
task :
|
|
183
|
+
task default: :spec
|
|
187
184
|
|
|
188
|
-
desc
|
|
189
|
-
task :
|
|
185
|
+
desc 'Generate all documentation'
|
|
186
|
+
task docs: 'docs:yard'
|
|
190
187
|
|
|
191
188
|
namespace :docs do
|
|
192
|
-
desc
|
|
189
|
+
desc 'Generate yard documentation'
|
|
193
190
|
task :yard do
|
|
194
|
-
require
|
|
191
|
+
require 'mongoid/version'
|
|
195
192
|
|
|
196
193
|
out = File.join('yard-docs', Mongoid::VERSION)
|
|
197
194
|
FileUtils.rm_rf(out)
|
data/lib/config/locales/en.yml
CHANGED
|
@@ -712,6 +712,17 @@ en:
|
|
|
712
712
|
the expression %{javascript} is not allowed."
|
|
713
713
|
resolution: "Please provide a standard hash to #where when the criteria
|
|
714
714
|
is for an embedded association."
|
|
715
|
+
unsupported_isolation_level:
|
|
716
|
+
message: "The isolation level '%{level}' is not supported."
|
|
717
|
+
summary: >
|
|
718
|
+
You requested an isolation level of '%{level}', which is not
|
|
719
|
+
supported. Only `:rails`, `:thread` and `:fiber` isolation
|
|
720
|
+
levels are currently supported; note that the `:fiber` level is
|
|
721
|
+
only supported on Ruby versions 3.2 and higher.
|
|
722
|
+
resolution: >
|
|
723
|
+
Use `:thread` as the isolation level. If you are using Ruby 3.2
|
|
724
|
+
or higher, you may also use `:fiber`. If using Rails 7+, you
|
|
725
|
+
may also use `:rails` to inherit the isolation level from Rails.
|
|
715
726
|
validations:
|
|
716
727
|
message: "Validation of %{document} failed."
|
|
717
728
|
summary: "The following errors were found: %{errors}"
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
module Mongoid
|
|
5
4
|
module Association
|
|
6
|
-
|
|
7
5
|
# This module contains all the behavior related to accessing associations
|
|
8
6
|
# through the getters and setters, and how to delegate to builders to
|
|
9
7
|
# create new ones.
|
|
@@ -45,10 +43,8 @@ module Mongoid
|
|
|
45
43
|
key = @attributes[association.inverse_type]
|
|
46
44
|
type = key ? association.resolver.model_for(key) : nil
|
|
47
45
|
target = if t = association.build(self, object, type, selected_fields)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
nil
|
|
51
|
-
end
|
|
46
|
+
association.create_relation(self, t)
|
|
47
|
+
end
|
|
52
48
|
|
|
53
49
|
# Only need to do this on embedded associations. The pending callbacks
|
|
54
50
|
# are only added when materializing the documents, which only happens
|
|
@@ -71,9 +67,9 @@ module Mongoid
|
|
|
71
67
|
#
|
|
72
68
|
# @param [ Symbol ] name The name of the association.
|
|
73
69
|
def reset_relation_criteria(name)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
return unless instance_variable_defined?("@_#{name}")
|
|
71
|
+
|
|
72
|
+
send(name).reset_unloaded
|
|
77
73
|
end
|
|
78
74
|
|
|
79
75
|
# Set the supplied association to an instance variable on the class with the
|
|
@@ -119,8 +115,8 @@ module Mongoid
|
|
|
119
115
|
if !without_autobuild? && association.embedded? && attribute_missing?(field_name)
|
|
120
116
|
# We always allow accessing the parent document of an embedded one.
|
|
121
117
|
try_get_parent = association.is_a?(
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
Mongoid::Association::Embedded::EmbeddedIn
|
|
119
|
+
) && field_name == association.key
|
|
124
120
|
raise Mongoid::Errors::AttributeNotLoaded.new(self.class, field_name) unless try_get_parent
|
|
125
121
|
end
|
|
126
122
|
|
|
@@ -131,6 +127,10 @@ module Mongoid
|
|
|
131
127
|
_loading do
|
|
132
128
|
if object && needs_no_database_query?(object, association)
|
|
133
129
|
__build__(name, object, association)
|
|
130
|
+
# Check if data was loaded via $lookup aggregation
|
|
131
|
+
elsif !association.embedded? && attributes.key?(name.to_s)
|
|
132
|
+
# Use the pre-loaded association data from $lookup
|
|
133
|
+
__build__(name, attributes[name.to_s], association)
|
|
134
134
|
else
|
|
135
135
|
selected_fields = _mongoid_filter_selected_fields(association.key)
|
|
136
136
|
__build__(name, attributes[association.key], association, selected_fields)
|
|
@@ -162,8 +162,7 @@ module Mongoid
|
|
|
162
162
|
# and the provided list does not include the association, any of its
|
|
163
163
|
# fields should be allowed.
|
|
164
164
|
if __selected_fields.values.all? { |v| v == 0 } &&
|
|
165
|
-
|
|
166
|
-
then
|
|
165
|
+
__selected_fields.keys.none? { |k| k.split('.', 2).first == assoc_key }
|
|
167
166
|
return nil
|
|
168
167
|
end
|
|
169
168
|
|
|
@@ -214,16 +213,14 @@ module Mongoid
|
|
|
214
213
|
# document that the $ is referring to should be retrieved with all
|
|
215
214
|
# fields. See https://www.mongodb.com/docs/manual/reference/operator/projection/positional/
|
|
216
215
|
# and https://jira.mongodb.org/browse/MONGOID-4769.
|
|
217
|
-
if filtered.keys == %w
|
|
218
|
-
filtered = nil
|
|
219
|
-
end
|
|
216
|
+
filtered = nil if filtered.keys == %w[$]
|
|
220
217
|
|
|
221
218
|
filtered
|
|
222
219
|
end
|
|
223
220
|
|
|
224
221
|
def needs_no_database_query?(object, association)
|
|
225
222
|
object.is_a?(Document) && !object.embedded? &&
|
|
226
|
-
|
|
223
|
+
object[association.try(:primary_key) || :_id] == attributes[association.key]
|
|
227
224
|
end
|
|
228
225
|
|
|
229
226
|
# Is the current code executing without autobuild functionality?
|
|
@@ -245,10 +242,10 @@ module Mongoid
|
|
|
245
242
|
#
|
|
246
243
|
# @return [ Object ] The result of the yield.
|
|
247
244
|
def without_autobuild
|
|
248
|
-
Threaded.begin_execution(
|
|
245
|
+
Threaded.begin_execution('without_autobuild')
|
|
249
246
|
yield
|
|
250
247
|
ensure
|
|
251
|
-
Threaded.exit_execution(
|
|
248
|
+
Threaded.exit_execution('without_autobuild')
|
|
252
249
|
end
|
|
253
250
|
|
|
254
251
|
# Parse out the attributes and the options from the args passed to a
|
|
@@ -261,7 +258,7 @@ module Mongoid
|
|
|
261
258
|
#
|
|
262
259
|
# @return [ Array<Hash> ] The attributes and options.
|
|
263
260
|
def parse_args(*args)
|
|
264
|
-
[args.first || {}, args.size > 1 ? args[1] : {}]
|
|
261
|
+
[ args.first || {}, (args.size > 1) ? args[1] : {} ]
|
|
265
262
|
end
|
|
266
263
|
|
|
267
264
|
# Adds the existence check for associations.
|
|
@@ -304,9 +301,7 @@ module Mongoid
|
|
|
304
301
|
association.inverse_class.tap do |klass|
|
|
305
302
|
klass.re_define_method(name) do |reload = false|
|
|
306
303
|
value = get_relation(name, association, nil, reload)
|
|
307
|
-
if value.nil? && association.autobuilding? && !without_autobuild?
|
|
308
|
-
value = send("build_#{name}")
|
|
309
|
-
end
|
|
304
|
+
value = send("build_#{name}") if value.nil? && association.autobuilding? && !without_autobuild?
|
|
310
305
|
value
|
|
311
306
|
end
|
|
312
307
|
end
|
|
@@ -347,9 +342,7 @@ module Mongoid
|
|
|
347
342
|
klass.re_define_method("#{name}=") do |object|
|
|
348
343
|
without_autobuild do
|
|
349
344
|
if value = get_relation(name, association, object)
|
|
350
|
-
|
|
351
|
-
value = __build__(name, value, association)
|
|
352
|
-
end
|
|
345
|
+
value = __build__(name, value, association) unless value.respond_to?(:substitute)
|
|
353
346
|
|
|
354
347
|
set_relation(name, value.substitute(object.substitutable))
|
|
355
348
|
else
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
module Mongoid
|
|
5
4
|
module Association
|
|
6
|
-
|
|
7
5
|
# Superclass for all objects that bind associations together.
|
|
8
6
|
module Bindable
|
|
9
7
|
include Threaded::Lifecycle
|
|
@@ -31,10 +29,10 @@ module Mongoid
|
|
|
31
29
|
#
|
|
32
30
|
# @return [ Object ] The result of the yield.
|
|
33
31
|
def binding
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
return if _binding?
|
|
33
|
+
|
|
34
|
+
_binding do
|
|
35
|
+
yield(self) if block_given?
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
|
|
@@ -51,26 +49,26 @@ module Mongoid
|
|
|
51
49
|
#
|
|
52
50
|
# @raise [ Errors::InverseNotFound ] If no inverse found.
|
|
53
51
|
def check_inverse!(doc)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
return if _association.bindable?(doc)
|
|
53
|
+
|
|
54
|
+
raise Errors::InverseNotFound.new(
|
|
55
|
+
_base.class,
|
|
56
|
+
_association.name,
|
|
57
|
+
doc.class,
|
|
58
|
+
_association.foreign_key
|
|
59
|
+
)
|
|
62
60
|
end
|
|
63
61
|
|
|
64
62
|
# Remove the associated document from the inverse's association.
|
|
65
63
|
#
|
|
66
64
|
# @param [ Document ] doc The document to remove.
|
|
67
65
|
def remove_associated(doc)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
return unless inverse = _association.inverse(doc)
|
|
67
|
+
|
|
68
|
+
if _association.many?
|
|
69
|
+
remove_associated_many(doc, inverse)
|
|
70
|
+
elsif _association.in_to?
|
|
71
|
+
remove_associated_in_to(doc, inverse)
|
|
74
72
|
end
|
|
75
73
|
end
|
|
76
74
|
|
|
@@ -83,13 +81,13 @@ module Mongoid
|
|
|
83
81
|
def remove_associated_many(doc, inverse)
|
|
84
82
|
# We only want to remove the inverse association when the inverse
|
|
85
83
|
# document is in memory.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
return unless inv = doc.ivar(inverse)
|
|
85
|
+
|
|
86
|
+
# This first condition is needed because when assigning the
|
|
87
|
+
# embeds_many association using the same embeds_many
|
|
88
|
+
# association, we delete from the array we are about to assign.
|
|
89
|
+
if _base != inv && (associated = inv.ivar(_association.name))
|
|
90
|
+
associated.delete(doc)
|
|
93
91
|
end
|
|
94
92
|
end
|
|
95
93
|
|
|
@@ -103,9 +101,9 @@ module Mongoid
|
|
|
103
101
|
def remove_associated_in_to(doc, inverse)
|
|
104
102
|
# We only want to remove the inverse association when the inverse
|
|
105
103
|
# document is in memory.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
return unless associated = doc.ivar(inverse)
|
|
105
|
+
|
|
106
|
+
associated.send(_association.setter, nil)
|
|
109
107
|
end
|
|
110
108
|
|
|
111
109
|
# Set the id of the related document in the foreign key field on the
|
|
@@ -119,9 +117,9 @@ module Mongoid
|
|
|
119
117
|
# @param [ Document ] keyed The document that stores the foreign key.
|
|
120
118
|
# @param [ Object ] id The id of the bound document.
|
|
121
119
|
def bind_foreign_key(keyed, id)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
return if keyed.frozen?
|
|
121
|
+
|
|
122
|
+
try_method(keyed, _association.foreign_key_setter, id)
|
|
125
123
|
end
|
|
126
124
|
|
|
127
125
|
# Set the type of the related document on the foreign type field, used
|
|
@@ -135,9 +133,9 @@ module Mongoid
|
|
|
135
133
|
# @param [ Document ] typed The document that stores the type field.
|
|
136
134
|
# @param [ String ] name The name of the model.
|
|
137
135
|
def bind_polymorphic_type(typed, name)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
return unless _association.type && !typed.frozen?
|
|
137
|
+
|
|
138
|
+
try_method(typed, _association.type_setter, name)
|
|
141
139
|
end
|
|
142
140
|
|
|
143
141
|
# Set the type of the related document on the foreign type field, used
|
|
@@ -151,9 +149,9 @@ module Mongoid
|
|
|
151
149
|
# @param [ Document ] typed The document that stores the type field.
|
|
152
150
|
# @param [ String ] name The name of the model.
|
|
153
151
|
def bind_polymorphic_inverse_type(typed, name)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
return unless _association.inverse_type && !typed.frozen?
|
|
153
|
+
|
|
154
|
+
try_method(typed, _association.inverse_type_setter, name)
|
|
157
155
|
end
|
|
158
156
|
|
|
159
157
|
# Bind the inverse document to the child document so that the in memory
|
|
@@ -167,9 +165,9 @@ module Mongoid
|
|
|
167
165
|
# @param [ Document ] doc The base document.
|
|
168
166
|
# @param [ Document ] inverse The inverse document.
|
|
169
167
|
def bind_inverse(doc, inverse)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
return unless doc.respond_to?(_association.inverse_setter) && !doc.frozen?
|
|
169
|
+
|
|
170
|
+
try_method(doc, _association.inverse_setter, inverse)
|
|
173
171
|
end
|
|
174
172
|
|
|
175
173
|
# Bind the provided document with the base from the parent association.
|
|
@@ -204,9 +202,9 @@ module Mongoid
|
|
|
204
202
|
# @return [ true | false ] If the association changed.
|
|
205
203
|
def set_base_association
|
|
206
204
|
inverse_association = _association.inverse_association(_target)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
return unless inverse_association != _association && !inverse_association.nil?
|
|
206
|
+
|
|
207
|
+
_base._association = inverse_association
|
|
210
208
|
end
|
|
211
209
|
|
|
212
210
|
# Bind the provided document with the base from the parent association.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
module Mongoid
|
|
5
4
|
module Association
|
|
6
|
-
|
|
7
5
|
# This module is responsible for defining the build and create methods used
|
|
8
6
|
# in one to one associations.
|
|
9
7
|
#
|
|
@@ -22,17 +20,20 @@ module Mongoid
|
|
|
22
20
|
|
|
23
21
|
private
|
|
24
22
|
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# doc.parse_args(:name => "Joe")
|
|
23
|
+
# Parses the arguments passed to the build and create methods. The first
|
|
24
|
+
# argument is always the attributes (defaulting to {} if not given). The
|
|
25
|
+
# last argument is always the options hash, if the last argument is a
|
|
26
|
+
# hash. The first of any remaining arguments is the type.
|
|
30
27
|
#
|
|
31
|
-
# @param [
|
|
28
|
+
# @param [ Array ] args The arguments passed to the method.
|
|
32
29
|
#
|
|
33
|
-
# @return [ Array
|
|
34
|
-
def parse_args(
|
|
35
|
-
|
|
30
|
+
# @return [ Array ] An array containing the attributes, type, and options.
|
|
31
|
+
def parse_args(args)
|
|
32
|
+
attributes = args.shift || {}
|
|
33
|
+
opts = args.last.is_a?(Hash) ? args.pop : {}
|
|
34
|
+
type = args.shift
|
|
35
|
+
|
|
36
|
+
[ attributes, type, opts ]
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
# Defines a builder method. This is defined as #build_name.
|
|
@@ -46,8 +47,9 @@ module Mongoid
|
|
|
46
47
|
def self.define_builder!(association)
|
|
47
48
|
association.inverse_class.tap do |klass|
|
|
48
49
|
klass.re_define_method("build_#{association.name}") do |*args|
|
|
49
|
-
attributes,
|
|
50
|
-
|
|
50
|
+
attributes, type, _opts = parse_args(args)
|
|
51
|
+
|
|
52
|
+
document = Factory.execute_build(type || association.relation_class, attributes, execute_callbacks: false)
|
|
51
53
|
_building do
|
|
52
54
|
child = send("#{association.name}=", document)
|
|
53
55
|
child.run_pending_callbacks
|
|
@@ -70,8 +72,9 @@ module Mongoid
|
|
|
70
72
|
def self.define_creator!(association)
|
|
71
73
|
association.inverse_class.tap do |klass|
|
|
72
74
|
klass.re_define_method("create_#{association.name}") do |*args|
|
|
73
|
-
attributes,
|
|
74
|
-
|
|
75
|
+
attributes, type, _opts = parse_args(args)
|
|
76
|
+
|
|
77
|
+
document = Factory.execute_build(type || association.relation_class, attributes, execute_callbacks: false)
|
|
75
78
|
doc = _assigning do
|
|
76
79
|
send("#{association.name}=", document)
|
|
77
80
|
end
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
3
|
module Mongoid
|
|
5
4
|
module Association
|
|
6
|
-
|
|
7
5
|
# Used for converting foreign key values to the correct type based on the
|
|
8
6
|
# types of ids that the document stores.
|
|
9
7
|
module Constrainable
|
|
10
|
-
|
|
11
8
|
# Convert the supplied object to the appropriate type to set as the
|
|
12
9
|
# foreign key for an association.
|
|
13
10
|
#
|
|
@@ -19,11 +16,12 @@ module Mongoid
|
|
|
19
16
|
# @return [ Object ] The object cast to the correct type.
|
|
20
17
|
def convert_to_foreign_key(object)
|
|
21
18
|
return convert_polymorphic(object) if polymorphic?
|
|
22
|
-
|
|
19
|
+
|
|
20
|
+
field = relation_class.fields['_id']
|
|
23
21
|
if relation_class.using_object_ids?
|
|
24
22
|
BSON::ObjectId.mongoize(object)
|
|
25
23
|
elsif object.is_a?(::Array)
|
|
26
|
-
object.map!{ |obj| field.mongoize(obj) }
|
|
24
|
+
object.map! { |obj| field.mongoize(obj) }
|
|
27
25
|
else
|
|
28
26
|
field.mongoize(object)
|
|
29
27
|
end
|