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