mongoid 9.0.11 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -0
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +34 -38
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +18 -13
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -66
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -14
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +1 -3
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +132 -42
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +72 -65
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -2
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -72
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +26 -25
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +0 -2
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +11 -14
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -15
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -41
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +330 -0
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +28 -30
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -32
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -178
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +104 -119
- data/spec/integration/encryption_spec.rb +8 -11
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -31
- data/spec/mongoid/config/encryption_spec.rb +54 -57
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -854
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -950
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -80
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -8
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -2
|
@@ -1,105 +1,94 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Changeable do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context "when the attribute has changed from the persisted value" do
|
|
11
|
-
|
|
12
|
-
context "when using the setter" do
|
|
13
|
-
|
|
6
|
+
describe '#attribute_change' do
|
|
7
|
+
context 'when the attribute has changed from the persisted value' do
|
|
8
|
+
context 'when using the setter' do
|
|
14
9
|
let(:person) do
|
|
15
|
-
Person.new(title:
|
|
10
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
16
11
|
end
|
|
17
12
|
|
|
18
13
|
before do
|
|
19
|
-
person.title =
|
|
14
|
+
person.title = 'Captain Obvious'
|
|
20
15
|
end
|
|
21
16
|
|
|
22
|
-
it
|
|
23
|
-
expect(person.send(:attribute_change,
|
|
24
|
-
[
|
|
17
|
+
it 'returns an array of the old value and new value' do
|
|
18
|
+
expect(person.send(:attribute_change, 'title')).to eq(
|
|
19
|
+
[ 'Grand Poobah', 'Captain Obvious' ]
|
|
25
20
|
)
|
|
26
21
|
end
|
|
27
22
|
|
|
28
|
-
it
|
|
23
|
+
it 'allows access via (attribute)_change' do
|
|
29
24
|
expect(person.title_change).to eq(
|
|
30
|
-
[
|
|
25
|
+
[ 'Grand Poobah', 'Captain Obvious' ]
|
|
31
26
|
)
|
|
32
27
|
end
|
|
33
28
|
|
|
34
|
-
context
|
|
35
|
-
|
|
29
|
+
context 'when the field is aliased' do
|
|
36
30
|
let(:person) do
|
|
37
|
-
Person.new(test:
|
|
31
|
+
Person.new(test: 'Aliased 1').tap(&:move_changes)
|
|
38
32
|
end
|
|
39
33
|
|
|
40
34
|
before do
|
|
41
|
-
person.test =
|
|
35
|
+
person.test = 'Aliased 2'
|
|
42
36
|
end
|
|
43
37
|
|
|
44
|
-
it
|
|
45
|
-
expect(person.send(:attribute_change,
|
|
46
|
-
[
|
|
38
|
+
it 'returns an array of the old value and new value' do
|
|
39
|
+
expect(person.send(:attribute_change, 'test')).to eq(
|
|
40
|
+
[ 'Aliased 1', 'Aliased 2' ]
|
|
47
41
|
)
|
|
48
42
|
end
|
|
49
43
|
|
|
50
|
-
it
|
|
44
|
+
it 'allows access via (attribute)_change' do
|
|
51
45
|
expect(person.test_change).to eq(
|
|
52
|
-
[
|
|
46
|
+
[ 'Aliased 1', 'Aliased 2' ]
|
|
53
47
|
)
|
|
54
48
|
end
|
|
55
49
|
end
|
|
56
50
|
end
|
|
57
51
|
|
|
58
|
-
context
|
|
59
|
-
|
|
52
|
+
context 'when using [] methods' do
|
|
60
53
|
let(:person) do
|
|
61
|
-
Person.new(title:
|
|
54
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
62
55
|
end
|
|
63
56
|
|
|
64
57
|
before do
|
|
65
|
-
person[:title] =
|
|
58
|
+
person[:title] = 'Captain Obvious'
|
|
66
59
|
end
|
|
67
60
|
|
|
68
|
-
it
|
|
69
|
-
expect(person.send(:attribute_change,
|
|
70
|
-
[
|
|
61
|
+
it 'returns an array of the old value and new value' do
|
|
62
|
+
expect(person.send(:attribute_change, 'title')).to eq(
|
|
63
|
+
[ 'Grand Poobah', 'Captain Obvious' ]
|
|
71
64
|
)
|
|
72
65
|
end
|
|
73
66
|
|
|
74
|
-
it
|
|
67
|
+
it 'allows access via (attribute)_change' do
|
|
75
68
|
expect(person.title_change).to eq(
|
|
76
|
-
[
|
|
69
|
+
[ 'Grand Poobah', 'Captain Obvious' ]
|
|
77
70
|
)
|
|
78
71
|
end
|
|
79
72
|
end
|
|
80
73
|
end
|
|
81
74
|
|
|
82
|
-
context
|
|
83
|
-
|
|
84
|
-
context "when using the setter" do
|
|
85
|
-
|
|
75
|
+
context 'when the attribute has changed from the default value' do
|
|
76
|
+
context 'when using the setter' do
|
|
86
77
|
let(:person) do
|
|
87
78
|
Person.new(pets: true)
|
|
88
79
|
end
|
|
89
80
|
|
|
90
|
-
it
|
|
91
|
-
expect(person.send(:attribute_change,
|
|
81
|
+
it 'returns an array of nil and new value' do
|
|
82
|
+
expect(person.send(:attribute_change, 'pets')).to eq([ nil, true ])
|
|
92
83
|
end
|
|
93
84
|
|
|
94
|
-
it
|
|
85
|
+
it 'allows access via (attribute)_change' do
|
|
95
86
|
expect(person.pets_change).to eq([ nil, true ])
|
|
96
87
|
end
|
|
97
88
|
end
|
|
98
89
|
|
|
99
|
-
context
|
|
100
|
-
|
|
101
|
-
context "when the field is defined" do
|
|
102
|
-
|
|
90
|
+
context 'when using [] methods' do
|
|
91
|
+
context 'when the field is defined' do
|
|
103
92
|
let(:person) do
|
|
104
93
|
Person.new
|
|
105
94
|
end
|
|
@@ -108,136 +97,128 @@ describe Mongoid::Changeable do
|
|
|
108
97
|
person[:pets] = true
|
|
109
98
|
end
|
|
110
99
|
|
|
111
|
-
it
|
|
112
|
-
expect(person.send(:attribute_change,
|
|
100
|
+
it 'returns an array of nil and new value' do
|
|
101
|
+
expect(person.send(:attribute_change, 'pets')).to eq([ nil, true ])
|
|
113
102
|
end
|
|
114
103
|
|
|
115
|
-
it
|
|
104
|
+
it 'allows access via (attribute)_change' do
|
|
116
105
|
expect(person.pets_change).to eq([ nil, true ])
|
|
117
106
|
end
|
|
118
107
|
end
|
|
119
108
|
|
|
120
|
-
context
|
|
121
|
-
|
|
109
|
+
context 'when the field is not defined' do
|
|
122
110
|
let(:person) do
|
|
123
111
|
Person.new
|
|
124
112
|
end
|
|
125
113
|
|
|
126
114
|
before do
|
|
127
|
-
person[:t] =
|
|
115
|
+
person[:t] = 'test'
|
|
128
116
|
end
|
|
129
117
|
|
|
130
|
-
it
|
|
131
|
-
expect(person.send(:attribute_change,
|
|
118
|
+
it 'returns an array of nil and new value' do
|
|
119
|
+
expect(person.send(:attribute_change, 't')).to eq([ nil, 'test' ])
|
|
132
120
|
end
|
|
133
121
|
end
|
|
134
122
|
end
|
|
135
123
|
end
|
|
136
124
|
|
|
137
|
-
context
|
|
138
|
-
|
|
125
|
+
context 'when the attribute changes multiple times' do
|
|
139
126
|
let(:person) do
|
|
140
|
-
Person.new(title:
|
|
127
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
141
128
|
end
|
|
142
129
|
|
|
143
130
|
before do
|
|
144
|
-
person.title =
|
|
145
|
-
person.title =
|
|
131
|
+
person.title = 'Captain Obvious'
|
|
132
|
+
person.title = 'Dark Helmet'
|
|
146
133
|
end
|
|
147
134
|
|
|
148
|
-
it
|
|
149
|
-
expect(person.send(:attribute_change,
|
|
150
|
-
[
|
|
135
|
+
it 'returns an array of the original value and new value' do
|
|
136
|
+
expect(person.send(:attribute_change, 'title')).to eq(
|
|
137
|
+
[ 'Grand Poobah', 'Dark Helmet' ]
|
|
151
138
|
)
|
|
152
139
|
end
|
|
153
140
|
|
|
154
|
-
it
|
|
141
|
+
it 'allows access via (attribute)_change' do
|
|
155
142
|
expect(person.title_change).to eq(
|
|
156
|
-
[
|
|
143
|
+
[ 'Grand Poobah', 'Dark Helmet' ]
|
|
157
144
|
)
|
|
158
145
|
end
|
|
159
146
|
end
|
|
160
147
|
|
|
161
|
-
context
|
|
162
|
-
|
|
163
|
-
context "when the attribute is an array" do
|
|
164
|
-
|
|
148
|
+
context 'when the attribute is modified in place' do
|
|
149
|
+
context 'when the attribute is an array' do
|
|
165
150
|
let(:person) do
|
|
166
|
-
Person.new(aliases: [
|
|
151
|
+
Person.new(aliases: [ 'Grand Poobah' ]).tap(&:move_changes)
|
|
167
152
|
end
|
|
168
153
|
|
|
169
154
|
before do
|
|
170
|
-
person.aliases[0] =
|
|
155
|
+
person.aliases[0] = 'Dark Helmet'
|
|
171
156
|
end
|
|
172
157
|
|
|
173
|
-
it
|
|
174
|
-
expect(person.send(:attribute_change,
|
|
175
|
-
[[
|
|
158
|
+
it 'returns an array of the original value and new value' do
|
|
159
|
+
expect(person.send(:attribute_change, 'aliases')).to eq(
|
|
160
|
+
[ [ 'Grand Poobah' ], [ 'Dark Helmet' ] ]
|
|
176
161
|
)
|
|
177
162
|
end
|
|
178
163
|
|
|
179
|
-
it
|
|
164
|
+
it 'allows access via (attribute)_change' do
|
|
180
165
|
expect(person.aliases_change).to eq(
|
|
181
|
-
[[
|
|
166
|
+
[ [ 'Grand Poobah' ], [ 'Dark Helmet' ] ]
|
|
182
167
|
)
|
|
183
168
|
end
|
|
184
169
|
|
|
185
|
-
context
|
|
186
|
-
|
|
170
|
+
context 'when the attribute changes multiple times' do
|
|
187
171
|
before do
|
|
188
|
-
person.aliases <<
|
|
172
|
+
person.aliases << 'Colonel Sanders'
|
|
189
173
|
end
|
|
190
174
|
|
|
191
|
-
it
|
|
192
|
-
expect(person.send(:attribute_change,
|
|
193
|
-
[[
|
|
175
|
+
it 'returns an array of the original value and new value' do
|
|
176
|
+
expect(person.send(:attribute_change, 'aliases')).to eq(
|
|
177
|
+
[ [ 'Grand Poobah' ], [ 'Dark Helmet', 'Colonel Sanders' ] ]
|
|
194
178
|
)
|
|
195
179
|
end
|
|
196
180
|
end
|
|
197
181
|
end
|
|
198
182
|
|
|
199
|
-
context
|
|
200
|
-
|
|
183
|
+
context 'when the attribute is a hash' do
|
|
201
184
|
let(:person) do
|
|
202
|
-
Person.new(map: { location:
|
|
185
|
+
Person.new(map: { location: 'Home' }).tap(&:move_changes)
|
|
203
186
|
end
|
|
204
187
|
|
|
205
188
|
before do
|
|
206
|
-
person.map[:location] =
|
|
189
|
+
person.map[:location] = 'Work'
|
|
207
190
|
end
|
|
208
191
|
|
|
209
|
-
it
|
|
210
|
-
expect(person.send(:attribute_change,
|
|
211
|
-
[{
|
|
192
|
+
it 'returns an array of the original value and new value' do
|
|
193
|
+
expect(person.send(:attribute_change, 'map')).to eq(
|
|
194
|
+
[ { 'location' => 'Home' }, { 'location' => 'Work' } ]
|
|
212
195
|
)
|
|
213
196
|
end
|
|
214
197
|
|
|
215
|
-
it
|
|
198
|
+
it 'allows access via (attribute)_change' do
|
|
216
199
|
expect(person.map_change).to eq(
|
|
217
|
-
[{
|
|
200
|
+
[ { 'location' => 'Home' }, { 'location' => 'Work' } ]
|
|
218
201
|
)
|
|
219
202
|
end
|
|
220
203
|
|
|
221
|
-
context
|
|
222
|
-
|
|
204
|
+
context 'when the attribute changes multiple times' do
|
|
223
205
|
before do
|
|
224
206
|
person.map[:lat] = 20.0
|
|
225
207
|
end
|
|
226
208
|
|
|
227
|
-
it
|
|
228
|
-
expect(person.send(:attribute_change,
|
|
229
|
-
[{
|
|
209
|
+
it 'returns an array of the original value and new value' do
|
|
210
|
+
expect(person.send(:attribute_change, 'map')).to eq(
|
|
211
|
+
[ { 'location' => 'Home' }, { 'location' => 'Work', 'lat' => 20.0 } ]
|
|
230
212
|
)
|
|
231
213
|
end
|
|
232
214
|
end
|
|
233
215
|
|
|
234
|
-
context
|
|
235
|
-
|
|
216
|
+
context 'when the values are arrays' do
|
|
236
217
|
let(:map) do
|
|
237
218
|
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
219
|
+
'stack1' => [ 1, 2, 3, 4 ],
|
|
220
|
+
'stack2' => [ 1, 2, 3, 4 ],
|
|
221
|
+
'stack3' => [ 1, 2, 3, 4 ]
|
|
241
222
|
}
|
|
242
223
|
end
|
|
243
224
|
|
|
@@ -246,25 +227,24 @@ describe Mongoid::Changeable do
|
|
|
246
227
|
person.move_changes
|
|
247
228
|
end
|
|
248
229
|
|
|
249
|
-
context
|
|
250
|
-
|
|
230
|
+
context 'when reordering the arrays inline' do
|
|
251
231
|
before do
|
|
252
|
-
person.map[
|
|
232
|
+
person.map['stack1'].reverse!
|
|
253
233
|
end
|
|
254
234
|
|
|
255
|
-
it
|
|
256
|
-
expect(person.send(:attribute_change,
|
|
235
|
+
it 'flags the attribute as changed' do
|
|
236
|
+
expect(person.send(:attribute_change, 'map')).to eq(
|
|
257
237
|
[
|
|
258
238
|
{
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
239
|
+
'stack1' => [ 1, 2, 3, 4 ],
|
|
240
|
+
'stack2' => [ 1, 2, 3, 4 ],
|
|
241
|
+
'stack3' => [ 1, 2, 3, 4 ]
|
|
262
242
|
},
|
|
263
243
|
{
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
244
|
+
'stack1' => [ 4, 3, 2, 1 ],
|
|
245
|
+
'stack2' => [ 1, 2, 3, 4 ],
|
|
246
|
+
'stack3' => [ 1, 2, 3, 4 ]
|
|
247
|
+
}
|
|
268
248
|
]
|
|
269
249
|
)
|
|
270
250
|
end
|
|
@@ -273,117 +253,107 @@ describe Mongoid::Changeable do
|
|
|
273
253
|
end
|
|
274
254
|
end
|
|
275
255
|
|
|
276
|
-
context
|
|
277
|
-
|
|
256
|
+
context 'when the attribute has not changed from the persisted value' do
|
|
278
257
|
let(:person) do
|
|
279
258
|
Person.new(title: nil)
|
|
280
259
|
end
|
|
281
260
|
|
|
282
|
-
it
|
|
283
|
-
expect(person.send(:attribute_change,
|
|
261
|
+
it 'returns nil' do
|
|
262
|
+
expect(person.send(:attribute_change, 'title')).to be_nil
|
|
284
263
|
end
|
|
285
264
|
end
|
|
286
265
|
|
|
287
|
-
context
|
|
288
|
-
|
|
289
|
-
context "when the attribute differs from the persisted value" do
|
|
290
|
-
|
|
266
|
+
context 'when the attribute has not changed from the default value' do
|
|
267
|
+
context 'when the attribute differs from the persisted value' do
|
|
291
268
|
let(:person) do
|
|
292
269
|
Person.new
|
|
293
270
|
end
|
|
294
271
|
|
|
295
|
-
it
|
|
296
|
-
expect(person.send(:attribute_change,
|
|
272
|
+
it 'returns the change' do
|
|
273
|
+
expect(person.send(:attribute_change, 'pets')).to eq([ nil, false ])
|
|
297
274
|
end
|
|
298
275
|
end
|
|
299
276
|
|
|
300
|
-
context
|
|
301
|
-
|
|
277
|
+
context 'when the attribute does not differ from the persisted value' do
|
|
302
278
|
let(:person) do
|
|
303
|
-
Person.instantiate(
|
|
279
|
+
Person.instantiate('pets' => false)
|
|
304
280
|
end
|
|
305
281
|
|
|
306
|
-
it
|
|
307
|
-
expect(person.send(:attribute_change,
|
|
282
|
+
it 'returns nil' do
|
|
283
|
+
expect(person.send(:attribute_change, 'pets')).to be_nil
|
|
308
284
|
end
|
|
309
285
|
end
|
|
310
286
|
end
|
|
311
287
|
|
|
312
|
-
context
|
|
313
|
-
|
|
288
|
+
context 'when the attribute has been set with the same value' do
|
|
314
289
|
let(:person) do
|
|
315
|
-
Person.new(title:
|
|
290
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
316
291
|
end
|
|
317
292
|
|
|
318
293
|
before do
|
|
319
|
-
person.title =
|
|
294
|
+
person.title = 'Grand Poobah'
|
|
320
295
|
end
|
|
321
296
|
|
|
322
|
-
it
|
|
323
|
-
expect(person.send(:attribute_change,
|
|
297
|
+
it 'returns an empty array' do
|
|
298
|
+
expect(person.send(:attribute_change, 'title')).to be_nil
|
|
324
299
|
end
|
|
325
300
|
end
|
|
326
301
|
|
|
327
|
-
context
|
|
328
|
-
|
|
302
|
+
context 'when the attribute is removed' do
|
|
329
303
|
let(:person) do
|
|
330
|
-
Person.new(title:
|
|
304
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
331
305
|
end
|
|
332
306
|
|
|
333
307
|
before do
|
|
334
308
|
person.remove_attribute(:title)
|
|
335
309
|
end
|
|
336
310
|
|
|
337
|
-
it
|
|
338
|
-
expect(person.send(:attribute_change,
|
|
339
|
-
[
|
|
311
|
+
it 'returns an empty array' do
|
|
312
|
+
expect(person.send(:attribute_change, 'title')).to eq(
|
|
313
|
+
[ 'Grand Poobah', nil ]
|
|
340
314
|
)
|
|
341
315
|
end
|
|
342
316
|
end
|
|
343
317
|
end
|
|
344
318
|
|
|
345
|
-
describe
|
|
346
|
-
|
|
347
|
-
context "when the attribute has changed from the persisted value" do
|
|
348
|
-
|
|
319
|
+
describe '#attribute_changed?' do
|
|
320
|
+
context 'when the attribute has changed from the persisted value' do
|
|
349
321
|
let(:person) do
|
|
350
|
-
Person.new(title:
|
|
322
|
+
Person.new(title: 'Grand Poobah')
|
|
351
323
|
end
|
|
352
324
|
|
|
353
325
|
before do
|
|
354
|
-
person.title =
|
|
326
|
+
person.title = 'Captain Obvious'
|
|
355
327
|
end
|
|
356
328
|
|
|
357
|
-
it
|
|
358
|
-
expect(person.send(:attribute_changed?,
|
|
329
|
+
it 'returns true' do
|
|
330
|
+
expect(person.send(:attribute_changed?, 'title')).to be true
|
|
359
331
|
end
|
|
360
332
|
|
|
361
|
-
it
|
|
333
|
+
it 'allows access via (attribute)_changed?' do
|
|
362
334
|
expect(person.title_changed?).to be true
|
|
363
335
|
end
|
|
364
336
|
|
|
365
|
-
context
|
|
366
|
-
|
|
337
|
+
context 'when the field is aliased' do
|
|
367
338
|
let(:person) do
|
|
368
|
-
Person.new(test:
|
|
339
|
+
Person.new(test: 'Aliased 1')
|
|
369
340
|
end
|
|
370
341
|
|
|
371
342
|
before do
|
|
372
|
-
person.test =
|
|
343
|
+
person.test = 'Aliased 2'
|
|
373
344
|
end
|
|
374
345
|
|
|
375
|
-
it
|
|
376
|
-
expect(person.send(:attribute_changed?,
|
|
346
|
+
it 'returns true' do
|
|
347
|
+
expect(person.send(:attribute_changed?, 'test')).to be true
|
|
377
348
|
end
|
|
378
349
|
|
|
379
|
-
it
|
|
350
|
+
it 'allows access via (attribute)_changed?' do
|
|
380
351
|
expect(person.test_changed?).to be true
|
|
381
352
|
end
|
|
382
353
|
end
|
|
383
354
|
end
|
|
384
355
|
|
|
385
|
-
context
|
|
386
|
-
|
|
356
|
+
context 'when the attribute has changed from the default value' do
|
|
387
357
|
let(:person) do
|
|
388
358
|
Person.new
|
|
389
359
|
end
|
|
@@ -392,355 +362,341 @@ describe Mongoid::Changeable do
|
|
|
392
362
|
person.pets = true
|
|
393
363
|
end
|
|
394
364
|
|
|
395
|
-
it
|
|
396
|
-
expect(person.send(:attribute_changed?,
|
|
365
|
+
it 'returns true' do
|
|
366
|
+
expect(person.send(:attribute_changed?, 'pets')).to be true
|
|
397
367
|
end
|
|
398
368
|
|
|
399
|
-
it
|
|
369
|
+
it 'allows access via (attribute)_changed?' do
|
|
400
370
|
expect(person.pets_changed?).to be true
|
|
401
371
|
end
|
|
402
372
|
end
|
|
403
373
|
|
|
404
|
-
context
|
|
405
|
-
|
|
374
|
+
context 'when the attribute has not changed the persisted value' do
|
|
406
375
|
let!(:person) do
|
|
407
|
-
Person.new(title:
|
|
376
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
408
377
|
end
|
|
409
378
|
|
|
410
|
-
it
|
|
411
|
-
expect(person.send(:attribute_changed?,
|
|
379
|
+
it 'returns false' do
|
|
380
|
+
expect(person.send(:attribute_changed?, 'title')).to be false
|
|
412
381
|
end
|
|
413
382
|
end
|
|
414
383
|
|
|
415
|
-
context
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
context "when the attribute differs from the persisted value" do
|
|
420
|
-
|
|
384
|
+
context 'when the attribute has not changed from the default value' do
|
|
385
|
+
context 'when the attribute is not enumerable' do
|
|
386
|
+
context 'when the attribute differs from the persisted value' do
|
|
421
387
|
let!(:person) do
|
|
422
388
|
Person.new
|
|
423
389
|
end
|
|
424
390
|
|
|
425
|
-
it
|
|
426
|
-
expect(person.send(:attribute_changed?,
|
|
391
|
+
it 'returns true' do
|
|
392
|
+
expect(person.send(:attribute_changed?, 'pets')).to be true
|
|
427
393
|
end
|
|
428
394
|
end
|
|
429
395
|
|
|
430
|
-
context
|
|
431
|
-
|
|
396
|
+
context 'when the attribute does not differ from the persisted value' do
|
|
432
397
|
let!(:person) do
|
|
433
|
-
Person.instantiate(
|
|
398
|
+
Person.instantiate('pets' => false)
|
|
434
399
|
end
|
|
435
400
|
|
|
436
|
-
it
|
|
437
|
-
expect(person.send(:attribute_changed?,
|
|
401
|
+
it 'returns false' do
|
|
402
|
+
expect(person.send(:attribute_changed?, 'pets')).to be false
|
|
438
403
|
end
|
|
439
404
|
end
|
|
440
405
|
end
|
|
441
406
|
|
|
442
|
-
context
|
|
443
|
-
|
|
407
|
+
context 'when the attribute is an array' do
|
|
444
408
|
let!(:person) do
|
|
445
|
-
Person.new(aliases: [
|
|
409
|
+
Person.new(aliases: [ 'Bond' ])
|
|
446
410
|
end
|
|
447
411
|
|
|
448
|
-
context
|
|
449
|
-
|
|
412
|
+
context 'when the array is only accessed' do
|
|
450
413
|
before do
|
|
451
414
|
person.move_changes
|
|
452
415
|
person.aliases
|
|
453
416
|
end
|
|
454
417
|
|
|
455
|
-
it
|
|
456
|
-
expect(person).
|
|
418
|
+
it 'returns false' do
|
|
419
|
+
expect(person).not_to be_aliases_changed
|
|
457
420
|
end
|
|
458
421
|
end
|
|
459
422
|
end
|
|
460
423
|
|
|
461
|
-
context
|
|
462
|
-
|
|
424
|
+
context 'when the attribute is a hash' do
|
|
463
425
|
let!(:person) do
|
|
464
|
-
Person.new(map: { key:
|
|
426
|
+
Person.new(map: { key: 'value' })
|
|
465
427
|
end
|
|
466
428
|
|
|
467
|
-
context
|
|
468
|
-
|
|
429
|
+
context 'when the hash is only accessed' do
|
|
469
430
|
before do
|
|
470
431
|
person.move_changes
|
|
471
432
|
person.map
|
|
472
433
|
end
|
|
473
434
|
|
|
474
|
-
it
|
|
475
|
-
expect(person).
|
|
435
|
+
it 'returns false' do
|
|
436
|
+
expect(person).not_to be_map_changed
|
|
476
437
|
end
|
|
477
438
|
end
|
|
478
439
|
end
|
|
479
440
|
end
|
|
480
441
|
|
|
481
|
-
context
|
|
482
|
-
|
|
442
|
+
context 'when including key word args' do
|
|
483
443
|
let(:person) { Person.new }
|
|
484
444
|
|
|
485
|
-
context
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
it "returns false" do
|
|
445
|
+
context 'when only including from' do
|
|
446
|
+
context 'when the object has not changed' do
|
|
447
|
+
it 'returns false' do
|
|
490
448
|
expect(person.send(:attribute_changed?, :score, from: nil)).to be false
|
|
491
449
|
end
|
|
492
450
|
|
|
493
|
-
it
|
|
451
|
+
it 'returns false using (attribute)_changed?' do
|
|
494
452
|
expect(person.score_changed?(from: nil)).to be false
|
|
495
453
|
end
|
|
496
454
|
end
|
|
497
455
|
|
|
498
|
-
context
|
|
499
|
-
|
|
456
|
+
context 'when the object has changed from the wrong item' do
|
|
500
457
|
before do
|
|
501
458
|
person.score = 2
|
|
502
459
|
end
|
|
503
460
|
|
|
504
|
-
it
|
|
461
|
+
it 'returns false' do
|
|
505
462
|
expect(person.send(:attribute_changed?, :score, from: 1)).to be false
|
|
506
463
|
end
|
|
507
464
|
|
|
508
|
-
it
|
|
465
|
+
it 'returns false using (attribute)_changed?' do
|
|
509
466
|
expect(person.score_changed?(from: 1)).to be false
|
|
510
467
|
end
|
|
511
468
|
end
|
|
512
469
|
|
|
513
|
-
context
|
|
514
|
-
|
|
470
|
+
context 'when the object has changed from the correct item' do
|
|
515
471
|
before do
|
|
516
472
|
person.score = 2
|
|
517
473
|
end
|
|
518
474
|
|
|
519
|
-
it
|
|
475
|
+
it 'returns true' do
|
|
520
476
|
expect(person.send(:attribute_changed?, :score, from: nil)).to be true
|
|
521
477
|
end
|
|
522
478
|
|
|
523
|
-
it
|
|
479
|
+
it 'returns true using (attribute)_changed?' do
|
|
524
480
|
expect(person.score_changed?(from: nil)).to be true
|
|
525
481
|
end
|
|
526
482
|
end
|
|
527
483
|
end
|
|
528
484
|
|
|
529
|
-
context
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
it "returns false" do
|
|
485
|
+
context 'when only including to' do
|
|
486
|
+
context 'when the object has not changed' do
|
|
487
|
+
it 'returns false' do
|
|
534
488
|
expect(person.send(:attribute_changed?, :score, to: nil)).to be false
|
|
535
489
|
end
|
|
536
490
|
|
|
537
|
-
it
|
|
491
|
+
it 'returns false using (attribute)_changed?' do
|
|
538
492
|
expect(person.score_changed?(to: nil)).to be false
|
|
539
493
|
end
|
|
540
494
|
end
|
|
541
495
|
|
|
542
|
-
context
|
|
543
|
-
|
|
496
|
+
context 'when the object has changed to the wrong item' do
|
|
544
497
|
before do
|
|
545
498
|
person.score = 2
|
|
546
499
|
end
|
|
547
500
|
|
|
548
|
-
it
|
|
501
|
+
it 'returns false' do
|
|
549
502
|
expect(person.send(:attribute_changed?, :score, to: 1)).to be false
|
|
550
503
|
end
|
|
551
504
|
|
|
552
|
-
it
|
|
505
|
+
it 'returns false using (attribute)_changed?' do
|
|
553
506
|
expect(person.score_changed?(to: 1)).to be false
|
|
554
507
|
end
|
|
555
508
|
end
|
|
556
509
|
|
|
557
|
-
context
|
|
558
|
-
|
|
510
|
+
context 'when the object has changed to the correct item' do
|
|
559
511
|
before do
|
|
560
512
|
person.score = 2
|
|
561
513
|
end
|
|
562
514
|
|
|
563
|
-
it
|
|
515
|
+
it 'returns true' do
|
|
564
516
|
expect(person.send(:attribute_changed?, :score, to: 2)).to be true
|
|
565
517
|
end
|
|
566
518
|
|
|
567
|
-
it
|
|
519
|
+
it 'returns true using (attribute)_changed?' do
|
|
568
520
|
expect(person.score_changed?(to: 2)).to be true
|
|
569
521
|
end
|
|
570
522
|
end
|
|
571
523
|
end
|
|
572
524
|
|
|
573
|
-
context
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
it "returns false" do
|
|
525
|
+
context 'when including from and to' do
|
|
526
|
+
context 'when the object has not changed' do
|
|
527
|
+
it 'returns false' do
|
|
578
528
|
expect(person.send(:attribute_changed?, :score, from: nil, to: nil)).to be false
|
|
579
529
|
end
|
|
580
530
|
|
|
581
|
-
it
|
|
531
|
+
it 'returns false using (attribute)_changed?' do
|
|
582
532
|
expect(person.score_changed?(from: nil, to: nil)).to be false
|
|
583
533
|
end
|
|
584
534
|
end
|
|
585
535
|
|
|
586
|
-
context
|
|
587
|
-
|
|
536
|
+
context 'when only the from is correct' do
|
|
588
537
|
before do
|
|
589
538
|
person.score = 2
|
|
590
539
|
end
|
|
591
540
|
|
|
592
|
-
it
|
|
541
|
+
it 'returns false' do
|
|
593
542
|
expect(person.send(:attribute_changed?, :score, from: nil, to: 3)).to be false
|
|
594
543
|
end
|
|
595
544
|
|
|
596
|
-
it
|
|
545
|
+
it 'returns false using (attribute)_changed?' do
|
|
597
546
|
expect(person.score_changed?(from: nil, to: 3)).to be false
|
|
598
547
|
end
|
|
599
548
|
end
|
|
600
549
|
|
|
601
|
-
context
|
|
602
|
-
|
|
550
|
+
context 'when only the to is correct' do
|
|
603
551
|
before do
|
|
604
552
|
person.score = 2
|
|
605
553
|
end
|
|
606
554
|
|
|
607
|
-
it
|
|
555
|
+
it 'returns false' do
|
|
608
556
|
expect(person.send(:attribute_changed?, :score, from: 1, to: 2)).to be false
|
|
609
557
|
end
|
|
610
558
|
|
|
611
|
-
it
|
|
559
|
+
it 'returns false using (attribute)_changed?' do
|
|
612
560
|
expect(person.score_changed?(from: 1, to: 2)).to be false
|
|
613
561
|
end
|
|
614
562
|
end
|
|
615
563
|
|
|
616
|
-
context
|
|
617
|
-
|
|
564
|
+
context 'when the from and to are correct' do
|
|
618
565
|
before do
|
|
619
566
|
person.score = 2
|
|
620
567
|
end
|
|
621
568
|
|
|
622
|
-
it
|
|
569
|
+
it 'returns true' do
|
|
623
570
|
expect(person.send(:attribute_changed?, :score, from: nil, to: 2)).to be true
|
|
624
571
|
end
|
|
625
572
|
|
|
626
|
-
it
|
|
573
|
+
it 'returns true using (attribute)_changed?' do
|
|
627
574
|
expect(person.score_changed?(from: nil, to: 2)).to be true
|
|
628
575
|
end
|
|
629
576
|
end
|
|
630
577
|
|
|
631
|
-
context
|
|
632
|
-
|
|
578
|
+
context 'when value is mongoized' do
|
|
633
579
|
before do
|
|
634
|
-
person.score =
|
|
580
|
+
person.score = '2'
|
|
635
581
|
end
|
|
636
582
|
|
|
637
|
-
it
|
|
583
|
+
it 'returns true with mongoized value' do
|
|
638
584
|
expect(person.send(:attribute_changed?, :score, from: nil, to: 2)).to be true
|
|
639
585
|
end
|
|
640
586
|
|
|
641
|
-
it
|
|
587
|
+
it 'returns true with mongoized value using (attribute)_changed?' do
|
|
642
588
|
expect(person.score_changed?(from: nil, to: 2)).to be true
|
|
643
589
|
end
|
|
644
590
|
end
|
|
645
591
|
|
|
646
|
-
context
|
|
647
|
-
|
|
592
|
+
context 'when value is mongoized' do
|
|
648
593
|
before do
|
|
649
|
-
person.score =
|
|
594
|
+
person.score = '2'
|
|
650
595
|
end
|
|
651
596
|
|
|
652
|
-
it
|
|
653
|
-
expect(person.send(:attribute_changed?, :score, from: nil, to:
|
|
597
|
+
it 'returns false with unmongoized value' do
|
|
598
|
+
expect(person.send(:attribute_changed?, :score, from: nil, to: '2')).to be false
|
|
654
599
|
end
|
|
655
600
|
|
|
656
|
-
it
|
|
657
|
-
expect(person.score_changed?(from: nil, to:
|
|
601
|
+
it 'returns false with unmongoized value using (attribute)_changed?' do
|
|
602
|
+
expect(person.score_changed?(from: nil, to: '2')).to be false
|
|
658
603
|
end
|
|
659
604
|
end
|
|
660
605
|
end
|
|
661
606
|
end
|
|
662
607
|
end
|
|
663
608
|
|
|
664
|
-
describe
|
|
665
|
-
|
|
666
|
-
context "when the attribute differs from the default value" do
|
|
667
|
-
|
|
609
|
+
describe '#attribute_changed_from_default?' do
|
|
610
|
+
context 'when the attribute differs from the default value' do
|
|
668
611
|
let(:person) do
|
|
669
612
|
Person.new(age: 33)
|
|
670
613
|
end
|
|
671
614
|
|
|
672
|
-
it
|
|
615
|
+
it 'returns true' do
|
|
673
616
|
expect(person).to be_age_changed_from_default
|
|
674
617
|
end
|
|
675
618
|
end
|
|
676
619
|
|
|
677
|
-
context
|
|
678
|
-
|
|
620
|
+
context 'when the attribute is the same as the default' do
|
|
679
621
|
let(:person) do
|
|
680
622
|
Person.new
|
|
681
623
|
end
|
|
682
624
|
|
|
683
|
-
it
|
|
684
|
-
expect(person).
|
|
625
|
+
it 'returns false' do
|
|
626
|
+
expect(person).not_to be_age_changed_from_default
|
|
685
627
|
end
|
|
686
628
|
end
|
|
687
629
|
end
|
|
688
630
|
|
|
689
|
-
describe
|
|
690
|
-
|
|
691
|
-
context "when the attribute has changed from the persisted value" do
|
|
692
|
-
|
|
631
|
+
describe '#attribute_was' do
|
|
632
|
+
context 'when the attribute has changed from the persisted value' do
|
|
693
633
|
let(:person) do
|
|
694
|
-
Person.new(title:
|
|
634
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
695
635
|
end
|
|
696
636
|
|
|
697
637
|
before do
|
|
698
|
-
person.title =
|
|
638
|
+
person.title = 'Captain Obvious'
|
|
699
639
|
end
|
|
700
640
|
|
|
701
|
-
it
|
|
702
|
-
expect(person.send(:attribute_was,
|
|
641
|
+
it 'returns the old value' do
|
|
642
|
+
expect(person.send(:attribute_was, 'title')).to eq('Grand Poobah')
|
|
703
643
|
end
|
|
704
644
|
|
|
705
|
-
it
|
|
706
|
-
expect(person.title_was).to eq(
|
|
645
|
+
it 'allows access via (attribute)_was' do
|
|
646
|
+
expect(person.title_was).to eq('Grand Poobah')
|
|
707
647
|
end
|
|
708
648
|
|
|
709
|
-
context
|
|
710
|
-
|
|
649
|
+
context 'when the field is aliased' do
|
|
711
650
|
let(:person) do
|
|
712
|
-
Person.new(test:
|
|
651
|
+
Person.new(test: 'Aliased 1').tap(&:move_changes)
|
|
713
652
|
end
|
|
714
653
|
|
|
715
654
|
before do
|
|
716
|
-
person.test =
|
|
655
|
+
person.test = 'Aliased 2'
|
|
717
656
|
end
|
|
718
657
|
|
|
719
|
-
it
|
|
720
|
-
expect(person.send(:attribute_was,
|
|
658
|
+
it 'returns the old value' do
|
|
659
|
+
expect(person.send(:attribute_was, 'test')).to eq('Aliased 1')
|
|
721
660
|
end
|
|
722
661
|
|
|
723
|
-
it
|
|
724
|
-
expect(person.test_was).to eq(
|
|
662
|
+
it 'allows access via (attribute)_was' do
|
|
663
|
+
expect(person.test_was).to eq('Aliased 1')
|
|
725
664
|
end
|
|
726
665
|
end
|
|
727
666
|
end
|
|
728
667
|
|
|
729
|
-
context
|
|
730
|
-
|
|
668
|
+
context 'when the attribute has not changed from the persisted value' do
|
|
731
669
|
let!(:person) do
|
|
732
|
-
Person.new(title:
|
|
670
|
+
Person.new(title: 'Grand Poobah').tap(&:move_changes)
|
|
733
671
|
end
|
|
734
672
|
|
|
735
|
-
it
|
|
736
|
-
expect(person.send(:attribute_was,
|
|
673
|
+
it 'returns the original value' do
|
|
674
|
+
expect(person.send(:attribute_was, 'title')).to eq('Grand Poobah')
|
|
675
|
+
end
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
context 'when the attribute is a Hash field stored as a BSON::Document' do
|
|
679
|
+
let(:person) do
|
|
680
|
+
Person.new(map: BSON::Document.new('foo' => true)).tap(&:move_changes)
|
|
681
|
+
end
|
|
682
|
+
|
|
683
|
+
before do
|
|
684
|
+
person.map['bar'] = true
|
|
685
|
+
end
|
|
686
|
+
|
|
687
|
+
it 'returns a BSON::Document, consistent with the field getter' do
|
|
688
|
+
expect(person.map_was).to be_a(BSON::Document)
|
|
689
|
+
end
|
|
690
|
+
|
|
691
|
+
it 'returns the correct previous value' do
|
|
692
|
+
expect(person.map_was).to eq('foo' => true)
|
|
737
693
|
end
|
|
738
694
|
end
|
|
739
695
|
end
|
|
740
696
|
|
|
741
697
|
describe '#attribute_previously_was' do
|
|
742
698
|
let(:previous_title) do
|
|
743
|
-
|
|
699
|
+
'Grand Poobah'
|
|
744
700
|
end
|
|
745
701
|
|
|
746
702
|
let(:age) do
|
|
@@ -752,7 +708,7 @@ describe Mongoid::Changeable do
|
|
|
752
708
|
end
|
|
753
709
|
|
|
754
710
|
let(:updated_title) do
|
|
755
|
-
|
|
711
|
+
'Captain Obvious'
|
|
756
712
|
end
|
|
757
713
|
|
|
758
714
|
before do
|
|
@@ -761,21 +717,21 @@ describe Mongoid::Changeable do
|
|
|
761
717
|
end
|
|
762
718
|
|
|
763
719
|
context 'when attribute changed' do
|
|
764
|
-
it
|
|
765
|
-
expect(person.send(:attribute_previously_was,
|
|
720
|
+
it 'returns the old value' do
|
|
721
|
+
expect(person.send(:attribute_previously_was, 'title')).to eq(previous_title)
|
|
766
722
|
end
|
|
767
723
|
|
|
768
|
-
it
|
|
724
|
+
it 'allows access via (attribute)_was' do
|
|
769
725
|
expect(person.title_previously_was).to eq(previous_title)
|
|
770
726
|
end
|
|
771
727
|
end
|
|
772
728
|
|
|
773
729
|
context 'when attribute did not change' do
|
|
774
|
-
it
|
|
775
|
-
expect(person.send(:attribute_previously_was,
|
|
730
|
+
it 'returns the same value' do
|
|
731
|
+
expect(person.send(:attribute_previously_was, 'age')).to eq(age)
|
|
776
732
|
end
|
|
777
733
|
|
|
778
|
-
it
|
|
734
|
+
it 'allows access via (attribute)_was' do
|
|
779
735
|
expect(person.age_previously_was).to eq(age)
|
|
780
736
|
end
|
|
781
737
|
end
|
|
@@ -785,25 +741,22 @@ describe Mongoid::Changeable do
|
|
|
785
741
|
expect(person.title_previously_was).to be_nil
|
|
786
742
|
expect(person.age_previously_was).to be_nil
|
|
787
743
|
end
|
|
788
|
-
|
|
789
744
|
end
|
|
790
745
|
|
|
791
|
-
describe
|
|
792
|
-
|
|
746
|
+
describe '#attribute_will_change!' do
|
|
793
747
|
let(:aliases) do
|
|
794
|
-
[
|
|
748
|
+
[ '007' ]
|
|
795
749
|
end
|
|
796
750
|
|
|
797
751
|
let(:person) do
|
|
798
|
-
Person.new(aliases: aliases, test:
|
|
752
|
+
Person.new(aliases: aliases, test: 'Aliased 1')
|
|
799
753
|
end
|
|
800
754
|
|
|
801
755
|
before do
|
|
802
756
|
person.changed_attributes.clear
|
|
803
757
|
end
|
|
804
758
|
|
|
805
|
-
context
|
|
806
|
-
|
|
759
|
+
context 'when the value has not changed' do
|
|
807
760
|
before do
|
|
808
761
|
person.aliases_will_change!
|
|
809
762
|
end
|
|
@@ -812,35 +765,32 @@ describe Mongoid::Changeable do
|
|
|
812
765
|
person.changes
|
|
813
766
|
end
|
|
814
767
|
|
|
815
|
-
it
|
|
768
|
+
it 'does not return the value in the changes' do
|
|
816
769
|
expect(changes).to be_empty
|
|
817
770
|
end
|
|
818
771
|
|
|
819
|
-
it
|
|
820
|
-
expect(person).
|
|
772
|
+
it 'is not flagged as changed' do
|
|
773
|
+
expect(person).not_to be_changed
|
|
821
774
|
end
|
|
822
775
|
end
|
|
823
776
|
|
|
824
|
-
context
|
|
825
|
-
|
|
777
|
+
context 'when the value has changed' do
|
|
826
778
|
before do
|
|
827
779
|
person.aliases_will_change!
|
|
828
|
-
person.aliases <<
|
|
780
|
+
person.aliases << '008'
|
|
829
781
|
end
|
|
830
782
|
|
|
831
783
|
let(:changes) do
|
|
832
784
|
person.changes
|
|
833
785
|
end
|
|
834
786
|
|
|
835
|
-
it
|
|
836
|
-
expect(changes).to eq({
|
|
787
|
+
it 'returns the value in the changes' do
|
|
788
|
+
expect(changes).to eq({ 'aliases' => [ [ '007' ], %w[007 008] ] })
|
|
837
789
|
end
|
|
838
790
|
end
|
|
839
791
|
|
|
840
|
-
context
|
|
841
|
-
|
|
842
|
-
context "when the attribute has not been cloned" do
|
|
843
|
-
|
|
792
|
+
context 'when the value is duplicable' do
|
|
793
|
+
context 'when the attribute has not been cloned' do
|
|
844
794
|
before do
|
|
845
795
|
person.aliases_will_change!
|
|
846
796
|
end
|
|
@@ -849,20 +799,19 @@ describe Mongoid::Changeable do
|
|
|
849
799
|
person.changed_attributes
|
|
850
800
|
end
|
|
851
801
|
|
|
852
|
-
it
|
|
853
|
-
expect(changed[
|
|
802
|
+
it 'clones the value' do
|
|
803
|
+
expect(changed['aliases']).not_to equal(aliases)
|
|
854
804
|
end
|
|
855
805
|
|
|
856
|
-
it
|
|
857
|
-
expect(changed[
|
|
806
|
+
it 'puts the old value in the changes' do
|
|
807
|
+
expect(changed['aliases']).to eq(aliases)
|
|
858
808
|
end
|
|
859
809
|
end
|
|
860
810
|
|
|
861
|
-
context
|
|
862
|
-
|
|
811
|
+
context 'when the attribute has been flagged' do
|
|
863
812
|
before do
|
|
864
|
-
person.changed_attributes[
|
|
865
|
-
expect(aliases).
|
|
813
|
+
person.changed_attributes['aliases'] = aliases
|
|
814
|
+
expect(aliases).not_to receive(:clone)
|
|
866
815
|
person.aliases_will_change!
|
|
867
816
|
end
|
|
868
817
|
|
|
@@ -870,321 +819,295 @@ describe Mongoid::Changeable do
|
|
|
870
819
|
person.changed_attributes
|
|
871
820
|
end
|
|
872
821
|
|
|
873
|
-
it
|
|
874
|
-
expect(changed[
|
|
822
|
+
it 'does not clone the value' do
|
|
823
|
+
expect(changed['aliases']).to equal(aliases)
|
|
875
824
|
end
|
|
876
825
|
|
|
877
|
-
it
|
|
878
|
-
expect(changed[
|
|
826
|
+
it 'retains the first value in the changes' do
|
|
827
|
+
expect(changed['aliases']).to eq(aliases)
|
|
879
828
|
end
|
|
880
829
|
end
|
|
881
830
|
end
|
|
882
831
|
end
|
|
883
832
|
|
|
884
|
-
describe
|
|
885
|
-
|
|
886
|
-
context "when the document has changed" do
|
|
887
|
-
|
|
833
|
+
describe '#changed' do
|
|
834
|
+
context 'when the document has changed' do
|
|
888
835
|
let(:person) do
|
|
889
|
-
Person.instantiate(title:
|
|
836
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
890
837
|
end
|
|
891
838
|
|
|
892
839
|
before do
|
|
893
|
-
person.title =
|
|
840
|
+
person.title = 'Captain Obvious'
|
|
894
841
|
end
|
|
895
842
|
|
|
896
|
-
it
|
|
897
|
-
expect(person.changed).to include(
|
|
843
|
+
it 'returns an array of changed field names' do
|
|
844
|
+
expect(person.changed).to include('title')
|
|
898
845
|
end
|
|
899
|
-
|
|
900
846
|
end
|
|
901
847
|
|
|
902
|
-
context
|
|
903
|
-
|
|
848
|
+
context 'When the document has changed but changed back to the original' do
|
|
904
849
|
let(:person) do
|
|
905
|
-
Person.instantiate(title:
|
|
850
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
906
851
|
end
|
|
907
852
|
|
|
908
853
|
before do
|
|
909
|
-
person.title =
|
|
854
|
+
person.title = 'Captain Obvious'
|
|
910
855
|
person.title = nil
|
|
911
856
|
end
|
|
912
857
|
|
|
913
|
-
it
|
|
914
|
-
expect(person.changed).not_to include(
|
|
858
|
+
it 'returns an array of changed field names' do
|
|
859
|
+
expect(person.changed).not_to include('title')
|
|
915
860
|
end
|
|
916
|
-
|
|
917
861
|
end
|
|
918
862
|
|
|
919
|
-
context
|
|
920
|
-
|
|
863
|
+
context 'when the document has not changed' do
|
|
921
864
|
let(:person) do
|
|
922
865
|
Person.instantiate({})
|
|
923
866
|
end
|
|
924
867
|
|
|
925
|
-
it
|
|
926
|
-
expect(person.changed).
|
|
868
|
+
it 'does not include non changed fields' do
|
|
869
|
+
expect(person.changed).not_to include('title')
|
|
927
870
|
end
|
|
928
871
|
end
|
|
929
872
|
|
|
930
|
-
context
|
|
931
|
-
|
|
873
|
+
context 'when the document is embedded' do
|
|
932
874
|
let(:person) do
|
|
933
875
|
Person.create!
|
|
934
876
|
end
|
|
935
877
|
|
|
936
878
|
let!(:name) do
|
|
937
|
-
person.create_name(first_name:
|
|
879
|
+
person.create_name(first_name: 'Layne', last_name: 'Staley')
|
|
938
880
|
end
|
|
939
881
|
|
|
940
|
-
context
|
|
941
|
-
|
|
882
|
+
context 'when changing attributes via []' do
|
|
942
883
|
before do
|
|
943
|
-
person.name[
|
|
884
|
+
person.name['a'] = 'testing'
|
|
944
885
|
end
|
|
945
886
|
|
|
946
|
-
it
|
|
887
|
+
it 'returns true' do
|
|
947
888
|
expect(person.name).to be_changed
|
|
948
889
|
end
|
|
949
890
|
end
|
|
950
891
|
end
|
|
951
892
|
end
|
|
952
893
|
|
|
953
|
-
describe
|
|
954
|
-
|
|
955
|
-
context "when the document has changed" do
|
|
956
|
-
|
|
894
|
+
describe '#changed?' do
|
|
895
|
+
context 'when the document has changed' do
|
|
957
896
|
let(:person) do
|
|
958
|
-
Person.new(title:
|
|
897
|
+
Person.new(title: 'Grand Poobah')
|
|
959
898
|
end
|
|
960
899
|
|
|
961
900
|
before do
|
|
962
|
-
person.title =
|
|
901
|
+
person.title = 'Captain Obvious'
|
|
963
902
|
end
|
|
964
903
|
|
|
965
|
-
it
|
|
904
|
+
it 'returns true' do
|
|
966
905
|
expect(person).to be_changed
|
|
967
906
|
end
|
|
968
907
|
end
|
|
969
908
|
|
|
970
|
-
context
|
|
971
|
-
|
|
972
|
-
context "when the field has not changed" do
|
|
973
|
-
|
|
909
|
+
context 'when a hash field has been accessed' do
|
|
910
|
+
context 'when the field has not changed' do
|
|
974
911
|
let(:person) do
|
|
975
|
-
Person.create!(map: { name:
|
|
912
|
+
Person.create!(map: { name: 'value' })
|
|
976
913
|
end
|
|
977
914
|
|
|
978
915
|
before do
|
|
979
916
|
person.map
|
|
980
917
|
end
|
|
981
918
|
|
|
982
|
-
it
|
|
983
|
-
expect(person).
|
|
919
|
+
it 'returns false' do
|
|
920
|
+
expect(person).not_to be_changed
|
|
984
921
|
end
|
|
985
922
|
end
|
|
986
923
|
|
|
987
|
-
context
|
|
988
|
-
|
|
924
|
+
context 'when the field is changed' do
|
|
989
925
|
let(:person) do
|
|
990
|
-
Person.create!(map: { name:
|
|
926
|
+
Person.create!(map: { name: 'value' })
|
|
991
927
|
end
|
|
992
928
|
|
|
993
929
|
before do
|
|
994
|
-
person.map = { name:
|
|
930
|
+
person.map = { name: 'another' }
|
|
995
931
|
end
|
|
996
932
|
|
|
997
|
-
it
|
|
933
|
+
it 'returns true' do
|
|
998
934
|
expect(person).to be_changed
|
|
999
935
|
end
|
|
1000
936
|
end
|
|
1001
937
|
|
|
1002
|
-
context
|
|
1003
|
-
|
|
938
|
+
context 'when a dynamic field is changed in place' do
|
|
1004
939
|
let(:person) do
|
|
1005
|
-
Person.create!(other_name: { full: {first: 'first', last: 'last'} })
|
|
940
|
+
Person.create!(other_name: { full: { first: 'first', last: 'last' } })
|
|
1006
941
|
end
|
|
1007
942
|
|
|
1008
943
|
before do
|
|
1009
944
|
person.other_name[:full][:first] = 'Name'
|
|
1010
945
|
end
|
|
1011
946
|
|
|
1012
|
-
it
|
|
1013
|
-
expect(person.changes).
|
|
947
|
+
it 'returns true' do
|
|
948
|
+
expect(person.changes).not_to be_empty
|
|
1014
949
|
expect(person).to be_changed
|
|
1015
950
|
end
|
|
1016
951
|
end
|
|
1017
952
|
end
|
|
1018
953
|
|
|
1019
|
-
context
|
|
1020
|
-
|
|
954
|
+
context 'when the document has not changed' do
|
|
1021
955
|
let(:acolyte) do
|
|
1022
|
-
Acolyte.instantiate(
|
|
956
|
+
Acolyte.instantiate('_id' => BSON::ObjectId.new)
|
|
1023
957
|
end
|
|
1024
958
|
|
|
1025
|
-
it
|
|
1026
|
-
expect(acolyte).
|
|
959
|
+
it 'returns false' do
|
|
960
|
+
expect(acolyte).not_to be_changed
|
|
1027
961
|
end
|
|
1028
962
|
end
|
|
1029
963
|
|
|
1030
|
-
context
|
|
1031
|
-
|
|
964
|
+
context 'when a child has changed' do
|
|
1032
965
|
let(:person) do
|
|
1033
966
|
Person.create!
|
|
1034
967
|
end
|
|
1035
968
|
|
|
1036
969
|
let!(:address) do
|
|
1037
|
-
person.addresses.create!(street:
|
|
970
|
+
person.addresses.create!(street: 'hobrecht')
|
|
1038
971
|
end
|
|
1039
972
|
|
|
1040
973
|
before do
|
|
1041
974
|
address.number = 10
|
|
1042
975
|
end
|
|
1043
976
|
|
|
1044
|
-
it
|
|
977
|
+
it 'returns true' do
|
|
1045
978
|
expect(person).to be_changed
|
|
1046
979
|
end
|
|
1047
980
|
end
|
|
1048
981
|
|
|
1049
|
-
context
|
|
1050
|
-
|
|
982
|
+
context 'when changed? has been called before child elements size change' do
|
|
1051
983
|
let(:person) do
|
|
1052
984
|
Person.create!
|
|
1053
985
|
end
|
|
1054
986
|
|
|
1055
987
|
let(:address) do
|
|
1056
|
-
person.addresses.create!(street:
|
|
988
|
+
person.addresses.create!(street: 'hobrecht')
|
|
1057
989
|
end
|
|
1058
990
|
|
|
1059
991
|
let!(:location) do
|
|
1060
|
-
address.locations.create!(name:
|
|
992
|
+
address.locations.create!(name: 'home')
|
|
1061
993
|
end
|
|
1062
994
|
|
|
1063
995
|
before do
|
|
1064
996
|
person.changed?
|
|
1065
997
|
end
|
|
1066
998
|
|
|
1067
|
-
context
|
|
1068
|
-
|
|
999
|
+
context 'when adding via new' do
|
|
1069
1000
|
before do
|
|
1070
1001
|
address.locations.new
|
|
1071
1002
|
end
|
|
1072
1003
|
|
|
1073
|
-
it
|
|
1004
|
+
it 'returns true' do
|
|
1074
1005
|
expect(person).to be_changed
|
|
1075
1006
|
end
|
|
1076
1007
|
end
|
|
1077
1008
|
|
|
1078
|
-
context
|
|
1079
|
-
|
|
1009
|
+
context 'when adding via build' do
|
|
1080
1010
|
before do
|
|
1081
1011
|
address.locations.build
|
|
1082
1012
|
end
|
|
1083
1013
|
|
|
1084
|
-
it
|
|
1014
|
+
it 'returns true' do
|
|
1085
1015
|
expect(person).to be_changed
|
|
1086
1016
|
end
|
|
1087
1017
|
end
|
|
1088
1018
|
|
|
1089
|
-
context
|
|
1090
|
-
|
|
1019
|
+
context 'when adding via create' do
|
|
1091
1020
|
before do
|
|
1092
1021
|
address.locations.create!
|
|
1093
1022
|
end
|
|
1094
1023
|
|
|
1095
|
-
it
|
|
1096
|
-
expect(person).
|
|
1024
|
+
it 'returns false' do
|
|
1025
|
+
expect(person).not_to be_changed
|
|
1097
1026
|
end
|
|
1098
1027
|
end
|
|
1099
1028
|
end
|
|
1100
1029
|
|
|
1101
|
-
context
|
|
1102
|
-
|
|
1030
|
+
context 'when a deeply embedded child has changed' do
|
|
1103
1031
|
let(:person) do
|
|
1104
1032
|
Person.create!
|
|
1105
1033
|
end
|
|
1106
1034
|
|
|
1107
1035
|
let(:address) do
|
|
1108
|
-
person.addresses.create!(street:
|
|
1036
|
+
person.addresses.create!(street: 'hobrecht')
|
|
1109
1037
|
end
|
|
1110
1038
|
|
|
1111
1039
|
let!(:location) do
|
|
1112
|
-
address.locations.create!(name:
|
|
1040
|
+
address.locations.create!(name: 'home')
|
|
1113
1041
|
end
|
|
1114
1042
|
|
|
1115
1043
|
before do
|
|
1116
|
-
location.name =
|
|
1044
|
+
location.name = 'work'
|
|
1117
1045
|
end
|
|
1118
1046
|
|
|
1119
|
-
it
|
|
1047
|
+
it 'returns true' do
|
|
1120
1048
|
expect(person).to be_changed
|
|
1121
1049
|
end
|
|
1122
1050
|
end
|
|
1123
1051
|
|
|
1124
|
-
context
|
|
1125
|
-
|
|
1052
|
+
context 'when a child is new' do
|
|
1126
1053
|
let(:person) do
|
|
1127
1054
|
Person.create!
|
|
1128
1055
|
end
|
|
1129
1056
|
|
|
1130
1057
|
let!(:address) do
|
|
1131
|
-
person.addresses.build(street:
|
|
1058
|
+
person.addresses.build(street: 'hobrecht')
|
|
1132
1059
|
end
|
|
1133
1060
|
|
|
1134
|
-
it
|
|
1061
|
+
it 'returns true' do
|
|
1135
1062
|
expect(person).to be_changed
|
|
1136
1063
|
end
|
|
1137
1064
|
end
|
|
1138
1065
|
|
|
1139
|
-
context
|
|
1140
|
-
|
|
1066
|
+
context 'when a deeply embedded child is new' do
|
|
1141
1067
|
let(:person) do
|
|
1142
1068
|
Person.create!
|
|
1143
1069
|
end
|
|
1144
1070
|
|
|
1145
1071
|
let(:address) do
|
|
1146
|
-
person.addresses.create!(street:
|
|
1072
|
+
person.addresses.create!(street: 'hobrecht')
|
|
1147
1073
|
end
|
|
1148
1074
|
|
|
1149
1075
|
let!(:location) do
|
|
1150
|
-
address.locations.build(name:
|
|
1076
|
+
address.locations.build(name: 'home')
|
|
1151
1077
|
end
|
|
1152
1078
|
|
|
1153
|
-
it
|
|
1079
|
+
it 'returns true' do
|
|
1154
1080
|
expect(person).to be_changed
|
|
1155
1081
|
end
|
|
1156
1082
|
end
|
|
1157
1083
|
end
|
|
1158
1084
|
|
|
1159
|
-
describe
|
|
1160
|
-
|
|
1161
|
-
context "when the document has changed" do
|
|
1162
|
-
|
|
1085
|
+
describe '#changes' do
|
|
1086
|
+
context 'when the document has changed' do
|
|
1163
1087
|
let(:person) do
|
|
1164
|
-
Person.instantiate(title:
|
|
1088
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
1165
1089
|
end
|
|
1166
1090
|
|
|
1167
1091
|
before do
|
|
1168
|
-
person.title =
|
|
1092
|
+
person.title = 'Captain Obvious'
|
|
1169
1093
|
end
|
|
1170
1094
|
|
|
1171
|
-
it
|
|
1172
|
-
expect(person.changes[
|
|
1173
|
-
[ nil,
|
|
1095
|
+
it 'returns a hash of changes' do
|
|
1096
|
+
expect(person.changes['title']).to eq(
|
|
1097
|
+
[ nil, 'Captain Obvious' ]
|
|
1174
1098
|
)
|
|
1175
1099
|
end
|
|
1176
1100
|
|
|
1177
|
-
it
|
|
1101
|
+
it 'returns a hash with indifferent access' do
|
|
1178
1102
|
expect(person.changes[:title]).to eq(
|
|
1179
|
-
[ nil,
|
|
1103
|
+
[ nil, 'Captain Obvious' ]
|
|
1180
1104
|
)
|
|
1181
1105
|
end
|
|
1182
1106
|
end
|
|
1183
1107
|
|
|
1184
1108
|
context 'when habtm association changes' do
|
|
1185
|
-
|
|
1186
1109
|
let(:person) do
|
|
1187
|
-
Person.create!(title:
|
|
1110
|
+
Person.create!(title: 'Grand Poobah')
|
|
1188
1111
|
end
|
|
1189
1112
|
|
|
1190
1113
|
let(:user_account) do
|
|
@@ -1195,16 +1118,15 @@ describe Mongoid::Changeable do
|
|
|
1195
1118
|
person.user_accounts << user_account
|
|
1196
1119
|
end
|
|
1197
1120
|
|
|
1198
|
-
it '
|
|
1199
|
-
person.changes.should
|
|
1200
|
-
person.changed_attributes.should
|
|
1121
|
+
it 'does not add to the changes or changed_attributes hash' do
|
|
1122
|
+
person.changes.should eq({})
|
|
1123
|
+
person.changed_attributes.should eq({})
|
|
1201
1124
|
end
|
|
1202
1125
|
end
|
|
1203
1126
|
|
|
1204
1127
|
context 'when habtm association _ids changes' do
|
|
1205
|
-
|
|
1206
1128
|
let(:person) do
|
|
1207
|
-
Person.create!(title:
|
|
1129
|
+
Person.create!(title: 'Grand Poobah')
|
|
1208
1130
|
end
|
|
1209
1131
|
|
|
1210
1132
|
let(:user_account) do
|
|
@@ -1215,16 +1137,15 @@ describe Mongoid::Changeable do
|
|
|
1215
1137
|
person.user_account_ids << user_account._id
|
|
1216
1138
|
end
|
|
1217
1139
|
|
|
1218
|
-
it '
|
|
1219
|
-
person.changes.should
|
|
1220
|
-
person.changed_attributes.should
|
|
1140
|
+
it 'adds to the changes or changed_attributes hash' do
|
|
1141
|
+
person.changes.should eq({ 'user_account_ids' => [ nil, [ user_account._id ] ] })
|
|
1142
|
+
person.changed_attributes.should eq({ 'user_account_ids' => nil })
|
|
1221
1143
|
end
|
|
1222
1144
|
end
|
|
1223
1145
|
|
|
1224
1146
|
context 'when assigning empty list to habtm association' do
|
|
1225
|
-
|
|
1226
1147
|
let(:person) do
|
|
1227
|
-
Person.create!(title:
|
|
1148
|
+
Person.create!(title: 'Grand Poobah', user_accounts: [ user_account ])
|
|
1228
1149
|
end
|
|
1229
1150
|
|
|
1230
1151
|
let(:user_account) do
|
|
@@ -1235,16 +1156,15 @@ describe Mongoid::Changeable do
|
|
|
1235
1156
|
person.user_accounts = []
|
|
1236
1157
|
end
|
|
1237
1158
|
|
|
1238
|
-
it '
|
|
1239
|
-
person.changes.should
|
|
1240
|
-
person.changed_attributes.should
|
|
1159
|
+
it 'does not add to the changes or changed_attributes hash' do
|
|
1160
|
+
person.changes.should eq({})
|
|
1161
|
+
person.changed_attributes.should eq({})
|
|
1241
1162
|
end
|
|
1242
1163
|
end
|
|
1243
1164
|
|
|
1244
1165
|
context 'when assigning empty list to habtm association _ids' do
|
|
1245
|
-
|
|
1246
1166
|
let(:person) do
|
|
1247
|
-
Person.create!(title:
|
|
1167
|
+
Person.create!(title: 'Grand Poobah', user_accounts: [ user_account ])
|
|
1248
1168
|
end
|
|
1249
1169
|
|
|
1250
1170
|
let(:user_account) do
|
|
@@ -1255,266 +1175,246 @@ describe Mongoid::Changeable do
|
|
|
1255
1175
|
person.user_account_ids = []
|
|
1256
1176
|
end
|
|
1257
1177
|
|
|
1258
|
-
it '
|
|
1259
|
-
person.changes.should
|
|
1260
|
-
person.changed_attributes.should
|
|
1178
|
+
it 'does not add to the changes or changed_attributes hash' do
|
|
1179
|
+
person.changes.should eq({ 'user_account_ids' => [ [ user_account._id ], [] ] })
|
|
1180
|
+
person.changed_attributes.should eq({ 'user_account_ids' => [ user_account._id ] })
|
|
1261
1181
|
end
|
|
1262
1182
|
end
|
|
1263
1183
|
|
|
1264
|
-
context
|
|
1265
|
-
|
|
1184
|
+
context 'when the document has not changed' do
|
|
1266
1185
|
let(:acolyte) do
|
|
1267
|
-
Acolyte.instantiate(
|
|
1186
|
+
Acolyte.instantiate('_id' => BSON::ObjectId.new)
|
|
1268
1187
|
end
|
|
1269
1188
|
|
|
1270
|
-
it
|
|
1189
|
+
it 'returns an empty hash' do
|
|
1271
1190
|
expect(acolyte.changes).to be_empty
|
|
1272
1191
|
end
|
|
1273
1192
|
end
|
|
1274
1193
|
end
|
|
1275
1194
|
|
|
1276
|
-
describe
|
|
1277
|
-
|
|
1278
|
-
context "when the document has changed" do
|
|
1279
|
-
|
|
1195
|
+
describe '#setters' do
|
|
1196
|
+
context 'when the document has changed' do
|
|
1280
1197
|
let(:person) do
|
|
1281
|
-
Person.new(aliases: [
|
|
1198
|
+
Person.new(aliases: [ '007' ]).tap do |p|
|
|
1282
1199
|
p.new_record = false
|
|
1283
1200
|
p.move_changes
|
|
1284
1201
|
end
|
|
1285
1202
|
end
|
|
1286
1203
|
|
|
1287
|
-
context
|
|
1288
|
-
|
|
1289
|
-
context "when the array has values removed" do
|
|
1290
|
-
|
|
1204
|
+
context 'when an array field has changed' do
|
|
1205
|
+
context 'when the array has values removed' do
|
|
1291
1206
|
before do
|
|
1292
|
-
person.aliases.delete_one(
|
|
1207
|
+
person.aliases.delete_one('007')
|
|
1293
1208
|
end
|
|
1294
1209
|
|
|
1295
1210
|
let!(:setters) do
|
|
1296
1211
|
person.setters
|
|
1297
1212
|
end
|
|
1298
1213
|
|
|
1299
|
-
it
|
|
1300
|
-
expect(setters).to eq({
|
|
1214
|
+
it 'contains array changes in the setters' do
|
|
1215
|
+
expect(setters).to eq({ 'aliases' => [] })
|
|
1301
1216
|
end
|
|
1302
1217
|
end
|
|
1303
1218
|
|
|
1304
|
-
context
|
|
1305
|
-
|
|
1219
|
+
context 'when the array has values added' do
|
|
1306
1220
|
before do
|
|
1307
|
-
person.aliases <<
|
|
1221
|
+
person.aliases << '008'
|
|
1308
1222
|
end
|
|
1309
1223
|
|
|
1310
1224
|
let!(:setters) do
|
|
1311
1225
|
person.setters
|
|
1312
1226
|
end
|
|
1313
1227
|
|
|
1314
|
-
it
|
|
1315
|
-
expect(setters).to eq({
|
|
1228
|
+
it 'contains array changes in the setters' do
|
|
1229
|
+
expect(setters).to eq({ 'aliases' => %w[007 008] })
|
|
1316
1230
|
end
|
|
1317
1231
|
end
|
|
1318
1232
|
|
|
1319
|
-
context
|
|
1320
|
-
|
|
1233
|
+
context 'when the array has changed completely' do
|
|
1321
1234
|
before do
|
|
1322
|
-
person.aliases <<
|
|
1323
|
-
person.aliases.delete_one(
|
|
1235
|
+
person.aliases << '008'
|
|
1236
|
+
person.aliases.delete_one('007')
|
|
1324
1237
|
end
|
|
1325
1238
|
|
|
1326
1239
|
let!(:setters) do
|
|
1327
1240
|
person.setters
|
|
1328
1241
|
end
|
|
1329
1242
|
|
|
1330
|
-
it
|
|
1331
|
-
expect(setters).to eq({
|
|
1243
|
+
it 'does not contain array changes in the setters' do
|
|
1244
|
+
expect(setters).to eq({ 'aliases' => [ '008' ] })
|
|
1332
1245
|
end
|
|
1333
1246
|
end
|
|
1334
1247
|
end
|
|
1335
1248
|
|
|
1336
|
-
context
|
|
1337
|
-
|
|
1249
|
+
context 'when the document is a root document' do
|
|
1338
1250
|
let(:person) do
|
|
1339
|
-
Person.instantiate(title:
|
|
1251
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
1340
1252
|
end
|
|
1341
1253
|
|
|
1342
1254
|
before do
|
|
1343
|
-
person.title =
|
|
1255
|
+
person.title = 'Captain Obvious'
|
|
1344
1256
|
end
|
|
1345
1257
|
|
|
1346
|
-
it
|
|
1347
|
-
expect(person.setters[
|
|
1258
|
+
it 'returns a hash of field names and new values' do
|
|
1259
|
+
expect(person.setters['title']).to eq('Captain Obvious')
|
|
1348
1260
|
end
|
|
1349
1261
|
end
|
|
1350
1262
|
|
|
1351
|
-
context
|
|
1352
|
-
|
|
1353
|
-
let(:
|
|
1354
|
-
let(:address) { person.addresses.create(street: "Oxford St") }
|
|
1263
|
+
context 'when the document is embedded' do
|
|
1264
|
+
let(:person) { Person.create(title: 'Grand Poobah') }
|
|
1265
|
+
let(:address) { person.addresses.create(street: 'Oxford St') }
|
|
1355
1266
|
|
|
1356
|
-
before { address.street =
|
|
1267
|
+
before { address.street = 'Bond St' }
|
|
1357
1268
|
|
|
1358
|
-
it
|
|
1269
|
+
it 'returns a hash of field names and new values' do
|
|
1359
1270
|
expect(address.setters).to eq(
|
|
1360
|
-
{
|
|
1271
|
+
{ 'addresses.0.street' => 'Bond St' }
|
|
1361
1272
|
)
|
|
1362
1273
|
end
|
|
1363
1274
|
|
|
1364
|
-
context
|
|
1365
|
-
let(:location) { address.locations.create(name:
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1275
|
+
context 'when the document is embedded multiple levels' do
|
|
1276
|
+
let(:location) { address.locations.create(name: 'Home') }
|
|
1277
|
+
|
|
1278
|
+
before { location.name = 'Work' }
|
|
1279
|
+
|
|
1280
|
+
it 'returns the proper hash with locations' do
|
|
1369
1281
|
expect(location.setters).to eq(
|
|
1370
|
-
{
|
|
1282
|
+
{ 'addresses.0.locations.0.name' => 'Work' }
|
|
1371
1283
|
)
|
|
1372
1284
|
end
|
|
1373
1285
|
end
|
|
1374
1286
|
end
|
|
1375
1287
|
end
|
|
1376
1288
|
|
|
1377
|
-
context
|
|
1378
|
-
|
|
1289
|
+
context 'when the document has not changed' do
|
|
1379
1290
|
let(:acolyte) do
|
|
1380
|
-
Acolyte.instantiate(
|
|
1291
|
+
Acolyte.instantiate('_id' => BSON::ObjectId.new)
|
|
1381
1292
|
end
|
|
1382
1293
|
|
|
1383
|
-
it
|
|
1294
|
+
it 'returns an empty hash' do
|
|
1384
1295
|
expect(acolyte.setters).to be_empty
|
|
1385
1296
|
end
|
|
1386
1297
|
end
|
|
1387
1298
|
end
|
|
1388
1299
|
|
|
1389
|
-
describe
|
|
1390
|
-
|
|
1300
|
+
describe '#previous_changes' do
|
|
1391
1301
|
let(:person) do
|
|
1392
|
-
Person.new(title:
|
|
1302
|
+
Person.new(title: 'Grand Poobah')
|
|
1393
1303
|
end
|
|
1394
1304
|
|
|
1395
1305
|
before do
|
|
1396
|
-
person.title =
|
|
1306
|
+
person.title = 'Captain Obvious'
|
|
1397
1307
|
end
|
|
1398
1308
|
|
|
1399
|
-
context
|
|
1400
|
-
|
|
1309
|
+
context 'when the document has been saved' do
|
|
1401
1310
|
before do
|
|
1402
1311
|
person.save!
|
|
1403
1312
|
end
|
|
1404
1313
|
|
|
1405
|
-
it
|
|
1406
|
-
expect(person.previous_changes[
|
|
1407
|
-
[ nil,
|
|
1314
|
+
it 'returns the changes before the save' do
|
|
1315
|
+
expect(person.previous_changes['title']).to eq(
|
|
1316
|
+
[ nil, 'Captain Obvious' ]
|
|
1408
1317
|
)
|
|
1409
1318
|
end
|
|
1410
1319
|
end
|
|
1411
1320
|
|
|
1412
|
-
context
|
|
1413
|
-
|
|
1414
|
-
it "returns an empty hash" do
|
|
1321
|
+
context 'when the document has not been saved' do
|
|
1322
|
+
it 'returns an empty hash' do
|
|
1415
1323
|
expect(person.previous_changes).to be_empty
|
|
1416
1324
|
end
|
|
1417
1325
|
end
|
|
1418
1326
|
end
|
|
1419
1327
|
|
|
1420
|
-
describe
|
|
1421
|
-
|
|
1328
|
+
describe '#move_changes' do
|
|
1422
1329
|
let(:person) do
|
|
1423
|
-
Person.new(title:
|
|
1330
|
+
Person.new(title: 'Sir')
|
|
1424
1331
|
end
|
|
1425
1332
|
|
|
1426
1333
|
before do
|
|
1427
|
-
person.atomic_pulls[
|
|
1334
|
+
person.atomic_pulls['addresses'] = Address.new
|
|
1428
1335
|
person.atomic_unsets << Address.new
|
|
1429
|
-
person.delayed_atomic_sets[
|
|
1336
|
+
person.delayed_atomic_sets['addresses'] = Address.new
|
|
1430
1337
|
person.move_changes
|
|
1431
1338
|
end
|
|
1432
1339
|
|
|
1433
|
-
it
|
|
1340
|
+
it 'clears the atomic pulls' do
|
|
1434
1341
|
expect(person.atomic_pulls).to be_empty
|
|
1435
1342
|
end
|
|
1436
1343
|
|
|
1437
|
-
it
|
|
1344
|
+
it 'clears the atomic unsets' do
|
|
1438
1345
|
expect(person.atomic_unsets).to be_empty
|
|
1439
1346
|
end
|
|
1440
1347
|
|
|
1441
|
-
it
|
|
1348
|
+
it 'clears the delayed atomic sets' do
|
|
1442
1349
|
expect(person.delayed_atomic_sets).to be_empty
|
|
1443
1350
|
end
|
|
1444
1351
|
|
|
1445
|
-
it
|
|
1352
|
+
it 'clears the changed attributes' do
|
|
1446
1353
|
expect(person.changed_attributes).to be_empty
|
|
1447
1354
|
end
|
|
1448
1355
|
end
|
|
1449
1356
|
|
|
1450
|
-
describe
|
|
1451
|
-
|
|
1452
|
-
context "when the attribute has changed" do
|
|
1453
|
-
|
|
1357
|
+
describe '#reset_attribute!' do
|
|
1358
|
+
context 'when the attribute has changed' do
|
|
1454
1359
|
let(:person) do
|
|
1455
|
-
Person.instantiate(title:
|
|
1360
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
1456
1361
|
end
|
|
1457
1362
|
|
|
1458
1363
|
before do
|
|
1459
|
-
person.title =
|
|
1460
|
-
person.send(:reset_attribute!,
|
|
1364
|
+
person.title = 'Captain Obvious'
|
|
1365
|
+
person.send(:reset_attribute!, 'title')
|
|
1461
1366
|
end
|
|
1462
1367
|
|
|
1463
|
-
it
|
|
1368
|
+
it 'resets the value to the original' do
|
|
1464
1369
|
expect(person.title).to be_nil
|
|
1465
1370
|
end
|
|
1466
1371
|
|
|
1467
|
-
it
|
|
1372
|
+
it 'allows access via reset_(attribute)!' do
|
|
1468
1373
|
expect(person.title).to be_nil
|
|
1469
1374
|
end
|
|
1470
1375
|
|
|
1471
|
-
it
|
|
1472
|
-
expect(person.changed).
|
|
1376
|
+
it 'removes the field from the changes' do
|
|
1377
|
+
expect(person.changed).not_to include('title')
|
|
1473
1378
|
end
|
|
1474
1379
|
|
|
1475
|
-
context
|
|
1476
|
-
|
|
1380
|
+
context 'when the field is aliased' do
|
|
1477
1381
|
let(:person) do
|
|
1478
|
-
Person.instantiate(test:
|
|
1382
|
+
Person.instantiate(test: 'Aliased 1')
|
|
1479
1383
|
end
|
|
1480
1384
|
|
|
1481
1385
|
before do
|
|
1482
|
-
person.test =
|
|
1483
|
-
person.send(:reset_attribute!,
|
|
1386
|
+
person.test = 'Aliased 2'
|
|
1387
|
+
person.send(:reset_attribute!, 'test')
|
|
1484
1388
|
end
|
|
1485
1389
|
|
|
1486
|
-
it
|
|
1390
|
+
it 'resets the value to the original' do
|
|
1487
1391
|
expect(person.test).to be_nil
|
|
1488
1392
|
end
|
|
1489
1393
|
|
|
1490
|
-
it
|
|
1491
|
-
expect(person.changed).
|
|
1394
|
+
it 'removes the field from the changes' do
|
|
1395
|
+
expect(person.changed).not_to include('test')
|
|
1492
1396
|
end
|
|
1493
1397
|
end
|
|
1494
1398
|
end
|
|
1495
1399
|
|
|
1496
|
-
context
|
|
1497
|
-
|
|
1400
|
+
context 'when the attribute has not changed' do
|
|
1498
1401
|
let(:person) do
|
|
1499
|
-
Person.instantiate(title:
|
|
1402
|
+
Person.instantiate(title: 'Grand Poobah')
|
|
1500
1403
|
end
|
|
1501
1404
|
|
|
1502
1405
|
before do
|
|
1503
|
-
person.send(:reset_attribute!,
|
|
1406
|
+
person.send(:reset_attribute!, 'title')
|
|
1504
1407
|
end
|
|
1505
1408
|
|
|
1506
|
-
it
|
|
1409
|
+
it 'does nothing' do
|
|
1507
1410
|
expect(person.title).to be_nil
|
|
1508
1411
|
end
|
|
1509
1412
|
end
|
|
1510
1413
|
end
|
|
1511
1414
|
|
|
1512
|
-
describe
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
context "when the document is new" do
|
|
1517
|
-
|
|
1415
|
+
describe '#reset_attribute_to_default!' do
|
|
1416
|
+
context 'when a default is defined' do
|
|
1417
|
+
context 'when the document is new' do
|
|
1518
1418
|
let(:person) do
|
|
1519
1419
|
Person.new(pets: true)
|
|
1520
1420
|
end
|
|
@@ -1523,13 +1423,12 @@ describe Mongoid::Changeable do
|
|
|
1523
1423
|
person.reset_pets_to_default!
|
|
1524
1424
|
end
|
|
1525
1425
|
|
|
1526
|
-
it
|
|
1426
|
+
it 'resets to the default value' do
|
|
1527
1427
|
expect(person.pets).to eq(false)
|
|
1528
1428
|
end
|
|
1529
1429
|
end
|
|
1530
1430
|
|
|
1531
|
-
context
|
|
1532
|
-
|
|
1431
|
+
context 'when the document is persisted' do
|
|
1533
1432
|
let(:person) do
|
|
1534
1433
|
Person.create!(pets: true)
|
|
1535
1434
|
end
|
|
@@ -1538,48 +1437,45 @@ describe Mongoid::Changeable do
|
|
|
1538
1437
|
person.reset_pets_to_default!
|
|
1539
1438
|
end
|
|
1540
1439
|
|
|
1541
|
-
it
|
|
1440
|
+
it 'resets to the default value' do
|
|
1542
1441
|
expect(person.pets).to eq(false)
|
|
1543
1442
|
end
|
|
1544
1443
|
|
|
1545
|
-
it
|
|
1444
|
+
it 'flags the document dirty' do
|
|
1546
1445
|
expect(person).to be_pets_changed
|
|
1547
1446
|
end
|
|
1548
1447
|
end
|
|
1549
1448
|
end
|
|
1550
1449
|
|
|
1551
|
-
context
|
|
1552
|
-
|
|
1553
|
-
context "when the document is new" do
|
|
1554
|
-
|
|
1450
|
+
context 'when a default is not defined' do
|
|
1451
|
+
context 'when the document is new' do
|
|
1555
1452
|
let(:person) do
|
|
1556
|
-
Person.new(title:
|
|
1453
|
+
Person.new(title: 'test')
|
|
1557
1454
|
end
|
|
1558
1455
|
|
|
1559
1456
|
before do
|
|
1560
1457
|
person.reset_title_to_default!
|
|
1561
1458
|
end
|
|
1562
1459
|
|
|
1563
|
-
it
|
|
1460
|
+
it 'resets to nil' do
|
|
1564
1461
|
expect(person.title).to be_nil
|
|
1565
1462
|
end
|
|
1566
1463
|
end
|
|
1567
1464
|
|
|
1568
|
-
context
|
|
1569
|
-
|
|
1465
|
+
context 'when the document is persisted' do
|
|
1570
1466
|
let(:person) do
|
|
1571
|
-
Person.create!(title:
|
|
1467
|
+
Person.create!(title: 'test')
|
|
1572
1468
|
end
|
|
1573
1469
|
|
|
1574
1470
|
before do
|
|
1575
1471
|
person.reset_title_to_default!
|
|
1576
1472
|
end
|
|
1577
1473
|
|
|
1578
|
-
it
|
|
1474
|
+
it 'resets to nil' do
|
|
1579
1475
|
expect(person.title).to be_nil
|
|
1580
1476
|
end
|
|
1581
1477
|
|
|
1582
|
-
it
|
|
1478
|
+
it 'flags the document dirty' do
|
|
1583
1479
|
expect(person).to be_title_changed
|
|
1584
1480
|
end
|
|
1585
1481
|
end
|
|
@@ -1587,58 +1483,52 @@ describe Mongoid::Changeable do
|
|
|
1587
1483
|
end
|
|
1588
1484
|
|
|
1589
1485
|
describe '#previously_changed?' do
|
|
1590
|
-
|
|
1591
1486
|
let(:person) do
|
|
1592
|
-
Person.new(title:
|
|
1487
|
+
Person.new(title: 'Grand Poobah')
|
|
1593
1488
|
end
|
|
1594
1489
|
|
|
1595
1490
|
before do
|
|
1596
|
-
person.title =
|
|
1491
|
+
person.title = 'Captain Obvious'
|
|
1597
1492
|
end
|
|
1598
1493
|
|
|
1599
|
-
context
|
|
1600
|
-
|
|
1494
|
+
context 'when the document has been saved' do
|
|
1601
1495
|
before do
|
|
1602
1496
|
person.save!
|
|
1603
1497
|
end
|
|
1604
1498
|
|
|
1605
|
-
it
|
|
1499
|
+
it 'returns true' do
|
|
1606
1500
|
expect(person.title_previously_changed?).to be(true)
|
|
1607
1501
|
end
|
|
1608
1502
|
end
|
|
1609
1503
|
|
|
1610
|
-
context
|
|
1611
|
-
|
|
1612
|
-
it "returns false" do
|
|
1504
|
+
context 'when the document has not been saved' do
|
|
1505
|
+
it 'returns false' do
|
|
1613
1506
|
expect(person.title_previously_changed?).to be(false)
|
|
1614
1507
|
end
|
|
1615
1508
|
end
|
|
1616
1509
|
end
|
|
1617
1510
|
|
|
1618
1511
|
describe '#previous_change' do
|
|
1619
|
-
|
|
1620
1512
|
let(:person) do
|
|
1621
|
-
Person.new(title:
|
|
1513
|
+
Person.new(title: 'Grand Poobah')
|
|
1622
1514
|
end
|
|
1623
1515
|
|
|
1624
1516
|
before do
|
|
1625
|
-
person.title =
|
|
1517
|
+
person.title = 'Captain Obvious'
|
|
1626
1518
|
end
|
|
1627
1519
|
|
|
1628
|
-
context
|
|
1629
|
-
|
|
1520
|
+
context 'when the document has been saved' do
|
|
1630
1521
|
before do
|
|
1631
1522
|
person.save!
|
|
1632
1523
|
end
|
|
1633
1524
|
|
|
1634
|
-
it
|
|
1635
|
-
expect(person.title_previous_change).to eq([ nil,
|
|
1525
|
+
it 'returns the changes' do
|
|
1526
|
+
expect(person.title_previous_change).to eq([ nil, 'Captain Obvious' ])
|
|
1636
1527
|
end
|
|
1637
1528
|
end
|
|
1638
1529
|
|
|
1639
|
-
context
|
|
1640
|
-
|
|
1641
|
-
it "returns no changes" do
|
|
1530
|
+
context 'when the document has not been saved' do
|
|
1531
|
+
it 'returns no changes' do
|
|
1642
1532
|
expect(person.title_previous_change).to eq(nil)
|
|
1643
1533
|
end
|
|
1644
1534
|
end
|
|
@@ -1646,26 +1536,26 @@ describe Mongoid::Changeable do
|
|
|
1646
1536
|
|
|
1647
1537
|
describe '#attribute_before_last_save' do
|
|
1648
1538
|
let(:person) do
|
|
1649
|
-
Person.create!(title:
|
|
1539
|
+
Person.create!(title: 'Grand Poobah')
|
|
1650
1540
|
end
|
|
1651
1541
|
|
|
1652
1542
|
before do
|
|
1653
|
-
person.title =
|
|
1543
|
+
person.title = 'Captain Obvious'
|
|
1654
1544
|
end
|
|
1655
1545
|
|
|
1656
|
-
context
|
|
1546
|
+
context 'when the document has been saved' do
|
|
1657
1547
|
before do
|
|
1658
1548
|
person.save!
|
|
1659
1549
|
end
|
|
1660
1550
|
|
|
1661
|
-
it
|
|
1662
|
-
expect(person.attribute_before_last_save(:title)).to eq(
|
|
1663
|
-
expect(person.title_before_last_save).to eq(
|
|
1551
|
+
it 'returns the changes' do
|
|
1552
|
+
expect(person.attribute_before_last_save(:title)).to eq('Grand Poobah')
|
|
1553
|
+
expect(person.title_before_last_save).to eq('Grand Poobah')
|
|
1664
1554
|
end
|
|
1665
1555
|
end
|
|
1666
1556
|
|
|
1667
|
-
context
|
|
1668
|
-
it
|
|
1557
|
+
context 'when the document has not been saved' do
|
|
1558
|
+
it 'returns no changes' do
|
|
1669
1559
|
expect(person.attribute_before_last_save(:title)).to be_nil
|
|
1670
1560
|
expect(person.title_before_last_save).to be_nil
|
|
1671
1561
|
end
|
|
@@ -1674,63 +1564,60 @@ describe Mongoid::Changeable do
|
|
|
1674
1564
|
|
|
1675
1565
|
describe '#saved_change_to_attribute' do
|
|
1676
1566
|
let(:person) do
|
|
1677
|
-
Person.create!(title:
|
|
1567
|
+
Person.create!(title: 'Grand Poobah')
|
|
1678
1568
|
end
|
|
1679
1569
|
|
|
1680
1570
|
before do
|
|
1681
|
-
person.title =
|
|
1571
|
+
person.title = 'Captain Obvious'
|
|
1682
1572
|
end
|
|
1683
1573
|
|
|
1684
|
-
context
|
|
1574
|
+
context 'when the document has been saved' do
|
|
1685
1575
|
before do
|
|
1686
1576
|
person.save!
|
|
1687
1577
|
end
|
|
1688
1578
|
|
|
1689
|
-
it
|
|
1690
|
-
expect(person.saved_change_to_attribute(:title)).to eq([
|
|
1691
|
-
expect(person.saved_change_to_title).to eq([
|
|
1579
|
+
it 'returns the changes' do
|
|
1580
|
+
expect(person.saved_change_to_attribute(:title)).to eq([ 'Grand Poobah', 'Captain Obvious' ])
|
|
1581
|
+
expect(person.saved_change_to_title).to eq([ 'Grand Poobah', 'Captain Obvious' ])
|
|
1692
1582
|
end
|
|
1693
1583
|
end
|
|
1694
1584
|
|
|
1695
|
-
context
|
|
1696
|
-
it
|
|
1697
|
-
expect(person.saved_change_to_attribute(:title)).to eq([nil,
|
|
1698
|
-
expect(person.saved_change_to_title).to eq([nil,
|
|
1585
|
+
context 'when the document has not been saved' do
|
|
1586
|
+
it 'returns changes for the previous save' do
|
|
1587
|
+
expect(person.saved_change_to_attribute(:title)).to eq([ nil, 'Grand Poobah' ])
|
|
1588
|
+
expect(person.saved_change_to_title).to eq([ nil, 'Grand Poobah' ])
|
|
1699
1589
|
end
|
|
1700
1590
|
end
|
|
1701
1591
|
end
|
|
1702
1592
|
|
|
1703
1593
|
describe '#saved_change_to_attribute?' do
|
|
1704
|
-
context
|
|
1594
|
+
context 'when the document has been saved' do
|
|
1705
1595
|
let(:person) do
|
|
1706
|
-
Person.create!(title:
|
|
1707
|
-
end
|
|
1708
|
-
|
|
1709
|
-
before do
|
|
1710
|
-
person.title = "Captain Obvious"
|
|
1596
|
+
Person.create!(title: 'Grand Poobah')
|
|
1711
1597
|
end
|
|
1712
1598
|
|
|
1713
1599
|
before do
|
|
1600
|
+
person.title = 'Captain Obvious'
|
|
1714
1601
|
person.save!
|
|
1715
1602
|
end
|
|
1716
1603
|
|
|
1717
|
-
it
|
|
1604
|
+
it 'detects the changes' do
|
|
1718
1605
|
expect(person.saved_change_to_attribute?(:title)).to be_truthy
|
|
1719
|
-
expect(person.saved_change_to_attribute?(:title, from:
|
|
1720
|
-
expect(person.saved_change_to_attribute?(:title, to:
|
|
1721
|
-
expect(person.saved_change_to_attribute?(:title, from:
|
|
1722
|
-
expect(person.saved_change_to_title?(from:
|
|
1606
|
+
expect(person.saved_change_to_attribute?(:title, from: 'Grand Poobah')).to be_truthy
|
|
1607
|
+
expect(person.saved_change_to_attribute?(:title, to: 'Captain Obvious')).to be_truthy
|
|
1608
|
+
expect(person.saved_change_to_attribute?(:title, from: 'Grand Poobah', to: 'Captain Obvious')).to be_truthy
|
|
1609
|
+
expect(person.saved_change_to_title?(from: 'Grand Poobah', to: 'Captain Obvious')).to be_truthy
|
|
1723
1610
|
expect(person.saved_change_to_attribute?(:age)).to be_falsey
|
|
1724
1611
|
expect(person.saved_change_to_age?).to be_falsey
|
|
1725
1612
|
end
|
|
1726
1613
|
end
|
|
1727
1614
|
|
|
1728
|
-
context
|
|
1615
|
+
context 'when the document has not been saved' do
|
|
1729
1616
|
let(:person) do
|
|
1730
|
-
Person.new(title:
|
|
1617
|
+
Person.new(title: 'Grand Poobah')
|
|
1731
1618
|
end
|
|
1732
1619
|
|
|
1733
|
-
it
|
|
1620
|
+
it 'returns changes for the previous save' do
|
|
1734
1621
|
expect(person.saved_change_to_attribute?(:title)).to be_falsey
|
|
1735
1622
|
expect(person.saved_change_to_title?).to be_falsey
|
|
1736
1623
|
end
|
|
@@ -1739,11 +1626,11 @@ describe Mongoid::Changeable do
|
|
|
1739
1626
|
|
|
1740
1627
|
describe '#will_save_change_to_attribute?' do
|
|
1741
1628
|
let(:person) do
|
|
1742
|
-
Person.create!(title:
|
|
1629
|
+
Person.create!(title: 'Grand Poobah')
|
|
1743
1630
|
end
|
|
1744
1631
|
|
|
1745
1632
|
before do
|
|
1746
|
-
person.title =
|
|
1633
|
+
person.title = 'Captain Obvious'
|
|
1747
1634
|
end
|
|
1748
1635
|
|
|
1749
1636
|
it 'correctly detects changes' do
|
|
@@ -1752,155 +1639,141 @@ describe Mongoid::Changeable do
|
|
|
1752
1639
|
expect(person.will_save_change_to_attribute?(:score)).to eq(false)
|
|
1753
1640
|
expect(person.will_save_change_to_score?).to eq(false)
|
|
1754
1641
|
end
|
|
1755
|
-
|
|
1756
1642
|
end
|
|
1757
1643
|
|
|
1758
|
-
context
|
|
1759
|
-
|
|
1644
|
+
context 'when fields have been defined pre-dirty inclusion' do
|
|
1760
1645
|
let(:document) do
|
|
1761
1646
|
Dokument.new
|
|
1762
1647
|
end
|
|
1763
1648
|
|
|
1764
|
-
it
|
|
1649
|
+
it 'defines a _change method' do
|
|
1765
1650
|
expect(document.updated_at_change).to be_nil
|
|
1766
1651
|
end
|
|
1767
1652
|
|
|
1768
|
-
it
|
|
1653
|
+
it 'defines a _changed? method' do
|
|
1769
1654
|
expect(document.updated_at_changed?).to be false
|
|
1770
1655
|
end
|
|
1771
1656
|
|
|
1772
|
-
it
|
|
1657
|
+
it 'defines a _changes method' do
|
|
1773
1658
|
expect(document.updated_at_was).to be_nil
|
|
1774
1659
|
end
|
|
1775
1660
|
end
|
|
1776
1661
|
|
|
1777
|
-
context
|
|
1778
|
-
|
|
1662
|
+
context 'when only embedded documents change' do
|
|
1779
1663
|
let!(:person) do
|
|
1780
1664
|
Person.create!
|
|
1781
1665
|
end
|
|
1782
1666
|
|
|
1783
|
-
context
|
|
1784
|
-
|
|
1785
|
-
context "when the child is new" do
|
|
1786
|
-
|
|
1667
|
+
context 'when the child is an embeds one' do
|
|
1668
|
+
context 'when the child is new' do
|
|
1787
1669
|
let!(:name) do
|
|
1788
|
-
person.build_name(first_name:
|
|
1670
|
+
person.build_name(first_name: 'Gordon', last_name: 'Ramsay')
|
|
1789
1671
|
end
|
|
1790
1672
|
|
|
1791
|
-
it
|
|
1673
|
+
it 'flags the parent as changed' do
|
|
1792
1674
|
expect(person).to be_changed
|
|
1793
1675
|
end
|
|
1794
1676
|
end
|
|
1795
1677
|
|
|
1796
|
-
context
|
|
1797
|
-
|
|
1678
|
+
context 'when the child is modified' do
|
|
1798
1679
|
let!(:name) do
|
|
1799
|
-
person.create_name(first_name:
|
|
1680
|
+
person.create_name(first_name: 'Gordon', last_name: 'Ramsay')
|
|
1800
1681
|
end
|
|
1801
1682
|
|
|
1802
1683
|
before do
|
|
1803
|
-
name.first_name =
|
|
1684
|
+
name.first_name = 'G'
|
|
1804
1685
|
end
|
|
1805
1686
|
|
|
1806
|
-
it
|
|
1687
|
+
it 'flags the parent as changed' do
|
|
1807
1688
|
expect(person).to be_changed
|
|
1808
1689
|
end
|
|
1809
1690
|
end
|
|
1810
1691
|
|
|
1811
|
-
context
|
|
1812
|
-
|
|
1692
|
+
context 'when the child is not modified' do
|
|
1813
1693
|
let!(:name) do
|
|
1814
|
-
person.create_name(first_name:
|
|
1694
|
+
person.create_name(first_name: 'Gordon', last_name: 'Ramsay')
|
|
1815
1695
|
end
|
|
1816
1696
|
|
|
1817
|
-
it
|
|
1818
|
-
expect(person).
|
|
1697
|
+
it 'does not flag the parent as changed' do
|
|
1698
|
+
expect(person).not_to be_changed
|
|
1819
1699
|
end
|
|
1820
1700
|
end
|
|
1821
1701
|
end
|
|
1822
1702
|
|
|
1823
|
-
context
|
|
1824
|
-
|
|
1825
|
-
context "when a child is new" do
|
|
1826
|
-
|
|
1703
|
+
context 'when the child is an embeds many' do
|
|
1704
|
+
context 'when a child is new' do
|
|
1827
1705
|
let!(:address) do
|
|
1828
|
-
person.addresses.build(street:
|
|
1706
|
+
person.addresses.build(street: 'jakobstr.')
|
|
1829
1707
|
end
|
|
1830
1708
|
|
|
1831
|
-
it
|
|
1709
|
+
it 'flags the parent as changed' do
|
|
1832
1710
|
expect(person).to be_changed
|
|
1833
1711
|
end
|
|
1834
1712
|
end
|
|
1835
1713
|
|
|
1836
|
-
context
|
|
1837
|
-
|
|
1714
|
+
context 'when a child is modified' do
|
|
1838
1715
|
let!(:address) do
|
|
1839
|
-
person.addresses.create!(street:
|
|
1716
|
+
person.addresses.create!(street: 'jakobstr.')
|
|
1840
1717
|
end
|
|
1841
1718
|
|
|
1842
1719
|
before do
|
|
1843
|
-
address.city =
|
|
1720
|
+
address.city = 'Berlin'
|
|
1844
1721
|
end
|
|
1845
1722
|
|
|
1846
|
-
it
|
|
1723
|
+
it 'flags the parent as changed' do
|
|
1847
1724
|
expect(person).to be_changed
|
|
1848
1725
|
end
|
|
1849
1726
|
end
|
|
1850
1727
|
|
|
1851
|
-
context
|
|
1852
|
-
|
|
1728
|
+
context 'when no child is modified' do
|
|
1853
1729
|
let!(:address) do
|
|
1854
|
-
person.addresses.create!(street:
|
|
1730
|
+
person.addresses.create!(street: 'skalitzerstr.')
|
|
1855
1731
|
end
|
|
1856
1732
|
|
|
1857
|
-
it
|
|
1858
|
-
expect(person).
|
|
1733
|
+
it 'does not flag the parent as changed' do
|
|
1734
|
+
expect(person).not_to be_changed
|
|
1859
1735
|
end
|
|
1860
1736
|
end
|
|
1861
1737
|
end
|
|
1862
1738
|
end
|
|
1863
1739
|
|
|
1864
|
-
context
|
|
1865
|
-
|
|
1740
|
+
context 'when changing a hash of hashes' do
|
|
1866
1741
|
let!(:person) do
|
|
1867
|
-
Person.create!(map: {
|
|
1742
|
+
Person.create!(map: { 'test' => {} })
|
|
1868
1743
|
end
|
|
1869
1744
|
|
|
1870
1745
|
before do
|
|
1871
|
-
person.map[
|
|
1746
|
+
person.map['test']['value'] = 10
|
|
1872
1747
|
end
|
|
1873
1748
|
|
|
1874
|
-
it
|
|
1749
|
+
it 'records the changes' do
|
|
1875
1750
|
expect(person.changes).to eq(
|
|
1876
|
-
{
|
|
1751
|
+
{ 'map' => [ { 'test' => {} }, { 'test' => { 'value' => 10 } } ] }
|
|
1877
1752
|
)
|
|
1878
1753
|
end
|
|
1879
1754
|
end
|
|
1880
1755
|
|
|
1881
|
-
context
|
|
1882
|
-
|
|
1756
|
+
context 'when modifying a many to many key' do
|
|
1883
1757
|
let!(:person) do
|
|
1884
1758
|
Person.create!
|
|
1885
1759
|
end
|
|
1886
1760
|
|
|
1887
1761
|
let!(:preference) do
|
|
1888
|
-
Preference.create!(name:
|
|
1762
|
+
Preference.create!(name: 'dirty')
|
|
1889
1763
|
end
|
|
1890
1764
|
|
|
1891
1765
|
before do
|
|
1892
1766
|
person.update_attributes!(preference_ids: [ preference.id ])
|
|
1893
1767
|
end
|
|
1894
1768
|
|
|
1895
|
-
it
|
|
1896
|
-
expect(person.previous_changes[
|
|
1897
|
-
[nil, [ preference.id ]]
|
|
1769
|
+
it 'records the foreign key dirty changes' do
|
|
1770
|
+
expect(person.previous_changes['preference_ids']).to eq(
|
|
1771
|
+
[ nil, [ preference.id ] ]
|
|
1898
1772
|
)
|
|
1899
1773
|
end
|
|
1900
1774
|
end
|
|
1901
1775
|
|
|
1902
|
-
context
|
|
1903
|
-
|
|
1776
|
+
context 'when accessing an array field' do
|
|
1904
1777
|
let!(:person) do
|
|
1905
1778
|
Person.create!
|
|
1906
1779
|
end
|
|
@@ -1909,24 +1782,22 @@ describe Mongoid::Changeable do
|
|
|
1909
1782
|
Person.find(person.id)
|
|
1910
1783
|
end
|
|
1911
1784
|
|
|
1912
|
-
context
|
|
1913
|
-
|
|
1785
|
+
context 'when the field is not changed' do
|
|
1914
1786
|
before do
|
|
1915
1787
|
from_db.preference_ids
|
|
1916
1788
|
end
|
|
1917
1789
|
|
|
1918
|
-
it
|
|
1919
|
-
expect(from_db.changes[
|
|
1790
|
+
it 'flags the change' do
|
|
1791
|
+
expect(from_db.changes['preference_ids']).to eq([ nil, [] ])
|
|
1920
1792
|
end
|
|
1921
1793
|
|
|
1922
|
-
it
|
|
1794
|
+
it 'does not include the changes in the setters' do
|
|
1923
1795
|
expect(from_db.setters).to be_empty
|
|
1924
1796
|
end
|
|
1925
1797
|
end
|
|
1926
1798
|
end
|
|
1927
1799
|
|
|
1928
|
-
context
|
|
1929
|
-
|
|
1800
|
+
context 'when reloading an unchanged document' do
|
|
1930
1801
|
let!(:person) do
|
|
1931
1802
|
Person.create!
|
|
1932
1803
|
end
|
|
@@ -1939,95 +1810,90 @@ describe Mongoid::Changeable do
|
|
|
1939
1810
|
from_db.reload
|
|
1940
1811
|
end
|
|
1941
1812
|
|
|
1942
|
-
it
|
|
1813
|
+
it 'clears the changed attributes' do
|
|
1943
1814
|
expect(from_db.changed_attributes).to be_empty
|
|
1944
1815
|
end
|
|
1945
1816
|
end
|
|
1946
1817
|
|
|
1947
|
-
context
|
|
1948
|
-
|
|
1818
|
+
context 'when fields are getting changed' do
|
|
1949
1819
|
let(:person) do
|
|
1950
1820
|
Person.create!(
|
|
1951
|
-
title:
|
|
1821
|
+
title: 'MC',
|
|
1952
1822
|
some_dynamic_field: 'blah'
|
|
1953
1823
|
)
|
|
1954
1824
|
end
|
|
1955
1825
|
|
|
1956
1826
|
before do
|
|
1957
|
-
person.title =
|
|
1958
|
-
person.write_attribute(:ssn,
|
|
1827
|
+
person.title = 'DJ'
|
|
1828
|
+
person.write_attribute(:ssn, '222-22-2222')
|
|
1959
1829
|
person.some_dynamic_field = 'bloop'
|
|
1960
1830
|
end
|
|
1961
1831
|
|
|
1962
|
-
it
|
|
1832
|
+
it 'marks the document as changed' do
|
|
1963
1833
|
expect(person).to be_changed
|
|
1964
1834
|
end
|
|
1965
1835
|
|
|
1966
|
-
it
|
|
1836
|
+
it 'marks field changes' do
|
|
1967
1837
|
expect(person.changes).to eq({
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1838
|
+
'title' => %w[MC DJ],
|
|
1839
|
+
'ssn' => [ nil, '222-22-2222' ],
|
|
1840
|
+
'some_dynamic_field' => %w[blah bloop]
|
|
1841
|
+
})
|
|
1972
1842
|
end
|
|
1973
1843
|
|
|
1974
|
-
it
|
|
1975
|
-
expect(person.changed).to eq([
|
|
1844
|
+
it 'marks changed fields' do
|
|
1845
|
+
expect(person.changed).to eq(%w[title ssn some_dynamic_field])
|
|
1976
1846
|
end
|
|
1977
1847
|
|
|
1978
|
-
it
|
|
1848
|
+
it 'marks the field as changed' do
|
|
1979
1849
|
expect(person.title_changed?).to be true
|
|
1980
1850
|
end
|
|
1981
1851
|
|
|
1982
|
-
it
|
|
1983
|
-
expect(person.title_was).to eq(
|
|
1852
|
+
it 'stores previous field values' do
|
|
1853
|
+
expect(person.title_was).to eq('MC')
|
|
1984
1854
|
end
|
|
1985
1855
|
|
|
1986
|
-
it
|
|
1987
|
-
expect(person.title_change).to eq([
|
|
1856
|
+
it 'marks field changes' do
|
|
1857
|
+
expect(person.title_change).to eq(%w[MC DJ])
|
|
1988
1858
|
end
|
|
1989
1859
|
|
|
1990
|
-
it
|
|
1860
|
+
it 'allows reset of field changes' do
|
|
1991
1861
|
person.reset_title!
|
|
1992
|
-
expect(person.title).to eq(
|
|
1993
|
-
expect(person.changed).to eq([
|
|
1862
|
+
expect(person.title).to eq('MC')
|
|
1863
|
+
expect(person.changed).to eq(%w[ssn some_dynamic_field])
|
|
1994
1864
|
end
|
|
1995
1865
|
|
|
1996
|
-
context
|
|
1997
|
-
|
|
1866
|
+
context 'after a save' do
|
|
1998
1867
|
before do
|
|
1999
1868
|
person.save!
|
|
2000
1869
|
end
|
|
2001
1870
|
|
|
2002
|
-
it
|
|
2003
|
-
expect(person).
|
|
1871
|
+
it 'clears changes' do
|
|
1872
|
+
expect(person).not_to be_changed
|
|
2004
1873
|
end
|
|
2005
1874
|
|
|
2006
|
-
it
|
|
2007
|
-
expect(person.previous_changes[
|
|
2008
|
-
expect(person.previous_changes[
|
|
1875
|
+
it 'stores previous changes' do
|
|
1876
|
+
expect(person.previous_changes['title']).to eq(%w[MC DJ])
|
|
1877
|
+
expect(person.previous_changes['ssn']).to eq([ nil, '222-22-2222' ])
|
|
2009
1878
|
end
|
|
2010
1879
|
end
|
|
2011
1880
|
|
|
2012
|
-
context
|
|
2013
|
-
|
|
1881
|
+
context 'when the previous value is nil' do
|
|
2014
1882
|
before do
|
|
2015
1883
|
person.score = 100
|
|
2016
1884
|
person.reset_score!
|
|
2017
1885
|
end
|
|
2018
1886
|
|
|
2019
|
-
it
|
|
1887
|
+
it 'removes the attribute from the document' do
|
|
2020
1888
|
expect(person.score).to be_nil
|
|
2021
1889
|
end
|
|
2022
1890
|
end
|
|
2023
1891
|
end
|
|
2024
1892
|
|
|
2025
|
-
context
|
|
2026
|
-
|
|
2027
|
-
context "when the document is persisted" do
|
|
2028
|
-
|
|
1893
|
+
context 'when accessing dirty attributes in callbacks' do
|
|
1894
|
+
context 'when the document is persisted' do
|
|
2029
1895
|
let!(:acolyte) do
|
|
2030
|
-
Acolyte.create!(name:
|
|
1896
|
+
Acolyte.create!(name: 'callback-test')
|
|
2031
1897
|
end
|
|
2032
1898
|
|
|
2033
1899
|
before do
|
|
@@ -2042,23 +1908,22 @@ describe Mongoid::Changeable do
|
|
|
2042
1908
|
|
|
2043
1909
|
after do
|
|
2044
1910
|
Acolyte._save_callbacks.select do |callback|
|
|
2045
|
-
[
|
|
1911
|
+
%i[before after].include?(callback.kind)
|
|
2046
1912
|
end.each do |callback|
|
|
2047
1913
|
Acolyte._save_callbacks.delete(callback)
|
|
2048
1914
|
end
|
|
2049
1915
|
end
|
|
2050
1916
|
|
|
2051
|
-
it
|
|
2052
|
-
acolyte.update_attribute(:status,
|
|
2053
|
-
expect(acolyte.changed_in_before_callback).to eq({
|
|
2054
|
-
expect(acolyte.changed_in_after_callback).to eq({
|
|
1917
|
+
it 'does not retain the changes until after all callbacks' do
|
|
1918
|
+
acolyte.update_attribute(:status, 'testing')
|
|
1919
|
+
expect(acolyte.changed_in_before_callback).to eq({ 'status' => [ nil, 'testing' ] })
|
|
1920
|
+
expect(acolyte.changed_in_after_callback).to eq({})
|
|
2055
1921
|
end
|
|
2056
1922
|
end
|
|
2057
1923
|
|
|
2058
|
-
context
|
|
2059
|
-
|
|
1924
|
+
context 'when the document is new' do
|
|
2060
1925
|
let!(:acolyte) do
|
|
2061
|
-
Acolyte.new(name:
|
|
1926
|
+
Acolyte.new(name: 'callback-test')
|
|
2062
1927
|
end
|
|
2063
1928
|
|
|
2064
1929
|
before do
|
|
@@ -2073,22 +1938,21 @@ describe Mongoid::Changeable do
|
|
|
2073
1938
|
|
|
2074
1939
|
after do
|
|
2075
1940
|
Acolyte._save_callbacks.select do |callback|
|
|
2076
|
-
[
|
|
1941
|
+
%i[before after].include?(callback.kind)
|
|
2077
1942
|
end.each do |callback|
|
|
2078
1943
|
Acolyte._save_callbacks.delete(callback)
|
|
2079
1944
|
end
|
|
2080
1945
|
end
|
|
2081
1946
|
|
|
2082
|
-
it
|
|
1947
|
+
it 'does not retain the changes until after all callbacks' do
|
|
2083
1948
|
acolyte.save!
|
|
2084
|
-
expect(acolyte.changed_before_in_callback[
|
|
2085
|
-
expect(acolyte.changed_after_in_callback[
|
|
1949
|
+
expect(acolyte.changed_before_in_callback['name']).to eq([ nil, 'callback-test' ])
|
|
1950
|
+
expect(acolyte.changed_after_in_callback['name']).to be_nil
|
|
2086
1951
|
end
|
|
2087
1952
|
end
|
|
2088
1953
|
end
|
|
2089
1954
|
|
|
2090
|
-
context
|
|
2091
|
-
|
|
1955
|
+
context 'when associations are getting changed' do
|
|
2092
1956
|
let(:person) do
|
|
2093
1957
|
Person.create!(addresses: [ Address.new ])
|
|
2094
1958
|
end
|
|
@@ -2097,25 +1961,22 @@ describe Mongoid::Changeable do
|
|
|
2097
1961
|
person.addresses = [ Address.new ]
|
|
2098
1962
|
end
|
|
2099
1963
|
|
|
2100
|
-
it
|
|
2101
|
-
expect(person.setters).
|
|
1964
|
+
it 'does not set the association to nil when hitting the database' do
|
|
1965
|
+
expect(person.setters).not_to eq({ 'addresses' => nil })
|
|
2102
1966
|
end
|
|
2103
1967
|
end
|
|
2104
1968
|
|
|
2105
1969
|
context 'when nesting deeply embedded documents' do
|
|
2106
|
-
|
|
2107
1970
|
context 'when persisting the root document' do
|
|
2108
|
-
|
|
2109
1971
|
let!(:person) do
|
|
2110
1972
|
Person.create!
|
|
2111
1973
|
end
|
|
2112
1974
|
|
|
2113
1975
|
it 'is not marked as changed' do
|
|
2114
|
-
expect(person).
|
|
1976
|
+
expect(person).not_to be_changed
|
|
2115
1977
|
end
|
|
2116
1978
|
|
|
2117
1979
|
context 'when creating a new first level embedded document' do
|
|
2118
|
-
|
|
2119
1980
|
let!(:address) do
|
|
2120
1981
|
person.addresses.new(street: 'goltzstr.')
|
|
2121
1982
|
end
|
|
@@ -2129,7 +1990,6 @@ describe Mongoid::Changeable do
|
|
|
2129
1990
|
end
|
|
2130
1991
|
|
|
2131
1992
|
context 'when building the lowest level document' do
|
|
2132
|
-
|
|
2133
1993
|
before do
|
|
2134
1994
|
person.save!
|
|
2135
1995
|
end
|
|
@@ -2151,7 +2011,6 @@ describe Mongoid::Changeable do
|
|
|
2151
2011
|
end
|
|
2152
2012
|
|
|
2153
2013
|
context 'when saving the hierarchy' do
|
|
2154
|
-
|
|
2155
2014
|
before do
|
|
2156
2015
|
person.save!
|
|
2157
2016
|
end
|
|
@@ -2169,7 +2028,6 @@ describe Mongoid::Changeable do
|
|
|
2169
2028
|
end
|
|
2170
2029
|
|
|
2171
2030
|
context 'when embedding further' do
|
|
2172
|
-
|
|
2173
2031
|
let!(:deepest) do
|
|
2174
2032
|
reloaded.addresses.first.code.build_deepest
|
|
2175
2033
|
end
|