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