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