mongoid 7.0.13 → 9.1.1
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 +41 -41
- data/LICENSE +1 -1
- data/README.md +29 -25
- data/Rakefile +150 -40
- data/lib/config/locales/en.yml +364 -108
- data/lib/mongoid/association/accessors.rb +205 -107
- data/lib/mongoid/association/bindable.rb +102 -56
- data/lib/mongoid/association/builders.rb +24 -26
- data/lib/mongoid/association/constrainable.rb +8 -11
- data/lib/mongoid/association/depending.rb +65 -59
- data/lib/mongoid/association/eager.rb +203 -0
- data/lib/mongoid/association/eager_load/discriminated_inclusion.rb +88 -0
- data/lib/mongoid/association/eager_load/embedded_distributor.rb +151 -0
- data/lib/mongoid/association/eager_load/inclusion.rb +173 -0
- data/lib/mongoid/association/eager_load/inclusion_tree.rb +96 -0
- data/lib/mongoid/association/eager_load/lookup_pipeline.rb +121 -0
- data/lib/mongoid/association/eager_load/polymorphic_preloader.rb +61 -0
- data/lib/mongoid/association/eager_load/polymorphic_targets.rb +151 -0
- data/lib/mongoid/association/eager_loadable.rb +135 -15
- data/lib/mongoid/association/embedded/batchable.rb +87 -75
- data/lib/mongoid/association/embedded/cyclic.rb +16 -25
- data/lib/mongoid/association/embedded/eager.rb +18 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +30 -14
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +10 -7
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +39 -32
- data/lib/mongoid/association/embedded/embedded_in.rb +37 -46
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +7 -11
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +11 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +309 -243
- data/lib/mongoid/association/embedded/embeds_many.rb +32 -56
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +6 -11
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +25 -11
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +145 -53
- data/lib/mongoid/association/embedded/embeds_one.rb +30 -50
- data/lib/mongoid/association/embedded.rb +3 -0
- data/lib/mongoid/association/macros.rb +97 -56
- data/lib/mongoid/association/many.rb +99 -36
- data/lib/mongoid/association/marshalable.rb +5 -7
- data/lib/mongoid/association/nested/many.rb +86 -47
- data/lib/mongoid/association/nested/nested_buildable.rb +58 -21
- data/lib/mongoid/association/nested/one.rb +81 -36
- data/lib/mongoid/association/nested.rb +4 -5
- data/lib/mongoid/association/one.rb +5 -14
- data/lib/mongoid/association/options.rb +48 -53
- data/lib/mongoid/association/proxy.rb +65 -54
- data/lib/mongoid/association/referenced/auto_save.rb +59 -20
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +21 -22
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +32 -11
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +47 -6
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +35 -42
- data/lib/mongoid/association/referenced/belongs_to.rb +77 -77
- data/lib/mongoid/association/referenced/counter_cache.rb +24 -35
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +26 -15
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +12 -7
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +3 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +202 -133
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +81 -83
- data/lib/mongoid/association/referenced/has_many/binding.rb +3 -7
- data/lib/mongoid/association/referenced/has_many/buildable.rb +15 -8
- data/lib/mongoid/association/referenced/has_many/eager.rb +3 -4
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +601 -456
- data/lib/mongoid/association/referenced/has_many/proxy.rb +344 -216
- data/lib/mongoid/association/referenced/has_many.rb +58 -74
- data/lib/mongoid/association/referenced/has_many_through/eager.rb +99 -0
- data/lib/mongoid/association/referenced/has_many_through/proxy.rb +68 -0
- data/lib/mongoid/association/referenced/has_many_through.rb +201 -0
- data/lib/mongoid/association/referenced/has_one/binding.rb +4 -10
- data/lib/mongoid/association/referenced/has_one/buildable.rb +29 -17
- data/lib/mongoid/association/referenced/has_one/eager.rb +4 -6
- data/lib/mongoid/association/referenced/has_one/proxy.rb +51 -47
- data/lib/mongoid/association/referenced/has_one.rb +45 -55
- data/lib/mongoid/association/referenced/has_one_through/eager.rb +65 -0
- data/lib/mongoid/association/referenced/has_one_through/proxy.rb +30 -0
- data/lib/mongoid/association/referenced/has_one_through.rb +167 -0
- data/lib/mongoid/association/referenced/syncable.rb +44 -62
- data/lib/mongoid/association/referenced/with_polymorphic_criteria.rb +41 -0
- data/lib/mongoid/association/referenced.rb +4 -0
- data/lib/mongoid/association/reflections.rb +11 -12
- data/lib/mongoid/association/relatable.rb +173 -146
- data/lib/mongoid/association.rb +35 -40
- data/lib/mongoid/atomic/modifiers.rb +91 -74
- data/lib/mongoid/atomic/paths/embedded/many.rb +25 -11
- data/lib/mongoid/atomic/paths/embedded/one.rb +6 -10
- data/lib/mongoid/atomic/paths/embedded.rb +5 -8
- data/lib/mongoid/atomic/paths/root.rb +5 -10
- data/lib/mongoid/atomic/paths.rb +4 -3
- data/lib/mongoid/atomic.rb +41 -89
- data/lib/mongoid/atomic_update_preparer.rb +89 -0
- data/lib/mongoid/attributes/dynamic.rb +12 -27
- data/lib/mongoid/attributes/embedded.rb +34 -0
- data/lib/mongoid/attributes/nested.rb +22 -25
- data/lib/mongoid/attributes/processing.rb +51 -34
- data/lib/mongoid/attributes/projector.rb +107 -0
- data/lib/mongoid/attributes/readonly.rb +15 -17
- data/lib/mongoid/attributes.rb +119 -126
- data/lib/mongoid/cacheable.rb +30 -14
- data/lib/mongoid/changeable.rb +196 -99
- data/lib/mongoid/clients/factory.rb +73 -17
- data/lib/mongoid/clients/options.rb +140 -19
- data/lib/mongoid/clients/sessions.rb +239 -87
- data/lib/mongoid/clients/storage_options.rb +42 -17
- data/lib/mongoid/clients/validators/storage.rb +6 -25
- data/lib/mongoid/clients/validators.rb +3 -2
- data/lib/mongoid/clients.rb +44 -22
- data/lib/mongoid/collection_configurable.rb +63 -0
- data/lib/mongoid/composable.rb +40 -39
- data/lib/mongoid/config/defaults.rb +46 -0
- data/lib/mongoid/config/encryption.rb +228 -0
- data/lib/mongoid/config/environment.rb +26 -13
- data/lib/mongoid/config/introspection.rb +150 -0
- data/lib/mongoid/config/options.rb +37 -26
- data/lib/mongoid/config/validators/async_query_executor.rb +31 -0
- data/lib/mongoid/config/validators/client.rb +20 -37
- data/lib/mongoid/config/validators/option.rb +5 -7
- data/lib/mongoid/config/validators.rb +5 -3
- data/lib/mongoid/config.rb +418 -60
- data/lib/mongoid/contextual/aggregable/memory.rb +45 -28
- data/lib/mongoid/contextual/aggregable/mongo.rb +49 -47
- data/lib/mongoid/contextual/aggregable/none.rb +64 -0
- data/lib/mongoid/contextual/aggregable.rb +16 -0
- data/lib/mongoid/contextual/atomic.rb +126 -45
- data/lib/mongoid/contextual/command.rb +3 -6
- data/lib/mongoid/contextual/map_reduce.rb +23 -49
- data/lib/mongoid/contextual/memory.rb +448 -121
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +707 -351
- data/lib/mongoid/contextual/none.rb +249 -33
- data/lib/mongoid/contextual/queryable.rb +6 -6
- data/lib/mongoid/contextual.rb +40 -15
- data/lib/mongoid/copyable.rb +45 -21
- data/lib/mongoid/criteria/findable.rb +65 -27
- data/lib/mongoid/criteria/includable.rb +97 -45
- data/lib/mongoid/criteria/inspectable.rb +6 -6
- data/lib/mongoid/criteria/marshalable.rb +15 -10
- data/lib/mongoid/criteria/modifiable.rb +8 -28
- data/lib/mongoid/criteria/options.rb +2 -5
- data/lib/mongoid/criteria/permission.rb +40 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +13 -24
- data/lib/mongoid/criteria/queryable/expandable.rb +64 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +14 -50
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +29 -13
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/date.rb +13 -16
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +14 -18
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +5 -44
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +23 -24
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +31 -29
- data/lib/mongoid/criteria/queryable/extensions/object.rb +15 -37
- data/lib/mongoid/criteria/queryable/extensions/range.rb +52 -22
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +22 -25
- data/lib/mongoid/criteria/queryable/extensions/set.rb +8 -10
- data/lib/mongoid/criteria/queryable/extensions/string.rb +24 -41
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +10 -28
- data/lib/mongoid/criteria/queryable/extensions/time.rb +11 -14
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -20
- data/lib/mongoid/criteria/queryable/extensions.rb +19 -24
- data/lib/mongoid/criteria/queryable/key.rb +49 -30
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -6
- data/lib/mongoid/criteria/queryable/mergeable.rb +203 -46
- data/lib/mongoid/criteria/queryable/optional.rb +32 -81
- data/lib/mongoid/criteria/queryable/options.rb +24 -29
- data/lib/mongoid/criteria/queryable/pipeline.rb +11 -23
- data/lib/mongoid/criteria/queryable/selectable.rb +558 -242
- data/lib/mongoid/criteria/queryable/selector.rb +134 -43
- data/lib/mongoid/criteria/queryable/smash.rb +41 -21
- data/lib/mongoid/criteria/queryable/storable.rb +219 -0
- data/lib/mongoid/criteria/queryable.rb +41 -27
- data/lib/mongoid/criteria/scopable.rb +37 -30
- data/lib/mongoid/criteria/translator.rb +43 -0
- data/lib/mongoid/criteria.rb +257 -152
- data/lib/mongoid/deprecable.rb +78 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +277 -171
- data/lib/mongoid/encryptable.rb +98 -0
- data/lib/mongoid/equality.rb +29 -31
- data/lib/mongoid/errors/ambiguous_relationship.rb +6 -9
- data/lib/mongoid/errors/attribute_not_loaded.rb +31 -0
- data/lib/mongoid/errors/callback.rb +3 -6
- data/lib/mongoid/errors/config_redactor.rb +43 -0
- data/lib/mongoid/errors/create_collection_failure.rb +31 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +16 -0
- data/lib/mongoid/errors/delete_restriction.rb +11 -16
- data/lib/mongoid/errors/document_not_destroyed.rb +5 -10
- data/lib/mongoid/errors/document_not_found.rb +37 -27
- data/lib/mongoid/errors/drop_collection_failure.rb +25 -0
- data/lib/mongoid/errors/empty_config_file.rb +23 -0
- data/lib/mongoid/errors/immutable_attribute.rb +24 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +3 -6
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +26 -0
- data/lib/mongoid/errors/invalid_around_callback.rb +16 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +23 -0
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +30 -0
- data/lib/mongoid/errors/invalid_collection.rb +3 -3
- data/lib/mongoid/errors/invalid_config_file.rb +23 -0
- data/lib/mongoid/errors/invalid_config_option.rb +5 -8
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +9 -13
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +23 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +21 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +29 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +24 -0
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +24 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +24 -0
- data/lib/mongoid/errors/invalid_field.rb +10 -11
- data/lib/mongoid/errors/invalid_field_operator.rb +29 -0
- data/lib/mongoid/errors/invalid_field_option.rb +4 -7
- data/lib/mongoid/errors/invalid_field_type.rb +24 -0
- data/lib/mongoid/errors/invalid_find.rb +3 -6
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +20 -0
- data/lib/mongoid/errors/invalid_includes.rb +5 -8
- data/lib/mongoid/errors/invalid_index.rb +3 -6
- data/lib/mongoid/errors/invalid_options.rb +5 -8
- data/lib/mongoid/errors/invalid_path.rb +3 -6
- data/lib/mongoid/errors/invalid_persistence_option.rb +6 -11
- data/lib/mongoid/errors/invalid_query.rb +36 -0
- data/lib/mongoid/errors/invalid_relation.rb +15 -22
- data/lib/mongoid/errors/invalid_relation_option.rb +8 -11
- data/lib/mongoid/errors/invalid_scope.rb +3 -6
- data/lib/mongoid/errors/invalid_session_nesting.rb +14 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +8 -9
- data/lib/mongoid/errors/invalid_storage_options.rb +4 -7
- data/lib/mongoid/errors/invalid_time.rb +3 -6
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +14 -0
- data/lib/mongoid/errors/inverse_not_found.rb +4 -7
- data/lib/mongoid/errors/mixed_client_configuration.rb +4 -7
- data/lib/mongoid/errors/mixed_relations.rb +3 -5
- data/lib/mongoid/errors/mongoid_error.rb +13 -23
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +4 -7
- data/lib/mongoid/errors/no_client_config.rb +5 -8
- data/lib/mongoid/errors/no_client_database.rb +5 -8
- data/lib/mongoid/errors/no_client_hosts.rb +5 -8
- data/lib/mongoid/errors/no_clients_config.rb +3 -6
- data/lib/mongoid/errors/no_default_client.rb +4 -7
- data/lib/mongoid/errors/no_encryption_schema.rb +28 -0
- data/lib/mongoid/errors/no_environment.rb +3 -6
- data/lib/mongoid/errors/no_map_reduce_output.rb +3 -6
- data/lib/mongoid/errors/no_metadata.rb +3 -6
- data/lib/mongoid/errors/no_parent.rb +3 -6
- data/lib/mongoid/errors/readonly_association.rb +29 -0
- data/lib/mongoid/errors/readonly_attribute.rb +4 -7
- data/lib/mongoid/errors/readonly_document.rb +4 -9
- data/lib/mongoid/errors/rollback.rb +13 -0
- data/lib/mongoid/errors/scope_overwrite.rb +4 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +14 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +4 -3
- data/lib/mongoid/errors/transaction_error.rb +22 -0
- data/lib/mongoid/errors/transactions_not_supported.rb +14 -0
- data/lib/mongoid/errors/unknown_attribute.rb +4 -7
- data/lib/mongoid/errors/unknown_model.rb +3 -6
- data/lib/mongoid/errors/unrecognized_model_alias.rb +53 -0
- data/lib/mongoid/errors/unrecognized_resolver.rb +27 -0
- data/lib/mongoid/errors/unregistered_class.rb +47 -0
- data/lib/mongoid/errors/unsaved_document.rb +4 -4
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +3 -6
- data/lib/mongoid/errors/validations.rb +5 -5
- data/lib/mongoid/errors.rb +82 -51
- data/lib/mongoid/evolvable.rb +4 -7
- data/lib/mongoid/extensions/array.rb +32 -55
- data/lib/mongoid/extensions/big_decimal.rb +45 -24
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +12 -8
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +38 -30
- data/lib/mongoid/extensions/date_time.rb +8 -22
- data/lib/mongoid/extensions/decimal128.rb +4 -8
- data/lib/mongoid/extensions/false_class.rb +11 -13
- data/lib/mongoid/extensions/float.rb +15 -19
- data/lib/mongoid/extensions/hash.rb +31 -116
- data/lib/mongoid/extensions/integer.rb +17 -21
- data/lib/mongoid/extensions/module.rb +6 -7
- data/lib/mongoid/extensions/nil_class.rb +6 -7
- data/lib/mongoid/extensions/object.rb +42 -84
- data/lib/mongoid/extensions/object_id.rb +5 -11
- data/lib/mongoid/extensions/range.rb +49 -25
- data/lib/mongoid/extensions/raw_value.rb +31 -0
- data/lib/mongoid/extensions/regexp.rb +16 -10
- data/lib/mongoid/extensions/set.rb +27 -15
- data/lib/mongoid/extensions/string.rb +40 -67
- data/lib/mongoid/extensions/symbol.rb +11 -26
- data/lib/mongoid/extensions/time.rb +49 -47
- data/lib/mongoid/extensions/time_with_zone.rb +30 -12
- data/lib/mongoid/extensions/true_class.rb +11 -13
- data/lib/mongoid/extensions/vector.rb +64 -0
- data/lib/mongoid/extensions.rb +28 -41
- data/lib/mongoid/factory.rb +205 -28
- data/lib/mongoid/field_readable.rb +69 -0
- data/lib/mongoid/fields/encrypted.rb +47 -0
- data/lib/mongoid/fields/foreign_key.rb +48 -35
- data/lib/mongoid/fields/localized.rb +33 -21
- data/lib/mongoid/fields/standard.rb +31 -48
- data/lib/mongoid/fields/validators/macro.rb +48 -45
- data/lib/mongoid/fields/validators.rb +3 -2
- data/lib/mongoid/fields.rb +499 -117
- data/lib/mongoid/findable.rb +174 -64
- data/lib/mongoid/identifiable.rb +28 -0
- data/lib/mongoid/indexable/specification.rb +76 -39
- data/lib/mongoid/indexable/validators/options.rb +36 -43
- data/lib/mongoid/indexable.rb +57 -58
- data/lib/mongoid/inspectable.rb +37 -15
- data/lib/mongoid/interceptable.rb +235 -66
- data/lib/mongoid/loadable.rb +146 -0
- data/lib/mongoid/loggable.rb +12 -18
- data/lib/mongoid/matchable.rb +7 -154
- data/lib/mongoid/matcher/all.rb +34 -0
- data/lib/mongoid/matcher/and.rb +32 -0
- data/lib/mongoid/matcher/bits.rb +65 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +39 -0
- data/lib/mongoid/matcher/bits_all_set.rb +39 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +39 -0
- data/lib/mongoid/matcher/bits_any_set.rb +39 -0
- data/lib/mongoid/matcher/elem_match.rb +49 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +29 -0
- data/lib/mongoid/matcher/eq.rb +23 -0
- data/lib/mongoid/matcher/eq_impl.rb +79 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +33 -0
- data/lib/mongoid/matcher/exists.rb +27 -0
- data/lib/mongoid/matcher/expression.rb +43 -0
- data/lib/mongoid/matcher/expression_operator.rb +31 -0
- data/lib/mongoid/matcher/field_expression.rb +74 -0
- data/lib/mongoid/matcher/field_operator.rb +76 -0
- data/lib/mongoid/matcher/gt.rb +29 -0
- data/lib/mongoid/matcher/gte.rb +29 -0
- data/lib/mongoid/matcher/in.rb +37 -0
- data/lib/mongoid/matcher/lt.rb +29 -0
- data/lib/mongoid/matcher/lte.rb +29 -0
- data/lib/mongoid/matcher/mod.rb +29 -0
- data/lib/mongoid/matcher/ne.rb +28 -0
- data/lib/mongoid/matcher/nin.rb +23 -0
- data/lib/mongoid/matcher/nor.rb +34 -0
- data/lib/mongoid/matcher/not.rb +42 -0
- data/lib/mongoid/matcher/or.rb +32 -0
- data/lib/mongoid/matcher/regex.rb +61 -0
- data/lib/mongoid/matcher/regexp_budget.rb +372 -0
- data/lib/mongoid/matcher/size.rb +39 -0
- data/lib/mongoid/matcher/type.rb +119 -0
- data/lib/mongoid/matcher.rb +141 -0
- data/lib/mongoid/model_resolver.rb +155 -0
- data/lib/mongoid/persistable/creatable.rb +50 -36
- data/lib/mongoid/persistable/deletable.rb +18 -30
- data/lib/mongoid/persistable/destroyable.rb +38 -14
- data/lib/mongoid/persistable/incrementable.rb +8 -10
- data/lib/mongoid/persistable/logical.rb +7 -10
- data/lib/mongoid/persistable/maxable.rb +35 -0
- data/lib/mongoid/persistable/minable.rb +35 -0
- data/lib/mongoid/persistable/multipliable.rb +34 -0
- data/lib/mongoid/persistable/poppable.rb +5 -9
- data/lib/mongoid/persistable/pullable.rb +6 -12
- data/lib/mongoid/persistable/pushable.rb +8 -14
- data/lib/mongoid/persistable/renamable.rb +11 -10
- data/lib/mongoid/persistable/savable.rb +16 -11
- data/lib/mongoid/persistable/settable.rb +7 -18
- data/lib/mongoid/persistable/unsettable.rb +11 -12
- data/lib/mongoid/persistable/updatable.rb +113 -35
- data/lib/mongoid/persistable/upsertable.rb +37 -12
- data/lib/mongoid/persistable.rb +169 -60
- data/lib/mongoid/persistence_context.rb +189 -75
- data/lib/mongoid/pluckable.rb +130 -0
- data/lib/mongoid/positional.rb +7 -15
- data/lib/mongoid/railtie.rb +36 -32
- data/lib/mongoid/railties/bson_object_id_serializer.rb +46 -0
- data/lib/mongoid/railties/console_sandbox.rb +40 -0
- data/lib/mongoid/railties/controller_runtime.rb +34 -20
- data/lib/mongoid/railties/database.rake +53 -29
- data/lib/mongoid/reloadable.rb +56 -45
- data/lib/mongoid/scopable.rb +50 -79
- data/lib/mongoid/search_indexable.rb +538 -0
- data/lib/mongoid/selectable.rb +8 -19
- data/lib/mongoid/serializable.rb +46 -40
- data/lib/mongoid/shardable.rb +102 -23
- data/lib/mongoid/stateful.rb +67 -26
- data/lib/mongoid/stringified_symbol.rb +61 -0
- data/lib/mongoid/tasks/database.rake +46 -15
- data/lib/mongoid/tasks/database.rb +204 -31
- data/lib/mongoid/tasks/encryption.rake +59 -0
- data/lib/mongoid/tasks/encryption.rb +103 -0
- data/lib/mongoid/threaded/lifecycle.rb +13 -34
- data/lib/mongoid/threaded.rb +353 -108
- data/lib/mongoid/timestamps/created/short.rb +4 -3
- data/lib/mongoid/timestamps/created.rb +15 -7
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +127 -29
- data/lib/mongoid/timestamps/updated/short.rb +4 -3
- data/lib/mongoid/timestamps/updated.rb +6 -9
- data/lib/mongoid/timestamps.rb +7 -7
- data/lib/mongoid/touchable.rb +176 -40
- data/lib/mongoid/traversable.rb +309 -106
- data/lib/mongoid/utils.rb +52 -0
- data/lib/mongoid/validatable/associated.rb +115 -22
- data/lib/mongoid/validatable/format.rb +2 -2
- data/lib/mongoid/validatable/length.rb +2 -2
- data/lib/mongoid/validatable/localizable.rb +3 -6
- data/lib/mongoid/validatable/macros.rb +25 -14
- data/lib/mongoid/validatable/numericality.rb +40 -0
- data/lib/mongoid/validatable/presence.rb +15 -21
- data/lib/mongoid/validatable/queryable.rb +9 -4
- data/lib/mongoid/validatable/uniqueness.rb +40 -53
- data/lib/mongoid/validatable.rb +41 -52
- data/lib/mongoid/version.rb +6 -2
- data/lib/mongoid/warnings.rb +40 -0
- data/lib/mongoid.rb +105 -44
- data/lib/rails/generators/mongoid/config/config_generator.rb +18 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +24 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +51 -56
- data/lib/rails/generators/mongoid/model/model_generator.rb +10 -8
- data/lib/rails/generators/mongoid_generator.rb +17 -7
- data/lib/rails/mongoid.rb +4 -32
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +17 -1
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/active_job_spec.rb +35 -0
- data/spec/integration/app_spec.rb +327 -144
- data/spec/integration/associations/belongs_to_spec.rb +165 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +241 -67
- data/spec/integration/associations/embeds_many_spec.rb +347 -0
- data/spec/integration/associations/embeds_one_spec.rb +62 -0
- data/spec/integration/associations/foreign_key_spec.rb +107 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +161 -0
- data/spec/integration/associations/has_many_spec.rb +184 -0
- data/spec/integration/associations/has_one_spec.rb +322 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +113 -0
- data/spec/integration/associations/reverse_population_spec.rb +34 -0
- data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
- data/spec/integration/associations/scope_option_spec.rb +100 -0
- data/spec/integration/atomic/modifiers_spec.rb +137 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +149 -3
- data/spec/integration/callbacks_spec.rb +422 -34
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +91 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +78 -0
- data/spec/integration/criteria/logical_spec.rb +105 -0
- data/spec/integration/criteria/range_spec.rb +349 -0
- data/spec/integration/criteria/raw_value_spec.rb +538 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +135 -15
- data/spec/integration/discriminator_key_spec.rb +392 -0
- data/spec/integration/discriminator_value_spec.rb +204 -0
- data/spec/integration/document_spec.rb +32 -3
- data/spec/integration/dots_and_dollars_spec.rb +273 -0
- data/spec/integration/encryption_spec.rb +248 -0
- data/spec/integration/i18n_fallbacks_spec.rb +47 -0
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +743 -0
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +144 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +195 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +171 -0
- data/spec/integration/matcher_operator_data/type.yml +64 -0
- data/spec/integration/matcher_operator_data/type_array.yml +15 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +37 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +113 -0
- data/spec/integration/matcher_regexp_timeout_spec.rb +215 -0
- data/spec/integration/matcher_spec.rb +237 -0
- data/spec/integration/persistence/collection_options_spec.rb +34 -0
- data/spec/integration/persistence/range_field_spec.rb +373 -0
- data/spec/integration/query_operator_guard_spec.rb +89 -0
- data/spec/integration/server_query_spec.rb +148 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +189 -0
- data/spec/lite_spec_helper.rb +56 -19
- data/spec/mongoid/association/accessors_spec.rb +375 -273
- data/spec/mongoid/association/auto_save_spec.rb +215 -106
- data/spec/mongoid/association/builders_spec.rb +124 -74
- data/spec/mongoid/association/constrainable_spec.rb +11 -21
- data/spec/mongoid/association/counter_cache_spec.rb +101 -131
- data/spec/mongoid/association/depending_spec.rb +454 -402
- data/spec/mongoid/association/eager_loadable_spec.rb +47 -0
- data/spec/mongoid/association/eager_spec.rb +471 -60
- data/spec/mongoid/association/embedded/cyclic_spec.rb +40 -49
- data/spec/mongoid/association/embedded/dirty_spec.rb +19 -21
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +39 -53
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +58 -8
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +208 -158
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +46 -134
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +11 -13
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +137 -35
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1716 -1327
- data/spec/mongoid/association/embedded/embeds_many_models.rb +191 -2
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +68 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +77 -119
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +17 -22
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +44 -24
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +234 -287
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +27 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +50 -134
- data/spec/mongoid/association/fallback_spec.rb +425 -0
- data/spec/mongoid/association/macros_spec.rb +250 -308
- data/spec/mongoid/association/nested/many_spec.rb +53 -72
- data/spec/mongoid/association/nested/one_spec.rb +68 -85
- data/spec/mongoid/association/options_spec.rb +189 -309
- data/spec/mongoid/association/polymorphic_spec.rb +36 -51
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +58 -75
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +131 -40
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +280 -52
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +345 -370
- data/spec/mongoid/association/referenced/belongs_to_models.rb +13 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +171 -329
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +45 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +66 -29
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +75 -36
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +28 -8
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +1151 -1283
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +69 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +176 -166
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +32 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +161 -24
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +169 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1021 -689
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +1743 -1955
- data/spec/mongoid/association/referenced/has_many_models.rb +85 -1
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +83 -178
- data/spec/mongoid/association/referenced/has_many_through/eager_spec.rb +58 -0
- data/spec/mongoid/association/referenced/has_many_through/proxy_spec.rb +62 -0
- data/spec/mongoid/association/referenced/has_many_through_spec.rb +399 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +28 -37
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +74 -28
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +60 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +380 -333
- data/spec/mongoid/association/referenced/has_one_models.rb +73 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +61 -185
- data/spec/mongoid/association/referenced/has_one_through/eager_spec.rb +58 -0
- data/spec/mongoid/association/referenced/has_one_through/proxy_spec.rb +49 -0
- data/spec/mongoid/association/referenced/has_one_through_spec.rb +211 -0
- data/spec/mongoid/association/reflections_spec.rb +16 -23
- data/spec/mongoid/association/syncable_spec.rb +132 -138
- data/spec/mongoid/association_spec.rb +59 -65
- data/spec/mongoid/atomic/modifiers_spec.rb +217 -180
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +41 -51
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +37 -48
- data/spec/mongoid/atomic/paths/root_spec.rb +11 -14
- data/spec/mongoid/atomic/paths_spec.rb +133 -128
- data/spec/mongoid/atomic_spec.rb +187 -154
- data/spec/mongoid/atomic_update_preparer_spec.rb +83 -0
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/embedded_spec.rb +118 -0
- data/spec/mongoid/attributes/nested_spec.rb +1604 -1737
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +37 -0
- data/spec/mongoid/attributes/readonly_spec.rb +106 -108
- data/spec/mongoid/attributes_spec.rb +1217 -715
- data/spec/mongoid/cacheable_spec.rb +78 -45
- data/spec/mongoid/changeable_spec.rb +914 -638
- data/spec/mongoid/clients/factory_spec.rb +314 -137
- data/spec/mongoid/clients/options_spec.rb +205 -76
- data/spec/mongoid/clients/sessions_spec.rb +73 -116
- data/spec/mongoid/clients/transactions_spec.rb +1128 -186
- data/spec/mongoid/clients/transactions_spec_models.rb +251 -0
- data/spec/mongoid/clients_spec.rb +433 -312
- data/spec/mongoid/collection_configurable_spec.rb +156 -0
- data/spec/mongoid/composable_spec.rb +4 -8
- data/spec/mongoid/config/defaults_spec.rb +125 -0
- data/spec/mongoid/config/encryption_spec.rb +377 -0
- data/spec/mongoid/config/environment_spec.rb +129 -49
- data/spec/mongoid/config/introspection_spec.rb +119 -0
- data/spec/mongoid/config/options_spec.rb +36 -23
- data/spec/mongoid/config_spec.rb +497 -148
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +507 -161
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +60 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +242 -158
- data/spec/mongoid/contextual/aggregable/none_spec.rb +47 -0
- data/spec/mongoid/contextual/atomic_spec.rb +510 -229
- data/spec/mongoid/contextual/map_reduce_spec.rb +114 -153
- data/spec/mongoid/contextual/memory_spec.rb +1947 -563
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +193 -0
- data/spec/mongoid/contextual/mongo_spec.rb +3317 -1268
- data/spec/mongoid/contextual/none_spec.rb +98 -89
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +769 -191
- data/spec/mongoid/copyable_spec_models.rb +30 -0
- data/spec/mongoid/criteria/findable_spec.rb +565 -506
- data/spec/mongoid/criteria/includable_spec.rb +2417 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +64 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +13 -13
- data/spec/mongoid/criteria/marshalable_spec.rb +29 -12
- data/spec/mongoid/criteria/modifiable_spec.rb +388 -530
- data/spec/mongoid/criteria/options_spec.rb +4 -6
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +114 -140
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +132 -198
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +199 -25
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +86 -116
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +69 -67
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +121 -113
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +96 -32
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +105 -152
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +97 -33
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +27 -37
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +79 -15
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +34 -53
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +259 -191
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +18 -34
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +16 -33
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +14 -18
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +91 -189
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +34 -100
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +99 -103
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +78 -85
- data/spec/mongoid/criteria/queryable/key_spec.rb +34 -35
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +150 -21
- data/spec/mongoid/criteria/queryable/optional_spec.rb +375 -954
- data/spec/mongoid/criteria/queryable/options_spec.rb +175 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +67 -86
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +43 -52
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2101 -414
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +35 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1283 -3140
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +754 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +404 -317
- data/spec/mongoid/criteria/queryable/smash_spec.rb +8 -10
- data/spec/mongoid/criteria/queryable/storable_spec.rb +249 -0
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +212 -118
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +389 -0
- data/spec/mongoid/criteria_spec.rb +1942 -2301
- data/spec/mongoid/document_fields_spec.rb +187 -14
- data/spec/mongoid/document_persistence_context_spec.rb +80 -6
- data/spec/mongoid/document_query_spec.rb +87 -0
- data/spec/mongoid/document_spec.rb +394 -538
- data/spec/mongoid/encryptable_spec.rb +61 -0
- data/spec/mongoid/equality_spec.rb +77 -103
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +10 -10
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +29 -0
- data/spec/mongoid/errors/callback_spec.rb +10 -10
- data/spec/mongoid/errors/config_redactor_spec.rb +112 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +9 -9
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +9 -9
- data/spec/mongoid/errors/document_not_found_spec.rb +108 -32
- data/spec/mongoid/errors/invalid_collection_spec.rb +11 -12
- data/spec/mongoid/errors/invalid_config_file_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_field_option_spec.rb +9 -9
- data/spec/mongoid/errors/invalid_field_spec.rb +13 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +53 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_includes_spec.rb +11 -12
- data/spec/mongoid/errors/invalid_index_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_options_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_path_spec.rb +9 -9
- data/spec/mongoid/errors/invalid_relation_spec.rb +17 -15
- data/spec/mongoid/errors/invalid_scope_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -5
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_time_spec.rb +10 -10
- data/spec/mongoid/errors/inverse_not_found_spec.rb +11 -11
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +42 -11
- data/spec/mongoid/errors/mixed_relations_spec.rb +10 -10
- data/spec/mongoid/errors/mongoid_error_spec.rb +23 -23
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +10 -10
- data/spec/mongoid/errors/no_client_config_spec.rb +11 -11
- data/spec/mongoid/errors/no_client_database_spec.rb +40 -11
- data/spec/mongoid/errors/no_client_hosts_spec.rb +37 -11
- data/spec/mongoid/errors/no_clients_config_spec.rb +9 -9
- data/spec/mongoid/errors/no_environment_spec.rb +10 -10
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +10 -10
- data/spec/mongoid/errors/no_metadata_spec.rb +9 -9
- data/spec/mongoid/errors/no_parent_spec.rb +10 -10
- data/spec/mongoid/errors/readonly_association_spec.rb +34 -0
- data/spec/mongoid/errors/readonly_attribute_spec.rb +9 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +9 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +11 -11
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +11 -11
- data/spec/mongoid/errors/unknown_attribute_spec.rb +9 -9
- data/spec/mongoid/errors/unsaved_document_spec.rb +10 -10
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +11 -11
- data/spec/mongoid/errors/validations_spec.rb +13 -13
- data/spec/mongoid/extensions/array_spec.rb +92 -377
- data/spec/mongoid/extensions/big_decimal_spec.rb +640 -217
- data/spec/mongoid/extensions/binary_spec.rb +50 -23
- data/spec/mongoid/extensions/boolean_spec.rb +73 -107
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +329 -0
- data/spec/mongoid/extensions/date_spec.rb +62 -173
- data/spec/mongoid/extensions/date_time_spec.rb +42 -95
- data/spec/mongoid/extensions/decimal128_spec.rb +14 -17
- data/spec/mongoid/extensions/false_class_spec.rb +13 -24
- data/spec/mongoid/extensions/float_spec.rb +66 -100
- data/spec/mongoid/extensions/hash_spec.rb +79 -165
- data/spec/mongoid/extensions/integer_spec.rb +63 -91
- data/spec/mongoid/extensions/module_spec.rb +15 -17
- data/spec/mongoid/extensions/nil_class_spec.rb +4 -4
- data/spec/mongoid/extensions/object_id_spec.rb +161 -246
- data/spec/mongoid/extensions/object_spec.rb +36 -238
- data/spec/mongoid/extensions/range_spec.rb +259 -69
- data/spec/mongoid/extensions/raw_value_spec.rb +65 -0
- data/spec/mongoid/extensions/regexp_spec.rb +56 -41
- data/spec/mongoid/extensions/set_spec.rb +110 -14
- data/spec/mongoid/extensions/string_spec.rb +139 -237
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +71 -0
- data/spec/mongoid/extensions/symbol_spec.rb +19 -62
- data/spec/mongoid/extensions/time_spec.rb +394 -192
- data/spec/mongoid/extensions/time_with_zone_spec.rb +111 -176
- data/spec/mongoid/extensions/true_class_spec.rb +13 -24
- data/spec/mongoid/extensions/vector_spec.rb +175 -0
- data/spec/mongoid/factory_spec.rb +378 -80
- data/spec/mongoid/fields/foreign_key_spec.rb +387 -267
- data/spec/mongoid/fields/localized_spec.rb +197 -196
- data/spec/mongoid/fields/standard_spec.rb +45 -58
- data/spec/mongoid/fields_spec.rb +1448 -525
- data/spec/mongoid/findable_spec.rb +659 -230
- data/spec/mongoid/indexable/specification_spec.rb +145 -40
- data/spec/mongoid/indexable_spec.rb +551 -188
- data/spec/mongoid/inspectable_spec.rb +126 -18
- data/spec/mongoid/interceptable_spec.rb +1431 -573
- data/spec/mongoid/interceptable_spec_models.rb +244 -0
- data/spec/mongoid/loadable_spec.rb +86 -0
- data/spec/mongoid/loading_spec.rb +114 -0
- data/spec/mongoid/loggable_spec.rb +5 -5
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +33 -0
- data/spec/mongoid/matcher/regexp_budget_spec.rb +570 -0
- data/spec/mongoid/model_resolver_spec.rb +167 -0
- data/spec/mongoid/mongoizable_spec.rb +277 -0
- data/spec/mongoid/monkey_patches_spec.rb +215 -0
- data/spec/mongoid/persistable/creatable_spec.rb +256 -209
- data/spec/mongoid/persistable/deletable_spec.rb +369 -80
- data/spec/mongoid/persistable/destroyable_spec.rb +439 -80
- data/spec/mongoid/persistable/incrementable_spec.rb +112 -77
- data/spec/mongoid/persistable/logical_spec.rb +92 -51
- data/spec/mongoid/persistable/maxable_spec.rb +148 -0
- data/spec/mongoid/persistable/minable_spec.rb +148 -0
- data/spec/mongoid/persistable/multipliable_spec.rb +212 -0
- data/spec/mongoid/persistable/poppable_spec.rb +87 -47
- data/spec/mongoid/persistable/pullable_spec.rb +161 -82
- data/spec/mongoid/persistable/pushable_spec.rb +188 -110
- data/spec/mongoid/persistable/renamable_spec.rb +91 -51
- data/spec/mongoid/persistable/savable_spec.rb +373 -155
- data/spec/mongoid/persistable/settable_spec.rb +164 -134
- data/spec/mongoid/persistable/unsettable_spec.rb +94 -58
- data/spec/mongoid/persistable/updatable_spec.rb +235 -267
- data/spec/mongoid/persistable/upsertable_spec.rb +150 -38
- data/spec/mongoid/persistable_spec.rb +198 -128
- data/spec/mongoid/persistence_context_spec.rb +133 -137
- data/spec/mongoid/positional_spec.rb +69 -78
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +27 -0
- data/spec/mongoid/railties/console_sandbox_spec.rb +43 -0
- data/spec/mongoid/relations/proxy_spec.rb +8 -6
- data/spec/mongoid/reloadable_spec.rb +552 -123
- data/spec/mongoid/scopable_spec.rb +522 -455
- data/spec/mongoid/search_indexable_spec.rb +838 -0
- data/spec/mongoid/selectable_spec.rb +41 -53
- data/spec/mongoid/serializable_spec.rb +394 -319
- data/spec/mongoid/shardable_models.rb +76 -0
- data/spec/mongoid/shardable_spec.rb +245 -41
- data/spec/mongoid/stateful_spec.rb +170 -45
- data/spec/mongoid/tasks/database_rake_spec.rb +284 -133
- data/spec/mongoid/tasks/database_spec.rb +245 -51
- data/spec/mongoid/tasks/encryption_spec.rb +189 -0
- data/spec/mongoid/threaded_spec.rb +118 -85
- data/spec/mongoid/timestamps/created/short_spec.rb +15 -16
- data/spec/mongoid/timestamps/created_spec.rb +36 -14
- data/spec/mongoid/timestamps/timeless_spec.rb +230 -47
- data/spec/mongoid/timestamps/updated/short_spec.rb +26 -30
- data/spec/mongoid/timestamps/updated_spec.rb +23 -27
- data/spec/mongoid/timestamps_spec.rb +408 -34
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +1235 -136
- data/spec/mongoid/touchable_spec_models.rb +178 -0
- data/spec/mongoid/traversable_spec.rb +1188 -79
- data/spec/mongoid/validatable/associated_spec.rb +86 -89
- data/spec/mongoid/validatable/format_spec.rb +26 -33
- data/spec/mongoid/validatable/length_spec.rb +64 -85
- data/spec/mongoid/validatable/numericality_spec.rb +124 -14
- data/spec/mongoid/validatable/presence_spec.rb +168 -215
- data/spec/mongoid/validatable/uniqueness_spec.rb +702 -826
- data/spec/mongoid/validatable_spec.rb +76 -105
- data/spec/mongoid/warnings_spec.rb +32 -0
- data/spec/mongoid_spec.rb +67 -30
- data/spec/rails/controller_extension/controller_runtime_spec.rb +59 -60
- data/spec/rails/mongoid_spec.rb +38 -139
- data/spec/shared/CANDIDATE.md +28 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/cluster_config.rb +16 -41
- data/spec/shared/lib/mrss/constraints.rb +44 -59
- data/spec/shared/lib/mrss/docker_runner.rb +42 -20
- data/spec/shared/lib/mrss/eg_config_utils.rb +20 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
- data/spec/shared/lib/mrss/release/candidate.rb +287 -0
- data/spec/shared/lib/mrss/release/product_data.rb +144 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +18 -24
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +48 -2
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/lib/tasks/candidate.rake +64 -0
- data/spec/shared/share/Dockerfile.erb +114 -96
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +12 -1
- data/spec/shared/shlib/server.sh +148 -65
- data/spec/shared/shlib/set_env.sh +56 -80
- data/spec/spec_helper.rb +104 -72
- data/spec/support/authorization.rb +2 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +37 -22
- data/spec/support/crypt/models.rb +206 -0
- data/spec/support/crypt.rb +77 -0
- data/spec/support/expectations.rb +38 -17
- data/spec/support/feature_sandbox.rb +69 -0
- data/spec/support/helpers.rb +11 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +106 -1
- data/spec/support/models/account.rb +38 -0
- data/spec/support/models/acolyte.rb +20 -0
- data/spec/support/models/actor.rb +21 -0
- data/spec/support/models/actress.rb +4 -0
- data/spec/support/models/address.rb +88 -0
- data/spec/support/models/address_component.rb +8 -0
- data/spec/support/models/address_number.rb +9 -0
- data/spec/support/models/agency.rb +8 -0
- data/spec/support/models/agent.rb +19 -0
- data/spec/support/models/album.rb +20 -0
- data/spec/support/models/alert.rb +10 -0
- data/spec/support/models/animal.rb +28 -0
- data/spec/support/models/answer.rb +9 -0
- data/spec/support/models/appointment.rb +10 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/support/models/article.rb +14 -0
- data/spec/support/models/artist.rb +95 -0
- data/spec/support/models/artwork.rb +7 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/support/models/audio.rb +8 -0
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/support/models/author.rb +9 -0
- data/spec/support/models/baby.rb +7 -0
- data/spec/support/models/band.rb +46 -0
- data/spec/support/models/bar.rb +13 -0
- data/spec/support/models/basic.rb +8 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/support/models/big_palette.rb +4 -0
- data/spec/support/models/birthday.rb +14 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/support/models/bomb.rb +7 -0
- data/spec/support/models/book.rb +20 -0
- data/spec/support/models/breed.rb +7 -0
- data/spec/support/models/browser.rb +8 -0
- data/spec/support/models/building.rb +10 -0
- data/spec/support/models/building_address.rb +10 -0
- data/spec/support/models/bus.rb +10 -0
- data/spec/support/models/business.rb +8 -0
- data/spec/support/models/callback_test.rb +12 -0
- data/spec/support/models/canvas.rb +27 -0
- data/spec/support/models/car.rb +3 -0
- data/spec/support/models/cat.rb +9 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/category.rb +11 -0
- data/spec/support/models/child.rb +7 -0
- data/spec/support/models/child_doc.rb +24 -0
- data/spec/support/models/church.rb +9 -0
- data/spec/support/models/circle.rb +5 -0
- data/spec/support/models/circuit.rb +7 -0
- data/spec/support/models/circus.rb +12 -0
- data/spec/support/models/code.rb +17 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/support/models/comment.rb +18 -0
- data/spec/support/models/company.rb +9 -0
- data/spec/support/models/consumption_period.rb +9 -0
- data/spec/support/models/contextable_item.rb +8 -0
- data/spec/support/models/contractor.rb +8 -0
- data/spec/support/models/cookie.rb +8 -0
- data/spec/support/models/country_code.rb +12 -0
- data/spec/support/models/courier_job.rb +7 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +8 -0
- data/spec/support/models/definition.rb +12 -0
- data/spec/support/models/delegating_patient.rb +15 -0
- data/spec/support/models/description.rb +13 -0
- data/spec/support/models/dictionary.rb +19 -0
- data/spec/support/models/division.rb +13 -0
- data/spec/support/models/doctor.rb +14 -0
- data/spec/support/models/dog.rb +10 -0
- data/spec/support/models/dokument.rb +9 -0
- data/spec/support/models/draft.rb +11 -0
- data/spec/support/models/dragon.rb +7 -0
- data/spec/support/models/driver.rb +10 -0
- data/spec/support/models/drug.rb +9 -0
- data/spec/support/models/dungeon.rb +7 -0
- data/spec/support/models/edit.rb +8 -0
- data/spec/support/models/email.rb +9 -0
- data/spec/support/models/employer.rb +7 -0
- data/spec/support/models/entry.rb +9 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/support/models/even.rb +10 -0
- data/spec/support/models/event.rb +24 -0
- data/spec/support/models/exhibition.rb +7 -0
- data/spec/support/models/exhibitor.rb +9 -0
- data/spec/support/models/explosion.rb +7 -0
- data/spec/support/models/eye.rb +11 -0
- data/spec/support/models/eye_bowl.rb +11 -0
- data/spec/support/models/face.rb +10 -0
- data/spec/support/models/fanatic.rb +9 -0
- data/spec/support/models/favorite.rb +15 -0
- data/spec/support/models/filesystem.rb +8 -0
- data/spec/support/models/fire_hydrant.rb +9 -0
- data/spec/support/models/firefox.rb +6 -0
- data/spec/support/models/fish.rb +9 -0
- data/spec/support/models/folder.rb +8 -0
- data/spec/support/models/folder_item.rb +10 -0
- data/spec/support/models/fruits.rb +41 -0
- data/spec/support/models/game.rb +21 -0
- data/spec/support/models/ghost.rb +9 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/support/models/home.rb +7 -0
- data/spec/support/models/house.rb +9 -0
- data/spec/support/models/html_writer.rb +5 -0
- data/spec/support/models/id_key.rb +9 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/support/models/image.rb +24 -0
- data/spec/support/models/implant.rb +27 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/support/models/item.rb +11 -0
- data/spec/support/models/jar.rb +9 -0
- data/spec/support/models/kaleidoscope.rb +9 -0
- data/spec/support/models/kangaroo.rb +7 -0
- data/spec/support/models/label.rb +53 -0
- data/spec/support/models/language.rb +8 -0
- data/spec/support/models/lat_lng.rb +23 -0
- data/spec/support/models/league.rb +14 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/support/models/line_item.rb +9 -0
- data/spec/support/models/location.rb +11 -0
- data/spec/support/models/login.rb +10 -0
- data/spec/support/models/manufacturer.rb +9 -0
- data/spec/support/models/meat.rb +7 -0
- data/spec/support/models/membership.rb +8 -0
- data/spec/support/models/message.rb +13 -0
- data/spec/support/models/minim.rb +6 -0
- data/spec/support/models/mixed_drink.rb +7 -0
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/support/models/movie.rb +16 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/support/models/name.rb +36 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/support/models/node.rb +8 -0
- data/spec/support/models/note.rb +20 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/support/models/odd.rb +10 -0
- data/spec/support/models/order.rb +13 -0
- data/spec/support/models/ordered_post.rb +14 -0
- data/spec/support/models/ordered_preference.rb +9 -0
- data/spec/support/models/oscar.rb +17 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/support/models/override.rb +11 -0
- data/spec/support/models/ownable.rb +9 -0
- data/spec/support/models/owner.rb +11 -0
- data/spec/support/models/pack.rb +5 -0
- data/spec/support/models/page.rb +19 -0
- data/spec/support/models/page_question.rb +7 -0
- data/spec/support/models/palette.rb +10 -0
- data/spec/support/models/parent.rb +8 -0
- data/spec/support/models/parent_doc.rb +9 -0
- data/spec/support/models/passport.rb +23 -0
- data/spec/support/models/patient.rb +12 -0
- data/spec/support/models/pdf_writer.rb +5 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/support/models/person.rb +237 -0
- data/spec/support/models/pet.rb +26 -0
- data/spec/support/models/pet_owner.rb +9 -0
- data/spec/support/models/phone.rb +13 -0
- data/spec/support/models/piano.rb +4 -0
- data/spec/support/models/pizza.rb +10 -0
- data/spec/support/models/player.rb +40 -0
- data/spec/support/models/post.rb +53 -0
- data/spec/support/models/post_genre.rb +9 -0
- data/spec/support/models/powerup.rb +25 -0
- data/spec/support/models/preference.rb +12 -0
- data/spec/support/models/princess.rb +13 -0
- data/spec/support/models/product.rb +23 -0
- data/spec/support/models/profile.rb +19 -0
- data/spec/support/models/pronunciation.rb +8 -0
- data/spec/support/models/pub.rb +9 -0
- data/spec/support/models/publication/encyclopedia.rb +11 -0
- data/spec/support/models/publication/review.rb +13 -0
- data/spec/support/models/publication.rb +4 -0
- data/spec/support/models/purchase.rb +7 -0
- data/spec/support/models/purchased_item.rb +11 -0
- data/spec/support/models/purse.rb +9 -0
- data/spec/support/models/question.rb +11 -0
- data/spec/support/models/quiz.rb +10 -0
- data/spec/support/models/rating.rb +11 -0
- data/spec/support/models/record.rb +54 -0
- data/spec/support/models/registry.rb +8 -0
- data/spec/support/models/role.rb +10 -0
- data/spec/support/models/root_category.rb +7 -0
- data/spec/support/models/sandbox/app/models/app_models_message.rb +3 -0
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +3 -0
- data/spec/support/models/sandbox/sandbox_message.rb +3 -0
- data/spec/support/models/sandbox/sandbox_user.rb +3 -0
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +3 -0
- data/spec/support/models/sandwich.rb +12 -0
- data/spec/support/models/scheduler.rb +9 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/scribe.rb +8 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/support/models/seo.rb +12 -0
- data/spec/support/models/series.rb +8 -0
- data/spec/support/models/server.rb +16 -0
- data/spec/support/models/service.rb +25 -0
- data/spec/support/models/shape.rb +15 -0
- data/spec/support/models/shelf.rb +8 -0
- data/spec/support/models/shield.rb +19 -0
- data/spec/support/models/shipment_address.rb +5 -0
- data/spec/support/models/shipping_container.rb +8 -0
- data/spec/support/models/shipping_pack.rb +5 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/support/models/shop.rb +9 -0
- data/spec/support/models/short_agent.rb +6 -0
- data/spec/support/models/short_quiz.rb +8 -0
- data/spec/support/models/simple.rb +8 -0
- data/spec/support/models/slave.rb +9 -0
- data/spec/support/models/song.rb +10 -0
- data/spec/support/models/sound.rb +8 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/support/models/square.rb +6 -0
- data/spec/support/models/staff.rb +9 -0
- data/spec/support/models/store_as_dup_test1.rb +8 -0
- data/spec/support/models/store_as_dup_test2.rb +8 -0
- data/spec/support/models/store_as_dup_test3.rb +8 -0
- data/spec/support/models/store_as_dup_test4.rb +8 -0
- data/spec/support/models/strategy.rb +5 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/sub_item.rb +5 -0
- data/spec/support/models/subscription.rb +8 -0
- data/spec/support/models/survey.rb +8 -0
- data/spec/support/models/symptom.rb +9 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/support/models/tag.rb +11 -0
- data/spec/support/models/target.rb +8 -0
- data/spec/support/models/template.rb +8 -0
- data/spec/support/models/thing.rb +12 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/support/models/title.rb +5 -0
- data/spec/support/models/tool.rb +11 -0
- data/spec/support/models/topping.rb +8 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/support/models/track.rb +41 -0
- data/spec/support/models/translation.rb +8 -0
- data/spec/support/models/tree.rb +11 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/support/models/user.rb +23 -0
- data/spec/support/models/user_account.rb +13 -0
- data/spec/support/models/validation_callback.rb +13 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/support/models/version.rb +8 -0
- data/spec/support/models/vertex.rb +8 -0
- data/spec/support/models/vet_visit.rb +8 -0
- data/spec/support/models/video.rb +16 -0
- data/spec/support/models/video_game.rb +3 -0
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/support/models/wiki_page.rb +17 -0
- data/spec/support/models/word.rb +18 -0
- data/spec/support/models/word_origin.rb +13 -0
- data/spec/support/models/writer.rb +14 -0
- data/spec/support/rails_mock.rb +27 -0
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +34 -0
- data/spec/support/sinatra_mock.rb +9 -0
- data/spec/support/spec_config.rb +45 -14
- metadata +1341 -780
- checksums.yaml.gz.sig +0 -0
- data/lib/mongoid/association/referenced/eager.rb +0 -162
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +0 -126
- data/lib/mongoid/contextual/geo_near.rb +0 -267
- data/lib/mongoid/criteria/queryable/forwardable.rb +0 -65
- data/lib/mongoid/errors/eager_load.rb +0 -22
- data/lib/mongoid/errors/invalid_session_use.rb +0 -24
- data/lib/mongoid/errors/invalid_storage_parent.rb +0 -26
- data/lib/mongoid/errors/invalid_value.rb +0 -16
- data/lib/mongoid/matchable/all.rb +0 -28
- data/lib/mongoid/matchable/and.rb +0 -30
- data/lib/mongoid/matchable/default.rb +0 -119
- data/lib/mongoid/matchable/elem_match.rb +0 -34
- data/lib/mongoid/matchable/eq.rb +0 -22
- data/lib/mongoid/matchable/exists.rb +0 -23
- data/lib/mongoid/matchable/gt.rb +0 -23
- data/lib/mongoid/matchable/gte.rb +0 -23
- data/lib/mongoid/matchable/in.rb +0 -24
- data/lib/mongoid/matchable/lt.rb +0 -23
- data/lib/mongoid/matchable/lte.rb +0 -23
- data/lib/mongoid/matchable/ne.rb +0 -21
- data/lib/mongoid/matchable/nin.rb +0 -22
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/matchable/or.rb +0 -33
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/lib/mongoid/matchable/size.rb +0 -21
- data/lib/mongoid/query_cache.rb +0 -331
- data/lib/support/ruby_version.rb +0 -26
- data/spec/app/models/account.rb +0 -36
- data/spec/app/models/acolyte.rb +0 -17
- data/spec/app/models/actor.rb +0 -18
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/address.rb +0 -79
- data/spec/app/models/address_component.rb +0 -5
- data/spec/app/models/address_number.rb +0 -6
- data/spec/app/models/agency.rb +0 -5
- data/spec/app/models/agent.rb +0 -16
- data/spec/app/models/album.rb +0 -18
- data/spec/app/models/alert.rb +0 -7
- data/spec/app/models/animal.rb +0 -26
- data/spec/app/models/answer.rb +0 -6
- data/spec/app/models/appointment.rb +0 -7
- data/spec/app/models/article.rb +0 -12
- data/spec/app/models/artist.rb +0 -87
- data/spec/app/models/artwork.rb +0 -4
- data/spec/app/models/audio.rb +0 -5
- data/spec/app/models/augmentation.rb +0 -11
- data/spec/app/models/author.rb +0 -6
- data/spec/app/models/baby.rb +0 -4
- data/spec/app/models/band.rb +0 -31
- data/spec/app/models/bar.rb +0 -10
- data/spec/app/models/basic.rb +0 -6
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/big_palette.rb +0 -2
- data/spec/app/models/birthday.rb +0 -13
- data/spec/app/models/bomb.rb +0 -4
- data/spec/app/models/book.rb +0 -16
- data/spec/app/models/breed.rb +0 -4
- data/spec/app/models/browser.rb +0 -6
- data/spec/app/models/building.rb +0 -6
- data/spec/app/models/building_address.rb +0 -7
- data/spec/app/models/bus.rb +0 -7
- data/spec/app/models/business.rb +0 -5
- data/spec/app/models/callback_test.rb +0 -9
- data/spec/app/models/canvas.rb +0 -25
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/cat.rb +0 -8
- data/spec/app/models/category.rb +0 -8
- data/spec/app/models/child.rb +0 -4
- data/spec/app/models/child_doc.rb +0 -22
- data/spec/app/models/church.rb +0 -6
- data/spec/app/models/circle.rb +0 -3
- data/spec/app/models/circuit.rb +0 -4
- data/spec/app/models/circus.rb +0 -7
- data/spec/app/models/code.rb +0 -11
- data/spec/app/models/comment.rb +0 -16
- data/spec/app/models/company.rb +0 -5
- data/spec/app/models/consumption_period.rb +0 -7
- data/spec/app/models/contextable_item.rb +0 -5
- data/spec/app/models/contractor.rb +0 -5
- data/spec/app/models/cookie.rb +0 -6
- data/spec/app/models/country_code.rb +0 -8
- data/spec/app/models/courier_job.rb +0 -4
- data/spec/app/models/customer.rb +0 -11
- data/spec/app/models/customer_address.rb +0 -12
- data/spec/app/models/definition.rb +0 -9
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/app/models/description.rb +0 -11
- data/spec/app/models/dictionary.rb +0 -10
- data/spec/app/models/division.rb +0 -10
- data/spec/app/models/doctor.rb +0 -12
- data/spec/app/models/dog.rb +0 -7
- data/spec/app/models/dokument.rb +0 -6
- data/spec/app/models/draft.rb +0 -9
- data/spec/app/models/dragon.rb +0 -4
- data/spec/app/models/driver.rb +0 -7
- data/spec/app/models/drug.rb +0 -6
- data/spec/app/models/dungeon.rb +0 -4
- data/spec/app/models/edit.rb +0 -5
- data/spec/app/models/email.rb +0 -6
- data/spec/app/models/employer.rb +0 -5
- data/spec/app/models/entry.rb +0 -6
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/even.rb +0 -7
- data/spec/app/models/event.rb +0 -22
- data/spec/app/models/exhibition.rb +0 -4
- data/spec/app/models/exhibitor.rb +0 -6
- data/spec/app/models/explosion.rb +0 -4
- data/spec/app/models/eye.rb +0 -9
- data/spec/app/models/eye_bowl.rb +0 -9
- data/spec/app/models/face.rb +0 -8
- data/spec/app/models/favorite.rb +0 -6
- data/spec/app/models/filesystem.rb +0 -5
- data/spec/app/models/fire_hydrant.rb +0 -6
- data/spec/app/models/firefox.rb +0 -4
- data/spec/app/models/fish.rb +0 -7
- data/spec/app/models/folder.rb +0 -7
- data/spec/app/models/folder_item.rb +0 -9
- data/spec/app/models/fruits.rb +0 -34
- data/spec/app/models/game.rb +0 -19
- data/spec/app/models/ghost.rb +0 -7
- data/spec/app/models/home.rb +0 -4
- data/spec/app/models/house.rb +0 -6
- data/spec/app/models/html_writer.rb +0 -3
- data/spec/app/models/id_key.rb +0 -6
- data/spec/app/models/image.rb +0 -22
- data/spec/app/models/implant.rb +0 -16
- data/spec/app/models/item.rb +0 -8
- data/spec/app/models/jar.rb +0 -7
- data/spec/app/models/kaleidoscope.rb +0 -6
- data/spec/app/models/kangaroo.rb +0 -4
- data/spec/app/models/label.rb +0 -47
- data/spec/app/models/language.rb +0 -5
- data/spec/app/models/lat_lng.rb +0 -15
- data/spec/app/models/league.rb +0 -11
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/line_item.rb +0 -6
- data/spec/app/models/location.rb +0 -8
- data/spec/app/models/login.rb +0 -8
- data/spec/app/models/manufacturer.rb +0 -7
- data/spec/app/models/meat.rb +0 -4
- data/spec/app/models/membership.rb +0 -4
- data/spec/app/models/message.rb +0 -11
- data/spec/app/models/minim.rb +0 -7
- data/spec/app/models/mixed_drink.rb +0 -4
- data/spec/app/models/movie.rb +0 -13
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/name.rb +0 -24
- data/spec/app/models/node.rb +0 -5
- data/spec/app/models/note.rb +0 -17
- data/spec/app/models/odd.rb +0 -7
- data/spec/app/models/ordered_post.rb +0 -11
- data/spec/app/models/ordered_preference.rb +0 -6
- data/spec/app/models/oscar.rb +0 -14
- data/spec/app/models/other_owner_object.rb +0 -2
- data/spec/app/models/override.rb +0 -16
- data/spec/app/models/ownable.rb +0 -6
- data/spec/app/models/owner.rb +0 -6
- data/spec/app/models/pack.rb +0 -3
- data/spec/app/models/page.rb +0 -16
- data/spec/app/models/page_question.rb +0 -4
- data/spec/app/models/palette.rb +0 -7
- data/spec/app/models/parent.rb +0 -5
- data/spec/app/models/parent_doc.rb +0 -6
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/patient.rb +0 -9
- data/spec/app/models/pdf_writer.rb +0 -3
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/person.rb +0 -210
- data/spec/app/models/pet.rb +0 -23
- data/spec/app/models/pet_owner.rb +0 -6
- data/spec/app/models/phone.rb +0 -9
- data/spec/app/models/pizza.rb +0 -7
- data/spec/app/models/player.rb +0 -35
- data/spec/app/models/post.rb +0 -50
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/app/models/powerup.rb +0 -11
- data/spec/app/models/preference.rb +0 -9
- data/spec/app/models/princess.rb +0 -10
- data/spec/app/models/product.rb +0 -17
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/pronunciation.rb +0 -5
- data/spec/app/models/pub.rb +0 -6
- data/spec/app/models/purchase.rb +0 -4
- data/spec/app/models/question.rb +0 -8
- data/spec/app/models/quiz.rb +0 -7
- data/spec/app/models/rating.rb +0 -8
- data/spec/app/models/record.rb +0 -52
- data/spec/app/models/registry.rb +0 -4
- data/spec/app/models/role.rb +0 -7
- data/spec/app/models/root_category.rb +0 -4
- data/spec/app/models/sandwich.rb +0 -9
- data/spec/app/models/scheduler.rb +0 -7
- data/spec/app/models/seo.rb +0 -7
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/server.rb +0 -13
- data/spec/app/models/service.rb +0 -22
- data/spec/app/models/shape.rb +0 -12
- data/spec/app/models/shelf.rb +0 -5
- data/spec/app/models/shipment_address.rb +0 -3
- data/spec/app/models/shipping_container.rb +0 -5
- data/spec/app/models/shipping_pack.rb +0 -3
- data/spec/app/models/shop.rb +0 -6
- data/spec/app/models/short_agent.rb +0 -4
- data/spec/app/models/short_quiz.rb +0 -5
- data/spec/app/models/simple.rb +0 -5
- data/spec/app/models/slave.rb +0 -6
- data/spec/app/models/song.rb +0 -8
- data/spec/app/models/sound.rb +0 -5
- data/spec/app/models/square.rb +0 -4
- data/spec/app/models/staff.rb +0 -7
- data/spec/app/models/store_as_dup_test1.rb +0 -5
- data/spec/app/models/store_as_dup_test2.rb +0 -5
- data/spec/app/models/store_as_dup_test3.rb +0 -7
- data/spec/app/models/store_as_dup_test4.rb +0 -7
- data/spec/app/models/strategy.rb +0 -3
- data/spec/app/models/sub_item.rb +0 -3
- data/spec/app/models/subscription.rb +0 -5
- data/spec/app/models/survey.rb +0 -5
- data/spec/app/models/symptom.rb +0 -6
- data/spec/app/models/tag.rb +0 -8
- data/spec/app/models/target.rb +0 -5
- data/spec/app/models/template.rb +0 -5
- data/spec/app/models/thing.rb +0 -9
- data/spec/app/models/title.rb +0 -3
- data/spec/app/models/tool.rb +0 -8
- data/spec/app/models/topping.rb +0 -5
- data/spec/app/models/track.rb +0 -38
- data/spec/app/models/translation.rb +0 -5
- data/spec/app/models/tree.rb +0 -9
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/user.rb +0 -21
- data/spec/app/models/user_account.rb +0 -10
- data/spec/app/models/validation_callback.rb +0 -10
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/version.rb +0 -5
- data/spec/app/models/vertex.rb +0 -6
- data/spec/app/models/vet_visit.rb +0 -5
- data/spec/app/models/video.rb +0 -13
- data/spec/app/models/video_game.rb +0 -1
- data/spec/app/models/weapon.rb +0 -11
- data/spec/app/models/wiki_page.rb +0 -14
- data/spec/app/models/word.rb +0 -15
- data/spec/app/models/word_origin.rb +0 -11
- data/spec/app/models/writer.rb +0 -11
- data/spec/integration/matchable_spec.rb +0 -680
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -469
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -58
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -58
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +0 -87
- data/spec/mongoid/errors/eager_load_spec.rb +0 -29
- data/spec/mongoid/extensions_spec.rb +0 -29
- data/spec/mongoid/matchable/all_spec.rb +0 -31
- data/spec/mongoid/matchable/and_spec.rb +0 -187
- data/spec/mongoid/matchable/default_spec.rb +0 -137
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -106
- data/spec/mongoid/matchable/eq_spec.rb +0 -48
- data/spec/mongoid/matchable/exists_spec.rb +0 -57
- data/spec/mongoid/matchable/gt_spec.rb +0 -86
- data/spec/mongoid/matchable/gte_spec.rb +0 -84
- data/spec/mongoid/matchable/in_spec.rb +0 -49
- data/spec/mongoid/matchable/lt_spec.rb +0 -85
- data/spec/mongoid/matchable/lte_spec.rb +0 -85
- data/spec/mongoid/matchable/ne_spec.rb +0 -46
- data/spec/mongoid/matchable/nin_spec.rb +0 -48
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/matchable/or_spec.rb +0 -131
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
- data/spec/mongoid/matchable/size_spec.rb +0 -25
- data/spec/mongoid/matchable_spec.rb +0 -853
- data/spec/mongoid/query_cache_spec.rb +0 -618
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/session_registry.rb +0 -50
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -1
- /data/spec/{app → support}/models/array_field.rb +0 -0
- /data/spec/{app → support}/models/updatable.rb +0 -0
|
@@ -1,115 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require_relative 'interceptable_spec_models'
|
|
2
5
|
|
|
3
6
|
describe Mongoid::Interceptable do
|
|
7
|
+
before do
|
|
8
|
+
# The find and initialize callbacks I added were causing failures
|
|
9
|
+
# because they were causing updates when we were asserting no updates
|
|
10
|
+
# happened.
|
|
11
|
+
Label.reset_callbacks(:initialize)
|
|
12
|
+
Label.reset_callbacks(:find)
|
|
13
|
+
end
|
|
4
14
|
|
|
5
15
|
class TestClass
|
|
6
16
|
include Mongoid::Interceptable
|
|
7
17
|
|
|
8
18
|
attr_reader :before_save_called, :after_save_called
|
|
9
19
|
|
|
10
|
-
before_save do |
|
|
20
|
+
before_save do |_object|
|
|
11
21
|
@before_save_called = true
|
|
12
22
|
end
|
|
13
23
|
|
|
14
|
-
after_save do |
|
|
24
|
+
after_save do |_object|
|
|
15
25
|
@after_save_called = true
|
|
16
26
|
end
|
|
17
27
|
end
|
|
18
28
|
|
|
19
|
-
describe
|
|
20
|
-
|
|
29
|
+
describe '.included' do
|
|
21
30
|
let(:klass) do
|
|
22
31
|
TestClass
|
|
23
32
|
end
|
|
24
33
|
|
|
25
|
-
it
|
|
34
|
+
it 'includes the before_create callback' do
|
|
26
35
|
expect(klass).to respond_to(:before_create)
|
|
27
36
|
end
|
|
28
37
|
|
|
29
|
-
it
|
|
38
|
+
it 'includes the after_create callback' do
|
|
30
39
|
expect(klass).to respond_to(:after_create)
|
|
31
40
|
end
|
|
32
41
|
|
|
33
|
-
it
|
|
42
|
+
it 'includes the before_destroy callback' do
|
|
34
43
|
expect(klass).to respond_to(:before_destroy)
|
|
35
44
|
end
|
|
36
45
|
|
|
37
|
-
it
|
|
46
|
+
it 'includes the after_destroy callback' do
|
|
38
47
|
expect(klass).to respond_to(:after_destroy)
|
|
39
48
|
end
|
|
40
49
|
|
|
41
|
-
it
|
|
50
|
+
it 'includes the before_save callback' do
|
|
42
51
|
expect(klass).to respond_to(:before_save)
|
|
43
52
|
end
|
|
44
53
|
|
|
45
|
-
it
|
|
54
|
+
it 'includes the after_save callback' do
|
|
46
55
|
expect(klass).to respond_to(:after_save)
|
|
47
56
|
end
|
|
48
57
|
|
|
49
|
-
it
|
|
58
|
+
it 'includes the before_update callback' do
|
|
50
59
|
expect(klass).to respond_to(:before_update)
|
|
51
60
|
end
|
|
52
61
|
|
|
53
|
-
it
|
|
62
|
+
it 'includes the after_update callback' do
|
|
54
63
|
expect(klass).to respond_to(:after_update)
|
|
55
64
|
end
|
|
56
65
|
|
|
57
|
-
it
|
|
66
|
+
it 'includes the before_validation callback' do
|
|
58
67
|
expect(klass).to respond_to(:before_validation)
|
|
59
68
|
end
|
|
60
69
|
|
|
61
|
-
it
|
|
70
|
+
it 'includes the after_validation callback' do
|
|
62
71
|
expect(klass).to respond_to(:after_validation)
|
|
63
72
|
end
|
|
64
73
|
|
|
65
|
-
it
|
|
74
|
+
it 'includes the after_initialize callback' do
|
|
66
75
|
expect(klass).to respond_to(:after_initialize)
|
|
67
76
|
end
|
|
68
77
|
|
|
69
|
-
it
|
|
78
|
+
it 'includes the after_build callback' do
|
|
70
79
|
expect(klass).to respond_to(:after_build)
|
|
71
80
|
end
|
|
72
81
|
end
|
|
73
82
|
|
|
74
|
-
describe
|
|
75
|
-
|
|
83
|
+
describe '.after_find' do
|
|
76
84
|
let!(:player) do
|
|
77
|
-
Player.create
|
|
85
|
+
Player.create!
|
|
78
86
|
end
|
|
79
87
|
|
|
80
|
-
context
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
it "does not execute the callback" do
|
|
88
|
+
context 'when the callback is on a root document' do
|
|
89
|
+
context 'when when the document is instantiated' do
|
|
90
|
+
it 'does not execute the callback' do
|
|
85
91
|
expect(player.impressions).to eq(0)
|
|
86
92
|
end
|
|
87
93
|
end
|
|
88
94
|
|
|
89
|
-
context
|
|
90
|
-
|
|
95
|
+
context 'when the document is found via #find' do
|
|
91
96
|
let(:from_db) do
|
|
92
97
|
Player.find(player.id)
|
|
93
98
|
end
|
|
94
99
|
|
|
95
|
-
it
|
|
100
|
+
it 'executes the callback' do
|
|
96
101
|
expect(from_db.impressions).to eq(1)
|
|
97
102
|
end
|
|
98
103
|
end
|
|
99
104
|
|
|
100
|
-
context
|
|
101
|
-
|
|
105
|
+
context 'when the document is found in a criteria' do
|
|
102
106
|
let(:from_db) do
|
|
103
107
|
Player.where(id: player.id).first
|
|
104
108
|
end
|
|
105
109
|
|
|
106
|
-
it
|
|
110
|
+
it 'executes the callback' do
|
|
107
111
|
expect(from_db.impressions).to eq(1)
|
|
108
112
|
end
|
|
109
113
|
end
|
|
110
114
|
|
|
111
|
-
context
|
|
112
|
-
|
|
115
|
+
context 'when the document is reloaded' do
|
|
113
116
|
let(:from_db) do
|
|
114
117
|
Player.find(player.id)
|
|
115
118
|
end
|
|
@@ -118,106 +121,99 @@ describe Mongoid::Interceptable do
|
|
|
118
121
|
from_db.reload
|
|
119
122
|
end
|
|
120
123
|
|
|
121
|
-
it
|
|
124
|
+
it 'executes the callback' do
|
|
122
125
|
expect(from_db.impressions).to eq(1)
|
|
123
126
|
end
|
|
124
127
|
end
|
|
125
128
|
end
|
|
126
129
|
|
|
127
|
-
context
|
|
128
|
-
|
|
130
|
+
context 'when the callback is on an embedded document' do
|
|
129
131
|
let!(:implant) do
|
|
130
|
-
player.implants.create
|
|
132
|
+
player.implants.create!
|
|
131
133
|
end
|
|
132
134
|
|
|
133
|
-
context
|
|
134
|
-
|
|
135
|
-
it "does not execute the callback" do
|
|
135
|
+
context 'when when the document is instantiated' do
|
|
136
|
+
it 'does not execute the callback' do
|
|
136
137
|
expect(implant.impressions).to eq(0)
|
|
137
138
|
end
|
|
138
139
|
end
|
|
139
140
|
|
|
140
|
-
context
|
|
141
|
-
|
|
141
|
+
context 'when the document is found via #find' do
|
|
142
142
|
let(:from_db) do
|
|
143
143
|
Player.find(player.id).implants.first
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
it
|
|
146
|
+
it 'executes the callback' do
|
|
147
147
|
expect(from_db.impressions).to eq(1)
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
context
|
|
152
|
-
|
|
151
|
+
context 'when the document is found in a criteria' do
|
|
153
152
|
let(:from_db) do
|
|
154
153
|
Player.find(player.id).implants.find(implant.id)
|
|
155
154
|
end
|
|
156
155
|
|
|
157
|
-
it
|
|
156
|
+
it 'executes the callback' do
|
|
158
157
|
expect(from_db.impressions).to eq(1)
|
|
159
158
|
end
|
|
160
159
|
end
|
|
161
160
|
end
|
|
162
161
|
end
|
|
163
162
|
|
|
164
|
-
describe
|
|
165
|
-
|
|
163
|
+
describe '.after_initialize' do
|
|
166
164
|
let(:game) do
|
|
167
165
|
Game.new
|
|
168
166
|
end
|
|
169
167
|
|
|
170
|
-
it
|
|
171
|
-
expect(game.name).to eq(
|
|
168
|
+
it 'runs after document instantiation' do
|
|
169
|
+
expect(game.name).to eq('Testing')
|
|
172
170
|
end
|
|
173
171
|
|
|
174
172
|
context 'when the document is embedded' do
|
|
175
|
-
|
|
176
173
|
after do
|
|
177
174
|
Book.destroy_all
|
|
178
175
|
end
|
|
179
176
|
|
|
180
177
|
let(:book) do
|
|
181
178
|
book = Book.new({
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
179
|
+
pages: [
|
|
180
|
+
{
|
|
181
|
+
content: 'Page 1',
|
|
182
|
+
notes: [
|
|
183
|
+
{ message: 'Page 1 / Note A' },
|
|
184
|
+
{ message: 'Page 1 / Note B' }
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
content: 'Page 2',
|
|
189
|
+
notes: [
|
|
190
|
+
{ message: 'Page 2 / Note A' },
|
|
191
|
+
{ message: 'Page 2 / Note B' }
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
})
|
|
199
196
|
book.id = '123'
|
|
200
|
-
book.save
|
|
197
|
+
book.save!
|
|
201
198
|
book
|
|
202
199
|
end
|
|
200
|
+
let(:expected_messages) do
|
|
201
|
+
book.reload.pages.reduce([]) do |messages, p|
|
|
202
|
+
messages + p.notes.reduce([]) do |msgs, n|
|
|
203
|
+
msgs << n.message
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
203
207
|
|
|
204
208
|
let(:new_message) do
|
|
205
209
|
'Note C'
|
|
206
210
|
end
|
|
207
211
|
|
|
208
212
|
before do
|
|
209
|
-
book.pages.each do |
|
|
213
|
+
book.pages.each do |page|
|
|
210
214
|
page.notes.destroy_all
|
|
211
215
|
page.notes.new(message: new_message)
|
|
212
|
-
page.save
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
let(:expected_messages) do
|
|
217
|
-
book.reload.pages.reduce([]) do |messages, p|
|
|
218
|
-
messages += p.notes.reduce([]) do |msgs, n|
|
|
219
|
-
msgs << n.message
|
|
220
|
-
end
|
|
216
|
+
page.save!
|
|
221
217
|
end
|
|
222
218
|
end
|
|
223
219
|
|
|
@@ -227,61 +223,55 @@ describe Mongoid::Interceptable do
|
|
|
227
223
|
end
|
|
228
224
|
end
|
|
229
225
|
|
|
230
|
-
describe
|
|
231
|
-
|
|
226
|
+
describe '.after_build' do
|
|
232
227
|
let(:weapon) do
|
|
233
228
|
Player.new(frags: 5).weapons.build
|
|
234
229
|
end
|
|
235
230
|
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
let(:augmentation) do
|
|
232
|
+
Player.new(frags: 5).build_augmentation
|
|
233
|
+
end
|
|
234
|
+
let(:powerup) do
|
|
235
|
+
Player.new(frags: 5).build_powerup
|
|
238
236
|
end
|
|
239
|
-
|
|
240
237
|
let(:implant) do
|
|
241
238
|
Player.new(frags: 5).implants.build
|
|
242
239
|
end
|
|
243
240
|
|
|
244
|
-
it
|
|
245
|
-
expect(
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
let(:powerup) do
|
|
249
|
-
Player.new(frags: 5).build_powerup
|
|
241
|
+
it 'runs after document build (references_many)' do
|
|
242
|
+
expect(weapon.name).to eq('Holy Hand Grenade (5)')
|
|
250
243
|
end
|
|
251
244
|
|
|
252
|
-
it
|
|
253
|
-
expect(
|
|
245
|
+
it 'runs after document build (embeds_many)' do
|
|
246
|
+
expect(implant.name).to eq('Cochlear Implant (5)')
|
|
254
247
|
end
|
|
255
248
|
|
|
256
|
-
|
|
257
|
-
|
|
249
|
+
it 'runs after document build (references_one)' do
|
|
250
|
+
expect(powerup.name).to eq('Quad Damage (5)')
|
|
258
251
|
end
|
|
259
252
|
|
|
260
|
-
it
|
|
261
|
-
expect(augmentation.name).to eq(
|
|
253
|
+
it 'runs after document build (embeds_one)' do
|
|
254
|
+
expect(augmentation.name).to eq('Infolink (5)')
|
|
262
255
|
end
|
|
263
256
|
end
|
|
264
257
|
|
|
265
|
-
describe
|
|
266
|
-
|
|
258
|
+
describe '.before_create' do
|
|
267
259
|
let(:artist) do
|
|
268
|
-
Artist.new(name:
|
|
260
|
+
Artist.new(name: 'Depeche Mode')
|
|
269
261
|
end
|
|
270
262
|
|
|
271
|
-
context
|
|
272
|
-
|
|
263
|
+
context 'callback returns true' do
|
|
273
264
|
before do
|
|
274
265
|
expect(artist).to receive(:before_create_stub).once.and_return(true)
|
|
275
|
-
artist.save
|
|
266
|
+
artist.save!
|
|
276
267
|
end
|
|
277
268
|
|
|
278
|
-
it
|
|
269
|
+
it 'gets saved' do
|
|
279
270
|
expect(artist.persisted?).to be true
|
|
280
271
|
end
|
|
281
272
|
end
|
|
282
273
|
|
|
283
|
-
context
|
|
284
|
-
|
|
274
|
+
context 'callback aborts the callback chain' do
|
|
285
275
|
before do
|
|
286
276
|
Artist.before_create(:before_create_fail_stub)
|
|
287
277
|
expect(artist).to receive(:before_create_fail_stub).once.and_call_original
|
|
@@ -292,37 +282,33 @@ describe Mongoid::Interceptable do
|
|
|
292
282
|
Artist.reset_callbacks(:create)
|
|
293
283
|
end
|
|
294
284
|
|
|
295
|
-
it
|
|
285
|
+
it 'does not get saved' do
|
|
296
286
|
expect(artist.persisted?).to be false
|
|
297
287
|
end
|
|
298
288
|
end
|
|
299
289
|
end
|
|
300
290
|
|
|
301
|
-
describe
|
|
302
|
-
|
|
303
|
-
context "when creating" do
|
|
304
|
-
|
|
291
|
+
describe '.before_save' do
|
|
292
|
+
context 'when creating' do
|
|
305
293
|
let(:artist) do
|
|
306
|
-
Artist.new(name:
|
|
294
|
+
Artist.new(name: 'Depeche Mode')
|
|
307
295
|
end
|
|
308
296
|
|
|
309
297
|
after do
|
|
310
298
|
artist.delete
|
|
311
299
|
end
|
|
312
300
|
|
|
313
|
-
context
|
|
314
|
-
|
|
301
|
+
context 'when the callback returns true' do
|
|
315
302
|
before do
|
|
316
303
|
expect(artist).to receive(:before_save_stub).once.and_return(true)
|
|
317
304
|
end
|
|
318
305
|
|
|
319
|
-
it
|
|
320
|
-
expect(artist.save).to be true
|
|
306
|
+
it 'the save returns true' do
|
|
307
|
+
expect(artist.save!).to be true
|
|
321
308
|
end
|
|
322
309
|
end
|
|
323
310
|
|
|
324
|
-
context
|
|
325
|
-
|
|
311
|
+
context 'when callback halts the callback chain' do
|
|
326
312
|
before do
|
|
327
313
|
Artist.before_save(:before_save_fail_stub)
|
|
328
314
|
end
|
|
@@ -331,18 +317,17 @@ describe Mongoid::Interceptable do
|
|
|
331
317
|
Artist.reset_callbacks(:save)
|
|
332
318
|
end
|
|
333
319
|
|
|
334
|
-
it
|
|
320
|
+
it 'the save returns false' do
|
|
335
321
|
expect(artist).to receive(:before_save_fail_stub).once.and_call_original
|
|
336
322
|
expect(artist.save).to be false
|
|
337
323
|
end
|
|
338
324
|
end
|
|
339
325
|
end
|
|
340
326
|
|
|
341
|
-
context
|
|
342
|
-
|
|
327
|
+
context 'when updating' do
|
|
343
328
|
let(:artist) do
|
|
344
|
-
Artist.create(name:
|
|
345
|
-
artist.name =
|
|
329
|
+
Artist.create!(name: 'Depeche Mode').tap do |artist|
|
|
330
|
+
artist.name = 'The Mountain Goats'
|
|
346
331
|
end
|
|
347
332
|
end
|
|
348
333
|
|
|
@@ -350,19 +335,17 @@ describe Mongoid::Interceptable do
|
|
|
350
335
|
artist.delete
|
|
351
336
|
end
|
|
352
337
|
|
|
353
|
-
context
|
|
354
|
-
|
|
338
|
+
context 'when the callback returns true' do
|
|
355
339
|
before do
|
|
356
340
|
expect(artist).to receive(:before_update_stub).once.and_return(true)
|
|
357
341
|
end
|
|
358
342
|
|
|
359
|
-
it
|
|
360
|
-
expect(artist.save).to be true
|
|
343
|
+
it 'the save returns true' do
|
|
344
|
+
expect(artist.save!).to be true
|
|
361
345
|
end
|
|
362
346
|
end
|
|
363
347
|
|
|
364
|
-
context
|
|
365
|
-
|
|
348
|
+
context 'when the callback halts the callback chain' do
|
|
366
349
|
before do
|
|
367
350
|
Artist.before_update(:before_update_fail_stub)
|
|
368
351
|
end
|
|
@@ -371,41 +354,116 @@ describe Mongoid::Interceptable do
|
|
|
371
354
|
Artist.reset_callbacks(:update)
|
|
372
355
|
end
|
|
373
356
|
|
|
374
|
-
it
|
|
357
|
+
it 'the save returns false' do
|
|
375
358
|
expect(artist).to receive(:before_update_fail_stub).once.and_call_original
|
|
376
359
|
expect(artist.save).to be false
|
|
377
360
|
end
|
|
378
361
|
end
|
|
379
362
|
end
|
|
380
|
-
end
|
|
381
363
|
|
|
382
|
-
|
|
364
|
+
context 'with embedded grandchildren' do
|
|
365
|
+
IS = InterceptableSpec
|
|
366
|
+
|
|
367
|
+
context 'when creating' do
|
|
368
|
+
let(:registry) { IS::CallbackRegistry.new(only: %i[ before_save ]) }
|
|
369
|
+
|
|
370
|
+
let(:expected_calls) do
|
|
371
|
+
[
|
|
372
|
+
# the parent
|
|
373
|
+
[ IS::CbParent, :before_save ],
|
|
374
|
+
|
|
375
|
+
# the immediate child of the parent
|
|
376
|
+
[ IS::CbCascadedNode, :before_save ],
|
|
377
|
+
|
|
378
|
+
# the grandchild of the parent
|
|
379
|
+
[ IS::CbCascadedNode, :before_save ]
|
|
380
|
+
]
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
let!(:parent) do
|
|
384
|
+
parent = IS::CbParent.new(registry)
|
|
385
|
+
child = IS::CbCascadedNode.new(registry)
|
|
386
|
+
grandchild = IS::CbCascadedNode.new(registry)
|
|
387
|
+
|
|
388
|
+
child.cb_cascaded_nodes = [ grandchild ]
|
|
389
|
+
parent.cb_cascaded_nodes = [ child ]
|
|
390
|
+
|
|
391
|
+
parent.tap(&:save)
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
it 'cascades callbacks to grandchildren' do
|
|
395
|
+
expect(registry.calls).to eq expected_calls
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
context 'when updating' do
|
|
400
|
+
let(:registry) { IS::CallbackRegistry.new(only: %i[ before_update ]) }
|
|
401
|
+
|
|
402
|
+
let(:expected_calls) do
|
|
403
|
+
[
|
|
404
|
+
# the parent
|
|
405
|
+
[ IS::CbParent, :before_update ],
|
|
406
|
+
|
|
407
|
+
# the immediate child of the parent
|
|
408
|
+
[ IS::CbCascadedNode, :before_update ],
|
|
409
|
+
|
|
410
|
+
# the grandchild of the parent
|
|
411
|
+
[ IS::CbCascadedNode, :before_update ]
|
|
412
|
+
]
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
let!(:parent) do
|
|
416
|
+
parent = IS::CbParent.new(nil)
|
|
417
|
+
child = IS::CbCascadedNode.new(nil)
|
|
418
|
+
grandchild = IS::CbCascadedNode.new(nil)
|
|
419
|
+
|
|
420
|
+
child.cb_cascaded_nodes = [ grandchild ]
|
|
421
|
+
parent.cb_cascaded_nodes = [ child ]
|
|
383
422
|
|
|
423
|
+
parent.save
|
|
424
|
+
|
|
425
|
+
parent.callback_registry = registry
|
|
426
|
+
child.callback_registry = registry
|
|
427
|
+
grandchild.callback_registry = registry
|
|
428
|
+
|
|
429
|
+
parent.name = 'updated'
|
|
430
|
+
child.name = 'updated'
|
|
431
|
+
grandchild.name = 'updated'
|
|
432
|
+
|
|
433
|
+
parent.tap(&:save)
|
|
434
|
+
end
|
|
435
|
+
|
|
436
|
+
it 'cascades callbacks to grandchildren' do
|
|
437
|
+
expect(registry.calls).to eq expected_calls
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
describe '.before_destroy' do
|
|
384
444
|
let(:artist) do
|
|
385
|
-
Artist.create(name:
|
|
445
|
+
Artist.create!(name: 'Depeche Mode')
|
|
386
446
|
end
|
|
387
447
|
|
|
388
448
|
before do
|
|
389
|
-
artist.name =
|
|
449
|
+
artist.name = 'The Mountain Goats'
|
|
390
450
|
end
|
|
391
451
|
|
|
392
452
|
after do
|
|
393
453
|
artist.delete
|
|
394
454
|
end
|
|
395
455
|
|
|
396
|
-
context
|
|
397
|
-
|
|
456
|
+
context 'when the callback returns true' do
|
|
398
457
|
before do
|
|
399
458
|
expect(artist).to receive(:before_destroy_stub).once.and_return(true)
|
|
400
459
|
end
|
|
401
460
|
|
|
402
|
-
it
|
|
461
|
+
it 'the destroy returns true' do
|
|
403
462
|
expect(artist.destroy).to be true
|
|
404
463
|
end
|
|
405
464
|
end
|
|
406
465
|
|
|
407
|
-
context
|
|
408
|
-
|
|
466
|
+
context 'when the callback halts the callback chain' do
|
|
409
467
|
before do
|
|
410
468
|
Artist.before_destroy(:before_destroy_fail_stub)
|
|
411
469
|
end
|
|
@@ -414,34 +472,32 @@ describe Mongoid::Interceptable do
|
|
|
414
472
|
Artist.reset_callbacks(:destroy)
|
|
415
473
|
end
|
|
416
474
|
|
|
417
|
-
it
|
|
475
|
+
it 'the destroy returns false' do
|
|
418
476
|
expect(artist).to receive(:before_destroy_fail_stub).once.and_call_original
|
|
419
477
|
expect(artist.destroy).to be false
|
|
420
478
|
end
|
|
421
479
|
end
|
|
422
480
|
|
|
423
|
-
context
|
|
424
|
-
|
|
481
|
+
context 'when cascading callbacks' do
|
|
425
482
|
let!(:moderat) do
|
|
426
|
-
Band.create!(name:
|
|
483
|
+
Band.create!(name: 'Moderat')
|
|
427
484
|
end
|
|
428
485
|
|
|
429
486
|
let!(:record) do
|
|
430
|
-
moderat.records.create(name:
|
|
487
|
+
moderat.records.create!(name: 'Moderat')
|
|
431
488
|
end
|
|
432
489
|
|
|
433
490
|
before do
|
|
434
491
|
moderat.destroy
|
|
435
492
|
end
|
|
436
493
|
|
|
437
|
-
it
|
|
494
|
+
it 'executes the child destroy callbacks' do
|
|
438
495
|
expect(record.before_destroy_called).to be true
|
|
439
496
|
end
|
|
440
497
|
end
|
|
441
498
|
end
|
|
442
499
|
|
|
443
|
-
describe
|
|
444
|
-
|
|
500
|
+
describe '#run_after_callbacks' do
|
|
445
501
|
let(:object) do
|
|
446
502
|
TestClass.new
|
|
447
503
|
end
|
|
@@ -450,17 +506,16 @@ describe Mongoid::Interceptable do
|
|
|
450
506
|
object.run_after_callbacks(:save)
|
|
451
507
|
end
|
|
452
508
|
|
|
453
|
-
it
|
|
509
|
+
it 'runs the after callbacks' do
|
|
454
510
|
expect(object.after_save_called).to be true
|
|
455
511
|
end
|
|
456
512
|
|
|
457
|
-
it
|
|
458
|
-
expect(object.before_save_called).to
|
|
513
|
+
it 'does not run the before callbacks' do
|
|
514
|
+
expect(object.before_save_called).to be_nil
|
|
459
515
|
end
|
|
460
516
|
end
|
|
461
517
|
|
|
462
|
-
describe
|
|
463
|
-
|
|
518
|
+
describe '#run_before_callbacks' do
|
|
464
519
|
let(:object) do
|
|
465
520
|
TestClass.new
|
|
466
521
|
end
|
|
@@ -469,21 +524,18 @@ describe Mongoid::Interceptable do
|
|
|
469
524
|
object.run_before_callbacks(:save)
|
|
470
525
|
end
|
|
471
526
|
|
|
472
|
-
it
|
|
527
|
+
it 'runs the before callbacks' do
|
|
473
528
|
expect(object.before_save_called).to be true
|
|
474
529
|
end
|
|
475
530
|
|
|
476
|
-
it
|
|
477
|
-
expect(object.after_save_called).to
|
|
531
|
+
it 'does not run the after callbacks' do
|
|
532
|
+
expect(object.after_save_called).to be_nil
|
|
478
533
|
end
|
|
479
534
|
end
|
|
480
535
|
|
|
481
|
-
context
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
context "when the child does not have the same callback defined" do
|
|
486
|
-
|
|
536
|
+
context 'when cascading callbacks' do
|
|
537
|
+
context 'when the parent has a custom callback' do
|
|
538
|
+
context 'when the child does not have the same callback defined' do
|
|
487
539
|
let(:exhibition) do
|
|
488
540
|
Exhibition.new
|
|
489
541
|
end
|
|
@@ -492,27 +544,32 @@ describe Mongoid::Interceptable do
|
|
|
492
544
|
exhibition.exhibitors.build
|
|
493
545
|
end
|
|
494
546
|
|
|
495
|
-
context
|
|
496
|
-
|
|
547
|
+
context 'when running the callbacks directly' do
|
|
497
548
|
before(:all) do
|
|
498
549
|
Exhibition.define_model_callbacks(:rearrange)
|
|
499
|
-
Exhibition.after_rearrange {
|
|
550
|
+
Exhibition.after_rearrange {}
|
|
500
551
|
end
|
|
501
552
|
|
|
502
553
|
after(:all) do
|
|
503
554
|
Exhibition.reset_callbacks(:rearrange)
|
|
504
555
|
end
|
|
505
556
|
|
|
506
|
-
it
|
|
557
|
+
it 'does not cascade to the child' do
|
|
507
558
|
expect(exhibition.run_callbacks(:rearrange)).to be true
|
|
508
559
|
end
|
|
509
560
|
end
|
|
510
561
|
|
|
511
|
-
context
|
|
512
|
-
|
|
562
|
+
context 'when the callbacks get triggered by a destroy' do
|
|
513
563
|
let(:band) do
|
|
514
564
|
Band.new
|
|
515
565
|
end
|
|
566
|
+
let(:attributes) do
|
|
567
|
+
{
|
|
568
|
+
records_attributes: {
|
|
569
|
+
'0' => { '_id' => record.id, '_destroy' => true }
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
end
|
|
516
573
|
|
|
517
574
|
let!(:record) do
|
|
518
575
|
band.records.build
|
|
@@ -528,27 +585,18 @@ describe Mongoid::Interceptable do
|
|
|
528
585
|
after(:all) do
|
|
529
586
|
# ActiveSupport may raise an error when trying to reset callbacks on all of Band's
|
|
530
587
|
# descendants, regardless of whether they have a particular callback defined.
|
|
531
|
-
|
|
532
|
-
end
|
|
533
|
-
|
|
534
|
-
let(:attributes) do
|
|
535
|
-
{
|
|
536
|
-
records_attributes: {
|
|
537
|
-
"0" => { "_id" => record.id, "_destroy" => true }
|
|
538
|
-
}
|
|
539
|
-
}
|
|
588
|
+
Band.reset_callbacks(:rearrange); rescue StandardError
|
|
540
589
|
end
|
|
541
590
|
|
|
542
|
-
it
|
|
591
|
+
it 'does not cascade to the child' do
|
|
543
592
|
Band.accepts_nested_attributes_for :records, allow_destroy: true
|
|
544
|
-
expect(band.update_attributes(attributes)).to be true
|
|
593
|
+
expect(band.update_attributes!(attributes)).to be true
|
|
545
594
|
end
|
|
546
595
|
end
|
|
547
596
|
end
|
|
548
597
|
end
|
|
549
598
|
|
|
550
|
-
context
|
|
551
|
-
|
|
599
|
+
context 'when a document can exist in more than 1 level' do
|
|
552
600
|
let(:band) do
|
|
553
601
|
Band.new
|
|
554
602
|
end
|
|
@@ -561,27 +609,39 @@ describe Mongoid::Interceptable do
|
|
|
561
609
|
Note.new
|
|
562
610
|
end
|
|
563
611
|
|
|
564
|
-
context
|
|
565
|
-
|
|
612
|
+
context 'when adding the document at multiple levels' do
|
|
566
613
|
before do
|
|
567
614
|
band.notes.push(note)
|
|
568
615
|
record.notes.push(note)
|
|
569
616
|
end
|
|
570
617
|
|
|
571
|
-
context
|
|
618
|
+
context 'when saving the root' do
|
|
619
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks enabled' do
|
|
620
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, true
|
|
621
|
+
config_override :around_callbacks_for_embeds, true
|
|
622
|
+
|
|
623
|
+
it 'executes the callbacks only once for each document' do
|
|
624
|
+
expect(note).to receive(:update_saved).once
|
|
625
|
+
band.save!
|
|
626
|
+
end
|
|
627
|
+
end
|
|
572
628
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
629
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks disabled' do
|
|
630
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, false
|
|
631
|
+
config_override :around_callbacks_for_embeds, true
|
|
632
|
+
|
|
633
|
+
it 'executes the callbacks once for each ember' do
|
|
634
|
+
expect(note).to receive(:update_saved).twice
|
|
635
|
+
band.save!
|
|
636
|
+
end
|
|
576
637
|
end
|
|
577
638
|
end
|
|
578
639
|
end
|
|
579
640
|
end
|
|
580
641
|
|
|
581
|
-
context
|
|
582
|
-
|
|
642
|
+
context 'when cascading after initialize' do
|
|
583
643
|
let!(:person) do
|
|
584
|
-
Person.create
|
|
644
|
+
Person.create!
|
|
585
645
|
end
|
|
586
646
|
|
|
587
647
|
before do
|
|
@@ -589,588 +649,541 @@ describe Mongoid::Interceptable do
|
|
|
589
649
|
end
|
|
590
650
|
|
|
591
651
|
it "doesn't cascade the initialize" do
|
|
592
|
-
expect_any_instance_of(Service).
|
|
652
|
+
expect_any_instance_of(Service).not_to receive(:after_initialize_called=)
|
|
593
653
|
expect(Person.find(person.id)).to eq(person)
|
|
594
654
|
end
|
|
595
655
|
end
|
|
596
656
|
|
|
597
|
-
context
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
expect {
|
|
657
|
+
context 'when attempting to cascade on a referenced relation' do
|
|
658
|
+
it 'raises an error' do
|
|
659
|
+
expect do
|
|
601
660
|
Band.has_and_belongs_to_many :tags, cascade_callbacks: true
|
|
602
|
-
|
|
661
|
+
end.to raise_error(Mongoid::Errors::InvalidRelationOption)
|
|
603
662
|
end
|
|
604
663
|
end
|
|
605
664
|
|
|
606
|
-
context
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
context "when the child is new" do
|
|
611
|
-
|
|
612
|
-
context "when the parent is new" do
|
|
613
|
-
|
|
665
|
+
context 'when the documents are embedded one level' do
|
|
666
|
+
describe '#after_create' do
|
|
667
|
+
context 'when the child is new' do
|
|
668
|
+
context 'when the parent is new' do
|
|
614
669
|
let(:band) do
|
|
615
|
-
Band.new(name:
|
|
670
|
+
Band.new(name: 'Moderat')
|
|
616
671
|
end
|
|
617
672
|
|
|
618
673
|
let!(:label) do
|
|
619
|
-
band.build_label(name:
|
|
674
|
+
band.build_label(name: 'Mute')
|
|
620
675
|
end
|
|
621
676
|
|
|
622
677
|
before do
|
|
623
|
-
band.save
|
|
678
|
+
band.save!
|
|
624
679
|
end
|
|
625
680
|
|
|
626
|
-
it
|
|
681
|
+
it 'executes the callback' do
|
|
627
682
|
expect(label.after_create_called).to be true
|
|
628
683
|
end
|
|
629
684
|
end
|
|
630
685
|
|
|
631
|
-
context
|
|
632
|
-
|
|
686
|
+
context 'when the parent is persisted' do
|
|
633
687
|
let(:band) do
|
|
634
|
-
Band.create(name:
|
|
688
|
+
Band.create!(name: 'Moderat')
|
|
635
689
|
end
|
|
636
690
|
|
|
637
691
|
let!(:label) do
|
|
638
|
-
band.build_label(name:
|
|
692
|
+
band.build_label(name: 'Mute')
|
|
639
693
|
end
|
|
640
694
|
|
|
641
695
|
before do
|
|
642
|
-
band.save
|
|
696
|
+
band.save!
|
|
643
697
|
end
|
|
644
698
|
|
|
645
|
-
it
|
|
699
|
+
it 'executes the callback' do
|
|
646
700
|
expect(label.after_create_called).to be true
|
|
647
701
|
end
|
|
648
702
|
end
|
|
649
703
|
end
|
|
650
704
|
|
|
651
|
-
context
|
|
652
|
-
|
|
705
|
+
context 'when the child is persisted' do
|
|
653
706
|
let(:band) do
|
|
654
|
-
Band.create(name:
|
|
707
|
+
Band.create!(name: 'Moderat')
|
|
655
708
|
end
|
|
656
709
|
|
|
657
710
|
let!(:label) do
|
|
658
|
-
band.create_label(name:
|
|
711
|
+
band.create_label(name: 'Mute')
|
|
659
712
|
end
|
|
660
713
|
|
|
661
714
|
before do
|
|
662
715
|
label.after_create_called = false
|
|
663
|
-
band.save
|
|
716
|
+
band.save!
|
|
664
717
|
end
|
|
665
718
|
|
|
666
|
-
it
|
|
719
|
+
it 'does not execute the callback' do
|
|
667
720
|
expect(label.after_create_called).to be false
|
|
668
721
|
end
|
|
669
722
|
end
|
|
670
723
|
end
|
|
671
724
|
|
|
672
|
-
describe
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
context "when the parent is new" do
|
|
677
|
-
|
|
725
|
+
describe '#after_save' do
|
|
726
|
+
context 'when the child is new' do
|
|
727
|
+
context 'when the parent is new' do
|
|
678
728
|
let(:band) do
|
|
679
|
-
Band.new(name:
|
|
729
|
+
Band.new(name: 'Moderat')
|
|
680
730
|
end
|
|
681
731
|
|
|
682
732
|
let!(:label) do
|
|
683
|
-
band.build_label(name:
|
|
733
|
+
band.build_label(name: 'Mute')
|
|
684
734
|
end
|
|
685
735
|
|
|
686
736
|
before do
|
|
687
|
-
band.save
|
|
737
|
+
band.save!
|
|
688
738
|
end
|
|
689
739
|
|
|
690
|
-
it
|
|
740
|
+
it 'executes the callback' do
|
|
691
741
|
expect(label.after_save_called).to be true
|
|
692
742
|
end
|
|
693
743
|
end
|
|
694
744
|
|
|
695
|
-
context
|
|
696
|
-
|
|
745
|
+
context 'when the parent is persisted' do
|
|
697
746
|
let(:band) do
|
|
698
|
-
Band.create(name:
|
|
747
|
+
Band.create!(name: 'Moderat')
|
|
699
748
|
end
|
|
700
749
|
|
|
701
750
|
let!(:label) do
|
|
702
|
-
band.build_label(name:
|
|
751
|
+
band.build_label(name: 'Mute')
|
|
703
752
|
end
|
|
704
753
|
|
|
705
754
|
before do
|
|
706
|
-
band.save
|
|
755
|
+
band.save!
|
|
707
756
|
end
|
|
708
757
|
|
|
709
|
-
it
|
|
758
|
+
it 'executes the callback' do
|
|
710
759
|
expect(label.after_save_called).to be true
|
|
711
760
|
end
|
|
712
761
|
end
|
|
713
762
|
end
|
|
714
763
|
|
|
715
|
-
context
|
|
716
|
-
|
|
764
|
+
context 'when the child is persisted' do
|
|
717
765
|
let(:band) do
|
|
718
|
-
Band.create(name:
|
|
766
|
+
Band.create!(name: 'Moderat')
|
|
719
767
|
end
|
|
720
768
|
|
|
721
769
|
let!(:label) do
|
|
722
|
-
band.create_label(name:
|
|
770
|
+
band.create_label(name: 'Mute')
|
|
723
771
|
end
|
|
724
772
|
|
|
725
773
|
before do
|
|
726
|
-
band.save
|
|
774
|
+
band.save!
|
|
727
775
|
end
|
|
728
776
|
|
|
729
|
-
it
|
|
777
|
+
it 'executes the callback' do
|
|
730
778
|
expect(label.after_save_called).to be true
|
|
731
779
|
end
|
|
732
780
|
end
|
|
733
781
|
end
|
|
734
782
|
|
|
735
|
-
describe
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
context "when the parent is new" do
|
|
740
|
-
|
|
783
|
+
describe '#after_update' do
|
|
784
|
+
context 'when the child is new' do
|
|
785
|
+
context 'when the parent is new' do
|
|
741
786
|
let(:band) do
|
|
742
|
-
Band.new(name:
|
|
787
|
+
Band.new(name: 'Moderat')
|
|
743
788
|
end
|
|
744
789
|
|
|
745
790
|
let!(:label) do
|
|
746
|
-
band.build_label(name:
|
|
791
|
+
band.build_label(name: 'Mute')
|
|
747
792
|
end
|
|
748
793
|
|
|
749
794
|
before do
|
|
750
|
-
band.save
|
|
795
|
+
band.save!
|
|
751
796
|
end
|
|
752
797
|
|
|
753
|
-
it
|
|
798
|
+
it 'does not execute the callback' do
|
|
754
799
|
expect(label.after_update_called).to be false
|
|
755
800
|
end
|
|
756
801
|
end
|
|
757
802
|
|
|
758
|
-
context
|
|
759
|
-
|
|
803
|
+
context 'when the parent is persisted' do
|
|
760
804
|
let(:band) do
|
|
761
|
-
Band.create(name:
|
|
805
|
+
Band.create!(name: 'Moderat')
|
|
762
806
|
end
|
|
763
807
|
|
|
764
808
|
let!(:label) do
|
|
765
|
-
band.build_label(name:
|
|
809
|
+
band.build_label(name: 'Mute')
|
|
766
810
|
end
|
|
767
811
|
|
|
768
812
|
before do
|
|
769
|
-
band.save
|
|
813
|
+
band.save!
|
|
770
814
|
end
|
|
771
815
|
|
|
772
|
-
it
|
|
816
|
+
it 'does not execute the callback' do
|
|
773
817
|
expect(label.after_update_called).to be false
|
|
774
818
|
end
|
|
775
819
|
end
|
|
776
820
|
end
|
|
777
821
|
|
|
778
|
-
context
|
|
779
|
-
|
|
822
|
+
context 'when the child is persisted' do
|
|
780
823
|
let(:band) do
|
|
781
|
-
Band.create(name:
|
|
824
|
+
Band.create!(name: 'Moderat')
|
|
782
825
|
end
|
|
783
826
|
|
|
784
|
-
context
|
|
785
|
-
|
|
827
|
+
context 'when the child is dirty' do
|
|
786
828
|
let!(:label) do
|
|
787
|
-
band.create_label(name:
|
|
829
|
+
band.create_label(name: 'Mute')
|
|
788
830
|
end
|
|
789
831
|
|
|
790
832
|
before do
|
|
791
|
-
label.name =
|
|
792
|
-
band.save
|
|
833
|
+
label.name = 'Nothing'
|
|
834
|
+
band.save!
|
|
793
835
|
end
|
|
794
836
|
|
|
795
|
-
it
|
|
837
|
+
it 'executes the callback' do
|
|
796
838
|
expect(label.after_update_called).to be true
|
|
797
839
|
end
|
|
798
840
|
end
|
|
799
841
|
|
|
800
|
-
context
|
|
801
|
-
|
|
842
|
+
context 'when the child is not dirty' do
|
|
802
843
|
let!(:label) do
|
|
803
|
-
band.build_label(name:
|
|
844
|
+
band.build_label(name: 'Mute')
|
|
804
845
|
end
|
|
805
846
|
|
|
806
847
|
before do
|
|
807
|
-
band.save
|
|
848
|
+
band.save!
|
|
808
849
|
end
|
|
809
850
|
|
|
810
|
-
it
|
|
851
|
+
it 'does not execute the callback' do
|
|
811
852
|
expect(label.after_update_called).to be false
|
|
812
853
|
end
|
|
813
854
|
end
|
|
814
855
|
end
|
|
815
856
|
end
|
|
816
857
|
|
|
817
|
-
describe
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
context "when the parent is new" do
|
|
822
|
-
|
|
858
|
+
describe '#after_validation' do
|
|
859
|
+
context 'when the child is new' do
|
|
860
|
+
context 'when the parent is new' do
|
|
823
861
|
let(:band) do
|
|
824
|
-
Band.new(name:
|
|
862
|
+
Band.new(name: 'Moderat')
|
|
825
863
|
end
|
|
826
864
|
|
|
827
865
|
let!(:label) do
|
|
828
|
-
band.build_label(name:
|
|
866
|
+
band.build_label(name: 'Mute')
|
|
829
867
|
end
|
|
830
868
|
|
|
831
869
|
before do
|
|
832
|
-
band.save
|
|
870
|
+
band.save!
|
|
833
871
|
end
|
|
834
872
|
|
|
835
|
-
it
|
|
873
|
+
it 'executes the callback' do
|
|
836
874
|
expect(label.after_validation_called).to be true
|
|
837
875
|
end
|
|
838
876
|
end
|
|
839
877
|
|
|
840
|
-
context
|
|
841
|
-
|
|
878
|
+
context 'when the parent is persisted' do
|
|
842
879
|
let(:band) do
|
|
843
|
-
Band.create(name:
|
|
880
|
+
Band.create!(name: 'Moderat')
|
|
844
881
|
end
|
|
845
882
|
|
|
846
883
|
let!(:label) do
|
|
847
|
-
band.build_label(name:
|
|
884
|
+
band.build_label(name: 'Mute')
|
|
848
885
|
end
|
|
849
886
|
|
|
850
887
|
before do
|
|
851
|
-
band.save
|
|
888
|
+
band.save!
|
|
852
889
|
end
|
|
853
890
|
|
|
854
|
-
it
|
|
891
|
+
it 'executes the callback' do
|
|
855
892
|
expect(label.after_validation_called).to be true
|
|
856
893
|
end
|
|
857
894
|
end
|
|
858
895
|
end
|
|
859
896
|
|
|
860
|
-
context
|
|
861
|
-
|
|
897
|
+
context 'when the child is persisted' do
|
|
862
898
|
let(:band) do
|
|
863
|
-
Band.create(name:
|
|
899
|
+
Band.create!(name: 'Moderat')
|
|
864
900
|
end
|
|
865
901
|
|
|
866
902
|
let!(:label) do
|
|
867
|
-
band.create_label(name:
|
|
903
|
+
band.create_label(name: 'Mute')
|
|
868
904
|
end
|
|
869
905
|
|
|
870
906
|
before do
|
|
871
|
-
band.save
|
|
907
|
+
band.save!
|
|
872
908
|
end
|
|
873
909
|
|
|
874
|
-
it
|
|
910
|
+
it 'executes the callback' do
|
|
875
911
|
expect(label.after_validation_called).to be true
|
|
876
912
|
end
|
|
877
913
|
end
|
|
878
914
|
end
|
|
879
915
|
|
|
880
|
-
describe
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
context "when the parent is new" do
|
|
885
|
-
|
|
916
|
+
describe '#before_create' do
|
|
917
|
+
context 'when the child is new' do
|
|
918
|
+
context 'when the parent is new' do
|
|
886
919
|
let(:band) do
|
|
887
|
-
Band.new(name:
|
|
920
|
+
Band.new(name: 'Moderat')
|
|
888
921
|
end
|
|
889
922
|
|
|
890
923
|
let!(:record) do
|
|
891
|
-
band.records.build(name:
|
|
924
|
+
band.records.build(name: 'Moderat')
|
|
892
925
|
end
|
|
893
926
|
|
|
894
927
|
before do
|
|
895
|
-
band.save
|
|
928
|
+
band.save!
|
|
896
929
|
end
|
|
897
930
|
|
|
898
|
-
it
|
|
931
|
+
it 'executes the callback' do
|
|
899
932
|
expect(record.before_create_called).to be true
|
|
900
933
|
end
|
|
901
934
|
end
|
|
902
935
|
|
|
903
|
-
context
|
|
904
|
-
|
|
936
|
+
context 'when the parent is persisted' do
|
|
905
937
|
let(:band) do
|
|
906
|
-
Band.create(name:
|
|
938
|
+
Band.create!(name: 'Moderat')
|
|
907
939
|
end
|
|
908
940
|
|
|
909
941
|
let!(:record) do
|
|
910
|
-
band.records.build(name:
|
|
942
|
+
band.records.build(name: 'Moderat')
|
|
911
943
|
end
|
|
912
944
|
|
|
913
945
|
before do
|
|
914
|
-
band.save
|
|
946
|
+
band.save!
|
|
915
947
|
end
|
|
916
948
|
|
|
917
|
-
it
|
|
949
|
+
it 'executes the callback' do
|
|
918
950
|
expect(record.before_create_called).to be true
|
|
919
951
|
end
|
|
920
952
|
end
|
|
921
953
|
end
|
|
922
954
|
|
|
923
|
-
context
|
|
924
|
-
|
|
955
|
+
context 'when the child is persisted' do
|
|
925
956
|
let(:band) do
|
|
926
|
-
Band.create(name:
|
|
957
|
+
Band.create!(name: 'Moderat')
|
|
927
958
|
end
|
|
928
959
|
|
|
929
960
|
let!(:record) do
|
|
930
|
-
band.records.create(name:
|
|
961
|
+
band.records.create!(name: 'Moderat')
|
|
931
962
|
end
|
|
932
963
|
|
|
933
964
|
before do
|
|
934
965
|
record.before_create_called = false
|
|
935
|
-
band.save
|
|
966
|
+
band.save!
|
|
936
967
|
end
|
|
937
968
|
|
|
938
|
-
it
|
|
969
|
+
it 'does not execute the callback' do
|
|
939
970
|
expect(record.before_create_called).to be false
|
|
940
971
|
end
|
|
941
972
|
end
|
|
942
973
|
end
|
|
943
974
|
|
|
944
|
-
describe
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
context "when the parent is new" do
|
|
949
|
-
|
|
975
|
+
describe '#before_save' do
|
|
976
|
+
context 'when the child is new' do
|
|
977
|
+
context 'when the parent is new' do
|
|
950
978
|
let(:band) do
|
|
951
|
-
Band.new(name:
|
|
979
|
+
Band.new(name: 'Moderat')
|
|
952
980
|
end
|
|
953
981
|
|
|
954
982
|
let!(:record) do
|
|
955
|
-
band.records.build(name:
|
|
983
|
+
band.records.build(name: 'Moderat')
|
|
956
984
|
end
|
|
957
985
|
|
|
958
986
|
before do
|
|
959
|
-
band.save
|
|
987
|
+
band.save!
|
|
960
988
|
end
|
|
961
989
|
|
|
962
|
-
it
|
|
990
|
+
it 'executes the callback' do
|
|
963
991
|
expect(record.before_save_called).to be true
|
|
964
992
|
end
|
|
965
993
|
|
|
966
|
-
it
|
|
994
|
+
it 'persists the change' do
|
|
967
995
|
expect(band.reload.records.first.before_save_called).to be true
|
|
968
996
|
end
|
|
969
997
|
end
|
|
970
998
|
|
|
971
|
-
context
|
|
972
|
-
|
|
999
|
+
context 'when the parent is persisted' do
|
|
973
1000
|
let(:band) do
|
|
974
|
-
Band.create(name:
|
|
1001
|
+
Band.create!(name: 'Moderat')
|
|
975
1002
|
end
|
|
976
1003
|
|
|
977
1004
|
let!(:record) do
|
|
978
|
-
band.records.build(name:
|
|
1005
|
+
band.records.build(name: 'Moderat')
|
|
979
1006
|
end
|
|
980
1007
|
|
|
981
1008
|
before do
|
|
982
|
-
band.save
|
|
1009
|
+
band.save!
|
|
983
1010
|
end
|
|
984
1011
|
|
|
985
|
-
it
|
|
1012
|
+
it 'executes the callback' do
|
|
986
1013
|
expect(record.before_save_called).to be true
|
|
987
1014
|
end
|
|
988
1015
|
|
|
989
|
-
it
|
|
1016
|
+
it 'persists the change' do
|
|
990
1017
|
expect(band.reload.records.first.before_save_called).to be true
|
|
991
1018
|
end
|
|
992
1019
|
end
|
|
993
1020
|
end
|
|
994
1021
|
|
|
995
|
-
context
|
|
996
|
-
|
|
1022
|
+
context 'when the child is persisted' do
|
|
997
1023
|
let(:band) do
|
|
998
|
-
Band.create(name:
|
|
1024
|
+
Band.create!(name: 'Moderat')
|
|
999
1025
|
end
|
|
1000
1026
|
|
|
1001
1027
|
let!(:record) do
|
|
1002
|
-
band.records.create(name:
|
|
1028
|
+
band.records.create!(name: 'Moderat')
|
|
1003
1029
|
end
|
|
1004
1030
|
|
|
1005
1031
|
before do
|
|
1006
|
-
band.save
|
|
1032
|
+
band.save!
|
|
1007
1033
|
end
|
|
1008
1034
|
|
|
1009
|
-
it
|
|
1035
|
+
it 'executes the callback' do
|
|
1010
1036
|
expect(record.before_save_called).to be true
|
|
1011
1037
|
end
|
|
1012
1038
|
|
|
1013
|
-
it
|
|
1039
|
+
it 'persists the change' do
|
|
1014
1040
|
expect(band.reload.records.first.before_save_called).to be true
|
|
1015
1041
|
end
|
|
1016
1042
|
end
|
|
1017
1043
|
|
|
1018
|
-
context
|
|
1019
|
-
|
|
1044
|
+
context 'when the child is created' do
|
|
1020
1045
|
let!(:band) do
|
|
1021
|
-
Band.create
|
|
1046
|
+
Band.create!
|
|
1022
1047
|
end
|
|
1023
1048
|
|
|
1024
1049
|
let!(:label) do
|
|
1025
1050
|
band.create_label(name: 'Label')
|
|
1026
1051
|
end
|
|
1027
1052
|
|
|
1028
|
-
it
|
|
1053
|
+
it 'only executes callback once' do
|
|
1029
1054
|
expect(label.before_save_count).to be 1
|
|
1030
1055
|
end
|
|
1031
1056
|
end
|
|
1032
1057
|
end
|
|
1033
1058
|
|
|
1034
|
-
describe
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
context "when the parent is new" do
|
|
1039
|
-
|
|
1059
|
+
describe '#before_update' do
|
|
1060
|
+
context 'when the child is new' do
|
|
1061
|
+
context 'when the parent is new' do
|
|
1040
1062
|
let(:band) do
|
|
1041
|
-
Band.new(name:
|
|
1063
|
+
Band.new(name: 'Moderat')
|
|
1042
1064
|
end
|
|
1043
1065
|
|
|
1044
1066
|
let!(:record) do
|
|
1045
|
-
band.records.build(name:
|
|
1067
|
+
band.records.build(name: 'Moderat')
|
|
1046
1068
|
end
|
|
1047
1069
|
|
|
1048
1070
|
before do
|
|
1049
|
-
band.save
|
|
1071
|
+
band.save!
|
|
1050
1072
|
end
|
|
1051
1073
|
|
|
1052
|
-
it
|
|
1074
|
+
it 'does not execute the callback' do
|
|
1053
1075
|
expect(record.before_update_called).to be false
|
|
1054
1076
|
end
|
|
1055
1077
|
end
|
|
1056
1078
|
|
|
1057
|
-
context
|
|
1058
|
-
|
|
1079
|
+
context 'when the parent is persisted' do
|
|
1059
1080
|
let(:band) do
|
|
1060
|
-
Band.create(name:
|
|
1081
|
+
Band.create!(name: 'Moderat')
|
|
1061
1082
|
end
|
|
1062
1083
|
|
|
1063
1084
|
let!(:record) do
|
|
1064
|
-
band.records.build(name:
|
|
1085
|
+
band.records.build(name: 'Moderat')
|
|
1065
1086
|
end
|
|
1066
1087
|
|
|
1067
1088
|
before do
|
|
1068
|
-
band.save
|
|
1089
|
+
band.save!
|
|
1069
1090
|
end
|
|
1070
1091
|
|
|
1071
|
-
it
|
|
1092
|
+
it 'does not execute the callback' do
|
|
1072
1093
|
expect(record.before_update_called).to be false
|
|
1073
1094
|
end
|
|
1074
1095
|
end
|
|
1075
1096
|
end
|
|
1076
1097
|
|
|
1077
|
-
context
|
|
1078
|
-
|
|
1098
|
+
context 'when the child is persisted' do
|
|
1079
1099
|
let(:band) do
|
|
1080
|
-
Band.create(name:
|
|
1100
|
+
Band.create!(name: 'Moderat')
|
|
1081
1101
|
end
|
|
1082
1102
|
|
|
1083
1103
|
let!(:record) do
|
|
1084
|
-
band.records.create(name:
|
|
1104
|
+
band.records.create!(name: 'Moderat')
|
|
1085
1105
|
end
|
|
1086
1106
|
|
|
1087
|
-
context
|
|
1088
|
-
|
|
1107
|
+
context 'when the child is dirty' do
|
|
1089
1108
|
before do
|
|
1090
|
-
record.name =
|
|
1091
|
-
band.save
|
|
1109
|
+
record.name = 'Nothing'
|
|
1110
|
+
band.save!
|
|
1092
1111
|
end
|
|
1093
1112
|
|
|
1094
|
-
it
|
|
1113
|
+
it 'executes the callback' do
|
|
1095
1114
|
expect(record.before_update_called).to be true
|
|
1096
1115
|
end
|
|
1097
1116
|
|
|
1098
|
-
it
|
|
1117
|
+
it 'persists the change' do
|
|
1099
1118
|
expect(band.reload.records.first.before_update_called).to be true
|
|
1100
1119
|
end
|
|
1101
1120
|
end
|
|
1102
1121
|
|
|
1103
|
-
context
|
|
1104
|
-
|
|
1122
|
+
context 'when the child is not dirty' do
|
|
1105
1123
|
before do
|
|
1106
|
-
band.save
|
|
1124
|
+
band.save!
|
|
1107
1125
|
end
|
|
1108
1126
|
|
|
1109
|
-
it
|
|
1127
|
+
it 'does not execute the callback' do
|
|
1110
1128
|
expect(record.before_update_called).to be false
|
|
1111
1129
|
end
|
|
1112
1130
|
end
|
|
1113
1131
|
end
|
|
1114
1132
|
end
|
|
1115
1133
|
|
|
1116
|
-
describe
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
context "when the parent is new" do
|
|
1121
|
-
|
|
1134
|
+
describe '#before_validation' do
|
|
1135
|
+
context 'when the child is new' do
|
|
1136
|
+
context 'when the parent is new' do
|
|
1122
1137
|
let(:band) do
|
|
1123
|
-
Band.new(name:
|
|
1138
|
+
Band.new(name: 'Moderat')
|
|
1124
1139
|
end
|
|
1125
1140
|
|
|
1126
1141
|
let!(:record) do
|
|
1127
|
-
band.records.build(name:
|
|
1142
|
+
band.records.build(name: 'Moderat')
|
|
1128
1143
|
end
|
|
1129
1144
|
|
|
1130
1145
|
before do
|
|
1131
|
-
band.save
|
|
1146
|
+
band.save!
|
|
1132
1147
|
end
|
|
1133
1148
|
|
|
1134
|
-
it
|
|
1149
|
+
it 'executes the callback' do
|
|
1135
1150
|
expect(record.before_validation_called).to be true
|
|
1136
1151
|
end
|
|
1137
1152
|
|
|
1138
|
-
it
|
|
1153
|
+
it 'persists the change' do
|
|
1139
1154
|
expect(band.reload.records.first.before_validation_called).to be true
|
|
1140
1155
|
end
|
|
1141
1156
|
end
|
|
1142
1157
|
|
|
1143
|
-
context
|
|
1144
|
-
|
|
1158
|
+
context 'when the parent is persisted' do
|
|
1145
1159
|
let(:band) do
|
|
1146
|
-
Band.create(name:
|
|
1160
|
+
Band.create!(name: 'Moderat')
|
|
1147
1161
|
end
|
|
1148
1162
|
|
|
1149
1163
|
let!(:record) do
|
|
1150
|
-
band.records.build(name:
|
|
1164
|
+
band.records.build(name: 'Moderat')
|
|
1151
1165
|
end
|
|
1152
1166
|
|
|
1153
1167
|
before do
|
|
1154
|
-
band.save
|
|
1168
|
+
band.save!
|
|
1155
1169
|
end
|
|
1156
1170
|
|
|
1157
|
-
it
|
|
1171
|
+
it 'executes the callback' do
|
|
1158
1172
|
expect(record.before_validation_called).to be true
|
|
1159
1173
|
end
|
|
1160
1174
|
|
|
1161
|
-
it
|
|
1175
|
+
it 'persists the change' do
|
|
1162
1176
|
expect(band.reload.records.first.before_validation_called).to be true
|
|
1163
1177
|
end
|
|
1164
1178
|
end
|
|
1165
1179
|
|
|
1166
1180
|
context 'when the parent is updated' do
|
|
1167
|
-
|
|
1168
1181
|
let(:band) do
|
|
1169
|
-
Band.create(name:
|
|
1182
|
+
Band.create!(name: 'Moderat')
|
|
1170
1183
|
end
|
|
1171
1184
|
|
|
1172
1185
|
before do
|
|
1173
|
-
band.update(records: [ { name: 'Black on Both Sides' }])
|
|
1186
|
+
band.update(records: [ { name: 'Black on Both Sides' } ])
|
|
1174
1187
|
end
|
|
1175
1188
|
|
|
1176
1189
|
it 'executes the callback' do
|
|
@@ -1184,13 +1197,12 @@ describe Mongoid::Interceptable do
|
|
|
1184
1197
|
end
|
|
1185
1198
|
|
|
1186
1199
|
context 'when the parent is updated' do
|
|
1187
|
-
|
|
1188
1200
|
let(:band) do
|
|
1189
|
-
Band.create(name:
|
|
1201
|
+
Band.create!(name: 'Moderat')
|
|
1190
1202
|
end
|
|
1191
1203
|
|
|
1192
1204
|
before do
|
|
1193
|
-
band.update(records: [ { name: 'Black on Both Sides' }])
|
|
1205
|
+
band.update(records: [ { name: 'Black on Both Sides' } ])
|
|
1194
1206
|
end
|
|
1195
1207
|
|
|
1196
1208
|
it 'executes the callback' do
|
|
@@ -1202,300 +1214,278 @@ describe Mongoid::Interceptable do
|
|
|
1202
1214
|
end
|
|
1203
1215
|
end
|
|
1204
1216
|
|
|
1205
|
-
context
|
|
1206
|
-
|
|
1217
|
+
context 'when the child is persisted' do
|
|
1207
1218
|
let(:band) do
|
|
1208
|
-
Band.create(name:
|
|
1219
|
+
Band.create!(name: 'Moderat')
|
|
1209
1220
|
end
|
|
1210
1221
|
|
|
1211
1222
|
let!(:record) do
|
|
1212
|
-
band.records.create(name:
|
|
1223
|
+
band.records.create!(name: 'Moderat')
|
|
1213
1224
|
end
|
|
1214
1225
|
|
|
1215
1226
|
before do
|
|
1216
|
-
band.save
|
|
1227
|
+
band.save!
|
|
1217
1228
|
end
|
|
1218
1229
|
|
|
1219
|
-
it
|
|
1230
|
+
it 'executes the callback' do
|
|
1220
1231
|
expect(record.before_validation_called).to be true
|
|
1221
1232
|
end
|
|
1222
1233
|
|
|
1223
|
-
it
|
|
1234
|
+
it 'persists the change' do
|
|
1224
1235
|
expect(band.reload.records.first.before_validation_called).to be true
|
|
1225
1236
|
end
|
|
1226
1237
|
end
|
|
1227
1238
|
end
|
|
1228
1239
|
end
|
|
1229
1240
|
|
|
1230
|
-
context
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
context "when the child is new" do
|
|
1235
|
-
|
|
1236
|
-
context "when the root is new" do
|
|
1237
|
-
|
|
1241
|
+
context 'when the document is embedded multiple levels' do
|
|
1242
|
+
describe '#before_create' do
|
|
1243
|
+
context 'when the child is new' do
|
|
1244
|
+
context 'when the root is new' do
|
|
1238
1245
|
let(:band) do
|
|
1239
|
-
Band.new(name:
|
|
1246
|
+
Band.new(name: 'Moderat')
|
|
1240
1247
|
end
|
|
1241
1248
|
|
|
1242
1249
|
let!(:record) do
|
|
1243
|
-
band.records.build(name:
|
|
1250
|
+
band.records.build(name: 'Moderat')
|
|
1244
1251
|
end
|
|
1245
1252
|
|
|
1246
1253
|
let!(:track) do
|
|
1247
|
-
record.tracks.build(name:
|
|
1254
|
+
record.tracks.build(name: 'Berlin')
|
|
1248
1255
|
end
|
|
1249
1256
|
|
|
1250
1257
|
before do
|
|
1251
|
-
band.save
|
|
1258
|
+
band.save!
|
|
1252
1259
|
end
|
|
1253
1260
|
|
|
1254
|
-
it
|
|
1261
|
+
it 'executes the callback' do
|
|
1255
1262
|
expect(track.before_create_called).to be true
|
|
1256
1263
|
end
|
|
1257
1264
|
end
|
|
1258
1265
|
|
|
1259
|
-
context
|
|
1260
|
-
|
|
1266
|
+
context 'when the root is persisted' do
|
|
1261
1267
|
let(:band) do
|
|
1262
|
-
Band.create(name:
|
|
1268
|
+
Band.create!(name: 'Moderat')
|
|
1263
1269
|
end
|
|
1264
1270
|
|
|
1265
1271
|
let!(:record) do
|
|
1266
|
-
band.records.build(name:
|
|
1272
|
+
band.records.build(name: 'Moderat')
|
|
1267
1273
|
end
|
|
1268
1274
|
|
|
1269
1275
|
let!(:track) do
|
|
1270
|
-
record.tracks.build(name:
|
|
1276
|
+
record.tracks.build(name: 'Berlin')
|
|
1271
1277
|
end
|
|
1272
1278
|
|
|
1273
1279
|
before do
|
|
1274
|
-
band.save
|
|
1280
|
+
band.save!
|
|
1275
1281
|
end
|
|
1276
1282
|
|
|
1277
|
-
it
|
|
1283
|
+
it 'executes the callback' do
|
|
1278
1284
|
expect(track.before_create_called).to be true
|
|
1279
1285
|
end
|
|
1280
1286
|
end
|
|
1281
1287
|
end
|
|
1282
1288
|
|
|
1283
|
-
context
|
|
1284
|
-
|
|
1289
|
+
context 'when the child is persisted' do
|
|
1285
1290
|
let(:band) do
|
|
1286
|
-
Band.create(name:
|
|
1291
|
+
Band.create!(name: 'Moderat')
|
|
1287
1292
|
end
|
|
1288
1293
|
|
|
1289
1294
|
let!(:record) do
|
|
1290
|
-
band.records.create(name:
|
|
1295
|
+
band.records.create!(name: 'Moderat')
|
|
1291
1296
|
end
|
|
1292
1297
|
|
|
1293
1298
|
let!(:track) do
|
|
1294
|
-
record.tracks.create(name:
|
|
1299
|
+
record.tracks.create!(name: 'Berlin')
|
|
1295
1300
|
end
|
|
1296
1301
|
|
|
1297
1302
|
before do
|
|
1298
1303
|
track.before_create_called = false
|
|
1299
|
-
band.save
|
|
1304
|
+
band.save!
|
|
1300
1305
|
end
|
|
1301
1306
|
|
|
1302
|
-
it
|
|
1307
|
+
it 'does not execute the callback' do
|
|
1303
1308
|
expect(track.before_create_called).to be false
|
|
1304
1309
|
end
|
|
1305
1310
|
end
|
|
1306
1311
|
end
|
|
1307
1312
|
|
|
1308
|
-
describe
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
context "when the root is new" do
|
|
1313
|
-
|
|
1313
|
+
describe '#before_save' do
|
|
1314
|
+
context 'when the child is new' do
|
|
1315
|
+
context 'when the root is new' do
|
|
1314
1316
|
let(:band) do
|
|
1315
|
-
Band.new(name:
|
|
1317
|
+
Band.new(name: 'Moderat')
|
|
1318
|
+
end
|
|
1319
|
+
let(:reloaded) do
|
|
1320
|
+
band.reload.records.first
|
|
1316
1321
|
end
|
|
1317
1322
|
|
|
1318
1323
|
let!(:record) do
|
|
1319
|
-
band.records.build(name:
|
|
1324
|
+
band.records.build(name: 'Moderat')
|
|
1320
1325
|
end
|
|
1321
1326
|
|
|
1322
1327
|
let!(:track) do
|
|
1323
|
-
record.tracks.build(name:
|
|
1328
|
+
record.tracks.build(name: 'Berlin')
|
|
1324
1329
|
end
|
|
1325
1330
|
|
|
1326
1331
|
before do
|
|
1327
|
-
band.save
|
|
1328
|
-
end
|
|
1329
|
-
|
|
1330
|
-
let(:reloaded) do
|
|
1331
|
-
band.reload.records.first
|
|
1332
|
+
band.save!
|
|
1332
1333
|
end
|
|
1333
1334
|
|
|
1334
|
-
it
|
|
1335
|
+
it 'executes the callback' do
|
|
1335
1336
|
expect(track.before_save_called).to be true
|
|
1336
1337
|
end
|
|
1337
1338
|
|
|
1338
|
-
it
|
|
1339
|
+
it 'persists the change' do
|
|
1339
1340
|
expect(reloaded.tracks.first.before_save_called).to be true
|
|
1340
1341
|
end
|
|
1341
1342
|
end
|
|
1342
1343
|
|
|
1343
|
-
context
|
|
1344
|
-
|
|
1344
|
+
context 'when the parent is persisted' do
|
|
1345
1345
|
let(:band) do
|
|
1346
|
-
Band.create(name:
|
|
1346
|
+
Band.create!(name: 'Moderat')
|
|
1347
|
+
end
|
|
1348
|
+
let(:reloaded) do
|
|
1349
|
+
band.reload.records.first
|
|
1347
1350
|
end
|
|
1348
1351
|
|
|
1349
1352
|
let!(:record) do
|
|
1350
|
-
band.records.build(name:
|
|
1353
|
+
band.records.build(name: 'Moderat')
|
|
1351
1354
|
end
|
|
1352
1355
|
|
|
1353
1356
|
let!(:track) do
|
|
1354
|
-
record.tracks.build(name:
|
|
1357
|
+
record.tracks.build(name: 'Berlin')
|
|
1355
1358
|
end
|
|
1356
1359
|
|
|
1357
1360
|
before do
|
|
1358
|
-
band.save
|
|
1359
|
-
end
|
|
1360
|
-
|
|
1361
|
-
let(:reloaded) do
|
|
1362
|
-
band.reload.records.first
|
|
1361
|
+
band.save!
|
|
1363
1362
|
end
|
|
1364
1363
|
|
|
1365
|
-
it
|
|
1364
|
+
it 'executes the callback' do
|
|
1366
1365
|
expect(track.before_save_called).to be true
|
|
1367
1366
|
end
|
|
1368
1367
|
|
|
1369
|
-
it
|
|
1368
|
+
it 'persists the change' do
|
|
1370
1369
|
expect(reloaded.tracks.first.before_save_called).to be true
|
|
1371
1370
|
end
|
|
1372
1371
|
end
|
|
1373
1372
|
end
|
|
1374
1373
|
|
|
1375
|
-
context
|
|
1376
|
-
|
|
1374
|
+
context 'when the child is persisted' do
|
|
1377
1375
|
let(:band) do
|
|
1378
|
-
Band.create(name:
|
|
1376
|
+
Band.create!(name: 'Moderat')
|
|
1377
|
+
end
|
|
1378
|
+
let(:reloaded) do
|
|
1379
|
+
band.reload.records.first
|
|
1379
1380
|
end
|
|
1380
1381
|
|
|
1381
1382
|
let!(:record) do
|
|
1382
|
-
band.records.create(name:
|
|
1383
|
+
band.records.create!(name: 'Moderat')
|
|
1383
1384
|
end
|
|
1384
1385
|
|
|
1385
1386
|
let!(:track) do
|
|
1386
|
-
record.tracks.create(name:
|
|
1387
|
+
record.tracks.create!(name: 'Berlin')
|
|
1387
1388
|
end
|
|
1388
1389
|
|
|
1389
1390
|
before do
|
|
1390
|
-
band.save
|
|
1391
|
-
end
|
|
1392
|
-
|
|
1393
|
-
let(:reloaded) do
|
|
1394
|
-
band.reload.records.first
|
|
1391
|
+
band.save!
|
|
1395
1392
|
end
|
|
1396
1393
|
|
|
1397
|
-
it
|
|
1394
|
+
it 'executes the callback' do
|
|
1398
1395
|
expect(track.before_save_called).to be true
|
|
1399
1396
|
end
|
|
1400
1397
|
|
|
1401
|
-
it
|
|
1398
|
+
it 'persists the change' do
|
|
1402
1399
|
expect(reloaded.tracks.first.before_save_called).to be true
|
|
1403
1400
|
end
|
|
1404
1401
|
end
|
|
1405
1402
|
end
|
|
1406
1403
|
|
|
1407
|
-
describe
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
context "when the parent is new" do
|
|
1412
|
-
|
|
1404
|
+
describe '#before_update' do
|
|
1405
|
+
context 'when the child is new' do
|
|
1406
|
+
context 'when the parent is new' do
|
|
1413
1407
|
let(:band) do
|
|
1414
|
-
Band.new(name:
|
|
1408
|
+
Band.new(name: 'Moderat')
|
|
1415
1409
|
end
|
|
1416
1410
|
|
|
1417
1411
|
let!(:record) do
|
|
1418
|
-
band.records.build(name:
|
|
1412
|
+
band.records.build(name: 'Moderat')
|
|
1419
1413
|
end
|
|
1420
1414
|
|
|
1421
1415
|
let!(:track) do
|
|
1422
|
-
record.tracks.build(name:
|
|
1416
|
+
record.tracks.build(name: 'Berlin')
|
|
1423
1417
|
end
|
|
1424
1418
|
|
|
1425
1419
|
before do
|
|
1426
|
-
band.save
|
|
1420
|
+
band.save!
|
|
1427
1421
|
end
|
|
1428
1422
|
|
|
1429
|
-
it
|
|
1423
|
+
it 'does not execute the callback' do
|
|
1430
1424
|
expect(track.before_update_called).to be false
|
|
1431
1425
|
end
|
|
1432
1426
|
end
|
|
1433
1427
|
|
|
1434
|
-
context
|
|
1435
|
-
|
|
1428
|
+
context 'when the parent is persisted' do
|
|
1436
1429
|
let(:band) do
|
|
1437
|
-
Band.create(name:
|
|
1430
|
+
Band.create!(name: 'Moderat')
|
|
1438
1431
|
end
|
|
1439
1432
|
|
|
1440
1433
|
let!(:record) do
|
|
1441
|
-
band.records.build(name:
|
|
1434
|
+
band.records.build(name: 'Moderat')
|
|
1442
1435
|
end
|
|
1443
1436
|
|
|
1444
1437
|
let!(:track) do
|
|
1445
|
-
record.tracks.build(name:
|
|
1438
|
+
record.tracks.build(name: 'Berlin')
|
|
1446
1439
|
end
|
|
1447
1440
|
|
|
1448
1441
|
before do
|
|
1449
|
-
band.save
|
|
1442
|
+
band.save!
|
|
1450
1443
|
end
|
|
1451
1444
|
|
|
1452
|
-
it
|
|
1445
|
+
it 'does not execute the callback' do
|
|
1453
1446
|
expect(track.before_update_called).to be false
|
|
1454
1447
|
end
|
|
1455
1448
|
end
|
|
1456
1449
|
end
|
|
1457
1450
|
|
|
1458
|
-
context
|
|
1459
|
-
|
|
1451
|
+
context 'when the child is persisted' do
|
|
1460
1452
|
let(:band) do
|
|
1461
|
-
Band.create(name:
|
|
1453
|
+
Band.create!(name: 'Moderat')
|
|
1462
1454
|
end
|
|
1463
1455
|
|
|
1464
1456
|
let!(:record) do
|
|
1465
|
-
band.records.create(name:
|
|
1457
|
+
band.records.create!(name: 'Moderat')
|
|
1466
1458
|
end
|
|
1467
1459
|
|
|
1468
1460
|
let!(:track) do
|
|
1469
|
-
record.tracks.create(name:
|
|
1461
|
+
record.tracks.create!(name: 'Berlin')
|
|
1470
1462
|
end
|
|
1471
1463
|
|
|
1472
|
-
context
|
|
1473
|
-
|
|
1464
|
+
context 'when the child is dirty' do
|
|
1474
1465
|
before do
|
|
1475
|
-
track.name =
|
|
1476
|
-
band.save
|
|
1466
|
+
track.name = 'Rusty Nails'
|
|
1467
|
+
band.save!
|
|
1477
1468
|
end
|
|
1478
1469
|
|
|
1479
1470
|
let(:reloaded) do
|
|
1480
1471
|
band.reload.records.first
|
|
1481
1472
|
end
|
|
1482
1473
|
|
|
1483
|
-
it
|
|
1474
|
+
it 'executes the callback' do
|
|
1484
1475
|
expect(track.before_update_called).to be true
|
|
1485
1476
|
end
|
|
1486
1477
|
|
|
1487
|
-
it
|
|
1478
|
+
it 'persists the change' do
|
|
1488
1479
|
expect(reloaded.tracks.first.before_update_called).to be true
|
|
1489
1480
|
end
|
|
1490
1481
|
end
|
|
1491
1482
|
|
|
1492
|
-
context
|
|
1493
|
-
|
|
1483
|
+
context 'when the child is not dirty' do
|
|
1494
1484
|
before do
|
|
1495
|
-
band.save
|
|
1485
|
+
band.save!
|
|
1496
1486
|
end
|
|
1497
1487
|
|
|
1498
|
-
it
|
|
1488
|
+
it 'does not execute the callback' do
|
|
1499
1489
|
expect(track.before_update_called).to be false
|
|
1500
1490
|
end
|
|
1501
1491
|
end
|
|
@@ -1503,11 +1493,9 @@ describe Mongoid::Interceptable do
|
|
|
1503
1493
|
end
|
|
1504
1494
|
|
|
1505
1495
|
describe '#after_destroy' do
|
|
1506
|
-
|
|
1507
1496
|
context 'when the parent is updated in a child after_destroy callback' do
|
|
1508
|
-
|
|
1509
1497
|
let!(:person) do
|
|
1510
|
-
Person.create!(ordered_posts: [OrderedPost.new])
|
|
1498
|
+
Person.create!(ordered_posts: [ OrderedPost.new ])
|
|
1511
1499
|
end
|
|
1512
1500
|
|
|
1513
1501
|
before do
|
|
@@ -1521,76 +1509,71 @@ describe Mongoid::Interceptable do
|
|
|
1521
1509
|
end
|
|
1522
1510
|
end
|
|
1523
1511
|
|
|
1524
|
-
describe
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
context "when the parent is new" do
|
|
1529
|
-
|
|
1512
|
+
describe '#before_validation' do
|
|
1513
|
+
context 'when the child is new' do
|
|
1514
|
+
context 'when the parent is new' do
|
|
1530
1515
|
let(:band) do
|
|
1531
|
-
Band.new(name:
|
|
1516
|
+
Band.new(name: 'Moderat')
|
|
1532
1517
|
end
|
|
1533
1518
|
|
|
1534
1519
|
let!(:record) do
|
|
1535
|
-
band.records.build(name:
|
|
1520
|
+
band.records.build(name: 'Moderat')
|
|
1536
1521
|
end
|
|
1537
1522
|
|
|
1538
1523
|
let!(:track) do
|
|
1539
|
-
record.tracks.build(name:
|
|
1524
|
+
record.tracks.build(name: 'Berlin')
|
|
1540
1525
|
end
|
|
1541
1526
|
|
|
1542
1527
|
before do
|
|
1543
|
-
band.save
|
|
1528
|
+
band.save!
|
|
1544
1529
|
end
|
|
1545
1530
|
|
|
1546
|
-
it
|
|
1531
|
+
it 'executes the callback' do
|
|
1547
1532
|
expect(track.before_validation_called).to be true
|
|
1548
1533
|
end
|
|
1549
1534
|
end
|
|
1550
1535
|
|
|
1551
|
-
context
|
|
1552
|
-
|
|
1536
|
+
context 'when the parent is persisted' do
|
|
1553
1537
|
let(:band) do
|
|
1554
|
-
Band.create(name:
|
|
1538
|
+
Band.create!(name: 'Moderat')
|
|
1555
1539
|
end
|
|
1556
1540
|
|
|
1557
1541
|
let!(:record) do
|
|
1558
|
-
band.records.build(name:
|
|
1542
|
+
band.records.build(name: 'Moderat')
|
|
1559
1543
|
end
|
|
1560
1544
|
|
|
1561
1545
|
let!(:track) do
|
|
1562
|
-
record.tracks.build(name:
|
|
1546
|
+
record.tracks.build(name: 'Berlin')
|
|
1563
1547
|
end
|
|
1564
1548
|
|
|
1565
1549
|
before do
|
|
1566
|
-
band.save
|
|
1550
|
+
band.save!
|
|
1567
1551
|
end
|
|
1568
1552
|
|
|
1569
|
-
it
|
|
1553
|
+
it 'executes the callback' do
|
|
1570
1554
|
expect(track.before_validation_called).to be true
|
|
1571
1555
|
end
|
|
1572
1556
|
end
|
|
1573
1557
|
end
|
|
1574
1558
|
|
|
1575
|
-
context
|
|
1576
|
-
|
|
1559
|
+
context 'when the child is persisted' do
|
|
1577
1560
|
let(:band) do
|
|
1578
|
-
Band.create(name:
|
|
1561
|
+
Band.create!(name: 'Moderat')
|
|
1579
1562
|
end
|
|
1580
1563
|
|
|
1581
1564
|
let!(:record) do
|
|
1582
|
-
band.records.create(name:
|
|
1565
|
+
band.records.create!(name: 'Moderat')
|
|
1583
1566
|
end
|
|
1584
1567
|
|
|
1585
1568
|
let!(:track) do
|
|
1586
|
-
record.tracks.create(name:
|
|
1569
|
+
record.tracks.create!(name: 'Berlin')
|
|
1587
1570
|
end
|
|
1588
1571
|
|
|
1589
1572
|
before do
|
|
1590
|
-
band.save
|
|
1573
|
+
band.save!
|
|
1591
1574
|
end
|
|
1592
1575
|
|
|
1593
|
-
it
|
|
1576
|
+
it 'executes the callback' do
|
|
1594
1577
|
expect(track.before_validation_called).to be true
|
|
1595
1578
|
end
|
|
1596
1579
|
end
|
|
@@ -1598,35 +1581,32 @@ describe Mongoid::Interceptable do
|
|
|
1598
1581
|
end
|
|
1599
1582
|
end
|
|
1600
1583
|
|
|
1601
|
-
context
|
|
1602
|
-
|
|
1603
|
-
it "goes in all validation callback in good order" do
|
|
1584
|
+
context 'callback on valid?' do
|
|
1585
|
+
it 'goes in all validation callback in good order' do
|
|
1604
1586
|
shin = ValidationCallback.new
|
|
1605
1587
|
shin.valid?
|
|
1606
|
-
expect(shin.history).to eq([
|
|
1588
|
+
expect(shin.history).to eq(%i[before_validation validate after_validation])
|
|
1607
1589
|
end
|
|
1608
1590
|
end
|
|
1609
1591
|
|
|
1610
|
-
context
|
|
1611
|
-
|
|
1592
|
+
context 'when creating child documents in callbacks' do
|
|
1612
1593
|
let(:parent) do
|
|
1613
1594
|
ParentDoc.new
|
|
1614
1595
|
end
|
|
1615
1596
|
|
|
1616
1597
|
before do
|
|
1617
|
-
parent.save
|
|
1598
|
+
parent.save!
|
|
1618
1599
|
end
|
|
1619
1600
|
|
|
1620
|
-
it
|
|
1621
|
-
parent.children.create(position: 1)
|
|
1601
|
+
it 'does not duplicate the child documents' do
|
|
1602
|
+
parent.children.create!(position: 1)
|
|
1622
1603
|
expect(ParentDoc.find(parent.id).children.size).to eq(1)
|
|
1623
1604
|
end
|
|
1624
1605
|
end
|
|
1625
1606
|
|
|
1626
|
-
context
|
|
1627
|
-
|
|
1607
|
+
context 'when callbacks cancel persistence' do
|
|
1628
1608
|
let(:address) do
|
|
1629
|
-
Address.new(street:
|
|
1609
|
+
Address.new(street: '123 Sesame')
|
|
1630
1610
|
end
|
|
1631
1611
|
|
|
1632
1612
|
before(:all) do
|
|
@@ -1639,84 +1619,962 @@ describe Mongoid::Interceptable do
|
|
|
1639
1619
|
Person.reset_callbacks(:save)
|
|
1640
1620
|
end
|
|
1641
1621
|
|
|
1642
|
-
context
|
|
1643
|
-
|
|
1622
|
+
context 'when creating a document' do
|
|
1644
1623
|
let(:person) do
|
|
1645
|
-
Person.new(mode: :prevent_save, title:
|
|
1624
|
+
Person.new(mode: :prevent_save, title: 'Associate', addresses: [ address ])
|
|
1646
1625
|
end
|
|
1647
1626
|
|
|
1648
|
-
it
|
|
1627
|
+
it 'fails to save' do
|
|
1649
1628
|
expect(person).to be_valid
|
|
1650
1629
|
expect(person.save).to be false
|
|
1651
1630
|
end
|
|
1652
1631
|
|
|
1653
|
-
it
|
|
1632
|
+
it 'is a new record' do
|
|
1654
1633
|
expect(person).to be_a_new_record
|
|
1655
|
-
expect { person.save }.not_to
|
|
1634
|
+
expect { person.save }.not_to(change { person.new_record? })
|
|
1656
1635
|
end
|
|
1657
1636
|
|
|
1658
|
-
it
|
|
1637
|
+
it 'is left dirty' do
|
|
1659
1638
|
expect(person).to be_changed
|
|
1660
|
-
expect { person.save }.not_to
|
|
1639
|
+
expect { person.save }.not_to(change { person.changed? })
|
|
1661
1640
|
end
|
|
1662
1641
|
|
|
1663
|
-
it
|
|
1642
|
+
it 'child documents are left dirty' do
|
|
1664
1643
|
expect(address).to be_changed
|
|
1665
|
-
expect { person.save }.not_to
|
|
1644
|
+
expect { person.save }.not_to(change { address.changed? })
|
|
1666
1645
|
end
|
|
1667
1646
|
end
|
|
1668
1647
|
|
|
1669
|
-
context
|
|
1670
|
-
|
|
1648
|
+
context 'when updating a document' do
|
|
1671
1649
|
let(:person) do
|
|
1672
|
-
Person.create
|
|
1650
|
+
Person.create!.tap do |person|
|
|
1673
1651
|
person.attributes = {
|
|
1674
1652
|
mode: :prevent_save,
|
|
1675
|
-
title:
|
|
1653
|
+
title: 'Associate',
|
|
1676
1654
|
addresses: [ address ]
|
|
1677
1655
|
}
|
|
1678
1656
|
end
|
|
1679
1657
|
end
|
|
1680
1658
|
|
|
1681
|
-
it
|
|
1659
|
+
it '#save returns false' do
|
|
1682
1660
|
expect(person).to be_valid
|
|
1683
1661
|
expect(person.save).to be false
|
|
1684
1662
|
end
|
|
1685
1663
|
|
|
1686
|
-
it
|
|
1687
|
-
expect(person).
|
|
1688
|
-
expect { person.save }.not_to
|
|
1664
|
+
it 'is a not a new record' do
|
|
1665
|
+
expect(person).not_to be_a_new_record
|
|
1666
|
+
expect { person.save }.not_to(change { person.new_record? })
|
|
1689
1667
|
end
|
|
1690
1668
|
|
|
1691
|
-
it
|
|
1669
|
+
it 'is left dirty' do
|
|
1692
1670
|
expect(person).to be_changed
|
|
1693
|
-
expect { person.save }.not_to
|
|
1671
|
+
expect { person.save }.not_to(change { person.changed? })
|
|
1694
1672
|
end
|
|
1695
1673
|
|
|
1696
|
-
it
|
|
1674
|
+
it 'child documents are left dirty' do
|
|
1697
1675
|
expect(address).to be_changed
|
|
1698
|
-
expect { person.save }.not_to
|
|
1676
|
+
expect { person.save }.not_to(change { address.changed? })
|
|
1699
1677
|
end
|
|
1700
1678
|
end
|
|
1701
1679
|
end
|
|
1702
1680
|
|
|
1703
|
-
context
|
|
1704
|
-
|
|
1681
|
+
context 'when loading a model multiple times' do
|
|
1705
1682
|
before do
|
|
1706
|
-
load
|
|
1707
|
-
load
|
|
1683
|
+
load File.join(MODELS, 'callback_test.rb')
|
|
1684
|
+
load File.join(MODELS, 'callback_test.rb')
|
|
1708
1685
|
end
|
|
1709
1686
|
|
|
1710
1687
|
let(:callback) do
|
|
1711
1688
|
CallbackTest.new
|
|
1712
1689
|
end
|
|
1713
1690
|
|
|
1714
|
-
context
|
|
1715
|
-
|
|
1716
|
-
it "only executes the callbacks once" do
|
|
1691
|
+
context 'when saving the document' do
|
|
1692
|
+
it 'only executes the callbacks once' do
|
|
1717
1693
|
expect(callback).to receive(:execute).once
|
|
1718
1694
|
callback.save
|
|
1719
1695
|
end
|
|
1720
1696
|
end
|
|
1721
1697
|
end
|
|
1698
|
+
|
|
1699
|
+
context 'when creating a parent and embedded child' do
|
|
1700
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1701
|
+
let(:parent) do
|
|
1702
|
+
InterceptableSpec::CbParent.new(registry).tap do |parent|
|
|
1703
|
+
parent.cb_children << InterceptableSpec::CbChild.new(registry, cb_parent: parent)
|
|
1704
|
+
end
|
|
1705
|
+
end
|
|
1706
|
+
|
|
1707
|
+
let(:expected) do
|
|
1708
|
+
[
|
|
1709
|
+
[ InterceptableSpec::CbParent, :before_validation ],
|
|
1710
|
+
[ InterceptableSpec::CbChild, :before_validation ],
|
|
1711
|
+
[ InterceptableSpec::CbChild, :after_validation ],
|
|
1712
|
+
[ InterceptableSpec::CbParent, :after_validation ],
|
|
1713
|
+
[ InterceptableSpec::CbParent, :before_save ],
|
|
1714
|
+
[ InterceptableSpec::CbParent, :around_save_open ],
|
|
1715
|
+
[ InterceptableSpec::CbParent, :before_create ],
|
|
1716
|
+
[ InterceptableSpec::CbParent, :around_create_open ],
|
|
1717
|
+
[ InterceptableSpec::CbParent, :around_create_close ],
|
|
1718
|
+
[ InterceptableSpec::CbParent, :after_create ],
|
|
1719
|
+
[ InterceptableSpec::CbParent, :around_save_close ],
|
|
1720
|
+
[ InterceptableSpec::CbParent, :after_save ]
|
|
1721
|
+
]
|
|
1722
|
+
end
|
|
1723
|
+
|
|
1724
|
+
it 'calls callbacks in the right order' do
|
|
1725
|
+
parent.save!
|
|
1726
|
+
expect(registry.calls).to eq expected
|
|
1727
|
+
end
|
|
1728
|
+
end
|
|
1729
|
+
|
|
1730
|
+
context 'when creating a parent and embedded child with cascading callbacks' do
|
|
1731
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1732
|
+
let(:parent) do
|
|
1733
|
+
InterceptableSpec::CbParent.new(registry).tap do |parent|
|
|
1734
|
+
parent.cb_cascaded_children <<
|
|
1735
|
+
InterceptableSpec::CbCascadedChild.new(registry, cb_parent: parent)
|
|
1736
|
+
end
|
|
1737
|
+
end
|
|
1738
|
+
|
|
1739
|
+
context 'with around callbacks' do
|
|
1740
|
+
config_override :around_callbacks_for_embeds, true
|
|
1741
|
+
|
|
1742
|
+
after do
|
|
1743
|
+
Mongoid::Threaded.stack('interceptable').clear
|
|
1744
|
+
end
|
|
1745
|
+
|
|
1746
|
+
let(:stack) { Mongoid::Threaded.stack('interceptable') }
|
|
1747
|
+
|
|
1748
|
+
let(:expected) do
|
|
1749
|
+
[
|
|
1750
|
+
[ InterceptableSpec::CbCascadedChild, :before_validation ],
|
|
1751
|
+
[ InterceptableSpec::CbCascadedChild, :after_validation ],
|
|
1752
|
+
[ InterceptableSpec::CbParent, :before_validation ],
|
|
1753
|
+
[ InterceptableSpec::CbCascadedChild, :before_validation ],
|
|
1754
|
+
[ InterceptableSpec::CbCascadedChild, :after_validation ],
|
|
1755
|
+
|
|
1756
|
+
[ InterceptableSpec::CbParent, :after_validation ],
|
|
1757
|
+
[ InterceptableSpec::CbParent, :before_save ],
|
|
1758
|
+
[ InterceptableSpec::CbParent, :around_save_open ],
|
|
1759
|
+
[ InterceptableSpec::CbParent, :before_create ],
|
|
1760
|
+
[ InterceptableSpec::CbParent, :around_create_open ],
|
|
1761
|
+
|
|
1762
|
+
[ InterceptableSpec::CbCascadedChild, :before_save ],
|
|
1763
|
+
[ InterceptableSpec::CbCascadedChild, :around_save_open ],
|
|
1764
|
+
[ InterceptableSpec::CbCascadedChild, :before_create ],
|
|
1765
|
+
[ InterceptableSpec::CbCascadedChild, :around_create_open ],
|
|
1766
|
+
|
|
1767
|
+
[ InterceptableSpec::CbCascadedChild, :around_create_close ],
|
|
1768
|
+
[ InterceptableSpec::CbCascadedChild, :after_create ],
|
|
1769
|
+
[ InterceptableSpec::CbCascadedChild, :around_save_close ],
|
|
1770
|
+
[ InterceptableSpec::CbCascadedChild, :after_save ],
|
|
1771
|
+
|
|
1772
|
+
[ InterceptableSpec::CbParent, :around_create_close ],
|
|
1773
|
+
[ InterceptableSpec::CbParent, :after_create ],
|
|
1774
|
+
[ InterceptableSpec::CbParent, :around_save_close ],
|
|
1775
|
+
[ InterceptableSpec::CbParent, :after_save ]
|
|
1776
|
+
]
|
|
1777
|
+
end
|
|
1778
|
+
|
|
1779
|
+
it 'calls callbacks in the right order' do
|
|
1780
|
+
parent.save!
|
|
1781
|
+
expect(registry.calls).to eq expected
|
|
1782
|
+
end
|
|
1783
|
+
|
|
1784
|
+
it 'shows that cascaded callbacks can access Mongoid state' do
|
|
1785
|
+
expect(stack).to be_empty
|
|
1786
|
+
parent.save!
|
|
1787
|
+
expect(stack).not_to be_empty
|
|
1788
|
+
end
|
|
1789
|
+
end
|
|
1790
|
+
|
|
1791
|
+
context 'without around callbacks' do
|
|
1792
|
+
config_override :around_callbacks_for_embeds, false
|
|
1793
|
+
|
|
1794
|
+
let(:expected) do
|
|
1795
|
+
[
|
|
1796
|
+
[ InterceptableSpec::CbCascadedChild, :before_validation ],
|
|
1797
|
+
[ InterceptableSpec::CbCascadedChild, :after_validation ],
|
|
1798
|
+
[ InterceptableSpec::CbParent, :before_validation ],
|
|
1799
|
+
[ InterceptableSpec::CbCascadedChild, :before_validation ],
|
|
1800
|
+
[ InterceptableSpec::CbCascadedChild, :after_validation ],
|
|
1801
|
+
|
|
1802
|
+
[ InterceptableSpec::CbParent, :after_validation ],
|
|
1803
|
+
[ InterceptableSpec::CbParent, :before_save ],
|
|
1804
|
+
[ InterceptableSpec::CbParent, :around_save_open ],
|
|
1805
|
+
[ InterceptableSpec::CbParent, :before_create ],
|
|
1806
|
+
[ InterceptableSpec::CbParent, :around_create_open ],
|
|
1807
|
+
|
|
1808
|
+
[ InterceptableSpec::CbCascadedChild, :before_save ],
|
|
1809
|
+
[ InterceptableSpec::CbCascadedChild, :before_create ],
|
|
1810
|
+
|
|
1811
|
+
[ InterceptableSpec::CbCascadedChild, :after_create ],
|
|
1812
|
+
[ InterceptableSpec::CbCascadedChild, :after_save ],
|
|
1813
|
+
|
|
1814
|
+
[ InterceptableSpec::CbParent, :around_create_close ],
|
|
1815
|
+
[ InterceptableSpec::CbParent, :after_create ],
|
|
1816
|
+
[ InterceptableSpec::CbParent, :around_save_close ],
|
|
1817
|
+
[ InterceptableSpec::CbParent, :after_save ]
|
|
1818
|
+
]
|
|
1819
|
+
end
|
|
1820
|
+
|
|
1821
|
+
it 'calls callbacks in the right order' do
|
|
1822
|
+
parent.save!
|
|
1823
|
+
expect(registry.calls).to eq expected
|
|
1824
|
+
end
|
|
1825
|
+
end
|
|
1826
|
+
end
|
|
1827
|
+
|
|
1828
|
+
context 'with associations' do
|
|
1829
|
+
context 'has_one' do
|
|
1830
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1831
|
+
|
|
1832
|
+
let(:parent) do
|
|
1833
|
+
InterceptableSpec::CbHasOneParent.new(registry).tap do |parent|
|
|
1834
|
+
parent.child = InterceptableSpec::CbHasOneChild.new(registry)
|
|
1835
|
+
end
|
|
1836
|
+
end
|
|
1837
|
+
|
|
1838
|
+
let(:expected) do
|
|
1839
|
+
[
|
|
1840
|
+
[ InterceptableSpec::CbHasOneParent, :before_validation ],
|
|
1841
|
+
[ InterceptableSpec::CbHasOneChild, :before_validation ],
|
|
1842
|
+
[ InterceptableSpec::CbHasOneChild, :after_validation ],
|
|
1843
|
+
[ InterceptableSpec::CbHasOneParent, :after_validation ],
|
|
1844
|
+
[ InterceptableSpec::CbHasOneParent, :before_save ],
|
|
1845
|
+
|
|
1846
|
+
[ InterceptableSpec::CbHasOneParent, :around_save_open ],
|
|
1847
|
+
[ InterceptableSpec::CbHasOneParent, :before_create ],
|
|
1848
|
+
[ InterceptableSpec::CbHasOneParent, :around_create_open ],
|
|
1849
|
+
|
|
1850
|
+
[ InterceptableSpec::CbHasOneParent, :insert_into_database ],
|
|
1851
|
+
|
|
1852
|
+
[ InterceptableSpec::CbHasOneChild, :before_validation ],
|
|
1853
|
+
[ InterceptableSpec::CbHasOneChild, :after_validation ],
|
|
1854
|
+
[ InterceptableSpec::CbHasOneChild, :before_save ],
|
|
1855
|
+
[ InterceptableSpec::CbHasOneChild, :around_save_open ],
|
|
1856
|
+
[ InterceptableSpec::CbHasOneChild, :before_create ],
|
|
1857
|
+
[ InterceptableSpec::CbHasOneChild, :around_create_open ],
|
|
1858
|
+
|
|
1859
|
+
[ InterceptableSpec::CbHasOneChild, :around_create_close ],
|
|
1860
|
+
[ InterceptableSpec::CbHasOneChild, :after_create ],
|
|
1861
|
+
[ InterceptableSpec::CbHasOneChild, :around_save_close ],
|
|
1862
|
+
[ InterceptableSpec::CbHasOneChild, :after_save ],
|
|
1863
|
+
|
|
1864
|
+
[ InterceptableSpec::CbHasOneParent, :around_create_close ],
|
|
1865
|
+
[ InterceptableSpec::CbHasOneParent, :after_create ],
|
|
1866
|
+
[ InterceptableSpec::CbHasOneParent, :around_save_close ],
|
|
1867
|
+
[ InterceptableSpec::CbHasOneParent, :after_save ]
|
|
1868
|
+
]
|
|
1869
|
+
end
|
|
1870
|
+
|
|
1871
|
+
it 'calls callbacks in the right order' do
|
|
1872
|
+
parent.save!
|
|
1873
|
+
expect(registry.calls).to eq expected
|
|
1874
|
+
end
|
|
1875
|
+
end
|
|
1876
|
+
|
|
1877
|
+
context 'embeds_one' do
|
|
1878
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1879
|
+
|
|
1880
|
+
let(:parent) do
|
|
1881
|
+
InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
|
|
1882
|
+
parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
|
|
1883
|
+
end
|
|
1884
|
+
end
|
|
1885
|
+
|
|
1886
|
+
context 'create' do
|
|
1887
|
+
context 'with around callbacks' do
|
|
1888
|
+
config_override :around_callbacks_for_embeds, true
|
|
1889
|
+
|
|
1890
|
+
let(:expected) do
|
|
1891
|
+
[
|
|
1892
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1893
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1894
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
|
|
1895
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1896
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1897
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
|
|
1898
|
+
|
|
1899
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_save ],
|
|
1900
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
|
|
1901
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_create ],
|
|
1902
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_create_open ],
|
|
1903
|
+
|
|
1904
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_save ],
|
|
1905
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_save_open ],
|
|
1906
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_create ],
|
|
1907
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_create_open ],
|
|
1908
|
+
|
|
1909
|
+
[ InterceptableSpec::CbEmbedsOneParent, :insert_into_database ],
|
|
1910
|
+
|
|
1911
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_create_close ],
|
|
1912
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_create ],
|
|
1913
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_save_close ],
|
|
1914
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_save ],
|
|
1915
|
+
|
|
1916
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_create_close ],
|
|
1917
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_create ],
|
|
1918
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
|
|
1919
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_save ]
|
|
1920
|
+
]
|
|
1921
|
+
end
|
|
1922
|
+
|
|
1923
|
+
it 'calls callbacks in the right order' do
|
|
1924
|
+
parent.save!
|
|
1925
|
+
expect(registry.calls).to eq expected
|
|
1926
|
+
end
|
|
1927
|
+
end
|
|
1928
|
+
|
|
1929
|
+
context 'without around callbacks' do
|
|
1930
|
+
config_override :around_callbacks_for_embeds, false
|
|
1931
|
+
|
|
1932
|
+
let(:expected) do
|
|
1933
|
+
[
|
|
1934
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1935
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1936
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
|
|
1937
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1938
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1939
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
|
|
1940
|
+
|
|
1941
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_save ],
|
|
1942
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
|
|
1943
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_create ],
|
|
1944
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_create_open ],
|
|
1945
|
+
|
|
1946
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_save ],
|
|
1947
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_create ],
|
|
1948
|
+
|
|
1949
|
+
[ InterceptableSpec::CbEmbedsOneParent, :insert_into_database ],
|
|
1950
|
+
|
|
1951
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_create ],
|
|
1952
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_save ],
|
|
1953
|
+
|
|
1954
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_create_close ],
|
|
1955
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_create ],
|
|
1956
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
|
|
1957
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_save ]
|
|
1958
|
+
]
|
|
1959
|
+
end
|
|
1960
|
+
|
|
1961
|
+
it 'calls callbacks in the right order' do
|
|
1962
|
+
parent.save!
|
|
1963
|
+
expect(registry.calls).to eq expected
|
|
1964
|
+
end
|
|
1965
|
+
end
|
|
1966
|
+
end
|
|
1967
|
+
|
|
1968
|
+
context 'update' do
|
|
1969
|
+
context 'with around callbacks' do
|
|
1970
|
+
config_override :around_callbacks_for_embeds, true
|
|
1971
|
+
|
|
1972
|
+
let(:expected) do
|
|
1973
|
+
[
|
|
1974
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1975
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1976
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
|
|
1977
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
1978
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
1979
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
|
|
1980
|
+
|
|
1981
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_save ],
|
|
1982
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
|
|
1983
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_update ],
|
|
1984
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_update_open ],
|
|
1985
|
+
|
|
1986
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_save ],
|
|
1987
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_save_open ],
|
|
1988
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_update ],
|
|
1989
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_update_open ],
|
|
1990
|
+
|
|
1991
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_update_close ],
|
|
1992
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_update ],
|
|
1993
|
+
[ InterceptableSpec::CbEmbedsOneChild, :around_save_close ],
|
|
1994
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_save ],
|
|
1995
|
+
|
|
1996
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_update_close ],
|
|
1997
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_update ],
|
|
1998
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
|
|
1999
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_save ]
|
|
2000
|
+
]
|
|
2001
|
+
end
|
|
2002
|
+
|
|
2003
|
+
it 'calls callbacks in the right order' do
|
|
2004
|
+
parent.callback_registry = nil
|
|
2005
|
+
parent.child.callback_registry = nil
|
|
2006
|
+
parent.save!
|
|
2007
|
+
|
|
2008
|
+
parent.callback_registry = registry
|
|
2009
|
+
parent.child.callback_registry = registry
|
|
2010
|
+
parent.name = 'name'
|
|
2011
|
+
parent.child.age = 10
|
|
2012
|
+
|
|
2013
|
+
parent.save!
|
|
2014
|
+
expect(registry.calls).to eq expected
|
|
2015
|
+
end
|
|
2016
|
+
end
|
|
2017
|
+
|
|
2018
|
+
context 'without around callbacks' do
|
|
2019
|
+
config_override :around_callbacks_for_embeds, false
|
|
2020
|
+
|
|
2021
|
+
let(:expected) do
|
|
2022
|
+
[
|
|
2023
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
2024
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
2025
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_validation ],
|
|
2026
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_validation ],
|
|
2027
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_validation ],
|
|
2028
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_validation ],
|
|
2029
|
+
|
|
2030
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_save ],
|
|
2031
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_open ],
|
|
2032
|
+
[ InterceptableSpec::CbEmbedsOneParent, :before_update ],
|
|
2033
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_update_open ],
|
|
2034
|
+
|
|
2035
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_save ],
|
|
2036
|
+
[ InterceptableSpec::CbEmbedsOneChild, :before_update ],
|
|
2037
|
+
|
|
2038
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_update ],
|
|
2039
|
+
[ InterceptableSpec::CbEmbedsOneChild, :after_save ],
|
|
2040
|
+
|
|
2041
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_update_close ],
|
|
2042
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_update ],
|
|
2043
|
+
[ InterceptableSpec::CbEmbedsOneParent, :around_save_close ],
|
|
2044
|
+
[ InterceptableSpec::CbEmbedsOneParent, :after_save ]
|
|
2045
|
+
]
|
|
2046
|
+
end
|
|
2047
|
+
|
|
2048
|
+
it 'calls callbacks in the right order' do
|
|
2049
|
+
parent.callback_registry = nil
|
|
2050
|
+
parent.child.callback_registry = nil
|
|
2051
|
+
parent.save!
|
|
2052
|
+
|
|
2053
|
+
parent.callback_registry = registry
|
|
2054
|
+
parent.child.callback_registry = registry
|
|
2055
|
+
parent.name = 'name'
|
|
2056
|
+
parent.child.age = 10
|
|
2057
|
+
|
|
2058
|
+
parent.save!
|
|
2059
|
+
expect(registry.calls).to eq expected
|
|
2060
|
+
end
|
|
2061
|
+
end
|
|
2062
|
+
end
|
|
2063
|
+
end
|
|
2064
|
+
|
|
2065
|
+
context 'has_many' do
|
|
2066
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2067
|
+
|
|
2068
|
+
let(:parent) do
|
|
2069
|
+
InterceptableSpec::CbHasManyParent.new(registry).tap do |parent|
|
|
2070
|
+
parent.children = [
|
|
2071
|
+
InterceptableSpec::CbHasManyChild.new(registry),
|
|
2072
|
+
InterceptableSpec::CbHasManyChild.new(registry)
|
|
2073
|
+
]
|
|
2074
|
+
end
|
|
2075
|
+
end
|
|
2076
|
+
|
|
2077
|
+
let(:expected) do
|
|
2078
|
+
[
|
|
2079
|
+
[ InterceptableSpec::CbHasManyParent, :before_validation ],
|
|
2080
|
+
[ InterceptableSpec::CbHasManyChild, :before_validation ],
|
|
2081
|
+
[ InterceptableSpec::CbHasManyChild, :after_validation ],
|
|
2082
|
+
[ InterceptableSpec::CbHasManyChild, :before_validation ],
|
|
2083
|
+
[ InterceptableSpec::CbHasManyChild, :after_validation ],
|
|
2084
|
+
[ InterceptableSpec::CbHasManyParent, :after_validation ],
|
|
2085
|
+
|
|
2086
|
+
[ InterceptableSpec::CbHasManyParent, :before_save ],
|
|
2087
|
+
[ InterceptableSpec::CbHasManyParent, :around_save_open ],
|
|
2088
|
+
[ InterceptableSpec::CbHasManyParent, :before_create ],
|
|
2089
|
+
[ InterceptableSpec::CbHasManyParent, :around_create_open ],
|
|
2090
|
+
|
|
2091
|
+
[ InterceptableSpec::CbHasManyParent, :insert_into_database ],
|
|
2092
|
+
|
|
2093
|
+
[ InterceptableSpec::CbHasManyChild, :before_validation ],
|
|
2094
|
+
[ InterceptableSpec::CbHasManyChild, :after_validation ],
|
|
2095
|
+
[ InterceptableSpec::CbHasManyChild, :before_save ],
|
|
2096
|
+
[ InterceptableSpec::CbHasManyChild, :around_save_open ],
|
|
2097
|
+
[ InterceptableSpec::CbHasManyChild, :before_create ],
|
|
2098
|
+
[ InterceptableSpec::CbHasManyChild, :around_create_open ],
|
|
2099
|
+
[ InterceptableSpec::CbHasManyChild, :around_create_close ],
|
|
2100
|
+
[ InterceptableSpec::CbHasManyChild, :after_create ],
|
|
2101
|
+
[ InterceptableSpec::CbHasManyChild, :around_save_close ],
|
|
2102
|
+
[ InterceptableSpec::CbHasManyChild, :after_save ],
|
|
2103
|
+
|
|
2104
|
+
[ InterceptableSpec::CbHasManyChild, :before_validation ],
|
|
2105
|
+
[ InterceptableSpec::CbHasManyChild, :after_validation ],
|
|
2106
|
+
[ InterceptableSpec::CbHasManyChild, :before_save ],
|
|
2107
|
+
[ InterceptableSpec::CbHasManyChild, :around_save_open ],
|
|
2108
|
+
[ InterceptableSpec::CbHasManyChild, :before_create ],
|
|
2109
|
+
[ InterceptableSpec::CbHasManyChild, :around_create_open ],
|
|
2110
|
+
[ InterceptableSpec::CbHasManyChild, :around_create_close ],
|
|
2111
|
+
[ InterceptableSpec::CbHasManyChild, :after_create ],
|
|
2112
|
+
[ InterceptableSpec::CbHasManyChild, :around_save_close ],
|
|
2113
|
+
[ InterceptableSpec::CbHasManyChild, :after_save ],
|
|
2114
|
+
|
|
2115
|
+
[ InterceptableSpec::CbHasManyParent, :around_create_close ],
|
|
2116
|
+
[ InterceptableSpec::CbHasManyParent, :after_create ],
|
|
2117
|
+
[ InterceptableSpec::CbHasManyParent, :around_save_close ],
|
|
2118
|
+
[ InterceptableSpec::CbHasManyParent, :after_save ]
|
|
2119
|
+
]
|
|
2120
|
+
end
|
|
2121
|
+
|
|
2122
|
+
it 'calls callbacks in the right order' do
|
|
2123
|
+
parent.save!
|
|
2124
|
+
expect(registry.calls).to eq expected
|
|
2125
|
+
end
|
|
2126
|
+
end
|
|
2127
|
+
|
|
2128
|
+
context 'embeds_many' do
|
|
2129
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2130
|
+
|
|
2131
|
+
let(:parent) do
|
|
2132
|
+
InterceptableSpec::CbEmbedsManyParent.new(registry).tap do |parent|
|
|
2133
|
+
parent.children = [
|
|
2134
|
+
InterceptableSpec::CbEmbedsManyChild.new(registry),
|
|
2135
|
+
InterceptableSpec::CbEmbedsManyChild.new(registry)
|
|
2136
|
+
]
|
|
2137
|
+
end
|
|
2138
|
+
end
|
|
2139
|
+
|
|
2140
|
+
context 'with around callbacks' do
|
|
2141
|
+
config_override :around_callbacks_for_embeds, true
|
|
2142
|
+
|
|
2143
|
+
let(:expected) do
|
|
2144
|
+
[
|
|
2145
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2146
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2147
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2148
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2149
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_validation ],
|
|
2150
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2151
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2152
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2153
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2154
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_validation ],
|
|
2155
|
+
|
|
2156
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_save ],
|
|
2157
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_save_open ],
|
|
2158
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_create ],
|
|
2159
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_create_open ],
|
|
2160
|
+
|
|
2161
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_save ],
|
|
2162
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_save_open ],
|
|
2163
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_save ],
|
|
2164
|
+
|
|
2165
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_save_open ],
|
|
2166
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_create ],
|
|
2167
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_create_open ],
|
|
2168
|
+
|
|
2169
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_create ],
|
|
2170
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_create_open ],
|
|
2171
|
+
|
|
2172
|
+
[ InterceptableSpec::CbEmbedsManyParent, :insert_into_database ],
|
|
2173
|
+
|
|
2174
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_create_close ],
|
|
2175
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_create ],
|
|
2176
|
+
|
|
2177
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_create_close ],
|
|
2178
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_create ],
|
|
2179
|
+
|
|
2180
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_save_close ],
|
|
2181
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_save ],
|
|
2182
|
+
|
|
2183
|
+
[ InterceptableSpec::CbEmbedsManyChild, :around_save_close ],
|
|
2184
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_save ],
|
|
2185
|
+
|
|
2186
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_create_close ],
|
|
2187
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_create ],
|
|
2188
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_save_close ],
|
|
2189
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_save ]
|
|
2190
|
+
]
|
|
2191
|
+
end
|
|
2192
|
+
|
|
2193
|
+
it 'calls callbacks in the right order' do
|
|
2194
|
+
parent.save!
|
|
2195
|
+
expect(registry.calls).to eq expected
|
|
2196
|
+
end
|
|
2197
|
+
end
|
|
2198
|
+
|
|
2199
|
+
context 'without around callbacks' do
|
|
2200
|
+
config_override :around_callbacks_for_embeds, false
|
|
2201
|
+
|
|
2202
|
+
let(:expected) do
|
|
2203
|
+
[
|
|
2204
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2205
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2206
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2207
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2208
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_validation ],
|
|
2209
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2210
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2211
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_validation ],
|
|
2212
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_validation ],
|
|
2213
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_validation ],
|
|
2214
|
+
|
|
2215
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_save ],
|
|
2216
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_save_open ],
|
|
2217
|
+
[ InterceptableSpec::CbEmbedsManyParent, :before_create ],
|
|
2218
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_create_open ],
|
|
2219
|
+
|
|
2220
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_save ],
|
|
2221
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_save ],
|
|
2222
|
+
|
|
2223
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_create ],
|
|
2224
|
+
|
|
2225
|
+
[ InterceptableSpec::CbEmbedsManyChild, :before_create ],
|
|
2226
|
+
|
|
2227
|
+
[ InterceptableSpec::CbEmbedsManyParent, :insert_into_database ],
|
|
2228
|
+
|
|
2229
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_create ],
|
|
2230
|
+
|
|
2231
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_create ],
|
|
2232
|
+
|
|
2233
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_save ],
|
|
2234
|
+
|
|
2235
|
+
[ InterceptableSpec::CbEmbedsManyChild, :after_save ],
|
|
2236
|
+
|
|
2237
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_create_close ],
|
|
2238
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_create ],
|
|
2239
|
+
[ InterceptableSpec::CbEmbedsManyParent, :around_save_close ],
|
|
2240
|
+
[ InterceptableSpec::CbEmbedsManyParent, :after_save ]
|
|
2241
|
+
]
|
|
2242
|
+
end
|
|
2243
|
+
|
|
2244
|
+
it 'calls callbacks in the right order' do
|
|
2245
|
+
parent.save!
|
|
2246
|
+
expect(registry.calls).to eq expected
|
|
2247
|
+
end
|
|
2248
|
+
end
|
|
2249
|
+
end
|
|
2250
|
+
end
|
|
2251
|
+
|
|
2252
|
+
context 'when accessing parent document from callbacks' do
|
|
2253
|
+
shared_examples 'accesses the correct parent' do
|
|
2254
|
+
it 'accesses the correct parent in after_find' do
|
|
2255
|
+
expect(from_db.after_find_player).to eq(player._id)
|
|
2256
|
+
end
|
|
2257
|
+
|
|
2258
|
+
it 'accesses the correct parent in after_initialize' do
|
|
2259
|
+
expect(from_db.after_initialize_player).to eq(player._id)
|
|
2260
|
+
end
|
|
2261
|
+
|
|
2262
|
+
it 'accesses the correct parent in default' do
|
|
2263
|
+
expect(from_db.after_default_player).to eq(player._id)
|
|
2264
|
+
end
|
|
2265
|
+
|
|
2266
|
+
it 'accesses the correct parent in unpersisted after_initialize' do
|
|
2267
|
+
expect(unpersisted.after_initialize_player).to eq(player._id)
|
|
2268
|
+
end
|
|
2269
|
+
end
|
|
2270
|
+
|
|
2271
|
+
context 'when using create methods' do
|
|
2272
|
+
context 'when the child is an embeds_many association' do
|
|
2273
|
+
let!(:player) do
|
|
2274
|
+
Player.create!.tap do |player|
|
|
2275
|
+
player.implants.create!
|
|
2276
|
+
end
|
|
2277
|
+
end
|
|
2278
|
+
let(:from_db) do
|
|
2279
|
+
Player.find(player.id).implants.first
|
|
2280
|
+
end
|
|
2281
|
+
|
|
2282
|
+
let(:unpersisted) { player.implants.first }
|
|
2283
|
+
|
|
2284
|
+
before do
|
|
2285
|
+
# The default is originally set when creating this document, and it is
|
|
2286
|
+
# subsequently persisted to the database. Therefore when we retrieve
|
|
2287
|
+
# this document from the database, this field is already set, and
|
|
2288
|
+
# the default Proc is not called. This unset is needed to allow the
|
|
2289
|
+
# default Proc to be called when the document is retrieved from the
|
|
2290
|
+
# database.
|
|
2291
|
+
Player.find(player.id).implants.first.unset(:after_default_player)
|
|
2292
|
+
end
|
|
2293
|
+
|
|
2294
|
+
include_examples 'accesses the correct parent'
|
|
2295
|
+
end
|
|
2296
|
+
|
|
2297
|
+
context 'when the child is an embeds_one association' do
|
|
2298
|
+
let!(:player) do
|
|
2299
|
+
Player.create!.tap do |player|
|
|
2300
|
+
player.create_augmentation
|
|
2301
|
+
end
|
|
2302
|
+
end
|
|
2303
|
+
let(:from_db) do
|
|
2304
|
+
Player.find(player.id).augmentation
|
|
2305
|
+
end
|
|
2306
|
+
|
|
2307
|
+
let(:unpersisted) { player.augmentation }
|
|
2308
|
+
|
|
2309
|
+
before do
|
|
2310
|
+
Player.find(player.id).augmentation.unset(:after_default_player)
|
|
2311
|
+
end
|
|
2312
|
+
|
|
2313
|
+
include_examples 'accesses the correct parent'
|
|
2314
|
+
end
|
|
2315
|
+
|
|
2316
|
+
context 'when the child is a has_many association' do
|
|
2317
|
+
let!(:player) do
|
|
2318
|
+
Player.create!.tap do |player|
|
|
2319
|
+
player.weapons.create!
|
|
2320
|
+
end
|
|
2321
|
+
end
|
|
2322
|
+
let(:from_db) do
|
|
2323
|
+
Player.find(player.id).weapons.first
|
|
2324
|
+
end
|
|
2325
|
+
|
|
2326
|
+
let(:unpersisted) { player.weapons.first }
|
|
2327
|
+
|
|
2328
|
+
before do
|
|
2329
|
+
Player.find(player.id).weapons.first.unset(:after_default_player)
|
|
2330
|
+
end
|
|
2331
|
+
|
|
2332
|
+
include_examples 'accesses the correct parent'
|
|
2333
|
+
end
|
|
2334
|
+
|
|
2335
|
+
context 'when the child is a has_one association' do
|
|
2336
|
+
let!(:player) do
|
|
2337
|
+
Player.create!.tap do |player|
|
|
2338
|
+
player.create_powerup
|
|
2339
|
+
player.save!
|
|
2340
|
+
end
|
|
2341
|
+
end
|
|
2342
|
+
let(:from_db) do
|
|
2343
|
+
Player.find(player.id).powerup
|
|
2344
|
+
end
|
|
2345
|
+
|
|
2346
|
+
let(:unpersisted) { player.powerup }
|
|
2347
|
+
|
|
2348
|
+
before do
|
|
2349
|
+
Player.find(player.id).powerup.unset(:after_default_player)
|
|
2350
|
+
end
|
|
2351
|
+
|
|
2352
|
+
include_examples 'accesses the correct parent'
|
|
2353
|
+
end
|
|
2354
|
+
|
|
2355
|
+
context 'when the child is a has_and_belongs_to_many association' do
|
|
2356
|
+
let!(:player) do
|
|
2357
|
+
Player.create!.tap do |player|
|
|
2358
|
+
player.shields.create!
|
|
2359
|
+
end
|
|
2360
|
+
end
|
|
2361
|
+
let(:from_db) do
|
|
2362
|
+
Player.find(player.id).shields.first
|
|
2363
|
+
end
|
|
2364
|
+
|
|
2365
|
+
let(:unpersisted) { player.shields.first }
|
|
2366
|
+
|
|
2367
|
+
before do
|
|
2368
|
+
Player.find(player.id).shields.unset(:after_default_player)
|
|
2369
|
+
end
|
|
2370
|
+
|
|
2371
|
+
include_examples 'accesses the correct parent'
|
|
2372
|
+
end
|
|
2373
|
+
end
|
|
2374
|
+
|
|
2375
|
+
context 'when using build methods' do
|
|
2376
|
+
context 'when the child is an embeds_many association' do
|
|
2377
|
+
let!(:player) do
|
|
2378
|
+
Player.create!.tap do |player|
|
|
2379
|
+
player.implants.build
|
|
2380
|
+
player.implants.first.save!
|
|
2381
|
+
end
|
|
2382
|
+
end
|
|
2383
|
+
let(:from_db) do
|
|
2384
|
+
Player.find(player.id).implants.first
|
|
2385
|
+
end
|
|
2386
|
+
|
|
2387
|
+
let(:unpersisted) { player.implants.first }
|
|
2388
|
+
|
|
2389
|
+
before do
|
|
2390
|
+
Player.find(player.id).implants.first.unset(:after_default_player)
|
|
2391
|
+
end
|
|
2392
|
+
|
|
2393
|
+
include_examples 'accesses the correct parent'
|
|
2394
|
+
end
|
|
2395
|
+
|
|
2396
|
+
context 'when the child is an embeds_one association' do
|
|
2397
|
+
let!(:player) do
|
|
2398
|
+
Player.create!.tap do |player|
|
|
2399
|
+
player.build_augmentation
|
|
2400
|
+
player.save!
|
|
2401
|
+
end
|
|
2402
|
+
end
|
|
2403
|
+
let(:from_db) do
|
|
2404
|
+
Player.find(player.id).augmentation
|
|
2405
|
+
end
|
|
2406
|
+
|
|
2407
|
+
let(:unpersisted) { player.augmentation }
|
|
2408
|
+
|
|
2409
|
+
before do
|
|
2410
|
+
Player.find(player.id).augmentation.unset(:after_default_player)
|
|
2411
|
+
end
|
|
2412
|
+
|
|
2413
|
+
include_examples 'accesses the correct parent'
|
|
2414
|
+
end
|
|
2415
|
+
|
|
2416
|
+
context 'when the child is a has_many association' do
|
|
2417
|
+
let!(:player) do
|
|
2418
|
+
Player.create!.tap do |player|
|
|
2419
|
+
player.weapons.build
|
|
2420
|
+
player.weapons.first.save!
|
|
2421
|
+
end
|
|
2422
|
+
end
|
|
2423
|
+
let(:from_db) do
|
|
2424
|
+
Player.find(player.id).weapons.first
|
|
2425
|
+
end
|
|
2426
|
+
|
|
2427
|
+
let(:unpersisted) { player.weapons.first }
|
|
2428
|
+
|
|
2429
|
+
before do
|
|
2430
|
+
Player.find(player.id).weapons.first.unset(:after_default_player)
|
|
2431
|
+
end
|
|
2432
|
+
|
|
2433
|
+
include_examples 'accesses the correct parent'
|
|
2434
|
+
end
|
|
2435
|
+
|
|
2436
|
+
context 'when the child is a has_one association' do
|
|
2437
|
+
let!(:player) do
|
|
2438
|
+
Player.create!.tap do |player|
|
|
2439
|
+
player.build_powerup
|
|
2440
|
+
player.powerup.save!
|
|
2441
|
+
end
|
|
2442
|
+
end
|
|
2443
|
+
let(:from_db) do
|
|
2444
|
+
Player.find(player.id).powerup
|
|
2445
|
+
end
|
|
2446
|
+
|
|
2447
|
+
let(:unpersisted) { player.powerup }
|
|
2448
|
+
|
|
2449
|
+
before do
|
|
2450
|
+
Player.find(player.id).powerup.unset(:after_default_player)
|
|
2451
|
+
end
|
|
2452
|
+
|
|
2453
|
+
include_examples 'accesses the correct parent'
|
|
2454
|
+
end
|
|
2455
|
+
|
|
2456
|
+
context 'when the child is a has_and_belongs_to_many association' do
|
|
2457
|
+
let!(:player) do
|
|
2458
|
+
Player.create!.tap do |player|
|
|
2459
|
+
player.shields.build
|
|
2460
|
+
player.shields.first.save!
|
|
2461
|
+
end
|
|
2462
|
+
end
|
|
2463
|
+
let(:from_db) do
|
|
2464
|
+
Player.find(player.id).shields.first
|
|
2465
|
+
end
|
|
2466
|
+
|
|
2467
|
+
let(:unpersisted) { player.shields.first }
|
|
2468
|
+
|
|
2469
|
+
before do
|
|
2470
|
+
Player.find(player.id).shields.unset(:after_default_player)
|
|
2471
|
+
end
|
|
2472
|
+
|
|
2473
|
+
include_examples 'accesses the correct parent'
|
|
2474
|
+
end
|
|
2475
|
+
end
|
|
2476
|
+
end
|
|
2477
|
+
|
|
2478
|
+
context 'when accessing associations in defaults' do
|
|
2479
|
+
context 'when not using autobuilding' do
|
|
2480
|
+
let(:band) { InterceptableBand.create(name: 'Molejo') }
|
|
2481
|
+
let(:song) { band.songs.create(name: 'Cilada') }
|
|
2482
|
+
|
|
2483
|
+
it 'assigns the default correctly' do
|
|
2484
|
+
expect(song.band_name).to eq('Molejo')
|
|
2485
|
+
end
|
|
2486
|
+
end
|
|
2487
|
+
|
|
2488
|
+
context 'when using autobuilding' do
|
|
2489
|
+
before do
|
|
2490
|
+
InterceptablePlane.create!.tap do |plane|
|
|
2491
|
+
plane.wings.create!
|
|
2492
|
+
end
|
|
2493
|
+
end
|
|
2494
|
+
|
|
2495
|
+
let(:plane) { InterceptablePlane.first }
|
|
2496
|
+
let(:wing) { InterceptableWing.first }
|
|
2497
|
+
let(:engine) { wing.engine }
|
|
2498
|
+
|
|
2499
|
+
it 'sets the defaults correctly' do
|
|
2500
|
+
expect(wing._id).to eq('hello-wing')
|
|
2501
|
+
expect(wing.p_id).to eq(plane._id.to_s)
|
|
2502
|
+
expect(wing.e_id).to eq(engine._id.to_s)
|
|
2503
|
+
expect(engine._id).to eq("hello-engine-#{wing.id}")
|
|
2504
|
+
end
|
|
2505
|
+
end
|
|
2506
|
+
end
|
|
2507
|
+
|
|
2508
|
+
# This case is rather niche. The _ids method used to use the `.only` method
|
|
2509
|
+
# to get only the _ids for an association, which was causing a
|
|
2510
|
+
# MissingAttributeError to be raised when accessing another association. This
|
|
2511
|
+
# was fixed by using `.pluck` over `.only`. Look at MONGOID-5306 for a more
|
|
2512
|
+
# detailed explanation.
|
|
2513
|
+
context 'when accessing _ids in validate and access an association in after_initialize' do
|
|
2514
|
+
it "doesn't raise AttributeNotLoaded" do
|
|
2515
|
+
company = InterceptableCompany.create!
|
|
2516
|
+
InterceptableShop.create!(company: company)
|
|
2517
|
+
user = InterceptableUser.new
|
|
2518
|
+
user.company = company
|
|
2519
|
+
expect do
|
|
2520
|
+
user.save!
|
|
2521
|
+
end.not_to raise_error(Mongoid::Errors::AttributeNotLoaded)
|
|
2522
|
+
end
|
|
2523
|
+
end
|
|
2524
|
+
|
|
2525
|
+
context 'when around callbacks for embedded are disabled' do
|
|
2526
|
+
config_override :around_callbacks_for_embeds, false
|
|
2527
|
+
|
|
2528
|
+
context 'when around callback is defined' do
|
|
2529
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2530
|
+
|
|
2531
|
+
let(:parent) do
|
|
2532
|
+
InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
|
|
2533
|
+
parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
|
|
2534
|
+
end
|
|
2535
|
+
end
|
|
2536
|
+
|
|
2537
|
+
before do
|
|
2538
|
+
expect(Mongoid.logger).to receive(:warn).with(/Around callbacks are disabled for embedded documents/).twice.and_call_original
|
|
2539
|
+
expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
|
|
2540
|
+
end
|
|
2541
|
+
|
|
2542
|
+
it 'logs a warning' do
|
|
2543
|
+
parent.save!
|
|
2544
|
+
end
|
|
2545
|
+
end
|
|
2546
|
+
end
|
|
2547
|
+
|
|
2548
|
+
context 'when around callbacks for embedded children are enabled' do
|
|
2549
|
+
config_override :around_callbacks_for_embeds, true
|
|
2550
|
+
|
|
2551
|
+
context 'when around callback is defined without a yield' do
|
|
2552
|
+
class Mother
|
|
2553
|
+
include Mongoid::Document
|
|
2554
|
+
|
|
2555
|
+
embeds_many :daughters, cascade_callbacks: true
|
|
2556
|
+
end
|
|
2557
|
+
|
|
2558
|
+
class Daughter
|
|
2559
|
+
include Mongoid::Document
|
|
2560
|
+
|
|
2561
|
+
embedded_in :mother
|
|
2562
|
+
around_save :log_callback
|
|
2563
|
+
|
|
2564
|
+
private
|
|
2565
|
+
|
|
2566
|
+
def log_callback
|
|
2567
|
+
logger.debug('callback invoked')
|
|
2568
|
+
end
|
|
2569
|
+
end
|
|
2570
|
+
|
|
2571
|
+
let(:mom) { Mother.create(daughters: [ Daughter.new, Daughter.new ]) }
|
|
2572
|
+
|
|
2573
|
+
it 'raises an InvalidAroundCallback error' do
|
|
2574
|
+
expect do
|
|
2575
|
+
mom.save
|
|
2576
|
+
end.to raise_error(Mongoid::Errors::InvalidAroundCallback)
|
|
2577
|
+
end
|
|
2578
|
+
end
|
|
2579
|
+
end
|
|
1722
2580
|
end
|