mongoid 9.0.11 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -0
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +34 -38
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +18 -13
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -66
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -14
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +1 -3
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +132 -42
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +72 -65
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -2
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -72
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +26 -25
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +0 -2
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +11 -14
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -15
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -41
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +330 -0
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +28 -30
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -32
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -178
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +104 -119
- data/spec/integration/encryption_spec.rb +8 -11
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -31
- data/spec/mongoid/config/encryption_spec.rb +54 -57
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -854
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -950
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -80
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -8
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -2
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Validatable::UniquenessValidator do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context "when the document is a root document" do
|
|
11
|
-
|
|
12
|
-
context "when setting the read preference to non-primary" do
|
|
13
|
-
|
|
6
|
+
describe '#valid?' do
|
|
7
|
+
context 'when the document is a root document' do
|
|
8
|
+
context 'when setting the read preference to non-primary' do
|
|
14
9
|
before do
|
|
15
10
|
Dictionary.validates_uniqueness_of :name
|
|
16
11
|
end
|
|
@@ -19,20 +14,19 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
19
14
|
Dictionary.reset_callbacks(:validate)
|
|
20
15
|
end
|
|
21
16
|
|
|
22
|
-
it
|
|
17
|
+
it 'reads from the primary' do
|
|
23
18
|
expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs|
|
|
24
19
|
crit = m.call(*args, **kwargs)
|
|
25
|
-
expect(crit.view.options[
|
|
20
|
+
expect(crit.view.options['read']).to eq({ 'mode' => :primary })
|
|
26
21
|
crit
|
|
27
22
|
end
|
|
28
23
|
Dictionary.with(read: { mode: :secondary }) do |klass|
|
|
29
|
-
klass.create!(name:
|
|
24
|
+
klass.create!(name: 'Websters')
|
|
30
25
|
end
|
|
31
26
|
end
|
|
32
27
|
end
|
|
33
28
|
|
|
34
|
-
context
|
|
35
|
-
|
|
29
|
+
context 'when adding custom persistence options' do
|
|
36
30
|
before do
|
|
37
31
|
Dictionary.validates_uniqueness_of :name
|
|
38
32
|
end
|
|
@@ -41,57 +35,52 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
41
35
|
Dictionary.reset_callbacks(:validate)
|
|
42
36
|
end
|
|
43
37
|
|
|
44
|
-
context
|
|
45
|
-
|
|
38
|
+
context 'when persisting to another collection' do
|
|
46
39
|
before do
|
|
47
|
-
Dictionary.with(collection:
|
|
48
|
-
klass.create!(name:
|
|
40
|
+
Dictionary.with(collection: 'dicts') do |klass|
|
|
41
|
+
klass.create!(name: 'websters')
|
|
49
42
|
end
|
|
50
43
|
end
|
|
51
44
|
|
|
52
|
-
context
|
|
53
|
-
|
|
45
|
+
context 'when the document is not valid' do
|
|
54
46
|
let(:websters) do
|
|
55
47
|
object = nil
|
|
56
|
-
valid = Dictionary.with(collection:
|
|
57
|
-
object = klass.new(name:
|
|
48
|
+
valid = Dictionary.with(collection: 'dicts') do |klass|
|
|
49
|
+
object = klass.new(name: 'websters')
|
|
58
50
|
object.valid?
|
|
59
51
|
end
|
|
60
|
-
{ :
|
|
52
|
+
{ valid: valid, object: object }
|
|
61
53
|
end
|
|
62
54
|
|
|
63
|
-
it
|
|
55
|
+
it 'performs the validation on the correct collection' do
|
|
64
56
|
expect(websters[:valid]).to be(false)
|
|
65
57
|
end
|
|
66
58
|
|
|
67
|
-
it
|
|
68
|
-
expect(websters[:object].errors[:name]).
|
|
59
|
+
it 'adds the uniqueness error' do
|
|
60
|
+
expect(websters[:object].errors[:name]).not_to be_nil
|
|
69
61
|
end
|
|
70
62
|
|
|
71
|
-
it
|
|
63
|
+
it 'clears the persistence options in the thread local' do
|
|
72
64
|
expect(Dictionary.persistence_context).to eq(Mongoid::PersistenceContext.new(Dictionary))
|
|
73
65
|
end
|
|
74
66
|
end
|
|
75
67
|
|
|
76
|
-
context
|
|
77
|
-
|
|
68
|
+
context 'when the document is valid' do
|
|
78
69
|
let(:oxford) do
|
|
79
|
-
Dictionary.with(collection:
|
|
80
|
-
klass.new(name:
|
|
70
|
+
Dictionary.with(collection: 'dicts') do |klass|
|
|
71
|
+
klass.new(name: 'oxford')
|
|
81
72
|
end
|
|
82
73
|
end
|
|
83
74
|
|
|
84
|
-
it
|
|
75
|
+
it 'performs the validation on the correct collection' do
|
|
85
76
|
expect(oxford).to be_valid
|
|
86
77
|
end
|
|
87
78
|
end
|
|
88
79
|
end
|
|
89
80
|
end
|
|
90
81
|
|
|
91
|
-
context
|
|
92
|
-
|
|
93
|
-
context "when validating a relation" do
|
|
94
|
-
|
|
82
|
+
context 'when the document contains no compound key' do
|
|
83
|
+
context 'when validating a relation' do
|
|
95
84
|
before do
|
|
96
85
|
Word.validates_uniqueness_of :dictionary
|
|
97
86
|
end
|
|
@@ -100,8 +89,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
100
89
|
Word.reset_callbacks(:validate)
|
|
101
90
|
end
|
|
102
91
|
|
|
103
|
-
context
|
|
104
|
-
|
|
92
|
+
context 'when the attribute id is unique' do
|
|
105
93
|
let(:dictionary) do
|
|
106
94
|
Dictionary.create!
|
|
107
95
|
end
|
|
@@ -110,67 +98,61 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
110
98
|
Word.new(dictionary: dictionary)
|
|
111
99
|
end
|
|
112
100
|
|
|
113
|
-
it
|
|
101
|
+
it 'returns true' do
|
|
114
102
|
expect(word).to be_valid
|
|
115
103
|
end
|
|
116
104
|
end
|
|
117
105
|
end
|
|
118
106
|
|
|
119
|
-
context
|
|
120
|
-
|
|
107
|
+
context 'when the field name is aliased' do
|
|
121
108
|
before do
|
|
122
|
-
Dictionary.create!(language:
|
|
109
|
+
Dictionary.create!(language: 'en')
|
|
123
110
|
end
|
|
124
111
|
|
|
125
112
|
let(:dictionary) do
|
|
126
|
-
Dictionary.new(language:
|
|
113
|
+
Dictionary.new(language: 'en')
|
|
127
114
|
end
|
|
128
115
|
|
|
129
116
|
after do
|
|
130
117
|
Dictionary.reset_callbacks(:validate)
|
|
131
118
|
end
|
|
132
119
|
|
|
133
|
-
context
|
|
134
|
-
|
|
120
|
+
context 'when the validation uses the aliased name' do
|
|
135
121
|
before do
|
|
136
122
|
Dictionary.validates_uniqueness_of :language
|
|
137
123
|
end
|
|
138
124
|
|
|
139
|
-
it
|
|
140
|
-
expect(dictionary).
|
|
125
|
+
it 'correctly detects a uniqueness conflict' do
|
|
126
|
+
expect(dictionary).not_to be_valid
|
|
141
127
|
end
|
|
142
128
|
|
|
143
|
-
it
|
|
129
|
+
it 'adds the uniqueness error to the aliased field name' do
|
|
144
130
|
dictionary.valid?
|
|
145
131
|
expect(dictionary.errors).to have_key(:language)
|
|
146
|
-
expect(dictionary.errors[:language]).to eq([
|
|
132
|
+
expect(dictionary.errors[:language]).to eq([ 'has already been taken' ])
|
|
147
133
|
end
|
|
148
134
|
end
|
|
149
135
|
|
|
150
|
-
context
|
|
151
|
-
|
|
136
|
+
context 'when the validation uses the underlying field name' do
|
|
152
137
|
before do
|
|
153
138
|
Dictionary.validates_uniqueness_of :l
|
|
154
139
|
end
|
|
155
140
|
|
|
156
|
-
it
|
|
157
|
-
expect(dictionary).
|
|
141
|
+
it 'correctly detects a uniqueness conflict' do
|
|
142
|
+
expect(dictionary).not_to be_valid
|
|
158
143
|
end
|
|
159
144
|
|
|
160
|
-
it
|
|
145
|
+
it 'adds the uniqueness error to the underlying field name' do
|
|
161
146
|
dictionary.valid?
|
|
162
147
|
expect(dictionary.errors).to have_key(:l)
|
|
163
|
-
expect(dictionary.errors[:l]).to eq([
|
|
148
|
+
expect(dictionary.errors[:l]).to eq([ 'has already been taken' ])
|
|
164
149
|
end
|
|
165
150
|
end
|
|
166
151
|
end
|
|
167
152
|
|
|
168
|
-
context
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
context "when case sensitive is true" do
|
|
173
|
-
|
|
153
|
+
context 'when the field is localized' do
|
|
154
|
+
context 'when no scope is provided' do
|
|
155
|
+
context 'when case sensitive is true' do
|
|
174
156
|
before do
|
|
175
157
|
Dictionary.validates_uniqueness_of :description
|
|
176
158
|
end
|
|
@@ -179,21 +161,18 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
179
161
|
Dictionary.reset_callbacks(:validate)
|
|
180
162
|
end
|
|
181
163
|
|
|
182
|
-
context
|
|
183
|
-
|
|
184
|
-
context "when no document with no value exists in the database" do
|
|
185
|
-
|
|
164
|
+
context 'when no attribute is set' do
|
|
165
|
+
context 'when no document with no value exists in the database' do
|
|
186
166
|
let(:dictionary) do
|
|
187
167
|
Dictionary.new
|
|
188
168
|
end
|
|
189
169
|
|
|
190
|
-
it
|
|
170
|
+
it 'returns true' do
|
|
191
171
|
expect(dictionary).to be_valid
|
|
192
172
|
end
|
|
193
173
|
end
|
|
194
174
|
|
|
195
|
-
context
|
|
196
|
-
|
|
175
|
+
context 'when a document with no value exists in the database' do
|
|
197
176
|
before do
|
|
198
177
|
Dictionary.create!
|
|
199
178
|
end
|
|
@@ -202,96 +181,88 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
202
181
|
Dictionary.new
|
|
203
182
|
end
|
|
204
183
|
|
|
205
|
-
it
|
|
206
|
-
expect(dictionary).
|
|
184
|
+
it 'returns false' do
|
|
185
|
+
expect(dictionary).not_to be_valid
|
|
207
186
|
end
|
|
208
187
|
end
|
|
209
188
|
end
|
|
210
189
|
|
|
211
|
-
context
|
|
212
|
-
|
|
213
|
-
context "when single localization" do
|
|
214
|
-
|
|
190
|
+
context 'when the attribute is unique' do
|
|
191
|
+
context 'when single localization' do
|
|
215
192
|
before do
|
|
216
|
-
Dictionary.create!(description:
|
|
193
|
+
Dictionary.create!(description: 'english')
|
|
217
194
|
end
|
|
218
195
|
|
|
219
196
|
let(:dictionary) do
|
|
220
|
-
Dictionary.new(description:
|
|
197
|
+
Dictionary.new(description: 'English')
|
|
221
198
|
end
|
|
222
199
|
|
|
223
|
-
it
|
|
200
|
+
it 'returns true' do
|
|
224
201
|
expect(dictionary).to be_valid
|
|
225
202
|
end
|
|
226
203
|
end
|
|
227
204
|
|
|
228
|
-
context
|
|
229
|
-
|
|
205
|
+
context 'when multiple localizations' do
|
|
230
206
|
before do
|
|
231
|
-
Dictionary
|
|
232
|
-
|
|
207
|
+
Dictionary
|
|
208
|
+
.create(description_translations: { 'en' => 'english', 'de' => 'german' })
|
|
233
209
|
end
|
|
234
210
|
|
|
235
211
|
let(:dictionary) do
|
|
236
|
-
Dictionary.new(description_translations: {
|
|
212
|
+
Dictionary.new(description_translations: { 'en' => 'English', 'de' => 'German' })
|
|
237
213
|
end
|
|
238
214
|
|
|
239
|
-
it
|
|
215
|
+
it 'returns true' do
|
|
240
216
|
expect(dictionary).to be_valid
|
|
241
217
|
end
|
|
242
218
|
end
|
|
243
219
|
end
|
|
244
220
|
|
|
245
|
-
context
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
context "when single localization" do
|
|
250
|
-
|
|
221
|
+
context 'when the attribute is not unique' do
|
|
222
|
+
context 'when the document is not the match' do
|
|
223
|
+
context 'when single localization' do
|
|
251
224
|
before do
|
|
252
|
-
Dictionary.create!(description:
|
|
225
|
+
Dictionary.create!(description: 'english')
|
|
253
226
|
end
|
|
254
227
|
|
|
255
228
|
let(:dictionary) do
|
|
256
|
-
Dictionary.new(description:
|
|
229
|
+
Dictionary.new(description: 'english')
|
|
257
230
|
end
|
|
258
231
|
|
|
259
|
-
it
|
|
260
|
-
expect(dictionary).
|
|
232
|
+
it 'returns false' do
|
|
233
|
+
expect(dictionary).not_to be_valid
|
|
261
234
|
end
|
|
262
235
|
|
|
263
|
-
it
|
|
236
|
+
it 'adds the uniqueness error' do
|
|
264
237
|
dictionary.valid?
|
|
265
|
-
expect(dictionary.errors[:description]).to eq([
|
|
238
|
+
expect(dictionary.errors[:description]).to eq([ 'has already been taken' ])
|
|
266
239
|
end
|
|
267
240
|
end
|
|
268
241
|
|
|
269
|
-
context
|
|
270
|
-
|
|
242
|
+
context 'when multiple localizations' do
|
|
271
243
|
before do
|
|
272
|
-
Dictionary
|
|
273
|
-
|
|
244
|
+
Dictionary
|
|
245
|
+
.create(description_translations: { 'en' => 'english', 'de' => 'german' })
|
|
274
246
|
end
|
|
275
247
|
|
|
276
248
|
let(:dictionary) do
|
|
277
|
-
Dictionary.new(description_translations: {
|
|
249
|
+
Dictionary.new(description_translations: { 'en' => 'english', 'de' => 'German' })
|
|
278
250
|
end
|
|
279
251
|
|
|
280
|
-
it
|
|
281
|
-
expect(dictionary).
|
|
252
|
+
it 'returns false' do
|
|
253
|
+
expect(dictionary).not_to be_valid
|
|
282
254
|
end
|
|
283
255
|
|
|
284
|
-
it
|
|
256
|
+
it 'adds the uniqueness error' do
|
|
285
257
|
dictionary.valid?
|
|
286
|
-
expect(dictionary.errors[:description]).to eq([
|
|
258
|
+
expect(dictionary.errors[:description]).to eq([ 'has already been taken' ])
|
|
287
259
|
end
|
|
288
260
|
end
|
|
289
261
|
end
|
|
290
262
|
end
|
|
291
263
|
end
|
|
292
264
|
|
|
293
|
-
context
|
|
294
|
-
|
|
265
|
+
context 'when case sensitive is false' do
|
|
295
266
|
before do
|
|
296
267
|
Dictionary.validates_uniqueness_of :description, case_sensitive: false
|
|
297
268
|
end
|
|
@@ -300,92 +271,84 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
300
271
|
Dictionary.reset_callbacks(:validate)
|
|
301
272
|
end
|
|
302
273
|
|
|
303
|
-
context
|
|
304
|
-
|
|
305
|
-
context "when there are no special characters" do
|
|
306
|
-
|
|
274
|
+
context 'when the attribute is unique' do
|
|
275
|
+
context 'when there are no special characters' do
|
|
307
276
|
before do
|
|
308
|
-
Dictionary.create!(description:
|
|
277
|
+
Dictionary.create!(description: 'english')
|
|
309
278
|
end
|
|
310
279
|
|
|
311
280
|
let(:dictionary) do
|
|
312
|
-
Dictionary.new(description:
|
|
281
|
+
Dictionary.new(description: 'german')
|
|
313
282
|
end
|
|
314
283
|
|
|
315
|
-
it
|
|
284
|
+
it 'returns true' do
|
|
316
285
|
expect(dictionary).to be_valid
|
|
317
286
|
end
|
|
318
287
|
end
|
|
319
288
|
|
|
320
|
-
context
|
|
321
|
-
|
|
289
|
+
context 'when special characters exist' do
|
|
322
290
|
before do
|
|
323
|
-
Dictionary.create!(description:
|
|
291
|
+
Dictionary.create!(description: 'english')
|
|
324
292
|
end
|
|
325
293
|
|
|
326
294
|
let(:dictionary) do
|
|
327
|
-
Dictionary.new(description:
|
|
295
|
+
Dictionary.new(description: 'en@gl.ish')
|
|
328
296
|
end
|
|
329
297
|
|
|
330
|
-
it
|
|
298
|
+
it 'returns true' do
|
|
331
299
|
expect(dictionary).to be_valid
|
|
332
300
|
end
|
|
333
301
|
end
|
|
334
302
|
end
|
|
335
303
|
|
|
336
|
-
context
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
context "when signle localization" do
|
|
341
|
-
|
|
304
|
+
context 'when the attribute is not unique' do
|
|
305
|
+
context 'when the document is not the match' do
|
|
306
|
+
context 'when single localization' do
|
|
342
307
|
before do
|
|
343
|
-
Dictionary.create!(description:
|
|
308
|
+
Dictionary.create!(description: 'english')
|
|
344
309
|
end
|
|
345
310
|
|
|
346
311
|
let(:dictionary) do
|
|
347
|
-
Dictionary.new(description:
|
|
312
|
+
Dictionary.new(description: 'English')
|
|
348
313
|
end
|
|
349
314
|
|
|
350
|
-
it
|
|
351
|
-
expect(dictionary).
|
|
315
|
+
it 'returns false' do
|
|
316
|
+
expect(dictionary).not_to be_valid
|
|
352
317
|
end
|
|
353
318
|
|
|
354
|
-
it
|
|
319
|
+
it 'adds the uniqueness error' do
|
|
355
320
|
dictionary.valid?
|
|
356
|
-
expect(dictionary.errors[:description]).to eq([
|
|
321
|
+
expect(dictionary.errors[:description]).to eq([ 'has already been taken' ])
|
|
357
322
|
end
|
|
358
323
|
end
|
|
359
324
|
|
|
360
|
-
context
|
|
361
|
-
|
|
325
|
+
context 'when multiple localizations' do
|
|
362
326
|
before do
|
|
363
|
-
Dictionary
|
|
364
|
-
|
|
327
|
+
Dictionary
|
|
328
|
+
.create(description_translations: { 'en' => 'english', 'de' => 'german' })
|
|
365
329
|
end
|
|
366
330
|
|
|
367
331
|
let(:dictionary) do
|
|
368
|
-
Dictionary.new(description_translations: {
|
|
332
|
+
Dictionary.new(description_translations: { 'en' => 'English', 'de' => 'German' })
|
|
369
333
|
end
|
|
370
334
|
|
|
371
|
-
it
|
|
372
|
-
expect(dictionary).
|
|
335
|
+
it 'returns false' do
|
|
336
|
+
expect(dictionary).not_to be_valid
|
|
373
337
|
end
|
|
374
338
|
|
|
375
|
-
it
|
|
339
|
+
it 'adds the uniqueness error' do
|
|
376
340
|
dictionary.valid?
|
|
377
|
-
expect(dictionary.errors[:description]).to eq([
|
|
341
|
+
expect(dictionary.errors[:description]).to eq([ 'has already been taken' ])
|
|
378
342
|
end
|
|
379
343
|
end
|
|
380
344
|
end
|
|
381
345
|
|
|
382
|
-
context
|
|
383
|
-
|
|
346
|
+
context 'when the document is the match in the database' do
|
|
384
347
|
let!(:dictionary) do
|
|
385
|
-
Dictionary.create!(description:
|
|
348
|
+
Dictionary.create!(description: 'english')
|
|
386
349
|
end
|
|
387
350
|
|
|
388
|
-
it
|
|
351
|
+
it 'returns true' do
|
|
389
352
|
expect(dictionary).to be_valid
|
|
390
353
|
end
|
|
391
354
|
end
|
|
@@ -393,8 +356,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
393
356
|
end
|
|
394
357
|
end
|
|
395
358
|
|
|
396
|
-
context
|
|
397
|
-
|
|
359
|
+
context 'when a scope is provided' do
|
|
398
360
|
before do
|
|
399
361
|
Dictionary.validates_uniqueness_of :description, scope: :name
|
|
400
362
|
end
|
|
@@ -403,34 +365,31 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
403
365
|
Dictionary.reset_callbacks(:validate)
|
|
404
366
|
end
|
|
405
367
|
|
|
406
|
-
context
|
|
407
|
-
|
|
408
|
-
context "when the document is not the match" do
|
|
409
|
-
|
|
368
|
+
context 'when the attribute is not unique in the scope' do
|
|
369
|
+
context 'when the document is not the match' do
|
|
410
370
|
before do
|
|
411
|
-
Dictionary
|
|
412
|
-
create(description:
|
|
371
|
+
Dictionary
|
|
372
|
+
.create(description: 'english', name: 'test')
|
|
413
373
|
end
|
|
414
374
|
|
|
415
375
|
let(:dictionary) do
|
|
416
|
-
Dictionary.new(description:
|
|
376
|
+
Dictionary.new(description: 'english', name: 'test')
|
|
417
377
|
end
|
|
418
378
|
|
|
419
|
-
it
|
|
420
|
-
expect(dictionary).
|
|
379
|
+
it 'returns false' do
|
|
380
|
+
expect(dictionary).not_to be_valid
|
|
421
381
|
end
|
|
422
382
|
|
|
423
|
-
it
|
|
383
|
+
it 'adds the uniqueness error' do
|
|
424
384
|
dictionary.valid?
|
|
425
|
-
expect(dictionary.errors[:description]).to eq([
|
|
385
|
+
expect(dictionary.errors[:description]).to eq([ 'has already been taken' ])
|
|
426
386
|
end
|
|
427
387
|
end
|
|
428
388
|
end
|
|
429
389
|
end
|
|
430
390
|
end
|
|
431
391
|
|
|
432
|
-
context
|
|
433
|
-
|
|
392
|
+
context 'when no scope is provided' do
|
|
434
393
|
before do
|
|
435
394
|
Dictionary.validates_uniqueness_of :name
|
|
436
395
|
end
|
|
@@ -439,87 +398,80 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
439
398
|
Dictionary.reset_callbacks(:validate)
|
|
440
399
|
end
|
|
441
400
|
|
|
442
|
-
context
|
|
443
|
-
|
|
401
|
+
context 'when the attribute is unique' do
|
|
444
402
|
let!(:oxford) do
|
|
445
|
-
Dictionary.create!(name:
|
|
403
|
+
Dictionary.create!(name: 'Oxford')
|
|
446
404
|
end
|
|
447
405
|
|
|
448
406
|
let(:dictionary) do
|
|
449
|
-
Dictionary.new(name:
|
|
407
|
+
Dictionary.new(name: 'Webster')
|
|
450
408
|
end
|
|
451
409
|
|
|
452
|
-
it
|
|
410
|
+
it 'returns true' do
|
|
453
411
|
expect(dictionary).to be_valid
|
|
454
412
|
end
|
|
455
413
|
|
|
456
|
-
context
|
|
457
|
-
|
|
414
|
+
context 'when subsequently cloning the document' do
|
|
458
415
|
let(:clone) do
|
|
459
416
|
oxford.clone
|
|
460
417
|
end
|
|
461
418
|
|
|
462
|
-
it
|
|
463
|
-
expect(clone).
|
|
419
|
+
it 'returns false for the clone' do
|
|
420
|
+
expect(clone).not_to be_valid
|
|
464
421
|
end
|
|
465
422
|
end
|
|
466
423
|
end
|
|
467
424
|
|
|
468
|
-
context
|
|
469
|
-
|
|
470
|
-
context "when the document is not the match" do
|
|
471
|
-
|
|
425
|
+
context 'when the attribute is not unique' do
|
|
426
|
+
context 'when the document is not the match' do
|
|
472
427
|
before do
|
|
473
|
-
Dictionary.create!(name:
|
|
428
|
+
Dictionary.create!(name: 'Oxford')
|
|
474
429
|
end
|
|
475
430
|
|
|
476
431
|
let!(:dictionary) do
|
|
477
|
-
Dictionary.new(name:
|
|
432
|
+
Dictionary.new(name: 'Oxford')
|
|
478
433
|
end
|
|
479
434
|
|
|
480
|
-
it
|
|
481
|
-
expect(dictionary).
|
|
435
|
+
it 'returns false' do
|
|
436
|
+
expect(dictionary).not_to be_valid
|
|
482
437
|
end
|
|
483
438
|
|
|
484
|
-
it
|
|
439
|
+
it 'adds the uniqueness error' do
|
|
485
440
|
dictionary.valid?
|
|
486
|
-
expect(dictionary.errors[:name]).to eq([
|
|
441
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
487
442
|
end
|
|
488
443
|
end
|
|
489
444
|
|
|
490
|
-
context
|
|
491
|
-
|
|
492
|
-
context "when the field has changed" do
|
|
493
|
-
|
|
445
|
+
context 'when the document is the match in the database' do
|
|
446
|
+
context 'when the field has changed' do
|
|
494
447
|
let!(:dictionary) do
|
|
495
|
-
Dictionary.create!(name:
|
|
448
|
+
Dictionary.create!(name: 'Oxford')
|
|
496
449
|
end
|
|
497
450
|
|
|
498
|
-
it
|
|
451
|
+
it 'returns true' do
|
|
499
452
|
expect(dictionary).to be_valid
|
|
500
453
|
end
|
|
501
454
|
end
|
|
502
455
|
|
|
503
|
-
context
|
|
504
|
-
|
|
456
|
+
context 'when the field has not changed' do
|
|
505
457
|
before do
|
|
506
458
|
Dictionary.default_scoping = nil
|
|
507
459
|
end
|
|
508
460
|
|
|
509
461
|
let!(:dictionary) do
|
|
510
|
-
Dictionary.create!(name:
|
|
462
|
+
Dictionary.create!(name: 'Oxford')
|
|
511
463
|
end
|
|
512
464
|
|
|
513
465
|
let!(:from_db) do
|
|
514
466
|
Dictionary.find(dictionary.id)
|
|
515
467
|
end
|
|
516
468
|
|
|
517
|
-
it
|
|
469
|
+
it 'returns true' do
|
|
518
470
|
expect(from_db).to be_valid
|
|
519
471
|
end
|
|
520
472
|
|
|
521
|
-
it
|
|
522
|
-
expect(Dictionary).
|
|
473
|
+
it 'does not touch the database' do
|
|
474
|
+
expect(Dictionary).not_to receive(:where)
|
|
523
475
|
from_db.valid?
|
|
524
476
|
end
|
|
525
477
|
end
|
|
@@ -527,11 +479,10 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
527
479
|
end
|
|
528
480
|
end
|
|
529
481
|
|
|
530
|
-
context
|
|
531
|
-
|
|
482
|
+
context 'when a default scope is on the model' do
|
|
532
483
|
before do
|
|
533
484
|
Dictionary.validates_uniqueness_of :name
|
|
534
|
-
Dictionary.default_scope(->{ Dictionary.where(year: 1990) })
|
|
485
|
+
Dictionary.default_scope(-> { Dictionary.where(year: 1990) })
|
|
535
486
|
end
|
|
536
487
|
|
|
537
488
|
after do
|
|
@@ -539,27 +490,24 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
539
490
|
Dictionary.reset_callbacks(:validate)
|
|
540
491
|
end
|
|
541
492
|
|
|
542
|
-
context
|
|
543
|
-
|
|
544
|
-
context "when the attribute is not unique" do
|
|
545
|
-
|
|
493
|
+
context 'when the document with the unique attribute is not in default scope' do
|
|
494
|
+
context 'when the attribute is not unique' do
|
|
546
495
|
before do
|
|
547
|
-
Dictionary.create!(name:
|
|
496
|
+
Dictionary.create!(name: 'Oxford')
|
|
548
497
|
end
|
|
549
498
|
|
|
550
499
|
let(:dictionary) do
|
|
551
|
-
Dictionary.new(name:
|
|
500
|
+
Dictionary.new(name: 'Oxford')
|
|
552
501
|
end
|
|
553
502
|
|
|
554
|
-
it
|
|
555
|
-
expect(dictionary).
|
|
503
|
+
it 'returns false' do
|
|
504
|
+
expect(dictionary).not_to be_valid
|
|
556
505
|
end
|
|
557
506
|
end
|
|
558
507
|
end
|
|
559
508
|
end
|
|
560
509
|
|
|
561
|
-
context
|
|
562
|
-
|
|
510
|
+
context 'when an aliased scope is provided' do
|
|
563
511
|
before do
|
|
564
512
|
Dictionary.validates_uniqueness_of :name, scope: :language
|
|
565
513
|
end
|
|
@@ -568,103 +516,95 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
568
516
|
Dictionary.reset_callbacks(:validate)
|
|
569
517
|
end
|
|
570
518
|
|
|
571
|
-
context
|
|
572
|
-
|
|
519
|
+
context 'when the attribute is unique' do
|
|
573
520
|
before do
|
|
574
|
-
Dictionary.create!(name:
|
|
521
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
575
522
|
end
|
|
576
523
|
|
|
577
524
|
let(:dictionary) do
|
|
578
|
-
Dictionary.new(name:
|
|
525
|
+
Dictionary.new(name: 'Webster')
|
|
579
526
|
end
|
|
580
527
|
|
|
581
|
-
it
|
|
528
|
+
it 'returns true' do
|
|
582
529
|
expect(dictionary).to be_valid
|
|
583
530
|
end
|
|
584
531
|
end
|
|
585
532
|
|
|
586
|
-
context
|
|
587
|
-
|
|
533
|
+
context 'when the attribute is unique in the scope' do
|
|
588
534
|
before do
|
|
589
|
-
Dictionary.create!(name:
|
|
535
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
590
536
|
end
|
|
591
537
|
|
|
592
538
|
let(:dictionary) do
|
|
593
|
-
Dictionary.new(name:
|
|
539
|
+
Dictionary.new(name: 'Webster', language: 'English')
|
|
594
540
|
end
|
|
595
541
|
|
|
596
|
-
it
|
|
542
|
+
it 'returns true' do
|
|
597
543
|
expect(dictionary).to be_valid
|
|
598
544
|
end
|
|
599
545
|
end
|
|
600
546
|
|
|
601
|
-
context
|
|
602
|
-
|
|
547
|
+
context 'when the attribute is not unique with no scope' do
|
|
603
548
|
before do
|
|
604
|
-
Dictionary.create!(name:
|
|
549
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
605
550
|
end
|
|
606
551
|
|
|
607
552
|
let(:dictionary) do
|
|
608
|
-
Dictionary.new(name:
|
|
553
|
+
Dictionary.new(name: 'Oxford')
|
|
609
554
|
end
|
|
610
555
|
|
|
611
|
-
it
|
|
556
|
+
it 'returns true' do
|
|
612
557
|
expect(dictionary).to be_valid
|
|
613
558
|
end
|
|
614
559
|
end
|
|
615
560
|
|
|
616
|
-
context
|
|
617
|
-
|
|
561
|
+
context 'when the attribute is not unique in another scope' do
|
|
618
562
|
before do
|
|
619
|
-
Dictionary.create!(name:
|
|
563
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
620
564
|
end
|
|
621
565
|
|
|
622
566
|
let(:dictionary) do
|
|
623
|
-
Dictionary.new(name:
|
|
567
|
+
Dictionary.new(name: 'Oxford', language: 'Deutsch')
|
|
624
568
|
end
|
|
625
569
|
|
|
626
|
-
it
|
|
570
|
+
it 'returns true' do
|
|
627
571
|
expect(dictionary).to be_valid
|
|
628
572
|
end
|
|
629
573
|
end
|
|
630
574
|
|
|
631
|
-
context
|
|
632
|
-
|
|
633
|
-
context "when the document is not the match" do
|
|
634
|
-
|
|
575
|
+
context 'when the attribute is not unique in the same scope' do
|
|
576
|
+
context 'when the document is not the match' do
|
|
635
577
|
before do
|
|
636
|
-
Dictionary.create!(name:
|
|
578
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
637
579
|
end
|
|
638
580
|
|
|
639
581
|
let(:dictionary) do
|
|
640
|
-
Dictionary.new(name:
|
|
582
|
+
Dictionary.new(name: 'Oxford', language: 'English')
|
|
641
583
|
end
|
|
642
584
|
|
|
643
|
-
it
|
|
644
|
-
expect(dictionary).
|
|
585
|
+
it 'returns false' do
|
|
586
|
+
expect(dictionary).not_to be_valid
|
|
645
587
|
end
|
|
646
588
|
|
|
647
|
-
it
|
|
589
|
+
it 'adds the uniqueness errors' do
|
|
648
590
|
dictionary.valid?
|
|
649
|
-
expect(dictionary.errors[:name]).to eq([
|
|
591
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
650
592
|
end
|
|
651
593
|
end
|
|
652
594
|
|
|
653
|
-
context
|
|
654
|
-
|
|
595
|
+
context 'when the document is the match in the database' do
|
|
655
596
|
let!(:dictionary) do
|
|
656
|
-
Dictionary.create!(name:
|
|
597
|
+
Dictionary.create!(name: 'Oxford', language: 'English')
|
|
657
598
|
end
|
|
658
599
|
|
|
659
|
-
it
|
|
600
|
+
it 'returns true' do
|
|
660
601
|
expect(dictionary).to be_valid
|
|
661
602
|
end
|
|
662
603
|
end
|
|
663
604
|
end
|
|
664
605
|
end
|
|
665
606
|
|
|
666
|
-
context
|
|
667
|
-
|
|
607
|
+
context 'when a single scope is provided' do
|
|
668
608
|
before do
|
|
669
609
|
Dictionary.validates_uniqueness_of :name, scope: :publisher
|
|
670
610
|
end
|
|
@@ -673,159 +613,148 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
673
613
|
Dictionary.reset_callbacks(:validate)
|
|
674
614
|
end
|
|
675
615
|
|
|
676
|
-
context
|
|
677
|
-
|
|
616
|
+
context 'when the attribute is unique' do
|
|
678
617
|
before do
|
|
679
|
-
Dictionary.create!(name:
|
|
618
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
680
619
|
end
|
|
681
620
|
|
|
682
621
|
let(:dictionary) do
|
|
683
|
-
Dictionary.new(name:
|
|
622
|
+
Dictionary.new(name: 'Webster')
|
|
684
623
|
end
|
|
685
624
|
|
|
686
|
-
it
|
|
625
|
+
it 'returns true' do
|
|
687
626
|
expect(dictionary).to be_valid
|
|
688
627
|
end
|
|
689
628
|
end
|
|
690
629
|
|
|
691
|
-
context
|
|
692
|
-
|
|
630
|
+
context 'when the attribute is unique in the scope' do
|
|
693
631
|
before do
|
|
694
|
-
Dictionary.create!(name:
|
|
632
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
695
633
|
end
|
|
696
634
|
|
|
697
635
|
let(:dictionary) do
|
|
698
|
-
Dictionary.new(name:
|
|
636
|
+
Dictionary.new(name: 'Webster', publisher: 'Amazon')
|
|
699
637
|
end
|
|
700
638
|
|
|
701
|
-
it
|
|
639
|
+
it 'returns true' do
|
|
702
640
|
expect(dictionary).to be_valid
|
|
703
641
|
end
|
|
704
642
|
end
|
|
705
643
|
|
|
706
|
-
context
|
|
707
|
-
|
|
644
|
+
context 'when uniqueness is violated due to scope change' do
|
|
708
645
|
let(:personal_folder) do
|
|
709
|
-
Folder.create!(name:
|
|
646
|
+
Folder.create!(name: 'Personal')
|
|
647
|
+
end
|
|
648
|
+
let(:item) do
|
|
649
|
+
public_folder.folder_items.last
|
|
710
650
|
end
|
|
711
651
|
|
|
712
652
|
let(:public_folder) do
|
|
713
|
-
Folder.create!(name:
|
|
653
|
+
Folder.create!(name: 'Public')
|
|
714
654
|
end
|
|
715
655
|
|
|
716
656
|
before do
|
|
717
|
-
personal_folder.folder_items << FolderItem.new(name:
|
|
718
|
-
public_folder.folder_items << FolderItem.new(name:
|
|
657
|
+
personal_folder.folder_items << FolderItem.new(name: 'non-unique')
|
|
658
|
+
public_folder.folder_items << FolderItem.new(name: 'non-unique')
|
|
719
659
|
end
|
|
720
660
|
|
|
721
|
-
|
|
722
|
-
public_folder.folder_items.last
|
|
723
|
-
end
|
|
724
|
-
|
|
725
|
-
it "should set an error for associated object not being unique" do
|
|
661
|
+
it 'sets an error for associated object not being unique' do
|
|
726
662
|
item.update_attributes(folder_id: personal_folder.id)
|
|
727
|
-
expect(item.errors.messages[:name].first).to eq(
|
|
663
|
+
expect(item.errors.messages[:name].first).to eq('has already been taken')
|
|
728
664
|
end
|
|
729
665
|
end
|
|
730
666
|
|
|
731
|
-
context
|
|
732
|
-
|
|
667
|
+
context 'when the attribute is not unique with no scope' do
|
|
733
668
|
before do
|
|
734
|
-
Dictionary.create!(name:
|
|
669
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
735
670
|
end
|
|
736
671
|
|
|
737
672
|
let(:dictionary) do
|
|
738
|
-
Dictionary.new(name:
|
|
673
|
+
Dictionary.new(name: 'Oxford')
|
|
739
674
|
end
|
|
740
675
|
|
|
741
|
-
it
|
|
676
|
+
it 'returns true' do
|
|
742
677
|
expect(dictionary).to be_valid
|
|
743
678
|
end
|
|
744
679
|
end
|
|
745
680
|
|
|
746
|
-
context
|
|
747
|
-
|
|
681
|
+
context 'when the attribute is not unique in another scope' do
|
|
748
682
|
before do
|
|
749
|
-
Dictionary.create!(name:
|
|
683
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
750
684
|
end
|
|
751
685
|
|
|
752
686
|
let(:dictionary) do
|
|
753
|
-
Dictionary.new(name:
|
|
687
|
+
Dictionary.new(name: 'Oxford', publisher: 'Addison')
|
|
754
688
|
end
|
|
755
689
|
|
|
756
|
-
it
|
|
690
|
+
it 'returns true' do
|
|
757
691
|
expect(dictionary).to be_valid
|
|
758
692
|
end
|
|
759
693
|
end
|
|
760
694
|
|
|
761
|
-
context
|
|
762
|
-
|
|
763
|
-
context "when the document is not the match" do
|
|
764
|
-
|
|
695
|
+
context 'when the attribute is not unique in the same scope' do
|
|
696
|
+
context 'when the document is not the match' do
|
|
765
697
|
before do
|
|
766
|
-
Dictionary.create!(name:
|
|
698
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
767
699
|
end
|
|
768
700
|
|
|
769
701
|
let(:dictionary) do
|
|
770
|
-
Dictionary.new(name:
|
|
702
|
+
Dictionary.new(name: 'Oxford', publisher: 'Amazon')
|
|
771
703
|
end
|
|
772
704
|
|
|
773
|
-
it
|
|
774
|
-
expect(dictionary).
|
|
705
|
+
it 'returns false' do
|
|
706
|
+
expect(dictionary).not_to be_valid
|
|
775
707
|
end
|
|
776
708
|
|
|
777
|
-
it
|
|
709
|
+
it 'adds the uniqueness errors' do
|
|
778
710
|
dictionary.valid?
|
|
779
|
-
expect(dictionary.errors[:name]).to eq([
|
|
711
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
780
712
|
end
|
|
781
713
|
end
|
|
782
714
|
|
|
783
|
-
context
|
|
784
|
-
|
|
715
|
+
context 'when the document is the match in the database' do
|
|
785
716
|
let!(:dictionary) do
|
|
786
|
-
Dictionary.create!(name:
|
|
717
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
787
718
|
end
|
|
788
719
|
|
|
789
|
-
it
|
|
720
|
+
it 'returns true' do
|
|
790
721
|
expect(dictionary).to be_valid
|
|
791
722
|
end
|
|
792
723
|
end
|
|
793
724
|
|
|
794
|
-
context
|
|
795
|
-
|
|
725
|
+
context 'when one of the scopes is a time' do
|
|
796
726
|
before do
|
|
797
727
|
Dictionary.create!(
|
|
798
|
-
name:
|
|
799
|
-
publisher:
|
|
728
|
+
name: 'Oxford',
|
|
729
|
+
publisher: 'Amazon',
|
|
800
730
|
published: 10.days.ago.to_time
|
|
801
731
|
)
|
|
802
732
|
end
|
|
803
733
|
|
|
804
734
|
let(:dictionary) do
|
|
805
735
|
Dictionary.new(
|
|
806
|
-
name:
|
|
807
|
-
publisher:
|
|
736
|
+
name: 'Oxford',
|
|
737
|
+
publisher: 'Amazon',
|
|
808
738
|
published: 10.days.ago.to_time
|
|
809
739
|
)
|
|
810
740
|
end
|
|
811
741
|
|
|
812
|
-
it
|
|
813
|
-
expect(dictionary).
|
|
742
|
+
it 'returns false' do
|
|
743
|
+
expect(dictionary).not_to be_valid
|
|
814
744
|
end
|
|
815
745
|
|
|
816
|
-
it
|
|
746
|
+
it 'adds the uniqueness errors' do
|
|
817
747
|
dictionary.valid?
|
|
818
|
-
expect(dictionary.errors[:name]).to eq([
|
|
748
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
819
749
|
end
|
|
820
750
|
end
|
|
821
751
|
end
|
|
822
752
|
end
|
|
823
753
|
|
|
824
|
-
context
|
|
825
|
-
|
|
754
|
+
context 'when a range condition is provided' do
|
|
826
755
|
before do
|
|
827
756
|
Dictionary.validates_uniqueness_of(:name,
|
|
828
|
-
|
|
757
|
+
conditions: -> { Dictionary.where(:year.gte => 1900, :year.lt => 2000) })
|
|
829
758
|
end
|
|
830
759
|
|
|
831
760
|
after do
|
|
@@ -833,11 +762,11 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
833
762
|
end
|
|
834
763
|
|
|
835
764
|
context 'when multiple documents would match the condition' do
|
|
836
|
-
it
|
|
837
|
-
Dictionary.create!(name:
|
|
765
|
+
it 'prevents creation of new document' do
|
|
766
|
+
Dictionary.create!(name: 'French-English', year: 1950)
|
|
838
767
|
|
|
839
768
|
expect do
|
|
840
|
-
Dictionary.create!(name:
|
|
769
|
+
Dictionary.create!(name: 'French-English', year: 1960)
|
|
841
770
|
end.to raise_error(Mongoid::Errors::Validations, /Name has already been taken/)
|
|
842
771
|
|
|
843
772
|
expect(Dictionary.all.size).to eq(1)
|
|
@@ -846,9 +775,9 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
846
775
|
|
|
847
776
|
context 'when only new document would match the condition' do
|
|
848
777
|
it 'creates the new document' do
|
|
849
|
-
Dictionary.create!(name:
|
|
778
|
+
Dictionary.create!(name: 'French-English', year: 950)
|
|
850
779
|
expect do
|
|
851
|
-
Dictionary.create!(name:
|
|
780
|
+
Dictionary.create!(name: 'French-English', year: 1950)
|
|
852
781
|
end.not_to raise_error
|
|
853
782
|
end
|
|
854
783
|
end
|
|
@@ -857,149 +786,140 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
857
786
|
it 'creates the new document' do
|
|
858
787
|
pending 'https://jira.mongodb.org/browse/MONGOID-4815'
|
|
859
788
|
|
|
860
|
-
Dictionary.create!(name:
|
|
789
|
+
Dictionary.create!(name: 'French-English', year: 1950)
|
|
861
790
|
expect do
|
|
862
|
-
Dictionary.create!(name:
|
|
791
|
+
Dictionary.create!(name: 'French-English', year: 950)
|
|
863
792
|
end.not_to raise_error
|
|
864
793
|
end
|
|
865
794
|
end
|
|
866
795
|
end
|
|
867
796
|
|
|
868
|
-
context
|
|
869
|
-
|
|
797
|
+
context 'when multiple scopes are provided' do
|
|
870
798
|
before do
|
|
871
|
-
Dictionary.validates_uniqueness_of :name, scope: [
|
|
799
|
+
Dictionary.validates_uniqueness_of :name, scope: %i[publisher year]
|
|
872
800
|
end
|
|
873
801
|
|
|
874
802
|
after do
|
|
875
803
|
Dictionary.reset_callbacks(:validate)
|
|
876
804
|
end
|
|
877
805
|
|
|
878
|
-
context
|
|
879
|
-
|
|
806
|
+
context 'when the attribute is unique' do
|
|
880
807
|
before do
|
|
881
|
-
Dictionary.create!(name:
|
|
808
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
882
809
|
end
|
|
883
810
|
|
|
884
811
|
let(:dictionary) do
|
|
885
|
-
Dictionary.new(name:
|
|
812
|
+
Dictionary.new(name: 'Webster')
|
|
886
813
|
end
|
|
887
814
|
|
|
888
|
-
it
|
|
815
|
+
it 'returns true' do
|
|
889
816
|
expect(dictionary).to be_valid
|
|
890
817
|
end
|
|
891
818
|
end
|
|
892
819
|
|
|
893
|
-
context
|
|
894
|
-
|
|
820
|
+
context 'when the attribute is unique in the scope' do
|
|
895
821
|
before do
|
|
896
822
|
Dictionary.create!(
|
|
897
|
-
name:
|
|
898
|
-
publisher:
|
|
823
|
+
name: 'Oxford',
|
|
824
|
+
publisher: 'Amazon',
|
|
899
825
|
year: 2011
|
|
900
826
|
)
|
|
901
827
|
end
|
|
902
828
|
|
|
903
829
|
let(:dictionary) do
|
|
904
830
|
Dictionary.new(
|
|
905
|
-
name:
|
|
906
|
-
publisher:
|
|
831
|
+
name: 'Webster',
|
|
832
|
+
publisher: 'Amazon',
|
|
907
833
|
year: 2011
|
|
908
834
|
)
|
|
909
835
|
end
|
|
910
836
|
|
|
911
|
-
it
|
|
837
|
+
it 'returns true' do
|
|
912
838
|
expect(dictionary).to be_valid
|
|
913
839
|
end
|
|
914
840
|
end
|
|
915
841
|
|
|
916
|
-
context
|
|
917
|
-
|
|
842
|
+
context 'when the attribute is not unique with no scope' do
|
|
918
843
|
before do
|
|
919
|
-
Dictionary.create!(name:
|
|
844
|
+
Dictionary.create!(name: 'Oxford', publisher: 'Amazon')
|
|
920
845
|
end
|
|
921
846
|
|
|
922
847
|
let(:dictionary) do
|
|
923
|
-
Dictionary.new(name:
|
|
848
|
+
Dictionary.new(name: 'Oxford')
|
|
924
849
|
end
|
|
925
850
|
|
|
926
|
-
it
|
|
851
|
+
it 'returns true' do
|
|
927
852
|
expect(dictionary).to be_valid
|
|
928
853
|
end
|
|
929
854
|
end
|
|
930
855
|
|
|
931
|
-
context
|
|
932
|
-
|
|
856
|
+
context 'when the attribute is not unique in another scope' do
|
|
933
857
|
before do
|
|
934
858
|
Dictionary.create!(
|
|
935
|
-
name:
|
|
936
|
-
publisher:
|
|
859
|
+
name: 'Oxford',
|
|
860
|
+
publisher: 'Amazon',
|
|
937
861
|
year: 1995
|
|
938
862
|
)
|
|
939
863
|
end
|
|
940
864
|
|
|
941
865
|
let(:dictionary) do
|
|
942
866
|
Dictionary.new(
|
|
943
|
-
name:
|
|
944
|
-
publisher:
|
|
867
|
+
name: 'Oxford',
|
|
868
|
+
publisher: 'Addison',
|
|
945
869
|
year: 2011
|
|
946
870
|
)
|
|
947
871
|
end
|
|
948
872
|
|
|
949
|
-
it
|
|
873
|
+
it 'returns true' do
|
|
950
874
|
expect(dictionary).to be_valid
|
|
951
875
|
end
|
|
952
876
|
end
|
|
953
877
|
|
|
954
|
-
context
|
|
955
|
-
|
|
956
|
-
context "when the document is not the match" do
|
|
957
|
-
|
|
878
|
+
context 'when the attribute is not unique in the same scope' do
|
|
879
|
+
context 'when the document is not the match' do
|
|
958
880
|
before do
|
|
959
881
|
Dictionary.create!(
|
|
960
|
-
name:
|
|
961
|
-
publisher:
|
|
882
|
+
name: 'Oxford',
|
|
883
|
+
publisher: 'Amazon',
|
|
962
884
|
year: 1960
|
|
963
885
|
)
|
|
964
886
|
end
|
|
965
887
|
|
|
966
888
|
let(:dictionary) do
|
|
967
889
|
Dictionary.new(
|
|
968
|
-
name:
|
|
969
|
-
publisher:
|
|
890
|
+
name: 'Oxford',
|
|
891
|
+
publisher: 'Amazon',
|
|
970
892
|
year: 1960
|
|
971
893
|
)
|
|
972
894
|
end
|
|
973
895
|
|
|
974
|
-
it
|
|
975
|
-
expect(dictionary).
|
|
896
|
+
it 'returns false' do
|
|
897
|
+
expect(dictionary).not_to be_valid
|
|
976
898
|
end
|
|
977
899
|
|
|
978
|
-
it
|
|
900
|
+
it 'adds the uniqueness errors' do
|
|
979
901
|
dictionary.valid?
|
|
980
|
-
expect(dictionary.errors[:name]).to eq([
|
|
902
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
981
903
|
end
|
|
982
904
|
end
|
|
983
905
|
|
|
984
|
-
context
|
|
985
|
-
|
|
906
|
+
context 'when the document is the match in the database' do
|
|
986
907
|
let!(:dictionary) do
|
|
987
908
|
Dictionary.create!(
|
|
988
|
-
name:
|
|
989
|
-
publisher:
|
|
909
|
+
name: 'Oxford',
|
|
910
|
+
publisher: 'Amazon',
|
|
990
911
|
year: 1960
|
|
991
912
|
)
|
|
992
913
|
end
|
|
993
914
|
|
|
994
|
-
it
|
|
915
|
+
it 'returns true' do
|
|
995
916
|
expect(dictionary).to be_valid
|
|
996
917
|
end
|
|
997
918
|
end
|
|
998
919
|
end
|
|
999
920
|
end
|
|
1000
921
|
|
|
1001
|
-
context
|
|
1002
|
-
|
|
922
|
+
context 'when case sensitive is true' do
|
|
1003
923
|
before do
|
|
1004
924
|
Dictionary.validates_uniqueness_of :name
|
|
1005
925
|
end
|
|
@@ -1008,58 +928,53 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1008
928
|
Dictionary.reset_callbacks(:validate)
|
|
1009
929
|
end
|
|
1010
930
|
|
|
1011
|
-
context
|
|
1012
|
-
|
|
931
|
+
context 'when the attribute is unique' do
|
|
1013
932
|
before do
|
|
1014
|
-
Dictionary.create!(name:
|
|
933
|
+
Dictionary.create!(name: 'Oxford')
|
|
1015
934
|
end
|
|
1016
935
|
|
|
1017
936
|
let(:dictionary) do
|
|
1018
|
-
Dictionary.new(name:
|
|
937
|
+
Dictionary.new(name: 'Webster')
|
|
1019
938
|
end
|
|
1020
939
|
|
|
1021
|
-
it
|
|
940
|
+
it 'returns true' do
|
|
1022
941
|
expect(dictionary).to be_valid
|
|
1023
942
|
end
|
|
1024
943
|
end
|
|
1025
944
|
|
|
1026
|
-
context
|
|
1027
|
-
|
|
1028
|
-
context "when the document is not the match" do
|
|
1029
|
-
|
|
945
|
+
context 'when the attribute is not unique' do
|
|
946
|
+
context 'when the document is not the match' do
|
|
1030
947
|
before do
|
|
1031
|
-
Dictionary.create!(name:
|
|
948
|
+
Dictionary.create!(name: 'Oxford')
|
|
1032
949
|
end
|
|
1033
950
|
|
|
1034
951
|
let(:dictionary) do
|
|
1035
|
-
Dictionary.new(name:
|
|
952
|
+
Dictionary.new(name: 'Oxford')
|
|
1036
953
|
end
|
|
1037
954
|
|
|
1038
|
-
it
|
|
1039
|
-
expect(dictionary).
|
|
955
|
+
it 'returns false' do
|
|
956
|
+
expect(dictionary).not_to be_valid
|
|
1040
957
|
end
|
|
1041
958
|
|
|
1042
|
-
it
|
|
959
|
+
it 'adds the uniqueness error' do
|
|
1043
960
|
dictionary.valid?
|
|
1044
|
-
expect(dictionary.errors[:name]).to eq([
|
|
961
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
1045
962
|
end
|
|
1046
963
|
end
|
|
1047
964
|
|
|
1048
|
-
context
|
|
1049
|
-
|
|
965
|
+
context 'when the document is the match in the database' do
|
|
1050
966
|
let!(:dictionary) do
|
|
1051
|
-
Dictionary.create!(name:
|
|
967
|
+
Dictionary.create!(name: 'Oxford')
|
|
1052
968
|
end
|
|
1053
969
|
|
|
1054
|
-
it
|
|
970
|
+
it 'returns true' do
|
|
1055
971
|
expect(dictionary).to be_valid
|
|
1056
972
|
end
|
|
1057
973
|
end
|
|
1058
974
|
end
|
|
1059
975
|
end
|
|
1060
976
|
|
|
1061
|
-
context
|
|
1062
|
-
|
|
977
|
+
context 'when case sensitive is false' do
|
|
1063
978
|
before do
|
|
1064
979
|
Dictionary.validates_uniqueness_of :name, case_sensitive: false
|
|
1065
980
|
end
|
|
@@ -1068,83 +983,75 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1068
983
|
Dictionary.reset_callbacks(:validate)
|
|
1069
984
|
end
|
|
1070
985
|
|
|
1071
|
-
context
|
|
1072
|
-
|
|
1073
|
-
context "when there are no special characters" do
|
|
1074
|
-
|
|
986
|
+
context 'when the attribute is unique' do
|
|
987
|
+
context 'when there are no special characters' do
|
|
1075
988
|
before do
|
|
1076
|
-
Dictionary.create!(name:
|
|
989
|
+
Dictionary.create!(name: 'Oxford')
|
|
1077
990
|
end
|
|
1078
991
|
|
|
1079
992
|
let(:dictionary) do
|
|
1080
|
-
Dictionary.new(name:
|
|
993
|
+
Dictionary.new(name: 'Webster')
|
|
1081
994
|
end
|
|
1082
995
|
|
|
1083
|
-
it
|
|
996
|
+
it 'returns true' do
|
|
1084
997
|
expect(dictionary).to be_valid
|
|
1085
998
|
end
|
|
1086
999
|
end
|
|
1087
1000
|
|
|
1088
|
-
context
|
|
1089
|
-
|
|
1001
|
+
context 'when special characters exist' do
|
|
1090
1002
|
before do
|
|
1091
|
-
Dictionary.create!(name:
|
|
1003
|
+
Dictionary.create!(name: 'Oxford')
|
|
1092
1004
|
end
|
|
1093
1005
|
|
|
1094
1006
|
let(:dictionary) do
|
|
1095
|
-
Dictionary.new(name:
|
|
1007
|
+
Dictionary.new(name: 'Web@st.er')
|
|
1096
1008
|
end
|
|
1097
1009
|
|
|
1098
|
-
it
|
|
1010
|
+
it 'returns true' do
|
|
1099
1011
|
expect(dictionary).to be_valid
|
|
1100
1012
|
end
|
|
1101
1013
|
end
|
|
1102
1014
|
end
|
|
1103
1015
|
|
|
1104
|
-
context
|
|
1105
|
-
|
|
1106
|
-
context "when the document is not the match" do
|
|
1107
|
-
|
|
1016
|
+
context 'when the attribute is not unique' do
|
|
1017
|
+
context 'when the document is not the match' do
|
|
1108
1018
|
before do
|
|
1109
|
-
Dictionary.create!(name:
|
|
1019
|
+
Dictionary.create!(name: 'Oxford')
|
|
1110
1020
|
end
|
|
1111
1021
|
|
|
1112
1022
|
let(:dictionary) do
|
|
1113
|
-
Dictionary.new(name:
|
|
1023
|
+
Dictionary.new(name: 'oxford')
|
|
1114
1024
|
end
|
|
1115
1025
|
|
|
1116
|
-
it
|
|
1117
|
-
expect(dictionary).
|
|
1026
|
+
it 'returns false' do
|
|
1027
|
+
expect(dictionary).not_to be_valid
|
|
1118
1028
|
end
|
|
1119
1029
|
|
|
1120
|
-
it
|
|
1030
|
+
it 'adds the uniqueness error' do
|
|
1121
1031
|
dictionary.valid?
|
|
1122
|
-
expect(dictionary.errors[:name]).to eq([
|
|
1032
|
+
expect(dictionary.errors[:name]).to eq([ 'has already been taken' ])
|
|
1123
1033
|
end
|
|
1124
1034
|
end
|
|
1125
1035
|
|
|
1126
|
-
context
|
|
1127
|
-
|
|
1036
|
+
context 'when the document is the match in the database' do
|
|
1128
1037
|
let!(:dictionary) do
|
|
1129
|
-
Dictionary.create!(name:
|
|
1038
|
+
Dictionary.create!(name: 'Oxford')
|
|
1130
1039
|
end
|
|
1131
1040
|
|
|
1132
|
-
it
|
|
1041
|
+
it 'returns true' do
|
|
1133
1042
|
expect(dictionary).to be_valid
|
|
1134
1043
|
end
|
|
1135
1044
|
end
|
|
1136
1045
|
end
|
|
1137
1046
|
end
|
|
1138
1047
|
|
|
1139
|
-
context
|
|
1140
|
-
|
|
1141
|
-
it "raises a validation error" do
|
|
1048
|
+
context 'when not allowing nil' do
|
|
1049
|
+
it 'raises a validation error' do
|
|
1142
1050
|
expect { LineItem.create! }.to raise_error Mongoid::Errors::Validations
|
|
1143
1051
|
end
|
|
1144
1052
|
end
|
|
1145
1053
|
|
|
1146
|
-
context
|
|
1147
|
-
|
|
1054
|
+
context 'when allowing nil' do
|
|
1148
1055
|
before do
|
|
1149
1056
|
Dictionary.validates_uniqueness_of :name, allow_nil: true
|
|
1150
1057
|
end
|
|
@@ -1153,8 +1060,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1153
1060
|
Dictionary.reset_callbacks(:validate)
|
|
1154
1061
|
end
|
|
1155
1062
|
|
|
1156
|
-
context
|
|
1157
|
-
|
|
1063
|
+
context 'when the attribute is nil' do
|
|
1158
1064
|
before do
|
|
1159
1065
|
Dictionary.create!
|
|
1160
1066
|
end
|
|
@@ -1163,14 +1069,13 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1163
1069
|
Dictionary.new
|
|
1164
1070
|
end
|
|
1165
1071
|
|
|
1166
|
-
it
|
|
1072
|
+
it 'returns true' do
|
|
1167
1073
|
expect(dictionary).to be_valid
|
|
1168
1074
|
end
|
|
1169
1075
|
end
|
|
1170
1076
|
end
|
|
1171
1077
|
|
|
1172
|
-
context
|
|
1173
|
-
|
|
1078
|
+
context 'when allowing blank' do
|
|
1174
1079
|
before do
|
|
1175
1080
|
Dictionary.validates_uniqueness_of :name, allow_blank: true
|
|
1176
1081
|
end
|
|
@@ -1179,27 +1084,24 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1179
1084
|
Dictionary.reset_callbacks(:validate)
|
|
1180
1085
|
end
|
|
1181
1086
|
|
|
1182
|
-
context
|
|
1183
|
-
|
|
1087
|
+
context 'when the attribute is blank' do
|
|
1184
1088
|
before do
|
|
1185
|
-
Dictionary.create!(name:
|
|
1089
|
+
Dictionary.create!(name: '')
|
|
1186
1090
|
end
|
|
1187
1091
|
|
|
1188
1092
|
let(:dictionary) do
|
|
1189
|
-
Dictionary.new(name:
|
|
1093
|
+
Dictionary.new(name: '')
|
|
1190
1094
|
end
|
|
1191
1095
|
|
|
1192
|
-
it
|
|
1096
|
+
it 'returns true' do
|
|
1193
1097
|
expect(dictionary).to be_valid
|
|
1194
1098
|
end
|
|
1195
1099
|
end
|
|
1196
1100
|
end
|
|
1197
1101
|
end
|
|
1198
1102
|
|
|
1199
|
-
context
|
|
1200
|
-
|
|
1201
|
-
context "when no scope is provided" do
|
|
1202
|
-
|
|
1103
|
+
context 'when the document contains a compound key' do
|
|
1104
|
+
context 'when no scope is provided' do
|
|
1203
1105
|
before do
|
|
1204
1106
|
Login.validates_uniqueness_of :username
|
|
1205
1107
|
end
|
|
@@ -1208,58 +1110,53 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1208
1110
|
Login.reset_callbacks(:validate)
|
|
1209
1111
|
end
|
|
1210
1112
|
|
|
1211
|
-
context
|
|
1212
|
-
|
|
1113
|
+
context 'when the attribute is unique' do
|
|
1213
1114
|
before do
|
|
1214
|
-
Login.create!(username:
|
|
1115
|
+
Login.create!(username: 'Oxford')
|
|
1215
1116
|
end
|
|
1216
1117
|
|
|
1217
1118
|
let(:login) do
|
|
1218
|
-
Login.new(username:
|
|
1119
|
+
Login.new(username: 'Webster')
|
|
1219
1120
|
end
|
|
1220
1121
|
|
|
1221
|
-
it
|
|
1122
|
+
it 'returns true' do
|
|
1222
1123
|
expect(login).to be_valid
|
|
1223
1124
|
end
|
|
1224
1125
|
end
|
|
1225
1126
|
|
|
1226
|
-
context
|
|
1227
|
-
|
|
1228
|
-
context "when the document is not the match" do
|
|
1229
|
-
|
|
1127
|
+
context 'when the attribute is not unique' do
|
|
1128
|
+
context 'when the document is not the match' do
|
|
1230
1129
|
before do
|
|
1231
|
-
Login.create!(username:
|
|
1130
|
+
Login.create!(username: 'Oxford')
|
|
1232
1131
|
end
|
|
1233
1132
|
|
|
1234
1133
|
let(:login) do
|
|
1235
|
-
Login.new(username:
|
|
1134
|
+
Login.new(username: 'Oxford')
|
|
1236
1135
|
end
|
|
1237
1136
|
|
|
1238
|
-
it
|
|
1239
|
-
expect(login).
|
|
1137
|
+
it 'returns false' do
|
|
1138
|
+
expect(login).not_to be_valid
|
|
1240
1139
|
end
|
|
1241
1140
|
|
|
1242
|
-
it
|
|
1141
|
+
it 'adds the uniqueness error' do
|
|
1243
1142
|
login.valid?
|
|
1244
|
-
expect(login.errors[:username]).to eq([
|
|
1143
|
+
expect(login.errors[:username]).to eq([ 'has already been taken' ])
|
|
1245
1144
|
end
|
|
1246
1145
|
end
|
|
1247
1146
|
|
|
1248
|
-
context
|
|
1249
|
-
|
|
1147
|
+
context 'when the document is the match in the database' do
|
|
1250
1148
|
let!(:login) do
|
|
1251
|
-
Login.create!(username:
|
|
1149
|
+
Login.create!(username: 'Oxford')
|
|
1252
1150
|
end
|
|
1253
1151
|
|
|
1254
|
-
it
|
|
1152
|
+
it 'returns true' do
|
|
1255
1153
|
expect(login).to be_valid
|
|
1256
1154
|
end
|
|
1257
1155
|
end
|
|
1258
1156
|
end
|
|
1259
1157
|
end
|
|
1260
1158
|
|
|
1261
|
-
context
|
|
1262
|
-
|
|
1159
|
+
context 'when a single scope is provided' do
|
|
1263
1160
|
before do
|
|
1264
1161
|
Login.validates_uniqueness_of :username, scope: :application_id
|
|
1265
1162
|
end
|
|
@@ -1268,103 +1165,95 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1268
1165
|
Login.reset_callbacks(:validate)
|
|
1269
1166
|
end
|
|
1270
1167
|
|
|
1271
|
-
context
|
|
1272
|
-
|
|
1168
|
+
context 'when the attribute is unique' do
|
|
1273
1169
|
before do
|
|
1274
|
-
Login.create!(username:
|
|
1170
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1275
1171
|
end
|
|
1276
1172
|
|
|
1277
1173
|
let(:login) do
|
|
1278
|
-
Login.new(username:
|
|
1174
|
+
Login.new(username: 'Webster')
|
|
1279
1175
|
end
|
|
1280
1176
|
|
|
1281
|
-
it
|
|
1177
|
+
it 'returns true' do
|
|
1282
1178
|
expect(login).to be_valid
|
|
1283
1179
|
end
|
|
1284
1180
|
end
|
|
1285
1181
|
|
|
1286
|
-
context
|
|
1287
|
-
|
|
1182
|
+
context 'when the attribute is unique in the scope' do
|
|
1288
1183
|
before do
|
|
1289
|
-
Login.create!(username:
|
|
1184
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1290
1185
|
end
|
|
1291
1186
|
|
|
1292
1187
|
let(:login) do
|
|
1293
|
-
Login.new(username:
|
|
1188
|
+
Login.new(username: 'Webster', application_id: 1)
|
|
1294
1189
|
end
|
|
1295
1190
|
|
|
1296
|
-
it
|
|
1191
|
+
it 'returns true' do
|
|
1297
1192
|
expect(login).to be_valid
|
|
1298
1193
|
end
|
|
1299
1194
|
end
|
|
1300
1195
|
|
|
1301
|
-
context
|
|
1302
|
-
|
|
1196
|
+
context 'when the attribute is not unique with no scope' do
|
|
1303
1197
|
before do
|
|
1304
|
-
Login.create!(username:
|
|
1198
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1305
1199
|
end
|
|
1306
1200
|
|
|
1307
1201
|
let(:login) do
|
|
1308
|
-
Login.new(username:
|
|
1202
|
+
Login.new(username: 'Oxford')
|
|
1309
1203
|
end
|
|
1310
1204
|
|
|
1311
|
-
it
|
|
1205
|
+
it 'returns true' do
|
|
1312
1206
|
expect(login).to be_valid
|
|
1313
1207
|
end
|
|
1314
1208
|
end
|
|
1315
1209
|
|
|
1316
|
-
context
|
|
1317
|
-
|
|
1210
|
+
context 'when the attribute is not unique in another scope' do
|
|
1318
1211
|
before do
|
|
1319
|
-
Login.create!(username:
|
|
1212
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1320
1213
|
end
|
|
1321
1214
|
|
|
1322
1215
|
let(:login) do
|
|
1323
|
-
Login.new(username:
|
|
1216
|
+
Login.new(username: 'Oxford', application_id: 2)
|
|
1324
1217
|
end
|
|
1325
1218
|
|
|
1326
|
-
it
|
|
1219
|
+
it 'returns true' do
|
|
1327
1220
|
expect(login).to be_valid
|
|
1328
1221
|
end
|
|
1329
1222
|
end
|
|
1330
1223
|
|
|
1331
|
-
context
|
|
1332
|
-
|
|
1333
|
-
context "when the document is not the match" do
|
|
1334
|
-
|
|
1224
|
+
context 'when the attribute is not unique in the same scope' do
|
|
1225
|
+
context 'when the document is not the match' do
|
|
1335
1226
|
before do
|
|
1336
|
-
Login.create!(username:
|
|
1227
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1337
1228
|
end
|
|
1338
1229
|
|
|
1339
1230
|
let(:login) do
|
|
1340
|
-
Login.new(username:
|
|
1231
|
+
Login.new(username: 'Oxford', application_id: 1)
|
|
1341
1232
|
end
|
|
1342
1233
|
|
|
1343
|
-
it
|
|
1344
|
-
expect(login).
|
|
1234
|
+
it 'returns false' do
|
|
1235
|
+
expect(login).not_to be_valid
|
|
1345
1236
|
end
|
|
1346
1237
|
|
|
1347
|
-
it
|
|
1238
|
+
it 'adds the uniqueness errors' do
|
|
1348
1239
|
login.valid?
|
|
1349
|
-
expect(login.errors[:username]).to eq([
|
|
1240
|
+
expect(login.errors[:username]).to eq([ 'has already been taken' ])
|
|
1350
1241
|
end
|
|
1351
1242
|
end
|
|
1352
1243
|
|
|
1353
|
-
context
|
|
1354
|
-
|
|
1244
|
+
context 'when the document is the match in the database' do
|
|
1355
1245
|
let!(:login) do
|
|
1356
|
-
Login.create!(username:
|
|
1246
|
+
Login.create!(username: 'Oxford', application_id: 1)
|
|
1357
1247
|
end
|
|
1358
1248
|
|
|
1359
|
-
it
|
|
1249
|
+
it 'returns true' do
|
|
1360
1250
|
expect(login).to be_valid
|
|
1361
1251
|
end
|
|
1362
1252
|
end
|
|
1363
1253
|
end
|
|
1364
1254
|
end
|
|
1365
1255
|
|
|
1366
|
-
context
|
|
1367
|
-
|
|
1256
|
+
context 'when case sensitive is true' do
|
|
1368
1257
|
before do
|
|
1369
1258
|
Login.validates_uniqueness_of :username
|
|
1370
1259
|
end
|
|
@@ -1373,58 +1262,53 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1373
1262
|
Login.reset_callbacks(:validate)
|
|
1374
1263
|
end
|
|
1375
1264
|
|
|
1376
|
-
context
|
|
1377
|
-
|
|
1265
|
+
context 'when the attribute is unique' do
|
|
1378
1266
|
before do
|
|
1379
|
-
Login.create!(username:
|
|
1267
|
+
Login.create!(username: 'Oxford')
|
|
1380
1268
|
end
|
|
1381
1269
|
|
|
1382
1270
|
let(:login) do
|
|
1383
|
-
Login.new(username:
|
|
1271
|
+
Login.new(username: 'Webster')
|
|
1384
1272
|
end
|
|
1385
1273
|
|
|
1386
|
-
it
|
|
1274
|
+
it 'returns true' do
|
|
1387
1275
|
expect(login).to be_valid
|
|
1388
1276
|
end
|
|
1389
1277
|
end
|
|
1390
1278
|
|
|
1391
|
-
context
|
|
1392
|
-
|
|
1393
|
-
context "when the document is not the match" do
|
|
1394
|
-
|
|
1279
|
+
context 'when the attribute is not unique' do
|
|
1280
|
+
context 'when the document is not the match' do
|
|
1395
1281
|
before do
|
|
1396
|
-
Login.create!(username:
|
|
1282
|
+
Login.create!(username: 'Oxford')
|
|
1397
1283
|
end
|
|
1398
1284
|
|
|
1399
1285
|
let(:login) do
|
|
1400
|
-
Login.new(username:
|
|
1286
|
+
Login.new(username: 'Oxford')
|
|
1401
1287
|
end
|
|
1402
1288
|
|
|
1403
|
-
it
|
|
1404
|
-
expect(login).
|
|
1289
|
+
it 'returns false' do
|
|
1290
|
+
expect(login).not_to be_valid
|
|
1405
1291
|
end
|
|
1406
1292
|
|
|
1407
|
-
it
|
|
1293
|
+
it 'adds the uniqueness error' do
|
|
1408
1294
|
login.valid?
|
|
1409
|
-
expect(login.errors[:username]).to eq([
|
|
1295
|
+
expect(login.errors[:username]).to eq([ 'has already been taken' ])
|
|
1410
1296
|
end
|
|
1411
1297
|
end
|
|
1412
1298
|
|
|
1413
|
-
context
|
|
1414
|
-
|
|
1299
|
+
context 'when the document is the match in the database' do
|
|
1415
1300
|
let!(:login) do
|
|
1416
|
-
Login.create!(username:
|
|
1301
|
+
Login.create!(username: 'Oxford')
|
|
1417
1302
|
end
|
|
1418
1303
|
|
|
1419
|
-
it
|
|
1304
|
+
it 'returns true' do
|
|
1420
1305
|
expect(login).to be_valid
|
|
1421
1306
|
end
|
|
1422
1307
|
end
|
|
1423
1308
|
end
|
|
1424
1309
|
end
|
|
1425
1310
|
|
|
1426
|
-
context
|
|
1427
|
-
|
|
1311
|
+
context 'when case sensitive is false' do
|
|
1428
1312
|
before do
|
|
1429
1313
|
Login.validates_uniqueness_of :username, case_sensitive: false
|
|
1430
1314
|
end
|
|
@@ -1433,76 +1317,69 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1433
1317
|
Login.reset_callbacks(:validate)
|
|
1434
1318
|
end
|
|
1435
1319
|
|
|
1436
|
-
context
|
|
1437
|
-
|
|
1438
|
-
context "when there are no special characters" do
|
|
1439
|
-
|
|
1320
|
+
context 'when the attribute is unique' do
|
|
1321
|
+
context 'when there are no special characters' do
|
|
1440
1322
|
before do
|
|
1441
|
-
Login.create!(username:
|
|
1323
|
+
Login.create!(username: 'Oxford')
|
|
1442
1324
|
end
|
|
1443
1325
|
|
|
1444
1326
|
let(:login) do
|
|
1445
|
-
Login.new(username:
|
|
1327
|
+
Login.new(username: 'Webster')
|
|
1446
1328
|
end
|
|
1447
1329
|
|
|
1448
|
-
it
|
|
1330
|
+
it 'returns true' do
|
|
1449
1331
|
expect(login).to be_valid
|
|
1450
1332
|
end
|
|
1451
1333
|
end
|
|
1452
1334
|
|
|
1453
|
-
context
|
|
1454
|
-
|
|
1335
|
+
context 'when special characters exist' do
|
|
1455
1336
|
before do
|
|
1456
|
-
Login.create!(username:
|
|
1337
|
+
Login.create!(username: 'Oxford')
|
|
1457
1338
|
end
|
|
1458
1339
|
|
|
1459
1340
|
let(:login) do
|
|
1460
|
-
Login.new(username:
|
|
1341
|
+
Login.new(username: 'Web@st.er')
|
|
1461
1342
|
end
|
|
1462
1343
|
|
|
1463
|
-
it
|
|
1344
|
+
it 'returns true' do
|
|
1464
1345
|
expect(login).to be_valid
|
|
1465
1346
|
end
|
|
1466
1347
|
end
|
|
1467
1348
|
end
|
|
1468
1349
|
|
|
1469
|
-
context
|
|
1470
|
-
|
|
1471
|
-
context "when the document is not the match" do
|
|
1472
|
-
|
|
1350
|
+
context 'when the attribute is not unique' do
|
|
1351
|
+
context 'when the document is not the match' do
|
|
1473
1352
|
before do
|
|
1474
|
-
Login.create!(username:
|
|
1353
|
+
Login.create!(username: 'Oxford')
|
|
1475
1354
|
end
|
|
1476
1355
|
|
|
1477
1356
|
let(:login) do
|
|
1478
|
-
Login.new(username:
|
|
1357
|
+
Login.new(username: 'oxford')
|
|
1479
1358
|
end
|
|
1480
1359
|
|
|
1481
|
-
it
|
|
1482
|
-
expect(login).
|
|
1360
|
+
it 'returns false' do
|
|
1361
|
+
expect(login).not_to be_valid
|
|
1483
1362
|
end
|
|
1484
1363
|
|
|
1485
|
-
it
|
|
1364
|
+
it 'adds the uniqueness error' do
|
|
1486
1365
|
login.valid?
|
|
1487
|
-
expect(login.errors[:username]).to eq([
|
|
1366
|
+
expect(login.errors[:username]).to eq([ 'has already been taken' ])
|
|
1488
1367
|
end
|
|
1489
1368
|
end
|
|
1490
1369
|
|
|
1491
|
-
context
|
|
1492
|
-
|
|
1370
|
+
context 'when the document is the match in the database' do
|
|
1493
1371
|
let!(:login) do
|
|
1494
|
-
Login.create!(username:
|
|
1372
|
+
Login.create!(username: 'Oxford')
|
|
1495
1373
|
end
|
|
1496
1374
|
|
|
1497
|
-
it
|
|
1375
|
+
it 'returns true' do
|
|
1498
1376
|
expect(login).to be_valid
|
|
1499
1377
|
end
|
|
1500
1378
|
end
|
|
1501
1379
|
end
|
|
1502
1380
|
end
|
|
1503
1381
|
|
|
1504
|
-
context
|
|
1505
|
-
|
|
1382
|
+
context 'when allowing nil' do
|
|
1506
1383
|
before do
|
|
1507
1384
|
Login.validates_uniqueness_of :username, allow_nil: true
|
|
1508
1385
|
end
|
|
@@ -1511,8 +1388,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1511
1388
|
Login.reset_callbacks(:validate)
|
|
1512
1389
|
end
|
|
1513
1390
|
|
|
1514
|
-
context
|
|
1515
|
-
|
|
1391
|
+
context 'when the attribute is nil' do
|
|
1516
1392
|
before do
|
|
1517
1393
|
Login.create!
|
|
1518
1394
|
end
|
|
@@ -1521,14 +1397,13 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1521
1397
|
Login.new
|
|
1522
1398
|
end
|
|
1523
1399
|
|
|
1524
|
-
it
|
|
1400
|
+
it 'returns true' do
|
|
1525
1401
|
expect(login).to be_valid
|
|
1526
1402
|
end
|
|
1527
1403
|
end
|
|
1528
1404
|
end
|
|
1529
1405
|
|
|
1530
|
-
context
|
|
1531
|
-
|
|
1406
|
+
context 'when allowing blank' do
|
|
1532
1407
|
before do
|
|
1533
1408
|
Login.validates_uniqueness_of :username, allow_blank: true
|
|
1534
1409
|
end
|
|
@@ -1537,25 +1412,23 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1537
1412
|
Login.reset_callbacks(:validate)
|
|
1538
1413
|
end
|
|
1539
1414
|
|
|
1540
|
-
context
|
|
1541
|
-
|
|
1415
|
+
context 'when the attribute is blank' do
|
|
1542
1416
|
before do
|
|
1543
|
-
Login.create!(username:
|
|
1417
|
+
Login.create!(username: '')
|
|
1544
1418
|
end
|
|
1545
1419
|
|
|
1546
1420
|
let(:login) do
|
|
1547
|
-
Login.new(username:
|
|
1421
|
+
Login.new(username: '')
|
|
1548
1422
|
end
|
|
1549
1423
|
|
|
1550
|
-
it
|
|
1424
|
+
it 'returns true' do
|
|
1551
1425
|
expect(login).to be_valid
|
|
1552
1426
|
end
|
|
1553
1427
|
end
|
|
1554
1428
|
end
|
|
1555
1429
|
end
|
|
1556
1430
|
|
|
1557
|
-
context
|
|
1558
|
-
|
|
1431
|
+
context 'when the attribute is a custom type' do
|
|
1559
1432
|
before do
|
|
1560
1433
|
Bar.validates_uniqueness_of :lat_lng
|
|
1561
1434
|
end
|
|
@@ -1564,8 +1437,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1564
1437
|
Bar.reset_callbacks(:validate)
|
|
1565
1438
|
end
|
|
1566
1439
|
|
|
1567
|
-
context
|
|
1568
|
-
|
|
1440
|
+
context 'when the attribute is unique' do
|
|
1569
1441
|
before do
|
|
1570
1442
|
Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
|
|
1571
1443
|
end
|
|
@@ -1574,14 +1446,12 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1574
1446
|
Bar.new(lat_lng: LatLng.new(54.30, 14.25))
|
|
1575
1447
|
end
|
|
1576
1448
|
|
|
1577
|
-
it
|
|
1449
|
+
it 'returns true' do
|
|
1578
1450
|
expect(unique_bar).to be_valid
|
|
1579
1451
|
end
|
|
1580
|
-
|
|
1581
1452
|
end
|
|
1582
1453
|
|
|
1583
|
-
context
|
|
1584
|
-
|
|
1454
|
+
context 'when the attribute is not unique' do
|
|
1585
1455
|
before do
|
|
1586
1456
|
Bar.create!(lat_lng: LatLng.new(52.30, 13.25))
|
|
1587
1457
|
end
|
|
@@ -1590,25 +1460,22 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1590
1460
|
Bar.new(lat_lng: LatLng.new(52.30, 13.25))
|
|
1591
1461
|
end
|
|
1592
1462
|
|
|
1593
|
-
it
|
|
1594
|
-
expect(non_unique_bar).
|
|
1463
|
+
it 'returns false' do
|
|
1464
|
+
expect(non_unique_bar).not_to be_valid
|
|
1595
1465
|
end
|
|
1596
|
-
|
|
1597
1466
|
end
|
|
1598
1467
|
end
|
|
1599
1468
|
|
|
1600
|
-
context
|
|
1601
|
-
|
|
1469
|
+
context 'when conditions is set' do
|
|
1602
1470
|
before do
|
|
1603
|
-
Band.validates_uniqueness_of :name, conditions: ->{ Band.where(active: true) }
|
|
1471
|
+
Band.validates_uniqueness_of :name, conditions: -> { Band.where(active: true) }
|
|
1604
1472
|
end
|
|
1605
1473
|
|
|
1606
1474
|
after do
|
|
1607
1475
|
Band.reset_callbacks(:validate)
|
|
1608
1476
|
end
|
|
1609
1477
|
|
|
1610
|
-
context
|
|
1611
|
-
|
|
1478
|
+
context 'when the attribute is unique' do
|
|
1612
1479
|
before do
|
|
1613
1480
|
Band.create!(name: 'Foo', active: false)
|
|
1614
1481
|
end
|
|
@@ -1617,14 +1484,12 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1617
1484
|
Band.new(name: 'Foo')
|
|
1618
1485
|
end
|
|
1619
1486
|
|
|
1620
|
-
it
|
|
1487
|
+
it 'returns true' do
|
|
1621
1488
|
expect(unique_band).to be_valid
|
|
1622
1489
|
end
|
|
1623
|
-
|
|
1624
1490
|
end
|
|
1625
1491
|
|
|
1626
|
-
context
|
|
1627
|
-
|
|
1492
|
+
context 'when the attribute is not unique' do
|
|
1628
1493
|
before do
|
|
1629
1494
|
Band.create!(name: 'Foo')
|
|
1630
1495
|
end
|
|
@@ -1633,32 +1498,29 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1633
1498
|
Band.new(name: 'Foo')
|
|
1634
1499
|
end
|
|
1635
1500
|
|
|
1636
|
-
it
|
|
1637
|
-
expect(non_unique_band).
|
|
1501
|
+
it 'returns false' do
|
|
1502
|
+
expect(non_unique_band).not_to be_valid
|
|
1638
1503
|
end
|
|
1639
1504
|
end
|
|
1640
1505
|
end
|
|
1641
1506
|
end
|
|
1642
1507
|
end
|
|
1643
1508
|
|
|
1644
|
-
context
|
|
1645
|
-
|
|
1509
|
+
context 'when the document is embedded' do
|
|
1646
1510
|
let(:word) do
|
|
1647
|
-
Word.create!(name:
|
|
1511
|
+
Word.create!(name: 'Schadenfreude')
|
|
1648
1512
|
end
|
|
1649
1513
|
|
|
1650
|
-
context
|
|
1651
|
-
|
|
1514
|
+
context 'when in an embeds_many' do
|
|
1652
1515
|
let!(:def_one) do
|
|
1653
|
-
word.definitions.create!(description:
|
|
1516
|
+
word.definitions.create!(description: '1')
|
|
1654
1517
|
end
|
|
1655
1518
|
|
|
1656
1519
|
let!(:def_two) do
|
|
1657
|
-
word.definitions.create!(description:
|
|
1520
|
+
word.definitions.create!(description: '2')
|
|
1658
1521
|
end
|
|
1659
1522
|
|
|
1660
|
-
context
|
|
1661
|
-
|
|
1523
|
+
context 'when setting the read preference to non-primary' do
|
|
1662
1524
|
before do
|
|
1663
1525
|
Definition.validates_uniqueness_of :description
|
|
1664
1526
|
end
|
|
@@ -1669,20 +1531,19 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1669
1531
|
|
|
1670
1532
|
let(:word) { Word.create! }
|
|
1671
1533
|
|
|
1672
|
-
it
|
|
1534
|
+
it 'reads from the primary' do
|
|
1673
1535
|
expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs|
|
|
1674
1536
|
crit = m.call(*args, **kwargs)
|
|
1675
1537
|
expect(crit.options[:read]).to eq({ mode: :primary })
|
|
1676
1538
|
crit
|
|
1677
1539
|
end
|
|
1678
|
-
Definition.with(read: { mode: :secondary }) do |
|
|
1540
|
+
Definition.with(read: { mode: :secondary }) do |_klass|
|
|
1679
1541
|
word.definitions.create!
|
|
1680
1542
|
end
|
|
1681
1543
|
end
|
|
1682
1544
|
end
|
|
1683
1545
|
|
|
1684
|
-
context
|
|
1685
|
-
|
|
1546
|
+
context 'when a document is being destroyed' do
|
|
1686
1547
|
before do
|
|
1687
1548
|
Definition.validates_uniqueness_of :description
|
|
1688
1549
|
end
|
|
@@ -1691,13 +1552,12 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1691
1552
|
Definition.reset_callbacks(:validate)
|
|
1692
1553
|
end
|
|
1693
1554
|
|
|
1694
|
-
context
|
|
1695
|
-
|
|
1555
|
+
context 'when changing a document to the destroyed property' do
|
|
1696
1556
|
let(:attributes) do
|
|
1697
1557
|
{
|
|
1698
1558
|
definitions_attributes: {
|
|
1699
|
-
|
|
1700
|
-
|
|
1559
|
+
'0' => { id: def_one.id, description: '0', '_destroy' => 1 },
|
|
1560
|
+
'1' => { id: def_two.id, description: '1' }
|
|
1701
1561
|
}
|
|
1702
1562
|
}
|
|
1703
1563
|
end
|
|
@@ -1706,16 +1566,14 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1706
1566
|
word.attributes = attributes
|
|
1707
1567
|
end
|
|
1708
1568
|
|
|
1709
|
-
it
|
|
1569
|
+
it 'returns true' do
|
|
1710
1570
|
expect(def_two).to be_valid
|
|
1711
1571
|
end
|
|
1712
1572
|
end
|
|
1713
1573
|
end
|
|
1714
1574
|
|
|
1715
|
-
context
|
|
1716
|
-
|
|
1717
|
-
context "when no scope is provided" do
|
|
1718
|
-
|
|
1575
|
+
context 'when the document does not use composite keys' do
|
|
1576
|
+
context 'when no scope is provided' do
|
|
1719
1577
|
before do
|
|
1720
1578
|
Definition.validates_uniqueness_of :description
|
|
1721
1579
|
end
|
|
@@ -1724,58 +1582,53 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1724
1582
|
Definition.reset_callbacks(:validate)
|
|
1725
1583
|
end
|
|
1726
1584
|
|
|
1727
|
-
context
|
|
1728
|
-
|
|
1585
|
+
context 'when the attribute is unique' do
|
|
1729
1586
|
before do
|
|
1730
|
-
word.definitions.build(description:
|
|
1587
|
+
word.definitions.build(description: 'Malicious joy')
|
|
1731
1588
|
end
|
|
1732
1589
|
|
|
1733
1590
|
let(:definition) do
|
|
1734
|
-
word.definitions.build(description:
|
|
1591
|
+
word.definitions.build(description: 'Gloating')
|
|
1735
1592
|
end
|
|
1736
1593
|
|
|
1737
|
-
it
|
|
1594
|
+
it 'returns true' do
|
|
1738
1595
|
expect(definition).to be_valid
|
|
1739
1596
|
end
|
|
1740
1597
|
end
|
|
1741
1598
|
|
|
1742
|
-
context
|
|
1743
|
-
|
|
1744
|
-
context "when the document is not the match" do
|
|
1745
|
-
|
|
1599
|
+
context 'when the attribute is not unique' do
|
|
1600
|
+
context 'when the document is not the match' do
|
|
1746
1601
|
before do
|
|
1747
|
-
word.definitions.build(description:
|
|
1602
|
+
word.definitions.build(description: 'Malicious joy')
|
|
1748
1603
|
end
|
|
1749
1604
|
|
|
1750
1605
|
let(:definition) do
|
|
1751
|
-
word.definitions.build(description:
|
|
1606
|
+
word.definitions.build(description: 'Malicious joy')
|
|
1752
1607
|
end
|
|
1753
1608
|
|
|
1754
|
-
it
|
|
1755
|
-
expect(definition).
|
|
1609
|
+
it 'returns false' do
|
|
1610
|
+
expect(definition).not_to be_valid
|
|
1756
1611
|
end
|
|
1757
1612
|
|
|
1758
|
-
it
|
|
1613
|
+
it 'adds the uniqueness error' do
|
|
1759
1614
|
definition.valid?
|
|
1760
|
-
expect(definition.errors[:description]).to eq([
|
|
1615
|
+
expect(definition.errors[:description]).to eq([ 'has already been taken' ])
|
|
1761
1616
|
end
|
|
1762
1617
|
end
|
|
1763
1618
|
|
|
1764
|
-
context
|
|
1765
|
-
|
|
1619
|
+
context 'when the document is the match in the database' do
|
|
1766
1620
|
let!(:definition) do
|
|
1767
|
-
word.definitions.build(description:
|
|
1621
|
+
word.definitions.build(description: 'Malicious joy')
|
|
1768
1622
|
end
|
|
1769
1623
|
|
|
1770
|
-
it
|
|
1624
|
+
it 'returns true' do
|
|
1771
1625
|
expect(definition).to be_valid
|
|
1772
1626
|
end
|
|
1773
1627
|
end
|
|
1774
1628
|
end
|
|
1775
1629
|
end
|
|
1776
1630
|
|
|
1777
|
-
context
|
|
1778
|
-
|
|
1631
|
+
context 'when a single scope is provided' do
|
|
1779
1632
|
before do
|
|
1780
1633
|
Definition.validates_uniqueness_of :description, scope: :part
|
|
1781
1634
|
end
|
|
@@ -1784,268 +1637,252 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
1784
1637
|
Definition.reset_callbacks(:validate)
|
|
1785
1638
|
end
|
|
1786
1639
|
|
|
1787
|
-
context
|
|
1788
|
-
|
|
1640
|
+
context 'when the attribute is unique' do
|
|
1789
1641
|
before do
|
|
1790
1642
|
word.definitions.build(
|
|
1791
|
-
description:
|
|
1643
|
+
description: 'Malicious joy', part: 'Noun'
|
|
1792
1644
|
)
|
|
1793
1645
|
end
|
|
1794
1646
|
|
|
1795
1647
|
let(:definition) do
|
|
1796
|
-
word.definitions.build(description:
|
|
1648
|
+
word.definitions.build(description: 'Gloating')
|
|
1797
1649
|
end
|
|
1798
1650
|
|
|
1799
|
-
it
|
|
1651
|
+
it 'returns true' do
|
|
1800
1652
|
expect(definition).to be_valid
|
|
1801
1653
|
end
|
|
1802
1654
|
end
|
|
1803
1655
|
|
|
1804
|
-
context
|
|
1805
|
-
|
|
1656
|
+
context 'when the attribute is unique in the scope' do
|
|
1806
1657
|
before do
|
|
1807
1658
|
word.definitions.build(
|
|
1808
|
-
description:
|
|
1809
|
-
part:
|
|
1659
|
+
description: 'Malicious joy',
|
|
1660
|
+
part: 'Noun'
|
|
1810
1661
|
)
|
|
1811
1662
|
end
|
|
1812
1663
|
|
|
1813
1664
|
let(:definition) do
|
|
1814
1665
|
word.definitions.build(
|
|
1815
|
-
description:
|
|
1816
|
-
part:
|
|
1666
|
+
description: 'Gloating',
|
|
1667
|
+
part: 'Noun'
|
|
1817
1668
|
)
|
|
1818
1669
|
end
|
|
1819
1670
|
|
|
1820
|
-
it
|
|
1671
|
+
it 'returns true' do
|
|
1821
1672
|
expect(definition).to be_valid
|
|
1822
1673
|
end
|
|
1823
1674
|
end
|
|
1824
1675
|
|
|
1825
|
-
context
|
|
1826
|
-
|
|
1676
|
+
context 'when the attribute is not unique with no scope' do
|
|
1827
1677
|
before do
|
|
1828
1678
|
word.definitions.build(
|
|
1829
|
-
description:
|
|
1830
|
-
part:
|
|
1679
|
+
description: 'Malicious joy',
|
|
1680
|
+
part: 'Noun'
|
|
1831
1681
|
)
|
|
1832
1682
|
end
|
|
1833
1683
|
|
|
1834
1684
|
let(:definition) do
|
|
1835
|
-
word.definitions.build(description:
|
|
1685
|
+
word.definitions.build(description: 'Malicious joy')
|
|
1836
1686
|
end
|
|
1837
1687
|
|
|
1838
|
-
it
|
|
1688
|
+
it 'returns true' do
|
|
1839
1689
|
expect(definition).to be_valid
|
|
1840
1690
|
end
|
|
1841
1691
|
end
|
|
1842
1692
|
|
|
1843
|
-
context
|
|
1844
|
-
|
|
1693
|
+
context 'when the attribute is not unique in another scope' do
|
|
1845
1694
|
before do
|
|
1846
1695
|
word.definitions.build(
|
|
1847
|
-
description:
|
|
1848
|
-
part:
|
|
1696
|
+
description: 'Malicious joy',
|
|
1697
|
+
part: 'Noun'
|
|
1849
1698
|
)
|
|
1850
1699
|
end
|
|
1851
1700
|
|
|
1852
1701
|
let(:definition) do
|
|
1853
1702
|
word.definitions.build(
|
|
1854
|
-
description:
|
|
1855
|
-
part:
|
|
1703
|
+
description: 'Malicious joy',
|
|
1704
|
+
part: 'Adj'
|
|
1856
1705
|
)
|
|
1857
1706
|
end
|
|
1858
1707
|
|
|
1859
|
-
it
|
|
1708
|
+
it 'returns true' do
|
|
1860
1709
|
expect(definition).to be_valid
|
|
1861
1710
|
end
|
|
1862
1711
|
end
|
|
1863
1712
|
|
|
1864
|
-
context
|
|
1865
|
-
|
|
1866
|
-
context "when the document is not the match" do
|
|
1867
|
-
|
|
1713
|
+
context 'when the attribute is not unique in the same scope' do
|
|
1714
|
+
context 'when the document is not the match' do
|
|
1868
1715
|
before do
|
|
1869
1716
|
word.definitions.build(
|
|
1870
|
-
description:
|
|
1871
|
-
part:
|
|
1717
|
+
description: 'Malicious joy',
|
|
1718
|
+
part: 'Noun'
|
|
1872
1719
|
)
|
|
1873
1720
|
end
|
|
1874
1721
|
|
|
1875
1722
|
let(:definition) do
|
|
1876
1723
|
word.definitions.build(
|
|
1877
|
-
description:
|
|
1878
|
-
part:
|
|
1724
|
+
description: 'Malicious joy',
|
|
1725
|
+
part: 'Noun'
|
|
1879
1726
|
)
|
|
1880
1727
|
end
|
|
1881
1728
|
|
|
1882
|
-
it
|
|
1883
|
-
expect(definition).
|
|
1729
|
+
it 'returns false' do
|
|
1730
|
+
expect(definition).not_to be_valid
|
|
1884
1731
|
end
|
|
1885
1732
|
|
|
1886
|
-
it
|
|
1733
|
+
it 'adds the uniqueness errors' do
|
|
1887
1734
|
definition.valid?
|
|
1888
|
-
expect(definition.errors[:description]).to eq([
|
|
1735
|
+
expect(definition.errors[:description]).to eq([ 'has already been taken' ])
|
|
1889
1736
|
end
|
|
1890
1737
|
end
|
|
1891
1738
|
|
|
1892
|
-
context
|
|
1893
|
-
|
|
1739
|
+
context 'when the document is the match in the database' do
|
|
1894
1740
|
let!(:definition) do
|
|
1895
1741
|
word.definitions.build(
|
|
1896
|
-
description:
|
|
1897
|
-
part:
|
|
1742
|
+
description: 'Malicious joy',
|
|
1743
|
+
part: 'Noun'
|
|
1898
1744
|
)
|
|
1899
1745
|
end
|
|
1900
1746
|
|
|
1901
|
-
it
|
|
1747
|
+
it 'returns true' do
|
|
1902
1748
|
expect(definition).to be_valid
|
|
1903
1749
|
end
|
|
1904
1750
|
end
|
|
1905
1751
|
end
|
|
1906
1752
|
end
|
|
1907
1753
|
|
|
1908
|
-
context
|
|
1909
|
-
|
|
1754
|
+
context 'when multiple scopes are provided' do
|
|
1910
1755
|
before do
|
|
1911
|
-
Definition.validates_uniqueness_of :description, scope: [
|
|
1756
|
+
Definition.validates_uniqueness_of :description, scope: %i[part regular]
|
|
1912
1757
|
end
|
|
1913
1758
|
|
|
1914
1759
|
after do
|
|
1915
1760
|
Definition.reset_callbacks(:validate)
|
|
1916
1761
|
end
|
|
1917
1762
|
|
|
1918
|
-
context
|
|
1919
|
-
|
|
1763
|
+
context 'when the attribute is unique' do
|
|
1920
1764
|
before do
|
|
1921
1765
|
word.definitions.build(
|
|
1922
|
-
description:
|
|
1923
|
-
part:
|
|
1766
|
+
description: 'Malicious joy',
|
|
1767
|
+
part: 'Noun'
|
|
1924
1768
|
)
|
|
1925
1769
|
end
|
|
1926
1770
|
|
|
1927
1771
|
let(:definition) do
|
|
1928
|
-
word.definitions.build(description:
|
|
1772
|
+
word.definitions.build(description: 'Gloating')
|
|
1929
1773
|
end
|
|
1930
1774
|
|
|
1931
|
-
it
|
|
1775
|
+
it 'returns true' do
|
|
1932
1776
|
expect(definition).to be_valid
|
|
1933
1777
|
end
|
|
1934
1778
|
end
|
|
1935
1779
|
|
|
1936
|
-
context
|
|
1937
|
-
|
|
1780
|
+
context 'when the attribute is unique in the scope' do
|
|
1938
1781
|
before do
|
|
1939
1782
|
word.definitions.build(
|
|
1940
|
-
description:
|
|
1941
|
-
part:
|
|
1783
|
+
description: 'Malicious joy',
|
|
1784
|
+
part: 'Noun',
|
|
1942
1785
|
regular: true
|
|
1943
1786
|
)
|
|
1944
1787
|
end
|
|
1945
1788
|
|
|
1946
1789
|
let(:definition) do
|
|
1947
1790
|
word.definitions.build(
|
|
1948
|
-
description:
|
|
1949
|
-
part:
|
|
1791
|
+
description: 'Gloating',
|
|
1792
|
+
part: 'Noun',
|
|
1950
1793
|
regular: true
|
|
1951
1794
|
)
|
|
1952
1795
|
end
|
|
1953
1796
|
|
|
1954
|
-
it
|
|
1797
|
+
it 'returns true' do
|
|
1955
1798
|
expect(definition).to be_valid
|
|
1956
1799
|
end
|
|
1957
1800
|
end
|
|
1958
1801
|
|
|
1959
|
-
context
|
|
1960
|
-
|
|
1802
|
+
context 'when the attribute is not unique with no scope' do
|
|
1961
1803
|
before do
|
|
1962
1804
|
word.definitions.build(
|
|
1963
|
-
description:
|
|
1964
|
-
part:
|
|
1805
|
+
description: 'Malicious joy',
|
|
1806
|
+
part: 'Noun'
|
|
1965
1807
|
)
|
|
1966
1808
|
end
|
|
1967
1809
|
|
|
1968
1810
|
let(:definition) do
|
|
1969
|
-
word.definitions.build(description:
|
|
1811
|
+
word.definitions.build(description: 'Malicious scope')
|
|
1970
1812
|
end
|
|
1971
1813
|
|
|
1972
|
-
it
|
|
1814
|
+
it 'returns true' do
|
|
1973
1815
|
expect(definition).to be_valid
|
|
1974
1816
|
end
|
|
1975
1817
|
end
|
|
1976
1818
|
|
|
1977
|
-
context
|
|
1978
|
-
|
|
1819
|
+
context 'when the attribute is not unique in another scope' do
|
|
1979
1820
|
before do
|
|
1980
1821
|
word.definitions.build(
|
|
1981
|
-
description:
|
|
1982
|
-
part:
|
|
1822
|
+
description: 'Malicious joy',
|
|
1823
|
+
part: 'Noun',
|
|
1983
1824
|
regular: true
|
|
1984
1825
|
)
|
|
1985
1826
|
end
|
|
1986
1827
|
|
|
1987
1828
|
let(:definition) do
|
|
1988
1829
|
word.definitions.build(
|
|
1989
|
-
description:
|
|
1990
|
-
part:
|
|
1830
|
+
description: 'Malicious joy',
|
|
1831
|
+
part: 'Adj',
|
|
1991
1832
|
regular: true
|
|
1992
1833
|
)
|
|
1993
1834
|
end
|
|
1994
1835
|
|
|
1995
|
-
it
|
|
1836
|
+
it 'returns true' do
|
|
1996
1837
|
expect(definition).to be_valid
|
|
1997
1838
|
end
|
|
1998
1839
|
end
|
|
1999
1840
|
|
|
2000
|
-
context
|
|
2001
|
-
|
|
2002
|
-
context "when the document is not the match" do
|
|
2003
|
-
|
|
1841
|
+
context 'when the attribute is not unique in the same scope' do
|
|
1842
|
+
context 'when the document is not the match' do
|
|
2004
1843
|
before do
|
|
2005
1844
|
word.definitions.build(
|
|
2006
|
-
description:
|
|
2007
|
-
part:
|
|
1845
|
+
description: 'Malicious joy',
|
|
1846
|
+
part: 'Noun',
|
|
2008
1847
|
regular: true
|
|
2009
1848
|
)
|
|
2010
1849
|
end
|
|
2011
1850
|
|
|
2012
1851
|
let(:definition) do
|
|
2013
1852
|
word.definitions.build(
|
|
2014
|
-
description:
|
|
2015
|
-
part:
|
|
1853
|
+
description: 'Malicious joy',
|
|
1854
|
+
part: 'Noun',
|
|
2016
1855
|
regular: true
|
|
2017
1856
|
)
|
|
2018
1857
|
end
|
|
2019
1858
|
|
|
2020
|
-
it
|
|
2021
|
-
expect(definition).
|
|
1859
|
+
it 'returns false' do
|
|
1860
|
+
expect(definition).not_to be_valid
|
|
2022
1861
|
end
|
|
2023
1862
|
|
|
2024
|
-
it
|
|
1863
|
+
it 'adds the uniqueness errors' do
|
|
2025
1864
|
definition.valid?
|
|
2026
|
-
expect(definition.errors[:description]).to eq([
|
|
1865
|
+
expect(definition.errors[:description]).to eq([ 'has already been taken' ])
|
|
2027
1866
|
end
|
|
2028
1867
|
end
|
|
2029
1868
|
|
|
2030
|
-
context
|
|
2031
|
-
|
|
1869
|
+
context 'when the document is the match in the database' do
|
|
2032
1870
|
let!(:definition) do
|
|
2033
1871
|
word.definitions.build(
|
|
2034
|
-
description:
|
|
2035
|
-
part:
|
|
1872
|
+
description: 'Malicious joy',
|
|
1873
|
+
part: 'Noun',
|
|
2036
1874
|
regular: false
|
|
2037
1875
|
)
|
|
2038
1876
|
end
|
|
2039
1877
|
|
|
2040
|
-
it
|
|
1878
|
+
it 'returns true' do
|
|
2041
1879
|
expect(definition).to be_valid
|
|
2042
1880
|
end
|
|
2043
1881
|
end
|
|
2044
1882
|
end
|
|
2045
1883
|
end
|
|
2046
1884
|
|
|
2047
|
-
context
|
|
2048
|
-
|
|
1885
|
+
context 'when case sensitive is true' do
|
|
2049
1886
|
before do
|
|
2050
1887
|
Definition.validates_uniqueness_of :description
|
|
2051
1888
|
end
|
|
@@ -2054,58 +1891,53 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2054
1891
|
Definition.reset_callbacks(:validate)
|
|
2055
1892
|
end
|
|
2056
1893
|
|
|
2057
|
-
context
|
|
2058
|
-
|
|
1894
|
+
context 'when the attribute is unique' do
|
|
2059
1895
|
before do
|
|
2060
|
-
word.definitions.build(description:
|
|
1896
|
+
word.definitions.build(description: 'Malicious jo')
|
|
2061
1897
|
end
|
|
2062
1898
|
|
|
2063
1899
|
let(:definition) do
|
|
2064
|
-
word.definitions.build(description:
|
|
1900
|
+
word.definitions.build(description: 'Gloating')
|
|
2065
1901
|
end
|
|
2066
1902
|
|
|
2067
|
-
it
|
|
1903
|
+
it 'returns true' do
|
|
2068
1904
|
expect(definition).to be_valid
|
|
2069
1905
|
end
|
|
2070
1906
|
end
|
|
2071
1907
|
|
|
2072
|
-
context
|
|
2073
|
-
|
|
2074
|
-
context "when the document is not the match" do
|
|
2075
|
-
|
|
1908
|
+
context 'when the attribute is not unique' do
|
|
1909
|
+
context 'when the document is not the match' do
|
|
2076
1910
|
before do
|
|
2077
|
-
word.definitions.build(description:
|
|
1911
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2078
1912
|
end
|
|
2079
1913
|
|
|
2080
1914
|
let(:definition) do
|
|
2081
|
-
word.definitions.build(description:
|
|
1915
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2082
1916
|
end
|
|
2083
1917
|
|
|
2084
|
-
it
|
|
2085
|
-
expect(definition).
|
|
1918
|
+
it 'returns false' do
|
|
1919
|
+
expect(definition).not_to be_valid
|
|
2086
1920
|
end
|
|
2087
1921
|
|
|
2088
|
-
it
|
|
1922
|
+
it 'adds the uniqueness error' do
|
|
2089
1923
|
definition.valid?
|
|
2090
|
-
expect(definition.errors[:description]).to eq([
|
|
1924
|
+
expect(definition.errors[:description]).to eq([ 'has already been taken' ])
|
|
2091
1925
|
end
|
|
2092
1926
|
end
|
|
2093
1927
|
|
|
2094
|
-
context
|
|
2095
|
-
|
|
1928
|
+
context 'when the document is the match in the database' do
|
|
2096
1929
|
let!(:definition) do
|
|
2097
|
-
word.definitions.build(description:
|
|
1930
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2098
1931
|
end
|
|
2099
1932
|
|
|
2100
|
-
it
|
|
1933
|
+
it 'returns true' do
|
|
2101
1934
|
expect(definition).to be_valid
|
|
2102
1935
|
end
|
|
2103
1936
|
end
|
|
2104
1937
|
end
|
|
2105
1938
|
end
|
|
2106
1939
|
|
|
2107
|
-
context
|
|
2108
|
-
|
|
1940
|
+
context 'when case sensitive is false' do
|
|
2109
1941
|
before do
|
|
2110
1942
|
Definition.validates_uniqueness_of :description, case_sensitive: false
|
|
2111
1943
|
end
|
|
@@ -2114,76 +1946,69 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2114
1946
|
Definition.reset_callbacks(:validate)
|
|
2115
1947
|
end
|
|
2116
1948
|
|
|
2117
|
-
context
|
|
2118
|
-
|
|
2119
|
-
context "when there are no special characters" do
|
|
2120
|
-
|
|
1949
|
+
context 'when the attribute is unique' do
|
|
1950
|
+
context 'when there are no special characters' do
|
|
2121
1951
|
before do
|
|
2122
|
-
word.definitions.build(description:
|
|
1952
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2123
1953
|
end
|
|
2124
1954
|
|
|
2125
1955
|
let(:definition) do
|
|
2126
|
-
word.definitions.build(description:
|
|
1956
|
+
word.definitions.build(description: 'Gloating')
|
|
2127
1957
|
end
|
|
2128
1958
|
|
|
2129
|
-
it
|
|
1959
|
+
it 'returns true' do
|
|
2130
1960
|
expect(definition).to be_valid
|
|
2131
1961
|
end
|
|
2132
1962
|
end
|
|
2133
1963
|
|
|
2134
|
-
context
|
|
2135
|
-
|
|
1964
|
+
context 'when special characters exist' do
|
|
2136
1965
|
before do
|
|
2137
|
-
word.definitions.build(description:
|
|
1966
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2138
1967
|
end
|
|
2139
1968
|
|
|
2140
1969
|
let(:definition) do
|
|
2141
|
-
word.definitions.build(description:
|
|
1970
|
+
word.definitions.build(description: 'M@licious.joy')
|
|
2142
1971
|
end
|
|
2143
1972
|
|
|
2144
|
-
it
|
|
1973
|
+
it 'returns true' do
|
|
2145
1974
|
expect(definition).to be_valid
|
|
2146
1975
|
end
|
|
2147
1976
|
end
|
|
2148
1977
|
end
|
|
2149
1978
|
|
|
2150
|
-
context
|
|
2151
|
-
|
|
2152
|
-
context "when the document is not the match" do
|
|
2153
|
-
|
|
1979
|
+
context 'when the attribute is not unique' do
|
|
1980
|
+
context 'when the document is not the match' do
|
|
2154
1981
|
before do
|
|
2155
|
-
word.definitions.build(description:
|
|
1982
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2156
1983
|
end
|
|
2157
1984
|
|
|
2158
1985
|
let(:definition) do
|
|
2159
|
-
word.definitions.build(description:
|
|
1986
|
+
word.definitions.build(description: 'Malicious JOY')
|
|
2160
1987
|
end
|
|
2161
1988
|
|
|
2162
|
-
it
|
|
2163
|
-
expect(definition).
|
|
1989
|
+
it 'returns false' do
|
|
1990
|
+
expect(definition).not_to be_valid
|
|
2164
1991
|
end
|
|
2165
1992
|
|
|
2166
|
-
it
|
|
1993
|
+
it 'adds the uniqueness error' do
|
|
2167
1994
|
definition.valid?
|
|
2168
|
-
expect(definition.errors[:description]).to eq([
|
|
1995
|
+
expect(definition.errors[:description]).to eq([ 'has already been taken' ])
|
|
2169
1996
|
end
|
|
2170
1997
|
end
|
|
2171
1998
|
|
|
2172
|
-
context
|
|
2173
|
-
|
|
1999
|
+
context 'when the document is the match in the database' do
|
|
2174
2000
|
let!(:definition) do
|
|
2175
|
-
word.definitions.build(description:
|
|
2001
|
+
word.definitions.build(description: 'Malicious joy')
|
|
2176
2002
|
end
|
|
2177
2003
|
|
|
2178
|
-
it
|
|
2004
|
+
it 'returns true' do
|
|
2179
2005
|
expect(definition).to be_valid
|
|
2180
2006
|
end
|
|
2181
2007
|
end
|
|
2182
2008
|
end
|
|
2183
2009
|
end
|
|
2184
2010
|
|
|
2185
|
-
context
|
|
2186
|
-
|
|
2011
|
+
context 'when allowing nil' do
|
|
2187
2012
|
before do
|
|
2188
2013
|
Definition.validates_uniqueness_of :description, allow_nil: true
|
|
2189
2014
|
end
|
|
@@ -2192,8 +2017,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2192
2017
|
Definition.reset_callbacks(:validate)
|
|
2193
2018
|
end
|
|
2194
2019
|
|
|
2195
|
-
context
|
|
2196
|
-
|
|
2020
|
+
context 'when the attribute is nil' do
|
|
2197
2021
|
before do
|
|
2198
2022
|
word.definitions.build
|
|
2199
2023
|
end
|
|
@@ -2202,14 +2026,13 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2202
2026
|
word.definitions.build
|
|
2203
2027
|
end
|
|
2204
2028
|
|
|
2205
|
-
it
|
|
2029
|
+
it 'returns true' do
|
|
2206
2030
|
expect(definition).to be_valid
|
|
2207
2031
|
end
|
|
2208
2032
|
end
|
|
2209
2033
|
end
|
|
2210
2034
|
|
|
2211
|
-
context
|
|
2212
|
-
|
|
2035
|
+
context 'when allowing blank' do
|
|
2213
2036
|
before do
|
|
2214
2037
|
Definition.validates_uniqueness_of :description, allow_blank: true
|
|
2215
2038
|
end
|
|
@@ -2218,113 +2041,104 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2218
2041
|
Definition.reset_callbacks(:validate)
|
|
2219
2042
|
end
|
|
2220
2043
|
|
|
2221
|
-
context
|
|
2222
|
-
|
|
2044
|
+
context 'when the attribute is blank' do
|
|
2223
2045
|
before do
|
|
2224
|
-
word.definitions.build(description:
|
|
2046
|
+
word.definitions.build(description: '')
|
|
2225
2047
|
end
|
|
2226
2048
|
|
|
2227
2049
|
let(:definition) do
|
|
2228
|
-
word.definitions.build(description:
|
|
2050
|
+
word.definitions.build(description: '')
|
|
2229
2051
|
end
|
|
2230
2052
|
|
|
2231
|
-
it
|
|
2053
|
+
it 'returns true' do
|
|
2232
2054
|
expect(definition).to be_valid
|
|
2233
2055
|
end
|
|
2234
2056
|
end
|
|
2235
2057
|
end
|
|
2236
2058
|
|
|
2237
|
-
context
|
|
2238
|
-
|
|
2059
|
+
context 'when the field name is aliased' do
|
|
2239
2060
|
before do
|
|
2240
|
-
word.definitions.build(part:
|
|
2061
|
+
word.definitions.build(part: 'noun', synonyms: 'foo')
|
|
2241
2062
|
end
|
|
2242
2063
|
|
|
2243
2064
|
let(:definition) do
|
|
2244
|
-
word.definitions.build(part:
|
|
2065
|
+
word.definitions.build(part: 'noun', synonyms: 'foo')
|
|
2245
2066
|
end
|
|
2246
2067
|
|
|
2247
2068
|
after do
|
|
2248
2069
|
Definition.reset_callbacks(:validate)
|
|
2249
2070
|
end
|
|
2250
2071
|
|
|
2251
|
-
context
|
|
2252
|
-
|
|
2072
|
+
context 'when the validation uses the aliased name' do
|
|
2253
2073
|
before do
|
|
2254
2074
|
Definition.validates_uniqueness_of :part, case_sensitive: false
|
|
2255
2075
|
end
|
|
2256
2076
|
|
|
2257
|
-
it
|
|
2258
|
-
expect(definition).
|
|
2077
|
+
it 'correctly detects a uniqueness conflict' do
|
|
2078
|
+
expect(definition).not_to be_valid
|
|
2259
2079
|
end
|
|
2260
2080
|
|
|
2261
|
-
it
|
|
2081
|
+
it 'adds the uniqueness error to the aliased field name' do
|
|
2262
2082
|
definition.valid?
|
|
2263
2083
|
expect(definition.errors).to have_key(:part)
|
|
2264
|
-
expect(definition.errors[:part]).to eq([
|
|
2084
|
+
expect(definition.errors[:part]).to eq([ 'has already been taken' ])
|
|
2265
2085
|
end
|
|
2266
2086
|
end
|
|
2267
2087
|
|
|
2268
|
-
context
|
|
2269
|
-
|
|
2088
|
+
context 'when the validation uses the underlying field name' do
|
|
2270
2089
|
before do
|
|
2271
2090
|
Definition.validates_uniqueness_of :p, case_sensitive: false
|
|
2272
2091
|
end
|
|
2273
2092
|
|
|
2274
|
-
it
|
|
2275
|
-
expect(definition).
|
|
2093
|
+
it 'correctly detects a uniqueness conflict' do
|
|
2094
|
+
expect(definition).not_to be_valid
|
|
2276
2095
|
end
|
|
2277
2096
|
|
|
2278
|
-
it
|
|
2097
|
+
it 'adds the uniqueness error to the underlying field name' do
|
|
2279
2098
|
definition.valid?
|
|
2280
2099
|
expect(definition.errors).to have_key(:p)
|
|
2281
|
-
expect(definition.errors[:p]).to eq([
|
|
2100
|
+
expect(definition.errors[:p]).to eq([ 'has already been taken' ])
|
|
2282
2101
|
end
|
|
2283
2102
|
end
|
|
2284
2103
|
|
|
2285
|
-
context
|
|
2286
|
-
|
|
2287
|
-
context "when the validation uses the aliased name" do
|
|
2288
|
-
|
|
2104
|
+
context 'when the field is localized' do
|
|
2105
|
+
context 'when the validation uses the aliased name' do
|
|
2289
2106
|
before do
|
|
2290
2107
|
Definition.validates_uniqueness_of :synonyms, case_sensitive: false
|
|
2291
2108
|
end
|
|
2292
2109
|
|
|
2293
|
-
it
|
|
2294
|
-
expect(definition).
|
|
2110
|
+
it 'correctly detects a uniqueness conflict' do
|
|
2111
|
+
expect(definition).not_to be_valid
|
|
2295
2112
|
end
|
|
2296
2113
|
|
|
2297
|
-
it
|
|
2114
|
+
it 'adds the uniqueness error to the aliased field name' do
|
|
2298
2115
|
definition.valid?
|
|
2299
2116
|
expect(definition.errors).to have_key(:synonyms)
|
|
2300
|
-
expect(definition.errors[:synonyms]).to eq([
|
|
2117
|
+
expect(definition.errors[:synonyms]).to eq([ 'has already been taken' ])
|
|
2301
2118
|
end
|
|
2302
2119
|
end
|
|
2303
2120
|
|
|
2304
|
-
context
|
|
2305
|
-
|
|
2121
|
+
context 'when the validation uses the underlying field name' do
|
|
2306
2122
|
before do
|
|
2307
2123
|
Definition.validates_uniqueness_of :syn, case_sensitive: false
|
|
2308
2124
|
end
|
|
2309
2125
|
|
|
2310
|
-
it
|
|
2311
|
-
expect(definition).
|
|
2126
|
+
it 'correctly detects a uniqueness conflict' do
|
|
2127
|
+
expect(definition).not_to be_valid
|
|
2312
2128
|
end
|
|
2313
2129
|
|
|
2314
|
-
it
|
|
2130
|
+
it 'adds the uniqueness error to the aliased field name' do
|
|
2315
2131
|
definition.valid?
|
|
2316
2132
|
expect(definition.errors).to have_key(:syn)
|
|
2317
|
-
expect(definition.errors[:syn]).to eq([
|
|
2133
|
+
expect(definition.errors[:syn]).to eq([ 'has already been taken' ])
|
|
2318
2134
|
end
|
|
2319
2135
|
end
|
|
2320
2136
|
end
|
|
2321
2137
|
end
|
|
2322
2138
|
end
|
|
2323
2139
|
|
|
2324
|
-
context
|
|
2325
|
-
|
|
2326
|
-
context "when no scope is provided" do
|
|
2327
|
-
|
|
2140
|
+
context 'when the document uses composite keys' do
|
|
2141
|
+
context 'when no scope is provided' do
|
|
2328
2142
|
before do
|
|
2329
2143
|
WordOrigin.validates_uniqueness_of :origin_id
|
|
2330
2144
|
end
|
|
@@ -2333,8 +2147,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2333
2147
|
WordOrigin.reset_callbacks(:validate)
|
|
2334
2148
|
end
|
|
2335
2149
|
|
|
2336
|
-
context
|
|
2337
|
-
|
|
2150
|
+
context 'when the attribute is unique' do
|
|
2338
2151
|
before do
|
|
2339
2152
|
word.word_origins.build(origin_id: 1)
|
|
2340
2153
|
end
|
|
@@ -2343,15 +2156,13 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2343
2156
|
word.word_origins.build(origin_id: 2)
|
|
2344
2157
|
end
|
|
2345
2158
|
|
|
2346
|
-
it
|
|
2159
|
+
it 'returns true' do
|
|
2347
2160
|
expect(word_origin).to be_valid
|
|
2348
2161
|
end
|
|
2349
2162
|
end
|
|
2350
2163
|
|
|
2351
|
-
context
|
|
2352
|
-
|
|
2353
|
-
context "when the document is not the match" do
|
|
2354
|
-
|
|
2164
|
+
context 'when the attribute is not unique' do
|
|
2165
|
+
context 'when the document is not the match' do
|
|
2355
2166
|
before do
|
|
2356
2167
|
word.word_origins.build(origin_id: 1)
|
|
2357
2168
|
end
|
|
@@ -2360,31 +2171,29 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2360
2171
|
word.word_origins.build(origin_id: 1)
|
|
2361
2172
|
end
|
|
2362
2173
|
|
|
2363
|
-
it
|
|
2364
|
-
expect(word_origin).
|
|
2174
|
+
it 'returns false' do
|
|
2175
|
+
expect(word_origin).not_to be_valid
|
|
2365
2176
|
end
|
|
2366
2177
|
|
|
2367
|
-
it
|
|
2178
|
+
it 'adds the uniqueness error' do
|
|
2368
2179
|
word_origin.valid?
|
|
2369
|
-
expect(word_origin.errors[:origin_id]).to eq([
|
|
2180
|
+
expect(word_origin.errors[:origin_id]).to eq([ 'has already been taken' ])
|
|
2370
2181
|
end
|
|
2371
2182
|
end
|
|
2372
2183
|
|
|
2373
|
-
context
|
|
2374
|
-
|
|
2184
|
+
context 'when the document is the match in the database' do
|
|
2375
2185
|
let!(:word_origin) do
|
|
2376
2186
|
word.word_origins.build(origin_id: 1)
|
|
2377
2187
|
end
|
|
2378
2188
|
|
|
2379
|
-
it
|
|
2189
|
+
it 'returns true' do
|
|
2380
2190
|
expect(word_origin).to be_valid
|
|
2381
2191
|
end
|
|
2382
2192
|
end
|
|
2383
2193
|
end
|
|
2384
2194
|
end
|
|
2385
2195
|
|
|
2386
|
-
context
|
|
2387
|
-
|
|
2196
|
+
context 'when allowing nil' do
|
|
2388
2197
|
before do
|
|
2389
2198
|
WordOrigin.validates_uniqueness_of :origin_id, allow_nil: true
|
|
2390
2199
|
end
|
|
@@ -2393,8 +2202,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2393
2202
|
WordOrigin.reset_callbacks(:validate)
|
|
2394
2203
|
end
|
|
2395
2204
|
|
|
2396
|
-
context
|
|
2397
|
-
|
|
2205
|
+
context 'when the attribute is nil' do
|
|
2398
2206
|
before do
|
|
2399
2207
|
word.word_origins.build
|
|
2400
2208
|
end
|
|
@@ -2403,14 +2211,13 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2403
2211
|
word.word_origins.build
|
|
2404
2212
|
end
|
|
2405
2213
|
|
|
2406
|
-
it
|
|
2214
|
+
it 'returns true' do
|
|
2407
2215
|
expect(word_origin).to be_valid
|
|
2408
2216
|
end
|
|
2409
2217
|
end
|
|
2410
2218
|
end
|
|
2411
2219
|
|
|
2412
|
-
context
|
|
2413
|
-
|
|
2220
|
+
context 'when allowing blank' do
|
|
2414
2221
|
before do
|
|
2415
2222
|
WordOrigin.validates_uniqueness_of :origin_id, allow_blank: true
|
|
2416
2223
|
end
|
|
@@ -2419,17 +2226,16 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2419
2226
|
WordOrigin.reset_callbacks(:validate)
|
|
2420
2227
|
end
|
|
2421
2228
|
|
|
2422
|
-
context
|
|
2423
|
-
|
|
2229
|
+
context 'when the attribute is blank' do
|
|
2424
2230
|
before do
|
|
2425
|
-
word.word_origins.build(origin_id:
|
|
2231
|
+
word.word_origins.build(origin_id: '')
|
|
2426
2232
|
end
|
|
2427
2233
|
|
|
2428
2234
|
let(:word_origin) do
|
|
2429
|
-
word.word_origins.build(origin_id:
|
|
2235
|
+
word.word_origins.build(origin_id: '')
|
|
2430
2236
|
end
|
|
2431
2237
|
|
|
2432
|
-
it
|
|
2238
|
+
it 'returns true' do
|
|
2433
2239
|
expect(word_origin).to be_valid
|
|
2434
2240
|
end
|
|
2435
2241
|
end
|
|
@@ -2437,8 +2243,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2437
2243
|
end
|
|
2438
2244
|
end
|
|
2439
2245
|
|
|
2440
|
-
context
|
|
2441
|
-
|
|
2246
|
+
context 'when in an embeds_one' do
|
|
2442
2247
|
before do
|
|
2443
2248
|
Pronunciation.validates_uniqueness_of :sound
|
|
2444
2249
|
end
|
|
@@ -2448,31 +2253,30 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2448
2253
|
end
|
|
2449
2254
|
|
|
2450
2255
|
let(:pronunciation) do
|
|
2451
|
-
word.build_pronunciation(sound:
|
|
2256
|
+
word.build_pronunciation(sound: 'Schwa')
|
|
2452
2257
|
end
|
|
2453
2258
|
|
|
2454
|
-
it
|
|
2259
|
+
it 'always returns true' do
|
|
2455
2260
|
expect(pronunciation).to be_valid
|
|
2456
2261
|
end
|
|
2457
2262
|
end
|
|
2458
2263
|
end
|
|
2459
2264
|
|
|
2460
|
-
context
|
|
2461
|
-
|
|
2265
|
+
context 'when describing validation on the instance level' do
|
|
2462
2266
|
let!(:dictionary) do
|
|
2463
|
-
Dictionary.create!(name:
|
|
2267
|
+
Dictionary.create!(name: 'en')
|
|
2464
2268
|
end
|
|
2465
2269
|
|
|
2466
2270
|
let(:validators) do
|
|
2467
2271
|
dictionary.validates_uniqueness_of :name
|
|
2468
2272
|
end
|
|
2469
2273
|
|
|
2470
|
-
it
|
|
2274
|
+
it 'adds the validation only to the instance' do
|
|
2471
2275
|
expect(validators).to eq([ described_class ])
|
|
2472
2276
|
end
|
|
2473
2277
|
end
|
|
2474
2278
|
|
|
2475
|
-
context
|
|
2279
|
+
context 'when validation works with inheritance' do
|
|
2476
2280
|
class EuropeanActor < Actor
|
|
2477
2281
|
validates_uniqueness_of :name
|
|
2478
2282
|
end
|
|
@@ -2481,23 +2285,22 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2481
2285
|
end
|
|
2482
2286
|
|
|
2483
2287
|
before do
|
|
2484
|
-
EuropeanActor.create!(name:
|
|
2288
|
+
EuropeanActor.create!(name: 'Antonio Banderas')
|
|
2485
2289
|
end
|
|
2486
2290
|
|
|
2487
2291
|
let!(:subclass_document_with_duplicated_name) do
|
|
2488
|
-
SpanishActor.new(name:
|
|
2292
|
+
SpanishActor.new(name: 'Antonio Banderas')
|
|
2489
2293
|
end
|
|
2490
2294
|
|
|
2491
|
-
it
|
|
2295
|
+
it 'is invalid' do
|
|
2492
2296
|
subclass_document_with_duplicated_name.tap do |d|
|
|
2493
2297
|
expect(d).to be_invalid
|
|
2494
|
-
expect(d.errors[:name]).to eq([
|
|
2298
|
+
expect(d.errors[:name]).to eq([ 'has already been taken' ])
|
|
2495
2299
|
end
|
|
2496
2300
|
end
|
|
2497
2301
|
end
|
|
2498
2302
|
|
|
2499
|
-
context
|
|
2500
|
-
|
|
2303
|
+
context 'when persisting with safe options' do
|
|
2501
2304
|
before do
|
|
2502
2305
|
Person.validates_uniqueness_of(:username)
|
|
2503
2306
|
Person.index({ ssn: 1 }, { unique: true })
|
|
@@ -2505,7 +2308,7 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2505
2308
|
end
|
|
2506
2309
|
|
|
2507
2310
|
let!(:person) do
|
|
2508
|
-
Person.create!(ssn:
|
|
2311
|
+
Person.create!(ssn: '132-11-1111', username: 'aaasdaffff')
|
|
2509
2312
|
end
|
|
2510
2313
|
|
|
2511
2314
|
after do
|
|
@@ -2513,15 +2316,14 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2513
2316
|
Person.collection.drop
|
|
2514
2317
|
end
|
|
2515
2318
|
|
|
2516
|
-
it
|
|
2517
|
-
expect
|
|
2518
|
-
Person.create!(ssn:
|
|
2519
|
-
|
|
2319
|
+
it 'transfers the options to the cloned client' do
|
|
2320
|
+
expect do
|
|
2321
|
+
Person.create!(ssn: '132-11-1111', username: 'asdfsdfA')
|
|
2322
|
+
end.to raise_error(Mongo::Error::OperationFailure)
|
|
2520
2323
|
end
|
|
2521
2324
|
end
|
|
2522
2325
|
|
|
2523
|
-
describe
|
|
2524
|
-
|
|
2326
|
+
describe 'i18n' do
|
|
2525
2327
|
context 'when using a different locale' do
|
|
2526
2328
|
with_default_i18n_configs
|
|
2527
2329
|
|
|
@@ -2536,11 +2338,11 @@ describe Mongoid::Validatable::UniquenessValidator do
|
|
|
2536
2338
|
I18n.backend.translations.delete(:fr)
|
|
2537
2339
|
end
|
|
2538
2340
|
|
|
2539
|
-
it
|
|
2341
|
+
it 'correctly translates the error message' do
|
|
2540
2342
|
Circus.create!(slogan: 'The Greatest Show on Mars')
|
|
2541
2343
|
dict = Circus.new(slogan: 'The Greatest Show on Mars')
|
|
2542
2344
|
dict.valid?
|
|
2543
|
-
expect(dict.errors.messages[:slogan]).to eq([
|
|
2345
|
+
expect(dict.errors.messages[:slogan]).to eq([ 'est déjà utilisé(e)' ])
|
|
2544
2346
|
end
|
|
2545
2347
|
end
|
|
2546
2348
|
end
|