mongoid 9.0.11 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -0
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +34 -38
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +18 -13
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -66
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -14
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +1 -3
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +132 -42
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +72 -65
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -2
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -72
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +26 -25
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +0 -2
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +11 -14
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -15
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -41
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +330 -0
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +28 -30
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -32
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -178
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +104 -119
- data/spec/integration/encryption_spec.rb +8 -11
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -31
- data/spec/mongoid/config/encryption_spec.rb +54 -57
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -854
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -950
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -80
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -8
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -2
|
@@ -1,47 +1,41 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Criteria::Findable do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context "when finding by a document" do
|
|
11
|
-
|
|
6
|
+
describe '#find' do
|
|
7
|
+
context 'when finding by a document' do
|
|
12
8
|
let(:band) do
|
|
13
|
-
Band.create!(name:
|
|
9
|
+
Band.create!(name: 'Tool')
|
|
14
10
|
end
|
|
15
11
|
|
|
16
12
|
let!(:record) do
|
|
17
|
-
band.records.create!(name:
|
|
13
|
+
band.records.create!(name: 'Undertow')
|
|
18
14
|
end
|
|
19
15
|
|
|
20
|
-
context
|
|
21
|
-
|
|
16
|
+
context 'when the document is the root' do
|
|
22
17
|
let(:found) do
|
|
23
18
|
Band.find(band)
|
|
24
19
|
end
|
|
25
20
|
|
|
26
|
-
it
|
|
21
|
+
it 'returns the matching document' do
|
|
27
22
|
expect(found).to eq(band)
|
|
28
23
|
end
|
|
29
24
|
end
|
|
30
25
|
|
|
31
|
-
context
|
|
32
|
-
|
|
26
|
+
context 'when the document is the proxy' do
|
|
33
27
|
let(:found) do
|
|
34
28
|
Band.find(band.records.first.band)
|
|
35
29
|
end
|
|
36
30
|
|
|
37
|
-
it
|
|
31
|
+
it 'returns the matching document' do
|
|
38
32
|
expect(found).to eq(band)
|
|
39
33
|
end
|
|
40
34
|
end
|
|
41
35
|
|
|
42
36
|
context 'when criteria has additional conditions' do
|
|
43
37
|
let(:band) do
|
|
44
|
-
Band.create!(name:
|
|
38
|
+
Band.create!(name: 'Tool')
|
|
45
39
|
end
|
|
46
40
|
|
|
47
41
|
let(:found) do
|
|
@@ -57,11 +51,11 @@ describe Mongoid::Criteria::Findable do
|
|
|
57
51
|
|
|
58
52
|
context 'when criteria has additional conditions on id' do
|
|
59
53
|
let(:band) do
|
|
60
|
-
Band.create!(name:
|
|
54
|
+
Band.create!(name: 'Tool')
|
|
61
55
|
end
|
|
62
56
|
|
|
63
57
|
let(:other) do
|
|
64
|
-
Band.create!(name:
|
|
58
|
+
Band.create!(name: 'Other')
|
|
65
59
|
end
|
|
66
60
|
|
|
67
61
|
let(:found) do
|
|
@@ -76,541 +70,516 @@ describe Mongoid::Criteria::Findable do
|
|
|
76
70
|
end
|
|
77
71
|
end
|
|
78
72
|
|
|
79
|
-
context
|
|
80
|
-
|
|
73
|
+
context 'when using object ids' do
|
|
81
74
|
let!(:band) do
|
|
82
75
|
Band.create!
|
|
83
76
|
end
|
|
84
77
|
|
|
85
|
-
context
|
|
86
|
-
|
|
87
|
-
context "when the id matches" do
|
|
88
|
-
|
|
78
|
+
context 'when providing a single id' do
|
|
79
|
+
context 'when the id matches' do
|
|
89
80
|
let(:found) do
|
|
90
81
|
Band.find(band.id)
|
|
91
82
|
end
|
|
92
83
|
|
|
93
|
-
it
|
|
84
|
+
it 'returns the matching document' do
|
|
94
85
|
expect(found).to eq(band)
|
|
95
86
|
end
|
|
96
87
|
|
|
97
|
-
context
|
|
98
|
-
|
|
88
|
+
context 'when finding by a JSON-dumped id' do
|
|
99
89
|
let(:found) do
|
|
100
90
|
Band.find(JSON.load(JSON.dump(band.id)))
|
|
101
91
|
end
|
|
102
92
|
|
|
103
|
-
it
|
|
93
|
+
it 'properly parses the id format' do
|
|
104
94
|
expect(found).to eq(band)
|
|
105
95
|
end
|
|
106
96
|
end
|
|
107
97
|
end
|
|
108
98
|
|
|
109
|
-
context
|
|
110
|
-
|
|
111
|
-
context "when raising a not found error" do
|
|
99
|
+
context 'when the id does not match' do
|
|
100
|
+
context 'when raising a not found error' do
|
|
112
101
|
config_override :raise_not_found_error, true
|
|
113
102
|
|
|
114
103
|
let(:found) do
|
|
115
104
|
Band.find(BSON::ObjectId.new)
|
|
116
105
|
end
|
|
117
106
|
|
|
118
|
-
it
|
|
119
|
-
expect
|
|
107
|
+
it 'raises an error' do
|
|
108
|
+
expect do
|
|
120
109
|
found
|
|
121
|
-
|
|
110
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
111
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
122
112
|
end
|
|
123
113
|
end
|
|
124
114
|
|
|
125
|
-
context
|
|
115
|
+
context 'when raising no error' do
|
|
126
116
|
config_override :raise_not_found_error, false
|
|
127
117
|
|
|
128
118
|
let(:found) do
|
|
129
119
|
Band.find(BSON::ObjectId.new)
|
|
130
120
|
end
|
|
131
121
|
|
|
132
|
-
it
|
|
122
|
+
it 'returns nil' do
|
|
133
123
|
expect(found).to be_nil
|
|
134
124
|
end
|
|
135
125
|
end
|
|
136
126
|
end
|
|
137
127
|
end
|
|
138
128
|
|
|
139
|
-
context
|
|
140
|
-
|
|
129
|
+
context 'when providing a splat of ids' do
|
|
141
130
|
let!(:band_two) do
|
|
142
|
-
Band.create!(name:
|
|
131
|
+
Band.create!(name: 'Tool')
|
|
143
132
|
end
|
|
144
133
|
|
|
145
|
-
context
|
|
146
|
-
|
|
134
|
+
context 'when all ids match' do
|
|
147
135
|
let(:found) do
|
|
148
136
|
Band.find(band.id, band_two.id)
|
|
149
137
|
end
|
|
150
138
|
|
|
151
|
-
it
|
|
139
|
+
it 'contains the first match' do
|
|
152
140
|
expect(found).to include(band)
|
|
153
141
|
end
|
|
154
142
|
|
|
155
|
-
it
|
|
143
|
+
it 'contains the second match' do
|
|
156
144
|
expect(found).to include(band_two)
|
|
157
145
|
end
|
|
158
146
|
|
|
159
|
-
context
|
|
160
|
-
|
|
147
|
+
context 'when ids are duplicates' do
|
|
161
148
|
let(:found) do
|
|
162
149
|
Band.find(band.id, band.id)
|
|
163
150
|
end
|
|
164
151
|
|
|
165
|
-
it
|
|
166
|
-
expect(found).to eq([band])
|
|
152
|
+
it 'contains only the first match' do
|
|
153
|
+
expect(found).to eq([ band ])
|
|
167
154
|
end
|
|
168
155
|
end
|
|
169
156
|
end
|
|
170
157
|
|
|
171
|
-
context
|
|
172
|
-
|
|
173
|
-
context "when raising a not found error" do
|
|
158
|
+
context 'when any id does not match' do
|
|
159
|
+
context 'when raising a not found error' do
|
|
174
160
|
config_override :raise_not_found_error, true
|
|
175
161
|
|
|
176
162
|
let(:found) do
|
|
177
163
|
Band.find(band.id, BSON::ObjectId.new)
|
|
178
164
|
end
|
|
179
165
|
|
|
180
|
-
it
|
|
181
|
-
expect
|
|
166
|
+
it 'raises an error' do
|
|
167
|
+
expect do
|
|
182
168
|
found
|
|
183
|
-
|
|
169
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
170
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
184
171
|
end
|
|
185
172
|
end
|
|
186
173
|
|
|
187
|
-
context
|
|
174
|
+
context 'when raising no error' do
|
|
188
175
|
config_override :raise_not_found_error, false
|
|
189
176
|
|
|
190
177
|
let(:found) do
|
|
191
178
|
Band.find(band.id, BSON::ObjectId.new)
|
|
192
179
|
end
|
|
193
180
|
|
|
194
|
-
it
|
|
181
|
+
it 'returns only the matching documents' do
|
|
195
182
|
expect(found).to eq([ band ])
|
|
196
183
|
end
|
|
197
184
|
end
|
|
198
185
|
end
|
|
199
186
|
end
|
|
200
187
|
|
|
201
|
-
context
|
|
202
|
-
|
|
188
|
+
context 'when providing an array of ids' do
|
|
203
189
|
let!(:band_two) do
|
|
204
|
-
Band.create!(name:
|
|
190
|
+
Band.create!(name: 'Tool')
|
|
205
191
|
end
|
|
206
192
|
|
|
207
|
-
context
|
|
208
|
-
|
|
193
|
+
context 'when all ids match' do
|
|
209
194
|
let(:found) do
|
|
210
195
|
Band.find([ band.id, band_two.id ])
|
|
211
196
|
end
|
|
212
197
|
|
|
213
|
-
it
|
|
198
|
+
it 'contains the first match' do
|
|
214
199
|
expect(found).to include(band)
|
|
215
200
|
end
|
|
216
201
|
|
|
217
|
-
it
|
|
202
|
+
it 'contains the second match' do
|
|
218
203
|
expect(found).to include(band_two)
|
|
219
204
|
end
|
|
220
205
|
|
|
221
|
-
context
|
|
222
|
-
|
|
206
|
+
context 'when ids are duplicates' do
|
|
223
207
|
let(:found) do
|
|
224
208
|
Band.find([ band.id, band.id ])
|
|
225
209
|
end
|
|
226
210
|
|
|
227
|
-
it
|
|
228
|
-
expect(found).to eq([band])
|
|
211
|
+
it 'contains only the first match' do
|
|
212
|
+
expect(found).to eq([ band ])
|
|
229
213
|
end
|
|
230
214
|
end
|
|
231
215
|
end
|
|
232
216
|
|
|
233
|
-
context
|
|
234
|
-
|
|
235
|
-
context "when raising a not found error" do
|
|
217
|
+
context 'when any id does not match' do
|
|
218
|
+
context 'when raising a not found error' do
|
|
236
219
|
config_override :raise_not_found_error, true
|
|
237
220
|
|
|
238
221
|
let(:found) do
|
|
239
222
|
Band.find([ band.id, BSON::ObjectId.new ])
|
|
240
223
|
end
|
|
241
224
|
|
|
242
|
-
it
|
|
243
|
-
expect
|
|
225
|
+
it 'raises an error' do
|
|
226
|
+
expect do
|
|
244
227
|
found
|
|
245
|
-
|
|
228
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
229
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
246
230
|
end
|
|
247
231
|
end
|
|
248
232
|
|
|
249
|
-
context
|
|
233
|
+
context 'when raising no error' do
|
|
250
234
|
config_override :raise_not_found_error, false
|
|
251
235
|
|
|
252
236
|
let(:found) do
|
|
253
237
|
Band.find([ band.id, BSON::ObjectId.new ])
|
|
254
238
|
end
|
|
255
239
|
|
|
256
|
-
it
|
|
240
|
+
it 'returns only the matching documents' do
|
|
257
241
|
expect(found).to eq([ band ])
|
|
258
242
|
end
|
|
259
243
|
end
|
|
260
244
|
end
|
|
261
245
|
end
|
|
262
246
|
|
|
263
|
-
context
|
|
264
|
-
|
|
247
|
+
context 'when providing nested arrays of ids' do
|
|
265
248
|
let!(:band_two) do
|
|
266
|
-
Band.create!(name:
|
|
249
|
+
Band.create!(name: 'Tool')
|
|
267
250
|
end
|
|
268
251
|
|
|
269
|
-
context
|
|
270
|
-
|
|
252
|
+
context 'when all ids match' do
|
|
271
253
|
let(:found) do
|
|
272
254
|
Band.find([ [ band.id ], [ [ band_two.id ] ] ])
|
|
273
255
|
end
|
|
274
256
|
|
|
275
|
-
it
|
|
257
|
+
it 'contains the first match' do
|
|
276
258
|
expect(found).to include(band)
|
|
277
259
|
end
|
|
278
260
|
|
|
279
|
-
it
|
|
261
|
+
it 'contains the second match' do
|
|
280
262
|
expect(found).to include(band_two)
|
|
281
263
|
end
|
|
282
264
|
|
|
283
|
-
context
|
|
284
|
-
|
|
265
|
+
context 'when ids are duplicates' do
|
|
285
266
|
let(:found) do
|
|
286
267
|
Band.find([ [ band.id ], [ [ band.id ] ] ])
|
|
287
268
|
end
|
|
288
269
|
|
|
289
|
-
it
|
|
290
|
-
expect(found).to eq([band])
|
|
270
|
+
it 'contains only the first match' do
|
|
271
|
+
expect(found).to eq([ band ])
|
|
291
272
|
end
|
|
292
273
|
end
|
|
293
274
|
end
|
|
294
275
|
|
|
295
|
-
context
|
|
296
|
-
|
|
297
|
-
context "when raising a not found error" do
|
|
276
|
+
context 'when any id does not match' do
|
|
277
|
+
context 'when raising a not found error' do
|
|
298
278
|
config_override :raise_not_found_error, true
|
|
299
279
|
|
|
300
280
|
let(:found) do
|
|
301
281
|
Band.find([ [ band.id ], [ [ BSON::ObjectId.new ] ] ])
|
|
302
282
|
end
|
|
303
283
|
|
|
304
|
-
it
|
|
305
|
-
expect
|
|
284
|
+
it 'raises an error' do
|
|
285
|
+
expect do
|
|
306
286
|
found
|
|
307
|
-
|
|
287
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
288
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
308
289
|
end
|
|
309
290
|
end
|
|
310
291
|
|
|
311
|
-
context
|
|
292
|
+
context 'when raising no error' do
|
|
312
293
|
config_override :raise_not_found_error, false
|
|
313
294
|
|
|
314
295
|
let(:found) do
|
|
315
296
|
Band.find([ [ band.id ], [ [ BSON::ObjectId.new ] ] ])
|
|
316
297
|
end
|
|
317
298
|
|
|
318
|
-
it
|
|
299
|
+
it 'returns only the matching documents' do
|
|
319
300
|
expect(found).to eq([ band ])
|
|
320
301
|
end
|
|
321
302
|
end
|
|
322
303
|
end
|
|
323
304
|
end
|
|
324
305
|
|
|
325
|
-
context
|
|
326
|
-
|
|
306
|
+
context 'when providing a Set of ids' do
|
|
327
307
|
let!(:band_two) do
|
|
328
|
-
Band.create!(name:
|
|
308
|
+
Band.create!(name: 'Tool')
|
|
329
309
|
end
|
|
330
310
|
|
|
331
|
-
context
|
|
311
|
+
context 'when all ids match' do
|
|
332
312
|
let(:found) do
|
|
333
|
-
Band.find(Set[
|
|
313
|
+
Band.find(Set[band.id, band_two.id])
|
|
334
314
|
end
|
|
335
315
|
|
|
336
|
-
it
|
|
316
|
+
it 'contains the first match' do
|
|
337
317
|
expect(found).to include(band)
|
|
338
318
|
end
|
|
339
319
|
|
|
340
|
-
it
|
|
320
|
+
it 'contains the second match' do
|
|
341
321
|
expect(found).to include(band_two)
|
|
342
322
|
end
|
|
343
323
|
end
|
|
344
324
|
|
|
345
|
-
context
|
|
346
|
-
|
|
347
|
-
context "when raising a not found error" do
|
|
325
|
+
context 'when any id does not match' do
|
|
326
|
+
context 'when raising a not found error' do
|
|
348
327
|
config_override :raise_not_found_error, true
|
|
349
328
|
|
|
350
329
|
let(:found) do
|
|
351
|
-
Band.find(Set[
|
|
330
|
+
Band.find(Set[band.id, BSON::ObjectId.new])
|
|
352
331
|
end
|
|
353
332
|
|
|
354
|
-
it
|
|
355
|
-
expect
|
|
333
|
+
it 'raises an error' do
|
|
334
|
+
expect do
|
|
356
335
|
found
|
|
357
|
-
|
|
336
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
337
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
358
338
|
end
|
|
359
339
|
end
|
|
360
340
|
|
|
361
|
-
context
|
|
341
|
+
context 'when raising no error' do
|
|
362
342
|
config_override :raise_not_found_error, false
|
|
363
343
|
|
|
364
344
|
let(:found) do
|
|
365
|
-
Band.find(Set[
|
|
345
|
+
Band.find(Set[band.id, BSON::ObjectId.new])
|
|
366
346
|
end
|
|
367
347
|
|
|
368
|
-
it
|
|
348
|
+
it 'returns only the matching documents' do
|
|
369
349
|
expect(found).to eq([ band ])
|
|
370
350
|
end
|
|
371
351
|
end
|
|
372
352
|
end
|
|
373
353
|
end
|
|
374
354
|
|
|
375
|
-
context
|
|
376
|
-
|
|
355
|
+
context 'when providing a Range of ids' do
|
|
377
356
|
let!(:band_two) do
|
|
378
|
-
Band.create!(name:
|
|
357
|
+
Band.create!(name: 'Tool')
|
|
379
358
|
end
|
|
380
359
|
|
|
381
|
-
context
|
|
360
|
+
context 'when all ids match' do
|
|
382
361
|
let(:found) do
|
|
383
362
|
Band.find(band.id.to_s..band_two.id.to_s)
|
|
384
363
|
end
|
|
385
364
|
|
|
386
|
-
it
|
|
365
|
+
it 'contains the first match' do
|
|
387
366
|
expect(found).to include(band)
|
|
388
367
|
end
|
|
389
368
|
|
|
390
|
-
it
|
|
369
|
+
it 'contains the second match' do
|
|
391
370
|
expect(found).to include(band_two)
|
|
392
371
|
end
|
|
393
372
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
context "when raising a not found error" do
|
|
373
|
+
context 'when any id does not match' do
|
|
374
|
+
context 'when raising a not found error' do
|
|
398
375
|
config_override :raise_not_found_error, true
|
|
399
376
|
|
|
400
377
|
let(:found) do
|
|
401
378
|
Band.find(band_two.id.to_s..BSON::ObjectId.new)
|
|
402
379
|
end
|
|
403
380
|
|
|
404
|
-
it
|
|
381
|
+
it 'does not raise error and returns only the matching documents' do
|
|
405
382
|
expect(found).to eq([ band_two ])
|
|
406
383
|
end
|
|
407
384
|
end
|
|
408
385
|
|
|
409
|
-
context
|
|
386
|
+
context 'when raising no error' do
|
|
410
387
|
config_override :raise_not_found_error, false
|
|
411
388
|
|
|
412
389
|
let(:found) do
|
|
413
390
|
Band.find(band_two.id.to_s..BSON::ObjectId.new)
|
|
414
391
|
end
|
|
415
392
|
|
|
416
|
-
it
|
|
393
|
+
it 'returns only the matching documents' do
|
|
417
394
|
expect(found).to eq([ band_two ])
|
|
418
395
|
end
|
|
419
396
|
end
|
|
420
397
|
end
|
|
421
398
|
end
|
|
422
399
|
|
|
423
|
-
context
|
|
424
|
-
|
|
425
|
-
context "when raising a not found error" do
|
|
400
|
+
context 'when all ids do not match' do
|
|
401
|
+
context 'when raising a not found error' do
|
|
426
402
|
config_override :raise_not_found_error, true
|
|
427
403
|
|
|
428
404
|
let(:found) do
|
|
429
405
|
Band.find(BSON::ObjectId.new..BSON::ObjectId.new)
|
|
430
406
|
end
|
|
431
407
|
|
|
432
|
-
it
|
|
433
|
-
expect
|
|
408
|
+
it 'raises an error' do
|
|
409
|
+
expect do
|
|
434
410
|
found
|
|
435
|
-
|
|
411
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
412
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
436
413
|
end
|
|
437
414
|
end
|
|
438
415
|
|
|
439
|
-
context
|
|
416
|
+
context 'when raising no error' do
|
|
440
417
|
config_override :raise_not_found_error, false
|
|
441
418
|
|
|
442
419
|
let(:found) do
|
|
443
420
|
Band.find(BSON::ObjectId.new..BSON::ObjectId.new)
|
|
444
421
|
end
|
|
445
422
|
|
|
446
|
-
it
|
|
423
|
+
it 'returns only the matching documents' do
|
|
447
424
|
expect(found).to eq([])
|
|
448
425
|
end
|
|
449
426
|
end
|
|
450
427
|
end
|
|
451
428
|
end
|
|
452
429
|
|
|
453
|
-
context
|
|
454
|
-
|
|
455
|
-
context "when the id matches" do
|
|
456
|
-
|
|
430
|
+
context 'when providing a single id as extended json' do
|
|
431
|
+
context 'when the id matches' do
|
|
457
432
|
let(:found) do
|
|
458
433
|
Band.find(band.id.as_json)
|
|
459
434
|
end
|
|
460
435
|
|
|
461
|
-
it
|
|
436
|
+
it 'returns the matching document' do
|
|
462
437
|
expect(found).to eq(band)
|
|
463
438
|
end
|
|
464
439
|
end
|
|
465
440
|
|
|
466
|
-
context
|
|
467
|
-
|
|
468
|
-
context "when raising a not found error" do
|
|
441
|
+
context 'when the id does not match' do
|
|
442
|
+
context 'when raising a not found error' do
|
|
469
443
|
config_override :raise_not_found_error, true
|
|
470
444
|
|
|
471
445
|
let(:found) do
|
|
472
446
|
Band.find(BSON::ObjectId.new.as_json)
|
|
473
447
|
end
|
|
474
448
|
|
|
475
|
-
it
|
|
476
|
-
expect
|
|
449
|
+
it 'raises an error' do
|
|
450
|
+
expect do
|
|
477
451
|
found
|
|
478
|
-
|
|
452
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
453
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
479
454
|
end
|
|
480
455
|
end
|
|
481
456
|
|
|
482
|
-
context
|
|
457
|
+
context 'when raising no error' do
|
|
483
458
|
config_override :raise_not_found_error, false
|
|
484
459
|
|
|
485
460
|
let(:found) do
|
|
486
461
|
Band.find(BSON::ObjectId.new.as_json)
|
|
487
462
|
end
|
|
488
463
|
|
|
489
|
-
it
|
|
464
|
+
it 'returns nil' do
|
|
490
465
|
expect(found).to be_nil
|
|
491
466
|
end
|
|
492
467
|
end
|
|
493
468
|
end
|
|
494
469
|
end
|
|
495
470
|
|
|
496
|
-
context
|
|
497
|
-
|
|
471
|
+
context 'when providing a splat of extended json ids' do
|
|
498
472
|
let!(:band_two) do
|
|
499
|
-
Band.create!(name:
|
|
473
|
+
Band.create!(name: 'Tool')
|
|
500
474
|
end
|
|
501
475
|
|
|
502
|
-
context
|
|
503
|
-
|
|
476
|
+
context 'when all ids match' do
|
|
504
477
|
let(:found) do
|
|
505
478
|
Band.find(band.id.as_json, band_two.id.as_json)
|
|
506
479
|
end
|
|
507
480
|
|
|
508
|
-
it
|
|
481
|
+
it 'contains the first match' do
|
|
509
482
|
expect(found).to include(band)
|
|
510
483
|
end
|
|
511
484
|
|
|
512
|
-
it
|
|
485
|
+
it 'contains the second match' do
|
|
513
486
|
expect(found).to include(band_two)
|
|
514
487
|
end
|
|
515
488
|
|
|
516
|
-
context
|
|
517
|
-
|
|
489
|
+
context 'when ids are duplicates' do
|
|
518
490
|
let(:found) do
|
|
519
491
|
Band.find(band.id, band.id)
|
|
520
492
|
end
|
|
521
493
|
|
|
522
|
-
it
|
|
523
|
-
expect(found).to eq([band])
|
|
494
|
+
it 'contains only the first match' do
|
|
495
|
+
expect(found).to eq([ band ])
|
|
524
496
|
end
|
|
525
497
|
end
|
|
526
498
|
end
|
|
527
499
|
|
|
528
|
-
context
|
|
529
|
-
|
|
530
|
-
context "when raising a not found error" do
|
|
500
|
+
context 'when any id does not match' do
|
|
501
|
+
context 'when raising a not found error' do
|
|
531
502
|
config_override :raise_not_found_error, true
|
|
532
503
|
|
|
533
504
|
let(:found) do
|
|
534
505
|
Band.find(band.id.as_json, BSON::ObjectId.new.as_json)
|
|
535
506
|
end
|
|
536
507
|
|
|
537
|
-
it
|
|
538
|
-
expect
|
|
508
|
+
it 'raises an error' do
|
|
509
|
+
expect do
|
|
539
510
|
found
|
|
540
|
-
|
|
511
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
512
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
541
513
|
end
|
|
542
514
|
end
|
|
543
515
|
|
|
544
|
-
context
|
|
516
|
+
context 'when raising no error' do
|
|
545
517
|
config_override :raise_not_found_error, false
|
|
546
518
|
|
|
547
519
|
let(:found) do
|
|
548
520
|
Band.find(band.id.as_json, BSON::ObjectId.new.as_json)
|
|
549
521
|
end
|
|
550
522
|
|
|
551
|
-
it
|
|
523
|
+
it 'returns only the matching documents' do
|
|
552
524
|
expect(found).to eq([ band ])
|
|
553
525
|
end
|
|
554
526
|
end
|
|
555
527
|
end
|
|
556
528
|
end
|
|
557
529
|
|
|
558
|
-
context
|
|
559
|
-
|
|
530
|
+
context 'when providing an array of extended json ids' do
|
|
560
531
|
let!(:band_two) do
|
|
561
|
-
Band.create!(name:
|
|
532
|
+
Band.create!(name: 'Tool')
|
|
562
533
|
end
|
|
563
534
|
|
|
564
|
-
context
|
|
565
|
-
|
|
535
|
+
context 'when all ids match' do
|
|
566
536
|
let(:found) do
|
|
567
537
|
Band.find([ band.id.as_json, band_two.id.as_json ])
|
|
568
538
|
end
|
|
569
539
|
|
|
570
|
-
it
|
|
540
|
+
it 'contains the first match' do
|
|
571
541
|
expect(found).to include(band)
|
|
572
542
|
end
|
|
573
543
|
|
|
574
|
-
it
|
|
544
|
+
it 'contains the second match' do
|
|
575
545
|
expect(found).to include(band_two)
|
|
576
546
|
end
|
|
577
547
|
|
|
578
|
-
context
|
|
579
|
-
|
|
548
|
+
context 'when ids are duplicates' do
|
|
580
549
|
let(:found) do
|
|
581
550
|
Band.find([ band.id, band.id ])
|
|
582
551
|
end
|
|
583
552
|
|
|
584
|
-
it
|
|
585
|
-
expect(found).to eq([band])
|
|
553
|
+
it 'contains only the first match' do
|
|
554
|
+
expect(found).to eq([ band ])
|
|
586
555
|
end
|
|
587
556
|
end
|
|
588
557
|
end
|
|
589
558
|
|
|
590
|
-
context
|
|
591
|
-
|
|
592
|
-
context "when raising a not found error" do
|
|
559
|
+
context 'when any id does not match' do
|
|
560
|
+
context 'when raising a not found error' do
|
|
593
561
|
config_override :raise_not_found_error, true
|
|
594
562
|
|
|
595
563
|
let(:found) do
|
|
596
564
|
Band.find([ band.id.as_json, BSON::ObjectId.new.as_json ])
|
|
597
565
|
end
|
|
598
566
|
|
|
599
|
-
it
|
|
600
|
-
expect
|
|
567
|
+
it 'raises an error' do
|
|
568
|
+
expect do
|
|
601
569
|
found
|
|
602
|
-
|
|
570
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
571
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
603
572
|
end
|
|
604
573
|
end
|
|
605
574
|
|
|
606
|
-
context
|
|
575
|
+
context 'when raising no error' do
|
|
607
576
|
config_override :raise_not_found_error, false
|
|
608
577
|
|
|
609
578
|
let(:found) do
|
|
610
579
|
Band.find([ band.id.as_json, BSON::ObjectId.new.as_json ])
|
|
611
580
|
end
|
|
612
581
|
|
|
613
|
-
it
|
|
582
|
+
it 'returns only the matching documents' do
|
|
614
583
|
expect(found).to eq([ band ])
|
|
615
584
|
end
|
|
616
585
|
end
|
|
@@ -618,165 +587,158 @@ describe Mongoid::Criteria::Findable do
|
|
|
618
587
|
end
|
|
619
588
|
end
|
|
620
589
|
|
|
621
|
-
context
|
|
622
|
-
|
|
590
|
+
context 'when using string ids' do
|
|
623
591
|
before(:all) do
|
|
624
592
|
Band.field :_id, overwrite: true, type: String
|
|
625
593
|
end
|
|
626
594
|
|
|
627
595
|
after(:all) do
|
|
628
|
-
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: ->{ BSON::ObjectId.new }
|
|
596
|
+
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new }
|
|
629
597
|
end
|
|
630
598
|
|
|
631
599
|
let!(:band) do
|
|
632
600
|
Band.create! do |band|
|
|
633
|
-
band.id =
|
|
601
|
+
band.id = 'tool'
|
|
634
602
|
end
|
|
635
603
|
end
|
|
636
604
|
|
|
637
|
-
context
|
|
638
|
-
|
|
639
|
-
context "when the id matches" do
|
|
640
|
-
|
|
605
|
+
context 'when providing a single id' do
|
|
606
|
+
context 'when the id matches' do
|
|
641
607
|
let(:found) do
|
|
642
608
|
Band.find(band.id)
|
|
643
609
|
end
|
|
644
610
|
|
|
645
|
-
it
|
|
611
|
+
it 'returns the matching document' do
|
|
646
612
|
expect(found).to eq(band)
|
|
647
613
|
end
|
|
648
614
|
end
|
|
649
615
|
|
|
650
|
-
context
|
|
651
|
-
|
|
652
|
-
context "when raising a not found error" do
|
|
616
|
+
context 'when the id does not match' do
|
|
617
|
+
context 'when raising a not found error' do
|
|
653
618
|
config_override :raise_not_found_error, true
|
|
654
619
|
|
|
655
620
|
let(:found) do
|
|
656
|
-
Band.find(
|
|
621
|
+
Band.find('depeche-mode')
|
|
657
622
|
end
|
|
658
623
|
|
|
659
|
-
it
|
|
660
|
-
expect
|
|
624
|
+
it 'raises an error' do
|
|
625
|
+
expect do
|
|
661
626
|
found
|
|
662
|
-
|
|
627
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
628
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
663
629
|
end
|
|
664
630
|
end
|
|
665
631
|
|
|
666
|
-
context
|
|
632
|
+
context 'when raising no error' do
|
|
667
633
|
config_override :raise_not_found_error, false
|
|
668
634
|
|
|
669
635
|
let(:found) do
|
|
670
|
-
Band.find(
|
|
636
|
+
Band.find('depeche-mode')
|
|
671
637
|
end
|
|
672
638
|
|
|
673
|
-
it
|
|
639
|
+
it 'returns nil' do
|
|
674
640
|
expect(found).to be_nil
|
|
675
641
|
end
|
|
676
642
|
end
|
|
677
643
|
end
|
|
678
644
|
end
|
|
679
645
|
|
|
680
|
-
context
|
|
681
|
-
|
|
646
|
+
context 'when providing a splat of ids' do
|
|
682
647
|
let!(:band_two) do
|
|
683
648
|
Band.create! do |band|
|
|
684
|
-
band.id =
|
|
649
|
+
band.id = 'depeche-mode'
|
|
685
650
|
end
|
|
686
651
|
end
|
|
687
652
|
|
|
688
|
-
context
|
|
689
|
-
|
|
653
|
+
context 'when all ids match' do
|
|
690
654
|
let(:found) do
|
|
691
655
|
Band.find(band.id, band_two.id)
|
|
692
656
|
end
|
|
693
657
|
|
|
694
|
-
it
|
|
658
|
+
it 'contains the first match' do
|
|
695
659
|
expect(found).to include(band)
|
|
696
660
|
end
|
|
697
661
|
|
|
698
|
-
it
|
|
662
|
+
it 'contains the second match' do
|
|
699
663
|
expect(found).to include(band_two)
|
|
700
664
|
end
|
|
701
665
|
end
|
|
702
666
|
|
|
703
|
-
context
|
|
704
|
-
|
|
705
|
-
context "when raising a not found error" do
|
|
667
|
+
context 'when any id does not match' do
|
|
668
|
+
context 'when raising a not found error' do
|
|
706
669
|
config_override :raise_not_found_error, true
|
|
707
670
|
|
|
708
671
|
let(:found) do
|
|
709
|
-
Band.find(band.id,
|
|
672
|
+
Band.find(band.id, 'new-order')
|
|
710
673
|
end
|
|
711
674
|
|
|
712
|
-
it
|
|
713
|
-
expect
|
|
675
|
+
it 'raises an error' do
|
|
676
|
+
expect do
|
|
714
677
|
found
|
|
715
|
-
|
|
678
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
679
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
716
680
|
end
|
|
717
681
|
end
|
|
718
682
|
|
|
719
|
-
context
|
|
683
|
+
context 'when raising no error' do
|
|
720
684
|
config_override :raise_not_found_error, false
|
|
721
685
|
|
|
722
686
|
let(:found) do
|
|
723
|
-
Band.find(band.id,
|
|
687
|
+
Band.find(band.id, 'new-order')
|
|
724
688
|
end
|
|
725
689
|
|
|
726
|
-
it
|
|
690
|
+
it 'returns only the matching documents' do
|
|
727
691
|
expect(found).to eq([ band ])
|
|
728
692
|
end
|
|
729
693
|
end
|
|
730
694
|
end
|
|
731
695
|
end
|
|
732
696
|
|
|
733
|
-
context
|
|
734
|
-
|
|
697
|
+
context 'when providing an array of ids' do
|
|
735
698
|
let!(:band_two) do
|
|
736
699
|
Band.create! do |band|
|
|
737
|
-
band.id =
|
|
700
|
+
band.id = 'depeche-mode'
|
|
738
701
|
end
|
|
739
702
|
end
|
|
740
703
|
|
|
741
|
-
context
|
|
742
|
-
|
|
704
|
+
context 'when all ids match' do
|
|
743
705
|
let(:found) do
|
|
744
706
|
Band.find([ band.id, band_two.id ])
|
|
745
707
|
end
|
|
746
708
|
|
|
747
|
-
it
|
|
709
|
+
it 'contains the first match' do
|
|
748
710
|
expect(found).to include(band)
|
|
749
711
|
end
|
|
750
712
|
|
|
751
|
-
it
|
|
713
|
+
it 'contains the second match' do
|
|
752
714
|
expect(found).to include(band_two)
|
|
753
715
|
end
|
|
754
716
|
end
|
|
755
717
|
|
|
756
|
-
context
|
|
757
|
-
|
|
758
|
-
context "when raising a not found error" do
|
|
718
|
+
context 'when any id does not match' do
|
|
719
|
+
context 'when raising a not found error' do
|
|
759
720
|
config_override :raise_not_found_error, true
|
|
760
721
|
|
|
761
722
|
let(:found) do
|
|
762
|
-
Band.find([ band.id,
|
|
723
|
+
Band.find([ band.id, 'new-order' ])
|
|
763
724
|
end
|
|
764
725
|
|
|
765
|
-
it
|
|
766
|
-
expect
|
|
726
|
+
it 'raises an error' do
|
|
727
|
+
expect do
|
|
767
728
|
found
|
|
768
|
-
|
|
729
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
730
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
769
731
|
end
|
|
770
732
|
end
|
|
771
733
|
|
|
772
|
-
context
|
|
734
|
+
context 'when raising no error' do
|
|
773
735
|
config_override :raise_not_found_error, false
|
|
774
736
|
|
|
775
737
|
let(:found) do
|
|
776
|
-
Band.find([ band.id,
|
|
738
|
+
Band.find([ band.id, 'new-order' ])
|
|
777
739
|
end
|
|
778
740
|
|
|
779
|
-
it
|
|
741
|
+
it 'returns only the matching documents' do
|
|
780
742
|
expect(found).to eq([ band ])
|
|
781
743
|
end
|
|
782
744
|
end
|
|
@@ -784,165 +746,158 @@ describe Mongoid::Criteria::Findable do
|
|
|
784
746
|
end
|
|
785
747
|
end
|
|
786
748
|
|
|
787
|
-
context
|
|
788
|
-
|
|
749
|
+
context 'when using hash ids' do
|
|
789
750
|
before(:all) do
|
|
790
751
|
Band.field :_id, overwrite: true, type: Hash
|
|
791
752
|
end
|
|
792
753
|
|
|
793
754
|
after(:all) do
|
|
794
|
-
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: ->{ BSON::ObjectId.new }
|
|
755
|
+
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new }
|
|
795
756
|
end
|
|
796
757
|
|
|
797
758
|
let!(:band) do
|
|
798
759
|
Band.create! do |band|
|
|
799
|
-
band.id = {
|
|
760
|
+
band.id = { 'new-order' => true, 'Depeche Mode' => false }
|
|
800
761
|
end
|
|
801
762
|
end
|
|
802
763
|
|
|
803
|
-
context
|
|
804
|
-
|
|
805
|
-
context "when the id matches" do
|
|
806
|
-
|
|
764
|
+
context 'when providing a single id' do
|
|
765
|
+
context 'when the id matches' do
|
|
807
766
|
let(:found) do
|
|
808
767
|
Band.find(band.id)
|
|
809
768
|
end
|
|
810
769
|
|
|
811
|
-
it
|
|
770
|
+
it 'returns the matching document' do
|
|
812
771
|
expect(found).to eq(band)
|
|
813
772
|
end
|
|
814
773
|
end
|
|
815
774
|
|
|
816
|
-
context
|
|
817
|
-
|
|
818
|
-
context "when raising a not found error" do
|
|
775
|
+
context 'when the id does not match' do
|
|
776
|
+
context 'when raising a not found error' do
|
|
819
777
|
config_override :raise_not_found_error, true
|
|
820
778
|
|
|
821
779
|
let(:found) do
|
|
822
|
-
Band.find({
|
|
780
|
+
Band.find({ 'new-order' => false, 'Faith no More' => true })
|
|
823
781
|
end
|
|
824
782
|
|
|
825
|
-
it
|
|
826
|
-
expect
|
|
783
|
+
it 'raises an error' do
|
|
784
|
+
expect do
|
|
827
785
|
found
|
|
828
|
-
|
|
786
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
787
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
829
788
|
end
|
|
830
789
|
end
|
|
831
790
|
|
|
832
|
-
context
|
|
791
|
+
context 'when raising no error' do
|
|
833
792
|
config_override :raise_not_found_error, false
|
|
834
793
|
|
|
835
794
|
let(:found) do
|
|
836
|
-
Band.find({
|
|
795
|
+
Band.find({ 'new-order' => false, 'Faith no More' => true })
|
|
837
796
|
end
|
|
838
797
|
|
|
839
|
-
it
|
|
798
|
+
it 'returns nil' do
|
|
840
799
|
expect(found).to be_nil
|
|
841
800
|
end
|
|
842
801
|
end
|
|
843
802
|
end
|
|
844
803
|
end
|
|
845
804
|
|
|
846
|
-
context
|
|
847
|
-
|
|
805
|
+
context 'when providing a splat of ids' do
|
|
848
806
|
let!(:band_two) do
|
|
849
807
|
Band.create! do |band|
|
|
850
|
-
band.id = {
|
|
808
|
+
band.id = { 'Radiohead' => false, 'Nirvana' => true }
|
|
851
809
|
end
|
|
852
810
|
end
|
|
853
811
|
|
|
854
|
-
context
|
|
855
|
-
|
|
812
|
+
context 'when all ids match' do
|
|
856
813
|
let(:found) do
|
|
857
814
|
Band.find(band.id, band_two.id)
|
|
858
815
|
end
|
|
859
816
|
|
|
860
|
-
it
|
|
817
|
+
it 'contains the first match' do
|
|
861
818
|
expect(found).to include(band)
|
|
862
819
|
end
|
|
863
820
|
|
|
864
|
-
it
|
|
821
|
+
it 'contains the second match' do
|
|
865
822
|
expect(found).to include(band_two)
|
|
866
823
|
end
|
|
867
824
|
end
|
|
868
825
|
|
|
869
|
-
context
|
|
870
|
-
|
|
871
|
-
context "when raising a not found error" do
|
|
826
|
+
context 'when any id does not match' do
|
|
827
|
+
context 'when raising a not found error' do
|
|
872
828
|
config_override :raise_not_found_error, true
|
|
873
829
|
|
|
874
830
|
let(:found) do
|
|
875
|
-
Band.find(band.id, {
|
|
831
|
+
Band.find(band.id, { 'Radiohead' => true, 'Nirvana' => false })
|
|
876
832
|
end
|
|
877
833
|
|
|
878
|
-
it
|
|
879
|
-
expect
|
|
834
|
+
it 'raises an error' do
|
|
835
|
+
expect do
|
|
880
836
|
found
|
|
881
|
-
|
|
837
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
838
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
882
839
|
end
|
|
883
840
|
end
|
|
884
841
|
|
|
885
|
-
context
|
|
842
|
+
context 'when raising no error' do
|
|
886
843
|
config_override :raise_not_found_error, false
|
|
887
844
|
|
|
888
845
|
let(:found) do
|
|
889
|
-
Band.find(band.id, {
|
|
846
|
+
Band.find(band.id, { 'Radiohead' => true, 'Nirvana' => false })
|
|
890
847
|
end
|
|
891
848
|
|
|
892
|
-
it
|
|
849
|
+
it 'returns only the matching documents' do
|
|
893
850
|
expect(found).to eq([ band ])
|
|
894
851
|
end
|
|
895
852
|
end
|
|
896
853
|
end
|
|
897
854
|
end
|
|
898
855
|
|
|
899
|
-
context
|
|
900
|
-
|
|
856
|
+
context 'when providing an array of ids' do
|
|
901
857
|
let!(:band_two) do
|
|
902
858
|
Band.create! do |band|
|
|
903
|
-
band.id = {
|
|
859
|
+
band.id = { 'Radiohead' => false, 'Nirvana' => true }
|
|
904
860
|
end
|
|
905
861
|
end
|
|
906
862
|
|
|
907
|
-
context
|
|
908
|
-
|
|
863
|
+
context 'when all ids match' do
|
|
909
864
|
let(:found) do
|
|
910
865
|
Band.find([ band.id, band_two.id ])
|
|
911
866
|
end
|
|
912
867
|
|
|
913
|
-
it
|
|
868
|
+
it 'contains the first match' do
|
|
914
869
|
expect(found).to include(band)
|
|
915
870
|
end
|
|
916
871
|
|
|
917
|
-
it
|
|
872
|
+
it 'contains the second match' do
|
|
918
873
|
expect(found).to include(band_two)
|
|
919
874
|
end
|
|
920
875
|
end
|
|
921
876
|
|
|
922
|
-
context
|
|
923
|
-
|
|
924
|
-
context "when raising a not found error" do
|
|
877
|
+
context 'when any id does not match' do
|
|
878
|
+
context 'when raising a not found error' do
|
|
925
879
|
config_override :raise_not_found_error, true
|
|
926
880
|
|
|
927
881
|
let(:found) do
|
|
928
|
-
Band.find([ band.id, {
|
|
882
|
+
Band.find([ band.id, { 'Radiohead' => true, 'Nirvana' => false } ])
|
|
929
883
|
end
|
|
930
884
|
|
|
931
|
-
it
|
|
932
|
-
expect
|
|
885
|
+
it 'raises an error' do
|
|
886
|
+
expect do
|
|
933
887
|
found
|
|
934
|
-
|
|
888
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
889
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
935
890
|
end
|
|
936
891
|
end
|
|
937
892
|
|
|
938
|
-
context
|
|
893
|
+
context 'when raising no error' do
|
|
939
894
|
config_override :raise_not_found_error, false
|
|
940
895
|
|
|
941
896
|
let(:found) do
|
|
942
|
-
Band.find([ band.id, {
|
|
897
|
+
Band.find([ band.id, { 'Radiohead' => true, 'Nirvana' => false } ])
|
|
943
898
|
end
|
|
944
899
|
|
|
945
|
-
it
|
|
900
|
+
it 'returns only the matching documents' do
|
|
946
901
|
expect(found).to eq([ band ])
|
|
947
902
|
end
|
|
948
903
|
end
|
|
@@ -950,14 +905,13 @@ describe Mongoid::Criteria::Findable do
|
|
|
950
905
|
end
|
|
951
906
|
end
|
|
952
907
|
|
|
953
|
-
context
|
|
954
|
-
|
|
908
|
+
context 'when using integer ids' do
|
|
955
909
|
before(:all) do
|
|
956
910
|
Band.field :_id, overwrite: true, type: Integer
|
|
957
911
|
end
|
|
958
912
|
|
|
959
913
|
after(:all) do
|
|
960
|
-
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: ->{ BSON::ObjectId.new }
|
|
914
|
+
Band.field :_id, overwrite: true, type: BSON::ObjectId, default: -> { BSON::ObjectId.new }
|
|
961
915
|
end
|
|
962
916
|
|
|
963
917
|
let!(:band) do
|
|
@@ -966,210 +920,202 @@ describe Mongoid::Criteria::Findable do
|
|
|
966
920
|
end
|
|
967
921
|
end
|
|
968
922
|
|
|
969
|
-
context
|
|
970
|
-
|
|
971
|
-
context "when the id matches" do
|
|
972
|
-
|
|
923
|
+
context 'when providing a single id' do
|
|
924
|
+
context 'when the id matches' do
|
|
973
925
|
let(:found) do
|
|
974
926
|
Band.find(band.id)
|
|
975
927
|
end
|
|
976
928
|
|
|
977
|
-
it
|
|
929
|
+
it 'returns the matching document' do
|
|
978
930
|
expect(found).to eq(band)
|
|
979
931
|
end
|
|
980
932
|
end
|
|
981
933
|
|
|
982
|
-
context
|
|
983
|
-
|
|
984
|
-
context "when raising a not found error" do
|
|
934
|
+
context 'when the id does not match' do
|
|
935
|
+
context 'when raising a not found error' do
|
|
985
936
|
config_override :raise_not_found_error, true
|
|
986
937
|
|
|
987
938
|
let(:found) do
|
|
988
939
|
Band.find(3)
|
|
989
940
|
end
|
|
990
941
|
|
|
991
|
-
it
|
|
992
|
-
expect
|
|
942
|
+
it 'raises an error' do
|
|
943
|
+
expect do
|
|
993
944
|
found
|
|
994
|
-
|
|
945
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
946
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
995
947
|
end
|
|
996
948
|
end
|
|
997
949
|
|
|
998
|
-
context
|
|
950
|
+
context 'when raising no error' do
|
|
999
951
|
config_override :raise_not_found_error, false
|
|
1000
952
|
|
|
1001
953
|
let(:found) do
|
|
1002
954
|
Band.find(3)
|
|
1003
955
|
end
|
|
1004
956
|
|
|
1005
|
-
it
|
|
957
|
+
it 'returns nil' do
|
|
1006
958
|
expect(found).to be_nil
|
|
1007
959
|
end
|
|
1008
960
|
end
|
|
1009
961
|
end
|
|
1010
962
|
end
|
|
1011
963
|
|
|
1012
|
-
context
|
|
1013
|
-
|
|
964
|
+
context 'when providing a splat of ids' do
|
|
1014
965
|
let!(:band_two) do
|
|
1015
966
|
Band.create! do |band|
|
|
1016
967
|
band.id = 2
|
|
1017
968
|
end
|
|
1018
969
|
end
|
|
1019
970
|
|
|
1020
|
-
context
|
|
1021
|
-
|
|
971
|
+
context 'when all ids match' do
|
|
1022
972
|
let(:found) do
|
|
1023
973
|
Band.find(band.id, band_two.id)
|
|
1024
974
|
end
|
|
1025
975
|
|
|
1026
|
-
it
|
|
976
|
+
it 'contains the first match' do
|
|
1027
977
|
expect(found).to include(band)
|
|
1028
978
|
end
|
|
1029
979
|
|
|
1030
|
-
it
|
|
980
|
+
it 'contains the second match' do
|
|
1031
981
|
expect(found).to include(band_two)
|
|
1032
982
|
end
|
|
1033
983
|
end
|
|
1034
984
|
|
|
1035
|
-
context
|
|
1036
|
-
|
|
1037
|
-
context "when raising a not found error" do
|
|
985
|
+
context 'when any id does not match' do
|
|
986
|
+
context 'when raising a not found error' do
|
|
1038
987
|
config_override :raise_not_found_error, true
|
|
1039
988
|
|
|
1040
989
|
let(:found) do
|
|
1041
990
|
Band.find(band.id, 3)
|
|
1042
991
|
end
|
|
1043
992
|
|
|
1044
|
-
it
|
|
1045
|
-
expect
|
|
993
|
+
it 'raises an error' do
|
|
994
|
+
expect do
|
|
1046
995
|
found
|
|
1047
|
-
|
|
996
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
997
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
1048
998
|
end
|
|
1049
999
|
end
|
|
1050
1000
|
|
|
1051
|
-
context
|
|
1001
|
+
context 'when raising no error' do
|
|
1052
1002
|
config_override :raise_not_found_error, false
|
|
1053
1003
|
|
|
1054
1004
|
let(:found) do
|
|
1055
1005
|
Band.find(band.id, 3)
|
|
1056
1006
|
end
|
|
1057
1007
|
|
|
1058
|
-
it
|
|
1008
|
+
it 'returns only the matching documents' do
|
|
1059
1009
|
expect(found).to eq([ band ])
|
|
1060
1010
|
end
|
|
1061
1011
|
end
|
|
1062
1012
|
end
|
|
1063
1013
|
end
|
|
1064
1014
|
|
|
1065
|
-
context
|
|
1066
|
-
|
|
1015
|
+
context 'when providing an array of ids' do
|
|
1067
1016
|
let!(:band_two) do
|
|
1068
1017
|
Band.create! do |band|
|
|
1069
1018
|
band.id = 2
|
|
1070
1019
|
end
|
|
1071
1020
|
end
|
|
1072
1021
|
|
|
1073
|
-
context
|
|
1074
|
-
|
|
1022
|
+
context 'when all ids match' do
|
|
1075
1023
|
let(:found) do
|
|
1076
1024
|
Band.find([ band.id, band_two.id ])
|
|
1077
1025
|
end
|
|
1078
1026
|
|
|
1079
|
-
it
|
|
1027
|
+
it 'contains the first match' do
|
|
1080
1028
|
expect(found).to include(band)
|
|
1081
1029
|
end
|
|
1082
1030
|
|
|
1083
|
-
it
|
|
1031
|
+
it 'contains the second match' do
|
|
1084
1032
|
expect(found).to include(band_two)
|
|
1085
1033
|
end
|
|
1086
1034
|
end
|
|
1087
1035
|
|
|
1088
|
-
context
|
|
1089
|
-
|
|
1090
|
-
context "when raising a not found error" do
|
|
1036
|
+
context 'when any id does not match' do
|
|
1037
|
+
context 'when raising a not found error' do
|
|
1091
1038
|
config_override :raise_not_found_error, true
|
|
1092
1039
|
|
|
1093
1040
|
let(:found) do
|
|
1094
1041
|
Band.find([ band.id, 3 ])
|
|
1095
1042
|
end
|
|
1096
1043
|
|
|
1097
|
-
it
|
|
1098
|
-
expect
|
|
1044
|
+
it 'raises an error' do
|
|
1045
|
+
expect do
|
|
1099
1046
|
found
|
|
1100
|
-
|
|
1047
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
1048
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
1101
1049
|
end
|
|
1102
1050
|
end
|
|
1103
1051
|
|
|
1104
|
-
context
|
|
1052
|
+
context 'when raising no error' do
|
|
1105
1053
|
config_override :raise_not_found_error, false
|
|
1106
1054
|
|
|
1107
1055
|
let(:found) do
|
|
1108
1056
|
Band.find([ band.id, 3 ])
|
|
1109
1057
|
end
|
|
1110
1058
|
|
|
1111
|
-
it
|
|
1059
|
+
it 'returns only the matching documents' do
|
|
1112
1060
|
expect(found).to eq([ band ])
|
|
1113
1061
|
end
|
|
1114
1062
|
end
|
|
1115
1063
|
end
|
|
1116
1064
|
end
|
|
1117
1065
|
|
|
1118
|
-
context
|
|
1119
|
-
|
|
1066
|
+
context 'when providing a range' do
|
|
1120
1067
|
let!(:band_two) do
|
|
1121
1068
|
Band.create! do |band|
|
|
1122
1069
|
band.id = 2
|
|
1123
1070
|
end
|
|
1124
1071
|
end
|
|
1125
1072
|
|
|
1126
|
-
context
|
|
1127
|
-
|
|
1073
|
+
context 'when all ids match' do
|
|
1128
1074
|
let(:found) do
|
|
1129
1075
|
Band.find(1..2)
|
|
1130
1076
|
end
|
|
1131
1077
|
|
|
1132
|
-
it
|
|
1078
|
+
it 'contains the first match' do
|
|
1133
1079
|
expect(found).to include(band)
|
|
1134
1080
|
end
|
|
1135
1081
|
|
|
1136
|
-
it
|
|
1082
|
+
it 'contains the second match' do
|
|
1137
1083
|
expect(found).to include(band_two)
|
|
1138
1084
|
end
|
|
1139
1085
|
end
|
|
1140
1086
|
|
|
1141
|
-
context
|
|
1142
|
-
|
|
1143
|
-
context "when raising a not found error" do
|
|
1087
|
+
context 'when any id does not match' do
|
|
1088
|
+
context 'when raising a not found error' do
|
|
1144
1089
|
config_override :raise_not_found_error, true
|
|
1145
1090
|
|
|
1146
1091
|
let(:found) do
|
|
1147
1092
|
Band.find(1..3)
|
|
1148
1093
|
end
|
|
1149
1094
|
|
|
1150
|
-
it
|
|
1151
|
-
expect
|
|
1095
|
+
it 'raises an error' do
|
|
1096
|
+
expect do
|
|
1152
1097
|
found
|
|
1153
|
-
|
|
1098
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound,
|
|
1099
|
+
/Document\(s\) not found for class Band with id\(s\)/)
|
|
1154
1100
|
end
|
|
1155
1101
|
end
|
|
1156
1102
|
|
|
1157
|
-
context
|
|
1103
|
+
context 'when raising no error' do
|
|
1158
1104
|
config_override :raise_not_found_error, false
|
|
1159
1105
|
|
|
1160
1106
|
let(:found) do
|
|
1161
1107
|
Band.find(1..3)
|
|
1162
1108
|
end
|
|
1163
1109
|
|
|
1164
|
-
it
|
|
1110
|
+
it 'contains the first match' do
|
|
1165
1111
|
expect(found).to include(band)
|
|
1166
1112
|
end
|
|
1167
1113
|
|
|
1168
|
-
it
|
|
1114
|
+
it 'contains the second match' do
|
|
1169
1115
|
expect(found).to include(band_two)
|
|
1170
1116
|
end
|
|
1171
1117
|
|
|
1172
|
-
it
|
|
1118
|
+
it 'returns only the matches' do
|
|
1173
1119
|
expect(found.count).to eq(2)
|
|
1174
1120
|
end
|
|
1175
1121
|
end
|
|
@@ -1177,68 +1123,60 @@ describe Mongoid::Criteria::Findable do
|
|
|
1177
1123
|
end
|
|
1178
1124
|
end
|
|
1179
1125
|
|
|
1180
|
-
context
|
|
1181
|
-
|
|
1126
|
+
context 'when using string and object ids' do
|
|
1182
1127
|
let!(:band) do
|
|
1183
1128
|
Band.create!
|
|
1184
1129
|
end
|
|
1185
1130
|
|
|
1186
|
-
context
|
|
1187
|
-
|
|
1188
|
-
context "when ids are duplicates" do
|
|
1189
|
-
|
|
1131
|
+
context 'when providing multiple ids' do
|
|
1132
|
+
context 'when ids are duplicates' do
|
|
1190
1133
|
let(:found) do
|
|
1191
1134
|
Band.find([ band.id.to_s, band.id ])
|
|
1192
1135
|
end
|
|
1193
1136
|
|
|
1194
|
-
it
|
|
1195
|
-
expect(found).to eq([band])
|
|
1137
|
+
it 'contains only the first match' do
|
|
1138
|
+
expect(found).to eq([ band ])
|
|
1196
1139
|
end
|
|
1197
1140
|
end
|
|
1198
1141
|
end
|
|
1199
1142
|
end
|
|
1200
1143
|
|
|
1201
|
-
context
|
|
1202
|
-
|
|
1144
|
+
context 'when passing in a block' do
|
|
1203
1145
|
let!(:band1) { Band.create!(name: '1') }
|
|
1204
1146
|
let!(:band2) { Band.create!(name: '2') }
|
|
1205
1147
|
let!(:band3) { Band.create!(name: '2') }
|
|
1206
1148
|
|
|
1207
|
-
it
|
|
1149
|
+
it 'yields the documents to the block' do
|
|
1208
1150
|
doc = Band.find { |b| b.name == '2' }
|
|
1209
1151
|
expect(doc).to eq(band2)
|
|
1210
1152
|
end
|
|
1211
1153
|
end
|
|
1212
1154
|
|
|
1213
|
-
context
|
|
1214
|
-
|
|
1155
|
+
context 'when passing in ids and a block' do
|
|
1215
1156
|
let!(:band1) { Band.create!(name: '1') }
|
|
1216
1157
|
let!(:band2) { Band.create!(name: '2') }
|
|
1217
1158
|
let!(:band3) { Band.create!(name: '2') }
|
|
1218
1159
|
|
|
1219
|
-
it
|
|
1160
|
+
it 'acts like findable find' do
|
|
1220
1161
|
docs = Band.find(band1.id, band2.id) { |b| b.name == '2' }
|
|
1221
1162
|
expect(docs).to eq([ band1, band2 ])
|
|
1222
1163
|
end
|
|
1223
1164
|
end
|
|
1224
1165
|
|
|
1225
|
-
context
|
|
1226
|
-
|
|
1166
|
+
context 'when passing in a Proc and a block' do
|
|
1227
1167
|
let!(:band1) { Band.create!(name: '1') }
|
|
1228
1168
|
let!(:band2) { Band.create!(name: '2') }
|
|
1229
1169
|
let!(:band3) { Band.create!(name: '2') }
|
|
1230
1170
|
|
|
1231
|
-
it
|
|
1171
|
+
it 'acts like findable find' do
|
|
1232
1172
|
docs = Band.find(-> { 'default' }) { |b| b.name == '3' }
|
|
1233
1173
|
expect(docs).to eq('default')
|
|
1234
1174
|
end
|
|
1235
1175
|
end
|
|
1236
1176
|
end
|
|
1237
1177
|
|
|
1238
|
-
describe
|
|
1239
|
-
|
|
1240
|
-
context "when only 1 id exists" do
|
|
1241
|
-
|
|
1178
|
+
describe '#for_ids' do
|
|
1179
|
+
context 'when only 1 id exists' do
|
|
1242
1180
|
let(:id) do
|
|
1243
1181
|
BSON::ObjectId.new
|
|
1244
1182
|
end
|
|
@@ -1247,24 +1185,22 @@ describe Mongoid::Criteria::Findable do
|
|
|
1247
1185
|
Band.queryable.for_ids([ id ])
|
|
1248
1186
|
end
|
|
1249
1187
|
|
|
1250
|
-
it
|
|
1251
|
-
expect(criteria.selector).to eq({
|
|
1188
|
+
it 'does not turn the selector into an $in' do
|
|
1189
|
+
expect(criteria.selector).to eq({ '_id' => id })
|
|
1252
1190
|
end
|
|
1253
1191
|
end
|
|
1254
1192
|
end
|
|
1255
1193
|
|
|
1256
|
-
describe
|
|
1257
|
-
|
|
1194
|
+
describe '#multiple_from__db' do
|
|
1258
1195
|
let!(:band) do
|
|
1259
|
-
Band.create!(name:
|
|
1196
|
+
Band.create!(name: 'Depeche Mode')
|
|
1260
1197
|
end
|
|
1261
1198
|
|
|
1262
1199
|
let!(:band_two) do
|
|
1263
|
-
Band.create!(name:
|
|
1200
|
+
Band.create!(name: 'Tool')
|
|
1264
1201
|
end
|
|
1265
1202
|
|
|
1266
|
-
context
|
|
1267
|
-
|
|
1203
|
+
context 'when providing a single id' do
|
|
1268
1204
|
let(:criteria) do
|
|
1269
1205
|
Band.where(_id: band.id)
|
|
1270
1206
|
end
|
|
@@ -1273,17 +1209,16 @@ describe Mongoid::Criteria::Findable do
|
|
|
1273
1209
|
criteria.multiple_from_db([ band.id ])
|
|
1274
1210
|
end
|
|
1275
1211
|
|
|
1276
|
-
it
|
|
1277
|
-
expect(from_db.first).
|
|
1212
|
+
it 'returns the document from the database' do
|
|
1213
|
+
expect(from_db.first).not_to equal(band)
|
|
1278
1214
|
end
|
|
1279
1215
|
|
|
1280
|
-
it
|
|
1216
|
+
it 'returns the correct document' do
|
|
1281
1217
|
expect(from_db.first).to eq(band)
|
|
1282
1218
|
end
|
|
1283
1219
|
end
|
|
1284
1220
|
|
|
1285
|
-
context
|
|
1286
|
-
|
|
1221
|
+
context 'when providing multiple ids' do
|
|
1287
1222
|
let(:criteria) do
|
|
1288
1223
|
Band.where(:_id.in => [ band.id, band_two.id ])
|
|
1289
1224
|
end
|
|
@@ -1292,11 +1227,11 @@ describe Mongoid::Criteria::Findable do
|
|
|
1292
1227
|
criteria.multiple_from_db([ band.id, band_two.id ])
|
|
1293
1228
|
end
|
|
1294
1229
|
|
|
1295
|
-
it
|
|
1296
|
-
expect(from_db.first).
|
|
1230
|
+
it 'returns the document from the database' do
|
|
1231
|
+
expect(from_db.first).not_to equal(band)
|
|
1297
1232
|
end
|
|
1298
1233
|
|
|
1299
|
-
it
|
|
1234
|
+
it 'returns the correct document' do
|
|
1300
1235
|
expect(from_db.first).to eq(band)
|
|
1301
1236
|
end
|
|
1302
1237
|
end
|
|
@@ -1304,7 +1239,7 @@ describe Mongoid::Criteria::Findable do
|
|
|
1304
1239
|
|
|
1305
1240
|
describe '#from_database_selector' do
|
|
1306
1241
|
let(:criteria) { Mongoid::Criteria.new(Band) }
|
|
1307
|
-
let(:result) { criteria.send(:from_database_selector, [1]) }
|
|
1242
|
+
let(:result) { criteria.send(:from_database_selector, [ 1 ]) }
|
|
1308
1243
|
|
|
1309
1244
|
context 'when criteria is empty' do
|
|
1310
1245
|
it 'adds id' do
|
|
@@ -1316,7 +1251,7 @@ describe Mongoid::Criteria::Findable do
|
|
|
1316
1251
|
let(:criteria) { Mongoid::Criteria.new(Band).where(id: 2) }
|
|
1317
1252
|
|
|
1318
1253
|
it 'adds id' do
|
|
1319
|
-
expect(result.selector).to eq('_id' => 2, '$and' => [{'_id' => 1}])
|
|
1254
|
+
expect(result.selector).to eq('_id' => 2, '$and' => [ { '_id' => 1 } ])
|
|
1320
1255
|
end
|
|
1321
1256
|
end
|
|
1322
1257
|
end
|