mongoid 7.0.5 → 8.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +33 -33
- data/LICENSE +1 -0
- data/README.md +34 -20
- data/Rakefile +88 -5
- data/lib/config/locales/en.yml +220 -105
- data/lib/mongoid/association/accessors.rb +176 -84
- data/lib/mongoid/association/bindable.rb +57 -28
- data/lib/mongoid/association/builders.rb +9 -15
- data/lib/mongoid/association/constrainable.rb +5 -7
- data/lib/mongoid/association/depending.rb +9 -18
- data/lib/mongoid/association/eager_loadable.rb +31 -10
- data/lib/mongoid/association/embedded/batchable.rb +68 -54
- data/lib/mongoid/association/embedded/cyclic.rb +10 -17
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +27 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +9 -6
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +16 -25
- data/lib/mongoid/association/embedded/embedded_in.rb +9 -28
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +5 -8
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +10 -6
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +172 -136
- data/lib/mongoid/association/embedded/embeds_many.rb +10 -37
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +4 -8
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +27 -10
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +64 -30
- data/lib/mongoid/association/embedded/embeds_one.rb +11 -34
- data/lib/mongoid/association/embedded.rb +2 -0
- data/lib/mongoid/association/macros.rb +71 -41
- data/lib/mongoid/association/many.rb +25 -35
- data/lib/mongoid/association/marshalable.rb +3 -6
- data/lib/mongoid/association/nested/many.rb +22 -30
- data/lib/mongoid/association/nested/nested_buildable.rb +9 -15
- data/lib/mongoid/association/nested/one.rb +57 -30
- data/lib/mongoid/association/nested.rb +3 -3
- data/lib/mongoid/association/one.rb +5 -12
- data/lib/mongoid/association/options.rb +16 -46
- data/lib/mongoid/association/proxy.rb +52 -40
- data/lib/mongoid/association/referenced/auto_save.rb +9 -14
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +5 -9
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +40 -3
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +19 -31
- data/lib/mongoid/association/referenced/belongs_to.rb +16 -38
- data/lib/mongoid/association/referenced/counter_cache.rb +14 -25
- data/lib/mongoid/association/referenced/eager.rb +41 -40
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +12 -11
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +5 -5
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +105 -68
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +29 -46
- data/lib/mongoid/association/referenced/has_many/binding.rb +3 -6
- data/lib/mongoid/association/referenced/has_many/buildable.rb +5 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +440 -456
- data/lib/mongoid/association/referenced/has_many/proxy.rb +113 -127
- data/lib/mongoid/association/referenced/has_many.rb +21 -45
- data/lib/mongoid/association/referenced/has_one/binding.rb +4 -9
- data/lib/mongoid/association/referenced/has_one/buildable.rb +20 -6
- data/lib/mongoid/association/referenced/has_one/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +16 -29
- data/lib/mongoid/association/referenced/has_one/proxy.rb +25 -30
- data/lib/mongoid/association/referenced/has_one.rb +16 -36
- data/lib/mongoid/association/referenced/syncable.rb +11 -26
- data/lib/mongoid/association/referenced.rb +2 -0
- data/lib/mongoid/association/reflections.rb +7 -6
- data/lib/mongoid/association/relatable.rb +62 -84
- data/lib/mongoid/association.rb +13 -27
- data/lib/mongoid/atomic/modifiers.rb +29 -53
- data/lib/mongoid/atomic/paths/embedded/many.rb +23 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded.rb +2 -3
- data/lib/mongoid/atomic/paths/root.rb +4 -7
- data/lib/mongoid/atomic/paths.rb +2 -1
- data/lib/mongoid/atomic.rb +51 -47
- data/lib/mongoid/attributes/dynamic.rb +22 -36
- data/lib/mongoid/attributes/nested.rb +12 -15
- data/lib/mongoid/attributes/processing.rb +46 -30
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +6 -9
- data/lib/mongoid/attributes.rb +103 -100
- data/lib/mongoid/cacheable.rb +7 -10
- data/lib/mongoid/changeable.rb +152 -73
- data/lib/mongoid/clients/factory.rb +42 -17
- data/lib/mongoid/clients/options.rb +15 -14
- data/lib/mongoid/clients/sessions.rb +10 -10
- data/lib/mongoid/clients/storage_options.rb +9 -17
- data/lib/mongoid/clients/validators/storage.rb +5 -24
- data/lib/mongoid/clients/validators.rb +2 -1
- data/lib/mongoid/clients.rb +3 -10
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +7 -9
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/environment.rb +51 -13
- data/lib/mongoid/config/options.rb +23 -23
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators/client.rb +8 -23
- data/lib/mongoid/config/validators/option.rb +2 -3
- data/lib/mongoid/config/validators.rb +3 -1
- data/lib/mongoid/config.rb +265 -48
- data/lib/mongoid/contextual/aggregable/memory.rb +40 -27
- data/lib/mongoid/contextual/aggregable/mongo.rb +32 -33
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +29 -31
- data/lib/mongoid/contextual/command.rb +2 -5
- data/lib/mongoid/contextual/geo_near.rb +13 -44
- data/lib/mongoid/contextual/map_reduce.rb +7 -35
- data/lib/mongoid/contextual/memory.rb +387 -81
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +664 -283
- data/lib/mongoid/contextual/none.rb +264 -31
- data/lib/mongoid/contextual/queryable.rb +3 -4
- data/lib/mongoid/contextual.rb +21 -11
- data/lib/mongoid/copyable.rb +42 -17
- data/lib/mongoid/criteria/findable.rb +20 -20
- data/lib/mongoid/criteria/includable.rb +32 -34
- data/lib/mongoid/criteria/inspectable.rb +2 -3
- data/lib/mongoid/criteria/marshalable.rb +12 -7
- data/lib/mongoid/criteria/modifiable.rb +4 -20
- data/lib/mongoid/criteria/options.rb +2 -3
- data/lib/mongoid/criteria/permission.rb +3 -2
- data/lib/mongoid/criteria/queryable/aggregable.rb +4 -15
- data/lib/mongoid/criteria/queryable/expandable.rb +68 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -41
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +28 -8
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +5 -6
- data/lib/mongoid/criteria/queryable/extensions/date.rb +9 -9
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +11 -12
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +4 -41
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +3 -14
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +4 -21
- data/lib/mongoid/criteria/queryable/extensions/object.rb +6 -30
- data/lib/mongoid/criteria/queryable/extensions/range.rb +49 -17
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +12 -19
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -5
- data/lib/mongoid/criteria/queryable/extensions/string.rb +7 -32
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +7 -22
- data/lib/mongoid/criteria/queryable/extensions/time.rb +10 -10
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +19 -7
- data/lib/mongoid/criteria/queryable/extensions.rb +1 -4
- data/lib/mongoid/criteria/queryable/key.rb +40 -25
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -4
- data/lib/mongoid/criteria/queryable/mergeable.rb +205 -44
- data/lib/mongoid/criteria/queryable/optional.rb +16 -65
- data/lib/mongoid/criteria/queryable/options.rb +4 -21
- data/lib/mongoid/criteria/queryable/pipeline.rb +5 -15
- data/lib/mongoid/criteria/queryable/selectable.rb +453 -177
- data/lib/mongoid/criteria/queryable/selector.rb +127 -30
- data/lib/mongoid/criteria/queryable/smash.rb +42 -18
- data/lib/mongoid/criteria/queryable/storable.rb +237 -0
- data/lib/mongoid/criteria/queryable.rb +18 -15
- data/lib/mongoid/criteria/scopable.rb +29 -21
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +106 -111
- data/lib/mongoid/deprecable.rb +37 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +151 -99
- data/lib/mongoid/equality.rb +35 -18
- data/lib/mongoid/errors/ambiguous_relationship.rb +4 -5
- data/lib/mongoid/errors/callback.rb +2 -3
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +18 -0
- data/lib/mongoid/errors/delete_restriction.rb +10 -13
- data/lib/mongoid/errors/document_not_destroyed.rb +4 -7
- data/lib/mongoid/errors/document_not_found.rb +35 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +2 -3
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_collection.rb +2 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +3 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +3 -4
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +8 -7
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +2 -3
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_find.rb +2 -3
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_includes.rb +2 -3
- data/lib/mongoid/errors/invalid_index.rb +2 -3
- data/lib/mongoid/errors/invalid_options.rb +4 -5
- data/lib/mongoid/errors/invalid_path.rb +2 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +2 -5
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +5 -10
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -5
- data/lib/mongoid/errors/invalid_scope.rb +2 -3
- data/lib/mongoid/errors/invalid_session_use.rb +3 -6
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -5
- data/lib/mongoid/errors/invalid_storage_options.rb +3 -4
- data/lib/mongoid/errors/invalid_storage_parent.rb +4 -3
- data/lib/mongoid/errors/invalid_time.rb +2 -3
- data/lib/mongoid/errors/inverse_not_found.rb +3 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +2 -3
- data/lib/mongoid/errors/mixed_relations.rb +2 -3
- data/lib/mongoid/errors/mongoid_error.rb +6 -13
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -4
- data/lib/mongoid/errors/no_client_config.rb +4 -5
- data/lib/mongoid/errors/no_client_database.rb +3 -4
- data/lib/mongoid/errors/no_client_hosts.rb +3 -4
- data/lib/mongoid/errors/no_clients_config.rb +2 -3
- data/lib/mongoid/errors/no_default_client.rb +3 -4
- data/lib/mongoid/errors/no_environment.rb +2 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +2 -3
- data/lib/mongoid/errors/no_metadata.rb +2 -3
- data/lib/mongoid/errors/no_parent.rb +2 -3
- data/lib/mongoid/errors/readonly_attribute.rb +3 -4
- data/lib/mongoid/errors/readonly_document.rb +3 -6
- data/lib/mongoid/errors/scope_overwrite.rb +2 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +3 -1
- data/lib/mongoid/errors/unknown_attribute.rb +3 -4
- data/lib/mongoid/errors/unknown_model.rb +2 -3
- data/lib/mongoid/errors/unsaved_document.rb +3 -2
- data/lib/mongoid/errors/unsupported_javascript.rb +2 -3
- data/lib/mongoid/errors/validations.rb +2 -1
- data/lib/mongoid/errors.rb +18 -4
- data/lib/mongoid/evolvable.rb +4 -5
- data/lib/mongoid/extensions/array.rb +37 -44
- data/lib/mongoid/extensions/big_decimal.rb +35 -21
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +10 -6
- data/lib/mongoid/extensions/date.rb +32 -25
- data/lib/mongoid/extensions/date_time.rb +5 -13
- data/lib/mongoid/extensions/decimal128.rb +2 -5
- data/lib/mongoid/extensions/false_class.rb +5 -8
- data/lib/mongoid/extensions/float.rb +12 -14
- data/lib/mongoid/extensions/hash.rb +91 -47
- data/lib/mongoid/extensions/integer.rb +12 -16
- data/lib/mongoid/extensions/module.rb +3 -4
- data/lib/mongoid/extensions/nil_class.rb +2 -5
- data/lib/mongoid/extensions/object.rb +27 -52
- data/lib/mongoid/extensions/object_id.rb +2 -7
- data/lib/mongoid/extensions/range.rb +42 -20
- data/lib/mongoid/extensions/regexp.rb +14 -8
- data/lib/mongoid/extensions/set.rb +13 -11
- data/lib/mongoid/extensions/string.rb +30 -61
- data/lib/mongoid/extensions/symbol.rb +6 -22
- data/lib/mongoid/extensions/time.rb +38 -22
- data/lib/mongoid/extensions/time_with_zone.rb +26 -9
- data/lib/mongoid/extensions/true_class.rb +5 -8
- data/lib/mongoid/extensions.rb +19 -3
- data/lib/mongoid/factory.rb +104 -17
- data/lib/mongoid/fields/foreign_key.rb +14 -26
- data/lib/mongoid/fields/localized.rb +21 -15
- data/lib/mongoid/fields/standard.rb +23 -43
- data/lib/mongoid/fields/validators/macro.rb +32 -20
- data/lib/mongoid/fields/validators.rb +2 -1
- data/lib/mongoid/fields.rb +360 -76
- data/lib/mongoid/findable.rb +115 -34
- data/lib/mongoid/indexable/specification.rb +5 -18
- data/lib/mongoid/indexable/validators/options.rb +8 -9
- data/lib/mongoid/indexable.rb +6 -21
- data/lib/mongoid/inspectable.rb +4 -11
- data/lib/mongoid/interceptable.rb +195 -42
- data/lib/mongoid/loggable.rb +13 -16
- data/lib/mongoid/matchable.rb +4 -156
- data/lib/mongoid/matcher/all.rb +22 -0
- data/lib/mongoid/matcher/and.rb +21 -0
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +36 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
- data/lib/mongoid/matcher/eq.rb +11 -0
- data/lib/mongoid/matcher/eq_impl.rb +67 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
- data/lib/mongoid/matcher/exists.rb +15 -0
- data/lib/mongoid/matcher/expression.rb +35 -0
- data/lib/mongoid/matcher/expression_operator.rb +19 -0
- data/lib/mongoid/matcher/field_expression.rb +62 -0
- data/lib/mongoid/matcher/field_operator.rb +54 -0
- data/lib/mongoid/matcher/gt.rb +17 -0
- data/lib/mongoid/matcher/gte.rb +17 -0
- data/lib/mongoid/matcher/in.rb +25 -0
- data/lib/mongoid/matcher/lt.rb +17 -0
- data/lib/mongoid/matcher/lte.rb +17 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/ne.rb +16 -0
- data/lib/mongoid/matcher/nin.rb +11 -0
- data/lib/mongoid/matcher/nor.rb +25 -0
- data/lib/mongoid/matcher/not.rb +29 -0
- data/lib/mongoid/matcher/or.rb +21 -0
- data/lib/mongoid/matcher/regex.rb +41 -0
- data/lib/mongoid/matcher/size.rb +26 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +130 -0
- data/lib/mongoid/persistable/creatable.rb +23 -30
- data/lib/mongoid/persistable/deletable.rb +7 -23
- data/lib/mongoid/persistable/destroyable.rb +12 -11
- data/lib/mongoid/persistable/incrementable.rb +6 -7
- data/lib/mongoid/persistable/logical.rb +4 -6
- data/lib/mongoid/persistable/poppable.rb +3 -6
- data/lib/mongoid/persistable/pullable.rb +3 -8
- data/lib/mongoid/persistable/pushable.rb +14 -10
- data/lib/mongoid/persistable/renamable.rb +10 -8
- data/lib/mongoid/persistable/savable.rb +16 -9
- data/lib/mongoid/persistable/settable.rb +3 -6
- data/lib/mongoid/persistable/unsettable.rb +10 -10
- data/lib/mongoid/persistable/updatable.rb +99 -30
- data/lib/mongoid/persistable/upsertable.rb +23 -9
- data/lib/mongoid/persistable.rb +138 -40
- data/lib/mongoid/persistence_context.rb +91 -51
- data/lib/mongoid/positional.rb +2 -5
- data/lib/mongoid/query_cache.rb +18 -238
- data/lib/mongoid/railtie.rb +3 -16
- data/lib/mongoid/railties/controller_runtime.rb +4 -2
- data/lib/mongoid/railties/database.rake +16 -2
- data/lib/mongoid/reloadable.rb +19 -22
- data/lib/mongoid/scopable.rb +34 -57
- data/lib/mongoid/selectable.rb +8 -18
- data/lib/mongoid/serializable.rb +33 -34
- data/lib/mongoid/shardable.rb +108 -21
- data/lib/mongoid/stateful.rb +60 -20
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +24 -5
- data/lib/mongoid/tasks/database.rb +105 -7
- data/lib/mongoid/threaded/lifecycle.rb +7 -26
- data/lib/mongoid/threaded.rb +44 -67
- data/lib/mongoid/timestamps/created/short.rb +2 -1
- data/lib/mongoid/timestamps/created.rb +4 -3
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +6 -9
- data/lib/mongoid/timestamps/updated/short.rb +2 -1
- data/lib/mongoid/timestamps/updated.rb +5 -6
- data/lib/mongoid/timestamps.rb +3 -2
- data/lib/mongoid/touchable.rb +54 -25
- data/lib/mongoid/traversable.rb +185 -61
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +99 -22
- data/lib/mongoid/validatable/format.rb +2 -1
- data/lib/mongoid/validatable/length.rb +2 -1
- data/lib/mongoid/validatable/localizable.rb +3 -4
- data/lib/mongoid/validatable/macros.rb +7 -14
- data/lib/mongoid/validatable/presence.rb +10 -15
- data/lib/mongoid/validatable/queryable.rb +2 -3
- data/lib/mongoid/validatable/uniqueness.rb +30 -42
- data/lib/mongoid/validatable.rb +24 -32
- data/lib/mongoid/version.rb +3 -2
- data/lib/mongoid/warnings.rb +44 -0
- data/lib/mongoid.rb +50 -17
- data/lib/rails/generators/mongoid/config/config_generator.rb +10 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +53 -32
- data/lib/rails/generators/mongoid/model/model_generator.rb +3 -2
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/mongoid_generator.rb +2 -1
- data/lib/rails/mongoid.rb +4 -5
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +17 -0
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +345 -0
- data/spec/integration/associations/belongs_to_spec.rb +20 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +283 -0
- data/spec/integration/associations/embeds_many_spec.rb +219 -0
- data/spec/integration/associations/embeds_one_spec.rb +41 -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 +61 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +272 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -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 +101 -0
- data/spec/integration/atomic/modifiers_spec.rb +116 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/callbacks_models.rb +192 -0
- data/spec/integration/callbacks_spec.rb +605 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +40 -0
- data/spec/integration/criteria/default_scope_spec.rb +72 -0
- data/spec/integration/criteria/logical_spec.rb +124 -0
- data/spec/integration/criteria/range_spec.rb +359 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +142 -0
- data/spec/integration/discriminator_key_spec.rb +391 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +51 -0
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +74 -0
- data/spec/integration/matcher_examples_spec.rb +765 -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 +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -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 +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -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 +41 -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 +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +35 -8
- data/spec/mongoid/association/accessors_spec.rb +284 -77
- data/spec/mongoid/association/auto_save_spec.rb +74 -33
- data/spec/mongoid/association/builders_spec.rb +3 -1
- data/spec/mongoid/association/constrainable_spec.rb +2 -0
- data/spec/mongoid/association/counter_cache_spec.rb +35 -33
- data/spec/mongoid/association/depending_spec.rb +431 -338
- data/spec/mongoid/association/eager_spec.rb +8 -5
- data/spec/mongoid/association/embedded/cyclic_spec.rb +4 -2
- data/spec/mongoid/association/embedded/dirty_spec.rb +4 -2
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +4 -1
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +56 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +152 -13
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +3 -1
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +114 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +741 -197
- data/spec/mongoid/association/embedded/embeds_many_models.rb +227 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +63 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +81 -1
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +27 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +38 -23
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +22 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +31 -3
- data/spec/mongoid/association/macros_spec.rb +11 -9
- data/spec/mongoid/association/nested/many_spec.rb +2 -0
- data/spec/mongoid/association/nested/one_spec.rb +18 -12
- data/spec/mongoid/association/options_spec.rb +2 -0
- data/spec/mongoid/association/polymorphic_spec.rb +2 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +4 -1
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +111 -16
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +242 -12
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +114 -58
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +28 -21
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +3 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +28 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +46 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +25 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +559 -385
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +68 -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 +81 -4
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +3 -1
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +132 -0
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +40 -9
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +415 -129
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +901 -502
- data/spec/mongoid/association/referenced/has_many_models.rb +61 -1
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +48 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +2 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +55 -9
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +34 -4
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +135 -27
- data/spec/mongoid/association/referenced/has_one_models.rb +65 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +24 -1
- data/spec/mongoid/association/reflections_spec.rb +2 -0
- data/spec/mongoid/association/syncable_spec.rb +48 -32
- data/spec/mongoid/association_spec.rb +2 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +49 -0
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +2 -0
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +2 -0
- data/spec/mongoid/atomic/paths/root_spec.rb +2 -0
- data/spec/mongoid/atomic/paths_spec.rb +93 -12
- data/spec/mongoid/atomic_spec.rb +53 -6
- data/spec/mongoid/attributes/dynamic_spec.rb +152 -0
- data/spec/mongoid/attributes/nested_spec.rb +149 -78
- 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 +40 -0
- data/spec/mongoid/attributes/readonly_spec.rb +24 -22
- data/spec/mongoid/attributes_spec.rb +922 -54
- data/spec/mongoid/cacheable_spec.rb +6 -4
- data/spec/mongoid/changeable_spec.rb +484 -67
- data/spec/mongoid/clients/factory_spec.rb +128 -28
- data/spec/mongoid/clients/options_spec.rb +49 -30
- data/spec/mongoid/clients/sessions_spec.rb +29 -66
- data/spec/mongoid/clients/transactions_spec.rb +74 -37
- data/spec/mongoid/clients_spec.rb +189 -23
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/composable_spec.rb +2 -0
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config/environment_spec.rb +126 -8
- data/spec/mongoid/config/options_spec.rb +22 -3
- data/spec/mongoid/config_spec.rb +513 -1
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +433 -153
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +122 -20
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +242 -81
- data/spec/mongoid/contextual/geo_near_spec.rb +30 -19
- data/spec/mongoid/contextual/map_reduce_spec.rb +22 -19
- data/spec/mongoid/contextual/memory_spec.rb +1828 -303
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +3514 -1205
- data/spec/mongoid/contextual/none_spec.rb +80 -67
- data/spec/mongoid/copyable_spec.rb +659 -36
- data/spec/mongoid/copyable_spec_models.rb +30 -0
- data/spec/mongoid/criteria/findable_spec.rb +161 -228
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +2 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +20 -1
- data/spec/mongoid/criteria/modifiable_spec.rb +43 -40
- data/spec/mongoid/criteria/options_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +61 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +9 -19
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +136 -26
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +13 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +46 -17
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +2 -15
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -8
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +239 -178
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +9 -7
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +7 -70
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +2 -59
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +53 -23
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +41 -1
- data/spec/mongoid/criteria/queryable/key_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +145 -12
- data/spec/mongoid/criteria/queryable/optional_spec.rb +18 -485
- data/spec/mongoid/criteria/queryable/options_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2538 -0
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1100 -2880
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +92 -5
- data/spec/mongoid/criteria/queryable/smash_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +298 -0
- data/spec/mongoid/criteria/scopable_spec.rb +129 -0
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +406 -0
- data/spec/mongoid/criteria_spec.rb +1320 -1723
- data/spec/mongoid/document_fields_spec.rb +262 -0
- data/spec/mongoid/document_persistence_context_spec.rb +32 -0
- data/spec/mongoid/document_query_spec.rb +89 -0
- data/spec/mongoid/document_spec.rb +153 -87
- data/spec/mongoid/equality_spec.rb +144 -41
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +5 -3
- data/spec/mongoid/errors/callback_spec.rb +2 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +4 -2
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +2 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +78 -0
- data/spec/mongoid/errors/invalid_collection_spec.rb +2 -0
- data/spec/mongoid/errors/{eager_load_spec.rb → invalid_config_file_spec.rb} +7 -5
- data/spec/mongoid/errors/invalid_config_option_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_field_option_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_field_spec.rb +3 -1
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_includes_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_index_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_options_spec.rb +4 -2
- data/spec/mongoid/errors/invalid_path_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_relation_spec.rb +4 -2
- data/spec/mongoid/errors/invalid_scope_spec.rb +3 -1
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_time_spec.rb +2 -0
- data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -1
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +2 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +2 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +24 -8
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +5 -3
- data/spec/mongoid/errors/no_client_config_spec.rb +4 -2
- data/spec/mongoid/errors/no_client_database_spec.rb +5 -3
- data/spec/mongoid/errors/no_client_hosts_spec.rb +5 -3
- data/spec/mongoid/errors/no_clients_config_spec.rb +2 -0
- data/spec/mongoid/errors/no_environment_spec.rb +5 -3
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +2 -0
- data/spec/mongoid/errors/no_metadata_spec.rb +4 -2
- data/spec/mongoid/errors/no_parent_spec.rb +3 -1
- data/spec/mongoid/errors/readonly_attribute_spec.rb +2 -0
- data/spec/mongoid/errors/readonly_document_spec.rb +4 -2
- data/spec/mongoid/errors/scope_overwrite_spec.rb +2 -0
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -1
- data/spec/mongoid/errors/unknown_attribute_spec.rb +4 -2
- data/spec/mongoid/errors/unsaved_document_spec.rb +3 -1
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +2 -0
- data/spec/mongoid/errors/validations_spec.rb +2 -0
- data/spec/mongoid/extensions/array_spec.rb +41 -45
- data/spec/mongoid/extensions/big_decimal_spec.rb +714 -212
- data/spec/mongoid/extensions/binary_spec.rb +46 -9
- data/spec/mongoid/extensions/boolean_spec.rb +70 -82
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +339 -0
- data/spec/mongoid/extensions/date_spec.rb +58 -140
- data/spec/mongoid/extensions/date_time_spec.rb +32 -69
- data/spec/mongoid/extensions/decimal128_spec.rb +2 -0
- data/spec/mongoid/extensions/false_class_spec.rb +3 -1
- data/spec/mongoid/extensions/float_spec.rb +66 -73
- data/spec/mongoid/extensions/hash_spec.rb +138 -3
- data/spec/mongoid/extensions/integer_spec.rb +61 -63
- data/spec/mongoid/extensions/module_spec.rb +2 -0
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -0
- data/spec/mongoid/extensions/object_id_spec.rb +2 -0
- data/spec/mongoid/extensions/object_spec.rb +13 -24
- data/spec/mongoid/extensions/range_spec.rb +257 -54
- data/spec/mongoid/extensions/regexp_spec.rb +60 -33
- data/spec/mongoid/extensions/set_spec.rb +108 -0
- data/spec/mongoid/extensions/string_spec.rb +111 -50
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +20 -25
- data/spec/mongoid/extensions/time_spec.rb +668 -106
- data/spec/mongoid/extensions/time_with_zone_spec.rb +57 -83
- data/spec/mongoid/extensions/true_class_spec.rb +3 -1
- data/spec/mongoid/extensions_spec.rb +16 -2
- data/spec/mongoid/factory_spec.rb +347 -27
- data/spec/mongoid/fields/foreign_key_spec.rb +2 -0
- data/spec/mongoid/fields/localized_spec.rb +86 -41
- data/spec/mongoid/fields/standard_spec.rb +2 -0
- data/spec/mongoid/fields_spec.rb +912 -114
- data/spec/mongoid/findable_spec.rb +520 -64
- data/spec/mongoid/indexable/specification_spec.rb +4 -2
- data/spec/mongoid/indexable_spec.rb +87 -32
- data/spec/mongoid/inspectable_spec.rb +39 -2
- data/spec/mongoid/interceptable_spec.rb +972 -98
- data/spec/mongoid/interceptable_spec_models.rb +307 -0
- data/spec/mongoid/loggable_spec.rb +2 -0
- 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 +36 -0
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +114 -29
- data/spec/mongoid/persistable/deletable_spec.rb +300 -18
- data/spec/mongoid/persistable/destroyable_spec.rb +228 -18
- data/spec/mongoid/persistable/incrementable_spec.rb +60 -7
- data/spec/mongoid/persistable/logical_spec.rb +56 -3
- data/spec/mongoid/persistable/poppable_spec.rb +55 -3
- data/spec/mongoid/persistable/pullable_spec.rb +108 -6
- data/spec/mongoid/persistable/pushable_spec.rb +163 -7
- data/spec/mongoid/persistable/renamable_spec.rb +54 -2
- data/spec/mongoid/persistable/savable_spec.rb +284 -25
- data/spec/mongoid/persistable/settable_spec.rb +91 -8
- data/spec/mongoid/persistable/unsettable_spec.rb +55 -3
- data/spec/mongoid/persistable/updatable_spec.rb +63 -49
- data/spec/mongoid/persistable/upsertable_spec.rb +93 -3
- data/spec/mongoid/persistable_spec.rb +85 -9
- data/spec/mongoid/persistence_context_spec.rb +59 -58
- data/spec/mongoid/positional_spec.rb +2 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +50 -0
- data/spec/mongoid/query_cache_spec.rb +410 -95
- data/spec/mongoid/relations/proxy_spec.rb +9 -7
- data/spec/mongoid/reloadable_spec.rb +381 -26
- data/spec/mongoid/scopable_spec.rb +193 -38
- data/spec/mongoid/selectable_spec.rb +8 -6
- data/spec/mongoid/serializable_spec.rb +148 -38
- data/spec/mongoid/shardable_models.rb +75 -0
- data/spec/mongoid/shardable_spec.rb +239 -34
- data/spec/mongoid/stateful_spec.rb +153 -9
- data/spec/mongoid/tasks/database_rake_spec.rb +89 -13
- data/spec/mongoid/tasks/database_spec.rb +130 -1
- data/spec/mongoid/threaded_spec.rb +4 -2
- data/spec/mongoid/timestamps/created/short_spec.rb +3 -1
- data/spec/mongoid/timestamps/created_spec.rb +3 -1
- data/spec/mongoid/timestamps/timeless_spec.rb +4 -2
- data/spec/mongoid/timestamps/updated/short_spec.rb +5 -3
- data/spec/mongoid/timestamps/updated_spec.rb +5 -3
- data/spec/mongoid/timestamps_spec.rb +400 -10
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +568 -33
- data/spec/mongoid/touchable_spec_models.rb +59 -0
- data/spec/mongoid/traversable_spec.rb +1145 -1
- data/spec/mongoid/validatable/associated_spec.rb +15 -30
- data/spec/mongoid/validatable/format_spec.rb +2 -0
- data/spec/mongoid/validatable/length_spec.rb +2 -0
- data/spec/mongoid/validatable/numericality_spec.rb +2 -0
- data/spec/mongoid/validatable/presence_spec.rb +28 -22
- data/spec/mongoid/validatable/uniqueness_spec.rb +159 -103
- data/spec/mongoid/validatable_spec.rb +5 -3
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +36 -10
- data/spec/rails/controller_extension/controller_runtime_spec.rb +5 -3
- data/spec/rails/mongoid_spec.rb +8 -18
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- 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 +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/share/Dockerfile.erb +321 -0
- 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 +74 -0
- data/spec/shared/shlib/server.sh +416 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +44 -66
- data/spec/support/authorization.rb +2 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +45 -69
- data/spec/support/expectations.rb +21 -3
- data/spec/support/helpers.rb +11 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +109 -0
- data/spec/{app → support}/models/account.rb +3 -1
- data/spec/{app → support}/models/acolyte.rb +2 -0
- data/spec/{app → support}/models/actor.rb +3 -1
- data/spec/support/models/actress.rb +4 -0
- data/spec/{app → support}/models/address.rb +6 -0
- data/spec/{app → support}/models/address_component.rb +2 -0
- data/spec/{app → support}/models/address_number.rb +2 -0
- data/spec/{app → support}/models/agency.rb +2 -0
- data/spec/{app → support}/models/agent.rb +2 -0
- data/spec/{app → support}/models/album.rb +2 -0
- data/spec/{app → support}/models/alert.rb +2 -0
- data/spec/{app → support}/models/animal.rb +2 -0
- data/spec/{app → support}/models/answer.rb +2 -0
- data/spec/{app → support}/models/appointment.rb +2 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/{app → support}/models/article.rb +2 -0
- data/spec/{app → support}/models/artist.rb +4 -1
- data/spec/{app → support}/models/artwork.rb +2 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/{app → support}/models/audio.rb +2 -0
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/{app → support}/models/author.rb +2 -0
- data/spec/{app → support}/models/baby.rb +2 -0
- data/spec/{app → support}/models/band.rb +10 -0
- data/spec/{app → support}/models/bar.rb +2 -0
- data/spec/{app → support}/models/basic.rb +2 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/{app → support}/models/big_palette.rb +2 -0
- data/spec/{app → support}/models/birthday.rb +2 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/{app → support}/models/bomb.rb +2 -0
- data/spec/{app → support}/models/book.rb +3 -0
- data/spec/{app → support}/models/breed.rb +2 -0
- data/spec/{app → support}/models/browser.rb +3 -1
- data/spec/{app → support}/models/building.rb +4 -0
- data/spec/{app → support}/models/building_address.rb +2 -0
- data/spec/{app → support}/models/bus.rb +2 -0
- data/spec/{app → support}/models/business.rb +2 -0
- data/spec/{app → support}/models/callback_test.rb +2 -0
- data/spec/{app → support}/models/canvas.rb +3 -1
- data/spec/support/models/car.rb +3 -0
- data/spec/{app → support}/models/cat.rb +2 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/{app → support}/models/category.rb +2 -0
- data/spec/{app → support}/models/child.rb +2 -0
- data/spec/{app → support}/models/child_doc.rb +5 -3
- data/spec/{app → support}/models/church.rb +2 -0
- data/spec/{app → support}/models/circle.rb +2 -0
- data/spec/{app → support}/models/circuit.rb +2 -0
- data/spec/support/models/circus.rb +12 -0
- data/spec/{app → support}/models/code.rb +4 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/{app → support}/models/comment.rb +2 -0
- data/spec/{app → support}/models/company.rb +2 -0
- data/spec/{app → support}/models/consumption_period.rb +2 -0
- data/spec/{app → support}/models/contextable_item.rb +2 -0
- data/spec/{app → support}/models/contractor.rb +2 -0
- data/spec/{app → support}/models/cookie.rb +2 -0
- data/spec/{app → support}/models/country_code.rb +4 -0
- data/spec/{app → support}/models/courier_job.rb +2 -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 +7 -0
- data/spec/{app → support}/models/definition.rb +2 -0
- data/spec/support/models/delegating_patient.rb +15 -0
- data/spec/{app → support}/models/description.rb +2 -0
- data/spec/{app → support}/models/dictionary.rb +8 -0
- data/spec/{app → support}/models/division.rb +2 -0
- data/spec/{app → support}/models/doctor.rb +2 -0
- data/spec/{app → support}/models/dog.rb +2 -0
- data/spec/{app → support}/models/dokument.rb +2 -0
- data/spec/{app → support}/models/draft.rb +2 -0
- data/spec/{app → support}/models/dragon.rb +2 -0
- data/spec/{app → support}/models/driver.rb +3 -1
- data/spec/{app → support}/models/drug.rb +2 -0
- data/spec/{app → support}/models/dungeon.rb +2 -0
- data/spec/{app → support}/models/edit.rb +2 -0
- data/spec/{app → support}/models/email.rb +2 -0
- data/spec/{app → support}/models/employer.rb +2 -0
- data/spec/{app → support}/models/entry.rb +2 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/{app → support}/models/even.rb +2 -0
- data/spec/{app → support}/models/event.rb +2 -0
- data/spec/{app → support}/models/exhibition.rb +2 -0
- data/spec/{app → support}/models/exhibitor.rb +2 -0
- data/spec/{app → support}/models/explosion.rb +2 -0
- data/spec/{app → support}/models/eye.rb +2 -0
- data/spec/{app → support}/models/eye_bowl.rb +2 -0
- data/spec/{app → support}/models/face.rb +2 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/{app → support}/models/favorite.rb +2 -0
- data/spec/{app → support}/models/filesystem.rb +2 -0
- data/spec/{app → support}/models/fire_hydrant.rb +2 -0
- data/spec/{app → support}/models/firefox.rb +2 -0
- data/spec/{app → support}/models/fish.rb +2 -0
- data/spec/{app → support}/models/folder.rb +2 -0
- data/spec/{app → support}/models/folder_item.rb +2 -0
- data/spec/{app → support}/models/fruits.rb +2 -0
- data/spec/{app → support}/models/game.rb +2 -0
- data/spec/{app → support}/models/ghost.rb +2 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/{app → support}/models/home.rb +2 -0
- data/spec/{app → support}/models/house.rb +2 -0
- data/spec/{app → support}/models/html_writer.rb +2 -0
- data/spec/{app → support}/models/id_key.rb +2 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/{app → support}/models/image.rb +2 -0
- data/spec/{app → support}/models/implant.rb +11 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/{app → support}/models/item.rb +3 -1
- data/spec/{app → support}/models/jar.rb +2 -0
- data/spec/{app → support}/models/kaleidoscope.rb +2 -0
- data/spec/{app → support}/models/kangaroo.rb +3 -1
- data/spec/{app → support}/models/label.rb +6 -1
- data/spec/{app → support}/models/language.rb +2 -0
- data/spec/{app → support}/models/lat_lng.rb +2 -0
- data/spec/{app → support}/models/league.rb +2 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/{app → support}/models/line_item.rb +2 -0
- data/spec/{app → support}/models/location.rb +2 -0
- data/spec/{app → support}/models/login.rb +2 -0
- data/spec/{app → support}/models/manufacturer.rb +2 -0
- data/spec/{app → support}/models/meat.rb +2 -0
- data/spec/{app → support}/models/membership.rb +3 -0
- data/spec/{app → support}/models/message.rb +2 -0
- data/spec/{app → support}/models/minim.rb +0 -1
- data/spec/{app → support}/models/mixed_drink.rb +2 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/{app → support}/models/movie.rb +2 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/{app → support}/models/name.rb +12 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/{app → support}/models/node.rb +2 -0
- data/spec/{app → support}/models/note.rb +2 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/{app → support}/models/odd.rb +2 -0
- data/spec/support/models/order.rb +12 -0
- data/spec/{app → support}/models/ordered_post.rb +3 -1
- data/spec/{app → support}/models/ordered_preference.rb +2 -0
- data/spec/{app → support}/models/oscar.rb +2 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/{app → support}/models/override.rb +2 -0
- data/spec/{app → support}/models/ownable.rb +2 -0
- data/spec/{app → support}/models/owner.rb +4 -0
- data/spec/{app → support}/models/pack.rb +2 -0
- data/spec/{app → support}/models/page.rb +2 -0
- data/spec/{app → support}/models/page_question.rb +2 -0
- data/spec/{app → support}/models/palette.rb +3 -1
- data/spec/{app → support}/models/parent.rb +2 -0
- data/spec/{app → support}/models/parent_doc.rb +2 -0
- data/spec/support/models/passport.rb +22 -0
- data/spec/{app → support}/models/patient.rb +2 -0
- data/spec/{app → support}/models/pdf_writer.rb +2 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/{app → support}/models/person.rb +23 -1
- data/spec/{app → support}/models/pet.rb +2 -0
- data/spec/{app → support}/models/pet_owner.rb +2 -0
- data/spec/{app → support}/models/phone.rb +5 -1
- data/spec/support/models/piano.rb +4 -0
- data/spec/{app → support}/models/pizza.rb +2 -0
- data/spec/{app → support}/models/player.rb +4 -0
- data/spec/{app → support}/models/post.rb +2 -0
- data/spec/{app → support}/models/post_genre.rb +2 -0
- data/spec/support/models/powerup.rb +25 -0
- data/spec/{app → support}/models/preference.rb +2 -0
- data/spec/{app → support}/models/princess.rb +2 -0
- data/spec/{app → support}/models/product.rb +3 -0
- data/spec/support/models/profile.rb +17 -0
- data/spec/{app → support}/models/pronunciation.rb +2 -0
- data/spec/{app → support}/models/pub.rb +2 -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/{app → support}/models/purchase.rb +2 -0
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/support/models/purse.rb +9 -0
- data/spec/{app → support}/models/question.rb +2 -0
- data/spec/{app → support}/models/quiz.rb +2 -0
- data/spec/{app → support}/models/rating.rb +2 -0
- data/spec/{app → support}/models/record.rb +2 -0
- data/spec/{app → support}/models/registry.rb +3 -0
- data/spec/{app → support}/models/role.rb +2 -0
- data/spec/{app → support}/models/root_category.rb +2 -0
- data/spec/{app → support}/models/sandwich.rb +2 -0
- data/spec/{app → support}/models/scheduler.rb +2 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/scribe.rb +7 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/{app → support}/models/seo.rb +2 -0
- data/spec/support/models/series.rb +7 -0
- data/spec/{app → support}/models/server.rb +2 -0
- data/spec/{app → support}/models/service.rb +2 -0
- data/spec/{app → support}/models/shape.rb +4 -2
- data/spec/{app → support}/models/shelf.rb +2 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/{app → support}/models/shipment_address.rb +2 -0
- data/spec/{app → support}/models/shipping_container.rb +2 -0
- data/spec/{app → support}/models/shipping_pack.rb +2 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/{app → support}/models/shop.rb +2 -0
- data/spec/{app → support}/models/short_agent.rb +2 -0
- data/spec/{app → support}/models/short_quiz.rb +2 -0
- data/spec/{app → support}/models/simple.rb +2 -0
- data/spec/{app → support}/models/slave.rb +2 -0
- data/spec/{app → support}/models/song.rb +2 -0
- data/spec/{app → support}/models/sound.rb +2 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/{app → support}/models/square.rb +2 -0
- data/spec/{app → support}/models/staff.rb +2 -0
- data/spec/{app → support}/models/store_as_dup_test1.rb +2 -0
- data/spec/{app → support}/models/store_as_dup_test2.rb +2 -0
- data/spec/{app → support}/models/strategy.rb +2 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/{app → support}/models/sub_item.rb +2 -0
- data/spec/{app → support}/models/subscription.rb +2 -0
- data/spec/{app → support}/models/survey.rb +2 -0
- data/spec/{app → support}/models/symptom.rb +2 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/{app → support}/models/tag.rb +2 -0
- data/spec/{app → support}/models/target.rb +2 -0
- data/spec/{app → support}/models/template.rb +2 -0
- data/spec/{app → support}/models/thing.rb +2 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/{app → support}/models/title.rb +2 -0
- data/spec/{app → support}/models/tool.rb +4 -2
- data/spec/{app → support}/models/topping.rb +2 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/{app → support}/models/track.rb +2 -0
- data/spec/{app → support}/models/translation.rb +2 -0
- data/spec/{app → support}/models/tree.rb +2 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/{app → support}/models/user.rb +2 -0
- data/spec/{app → support}/models/user_account.rb +2 -0
- data/spec/{app → support}/models/validation_callback.rb +2 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/{app → support}/models/version.rb +2 -0
- data/spec/{app → support}/models/vertex.rb +3 -1
- data/spec/{app → support}/models/vet_visit.rb +2 -0
- data/spec/{app → support}/models/video.rb +2 -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/{app → support}/models/wiki_page.rb +3 -0
- data/spec/{app → support}/models/word.rb +2 -0
- data/spec/{app → support}/models/word_origin.rb +2 -0
- data/spec/{app → support}/models/writer.rb +4 -2
- 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 +53 -0
- data/spec/support/spec_config.rb +30 -5
- data.tar.gz.sig +0 -0
- metadata +1249 -749
- metadata.gz.sig +0 -0
- data/lib/mongoid/criteria/queryable/forwardable.rb +0 -65
- data/lib/mongoid/errors/eager_load.rb +0 -22
- data/lib/mongoid/errors/invalid_value.rb +0 -16
- data/lib/mongoid/matchable/all.rb +0 -27
- data/lib/mongoid/matchable/and.rb +0 -30
- data/lib/mongoid/matchable/default.rb +0 -72
- 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/support/ruby_version.rb +0 -26
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/augmentation.rb +0 -11
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/circus.rb +0 -7
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/other_owner_object.rb +0 -2
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/powerup.rb +0 -11
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/video_game.rb +0 -1
- data/spec/app/models/weapon.rb +0 -11
- 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/matchable/all_spec.rb +0 -31
- data/spec/mongoid/matchable/and_spec.rb +0 -187
- data/spec/mongoid/matchable/default_spec.rb +0 -130
- 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/support/cluster_config.rb +0 -158
- /data/spec/{app → support}/models/array_field.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test3.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test4.rb +0 -0
- /data/spec/{app → support}/models/updatable.rb +0 -0
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "spec_helper"
|
|
4
|
+
require_relative './interceptable_spec_models'
|
|
2
5
|
|
|
3
6
|
describe Mongoid::Interceptable do
|
|
4
7
|
|
|
8
|
+
before do
|
|
9
|
+
# The find and initialize callbacks I added were causing failures
|
|
10
|
+
# because they were causing updates when we were asserting no updates
|
|
11
|
+
# happened.
|
|
12
|
+
Label.reset_callbacks(:initialize)
|
|
13
|
+
Label.reset_callbacks(:find)
|
|
14
|
+
end
|
|
15
|
+
|
|
5
16
|
class TestClass
|
|
6
17
|
include Mongoid::Interceptable
|
|
7
18
|
|
|
@@ -74,7 +85,7 @@ describe Mongoid::Interceptable do
|
|
|
74
85
|
describe ".after_find" do
|
|
75
86
|
|
|
76
87
|
let!(:player) do
|
|
77
|
-
Player.create
|
|
88
|
+
Player.create!
|
|
78
89
|
end
|
|
79
90
|
|
|
80
91
|
context "when the callback is on a root document" do
|
|
@@ -127,7 +138,7 @@ describe Mongoid::Interceptable do
|
|
|
127
138
|
context "when the callback is on an embedded document" do
|
|
128
139
|
|
|
129
140
|
let!(:implant) do
|
|
130
|
-
player.implants.create
|
|
141
|
+
player.implants.create!
|
|
131
142
|
end
|
|
132
143
|
|
|
133
144
|
context "when when the document is instantiated" do
|
|
@@ -197,7 +208,7 @@ describe Mongoid::Interceptable do
|
|
|
197
208
|
]
|
|
198
209
|
})
|
|
199
210
|
book.id = '123'
|
|
200
|
-
book.save
|
|
211
|
+
book.save!
|
|
201
212
|
book
|
|
202
213
|
end
|
|
203
214
|
|
|
@@ -209,7 +220,7 @@ describe Mongoid::Interceptable do
|
|
|
209
220
|
book.pages.each do | page |
|
|
210
221
|
page.notes.destroy_all
|
|
211
222
|
page.notes.new(message: new_message)
|
|
212
|
-
page.save
|
|
223
|
+
page.save!
|
|
213
224
|
end
|
|
214
225
|
end
|
|
215
226
|
|
|
@@ -272,7 +283,7 @@ describe Mongoid::Interceptable do
|
|
|
272
283
|
|
|
273
284
|
before do
|
|
274
285
|
expect(artist).to receive(:before_create_stub).once.and_return(true)
|
|
275
|
-
artist.save
|
|
286
|
+
artist.save!
|
|
276
287
|
end
|
|
277
288
|
|
|
278
289
|
it "gets saved" do
|
|
@@ -317,7 +328,7 @@ describe Mongoid::Interceptable do
|
|
|
317
328
|
end
|
|
318
329
|
|
|
319
330
|
it "the save returns true" do
|
|
320
|
-
expect(artist.save).to be true
|
|
331
|
+
expect(artist.save!).to be true
|
|
321
332
|
end
|
|
322
333
|
end
|
|
323
334
|
|
|
@@ -341,7 +352,7 @@ describe Mongoid::Interceptable do
|
|
|
341
352
|
context "when updating" do
|
|
342
353
|
|
|
343
354
|
let(:artist) do
|
|
344
|
-
Artist.create(name: "Depeche Mode").tap do |artist|
|
|
355
|
+
Artist.create!(name: "Depeche Mode").tap do |artist|
|
|
345
356
|
artist.name = "The Mountain Goats"
|
|
346
357
|
end
|
|
347
358
|
end
|
|
@@ -357,7 +368,7 @@ describe Mongoid::Interceptable do
|
|
|
357
368
|
end
|
|
358
369
|
|
|
359
370
|
it "the save returns true" do
|
|
360
|
-
expect(artist.save).to be true
|
|
371
|
+
expect(artist.save!).to be true
|
|
361
372
|
end
|
|
362
373
|
end
|
|
363
374
|
|
|
@@ -382,7 +393,7 @@ describe Mongoid::Interceptable do
|
|
|
382
393
|
describe ".before_destroy" do
|
|
383
394
|
|
|
384
395
|
let(:artist) do
|
|
385
|
-
Artist.create(name: "Depeche Mode")
|
|
396
|
+
Artist.create!(name: "Depeche Mode")
|
|
386
397
|
end
|
|
387
398
|
|
|
388
399
|
before do
|
|
@@ -427,7 +438,7 @@ describe Mongoid::Interceptable do
|
|
|
427
438
|
end
|
|
428
439
|
|
|
429
440
|
let!(:record) do
|
|
430
|
-
moderat.records.create(name: "Moderat")
|
|
441
|
+
moderat.records.create!(name: "Moderat")
|
|
431
442
|
end
|
|
432
443
|
|
|
433
444
|
before do
|
|
@@ -541,7 +552,7 @@ describe Mongoid::Interceptable do
|
|
|
541
552
|
|
|
542
553
|
it "does not cascade to the child" do
|
|
543
554
|
Band.accepts_nested_attributes_for :records, allow_destroy: true
|
|
544
|
-
expect(band.update_attributes(attributes)).to be true
|
|
555
|
+
expect(band.update_attributes!(attributes)).to be true
|
|
545
556
|
end
|
|
546
557
|
end
|
|
547
558
|
end
|
|
@@ -569,10 +580,24 @@ describe Mongoid::Interceptable do
|
|
|
569
580
|
end
|
|
570
581
|
|
|
571
582
|
context "when saving the root" do
|
|
583
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks enabled' do
|
|
584
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, true
|
|
585
|
+
config_override :around_callbacks_for_embeds, true
|
|
586
|
+
|
|
587
|
+
it "executes the callbacks only once for each document" do
|
|
588
|
+
expect(note).to receive(:update_saved).once
|
|
589
|
+
band.save!
|
|
590
|
+
end
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
context 'with prevent_multiple_calls_of_embedded_callbacks disabled' do
|
|
594
|
+
config_override :prevent_multiple_calls_of_embedded_callbacks, false
|
|
595
|
+
config_override :around_callbacks_for_embeds, true
|
|
572
596
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
597
|
+
it "executes the callbacks once for each ember" do
|
|
598
|
+
expect(note).to receive(:update_saved).twice
|
|
599
|
+
band.save!
|
|
600
|
+
end
|
|
576
601
|
end
|
|
577
602
|
end
|
|
578
603
|
end
|
|
@@ -581,7 +606,7 @@ describe Mongoid::Interceptable do
|
|
|
581
606
|
context "when cascading after initialize" do
|
|
582
607
|
|
|
583
608
|
let!(:person) do
|
|
584
|
-
Person.create
|
|
609
|
+
Person.create!
|
|
585
610
|
end
|
|
586
611
|
|
|
587
612
|
before do
|
|
@@ -620,7 +645,7 @@ describe Mongoid::Interceptable do
|
|
|
620
645
|
end
|
|
621
646
|
|
|
622
647
|
before do
|
|
623
|
-
band.save
|
|
648
|
+
band.save!
|
|
624
649
|
end
|
|
625
650
|
|
|
626
651
|
it "executes the callback" do
|
|
@@ -631,7 +656,7 @@ describe Mongoid::Interceptable do
|
|
|
631
656
|
context "when the parent is persisted" do
|
|
632
657
|
|
|
633
658
|
let(:band) do
|
|
634
|
-
Band.create(name: "Moderat")
|
|
659
|
+
Band.create!(name: "Moderat")
|
|
635
660
|
end
|
|
636
661
|
|
|
637
662
|
let!(:label) do
|
|
@@ -639,7 +664,7 @@ describe Mongoid::Interceptable do
|
|
|
639
664
|
end
|
|
640
665
|
|
|
641
666
|
before do
|
|
642
|
-
band.save
|
|
667
|
+
band.save!
|
|
643
668
|
end
|
|
644
669
|
|
|
645
670
|
it "executes the callback" do
|
|
@@ -651,7 +676,7 @@ describe Mongoid::Interceptable do
|
|
|
651
676
|
context "when the child is persisted" do
|
|
652
677
|
|
|
653
678
|
let(:band) do
|
|
654
|
-
Band.create(name: "Moderat")
|
|
679
|
+
Band.create!(name: "Moderat")
|
|
655
680
|
end
|
|
656
681
|
|
|
657
682
|
let!(:label) do
|
|
@@ -660,7 +685,7 @@ describe Mongoid::Interceptable do
|
|
|
660
685
|
|
|
661
686
|
before do
|
|
662
687
|
label.after_create_called = false
|
|
663
|
-
band.save
|
|
688
|
+
band.save!
|
|
664
689
|
end
|
|
665
690
|
|
|
666
691
|
it "does not execute the callback" do
|
|
@@ -684,7 +709,7 @@ describe Mongoid::Interceptable do
|
|
|
684
709
|
end
|
|
685
710
|
|
|
686
711
|
before do
|
|
687
|
-
band.save
|
|
712
|
+
band.save!
|
|
688
713
|
end
|
|
689
714
|
|
|
690
715
|
it "executes the callback" do
|
|
@@ -695,7 +720,7 @@ describe Mongoid::Interceptable do
|
|
|
695
720
|
context "when the parent is persisted" do
|
|
696
721
|
|
|
697
722
|
let(:band) do
|
|
698
|
-
Band.create(name: "Moderat")
|
|
723
|
+
Band.create!(name: "Moderat")
|
|
699
724
|
end
|
|
700
725
|
|
|
701
726
|
let!(:label) do
|
|
@@ -703,7 +728,7 @@ describe Mongoid::Interceptable do
|
|
|
703
728
|
end
|
|
704
729
|
|
|
705
730
|
before do
|
|
706
|
-
band.save
|
|
731
|
+
band.save!
|
|
707
732
|
end
|
|
708
733
|
|
|
709
734
|
it "executes the callback" do
|
|
@@ -715,7 +740,7 @@ describe Mongoid::Interceptable do
|
|
|
715
740
|
context "when the child is persisted" do
|
|
716
741
|
|
|
717
742
|
let(:band) do
|
|
718
|
-
Band.create(name: "Moderat")
|
|
743
|
+
Band.create!(name: "Moderat")
|
|
719
744
|
end
|
|
720
745
|
|
|
721
746
|
let!(:label) do
|
|
@@ -723,7 +748,7 @@ describe Mongoid::Interceptable do
|
|
|
723
748
|
end
|
|
724
749
|
|
|
725
750
|
before do
|
|
726
|
-
band.save
|
|
751
|
+
band.save!
|
|
727
752
|
end
|
|
728
753
|
|
|
729
754
|
it "executes the callback" do
|
|
@@ -747,7 +772,7 @@ describe Mongoid::Interceptable do
|
|
|
747
772
|
end
|
|
748
773
|
|
|
749
774
|
before do
|
|
750
|
-
band.save
|
|
775
|
+
band.save!
|
|
751
776
|
end
|
|
752
777
|
|
|
753
778
|
it "does not execute the callback" do
|
|
@@ -758,7 +783,7 @@ describe Mongoid::Interceptable do
|
|
|
758
783
|
context "when the parent is persisted" do
|
|
759
784
|
|
|
760
785
|
let(:band) do
|
|
761
|
-
Band.create(name: "Moderat")
|
|
786
|
+
Band.create!(name: "Moderat")
|
|
762
787
|
end
|
|
763
788
|
|
|
764
789
|
let!(:label) do
|
|
@@ -766,7 +791,7 @@ describe Mongoid::Interceptable do
|
|
|
766
791
|
end
|
|
767
792
|
|
|
768
793
|
before do
|
|
769
|
-
band.save
|
|
794
|
+
band.save!
|
|
770
795
|
end
|
|
771
796
|
|
|
772
797
|
it "does not execute the callback" do
|
|
@@ -778,7 +803,7 @@ describe Mongoid::Interceptable do
|
|
|
778
803
|
context "when the child is persisted" do
|
|
779
804
|
|
|
780
805
|
let(:band) do
|
|
781
|
-
Band.create(name: "Moderat")
|
|
806
|
+
Band.create!(name: "Moderat")
|
|
782
807
|
end
|
|
783
808
|
|
|
784
809
|
context "when the child is dirty" do
|
|
@@ -789,7 +814,7 @@ describe Mongoid::Interceptable do
|
|
|
789
814
|
|
|
790
815
|
before do
|
|
791
816
|
label.name = "Nothing"
|
|
792
|
-
band.save
|
|
817
|
+
band.save!
|
|
793
818
|
end
|
|
794
819
|
|
|
795
820
|
it "executes the callback" do
|
|
@@ -804,7 +829,7 @@ describe Mongoid::Interceptable do
|
|
|
804
829
|
end
|
|
805
830
|
|
|
806
831
|
before do
|
|
807
|
-
band.save
|
|
832
|
+
band.save!
|
|
808
833
|
end
|
|
809
834
|
|
|
810
835
|
it "does not execute the callback" do
|
|
@@ -829,7 +854,7 @@ describe Mongoid::Interceptable do
|
|
|
829
854
|
end
|
|
830
855
|
|
|
831
856
|
before do
|
|
832
|
-
band.save
|
|
857
|
+
band.save!
|
|
833
858
|
end
|
|
834
859
|
|
|
835
860
|
it "executes the callback" do
|
|
@@ -840,7 +865,7 @@ describe Mongoid::Interceptable do
|
|
|
840
865
|
context "when the parent is persisted" do
|
|
841
866
|
|
|
842
867
|
let(:band) do
|
|
843
|
-
Band.create(name: "Moderat")
|
|
868
|
+
Band.create!(name: "Moderat")
|
|
844
869
|
end
|
|
845
870
|
|
|
846
871
|
let!(:label) do
|
|
@@ -848,7 +873,7 @@ describe Mongoid::Interceptable do
|
|
|
848
873
|
end
|
|
849
874
|
|
|
850
875
|
before do
|
|
851
|
-
band.save
|
|
876
|
+
band.save!
|
|
852
877
|
end
|
|
853
878
|
|
|
854
879
|
it "executes the callback" do
|
|
@@ -860,7 +885,7 @@ describe Mongoid::Interceptable do
|
|
|
860
885
|
context "when the child is persisted" do
|
|
861
886
|
|
|
862
887
|
let(:band) do
|
|
863
|
-
Band.create(name: "Moderat")
|
|
888
|
+
Band.create!(name: "Moderat")
|
|
864
889
|
end
|
|
865
890
|
|
|
866
891
|
let!(:label) do
|
|
@@ -868,7 +893,7 @@ describe Mongoid::Interceptable do
|
|
|
868
893
|
end
|
|
869
894
|
|
|
870
895
|
before do
|
|
871
|
-
band.save
|
|
896
|
+
band.save!
|
|
872
897
|
end
|
|
873
898
|
|
|
874
899
|
it "executes the callback" do
|
|
@@ -892,7 +917,7 @@ describe Mongoid::Interceptable do
|
|
|
892
917
|
end
|
|
893
918
|
|
|
894
919
|
before do
|
|
895
|
-
band.save
|
|
920
|
+
band.save!
|
|
896
921
|
end
|
|
897
922
|
|
|
898
923
|
it "executes the callback" do
|
|
@@ -903,7 +928,7 @@ describe Mongoid::Interceptable do
|
|
|
903
928
|
context "when the parent is persisted" do
|
|
904
929
|
|
|
905
930
|
let(:band) do
|
|
906
|
-
Band.create(name: "Moderat")
|
|
931
|
+
Band.create!(name: "Moderat")
|
|
907
932
|
end
|
|
908
933
|
|
|
909
934
|
let!(:record) do
|
|
@@ -911,7 +936,7 @@ describe Mongoid::Interceptable do
|
|
|
911
936
|
end
|
|
912
937
|
|
|
913
938
|
before do
|
|
914
|
-
band.save
|
|
939
|
+
band.save!
|
|
915
940
|
end
|
|
916
941
|
|
|
917
942
|
it "executes the callback" do
|
|
@@ -923,16 +948,16 @@ describe Mongoid::Interceptable do
|
|
|
923
948
|
context "when the child is persisted" do
|
|
924
949
|
|
|
925
950
|
let(:band) do
|
|
926
|
-
Band.create(name: "Moderat")
|
|
951
|
+
Band.create!(name: "Moderat")
|
|
927
952
|
end
|
|
928
953
|
|
|
929
954
|
let!(:record) do
|
|
930
|
-
band.records.create(name: "Moderat")
|
|
955
|
+
band.records.create!(name: "Moderat")
|
|
931
956
|
end
|
|
932
957
|
|
|
933
958
|
before do
|
|
934
959
|
record.before_create_called = false
|
|
935
|
-
band.save
|
|
960
|
+
band.save!
|
|
936
961
|
end
|
|
937
962
|
|
|
938
963
|
it "does not execute the callback" do
|
|
@@ -956,7 +981,7 @@ describe Mongoid::Interceptable do
|
|
|
956
981
|
end
|
|
957
982
|
|
|
958
983
|
before do
|
|
959
|
-
band.save
|
|
984
|
+
band.save!
|
|
960
985
|
end
|
|
961
986
|
|
|
962
987
|
it "executes the callback" do
|
|
@@ -971,7 +996,7 @@ describe Mongoid::Interceptable do
|
|
|
971
996
|
context "when the parent is persisted" do
|
|
972
997
|
|
|
973
998
|
let(:band) do
|
|
974
|
-
Band.create(name: "Moderat")
|
|
999
|
+
Band.create!(name: "Moderat")
|
|
975
1000
|
end
|
|
976
1001
|
|
|
977
1002
|
let!(:record) do
|
|
@@ -979,7 +1004,7 @@ describe Mongoid::Interceptable do
|
|
|
979
1004
|
end
|
|
980
1005
|
|
|
981
1006
|
before do
|
|
982
|
-
band.save
|
|
1007
|
+
band.save!
|
|
983
1008
|
end
|
|
984
1009
|
|
|
985
1010
|
it "executes the callback" do
|
|
@@ -995,15 +1020,15 @@ describe Mongoid::Interceptable do
|
|
|
995
1020
|
context "when the child is persisted" do
|
|
996
1021
|
|
|
997
1022
|
let(:band) do
|
|
998
|
-
Band.create(name: "Moderat")
|
|
1023
|
+
Band.create!(name: "Moderat")
|
|
999
1024
|
end
|
|
1000
1025
|
|
|
1001
1026
|
let!(:record) do
|
|
1002
|
-
band.records.create(name: "Moderat")
|
|
1027
|
+
band.records.create!(name: "Moderat")
|
|
1003
1028
|
end
|
|
1004
1029
|
|
|
1005
1030
|
before do
|
|
1006
|
-
band.save
|
|
1031
|
+
band.save!
|
|
1007
1032
|
end
|
|
1008
1033
|
|
|
1009
1034
|
it "executes the callback" do
|
|
@@ -1018,7 +1043,7 @@ describe Mongoid::Interceptable do
|
|
|
1018
1043
|
context "when the child is created" do
|
|
1019
1044
|
|
|
1020
1045
|
let!(:band) do
|
|
1021
|
-
Band.create
|
|
1046
|
+
Band.create!
|
|
1022
1047
|
end
|
|
1023
1048
|
|
|
1024
1049
|
let!(:label) do
|
|
@@ -1046,7 +1071,7 @@ describe Mongoid::Interceptable do
|
|
|
1046
1071
|
end
|
|
1047
1072
|
|
|
1048
1073
|
before do
|
|
1049
|
-
band.save
|
|
1074
|
+
band.save!
|
|
1050
1075
|
end
|
|
1051
1076
|
|
|
1052
1077
|
it "does not execute the callback" do
|
|
@@ -1057,7 +1082,7 @@ describe Mongoid::Interceptable do
|
|
|
1057
1082
|
context "when the parent is persisted" do
|
|
1058
1083
|
|
|
1059
1084
|
let(:band) do
|
|
1060
|
-
Band.create(name: "Moderat")
|
|
1085
|
+
Band.create!(name: "Moderat")
|
|
1061
1086
|
end
|
|
1062
1087
|
|
|
1063
1088
|
let!(:record) do
|
|
@@ -1065,7 +1090,7 @@ describe Mongoid::Interceptable do
|
|
|
1065
1090
|
end
|
|
1066
1091
|
|
|
1067
1092
|
before do
|
|
1068
|
-
band.save
|
|
1093
|
+
band.save!
|
|
1069
1094
|
end
|
|
1070
1095
|
|
|
1071
1096
|
it "does not execute the callback" do
|
|
@@ -1077,18 +1102,18 @@ describe Mongoid::Interceptable do
|
|
|
1077
1102
|
context "when the child is persisted" do
|
|
1078
1103
|
|
|
1079
1104
|
let(:band) do
|
|
1080
|
-
Band.create(name: "Moderat")
|
|
1105
|
+
Band.create!(name: "Moderat")
|
|
1081
1106
|
end
|
|
1082
1107
|
|
|
1083
1108
|
let!(:record) do
|
|
1084
|
-
band.records.create(name: "Moderat")
|
|
1109
|
+
band.records.create!(name: "Moderat")
|
|
1085
1110
|
end
|
|
1086
1111
|
|
|
1087
1112
|
context "when the child is dirty" do
|
|
1088
1113
|
|
|
1089
1114
|
before do
|
|
1090
1115
|
record.name = "Nothing"
|
|
1091
|
-
band.save
|
|
1116
|
+
band.save!
|
|
1092
1117
|
end
|
|
1093
1118
|
|
|
1094
1119
|
it "executes the callback" do
|
|
@@ -1103,7 +1128,7 @@ describe Mongoid::Interceptable do
|
|
|
1103
1128
|
context "when the child is not dirty" do
|
|
1104
1129
|
|
|
1105
1130
|
before do
|
|
1106
|
-
band.save
|
|
1131
|
+
band.save!
|
|
1107
1132
|
end
|
|
1108
1133
|
|
|
1109
1134
|
it "does not execute the callback" do
|
|
@@ -1128,7 +1153,7 @@ describe Mongoid::Interceptable do
|
|
|
1128
1153
|
end
|
|
1129
1154
|
|
|
1130
1155
|
before do
|
|
1131
|
-
band.save
|
|
1156
|
+
band.save!
|
|
1132
1157
|
end
|
|
1133
1158
|
|
|
1134
1159
|
it "executes the callback" do
|
|
@@ -1143,7 +1168,7 @@ describe Mongoid::Interceptable do
|
|
|
1143
1168
|
context "when the parent is persisted" do
|
|
1144
1169
|
|
|
1145
1170
|
let(:band) do
|
|
1146
|
-
Band.create(name: "Moderat")
|
|
1171
|
+
Band.create!(name: "Moderat")
|
|
1147
1172
|
end
|
|
1148
1173
|
|
|
1149
1174
|
let!(:record) do
|
|
@@ -1151,7 +1176,7 @@ describe Mongoid::Interceptable do
|
|
|
1151
1176
|
end
|
|
1152
1177
|
|
|
1153
1178
|
before do
|
|
1154
|
-
band.save
|
|
1179
|
+
band.save!
|
|
1155
1180
|
end
|
|
1156
1181
|
|
|
1157
1182
|
it "executes the callback" do
|
|
@@ -1166,7 +1191,7 @@ describe Mongoid::Interceptable do
|
|
|
1166
1191
|
context 'when the parent is updated' do
|
|
1167
1192
|
|
|
1168
1193
|
let(:band) do
|
|
1169
|
-
Band.create(name: "Moderat")
|
|
1194
|
+
Band.create!(name: "Moderat")
|
|
1170
1195
|
end
|
|
1171
1196
|
|
|
1172
1197
|
before do
|
|
@@ -1186,7 +1211,7 @@ describe Mongoid::Interceptable do
|
|
|
1186
1211
|
context 'when the parent is updated' do
|
|
1187
1212
|
|
|
1188
1213
|
let(:band) do
|
|
1189
|
-
Band.create(name: "Moderat")
|
|
1214
|
+
Band.create!(name: "Moderat")
|
|
1190
1215
|
end
|
|
1191
1216
|
|
|
1192
1217
|
before do
|
|
@@ -1205,15 +1230,15 @@ describe Mongoid::Interceptable do
|
|
|
1205
1230
|
context "when the child is persisted" do
|
|
1206
1231
|
|
|
1207
1232
|
let(:band) do
|
|
1208
|
-
Band.create(name: "Moderat")
|
|
1233
|
+
Band.create!(name: "Moderat")
|
|
1209
1234
|
end
|
|
1210
1235
|
|
|
1211
1236
|
let!(:record) do
|
|
1212
|
-
band.records.create(name: "Moderat")
|
|
1237
|
+
band.records.create!(name: "Moderat")
|
|
1213
1238
|
end
|
|
1214
1239
|
|
|
1215
1240
|
before do
|
|
1216
|
-
band.save
|
|
1241
|
+
band.save!
|
|
1217
1242
|
end
|
|
1218
1243
|
|
|
1219
1244
|
it "executes the callback" do
|
|
@@ -1248,7 +1273,7 @@ describe Mongoid::Interceptable do
|
|
|
1248
1273
|
end
|
|
1249
1274
|
|
|
1250
1275
|
before do
|
|
1251
|
-
band.save
|
|
1276
|
+
band.save!
|
|
1252
1277
|
end
|
|
1253
1278
|
|
|
1254
1279
|
it "executes the callback" do
|
|
@@ -1259,7 +1284,7 @@ describe Mongoid::Interceptable do
|
|
|
1259
1284
|
context "when the root is persisted" do
|
|
1260
1285
|
|
|
1261
1286
|
let(:band) do
|
|
1262
|
-
Band.create(name: "Moderat")
|
|
1287
|
+
Band.create!(name: "Moderat")
|
|
1263
1288
|
end
|
|
1264
1289
|
|
|
1265
1290
|
let!(:record) do
|
|
@@ -1271,7 +1296,7 @@ describe Mongoid::Interceptable do
|
|
|
1271
1296
|
end
|
|
1272
1297
|
|
|
1273
1298
|
before do
|
|
1274
|
-
band.save
|
|
1299
|
+
band.save!
|
|
1275
1300
|
end
|
|
1276
1301
|
|
|
1277
1302
|
it "executes the callback" do
|
|
@@ -1283,20 +1308,20 @@ describe Mongoid::Interceptable do
|
|
|
1283
1308
|
context "when the child is persisted" do
|
|
1284
1309
|
|
|
1285
1310
|
let(:band) do
|
|
1286
|
-
Band.create(name: "Moderat")
|
|
1311
|
+
Band.create!(name: "Moderat")
|
|
1287
1312
|
end
|
|
1288
1313
|
|
|
1289
1314
|
let!(:record) do
|
|
1290
|
-
band.records.create(name: "Moderat")
|
|
1315
|
+
band.records.create!(name: "Moderat")
|
|
1291
1316
|
end
|
|
1292
1317
|
|
|
1293
1318
|
let!(:track) do
|
|
1294
|
-
record.tracks.create(name: "Berlin")
|
|
1319
|
+
record.tracks.create!(name: "Berlin")
|
|
1295
1320
|
end
|
|
1296
1321
|
|
|
1297
1322
|
before do
|
|
1298
1323
|
track.before_create_called = false
|
|
1299
|
-
band.save
|
|
1324
|
+
band.save!
|
|
1300
1325
|
end
|
|
1301
1326
|
|
|
1302
1327
|
it "does not execute the callback" do
|
|
@@ -1324,7 +1349,7 @@ describe Mongoid::Interceptable do
|
|
|
1324
1349
|
end
|
|
1325
1350
|
|
|
1326
1351
|
before do
|
|
1327
|
-
band.save
|
|
1352
|
+
band.save!
|
|
1328
1353
|
end
|
|
1329
1354
|
|
|
1330
1355
|
let(:reloaded) do
|
|
@@ -1343,7 +1368,7 @@ describe Mongoid::Interceptable do
|
|
|
1343
1368
|
context "when the parent is persisted" do
|
|
1344
1369
|
|
|
1345
1370
|
let(:band) do
|
|
1346
|
-
Band.create(name: "Moderat")
|
|
1371
|
+
Band.create!(name: "Moderat")
|
|
1347
1372
|
end
|
|
1348
1373
|
|
|
1349
1374
|
let!(:record) do
|
|
@@ -1355,7 +1380,7 @@ describe Mongoid::Interceptable do
|
|
|
1355
1380
|
end
|
|
1356
1381
|
|
|
1357
1382
|
before do
|
|
1358
|
-
band.save
|
|
1383
|
+
band.save!
|
|
1359
1384
|
end
|
|
1360
1385
|
|
|
1361
1386
|
let(:reloaded) do
|
|
@@ -1375,19 +1400,19 @@ describe Mongoid::Interceptable do
|
|
|
1375
1400
|
context "when the child is persisted" do
|
|
1376
1401
|
|
|
1377
1402
|
let(:band) do
|
|
1378
|
-
Band.create(name: "Moderat")
|
|
1403
|
+
Band.create!(name: "Moderat")
|
|
1379
1404
|
end
|
|
1380
1405
|
|
|
1381
1406
|
let!(:record) do
|
|
1382
|
-
band.records.create(name: "Moderat")
|
|
1407
|
+
band.records.create!(name: "Moderat")
|
|
1383
1408
|
end
|
|
1384
1409
|
|
|
1385
1410
|
let!(:track) do
|
|
1386
|
-
record.tracks.create(name: "Berlin")
|
|
1411
|
+
record.tracks.create!(name: "Berlin")
|
|
1387
1412
|
end
|
|
1388
1413
|
|
|
1389
1414
|
before do
|
|
1390
|
-
band.save
|
|
1415
|
+
band.save!
|
|
1391
1416
|
end
|
|
1392
1417
|
|
|
1393
1418
|
let(:reloaded) do
|
|
@@ -1423,7 +1448,7 @@ describe Mongoid::Interceptable do
|
|
|
1423
1448
|
end
|
|
1424
1449
|
|
|
1425
1450
|
before do
|
|
1426
|
-
band.save
|
|
1451
|
+
band.save!
|
|
1427
1452
|
end
|
|
1428
1453
|
|
|
1429
1454
|
it "does not execute the callback" do
|
|
@@ -1434,7 +1459,7 @@ describe Mongoid::Interceptable do
|
|
|
1434
1459
|
context "when the parent is persisted" do
|
|
1435
1460
|
|
|
1436
1461
|
let(:band) do
|
|
1437
|
-
Band.create(name: "Moderat")
|
|
1462
|
+
Band.create!(name: "Moderat")
|
|
1438
1463
|
end
|
|
1439
1464
|
|
|
1440
1465
|
let!(:record) do
|
|
@@ -1446,7 +1471,7 @@ describe Mongoid::Interceptable do
|
|
|
1446
1471
|
end
|
|
1447
1472
|
|
|
1448
1473
|
before do
|
|
1449
|
-
band.save
|
|
1474
|
+
band.save!
|
|
1450
1475
|
end
|
|
1451
1476
|
|
|
1452
1477
|
it "does not execute the callback" do
|
|
@@ -1458,22 +1483,22 @@ describe Mongoid::Interceptable do
|
|
|
1458
1483
|
context "when the child is persisted" do
|
|
1459
1484
|
|
|
1460
1485
|
let(:band) do
|
|
1461
|
-
Band.create(name: "Moderat")
|
|
1486
|
+
Band.create!(name: "Moderat")
|
|
1462
1487
|
end
|
|
1463
1488
|
|
|
1464
1489
|
let!(:record) do
|
|
1465
|
-
band.records.create(name: "Moderat")
|
|
1490
|
+
band.records.create!(name: "Moderat")
|
|
1466
1491
|
end
|
|
1467
1492
|
|
|
1468
1493
|
let!(:track) do
|
|
1469
|
-
record.tracks.create(name: "Berlin")
|
|
1494
|
+
record.tracks.create!(name: "Berlin")
|
|
1470
1495
|
end
|
|
1471
1496
|
|
|
1472
1497
|
context "when the child is dirty" do
|
|
1473
1498
|
|
|
1474
1499
|
before do
|
|
1475
1500
|
track.name = "Rusty Nails"
|
|
1476
|
-
band.save
|
|
1501
|
+
band.save!
|
|
1477
1502
|
end
|
|
1478
1503
|
|
|
1479
1504
|
let(:reloaded) do
|
|
@@ -1492,7 +1517,7 @@ describe Mongoid::Interceptable do
|
|
|
1492
1517
|
context "when the child is not dirty" do
|
|
1493
1518
|
|
|
1494
1519
|
before do
|
|
1495
|
-
band.save
|
|
1520
|
+
band.save!
|
|
1496
1521
|
end
|
|
1497
1522
|
|
|
1498
1523
|
it "does not execute the callback" do
|
|
@@ -1540,7 +1565,7 @@ describe Mongoid::Interceptable do
|
|
|
1540
1565
|
end
|
|
1541
1566
|
|
|
1542
1567
|
before do
|
|
1543
|
-
band.save
|
|
1568
|
+
band.save!
|
|
1544
1569
|
end
|
|
1545
1570
|
|
|
1546
1571
|
it "executes the callback" do
|
|
@@ -1551,7 +1576,7 @@ describe Mongoid::Interceptable do
|
|
|
1551
1576
|
context "when the parent is persisted" do
|
|
1552
1577
|
|
|
1553
1578
|
let(:band) do
|
|
1554
|
-
Band.create(name: "Moderat")
|
|
1579
|
+
Band.create!(name: "Moderat")
|
|
1555
1580
|
end
|
|
1556
1581
|
|
|
1557
1582
|
let!(:record) do
|
|
@@ -1563,7 +1588,7 @@ describe Mongoid::Interceptable do
|
|
|
1563
1588
|
end
|
|
1564
1589
|
|
|
1565
1590
|
before do
|
|
1566
|
-
band.save
|
|
1591
|
+
band.save!
|
|
1567
1592
|
end
|
|
1568
1593
|
|
|
1569
1594
|
it "executes the callback" do
|
|
@@ -1575,19 +1600,19 @@ describe Mongoid::Interceptable do
|
|
|
1575
1600
|
context "when the child is persisted" do
|
|
1576
1601
|
|
|
1577
1602
|
let(:band) do
|
|
1578
|
-
Band.create(name: "Moderat")
|
|
1603
|
+
Band.create!(name: "Moderat")
|
|
1579
1604
|
end
|
|
1580
1605
|
|
|
1581
1606
|
let!(:record) do
|
|
1582
|
-
band.records.create(name: "Moderat")
|
|
1607
|
+
band.records.create!(name: "Moderat")
|
|
1583
1608
|
end
|
|
1584
1609
|
|
|
1585
1610
|
let!(:track) do
|
|
1586
|
-
record.tracks.create(name: "Berlin")
|
|
1611
|
+
record.tracks.create!(name: "Berlin")
|
|
1587
1612
|
end
|
|
1588
1613
|
|
|
1589
1614
|
before do
|
|
1590
|
-
band.save
|
|
1615
|
+
band.save!
|
|
1591
1616
|
end
|
|
1592
1617
|
|
|
1593
1618
|
it "executes the callback" do
|
|
@@ -1614,11 +1639,11 @@ describe Mongoid::Interceptable do
|
|
|
1614
1639
|
end
|
|
1615
1640
|
|
|
1616
1641
|
before do
|
|
1617
|
-
parent.save
|
|
1642
|
+
parent.save!
|
|
1618
1643
|
end
|
|
1619
1644
|
|
|
1620
1645
|
it "does not duplicate the child documents" do
|
|
1621
|
-
parent.children.create(position: 1)
|
|
1646
|
+
parent.children.create!(position: 1)
|
|
1622
1647
|
expect(ParentDoc.find(parent.id).children.size).to eq(1)
|
|
1623
1648
|
end
|
|
1624
1649
|
end
|
|
@@ -1669,7 +1694,7 @@ describe Mongoid::Interceptable do
|
|
|
1669
1694
|
context "when updating a document" do
|
|
1670
1695
|
|
|
1671
1696
|
let(:person) do
|
|
1672
|
-
Person.create
|
|
1697
|
+
Person.create!.tap do |person|
|
|
1673
1698
|
person.attributes = {
|
|
1674
1699
|
mode: :prevent_save,
|
|
1675
1700
|
title: "Associate",
|
|
@@ -1703,8 +1728,8 @@ describe Mongoid::Interceptable do
|
|
|
1703
1728
|
context "when loading a model multiple times" do
|
|
1704
1729
|
|
|
1705
1730
|
before do
|
|
1706
|
-
load "
|
|
1707
|
-
load "
|
|
1731
|
+
load File.join(MODELS, "callback_test.rb")
|
|
1732
|
+
load File.join(MODELS, "callback_test.rb")
|
|
1708
1733
|
end
|
|
1709
1734
|
|
|
1710
1735
|
let(:callback) do
|
|
@@ -1719,4 +1744,853 @@ describe Mongoid::Interceptable do
|
|
|
1719
1744
|
end
|
|
1720
1745
|
end
|
|
1721
1746
|
end
|
|
1747
|
+
|
|
1748
|
+
context 'when creating a parent and embedded child' do
|
|
1749
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1750
|
+
let(:parent) do
|
|
1751
|
+
InterceptableSpec::CbParent.new(registry).tap do |parent|
|
|
1752
|
+
parent.cb_children << InterceptableSpec::CbChild.new(registry, cb_parent: parent)
|
|
1753
|
+
end
|
|
1754
|
+
end
|
|
1755
|
+
|
|
1756
|
+
let(:expected) do
|
|
1757
|
+
[
|
|
1758
|
+
[InterceptableSpec::CbParent, :before_validation],
|
|
1759
|
+
[InterceptableSpec::CbChild, :before_validation],
|
|
1760
|
+
[InterceptableSpec::CbChild, :after_validation],
|
|
1761
|
+
[InterceptableSpec::CbParent, :after_validation],
|
|
1762
|
+
[InterceptableSpec::CbParent, :before_save],
|
|
1763
|
+
[InterceptableSpec::CbParent, :around_save_open],
|
|
1764
|
+
[InterceptableSpec::CbParent, :before_create],
|
|
1765
|
+
[InterceptableSpec::CbParent, :around_create_open],
|
|
1766
|
+
[InterceptableSpec::CbParent, :around_create_close],
|
|
1767
|
+
[InterceptableSpec::CbParent, :after_create],
|
|
1768
|
+
[InterceptableSpec::CbParent, :around_save_close],
|
|
1769
|
+
[InterceptableSpec::CbParent, :after_save],
|
|
1770
|
+
]
|
|
1771
|
+
end
|
|
1772
|
+
|
|
1773
|
+
it 'calls callbacks in the right order' do
|
|
1774
|
+
parent.save!
|
|
1775
|
+
expect(registry.calls).to eq expected
|
|
1776
|
+
end
|
|
1777
|
+
end
|
|
1778
|
+
|
|
1779
|
+
context 'when creating a parent and embedded child with cascading callbacks' do
|
|
1780
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1781
|
+
let(:parent) do
|
|
1782
|
+
InterceptableSpec::CbParent.new(registry).tap do |parent|
|
|
1783
|
+
parent.cb_cascaded_children <<
|
|
1784
|
+
InterceptableSpec::CbCascadedChild.new(registry, cb_parent: parent)
|
|
1785
|
+
end
|
|
1786
|
+
end
|
|
1787
|
+
|
|
1788
|
+
context 'with around callbacks' do
|
|
1789
|
+
config_override :around_callbacks_for_embeds, true
|
|
1790
|
+
|
|
1791
|
+
let(:expected) do
|
|
1792
|
+
[
|
|
1793
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
|
1794
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
|
1795
|
+
[InterceptableSpec::CbParent, :before_validation],
|
|
1796
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
|
1797
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
|
1798
|
+
|
|
1799
|
+
[InterceptableSpec::CbParent, :after_validation],
|
|
1800
|
+
[InterceptableSpec::CbParent, :before_save],
|
|
1801
|
+
[InterceptableSpec::CbParent, :around_save_open],
|
|
1802
|
+
[InterceptableSpec::CbParent, :before_create],
|
|
1803
|
+
[InterceptableSpec::CbParent, :around_create_open],
|
|
1804
|
+
|
|
1805
|
+
[InterceptableSpec::CbCascadedChild, :before_save],
|
|
1806
|
+
[InterceptableSpec::CbCascadedChild, :around_save_open],
|
|
1807
|
+
[InterceptableSpec::CbCascadedChild, :before_create],
|
|
1808
|
+
[InterceptableSpec::CbCascadedChild, :around_create_open],
|
|
1809
|
+
|
|
1810
|
+
[InterceptableSpec::CbCascadedChild, :around_create_close],
|
|
1811
|
+
[InterceptableSpec::CbCascadedChild, :after_create],
|
|
1812
|
+
[InterceptableSpec::CbCascadedChild, :around_save_close],
|
|
1813
|
+
[InterceptableSpec::CbCascadedChild, :after_save],
|
|
1814
|
+
|
|
1815
|
+
[InterceptableSpec::CbParent, :around_create_close],
|
|
1816
|
+
[InterceptableSpec::CbParent, :after_create],
|
|
1817
|
+
[InterceptableSpec::CbParent, :around_save_close],
|
|
1818
|
+
[InterceptableSpec::CbParent, :after_save]
|
|
1819
|
+
]
|
|
1820
|
+
end
|
|
1821
|
+
|
|
1822
|
+
it 'calls callbacks in the right order' do
|
|
1823
|
+
parent.save!
|
|
1824
|
+
expect(registry.calls).to eq expected
|
|
1825
|
+
end
|
|
1826
|
+
end
|
|
1827
|
+
|
|
1828
|
+
context 'without around callbacks' do
|
|
1829
|
+
config_override :around_callbacks_for_embeds, false
|
|
1830
|
+
|
|
1831
|
+
let(:expected) do
|
|
1832
|
+
[
|
|
1833
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
|
1834
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
|
1835
|
+
[InterceptableSpec::CbParent, :before_validation],
|
|
1836
|
+
[InterceptableSpec::CbCascadedChild, :before_validation],
|
|
1837
|
+
[InterceptableSpec::CbCascadedChild, :after_validation],
|
|
1838
|
+
|
|
1839
|
+
[InterceptableSpec::CbParent, :after_validation],
|
|
1840
|
+
[InterceptableSpec::CbParent, :before_save],
|
|
1841
|
+
[InterceptableSpec::CbParent, :around_save_open],
|
|
1842
|
+
[InterceptableSpec::CbParent, :before_create],
|
|
1843
|
+
[InterceptableSpec::CbParent, :around_create_open],
|
|
1844
|
+
|
|
1845
|
+
[InterceptableSpec::CbCascadedChild, :before_save],
|
|
1846
|
+
[InterceptableSpec::CbCascadedChild, :before_create],
|
|
1847
|
+
|
|
1848
|
+
[InterceptableSpec::CbCascadedChild, :after_create],
|
|
1849
|
+
[InterceptableSpec::CbCascadedChild, :after_save],
|
|
1850
|
+
|
|
1851
|
+
[InterceptableSpec::CbParent, :around_create_close],
|
|
1852
|
+
[InterceptableSpec::CbParent, :after_create],
|
|
1853
|
+
[InterceptableSpec::CbParent, :around_save_close],
|
|
1854
|
+
[InterceptableSpec::CbParent, :after_save]
|
|
1855
|
+
]
|
|
1856
|
+
end
|
|
1857
|
+
|
|
1858
|
+
it 'calls callbacks in the right order' do
|
|
1859
|
+
parent.save!
|
|
1860
|
+
expect(registry.calls).to eq expected
|
|
1861
|
+
end
|
|
1862
|
+
end
|
|
1863
|
+
end
|
|
1864
|
+
|
|
1865
|
+
context "with associations" do
|
|
1866
|
+
context "has_one" do
|
|
1867
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1868
|
+
|
|
1869
|
+
let(:parent) do
|
|
1870
|
+
InterceptableSpec::CbHasOneParent.new(registry).tap do |parent|
|
|
1871
|
+
parent.child = InterceptableSpec::CbHasOneChild.new(registry)
|
|
1872
|
+
end
|
|
1873
|
+
end
|
|
1874
|
+
|
|
1875
|
+
let(:expected) do
|
|
1876
|
+
[
|
|
1877
|
+
[InterceptableSpec::CbHasOneParent, :before_validation],
|
|
1878
|
+
[InterceptableSpec::CbHasOneChild, :before_validation],
|
|
1879
|
+
[InterceptableSpec::CbHasOneChild, :after_validation],
|
|
1880
|
+
[InterceptableSpec::CbHasOneParent, :after_validation],
|
|
1881
|
+
[InterceptableSpec::CbHasOneParent, :before_save],
|
|
1882
|
+
|
|
1883
|
+
[InterceptableSpec::CbHasOneParent, :around_save_open],
|
|
1884
|
+
[InterceptableSpec::CbHasOneParent, :before_create],
|
|
1885
|
+
[InterceptableSpec::CbHasOneParent, :around_create_open],
|
|
1886
|
+
|
|
1887
|
+
[InterceptableSpec::CbHasOneParent, :insert_into_database],
|
|
1888
|
+
|
|
1889
|
+
[InterceptableSpec::CbHasOneChild, :before_validation],
|
|
1890
|
+
[InterceptableSpec::CbHasOneChild, :after_validation],
|
|
1891
|
+
[InterceptableSpec::CbHasOneChild, :before_save],
|
|
1892
|
+
[InterceptableSpec::CbHasOneChild, :around_save_open],
|
|
1893
|
+
[InterceptableSpec::CbHasOneChild, :before_create],
|
|
1894
|
+
[InterceptableSpec::CbHasOneChild, :around_create_open],
|
|
1895
|
+
|
|
1896
|
+
[InterceptableSpec::CbHasOneChild, :around_create_close],
|
|
1897
|
+
[InterceptableSpec::CbHasOneChild, :after_create],
|
|
1898
|
+
[InterceptableSpec::CbHasOneChild, :around_save_close],
|
|
1899
|
+
[InterceptableSpec::CbHasOneChild, :after_save],
|
|
1900
|
+
|
|
1901
|
+
[InterceptableSpec::CbHasOneParent, :around_create_close],
|
|
1902
|
+
[InterceptableSpec::CbHasOneParent, :after_create],
|
|
1903
|
+
[InterceptableSpec::CbHasOneParent, :around_save_close],
|
|
1904
|
+
[InterceptableSpec::CbHasOneParent, :after_save],
|
|
1905
|
+
]
|
|
1906
|
+
end
|
|
1907
|
+
|
|
1908
|
+
it 'calls callbacks in the right order' do
|
|
1909
|
+
parent.save!
|
|
1910
|
+
expect(registry.calls).to eq expected
|
|
1911
|
+
end
|
|
1912
|
+
end
|
|
1913
|
+
|
|
1914
|
+
context "embeds_one" do
|
|
1915
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
1916
|
+
|
|
1917
|
+
let(:parent) do
|
|
1918
|
+
InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
|
|
1919
|
+
parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
|
|
1920
|
+
end
|
|
1921
|
+
end
|
|
1922
|
+
|
|
1923
|
+
context "create" do
|
|
1924
|
+
context "with around callbacks" do
|
|
1925
|
+
config_override :around_callbacks_for_embeds, true
|
|
1926
|
+
|
|
1927
|
+
let(:expected) do
|
|
1928
|
+
[
|
|
1929
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
1930
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
1931
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
|
1932
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
1933
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
1934
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
|
1935
|
+
|
|
1936
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
|
1937
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
|
1938
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_create],
|
|
1939
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_open],
|
|
1940
|
+
|
|
1941
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
|
1942
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_open],
|
|
1943
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_create],
|
|
1944
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_create_open],
|
|
1945
|
+
|
|
1946
|
+
[InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
|
|
1947
|
+
|
|
1948
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_create_close],
|
|
1949
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_create],
|
|
1950
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_close],
|
|
1951
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
|
1952
|
+
|
|
1953
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_close],
|
|
1954
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_create],
|
|
1955
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
|
1956
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
|
1957
|
+
]
|
|
1958
|
+
end
|
|
1959
|
+
|
|
1960
|
+
it 'calls callbacks in the right order' do
|
|
1961
|
+
parent.save!
|
|
1962
|
+
expect(registry.calls).to eq expected
|
|
1963
|
+
end
|
|
1964
|
+
end
|
|
1965
|
+
|
|
1966
|
+
context "without around callbacks" do
|
|
1967
|
+
config_override :around_callbacks_for_embeds, false
|
|
1968
|
+
|
|
1969
|
+
let(:expected) do
|
|
1970
|
+
[
|
|
1971
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
1972
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
1973
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
|
1974
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
1975
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
1976
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
|
1977
|
+
|
|
1978
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
|
1979
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
|
1980
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_create],
|
|
1981
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_open],
|
|
1982
|
+
|
|
1983
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
|
1984
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_create],
|
|
1985
|
+
|
|
1986
|
+
[InterceptableSpec::CbEmbedsOneParent, :insert_into_database],
|
|
1987
|
+
|
|
1988
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_create],
|
|
1989
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
|
1990
|
+
|
|
1991
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_create_close],
|
|
1992
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_create],
|
|
1993
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
|
1994
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
|
1995
|
+
]
|
|
1996
|
+
end
|
|
1997
|
+
|
|
1998
|
+
it 'calls callbacks in the right order' do
|
|
1999
|
+
parent.save!
|
|
2000
|
+
expect(registry.calls).to eq expected
|
|
2001
|
+
end
|
|
2002
|
+
end
|
|
2003
|
+
end
|
|
2004
|
+
|
|
2005
|
+
context "update" do
|
|
2006
|
+
context "with around callbacks" do
|
|
2007
|
+
config_override :around_callbacks_for_embeds, true
|
|
2008
|
+
|
|
2009
|
+
let(:expected) do
|
|
2010
|
+
[
|
|
2011
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
2012
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
2013
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
|
2014
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
2015
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
2016
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
|
2017
|
+
|
|
2018
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
|
2019
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
|
2020
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_update],
|
|
2021
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_open],
|
|
2022
|
+
|
|
2023
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
|
2024
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_open],
|
|
2025
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_update],
|
|
2026
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_update_open],
|
|
2027
|
+
|
|
2028
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_update_close],
|
|
2029
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_update],
|
|
2030
|
+
[InterceptableSpec::CbEmbedsOneChild, :around_save_close],
|
|
2031
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
|
2032
|
+
|
|
2033
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_close],
|
|
2034
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_update],
|
|
2035
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
|
2036
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
|
2037
|
+
]
|
|
2038
|
+
end
|
|
2039
|
+
|
|
2040
|
+
it 'calls callbacks in the right order' do
|
|
2041
|
+
parent.callback_registry = nil
|
|
2042
|
+
parent.child.callback_registry = nil
|
|
2043
|
+
parent.save!
|
|
2044
|
+
|
|
2045
|
+
parent.callback_registry = registry
|
|
2046
|
+
parent.child.callback_registry = registry
|
|
2047
|
+
parent.name = "name"
|
|
2048
|
+
parent.child.age = 10
|
|
2049
|
+
|
|
2050
|
+
parent.save!
|
|
2051
|
+
expect(registry.calls).to eq expected
|
|
2052
|
+
end
|
|
2053
|
+
end
|
|
2054
|
+
|
|
2055
|
+
context "without around callbacks" do
|
|
2056
|
+
config_override :around_callbacks_for_embeds, false
|
|
2057
|
+
|
|
2058
|
+
let(:expected) do
|
|
2059
|
+
[
|
|
2060
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
2061
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
2062
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_validation],
|
|
2063
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_validation],
|
|
2064
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_validation],
|
|
2065
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_validation],
|
|
2066
|
+
|
|
2067
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_save],
|
|
2068
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_open],
|
|
2069
|
+
[InterceptableSpec::CbEmbedsOneParent, :before_update],
|
|
2070
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_open],
|
|
2071
|
+
|
|
2072
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_save],
|
|
2073
|
+
[InterceptableSpec::CbEmbedsOneChild, :before_update],
|
|
2074
|
+
|
|
2075
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_update],
|
|
2076
|
+
[InterceptableSpec::CbEmbedsOneChild, :after_save],
|
|
2077
|
+
|
|
2078
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_update_close],
|
|
2079
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_update],
|
|
2080
|
+
[InterceptableSpec::CbEmbedsOneParent, :around_save_close],
|
|
2081
|
+
[InterceptableSpec::CbEmbedsOneParent, :after_save]
|
|
2082
|
+
]
|
|
2083
|
+
end
|
|
2084
|
+
|
|
2085
|
+
it 'calls callbacks in the right order' do
|
|
2086
|
+
parent.callback_registry = nil
|
|
2087
|
+
parent.child.callback_registry = nil
|
|
2088
|
+
parent.save!
|
|
2089
|
+
|
|
2090
|
+
parent.callback_registry = registry
|
|
2091
|
+
parent.child.callback_registry = registry
|
|
2092
|
+
parent.name = "name"
|
|
2093
|
+
parent.child.age = 10
|
|
2094
|
+
|
|
2095
|
+
parent.save!
|
|
2096
|
+
expect(registry.calls).to eq expected
|
|
2097
|
+
end
|
|
2098
|
+
end
|
|
2099
|
+
end
|
|
2100
|
+
end
|
|
2101
|
+
|
|
2102
|
+
context "has_many" do
|
|
2103
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2104
|
+
|
|
2105
|
+
let(:parent) do
|
|
2106
|
+
InterceptableSpec::CbHasManyParent.new(registry).tap do |parent|
|
|
2107
|
+
parent.children = [
|
|
2108
|
+
InterceptableSpec::CbHasManyChild.new(registry),
|
|
2109
|
+
InterceptableSpec::CbHasManyChild.new(registry)
|
|
2110
|
+
]
|
|
2111
|
+
end
|
|
2112
|
+
end
|
|
2113
|
+
|
|
2114
|
+
let(:expected) do
|
|
2115
|
+
[
|
|
2116
|
+
[InterceptableSpec::CbHasManyParent, :before_validation],
|
|
2117
|
+
[InterceptableSpec::CbHasManyChild, :before_validation],
|
|
2118
|
+
[InterceptableSpec::CbHasManyChild, :after_validation],
|
|
2119
|
+
[InterceptableSpec::CbHasManyChild, :before_validation],
|
|
2120
|
+
[InterceptableSpec::CbHasManyChild, :after_validation],
|
|
2121
|
+
[InterceptableSpec::CbHasManyParent, :after_validation],
|
|
2122
|
+
|
|
2123
|
+
[InterceptableSpec::CbHasManyParent, :before_save],
|
|
2124
|
+
[InterceptableSpec::CbHasManyParent, :around_save_open],
|
|
2125
|
+
[InterceptableSpec::CbHasManyParent, :before_create],
|
|
2126
|
+
[InterceptableSpec::CbHasManyParent, :around_create_open],
|
|
2127
|
+
|
|
2128
|
+
[InterceptableSpec::CbHasManyParent, :insert_into_database],
|
|
2129
|
+
|
|
2130
|
+
[InterceptableSpec::CbHasManyChild, :before_validation],
|
|
2131
|
+
[InterceptableSpec::CbHasManyChild, :after_validation],
|
|
2132
|
+
[InterceptableSpec::CbHasManyChild, :before_save],
|
|
2133
|
+
[InterceptableSpec::CbHasManyChild, :around_save_open],
|
|
2134
|
+
[InterceptableSpec::CbHasManyChild, :before_create],
|
|
2135
|
+
[InterceptableSpec::CbHasManyChild, :around_create_open],
|
|
2136
|
+
[InterceptableSpec::CbHasManyChild, :around_create_close],
|
|
2137
|
+
[InterceptableSpec::CbHasManyChild, :after_create],
|
|
2138
|
+
[InterceptableSpec::CbHasManyChild, :around_save_close],
|
|
2139
|
+
[InterceptableSpec::CbHasManyChild, :after_save],
|
|
2140
|
+
|
|
2141
|
+
[InterceptableSpec::CbHasManyChild, :before_validation],
|
|
2142
|
+
[InterceptableSpec::CbHasManyChild, :after_validation],
|
|
2143
|
+
[InterceptableSpec::CbHasManyChild, :before_save],
|
|
2144
|
+
[InterceptableSpec::CbHasManyChild, :around_save_open],
|
|
2145
|
+
[InterceptableSpec::CbHasManyChild, :before_create],
|
|
2146
|
+
[InterceptableSpec::CbHasManyChild, :around_create_open],
|
|
2147
|
+
[InterceptableSpec::CbHasManyChild, :around_create_close],
|
|
2148
|
+
[InterceptableSpec::CbHasManyChild, :after_create],
|
|
2149
|
+
[InterceptableSpec::CbHasManyChild, :around_save_close],
|
|
2150
|
+
[InterceptableSpec::CbHasManyChild, :after_save],
|
|
2151
|
+
|
|
2152
|
+
[InterceptableSpec::CbHasManyParent, :around_create_close],
|
|
2153
|
+
[InterceptableSpec::CbHasManyParent, :after_create],
|
|
2154
|
+
[InterceptableSpec::CbHasManyParent, :around_save_close],
|
|
2155
|
+
[InterceptableSpec::CbHasManyParent, :after_save]
|
|
2156
|
+
]
|
|
2157
|
+
end
|
|
2158
|
+
|
|
2159
|
+
it 'calls callbacks in the right order' do
|
|
2160
|
+
parent.save!
|
|
2161
|
+
expect(registry.calls).to eq expected
|
|
2162
|
+
end
|
|
2163
|
+
end
|
|
2164
|
+
|
|
2165
|
+
context "embeds_many" do
|
|
2166
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2167
|
+
|
|
2168
|
+
let(:parent) do
|
|
2169
|
+
InterceptableSpec::CbEmbedsManyParent.new(registry).tap do |parent|
|
|
2170
|
+
parent.children = [
|
|
2171
|
+
InterceptableSpec::CbEmbedsManyChild.new(registry),
|
|
2172
|
+
InterceptableSpec::CbEmbedsManyChild.new(registry),
|
|
2173
|
+
]
|
|
2174
|
+
end
|
|
2175
|
+
end
|
|
2176
|
+
|
|
2177
|
+
context "with around callbacks" do
|
|
2178
|
+
config_override :around_callbacks_for_embeds, true
|
|
2179
|
+
|
|
2180
|
+
let(:expected) do
|
|
2181
|
+
[
|
|
2182
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2183
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2184
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2185
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2186
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_validation],
|
|
2187
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2188
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2189
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2190
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2191
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_validation],
|
|
2192
|
+
|
|
2193
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_save],
|
|
2194
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_open],
|
|
2195
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_create],
|
|
2196
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_open],
|
|
2197
|
+
|
|
2198
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
|
2199
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_open],
|
|
2200
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
|
2201
|
+
|
|
2202
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_open],
|
|
2203
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
|
2204
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_open],
|
|
2205
|
+
|
|
2206
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
|
2207
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_open],
|
|
2208
|
+
|
|
2209
|
+
[InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
|
|
2210
|
+
|
|
2211
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_close],
|
|
2212
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
|
2213
|
+
|
|
2214
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_create_close],
|
|
2215
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
|
2216
|
+
|
|
2217
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_close],
|
|
2218
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
|
2219
|
+
|
|
2220
|
+
[InterceptableSpec::CbEmbedsManyChild, :around_save_close],
|
|
2221
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
|
2222
|
+
|
|
2223
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_close],
|
|
2224
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_create],
|
|
2225
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_close],
|
|
2226
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_save]
|
|
2227
|
+
]
|
|
2228
|
+
end
|
|
2229
|
+
|
|
2230
|
+
it 'calls callbacks in the right order' do
|
|
2231
|
+
parent.save!
|
|
2232
|
+
expect(registry.calls).to eq expected
|
|
2233
|
+
end
|
|
2234
|
+
end
|
|
2235
|
+
|
|
2236
|
+
context "without around callbacks" do
|
|
2237
|
+
config_override :around_callbacks_for_embeds, false
|
|
2238
|
+
|
|
2239
|
+
let(:expected) do
|
|
2240
|
+
[
|
|
2241
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2242
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2243
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2244
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2245
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_validation],
|
|
2246
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2247
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2248
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_validation],
|
|
2249
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_validation],
|
|
2250
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_validation],
|
|
2251
|
+
|
|
2252
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_save],
|
|
2253
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_open],
|
|
2254
|
+
[InterceptableSpec::CbEmbedsManyParent, :before_create],
|
|
2255
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_open],
|
|
2256
|
+
|
|
2257
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
|
2258
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_save],
|
|
2259
|
+
|
|
2260
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
|
2261
|
+
|
|
2262
|
+
[InterceptableSpec::CbEmbedsManyChild, :before_create],
|
|
2263
|
+
|
|
2264
|
+
[InterceptableSpec::CbEmbedsManyParent, :insert_into_database],
|
|
2265
|
+
|
|
2266
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
|
2267
|
+
|
|
2268
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_create],
|
|
2269
|
+
|
|
2270
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
|
2271
|
+
|
|
2272
|
+
[InterceptableSpec::CbEmbedsManyChild, :after_save],
|
|
2273
|
+
|
|
2274
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_create_close],
|
|
2275
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_create],
|
|
2276
|
+
[InterceptableSpec::CbEmbedsManyParent, :around_save_close],
|
|
2277
|
+
[InterceptableSpec::CbEmbedsManyParent, :after_save]
|
|
2278
|
+
]
|
|
2279
|
+
end
|
|
2280
|
+
|
|
2281
|
+
it 'calls callbacks in the right order' do
|
|
2282
|
+
parent.save!
|
|
2283
|
+
expect(registry.calls).to eq expected
|
|
2284
|
+
end
|
|
2285
|
+
end
|
|
2286
|
+
end
|
|
2287
|
+
end
|
|
2288
|
+
|
|
2289
|
+
context "when accessing parent document from callbacks" do
|
|
2290
|
+
shared_examples 'accesses the correct parent' do
|
|
2291
|
+
it "accesses the correct parent in after_find" do
|
|
2292
|
+
expect(from_db.after_find_player).to eq(player._id)
|
|
2293
|
+
end
|
|
2294
|
+
|
|
2295
|
+
it "accesses the correct parent in after_initialize" do
|
|
2296
|
+
expect(from_db.after_initialize_player).to eq(player._id)
|
|
2297
|
+
end
|
|
2298
|
+
|
|
2299
|
+
it "accesses the correct parent in default" do
|
|
2300
|
+
expect(from_db.after_default_player).to eq(player._id)
|
|
2301
|
+
end
|
|
2302
|
+
|
|
2303
|
+
it "accesses the correct parent in unpersisted after_initialize" do
|
|
2304
|
+
expect(unpersisted.after_initialize_player).to eq(player._id)
|
|
2305
|
+
end
|
|
2306
|
+
end
|
|
2307
|
+
|
|
2308
|
+
context "when using create methods" do
|
|
2309
|
+
|
|
2310
|
+
context "when the child is an embeds_many association" do
|
|
2311
|
+
let!(:player) do
|
|
2312
|
+
Player.create!.tap do |player|
|
|
2313
|
+
player.implants.create!
|
|
2314
|
+
end
|
|
2315
|
+
end
|
|
2316
|
+
|
|
2317
|
+
let(:unpersisted) { player.implants.first }
|
|
2318
|
+
|
|
2319
|
+
before do
|
|
2320
|
+
# The default is originally set when creating this document, and it is
|
|
2321
|
+
# subsequently persisted to the database. Therefore when we retrieve
|
|
2322
|
+
# this document from the database, this field is already set, and
|
|
2323
|
+
# the default Proc is not called. This unset is needed to allow the
|
|
2324
|
+
# default Proc to be called when the document is retrieved from the
|
|
2325
|
+
# database.
|
|
2326
|
+
Player.find(player.id).implants.first.unset(:after_default_player)
|
|
2327
|
+
end
|
|
2328
|
+
|
|
2329
|
+
let(:from_db) do
|
|
2330
|
+
Player.find(player.id).implants.first
|
|
2331
|
+
end
|
|
2332
|
+
|
|
2333
|
+
include_examples 'accesses the correct parent'
|
|
2334
|
+
end
|
|
2335
|
+
|
|
2336
|
+
context "when the child is an embeds_one association" do
|
|
2337
|
+
let!(:player) do
|
|
2338
|
+
Player.create!.tap do |player|
|
|
2339
|
+
player.create_augmentation
|
|
2340
|
+
end
|
|
2341
|
+
end
|
|
2342
|
+
|
|
2343
|
+
let(:unpersisted) { player.augmentation }
|
|
2344
|
+
|
|
2345
|
+
before do
|
|
2346
|
+
Player.find(player.id).augmentation.unset(:after_default_player)
|
|
2347
|
+
end
|
|
2348
|
+
|
|
2349
|
+
let(:from_db) do
|
|
2350
|
+
Player.find(player.id).augmentation
|
|
2351
|
+
end
|
|
2352
|
+
|
|
2353
|
+
include_examples 'accesses the correct parent'
|
|
2354
|
+
end
|
|
2355
|
+
|
|
2356
|
+
context "when the child is a has_many association" do
|
|
2357
|
+
let!(:player) do
|
|
2358
|
+
Player.create!.tap do |player|
|
|
2359
|
+
player.weapons.create!
|
|
2360
|
+
end
|
|
2361
|
+
end
|
|
2362
|
+
|
|
2363
|
+
let(:unpersisted) { player.weapons.first }
|
|
2364
|
+
|
|
2365
|
+
before do
|
|
2366
|
+
Player.find(player.id).weapons.first.unset(:after_default_player)
|
|
2367
|
+
end
|
|
2368
|
+
|
|
2369
|
+
let(:from_db) do
|
|
2370
|
+
Player.find(player.id).weapons.first
|
|
2371
|
+
end
|
|
2372
|
+
|
|
2373
|
+
include_examples 'accesses the correct parent'
|
|
2374
|
+
end
|
|
2375
|
+
|
|
2376
|
+
context "when the child is a has_one association" do
|
|
2377
|
+
let!(:player) do
|
|
2378
|
+
Player.create!.tap do |player|
|
|
2379
|
+
player.create_powerup
|
|
2380
|
+
player.save!
|
|
2381
|
+
end
|
|
2382
|
+
end
|
|
2383
|
+
|
|
2384
|
+
let(:unpersisted) { player.powerup }
|
|
2385
|
+
|
|
2386
|
+
before do
|
|
2387
|
+
Player.find(player.id).powerup.unset(:after_default_player)
|
|
2388
|
+
end
|
|
2389
|
+
|
|
2390
|
+
let(:from_db) do
|
|
2391
|
+
Player.find(player.id).powerup
|
|
2392
|
+
end
|
|
2393
|
+
|
|
2394
|
+
include_examples 'accesses the correct parent'
|
|
2395
|
+
end
|
|
2396
|
+
|
|
2397
|
+
context "when the child is a has_and_belongs_to_many association" do
|
|
2398
|
+
let!(:player) do
|
|
2399
|
+
Player.create!.tap do |player|
|
|
2400
|
+
player.shields.create!
|
|
2401
|
+
end
|
|
2402
|
+
end
|
|
2403
|
+
|
|
2404
|
+
let(:unpersisted) { player.shields.first }
|
|
2405
|
+
|
|
2406
|
+
before do
|
|
2407
|
+
Player.find(player.id).shields.unset(:after_default_player)
|
|
2408
|
+
end
|
|
2409
|
+
|
|
2410
|
+
let(:from_db) do
|
|
2411
|
+
Player.find(player.id).shields.first
|
|
2412
|
+
end
|
|
2413
|
+
|
|
2414
|
+
include_examples 'accesses the correct parent'
|
|
2415
|
+
end
|
|
2416
|
+
end
|
|
2417
|
+
|
|
2418
|
+
context "when using build methods" do
|
|
2419
|
+
|
|
2420
|
+
context "when the child is an embeds_many association" do
|
|
2421
|
+
let!(:player) do
|
|
2422
|
+
Player.create!.tap do |player|
|
|
2423
|
+
player.implants.build
|
|
2424
|
+
player.implants.first.save!
|
|
2425
|
+
end
|
|
2426
|
+
end
|
|
2427
|
+
|
|
2428
|
+
let(:unpersisted) { player.implants.first }
|
|
2429
|
+
|
|
2430
|
+
before do
|
|
2431
|
+
Player.find(player.id).implants.first.unset(:after_default_player)
|
|
2432
|
+
end
|
|
2433
|
+
|
|
2434
|
+
let(:from_db) do
|
|
2435
|
+
Player.find(player.id).implants.first
|
|
2436
|
+
end
|
|
2437
|
+
|
|
2438
|
+
include_examples 'accesses the correct parent'
|
|
2439
|
+
end
|
|
2440
|
+
|
|
2441
|
+
context "when the child is an embeds_one association" do
|
|
2442
|
+
let!(:player) do
|
|
2443
|
+
Player.create!.tap do |player|
|
|
2444
|
+
player.build_augmentation
|
|
2445
|
+
player.save!
|
|
2446
|
+
end
|
|
2447
|
+
end
|
|
2448
|
+
|
|
2449
|
+
let(:unpersisted) { player.augmentation }
|
|
2450
|
+
|
|
2451
|
+
before do
|
|
2452
|
+
Player.find(player.id).augmentation.unset(:after_default_player)
|
|
2453
|
+
end
|
|
2454
|
+
|
|
2455
|
+
let(:from_db) do
|
|
2456
|
+
Player.find(player.id).augmentation
|
|
2457
|
+
end
|
|
2458
|
+
|
|
2459
|
+
include_examples 'accesses the correct parent'
|
|
2460
|
+
end
|
|
2461
|
+
|
|
2462
|
+
context "when the child is a has_many association" do
|
|
2463
|
+
let!(:player) do
|
|
2464
|
+
Player.create!.tap do |player|
|
|
2465
|
+
player.weapons.build
|
|
2466
|
+
player.weapons.first.save!
|
|
2467
|
+
end
|
|
2468
|
+
end
|
|
2469
|
+
|
|
2470
|
+
let(:unpersisted) { player.weapons.first }
|
|
2471
|
+
|
|
2472
|
+
before do
|
|
2473
|
+
Player.find(player.id).weapons.first.unset(:after_default_player)
|
|
2474
|
+
end
|
|
2475
|
+
|
|
2476
|
+
let(:from_db) do
|
|
2477
|
+
Player.find(player.id).weapons.first
|
|
2478
|
+
end
|
|
2479
|
+
|
|
2480
|
+
include_examples 'accesses the correct parent'
|
|
2481
|
+
end
|
|
2482
|
+
|
|
2483
|
+
context "when the child is a has_one association" do
|
|
2484
|
+
let!(:player) do
|
|
2485
|
+
Player.create!.tap do |player|
|
|
2486
|
+
player.build_powerup
|
|
2487
|
+
player.powerup.save!
|
|
2488
|
+
end
|
|
2489
|
+
end
|
|
2490
|
+
|
|
2491
|
+
let(:unpersisted) { player.powerup }
|
|
2492
|
+
|
|
2493
|
+
before do
|
|
2494
|
+
Player.find(player.id).powerup.unset(:after_default_player)
|
|
2495
|
+
end
|
|
2496
|
+
|
|
2497
|
+
let(:from_db) do
|
|
2498
|
+
Player.find(player.id).powerup
|
|
2499
|
+
end
|
|
2500
|
+
|
|
2501
|
+
include_examples 'accesses the correct parent'
|
|
2502
|
+
end
|
|
2503
|
+
|
|
2504
|
+
context "when the child is a has_and_belongs_to_many association" do
|
|
2505
|
+
let!(:player) do
|
|
2506
|
+
Player.create!.tap do |player|
|
|
2507
|
+
player.shields.build
|
|
2508
|
+
player.shields.first.save!
|
|
2509
|
+
end
|
|
2510
|
+
end
|
|
2511
|
+
|
|
2512
|
+
let(:unpersisted) { player.shields.first }
|
|
2513
|
+
|
|
2514
|
+
before do
|
|
2515
|
+
Player.find(player.id).shields.unset(:after_default_player)
|
|
2516
|
+
end
|
|
2517
|
+
|
|
2518
|
+
let(:from_db) do
|
|
2519
|
+
Player.find(player.id).shields.first
|
|
2520
|
+
end
|
|
2521
|
+
|
|
2522
|
+
include_examples 'accesses the correct parent'
|
|
2523
|
+
end
|
|
2524
|
+
end
|
|
2525
|
+
end
|
|
2526
|
+
|
|
2527
|
+
context "when accessing associations in defaults" do
|
|
2528
|
+
context "when not using autobuilding" do
|
|
2529
|
+
let(:band) { InterceptableBand.create(name: "Molejo") }
|
|
2530
|
+
let(:song) { band.songs.create(name: "Cilada") }
|
|
2531
|
+
|
|
2532
|
+
it "assigns the default correctly" do
|
|
2533
|
+
expect(song.band_name).to eq("Molejo")
|
|
2534
|
+
end
|
|
2535
|
+
end
|
|
2536
|
+
|
|
2537
|
+
context "when using autobuilding" do
|
|
2538
|
+
before do
|
|
2539
|
+
InterceptablePlane.create!.tap do |plane|
|
|
2540
|
+
plane.wings.create!
|
|
2541
|
+
end
|
|
2542
|
+
end
|
|
2543
|
+
|
|
2544
|
+
let(:plane) { InterceptablePlane.first }
|
|
2545
|
+
let(:wing) { InterceptableWing.first }
|
|
2546
|
+
let(:engine) { wing.engine }
|
|
2547
|
+
|
|
2548
|
+
it "sets the defaults correctly" do
|
|
2549
|
+
expect(wing._id).to eq("hello-wing")
|
|
2550
|
+
expect(wing.p_id).to eq(plane._id.to_s)
|
|
2551
|
+
expect(wing.e_id).to eq(engine._id.to_s)
|
|
2552
|
+
expect(engine._id).to eq("hello-engine-#{wing.id}")
|
|
2553
|
+
end
|
|
2554
|
+
end
|
|
2555
|
+
end
|
|
2556
|
+
|
|
2557
|
+
# This case is rather niche. The _ids method used to use the `.only` method
|
|
2558
|
+
# to get only the _ids for an association, which was causing a
|
|
2559
|
+
# MissingAttributeError to be raised when accessing another association. This
|
|
2560
|
+
# was fixed by using `.pluck` over `.only`. Look at MONGOID-5306 for a more
|
|
2561
|
+
# detailed explanation.
|
|
2562
|
+
context "when accessing _ids in validate and access an association in after_initialize" do
|
|
2563
|
+
it "doesn't raise a MissingAttributeError" do
|
|
2564
|
+
company = InterceptableCompany.create!
|
|
2565
|
+
shop = InterceptableShop.create!(company: company)
|
|
2566
|
+
user = InterceptableUser.new
|
|
2567
|
+
user.company = company
|
|
2568
|
+
expect do
|
|
2569
|
+
user.save!
|
|
2570
|
+
end.to_not raise_error(ActiveModel::MissingAttributeError)
|
|
2571
|
+
end
|
|
2572
|
+
end
|
|
2573
|
+
|
|
2574
|
+
context "when around callbacks for embedded are disabled" do
|
|
2575
|
+
config_override :around_callbacks_for_embeds, false
|
|
2576
|
+
|
|
2577
|
+
context "when around callback is defined" do
|
|
2578
|
+
let(:registry) { InterceptableSpec::CallbackRegistry.new }
|
|
2579
|
+
|
|
2580
|
+
let(:parent) do
|
|
2581
|
+
InterceptableSpec::CbEmbedsOneParent.new(registry).tap do |parent|
|
|
2582
|
+
parent.child = InterceptableSpec::CbEmbedsOneChild.new(registry)
|
|
2583
|
+
end
|
|
2584
|
+
end
|
|
2585
|
+
|
|
2586
|
+
before do
|
|
2587
|
+
expect(Mongoid.logger).to receive(:warn).with(/Around callbacks are disabled for embedded documents/).twice.and_call_original
|
|
2588
|
+
expect(Mongoid.logger).to receive(:warn).with(/To enable around callbacks for embedded documents/).twice.and_call_original
|
|
2589
|
+
end
|
|
2590
|
+
|
|
2591
|
+
it "logs a warning" do
|
|
2592
|
+
parent.save!
|
|
2593
|
+
end
|
|
2594
|
+
end
|
|
2595
|
+
end
|
|
1722
2596
|
end
|