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