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