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