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,36 +1,30 @@
|
|
|
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::Queryable::Selectable do
|
|
7
|
-
|
|
8
6
|
let(:query) do
|
|
9
|
-
Mongoid::Query.new(
|
|
7
|
+
Mongoid::Query.new('id' => '_id')
|
|
10
8
|
end
|
|
11
9
|
|
|
12
10
|
shared_examples_for 'returns a cloned query' do
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
expect(selection).to_not equal(query)
|
|
11
|
+
it 'returns a cloned query' do
|
|
12
|
+
expect(selection).not_to equal(query)
|
|
16
13
|
end
|
|
17
14
|
end
|
|
18
15
|
|
|
19
16
|
# Hoisting means the operator can be elided, for example
|
|
20
17
|
# Foo.and(a: 1) produces simply {'a' => 1}.
|
|
21
18
|
shared_examples_for 'a hoisting logical operation' do
|
|
22
|
-
|
|
23
19
|
let(:query) do
|
|
24
20
|
Mongoid::Query.new
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
context
|
|
28
|
-
|
|
23
|
+
context 'when provided a single criterion' do
|
|
29
24
|
shared_examples_for 'adds the conditions to top level' do
|
|
30
|
-
|
|
31
|
-
it "adds the conditions to top level" do
|
|
25
|
+
it 'adds the conditions to top level' do
|
|
32
26
|
expect(selection.selector).to eq(
|
|
33
|
-
|
|
27
|
+
'field' => [ 1, 2 ]
|
|
34
28
|
)
|
|
35
29
|
end
|
|
36
30
|
|
|
@@ -45,7 +39,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
45
39
|
|
|
46
40
|
context 'when the criterion is wrapped in an array' do
|
|
47
41
|
let(:selection) do
|
|
48
|
-
query.send(tested_method, [{field: [ 1, 2 ] }])
|
|
42
|
+
query.send(tested_method, [ { field: [ 1, 2 ] } ])
|
|
49
43
|
end
|
|
50
44
|
|
|
51
45
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -53,7 +47,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
53
47
|
|
|
54
48
|
context 'when the criterion is wrapped in a deep array with nil elements' do
|
|
55
49
|
let(:selection) do
|
|
56
|
-
query.send(tested_method, [[[{field: [ 1, 2 ] }]], [nil]])
|
|
50
|
+
query.send(tested_method, [ [ [ { field: [ 1, 2 ] } ] ], [ nil ] ])
|
|
57
51
|
end
|
|
58
52
|
|
|
59
53
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -74,19 +68,15 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
74
68
|
it 'combines' do
|
|
75
69
|
expect(result.selector).to eq(
|
|
76
70
|
'hello' => 'world',
|
|
77
|
-
'foo' => 'bar'
|
|
71
|
+
'foo' => 'bar'
|
|
78
72
|
)
|
|
79
73
|
end
|
|
80
74
|
end
|
|
81
75
|
|
|
82
|
-
context
|
|
83
|
-
|
|
76
|
+
context 'when provided a single criterion that is handled via Key' do
|
|
84
77
|
shared_examples_for 'adds the conditions to top level' do
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
expect(selection.selector).to eq({
|
|
88
|
-
"field" => {'$gt' => 3},
|
|
89
|
-
})
|
|
78
|
+
it 'adds the conditions to top level' do
|
|
79
|
+
expect(selection.selector).to eq({ 'field' => { '$gt' => 3 } })
|
|
90
80
|
end
|
|
91
81
|
|
|
92
82
|
it_behaves_like 'returns a cloned query'
|
|
@@ -100,7 +90,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
100
90
|
|
|
101
91
|
context 'when the criterion is wrapped in an array' do
|
|
102
92
|
let(:selection) do
|
|
103
|
-
query.send(tested_method, [{ :field.gt => 3 }])
|
|
93
|
+
query.send(tested_method, [ { :field.gt => 3 } ])
|
|
104
94
|
end
|
|
105
95
|
|
|
106
96
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -108,7 +98,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
108
98
|
|
|
109
99
|
context 'when the criterion is wrapped in a deep array with nil elements' do
|
|
110
100
|
let(:selection) do
|
|
111
|
-
query.send(tested_method, [[[{ :field.gt => 3 }]], [nil]])
|
|
101
|
+
query.send(tested_method, [ [ [ { :field.gt => 3 } ] ], [ nil ] ])
|
|
112
102
|
end
|
|
113
103
|
|
|
114
104
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -120,9 +110,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
120
110
|
end
|
|
121
111
|
|
|
122
112
|
it 'adds the conditions' do
|
|
123
|
-
expect(selection.selector).to eq({
|
|
124
|
-
"field" => {'$gte' => Time.new(2020, 1, 1)},
|
|
125
|
-
})
|
|
113
|
+
expect(selection.selector).to eq({ 'field' => { '$gte' => Time.new(2020, 1, 1) } })
|
|
126
114
|
end
|
|
127
115
|
|
|
128
116
|
it 'keeps argument type' do
|
|
@@ -136,9 +124,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
136
124
|
end
|
|
137
125
|
|
|
138
126
|
it 'adds the conditions' do
|
|
139
|
-
expect(selection.selector).to eq({
|
|
140
|
-
"field" => {'$gte' => Time.utc(2020, 1, 1)},
|
|
141
|
-
})
|
|
127
|
+
expect(selection.selector).to eq({ 'field' => { '$gte' => Time.utc(2020, 1, 1) } })
|
|
142
128
|
end
|
|
143
129
|
|
|
144
130
|
it 'converts argument to a time' do
|
|
@@ -152,9 +138,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
152
138
|
end
|
|
153
139
|
|
|
154
140
|
it 'adds the conditions' do
|
|
155
|
-
expect(selection.selector).to eq({
|
|
156
|
-
"field" => {'$gte' => Time.utc(2020, 1, 1)},
|
|
157
|
-
})
|
|
141
|
+
expect(selection.selector).to eq({ 'field' => { '$gte' => Time.utc(2020, 1, 1) } })
|
|
158
142
|
end
|
|
159
143
|
|
|
160
144
|
it 'converts argument to a time' do
|
|
@@ -163,52 +147,38 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
163
147
|
end
|
|
164
148
|
end
|
|
165
149
|
|
|
166
|
-
context
|
|
167
|
-
|
|
150
|
+
context 'when provided a nested criterion' do
|
|
168
151
|
let(:selection) do
|
|
169
152
|
query.send(tested_method, :test.elem_match => { :field.in => [ 1, 2 ] })
|
|
170
153
|
end
|
|
171
154
|
|
|
172
|
-
it
|
|
173
|
-
expect(selection.selector).to eq({
|
|
174
|
-
"test" => { "$elemMatch" => { "field" => { "$in" => [ 1, 2 ] }}}
|
|
175
|
-
})
|
|
155
|
+
it 'builds the correct selector' do
|
|
156
|
+
expect(selection.selector).to eq({ 'test' => { '$elemMatch' => { 'field' => { '$in' => [ 1, 2 ] } } } })
|
|
176
157
|
end
|
|
177
158
|
|
|
178
159
|
it_behaves_like 'returns a cloned query'
|
|
179
160
|
end
|
|
180
161
|
|
|
181
|
-
context
|
|
182
|
-
|
|
183
|
-
context "when the criteria are for different fields" do
|
|
184
|
-
|
|
162
|
+
context 'when chaining the criteria' do
|
|
163
|
+
context 'when the criteria are for different fields' do
|
|
185
164
|
let(:selection) do
|
|
186
165
|
query.and(first: [ 1, 2 ]).send(tested_method, second: [ 3, 4 ])
|
|
187
166
|
end
|
|
188
167
|
|
|
189
|
-
it
|
|
190
|
-
expect(selection.selector).to eq({
|
|
191
|
-
"first" => [ 1, 2 ],
|
|
192
|
-
"second" => [ 3, 4 ],
|
|
193
|
-
})
|
|
168
|
+
it 'adds the conditions to top level' do
|
|
169
|
+
expect(selection.selector).to eq({ 'first' => [ 1, 2 ], 'second' => [ 3, 4 ] })
|
|
194
170
|
end
|
|
195
171
|
|
|
196
172
|
it_behaves_like 'returns a cloned query'
|
|
197
173
|
end
|
|
198
174
|
|
|
199
|
-
context
|
|
200
|
-
|
|
175
|
+
context 'when the criteria are on the same field' do
|
|
201
176
|
let(:selection) do
|
|
202
177
|
query.and(first: [ 1, 2 ]).send(tested_method, first: [ 3, 4 ])
|
|
203
178
|
end
|
|
204
179
|
|
|
205
|
-
it
|
|
206
|
-
expect(selection.selector).to eq({
|
|
207
|
-
"first" => [ 1, 2 ],
|
|
208
|
-
"$and" => [
|
|
209
|
-
{ "first" => [ 3, 4 ] }
|
|
210
|
-
]
|
|
211
|
-
})
|
|
180
|
+
it 'combines via $and operator' do
|
|
181
|
+
expect(selection.selector).to eq({ 'first' => [ 1, 2 ], '$and' => [ { 'first' => [ 3, 4 ] } ] })
|
|
212
182
|
end
|
|
213
183
|
|
|
214
184
|
it_behaves_like 'returns a cloned query'
|
|
@@ -219,24 +189,23 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
219
189
|
# Non-hoisting means the operator is always present, for example
|
|
220
190
|
# Foo.or(a: 1) produces {'$or' => [{'a' => 1}]}.
|
|
221
191
|
shared_examples_for 'a non-hoisting logical operation' do
|
|
222
|
-
|
|
223
192
|
context 'when there is a single predicate' do
|
|
224
193
|
let(:query) do
|
|
225
194
|
Mongoid::Query.new.send(tested_method, hello: 'world')
|
|
226
195
|
end
|
|
227
196
|
|
|
228
197
|
it 'adds the predicate' do
|
|
229
|
-
expect(query.selector).to eq(expected_operator => [{'hello' => 'world'}])
|
|
198
|
+
expect(query.selector).to eq(expected_operator => [ { 'hello' => 'world' } ])
|
|
230
199
|
end
|
|
231
200
|
end
|
|
232
201
|
|
|
233
202
|
context 'when the single predicate is wrapped in an array' do
|
|
234
203
|
let(:query) do
|
|
235
|
-
Mongoid::Query.new.send(tested_method, [{hello: 'world'}])
|
|
204
|
+
Mongoid::Query.new.send(tested_method, [ { hello: 'world' } ])
|
|
236
205
|
end
|
|
237
206
|
|
|
238
207
|
it 'adds the predicate' do
|
|
239
|
-
expect(query.selector).to eq(expected_operator => [{'hello' => 'world'}])
|
|
208
|
+
expect(query.selector).to eq(expected_operator => [ { 'hello' => 'world' } ])
|
|
240
209
|
end
|
|
241
210
|
end
|
|
242
211
|
|
|
@@ -254,7 +223,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
254
223
|
it 'combines' do
|
|
255
224
|
# This is used for $or / $nor, the two conditions should remain
|
|
256
225
|
# as separate hashes
|
|
257
|
-
expect(result.selector).to eq(expected_operator => [{'hello' => 'world'}, {'foo' => 'bar'}])
|
|
226
|
+
expect(result.selector).to eq(expected_operator => [ { 'hello' => 'world' }, { 'foo' => 'bar' } ])
|
|
258
227
|
end
|
|
259
228
|
end
|
|
260
229
|
|
|
@@ -268,7 +237,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
268
237
|
end
|
|
269
238
|
|
|
270
239
|
let(:other2) do
|
|
271
|
-
{bar: 42}
|
|
240
|
+
{ bar: 42 }
|
|
272
241
|
end
|
|
273
242
|
|
|
274
243
|
let(:other3) do
|
|
@@ -279,72 +248,67 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
279
248
|
|
|
280
249
|
it 'combines' do
|
|
281
250
|
expect(result.selector).to eq(expected_operator => [
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
251
|
+
{ 'hello' => 'world' },
|
|
252
|
+
{ 'foo' => 'bar' },
|
|
253
|
+
{ 'bar' => 42 },
|
|
254
|
+
{ 'a' => 2 }
|
|
255
|
+
])
|
|
287
256
|
end
|
|
288
257
|
end
|
|
289
258
|
end
|
|
290
259
|
|
|
291
|
-
describe
|
|
292
|
-
|
|
260
|
+
describe '#and' do
|
|
293
261
|
let(:tested_method) { :and }
|
|
294
262
|
let(:expected_operator) { '$and' }
|
|
295
263
|
|
|
296
264
|
it_behaves_like 'a hoisting logical operation'
|
|
297
265
|
|
|
298
|
-
context
|
|
299
|
-
|
|
266
|
+
context 'when provided no criterion' do
|
|
300
267
|
let(:selection) do
|
|
301
268
|
query.and
|
|
302
269
|
end
|
|
303
270
|
|
|
304
|
-
it
|
|
271
|
+
it 'does not add any criterion' do
|
|
305
272
|
expect(selection.selector).to eq({})
|
|
306
273
|
end
|
|
307
274
|
|
|
308
|
-
it
|
|
275
|
+
it 'returns the query' do
|
|
309
276
|
expect(selection).to eq(query)
|
|
310
277
|
end
|
|
311
278
|
|
|
312
279
|
it_behaves_like 'returns a cloned query'
|
|
313
280
|
end
|
|
314
281
|
|
|
315
|
-
context
|
|
316
|
-
|
|
282
|
+
context 'when provided nil' do
|
|
317
283
|
let(:selection) do
|
|
318
284
|
query.and(nil)
|
|
319
285
|
end
|
|
320
286
|
|
|
321
|
-
it
|
|
287
|
+
it 'does not add any criterion' do
|
|
322
288
|
expect(selection.selector).to eq({})
|
|
323
289
|
end
|
|
324
290
|
|
|
325
|
-
it
|
|
291
|
+
it 'returns the query' do
|
|
326
292
|
expect(selection).to eq(query)
|
|
327
293
|
end
|
|
328
294
|
|
|
329
295
|
it_behaves_like 'returns a cloned query'
|
|
330
296
|
end
|
|
331
297
|
|
|
332
|
-
context
|
|
333
|
-
|
|
334
|
-
context "when the criterion is already included" do
|
|
335
|
-
|
|
298
|
+
context 'when provided multiple criteria' do
|
|
299
|
+
context 'when the criterion is already included' do
|
|
336
300
|
context 'simple criterion' do
|
|
337
301
|
let(:selection) do
|
|
338
302
|
query.and({ first: [ 1, 2 ] }).and({ first: [ 1, 2 ] })
|
|
339
303
|
end
|
|
340
304
|
|
|
341
|
-
it
|
|
305
|
+
it 'adds all conditions' do
|
|
342
306
|
expect(selection.selector).to eq({
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
307
|
+
'first' => [ 1, 2 ],
|
|
308
|
+
'$and' => [
|
|
309
|
+
{ 'first' => [ 1, 2 ] }
|
|
310
|
+
]
|
|
311
|
+
})
|
|
348
312
|
end
|
|
349
313
|
|
|
350
314
|
it_behaves_like 'returns a cloned query'
|
|
@@ -355,13 +319,13 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
355
319
|
query.and({ first: [ 1, 2 ] }).and(:first.gt => 3)
|
|
356
320
|
end
|
|
357
321
|
|
|
358
|
-
it
|
|
322
|
+
it 'adds all conditions' do
|
|
359
323
|
expect(selection.selector).to eq({
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
324
|
+
'first' => [ 1, 2 ],
|
|
325
|
+
'$and' => [
|
|
326
|
+
{ 'first' => { '$gt' => 3 } }
|
|
327
|
+
]
|
|
328
|
+
})
|
|
365
329
|
end
|
|
366
330
|
|
|
367
331
|
it_behaves_like 'returns a cloned query'
|
|
@@ -372,46 +336,44 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
372
336
|
query.and(:first.lt => 5).and(:first.gt => 3)
|
|
373
337
|
end
|
|
374
338
|
|
|
375
|
-
it
|
|
339
|
+
it 'adds all conditions' do
|
|
376
340
|
expect(selection.selector).to eq({
|
|
377
|
-
|
|
378
|
-
|
|
341
|
+
'first' => { '$lt' => 5, '$gt' => 3 }
|
|
342
|
+
})
|
|
379
343
|
end
|
|
380
344
|
|
|
381
345
|
it_behaves_like 'returns a cloned query'
|
|
382
346
|
end
|
|
383
347
|
end
|
|
384
348
|
|
|
385
|
-
context
|
|
386
|
-
|
|
349
|
+
context 'when the new criteria are for different fields' do
|
|
387
350
|
let(:selection) do
|
|
388
351
|
query.and({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
|
|
389
352
|
end
|
|
390
353
|
|
|
391
|
-
it
|
|
354
|
+
it 'adds all conditions to top level' do
|
|
392
355
|
expect(selection.selector).to eq({
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
356
|
+
'first' => [ 1, 2 ],
|
|
357
|
+
'second' => [ 3, 4 ]
|
|
358
|
+
})
|
|
396
359
|
end
|
|
397
360
|
|
|
398
361
|
it_behaves_like 'returns a cloned query'
|
|
399
362
|
end
|
|
400
363
|
|
|
401
|
-
context
|
|
402
|
-
|
|
364
|
+
context 'when the new criteria are for the same field' do
|
|
403
365
|
context 'when criteria are simple' do
|
|
404
366
|
let(:selection) do
|
|
405
367
|
query.and({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
|
|
406
368
|
end
|
|
407
369
|
|
|
408
|
-
it
|
|
370
|
+
it 'combines via $and operator' do
|
|
409
371
|
expect(selection.selector).to eq({
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
372
|
+
'first' => [ 1, 2 ],
|
|
373
|
+
'$and' => [
|
|
374
|
+
{ 'first' => [ 3, 4 ] }
|
|
375
|
+
]
|
|
376
|
+
})
|
|
415
377
|
end
|
|
416
378
|
|
|
417
379
|
it_behaves_like 'returns a cloned query'
|
|
@@ -421,26 +383,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
421
383
|
shared_examples 'behave correctly' do
|
|
422
384
|
let(:selection) do
|
|
423
385
|
query.and(
|
|
424
|
-
{ field: {first_operator => [ 1, 2 ] }},
|
|
425
|
-
{ field: {second_operator => [ 3, 4 ] }}
|
|
386
|
+
{ field: { first_operator => [ 1, 2 ] } },
|
|
387
|
+
{ field: { second_operator => [ 3, 4 ] } }
|
|
426
388
|
)
|
|
427
389
|
end
|
|
428
390
|
|
|
429
|
-
it
|
|
391
|
+
it 'combines via $and operator and stringifies all keys' do
|
|
430
392
|
expect(selection.selector).to eq({
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
393
|
+
'field' => { '$in' => [ 1, 2 ] },
|
|
394
|
+
'$and' => [
|
|
395
|
+
{ 'field' => { '$in' => [ 3, 4 ] } }
|
|
396
|
+
]
|
|
397
|
+
})
|
|
436
398
|
end
|
|
437
399
|
end
|
|
438
400
|
|
|
439
401
|
[
|
|
440
|
-
['$in', '$in'],
|
|
441
|
-
[:$in, '$in'],
|
|
442
|
-
['$in', :$in],
|
|
443
|
-
[
|
|
402
|
+
[ '$in', '$in' ],
|
|
403
|
+
[ :$in, '$in' ],
|
|
404
|
+
[ '$in', :$in ],
|
|
405
|
+
%i[$in $in]
|
|
444
406
|
].each do |first_operator, second_operator|
|
|
445
407
|
context "when first operator is #{first_operator.inspect} and second operator is #{second_operator.inspect}" do
|
|
446
408
|
let(:first_operator) { first_operator }
|
|
@@ -453,11 +415,10 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
453
415
|
|
|
454
416
|
context 'when criteria are handled via Key' do
|
|
455
417
|
shared_examples_for 'adds the conditions to top level' do
|
|
456
|
-
|
|
457
|
-
it "adds the conditions to top level" do
|
|
418
|
+
it 'adds the conditions to top level' do
|
|
458
419
|
expect(selection.selector).to eq({
|
|
459
|
-
|
|
460
|
-
|
|
420
|
+
'field' => { '$gt' => 3, '$lt' => 5 }
|
|
421
|
+
})
|
|
461
422
|
end
|
|
462
423
|
|
|
463
424
|
it_behaves_like 'returns a cloned query'
|
|
@@ -473,7 +434,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
473
434
|
|
|
474
435
|
context 'criteria are provided in separate hashes' do
|
|
475
436
|
let(:selection) do
|
|
476
|
-
query.send(tested_method, {:field.gt => 3}, {:field.lt => 5})
|
|
437
|
+
query.send(tested_method, { :field.gt => 3 }, { :field.lt => 5 })
|
|
477
438
|
end
|
|
478
439
|
|
|
479
440
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -481,7 +442,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
481
442
|
|
|
482
443
|
context 'when the criterion is wrapped in an array' do
|
|
483
444
|
let(:selection) do
|
|
484
|
-
query.send(tested_method, [:field.gt => 3], [:field.lt => 5])
|
|
445
|
+
query.send(tested_method, [ { :field.gt => 3 } ], [ { :field.lt => 5 } ])
|
|
485
446
|
end
|
|
486
447
|
|
|
487
448
|
it_behaves_like 'adds the conditions to top level'
|
|
@@ -490,34 +451,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
490
451
|
|
|
491
452
|
context 'when criteria are simple and handled via Key' do
|
|
492
453
|
shared_examples_for 'combines conditions with $and' do
|
|
493
|
-
|
|
494
|
-
it "combines conditions with $and" do
|
|
454
|
+
it 'combines conditions with $and' do
|
|
495
455
|
expect(selection.selector).to eq({
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
456
|
+
'field' => 3,
|
|
457
|
+
'$and' => [ { 'field' => { '$lt' => 5 } } ]
|
|
458
|
+
})
|
|
499
459
|
end
|
|
500
460
|
|
|
501
461
|
it_behaves_like 'returns a cloned query'
|
|
502
462
|
end
|
|
503
463
|
|
|
504
464
|
shared_examples_for 'combines conditions with $eq' do
|
|
505
|
-
|
|
506
|
-
it "combines conditions with $eq" do
|
|
465
|
+
it 'combines conditions with $eq' do
|
|
507
466
|
expect(selection.selector).to eq({
|
|
508
|
-
|
|
509
|
-
|
|
467
|
+
'field' => { '$eq' => 3, '$lt' => 5 }
|
|
468
|
+
})
|
|
510
469
|
end
|
|
511
470
|
|
|
512
471
|
it_behaves_like 'returns a cloned query'
|
|
513
472
|
end
|
|
514
473
|
|
|
515
474
|
shared_examples_for 'combines conditions with $regex' do
|
|
516
|
-
|
|
517
|
-
it "combines conditions with $regex" do
|
|
475
|
+
it 'combines conditions with $regex' do
|
|
518
476
|
expect(selection.selector).to eq({
|
|
519
|
-
|
|
520
|
-
|
|
477
|
+
'field' => { '$regex' => /t/, '$lt' => 5 }
|
|
478
|
+
})
|
|
521
479
|
end
|
|
522
480
|
|
|
523
481
|
it_behaves_like 'returns a cloned query'
|
|
@@ -543,7 +501,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
543
501
|
|
|
544
502
|
context 'criteria are provided in separate hashes' do
|
|
545
503
|
let(:selection) do
|
|
546
|
-
query.send(tested_method, {:
|
|
504
|
+
query.send(tested_method, { field: 3 }, { :field.lt => 5 })
|
|
547
505
|
end
|
|
548
506
|
|
|
549
507
|
it_behaves_like 'combines conditions with $and'
|
|
@@ -551,7 +509,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
551
509
|
|
|
552
510
|
context 'when the criterion is wrapped in an array' do
|
|
553
511
|
let(:selection) do
|
|
554
|
-
query.send(tested_method, [:
|
|
512
|
+
query.send(tested_method, [ { field: 3 } ], [ { :field.lt => 5 } ])
|
|
555
513
|
end
|
|
556
514
|
|
|
557
515
|
it_behaves_like 'combines conditions with $and'
|
|
@@ -560,34 +518,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
560
518
|
|
|
561
519
|
context 'when criteria are handled via Key and simple' do
|
|
562
520
|
shared_examples_for 'combines conditions with $and' do
|
|
563
|
-
|
|
564
|
-
it "combines conditions with $and" do
|
|
521
|
+
it 'combines conditions with $and' do
|
|
565
522
|
expect(selection.selector).to eq({
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
523
|
+
'field' => { '$gt' => 3 },
|
|
524
|
+
'$and' => [ { 'field' => 5 } ]
|
|
525
|
+
})
|
|
569
526
|
end
|
|
570
527
|
|
|
571
528
|
it_behaves_like 'returns a cloned query'
|
|
572
529
|
end
|
|
573
530
|
|
|
574
531
|
shared_examples_for 'combines conditions with $eq' do
|
|
575
|
-
|
|
576
|
-
it "combines conditions with $eq" do
|
|
532
|
+
it 'combines conditions with $eq' do
|
|
577
533
|
expect(selection.selector).to eq({
|
|
578
|
-
|
|
579
|
-
|
|
534
|
+
'field' => { '$gt' => 3, '$eq' => 5 }
|
|
535
|
+
})
|
|
580
536
|
end
|
|
581
537
|
|
|
582
538
|
it_behaves_like 'returns a cloned query'
|
|
583
539
|
end
|
|
584
540
|
|
|
585
541
|
shared_examples_for 'combines conditions with $regex' do
|
|
586
|
-
|
|
587
|
-
it "combines conditions with $regex" do
|
|
542
|
+
it 'combines conditions with $regex' do
|
|
588
543
|
expect(selection.selector).to eq({
|
|
589
|
-
|
|
590
|
-
|
|
544
|
+
'field' => { '$gt' => 3, '$regex' => /t/ }
|
|
545
|
+
})
|
|
591
546
|
end
|
|
592
547
|
|
|
593
548
|
it_behaves_like 'returns a cloned query'
|
|
@@ -613,7 +568,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
613
568
|
|
|
614
569
|
context 'criteria are provided in separate hashes' do
|
|
615
570
|
let(:selection) do
|
|
616
|
-
query.send(tested_method, {:field.gt => 3}, {:
|
|
571
|
+
query.send(tested_method, { :field.gt => 3 }, { field: 5 })
|
|
617
572
|
end
|
|
618
573
|
|
|
619
574
|
it_behaves_like 'combines conditions with $and'
|
|
@@ -621,7 +576,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
621
576
|
|
|
622
577
|
context 'when the criterion is wrapped in an array' do
|
|
623
578
|
let(:selection) do
|
|
624
|
-
query.send(tested_method, [:field.gt => 3], [:
|
|
579
|
+
query.send(tested_method, [ { :field.gt => 3 } ], [ { field: 5 } ])
|
|
625
580
|
end
|
|
626
581
|
|
|
627
582
|
it_behaves_like 'combines conditions with $and'
|
|
@@ -638,7 +593,6 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
638
593
|
let(:result) { query.and(other) }
|
|
639
594
|
|
|
640
595
|
context 'different fields' do
|
|
641
|
-
|
|
642
596
|
let(:other) do
|
|
643
597
|
Mongoid::Query.new.where(foo: 'bar')
|
|
644
598
|
end
|
|
@@ -649,13 +603,12 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
649
603
|
end
|
|
650
604
|
|
|
651
605
|
context 'same field' do
|
|
652
|
-
|
|
653
606
|
let(:other) do
|
|
654
607
|
Mongoid::Query.new.where(hello: /bar/)
|
|
655
608
|
end
|
|
656
609
|
|
|
657
610
|
it 'combines fields with $and' do
|
|
658
|
-
expect(result.selector).to eq('hello' => 'world', '$and' => [{'hello' => /bar/}])
|
|
611
|
+
expect(result.selector).to eq('hello' => 'world', '$and' => [ { 'hello' => /bar/ } ])
|
|
659
612
|
end
|
|
660
613
|
end
|
|
661
614
|
end
|
|
@@ -670,7 +623,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
670
623
|
end
|
|
671
624
|
|
|
672
625
|
let(:other2) do
|
|
673
|
-
{bar: 42}
|
|
626
|
+
{ bar: 42 }
|
|
674
627
|
end
|
|
675
628
|
|
|
676
629
|
let(:other3) do
|
|
@@ -681,10 +634,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
681
634
|
|
|
682
635
|
it 'combines' do
|
|
683
636
|
expect(result.selector).to eq('hello' => 'world',
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
)
|
|
637
|
+
'foo' => 'bar',
|
|
638
|
+
'bar' => 42,
|
|
639
|
+
'a' => 2)
|
|
688
640
|
end
|
|
689
641
|
end
|
|
690
642
|
|
|
@@ -696,7 +648,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
696
648
|
end
|
|
697
649
|
|
|
698
650
|
let(:expected) do
|
|
699
|
-
{'created_at' => {'$gt' => time.utc}}
|
|
651
|
+
{ 'created_at' => { '$gt' => time.utc } }
|
|
700
652
|
end
|
|
701
653
|
|
|
702
654
|
it 'combines and evolves' do
|
|
@@ -709,7 +661,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
709
661
|
let(:selector) { scope.selector }
|
|
710
662
|
|
|
711
663
|
it 'adds most recent criterion as $and' do
|
|
712
|
-
expect(selector).to eq('foo' => 1, '$and' => [{'foo' => 2}])
|
|
664
|
+
expect(selector).to eq('foo' => 1, '$and' => [ { 'foo' => 2 } ])
|
|
713
665
|
end
|
|
714
666
|
end
|
|
715
667
|
|
|
@@ -765,10 +717,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
765
717
|
end
|
|
766
718
|
|
|
767
719
|
it 'adds new conditions to top level' do
|
|
768
|
-
selection.selector.should
|
|
769
|
-
'foo' => 'bar',
|
|
770
|
-
'hello' => 'world',
|
|
771
|
-
}
|
|
720
|
+
selection.selector.should eq({ 'foo' => 'bar', 'hello' => 'world' })
|
|
772
721
|
end
|
|
773
722
|
end
|
|
774
723
|
|
|
@@ -778,128 +727,117 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
778
727
|
end
|
|
779
728
|
|
|
780
729
|
it 'adds new conditions to top level' do
|
|
781
|
-
selection.selector.should
|
|
782
|
-
'foo' => 'bar',
|
|
783
|
-
'hello' => 'world',
|
|
784
|
-
}
|
|
730
|
+
selection.selector.should eq({ 'foo' => 'bar', 'hello' => 'world' })
|
|
785
731
|
end
|
|
786
732
|
end
|
|
787
733
|
|
|
788
734
|
context 'when complex criteria conditions are given' do
|
|
789
735
|
let(:selection) do
|
|
790
|
-
base_selection.and(query.or([one: 'one'], [two: 'two']))
|
|
736
|
+
base_selection.and(query.or([ { one: 'one' } ], [ { two: 'two' } ]))
|
|
791
737
|
end
|
|
792
738
|
|
|
793
739
|
it 'adds new conditions to top level' do
|
|
794
|
-
selection.selector.should
|
|
795
|
-
'foo' => 'bar',
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
740
|
+
selection.selector.should eq(
|
|
741
|
+
{ 'foo' => 'bar',
|
|
742
|
+
'$or' => [
|
|
743
|
+
{ 'one' => 'one' },
|
|
744
|
+
{ 'two' => 'two' }
|
|
745
|
+
] }
|
|
746
|
+
)
|
|
801
747
|
end
|
|
802
748
|
end
|
|
803
749
|
end
|
|
804
750
|
end
|
|
805
751
|
|
|
806
752
|
shared_examples '$or/$nor' do
|
|
807
|
-
|
|
808
753
|
it_behaves_like 'a non-hoisting logical operation'
|
|
809
754
|
|
|
810
|
-
context
|
|
811
|
-
|
|
755
|
+
context 'when provided no arguments' do
|
|
812
756
|
let(:selection) do
|
|
813
757
|
query.send(tested_method)
|
|
814
758
|
end
|
|
815
759
|
|
|
816
760
|
it_behaves_like 'returns a cloned query'
|
|
817
761
|
|
|
818
|
-
it
|
|
762
|
+
it 'does not add any criteria' do
|
|
819
763
|
expect(selection.selector).to eq({})
|
|
820
764
|
end
|
|
821
765
|
|
|
822
|
-
it
|
|
766
|
+
it 'returns the query' do
|
|
823
767
|
expect(selection).to eq(query)
|
|
824
768
|
end
|
|
825
769
|
end
|
|
826
770
|
|
|
827
|
-
context
|
|
828
|
-
|
|
771
|
+
context 'when provided nil' do
|
|
829
772
|
let(:selection) do
|
|
830
773
|
query.send(tested_method, nil)
|
|
831
774
|
end
|
|
832
775
|
|
|
833
776
|
it_behaves_like 'returns a cloned query'
|
|
834
777
|
|
|
835
|
-
it
|
|
778
|
+
it 'does not add any criteria' do
|
|
836
779
|
expect(selection.selector).to eq({})
|
|
837
780
|
end
|
|
838
781
|
|
|
839
|
-
it
|
|
782
|
+
it 'returns the query' do
|
|
840
783
|
expect(selection).to eq(query)
|
|
841
784
|
end
|
|
842
785
|
end
|
|
843
786
|
|
|
844
|
-
context
|
|
845
|
-
|
|
787
|
+
context 'when provided a single criterion' do
|
|
846
788
|
let(:selection) do
|
|
847
789
|
query.send(tested_method, field: [ 1, 2 ])
|
|
848
790
|
end
|
|
849
791
|
|
|
850
792
|
it_behaves_like 'returns a cloned query'
|
|
851
793
|
|
|
852
|
-
it
|
|
794
|
+
it 'adds the $or/$nor selector' do
|
|
853
795
|
expect(selection.selector).to eq({
|
|
854
|
-
|
|
855
|
-
|
|
796
|
+
expected_operator => [ { 'field' => [ 1, 2 ] } ]
|
|
797
|
+
})
|
|
856
798
|
end
|
|
857
799
|
|
|
858
800
|
context 'when the criterion is wrapped in array' do
|
|
859
|
-
|
|
860
801
|
let(:selection) do
|
|
861
|
-
query.send(tested_method, [{ field: [ 1, 2 ] }])
|
|
802
|
+
query.send(tested_method, [ { field: [ 1, 2 ] } ])
|
|
862
803
|
end
|
|
863
804
|
|
|
864
805
|
it_behaves_like 'returns a cloned query'
|
|
865
806
|
|
|
866
|
-
it
|
|
807
|
+
it 'adds the $or/$nor selector' do
|
|
867
808
|
expect(selection.selector).to eq({
|
|
868
|
-
|
|
869
|
-
|
|
809
|
+
expected_operator => [ { 'field' => [ 1, 2 ] } ]
|
|
810
|
+
})
|
|
870
811
|
end
|
|
871
812
|
|
|
872
813
|
context 'when the array has nil as one of the elements' do
|
|
873
|
-
|
|
874
814
|
let(:selection) do
|
|
875
|
-
query.send(tested_method, [{ field: [ 1, 2 ] }, nil])
|
|
815
|
+
query.send(tested_method, [ { field: [ 1, 2 ] }, nil ])
|
|
876
816
|
end
|
|
877
817
|
|
|
878
818
|
it_behaves_like 'returns a cloned query'
|
|
879
819
|
|
|
880
|
-
it
|
|
820
|
+
it 'adds the $or/$nor selector ignoring the nil element' do
|
|
881
821
|
expect(selection.selector).to eq({
|
|
882
|
-
|
|
883
|
-
|
|
822
|
+
expected_operator => [ { 'field' => [ 1, 2 ] } ]
|
|
823
|
+
})
|
|
884
824
|
end
|
|
885
825
|
end
|
|
886
826
|
end
|
|
887
827
|
|
|
888
828
|
context 'when query already has a condition on another field' do
|
|
889
|
-
|
|
890
829
|
let(:selection) do
|
|
891
830
|
query.where(foo: 'bar').send(tested_method, field: [ 1, 2 ])
|
|
892
831
|
end
|
|
893
832
|
|
|
894
833
|
it 'moves original conditions under $or/$nor' do
|
|
895
834
|
expect(selection.selector).to eq({
|
|
896
|
-
|
|
897
|
-
|
|
835
|
+
expected_operator => [ { 'foo' => 'bar' }, { 'field' => [ 1, 2 ] } ]
|
|
836
|
+
})
|
|
898
837
|
end
|
|
899
838
|
end
|
|
900
839
|
|
|
901
840
|
context 'when query already has an $or/$nor condition and another condition' do
|
|
902
|
-
|
|
903
841
|
let(:selection) do
|
|
904
842
|
query.send(tested_method, field: [ 1, 2 ]).where(foo: 'bar').send(tested_method, test: 1)
|
|
905
843
|
end
|
|
@@ -908,49 +846,46 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
908
846
|
expect(selection.selector).to eq(
|
|
909
847
|
expected_operator => [
|
|
910
848
|
{
|
|
911
|
-
expected_operator => [{
|
|
912
|
-
'foo' => 'bar'
|
|
849
|
+
expected_operator => [ { 'field' => [ 1, 2 ] } ],
|
|
850
|
+
'foo' => 'bar'
|
|
913
851
|
},
|
|
914
|
-
{'test' => 1}
|
|
852
|
+
{ 'test' => 1 }
|
|
915
853
|
]
|
|
916
854
|
)
|
|
917
855
|
end
|
|
918
856
|
end
|
|
919
857
|
end
|
|
920
858
|
|
|
921
|
-
context
|
|
922
|
-
|
|
923
|
-
context "when the criteria are for different fields" do
|
|
924
|
-
|
|
859
|
+
context 'when provided multiple criteria' do
|
|
860
|
+
context 'when the criteria are for different fields' do
|
|
925
861
|
let(:selection) do
|
|
926
862
|
query.send(tested_method, { first: [ 1, 2 ] }, { second: [ 3, 4 ] })
|
|
927
863
|
end
|
|
928
864
|
|
|
929
865
|
it_behaves_like 'returns a cloned query'
|
|
930
866
|
|
|
931
|
-
it
|
|
867
|
+
it 'adds the $or/$nor selector' do
|
|
932
868
|
expect(selection.selector).to eq({
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
869
|
+
expected_operator => [
|
|
870
|
+
{ 'first' => [ 1, 2 ] },
|
|
871
|
+
{ 'second' => [ 3, 4 ] }
|
|
872
|
+
]
|
|
873
|
+
})
|
|
938
874
|
end
|
|
939
875
|
end
|
|
940
876
|
|
|
941
|
-
context
|
|
942
|
-
|
|
877
|
+
context 'when the criteria uses a Key instance' do
|
|
943
878
|
let(:selection) do
|
|
944
879
|
query.send(tested_method, { first: [ 1, 2 ] }, { :second.gt => 3 })
|
|
945
880
|
end
|
|
946
881
|
|
|
947
|
-
it
|
|
882
|
+
it 'adds the $or/$nor selector' do
|
|
948
883
|
expect(selection.selector).to eq({
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
884
|
+
expected_operator => [
|
|
885
|
+
{ 'first' => [ 1, 2 ] },
|
|
886
|
+
{ 'second' => { '$gt' => 3 } }
|
|
887
|
+
]
|
|
888
|
+
})
|
|
954
889
|
end
|
|
955
890
|
|
|
956
891
|
it_behaves_like 'returns a cloned query'
|
|
@@ -962,8 +897,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
962
897
|
|
|
963
898
|
it 'adds the conditions' do
|
|
964
899
|
expect(selection.selector).to eq(expected_operator => [
|
|
965
|
-
|
|
966
|
-
|
|
900
|
+
{ 'field' => { '$gte' => Time.new(2020, 1, 1) } }
|
|
901
|
+
])
|
|
967
902
|
end
|
|
968
903
|
|
|
969
904
|
it 'keeps the type' do
|
|
@@ -978,8 +913,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
978
913
|
|
|
979
914
|
it 'adds the conditions' do
|
|
980
915
|
expect(selection.selector).to eq(expected_operator => [
|
|
981
|
-
|
|
982
|
-
|
|
916
|
+
{ 'field' => { '$gte' => Time.utc(2020, 1, 1) } }
|
|
917
|
+
])
|
|
983
918
|
end
|
|
984
919
|
|
|
985
920
|
it 'converts argument to a time' do
|
|
@@ -994,8 +929,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
994
929
|
|
|
995
930
|
it 'adds the conditions' do
|
|
996
931
|
expect(selection.selector).to eq(expected_operator => [
|
|
997
|
-
|
|
998
|
-
|
|
932
|
+
{ 'field' => { '$gte' => Time.utc(2020, 1, 1) } }
|
|
933
|
+
])
|
|
999
934
|
end
|
|
1000
935
|
|
|
1001
936
|
it 'converts argument to a time' do
|
|
@@ -1004,41 +939,38 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1004
939
|
end
|
|
1005
940
|
end
|
|
1006
941
|
|
|
1007
|
-
context
|
|
1008
|
-
|
|
942
|
+
context 'when a criterion has an aliased field' do
|
|
1009
943
|
let(:selection) do
|
|
1010
944
|
query.send(tested_method, { id: 1 })
|
|
1011
945
|
end
|
|
1012
946
|
|
|
1013
|
-
it
|
|
947
|
+
it 'adds the $or/$nor selector and aliases the field' do
|
|
1014
948
|
expect(selection.selector).to eq({
|
|
1015
|
-
|
|
1016
|
-
|
|
949
|
+
expected_operator => [ { '_id' => 1 } ]
|
|
950
|
+
})
|
|
1017
951
|
end
|
|
1018
952
|
|
|
1019
953
|
it_behaves_like 'returns a cloned query'
|
|
1020
954
|
end
|
|
1021
955
|
|
|
1022
|
-
context
|
|
1023
|
-
|
|
956
|
+
context 'when a criterion is wrapped in an array' do
|
|
1024
957
|
let(:selection) do
|
|
1025
|
-
query.send(tested_method, [{ first: [ 1, 2 ] }, { :second.gt => 3 }])
|
|
958
|
+
query.send(tested_method, [ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
|
|
1026
959
|
end
|
|
1027
960
|
|
|
1028
961
|
it_behaves_like 'returns a cloned query'
|
|
1029
962
|
|
|
1030
|
-
it
|
|
963
|
+
it 'adds the $or/$nor selector' do
|
|
1031
964
|
expect(selection.selector).to eq({
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
965
|
+
expected_operator => [
|
|
966
|
+
{ 'first' => [ 1, 2 ] },
|
|
967
|
+
{ 'second' => { '$gt' => 3 } }
|
|
968
|
+
]
|
|
969
|
+
})
|
|
1037
970
|
end
|
|
1038
971
|
end
|
|
1039
972
|
|
|
1040
|
-
context
|
|
1041
|
-
|
|
973
|
+
context 'when the criteria are on the same field' do
|
|
1042
974
|
context 'simple criteria' do
|
|
1043
975
|
let(:selection) do
|
|
1044
976
|
query.send(tested_method, { first: [ 1, 2 ] }, { first: [ 3, 4 ] })
|
|
@@ -1046,13 +978,13 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1046
978
|
|
|
1047
979
|
it_behaves_like 'returns a cloned query'
|
|
1048
980
|
|
|
1049
|
-
it
|
|
981
|
+
it 'appends both $or/$nor expressions' do
|
|
1050
982
|
expect(selection.selector).to eq({
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
983
|
+
expected_operator => [
|
|
984
|
+
{ 'first' => [ 1, 2 ] },
|
|
985
|
+
{ 'first' => [ 3, 4 ] }
|
|
986
|
+
]
|
|
987
|
+
})
|
|
1056
988
|
end
|
|
1057
989
|
end
|
|
1058
990
|
|
|
@@ -1063,86 +995,82 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1063
995
|
|
|
1064
996
|
it_behaves_like 'returns a cloned query'
|
|
1065
997
|
|
|
1066
|
-
it
|
|
998
|
+
it 'adds all criteria' do
|
|
1067
999
|
expect(selection.selector).to eq({
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1000
|
+
expected_operator => [
|
|
1001
|
+
{ 'first' => { '$gt' => 3, '$lt' => 5 } }
|
|
1002
|
+
]
|
|
1003
|
+
})
|
|
1072
1004
|
end
|
|
1073
1005
|
end
|
|
1074
1006
|
|
|
1075
1007
|
context 'Key criteria as multiple arguments' do
|
|
1076
1008
|
let(:selection) do
|
|
1077
|
-
query.send(tested_method, {:first.gt => 3}, {:first.lt => 5})
|
|
1009
|
+
query.send(tested_method, { :first.gt => 3 }, { :first.lt => 5 })
|
|
1078
1010
|
end
|
|
1079
1011
|
|
|
1080
1012
|
it_behaves_like 'returns a cloned query'
|
|
1081
1013
|
|
|
1082
|
-
it
|
|
1014
|
+
it 'adds all criteria' do
|
|
1083
1015
|
expect(selection.selector).to eq({
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1016
|
+
expected_operator => [
|
|
1017
|
+
{ 'first' => { '$gt' => 3 } },
|
|
1018
|
+
{ 'first' => { '$lt' => 5 } }
|
|
1019
|
+
]
|
|
1020
|
+
})
|
|
1089
1021
|
end
|
|
1090
1022
|
end
|
|
1091
1023
|
end
|
|
1092
1024
|
end
|
|
1093
1025
|
|
|
1094
|
-
context
|
|
1095
|
-
|
|
1096
|
-
context "when the criterion are for different fields" do
|
|
1097
|
-
|
|
1026
|
+
context 'when chaining the criterion' do
|
|
1027
|
+
context 'when the criterion are for different fields' do
|
|
1098
1028
|
let(:selection) do
|
|
1099
1029
|
query.send(tested_method, first: [ 1, 2 ]).send(tested_method, second: [ 3, 4 ])
|
|
1100
1030
|
end
|
|
1101
1031
|
|
|
1102
1032
|
it_behaves_like 'returns a cloned query'
|
|
1103
1033
|
|
|
1104
|
-
it
|
|
1034
|
+
it 'adds the $or/$nor selectors' do
|
|
1105
1035
|
expect(selection.selector).to eq({
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1036
|
+
expected_operator => [
|
|
1037
|
+
{ 'first' => [ 1, 2 ] },
|
|
1038
|
+
{ 'second' => [ 3, 4 ] }
|
|
1039
|
+
]
|
|
1040
|
+
})
|
|
1111
1041
|
end
|
|
1112
1042
|
end
|
|
1113
1043
|
|
|
1114
|
-
context
|
|
1115
|
-
|
|
1044
|
+
context 'when the criterion are on the same field' do
|
|
1116
1045
|
let(:selection) do
|
|
1117
1046
|
query.send(tested_method, first: [ 1, 2 ]).send(tested_method, first: [ 3, 4 ])
|
|
1118
1047
|
end
|
|
1119
1048
|
|
|
1120
1049
|
it_behaves_like 'returns a cloned query'
|
|
1121
1050
|
|
|
1122
|
-
it
|
|
1051
|
+
it 'appends both $or/$nor expressions' do
|
|
1123
1052
|
expect(selection.selector).to eq({
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1053
|
+
expected_operator => [
|
|
1054
|
+
{ 'first' => [ 1, 2 ] },
|
|
1055
|
+
{ 'first' => [ 3, 4 ] }
|
|
1056
|
+
]
|
|
1057
|
+
})
|
|
1129
1058
|
end
|
|
1130
1059
|
end
|
|
1131
1060
|
end
|
|
1132
1061
|
|
|
1133
1062
|
context 'when giving multiple conditions in one call on the same key with symbol operator' do
|
|
1134
|
-
|
|
1135
1063
|
context 'non-regexp argument' do
|
|
1136
1064
|
let(:selection) do
|
|
1137
1065
|
query.send(tested_method, field: 1, :field.gt => 0)
|
|
1138
1066
|
end
|
|
1139
1067
|
|
|
1140
1068
|
it 'combines conditions with $eq' do
|
|
1141
|
-
selection.selector.should
|
|
1142
|
-
expected_operator => [
|
|
1143
|
-
'field' => {'$eq' => 1, '$gt' => 0}
|
|
1144
|
-
]
|
|
1145
|
-
|
|
1069
|
+
selection.selector.should eq(
|
|
1070
|
+
{ expected_operator => [
|
|
1071
|
+
{ 'field' => { '$eq' => 1, '$gt' => 0 } }
|
|
1072
|
+
] }
|
|
1073
|
+
)
|
|
1146
1074
|
end
|
|
1147
1075
|
end
|
|
1148
1076
|
|
|
@@ -1152,35 +1080,31 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1152
1080
|
end
|
|
1153
1081
|
|
|
1154
1082
|
it 'combines conditions with $regex' do
|
|
1155
|
-
selection.selector.should
|
|
1156
|
-
expected_operator => [
|
|
1157
|
-
'field' => {'$regex' => /t/, '$gt' => 0}
|
|
1158
|
-
]
|
|
1159
|
-
|
|
1083
|
+
selection.selector.should eq(
|
|
1084
|
+
{ expected_operator => [
|
|
1085
|
+
{ 'field' => { '$regex' => /t/, '$gt' => 0 } }
|
|
1086
|
+
] }
|
|
1087
|
+
)
|
|
1160
1088
|
end
|
|
1161
1089
|
end
|
|
1162
|
-
|
|
1163
1090
|
end
|
|
1164
1091
|
end
|
|
1165
1092
|
|
|
1166
|
-
describe
|
|
1167
|
-
|
|
1093
|
+
describe '#or' do
|
|
1168
1094
|
let(:tested_method) { :or }
|
|
1169
1095
|
let(:expected_operator) { '$or' }
|
|
1170
1096
|
|
|
1171
1097
|
it_behaves_like '$or/$nor'
|
|
1172
1098
|
end
|
|
1173
1099
|
|
|
1174
|
-
describe
|
|
1175
|
-
|
|
1100
|
+
describe '#nor' do
|
|
1176
1101
|
let(:tested_method) { :nor }
|
|
1177
1102
|
let(:expected_operator) { '$nor' }
|
|
1178
1103
|
|
|
1179
1104
|
it_behaves_like '$or/$nor'
|
|
1180
1105
|
end
|
|
1181
1106
|
|
|
1182
|
-
describe
|
|
1183
|
-
|
|
1107
|
+
describe '#any_of' do
|
|
1184
1108
|
let(:tested_method) { :any_of }
|
|
1185
1109
|
let(:expected_operator) { '$or' }
|
|
1186
1110
|
|
|
@@ -1198,7 +1122,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1198
1122
|
end
|
|
1199
1123
|
|
|
1200
1124
|
let(:other2) do
|
|
1201
|
-
{bar: 42}
|
|
1125
|
+
{ bar: 42 }
|
|
1202
1126
|
end
|
|
1203
1127
|
|
|
1204
1128
|
let(:other3) do
|
|
@@ -1211,96 +1135,89 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1211
1135
|
expect(result.selector).to eq(
|
|
1212
1136
|
'hello' => 'world',
|
|
1213
1137
|
expected_operator => [
|
|
1214
|
-
{'foo' => 'bar'},
|
|
1215
|
-
{'bar' => 42},
|
|
1216
|
-
{'a' => 2}
|
|
1217
|
-
]
|
|
1138
|
+
{ 'foo' => 'bar' },
|
|
1139
|
+
{ 'bar' => 42 },
|
|
1140
|
+
{ 'a' => 2 }
|
|
1141
|
+
]
|
|
1218
1142
|
)
|
|
1219
1143
|
end
|
|
1220
1144
|
end
|
|
1221
1145
|
|
|
1222
|
-
context
|
|
1223
|
-
|
|
1146
|
+
context 'when provided no arguments' do
|
|
1224
1147
|
let(:selection) do
|
|
1225
1148
|
query.any_of
|
|
1226
1149
|
end
|
|
1227
1150
|
|
|
1228
1151
|
it_behaves_like 'returns a cloned query'
|
|
1229
1152
|
|
|
1230
|
-
it
|
|
1153
|
+
it 'does not add any criteria' do
|
|
1231
1154
|
expect(selection.selector).to eq({})
|
|
1232
1155
|
end
|
|
1233
1156
|
|
|
1234
|
-
it
|
|
1157
|
+
it 'returns the query' do
|
|
1235
1158
|
expect(selection).to eq(query)
|
|
1236
1159
|
end
|
|
1237
1160
|
end
|
|
1238
1161
|
|
|
1239
|
-
context
|
|
1240
|
-
|
|
1162
|
+
context 'when provided nil' do
|
|
1241
1163
|
let(:selection) do
|
|
1242
1164
|
query.any_of(nil)
|
|
1243
1165
|
end
|
|
1244
1166
|
|
|
1245
1167
|
it_behaves_like 'returns a cloned query'
|
|
1246
1168
|
|
|
1247
|
-
it
|
|
1169
|
+
it 'does not add any criteria' do
|
|
1248
1170
|
expect(selection.selector).to eq({})
|
|
1249
1171
|
end
|
|
1250
1172
|
|
|
1251
|
-
it
|
|
1173
|
+
it 'returns the query' do
|
|
1252
1174
|
expect(selection).to eq(query)
|
|
1253
1175
|
end
|
|
1254
1176
|
end
|
|
1255
1177
|
|
|
1256
|
-
context
|
|
1257
|
-
|
|
1178
|
+
context 'when provided a single criterion' do
|
|
1258
1179
|
let(:selection) do
|
|
1259
1180
|
query.any_of(field: [ 1, 2 ])
|
|
1260
1181
|
end
|
|
1261
1182
|
|
|
1262
1183
|
it_behaves_like 'returns a cloned query'
|
|
1263
1184
|
|
|
1264
|
-
it
|
|
1185
|
+
it 'adds the $or selector' do
|
|
1265
1186
|
expect(selection.selector).to eq(
|
|
1266
|
-
|
|
1187
|
+
'field' => [ 1, 2 ]
|
|
1267
1188
|
)
|
|
1268
1189
|
end
|
|
1269
1190
|
|
|
1270
1191
|
context 'when the criterion is wrapped in array' do
|
|
1271
|
-
|
|
1272
1192
|
let(:selection) do
|
|
1273
|
-
query.any_of([{ field: [ 1, 2 ] }])
|
|
1193
|
+
query.any_of([ { field: [ 1, 2 ] } ])
|
|
1274
1194
|
end
|
|
1275
1195
|
|
|
1276
1196
|
it_behaves_like 'returns a cloned query'
|
|
1277
1197
|
|
|
1278
|
-
it
|
|
1198
|
+
it 'adds the condition' do
|
|
1279
1199
|
expect(selection.selector).to eq(
|
|
1280
|
-
|
|
1200
|
+
'field' => [ 1, 2 ]
|
|
1281
1201
|
)
|
|
1282
1202
|
end
|
|
1283
1203
|
|
|
1284
1204
|
context 'when the array has nil as one of the elements' do
|
|
1285
|
-
|
|
1286
1205
|
let(:selection) do
|
|
1287
|
-
query.any_of([{ field: [ 1, 2 ] }, nil])
|
|
1206
|
+
query.any_of([ { field: [ 1, 2 ] }, nil ])
|
|
1288
1207
|
end
|
|
1289
1208
|
|
|
1290
1209
|
it_behaves_like 'returns a cloned query'
|
|
1291
1210
|
|
|
1292
|
-
it
|
|
1211
|
+
it 'adds the $or selector ignoring the nil element' do
|
|
1293
1212
|
expect(selection.selector).to eq(
|
|
1294
|
-
|
|
1213
|
+
'field' => [ 1, 2 ]
|
|
1295
1214
|
)
|
|
1296
1215
|
end
|
|
1297
1216
|
end
|
|
1298
1217
|
end
|
|
1299
1218
|
|
|
1300
1219
|
context 'when query already has a condition on another field' do
|
|
1301
|
-
|
|
1302
1220
|
context 'when there is one argument' do
|
|
1303
|
-
|
|
1304
1221
|
let(:selection) do
|
|
1305
1222
|
query.where(foo: 'bar').any_of(field: [ 1, 2 ])
|
|
1306
1223
|
end
|
|
@@ -1308,106 +1225,100 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1308
1225
|
it 'adds the new condition' do
|
|
1309
1226
|
expect(selection.selector).to eq(
|
|
1310
1227
|
'foo' => 'bar',
|
|
1311
|
-
'field' => [1, 2]
|
|
1228
|
+
'field' => [ 1, 2 ]
|
|
1312
1229
|
)
|
|
1313
1230
|
end
|
|
1314
1231
|
end
|
|
1315
1232
|
|
|
1316
1233
|
context 'when there are multiple arguments' do
|
|
1317
|
-
|
|
1318
1234
|
let(:selection) do
|
|
1319
|
-
query.where(foo: 'bar').any_of({field: [ 1, 2 ]}, {hello: 'world'})
|
|
1235
|
+
query.where(foo: 'bar').any_of({ field: [ 1, 2 ] }, { hello: 'world' })
|
|
1320
1236
|
end
|
|
1321
1237
|
|
|
1322
1238
|
it 'adds the new condition' do
|
|
1323
1239
|
expect(selection.selector).to eq(
|
|
1324
1240
|
'foo' => 'bar',
|
|
1325
1241
|
'$or' => [
|
|
1326
|
-
{'field' => [1, 2]},
|
|
1327
|
-
{'hello' => 'world'}
|
|
1328
|
-
]
|
|
1242
|
+
{ 'field' => [ 1, 2 ] },
|
|
1243
|
+
{ 'hello' => 'world' }
|
|
1244
|
+
]
|
|
1329
1245
|
)
|
|
1330
1246
|
end
|
|
1331
1247
|
end
|
|
1332
1248
|
end
|
|
1333
1249
|
|
|
1334
1250
|
context 'when query already has an $or condition and another condition' do
|
|
1335
|
-
|
|
1336
1251
|
let(:selection) do
|
|
1337
1252
|
query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of(test: 1)
|
|
1338
1253
|
end
|
|
1339
1254
|
|
|
1340
1255
|
it 'adds the new condition' do
|
|
1341
1256
|
expect(selection.selector).to eq(
|
|
1342
|
-
'$or' => [{'field' => [1, 2]}],
|
|
1257
|
+
'$or' => [ { 'field' => [ 1, 2 ] } ],
|
|
1343
1258
|
'foo' => 'bar',
|
|
1344
|
-
'test' => 1
|
|
1259
|
+
'test' => 1
|
|
1345
1260
|
)
|
|
1346
1261
|
end
|
|
1347
1262
|
end
|
|
1348
1263
|
|
|
1349
1264
|
context 'when any_of has multiple arguments' do
|
|
1350
|
-
|
|
1351
1265
|
let(:selection) do
|
|
1352
|
-
query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of({a: 1}, {b: 2})
|
|
1266
|
+
query.or(field: [ 1, 2 ]).where(foo: 'bar').any_of({ a: 1 }, { b: 2 })
|
|
1353
1267
|
end
|
|
1354
1268
|
|
|
1355
1269
|
it 'adds the new condition to top level' do
|
|
1356
1270
|
expect(selection.selector).to eq(
|
|
1357
|
-
'$or' => [{'field' => [1, 2]}],
|
|
1271
|
+
'$or' => [ { 'field' => [ 1, 2 ] } ],
|
|
1358
1272
|
'foo' => 'bar',
|
|
1359
|
-
'$and' => [{'$or' => [{'a' => 1}, {'b' => 2}]}]
|
|
1273
|
+
'$and' => [ { '$or' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
|
|
1360
1274
|
)
|
|
1361
1275
|
end
|
|
1362
1276
|
|
|
1363
1277
|
context 'when query already has a top-level $and' do
|
|
1364
1278
|
let(:selection) do
|
|
1365
|
-
query.or(field: [ 1, 2 ]).where('$and' => [foo: 'bar']).any_of({a: 1}, {b: 2})
|
|
1279
|
+
query.or(field: [ 1, 2 ]).where('$and' => [ { foo: 'bar' } ]).any_of({ a: 1 }, { b: 2 })
|
|
1366
1280
|
end
|
|
1367
1281
|
|
|
1368
1282
|
it 'adds the new condition to top level $and' do
|
|
1369
1283
|
expect(selection.selector).to eq(
|
|
1370
|
-
'$or' => [{'field' => [1, 2]}],
|
|
1371
|
-
'$and' => [{'foo' => 'bar'}, {'$or' => [{'a' => 1}, {'b' => 2}]}]
|
|
1284
|
+
'$or' => [ { 'field' => [ 1, 2 ] } ],
|
|
1285
|
+
'$and' => [ { 'foo' => 'bar' }, { '$or' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
|
|
1372
1286
|
)
|
|
1373
1287
|
end
|
|
1374
1288
|
end
|
|
1375
1289
|
end
|
|
1376
1290
|
end
|
|
1377
1291
|
|
|
1378
|
-
context
|
|
1379
|
-
|
|
1380
|
-
context "when the criteria are for different fields" do
|
|
1381
|
-
|
|
1292
|
+
context 'when provided multiple criteria' do
|
|
1293
|
+
context 'when the criteria are for different fields' do
|
|
1382
1294
|
let(:selection) do
|
|
1383
1295
|
query.any_of({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
|
|
1384
1296
|
end
|
|
1385
1297
|
|
|
1386
1298
|
it_behaves_like 'returns a cloned query'
|
|
1387
1299
|
|
|
1388
|
-
it
|
|
1300
|
+
it 'adds the $or selector' do
|
|
1389
1301
|
expect(selection.selector).to eq({
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1302
|
+
'$or' => [
|
|
1303
|
+
{ 'first' => [ 1, 2 ] },
|
|
1304
|
+
{ 'second' => [ 3, 4 ] }
|
|
1305
|
+
]
|
|
1306
|
+
})
|
|
1395
1307
|
end
|
|
1396
1308
|
end
|
|
1397
1309
|
|
|
1398
|
-
context
|
|
1399
|
-
|
|
1310
|
+
context 'when the criteria uses a Key instance' do
|
|
1400
1311
|
let(:selection) do
|
|
1401
1312
|
query.any_of({ first: [ 1, 2 ] }, { :second.gt => 3 })
|
|
1402
1313
|
end
|
|
1403
1314
|
|
|
1404
|
-
it
|
|
1315
|
+
it 'adds the $or selector' do
|
|
1405
1316
|
expect(selection.selector).to eq({
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1317
|
+
'$or' => [
|
|
1318
|
+
{ 'first' => [ 1, 2 ] },
|
|
1319
|
+
{ 'second' => { '$gt' => 3 } }
|
|
1320
|
+
]
|
|
1321
|
+
})
|
|
1411
1322
|
end
|
|
1412
1323
|
|
|
1413
1324
|
it_behaves_like 'returns a cloned query'
|
|
@@ -1415,42 +1326,39 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1415
1326
|
|
|
1416
1327
|
context 'when criteria are simple and handled via Key' do
|
|
1417
1328
|
shared_examples_for 'adds conditions with $or' do
|
|
1418
|
-
|
|
1419
|
-
it "adds conditions with $or" do
|
|
1329
|
+
it 'adds conditions with $or' do
|
|
1420
1330
|
expect(selection.selector).to eq({
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1331
|
+
'$or' => [
|
|
1332
|
+
{ 'field' => 3 },
|
|
1333
|
+
{ 'field' => { '$lt' => 5 } }
|
|
1334
|
+
]
|
|
1335
|
+
})
|
|
1426
1336
|
end
|
|
1427
1337
|
|
|
1428
1338
|
it_behaves_like 'returns a cloned query'
|
|
1429
1339
|
end
|
|
1430
1340
|
|
|
1431
1341
|
shared_examples_for 'combines conditions with $eq' do
|
|
1432
|
-
|
|
1433
|
-
it "combines conditions with $eq" do
|
|
1342
|
+
it 'combines conditions with $eq' do
|
|
1434
1343
|
expect(selection.selector).to eq({
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1344
|
+
'field' => {
|
|
1345
|
+
'$eq' => 3,
|
|
1346
|
+
'$lt' => 5
|
|
1347
|
+
}
|
|
1348
|
+
})
|
|
1440
1349
|
end
|
|
1441
1350
|
|
|
1442
1351
|
it_behaves_like 'returns a cloned query'
|
|
1443
1352
|
end
|
|
1444
1353
|
|
|
1445
1354
|
shared_examples_for 'combines conditions with $regex' do
|
|
1446
|
-
|
|
1447
|
-
it "combines conditions with $regex" do
|
|
1355
|
+
it 'combines conditions with $regex' do
|
|
1448
1356
|
expect(selection.selector).to eq({
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1357
|
+
'field' => {
|
|
1358
|
+
'$regex' => /t/,
|
|
1359
|
+
'$lt' => 5
|
|
1360
|
+
}
|
|
1361
|
+
})
|
|
1454
1362
|
end
|
|
1455
1363
|
|
|
1456
1364
|
it_behaves_like 'returns a cloned query'
|
|
@@ -1476,7 +1384,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1476
1384
|
|
|
1477
1385
|
context 'criteria are provided in separate hashes' do
|
|
1478
1386
|
let(:selection) do
|
|
1479
|
-
query.send(tested_method, {:
|
|
1387
|
+
query.send(tested_method, { field: 3 }, { :field.lt => 5 })
|
|
1480
1388
|
end
|
|
1481
1389
|
|
|
1482
1390
|
it_behaves_like 'adds conditions with $or'
|
|
@@ -1484,7 +1392,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1484
1392
|
|
|
1485
1393
|
context 'when the criterion is wrapped in an array' do
|
|
1486
1394
|
let(:selection) do
|
|
1487
|
-
query.send(tested_method, [:
|
|
1395
|
+
query.send(tested_method, [ { field: 3 } ], [ { :field.lt => 5 } ])
|
|
1488
1396
|
end
|
|
1489
1397
|
|
|
1490
1398
|
it_behaves_like 'adds conditions with $or'
|
|
@@ -1493,24 +1401,22 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1493
1401
|
|
|
1494
1402
|
context 'when criteria are handled via Key and simple' do
|
|
1495
1403
|
shared_examples_for 'adds conditions with $or' do
|
|
1496
|
-
|
|
1497
|
-
it "adds conditions with $or" do
|
|
1404
|
+
it 'adds conditions with $or' do
|
|
1498
1405
|
expect(selection.selector).to eq({
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1406
|
+
'$or' => [
|
|
1407
|
+
{ 'field' => { '$gt' => 3 } },
|
|
1408
|
+
{ 'field' => 5 }
|
|
1409
|
+
]
|
|
1410
|
+
})
|
|
1504
1411
|
end
|
|
1505
1412
|
|
|
1506
1413
|
it_behaves_like 'returns a cloned query'
|
|
1507
1414
|
end
|
|
1508
1415
|
|
|
1509
1416
|
shared_examples_for 'combines conditions with $eq' do
|
|
1510
|
-
|
|
1511
|
-
it "combines conditions with $eq" do
|
|
1417
|
+
it 'combines conditions with $eq' do
|
|
1512
1418
|
expect(selection.selector).to eq(
|
|
1513
|
-
'field' => {'$gt' => 3, '$eq' => 5}
|
|
1419
|
+
'field' => { '$gt' => 3, '$eq' => 5 }
|
|
1514
1420
|
)
|
|
1515
1421
|
end
|
|
1516
1422
|
|
|
@@ -1518,10 +1424,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1518
1424
|
end
|
|
1519
1425
|
|
|
1520
1426
|
shared_examples_for 'combines conditions with $regex' do
|
|
1521
|
-
|
|
1522
|
-
it "combines conditions with $regex" do
|
|
1427
|
+
it 'combines conditions with $regex' do
|
|
1523
1428
|
expect(selection.selector).to eq(
|
|
1524
|
-
'field' => {'$gt' => 3, '$regex' => /t/}
|
|
1429
|
+
'field' => { '$gt' => 3, '$regex' => /t/ }
|
|
1525
1430
|
)
|
|
1526
1431
|
end
|
|
1527
1432
|
|
|
@@ -1548,7 +1453,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1548
1453
|
|
|
1549
1454
|
context 'criteria are provided in separate hashes' do
|
|
1550
1455
|
let(:selection) do
|
|
1551
|
-
query.send(tested_method, {:field.gt => 3}, {:
|
|
1456
|
+
query.send(tested_method, { :field.gt => 3 }, { field: 5 })
|
|
1552
1457
|
end
|
|
1553
1458
|
|
|
1554
1459
|
it_behaves_like 'adds conditions with $or'
|
|
@@ -1556,95 +1461,89 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1556
1461
|
|
|
1557
1462
|
context 'when the criterion is wrapped in an array' do
|
|
1558
1463
|
let(:selection) do
|
|
1559
|
-
query.send(tested_method, [:field.gt => 3], [:
|
|
1464
|
+
query.send(tested_method, [ { :field.gt => 3 } ], [ { field: 5 } ])
|
|
1560
1465
|
end
|
|
1561
1466
|
|
|
1562
1467
|
it_behaves_like 'adds conditions with $or'
|
|
1563
1468
|
end
|
|
1564
1469
|
end
|
|
1565
1470
|
|
|
1566
|
-
context
|
|
1567
|
-
|
|
1471
|
+
context 'when a criterion has an aliased field' do
|
|
1568
1472
|
let(:selection) do
|
|
1569
1473
|
query.any_of({ id: 1 })
|
|
1570
1474
|
end
|
|
1571
1475
|
|
|
1572
|
-
it
|
|
1476
|
+
it 'adds the $or selector and aliases the field' do
|
|
1573
1477
|
expect(selection.selector).to eq(
|
|
1574
|
-
|
|
1478
|
+
'_id' => 1
|
|
1575
1479
|
)
|
|
1576
1480
|
end
|
|
1577
1481
|
|
|
1578
1482
|
it_behaves_like 'returns a cloned query'
|
|
1579
1483
|
end
|
|
1580
1484
|
|
|
1581
|
-
context
|
|
1582
|
-
|
|
1485
|
+
context 'when a criterion is wrapped in an array' do
|
|
1583
1486
|
let(:selection) do
|
|
1584
|
-
query.any_of([{ first: [ 1, 2 ] }, { :second.gt => 3 }])
|
|
1487
|
+
query.any_of([ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
|
|
1585
1488
|
end
|
|
1586
1489
|
|
|
1587
1490
|
it_behaves_like 'returns a cloned query'
|
|
1588
1491
|
|
|
1589
|
-
it
|
|
1492
|
+
it 'adds the $or selector' do
|
|
1590
1493
|
expect(selection.selector).to eq({
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1494
|
+
'$or' => [
|
|
1495
|
+
{ 'first' => [ 1, 2 ] },
|
|
1496
|
+
{ 'second' => { '$gt' => 3 } }
|
|
1497
|
+
]
|
|
1498
|
+
})
|
|
1596
1499
|
end
|
|
1597
1500
|
end
|
|
1598
1501
|
|
|
1599
|
-
context
|
|
1600
|
-
|
|
1502
|
+
context 'when the criteria are on the same field' do
|
|
1601
1503
|
let(:selection) do
|
|
1602
1504
|
query.any_of({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
|
|
1603
1505
|
end
|
|
1604
1506
|
|
|
1605
1507
|
it_behaves_like 'returns a cloned query'
|
|
1606
1508
|
|
|
1607
|
-
it
|
|
1509
|
+
it 'appends both $or expressions' do
|
|
1608
1510
|
expect(selection.selector).to eq({
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1511
|
+
'$or' => [
|
|
1512
|
+
{ 'first' => [ 1, 2 ] },
|
|
1513
|
+
{ 'first' => [ 3, 4 ] }
|
|
1514
|
+
]
|
|
1515
|
+
})
|
|
1614
1516
|
end
|
|
1615
1517
|
end
|
|
1616
1518
|
end
|
|
1617
1519
|
|
|
1618
|
-
context
|
|
1619
|
-
|
|
1620
|
-
context "when the criteria are for different fields" do
|
|
1621
|
-
|
|
1520
|
+
context 'when chaining the criteria' do
|
|
1521
|
+
context 'when the criteria are for different fields' do
|
|
1622
1522
|
let(:selection) do
|
|
1623
1523
|
query.any_of(first: [ 1, 2 ]).any_of(second: [ 3, 4 ])
|
|
1624
1524
|
end
|
|
1625
1525
|
|
|
1626
1526
|
it_behaves_like 'returns a cloned query'
|
|
1627
1527
|
|
|
1628
|
-
it
|
|
1528
|
+
it 'adds the conditions separately' do
|
|
1629
1529
|
expect(selection.selector).to eq(
|
|
1630
|
-
|
|
1631
|
-
|
|
1530
|
+
'first' => [ 1, 2 ],
|
|
1531
|
+
'second' => [ 3, 4 ]
|
|
1632
1532
|
)
|
|
1633
1533
|
end
|
|
1634
1534
|
end
|
|
1635
1535
|
|
|
1636
|
-
context
|
|
1637
|
-
|
|
1536
|
+
context 'when the criteria are on the same field' do
|
|
1638
1537
|
let(:selection) do
|
|
1639
1538
|
query.any_of(first: [ 1, 2 ]).any_of(first: [ 3, 4 ])
|
|
1640
1539
|
end
|
|
1641
1540
|
|
|
1642
1541
|
it_behaves_like 'returns a cloned query'
|
|
1643
1542
|
|
|
1644
|
-
it
|
|
1543
|
+
it 'adds the conditions separately' do
|
|
1645
1544
|
expect(selection.selector).to eq(
|
|
1646
|
-
|
|
1647
|
-
'$and' => [{
|
|
1545
|
+
'first' => [ 1, 2 ],
|
|
1546
|
+
'$and' => [ { 'first' => [ 3, 4 ] } ]
|
|
1648
1547
|
)
|
|
1649
1548
|
end
|
|
1650
1549
|
end
|
|
@@ -1652,66 +1551,66 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1652
1551
|
|
|
1653
1552
|
context 'when using multiple criteria and symbol operators' do
|
|
1654
1553
|
context 'when using fields that meaningfully evolve values' do
|
|
1655
|
-
|
|
1656
1554
|
let(:query) do
|
|
1657
|
-
Dictionary.any_of({a: 1}, :published.gt => Date.new(2020, 2, 3))
|
|
1555
|
+
Dictionary.any_of({ a: 1 }, :published.gt => Date.new(2020, 2, 3))
|
|
1658
1556
|
end
|
|
1659
1557
|
|
|
1660
1558
|
it 'generates the expected query' do
|
|
1661
|
-
query.selector.should
|
|
1662
|
-
{'
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1559
|
+
query.selector.should eq(
|
|
1560
|
+
{ '$or' => [
|
|
1561
|
+
{ 'a' => 1 },
|
|
1562
|
+
# Date instance is converted to a Time instance in local time,
|
|
1563
|
+
# because we are querying on a Time field and dates are interpreted
|
|
1564
|
+
# in local time when assigning to Time fields
|
|
1565
|
+
{ 'published' => { '$gt' => Time.zone.local(2020, 2, 3) } }
|
|
1566
|
+
] }
|
|
1567
|
+
)
|
|
1668
1568
|
end
|
|
1669
1569
|
end
|
|
1670
1570
|
|
|
1671
1571
|
context 'when using fields that do not meaningfully evolve values' do
|
|
1672
|
-
|
|
1673
1572
|
let(:query) do
|
|
1674
|
-
Dictionary.any_of({a: 1}, :submitted_on.gt => Date.new(2020, 2, 3))
|
|
1573
|
+
Dictionary.any_of({ a: 1 }, :submitted_on.gt => Date.new(2020, 2, 3))
|
|
1675
1574
|
end
|
|
1676
1575
|
|
|
1677
1576
|
it 'generates the expected query' do
|
|
1678
|
-
query.selector.should
|
|
1679
|
-
{'
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1577
|
+
query.selector.should eq(
|
|
1578
|
+
{ '$or' => [
|
|
1579
|
+
{ 'a' => 1 },
|
|
1580
|
+
# Date instance is converted to a Time instance in UTC,
|
|
1581
|
+
# because we are querying on a Date field and dates are interpreted
|
|
1582
|
+
# in UTC when persisted as dates by Mongoid
|
|
1583
|
+
{ 'submitted_on' => { '$gt' => Time.utc(2020, 2, 3) } }
|
|
1584
|
+
] }
|
|
1585
|
+
)
|
|
1685
1586
|
end
|
|
1686
1587
|
end
|
|
1687
1588
|
end
|
|
1688
1589
|
end
|
|
1689
1590
|
|
|
1690
|
-
describe
|
|
1691
|
-
|
|
1692
|
-
context "when provided no criterion" do
|
|
1693
|
-
|
|
1591
|
+
describe '#not' do
|
|
1592
|
+
context 'when provided no criterion' do
|
|
1694
1593
|
let(:selection) do
|
|
1695
1594
|
query.not
|
|
1696
1595
|
end
|
|
1697
1596
|
|
|
1698
|
-
it
|
|
1597
|
+
it 'does not add any criterion' do
|
|
1699
1598
|
expect(selection.selector).to eq({})
|
|
1700
1599
|
end
|
|
1701
1600
|
|
|
1702
|
-
it
|
|
1601
|
+
it 'returns the query' do
|
|
1703
1602
|
expect(selection).to eq(query)
|
|
1704
1603
|
end
|
|
1705
1604
|
|
|
1706
|
-
it
|
|
1605
|
+
it 'returns a cloned query' do
|
|
1707
1606
|
expect(selection).not_to equal(query)
|
|
1708
1607
|
end
|
|
1709
1608
|
|
|
1710
1609
|
it 'does not mutate receiver' do
|
|
1711
|
-
expect(query.negating).to
|
|
1610
|
+
expect(query.negating).to be_nil
|
|
1712
1611
|
|
|
1713
1612
|
selection
|
|
1714
|
-
expect(query.negating).to
|
|
1613
|
+
expect(query.negating).to be_nil
|
|
1715
1614
|
end
|
|
1716
1615
|
|
|
1717
1616
|
shared_examples_for 'negates the next condition' do
|
|
@@ -1719,267 +1618,252 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1719
1618
|
query.not.send(query_method, field: [ 1, 2 ])
|
|
1720
1619
|
end
|
|
1721
1620
|
|
|
1722
|
-
it
|
|
1621
|
+
it 'negates the next condition' do
|
|
1723
1622
|
expect(selection.selector).to eq(
|
|
1724
|
-
{
|
|
1623
|
+
{ 'field' => { '$not' => { operator => [ 1, 2 ] } } }
|
|
1725
1624
|
)
|
|
1726
1625
|
end
|
|
1727
1626
|
|
|
1728
1627
|
it_behaves_like 'returns a cloned query'
|
|
1729
1628
|
|
|
1730
|
-
it
|
|
1731
|
-
expect(selection).
|
|
1629
|
+
it 'removes the negation on the clone' do
|
|
1630
|
+
expect(selection).not_to be_negating
|
|
1732
1631
|
end
|
|
1733
1632
|
end
|
|
1734
1633
|
|
|
1735
|
-
context
|
|
1634
|
+
context 'when the next condition is #all' do
|
|
1736
1635
|
let(:query_method) { :all }
|
|
1737
1636
|
let(:operator) { '$all' }
|
|
1738
1637
|
|
|
1739
1638
|
it_behaves_like 'negates the next condition'
|
|
1740
1639
|
end
|
|
1741
1640
|
|
|
1742
|
-
context
|
|
1641
|
+
context 'when the next condition is #in' do
|
|
1743
1642
|
let(:query_method) { :in }
|
|
1744
1643
|
let(:operator) { '$in' }
|
|
1745
1644
|
|
|
1746
1645
|
it_behaves_like 'negates the next condition'
|
|
1747
1646
|
end
|
|
1748
1647
|
|
|
1749
|
-
context
|
|
1648
|
+
context 'when the next condition is #nin' do
|
|
1750
1649
|
let(:query_method) { :nin }
|
|
1751
1650
|
let(:operator) { '$nin' }
|
|
1752
1651
|
|
|
1753
1652
|
it_behaves_like 'negates the next condition'
|
|
1754
1653
|
end
|
|
1755
1654
|
|
|
1756
|
-
context
|
|
1757
|
-
|
|
1655
|
+
context 'when the following criteria is a gt method' do
|
|
1758
1656
|
let(:selection) do
|
|
1759
1657
|
query.not.gt(age: 50)
|
|
1760
1658
|
end
|
|
1761
1659
|
|
|
1762
|
-
it
|
|
1660
|
+
it 'negates the gt selection' do
|
|
1763
1661
|
expect(selection.selector).to eq(
|
|
1764
|
-
{
|
|
1662
|
+
{ 'age' => { '$not' => { '$gt' => 50 } } }
|
|
1765
1663
|
)
|
|
1766
1664
|
end
|
|
1767
1665
|
|
|
1768
1666
|
it_behaves_like 'returns a cloned query'
|
|
1769
1667
|
|
|
1770
|
-
it
|
|
1771
|
-
expect(selection).
|
|
1668
|
+
it 'removes the negation on the clone' do
|
|
1669
|
+
expect(selection).not_to be_negating
|
|
1772
1670
|
end
|
|
1773
1671
|
end
|
|
1774
1672
|
|
|
1775
|
-
context
|
|
1776
|
-
|
|
1673
|
+
context 'when the criteria uses Key' do
|
|
1777
1674
|
let(:selection) do
|
|
1778
1675
|
query.not(:age.gt => 50)
|
|
1779
1676
|
end
|
|
1780
1677
|
|
|
1781
|
-
it
|
|
1678
|
+
it 'negates the gt selection' do
|
|
1782
1679
|
expect(selection.selector).to eq(
|
|
1783
|
-
'$and' => ['$nor' => ['age' => {'$gt' => 50}]]
|
|
1680
|
+
'$and' => [ { '$nor' => [ { 'age' => { '$gt' => 50 } } ] } ]
|
|
1784
1681
|
)
|
|
1785
1682
|
end
|
|
1786
1683
|
|
|
1787
1684
|
it_behaves_like 'returns a cloned query'
|
|
1788
1685
|
|
|
1789
|
-
it
|
|
1790
|
-
expect(selection).
|
|
1686
|
+
it 'removes the negation on the clone' do
|
|
1687
|
+
expect(selection).not_to be_negating
|
|
1791
1688
|
end
|
|
1792
1689
|
end
|
|
1793
1690
|
|
|
1794
|
-
context
|
|
1795
|
-
|
|
1691
|
+
context 'when the following criteria is a where' do
|
|
1796
1692
|
let(:selection) do
|
|
1797
1693
|
query.not.where(field: 1, :other.in => [ 1, 2 ])
|
|
1798
1694
|
end
|
|
1799
1695
|
|
|
1800
|
-
it
|
|
1696
|
+
it 'negates the selection with an operator' do
|
|
1801
1697
|
expect(selection.selector).to eq(
|
|
1802
|
-
{
|
|
1698
|
+
{ 'field' => { '$ne' => 1 }, 'other' => { '$not' => { '$in' => [ 1, 2 ] } } }
|
|
1803
1699
|
)
|
|
1804
1700
|
end
|
|
1805
1701
|
|
|
1806
1702
|
it_behaves_like 'returns a cloned query'
|
|
1807
1703
|
|
|
1808
|
-
it
|
|
1809
|
-
expect(selection).
|
|
1704
|
+
it 'removes the negation on the clone' do
|
|
1705
|
+
expect(selection).not_to be_negating
|
|
1810
1706
|
end
|
|
1811
1707
|
end
|
|
1812
1708
|
|
|
1813
|
-
context
|
|
1814
|
-
|
|
1709
|
+
context 'when the following criteria is a where with a regexp' do
|
|
1815
1710
|
let(:selection) do
|
|
1816
1711
|
query.not.where(field: 1, other: /test/)
|
|
1817
1712
|
end
|
|
1818
1713
|
|
|
1819
|
-
it
|
|
1714
|
+
it 'negates the selection with an operator' do
|
|
1820
1715
|
expect(selection.selector).to eq(
|
|
1821
|
-
{
|
|
1716
|
+
{ 'field' => { '$ne' => 1 }, 'other' => { '$not' => /test/ } }
|
|
1822
1717
|
)
|
|
1823
1718
|
end
|
|
1824
1719
|
|
|
1825
1720
|
it_behaves_like 'returns a cloned query'
|
|
1826
1721
|
|
|
1827
|
-
it
|
|
1828
|
-
expect(selection).
|
|
1722
|
+
it 'removes the negation on the clone' do
|
|
1723
|
+
expect(selection).not_to be_negating
|
|
1829
1724
|
end
|
|
1830
1725
|
end
|
|
1831
1726
|
|
|
1832
1727
|
context 'when the following criteria uses string were form' do
|
|
1833
|
-
|
|
1834
1728
|
let(:selection) do
|
|
1835
1729
|
query.not.where('hello world')
|
|
1836
1730
|
end
|
|
1837
1731
|
|
|
1838
|
-
it
|
|
1732
|
+
it 'negates the selection with an operator' do
|
|
1839
1733
|
expect(selection.selector).to eq(
|
|
1840
|
-
'$and' => [{'$nor' => [{'$where' => 'hello world'}]}]
|
|
1734
|
+
'$and' => [ { '$nor' => [ { '$where' => 'hello world' } ] } ]
|
|
1841
1735
|
)
|
|
1842
1736
|
end
|
|
1843
1737
|
|
|
1844
1738
|
it_behaves_like 'returns a cloned query'
|
|
1845
1739
|
|
|
1846
|
-
it
|
|
1847
|
-
expect(selection).
|
|
1740
|
+
it 'removes the negation on the clone' do
|
|
1741
|
+
expect(selection).not_to be_negating
|
|
1848
1742
|
end
|
|
1849
|
-
|
|
1850
1743
|
end
|
|
1851
1744
|
end
|
|
1852
1745
|
|
|
1853
|
-
context
|
|
1854
|
-
|
|
1746
|
+
context 'when provided nil' do
|
|
1855
1747
|
let(:selection) do
|
|
1856
1748
|
query.not(nil)
|
|
1857
1749
|
end
|
|
1858
1750
|
|
|
1859
|
-
it
|
|
1751
|
+
it 'does not add any criterion' do
|
|
1860
1752
|
expect(selection.selector).to eq({})
|
|
1861
1753
|
end
|
|
1862
1754
|
|
|
1863
|
-
it
|
|
1755
|
+
it 'returns the query' do
|
|
1864
1756
|
expect(selection).to eq(query)
|
|
1865
1757
|
end
|
|
1866
1758
|
|
|
1867
1759
|
it_behaves_like 'returns a cloned query'
|
|
1868
1760
|
end
|
|
1869
1761
|
|
|
1870
|
-
context
|
|
1871
|
-
|
|
1762
|
+
context 'when provided a single criterion' do
|
|
1872
1763
|
let(:selection) do
|
|
1873
1764
|
query.not(field: /test/)
|
|
1874
1765
|
end
|
|
1875
1766
|
|
|
1876
|
-
it
|
|
1767
|
+
it 'adds the $not selector' do
|
|
1877
1768
|
expect(selection.selector).to eq({
|
|
1878
|
-
|
|
1879
|
-
|
|
1769
|
+
'field' => { '$not' => /test/ }
|
|
1770
|
+
})
|
|
1880
1771
|
end
|
|
1881
1772
|
|
|
1882
1773
|
it_behaves_like 'returns a cloned query'
|
|
1883
1774
|
end
|
|
1884
1775
|
|
|
1885
|
-
context
|
|
1776
|
+
context 'when negating a field in the original selector' do
|
|
1886
1777
|
let(:query) do
|
|
1887
|
-
Mongoid::Query.new(
|
|
1778
|
+
Mongoid::Query.new('id' => '_id').where(field: 'foo')
|
|
1888
1779
|
end
|
|
1889
1780
|
|
|
1890
1781
|
let(:selection) do
|
|
1891
1782
|
query.not(field: 'bar')
|
|
1892
1783
|
end
|
|
1893
1784
|
|
|
1894
|
-
it
|
|
1785
|
+
it 'combines the conditions' do
|
|
1895
1786
|
expect(selection.selector).to eq({
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1787
|
+
'field' => 'foo',
|
|
1788
|
+
'$and' => [ { '$nor' => [ { 'field' => 'bar' } ] } ]
|
|
1789
|
+
})
|
|
1899
1790
|
end
|
|
1900
1791
|
|
|
1901
1792
|
it_behaves_like 'returns a cloned query'
|
|
1902
1793
|
end
|
|
1903
1794
|
|
|
1904
|
-
context
|
|
1905
|
-
|
|
1906
|
-
context "when the criteria are for different fields" do
|
|
1907
|
-
|
|
1795
|
+
context 'when provided multiple criteria' do
|
|
1796
|
+
context 'when the criteria are for different fields' do
|
|
1908
1797
|
let(:selection) do
|
|
1909
1798
|
query.not(first: /1/, second: /2/)
|
|
1910
1799
|
end
|
|
1911
1800
|
|
|
1912
|
-
it
|
|
1801
|
+
it 'adds the $not selectors' do
|
|
1913
1802
|
expect(selection.selector).to eq({
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1803
|
+
'first' => { '$not' => /1/ },
|
|
1804
|
+
'second' => { '$not' => /2/ }
|
|
1805
|
+
})
|
|
1917
1806
|
end
|
|
1918
1807
|
|
|
1919
1808
|
it_behaves_like 'returns a cloned query'
|
|
1920
1809
|
end
|
|
1921
1810
|
|
|
1922
|
-
context
|
|
1923
|
-
|
|
1811
|
+
context 'when the criteria are given in separate arguments' do
|
|
1924
1812
|
let(:selection) do
|
|
1925
|
-
query.not({first: /1/}, {second: /2/})
|
|
1813
|
+
query.not({ first: /1/ }, { second: /2/ })
|
|
1926
1814
|
end
|
|
1927
1815
|
|
|
1928
|
-
it
|
|
1816
|
+
it 'adds the $not selectors' do
|
|
1929
1817
|
expect(selection.selector).to eq({
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1818
|
+
'first' => { '$not' => /1/ },
|
|
1819
|
+
'second' => { '$not' => /2/ }
|
|
1820
|
+
})
|
|
1933
1821
|
end
|
|
1934
1822
|
|
|
1935
1823
|
it_behaves_like 'returns a cloned query'
|
|
1936
1824
|
end
|
|
1937
1825
|
end
|
|
1938
1826
|
|
|
1939
|
-
context
|
|
1940
|
-
|
|
1941
|
-
context "when the criterion are for different fields" do
|
|
1942
|
-
|
|
1827
|
+
context 'when chaining the criterion' do
|
|
1828
|
+
context 'when the criterion are for different fields' do
|
|
1943
1829
|
let(:selection) do
|
|
1944
1830
|
query.not(first: /1/).not(second: /2/)
|
|
1945
1831
|
end
|
|
1946
1832
|
|
|
1947
|
-
it
|
|
1833
|
+
it 'adds the $not selectors' do
|
|
1948
1834
|
expect(selection.selector).to eq({
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1835
|
+
'first' => { '$not' => /1/ },
|
|
1836
|
+
'second' => { '$not' => /2/ }
|
|
1837
|
+
})
|
|
1952
1838
|
end
|
|
1953
1839
|
|
|
1954
1840
|
it_behaves_like 'returns a cloned query'
|
|
1955
1841
|
end
|
|
1956
1842
|
|
|
1957
|
-
context
|
|
1958
|
-
|
|
1843
|
+
context 'when the criterion are on the same field' do
|
|
1959
1844
|
let(:selection) do
|
|
1960
1845
|
query.not(first: /1/).not(first: /2/)
|
|
1961
1846
|
end
|
|
1962
1847
|
|
|
1963
|
-
it
|
|
1848
|
+
it 'combines conditions' do
|
|
1964
1849
|
expect(selection.selector).to eq(
|
|
1965
|
-
|
|
1966
|
-
'$and' => [{'$nor' => [{'first' => /2/}]}]
|
|
1850
|
+
'first' => { '$not' => /1/ },
|
|
1851
|
+
'$and' => [ { '$nor' => [ { 'first' => /2/ } ] } ]
|
|
1967
1852
|
)
|
|
1968
1853
|
end
|
|
1969
1854
|
|
|
1970
1855
|
it_behaves_like 'returns a cloned query'
|
|
1971
1856
|
end
|
|
1972
1857
|
|
|
1973
|
-
context
|
|
1974
|
-
|
|
1858
|
+
context 'when the criterion are a double negative' do
|
|
1975
1859
|
let(:selection) do
|
|
1976
1860
|
query.not.where(:first.not => /1/)
|
|
1977
1861
|
end
|
|
1978
1862
|
|
|
1979
|
-
it
|
|
1863
|
+
it 'does not double the $not selector' do
|
|
1980
1864
|
expect(selection.selector).to eq({
|
|
1981
|
-
|
|
1982
|
-
|
|
1865
|
+
'first' => { '$not' => /1/ }
|
|
1866
|
+
})
|
|
1983
1867
|
end
|
|
1984
1868
|
|
|
1985
1869
|
it_behaves_like 'returns a cloned query'
|
|
@@ -1998,7 +1882,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
1998
1882
|
let(:result) { query.not(other) }
|
|
1999
1883
|
|
|
2000
1884
|
it 'combines' do
|
|
2001
|
-
expect(result.selector).to eq('hello' => 'world', 'foo' => {'$ne' => 'bar'})
|
|
1885
|
+
expect(result.selector).to eq('hello' => 'world', 'foo' => { '$ne' => 'bar' })
|
|
2002
1886
|
end
|
|
2003
1887
|
end
|
|
2004
1888
|
|
|
@@ -2015,7 +1899,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2015
1899
|
|
|
2016
1900
|
it 'combines fields into top level criteria' do
|
|
2017
1901
|
expect(result.selector).to eq('hello' => 'world',
|
|
2018
|
-
|
|
1902
|
+
'a' => { '$ne' => 1 }, 'b' => { '$ne' => 2 })
|
|
2019
1903
|
end
|
|
2020
1904
|
end
|
|
2021
1905
|
|
|
@@ -2025,14 +1909,15 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2025
1909
|
end
|
|
2026
1910
|
|
|
2027
1911
|
let(:other) do
|
|
2028
|
-
Mongoid::Query.new.where('$nor' => [{a: 1, b: 2}])
|
|
1912
|
+
Mongoid::Query.new.where('$nor' => [ { a: 1, b: 2 } ])
|
|
2029
1913
|
end
|
|
2030
1914
|
|
|
2031
1915
|
let(:result) { query.not(other) }
|
|
2032
1916
|
|
|
2033
1917
|
it 'combines with $and of $nor' do
|
|
2034
|
-
expect(result.selector).to eq('hello' => 'world', '$and' => [{'$nor' => [{
|
|
2035
|
-
|
|
1918
|
+
expect(result.selector).to eq('hello' => 'world', '$and' => [ { '$nor' => [ {
|
|
1919
|
+
'$nor' => [ { 'a' => 1, 'b' => 2 } ]
|
|
1920
|
+
} ] } ])
|
|
2036
1921
|
end
|
|
2037
1922
|
end
|
|
2038
1923
|
|
|
@@ -2046,7 +1931,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2046
1931
|
end
|
|
2047
1932
|
|
|
2048
1933
|
let(:other2) do
|
|
2049
|
-
{bar: 42}
|
|
1934
|
+
{ bar: 42 }
|
|
2050
1935
|
end
|
|
2051
1936
|
|
|
2052
1937
|
let(:other3) do
|
|
@@ -2057,26 +1942,24 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2057
1942
|
|
|
2058
1943
|
it 'combines' do
|
|
2059
1944
|
expect(result.selector).to eq('hello' => 'world',
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
)
|
|
1945
|
+
'foo' => { '$ne' => 'bar' },
|
|
1946
|
+
'bar' => { '$ne' => 42 },
|
|
1947
|
+
'a' => { '$ne' => 2 })
|
|
2064
1948
|
end
|
|
2065
1949
|
end
|
|
2066
1950
|
|
|
2067
1951
|
context 'when giving multiple conditions in one call on the same key with symbol operator' do
|
|
2068
|
-
|
|
2069
1952
|
context 'non-regexp argument' do
|
|
2070
1953
|
let(:selection) do
|
|
2071
1954
|
query.not(field: 1, :field.gt => 0)
|
|
2072
1955
|
end
|
|
2073
1956
|
|
|
2074
1957
|
it 'combines conditions with $eq' do
|
|
2075
|
-
selection.selector.should
|
|
2076
|
-
'$and' => ['$nor' => [
|
|
2077
|
-
'field' => {'$eq' => 1, '$gt' => 0}
|
|
2078
|
-
]]
|
|
2079
|
-
|
|
1958
|
+
selection.selector.should eq(
|
|
1959
|
+
'$and' => [ { '$nor' => [
|
|
1960
|
+
{ 'field' => { '$eq' => 1, '$gt' => 0 } }
|
|
1961
|
+
] } ]
|
|
1962
|
+
)
|
|
2080
1963
|
end
|
|
2081
1964
|
end
|
|
2082
1965
|
|
|
@@ -2086,39 +1969,40 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2086
1969
|
end
|
|
2087
1970
|
|
|
2088
1971
|
it 'combines conditions with $regex' do
|
|
2089
|
-
selection.selector.should
|
|
2090
|
-
'$and' => ['$nor' => [
|
|
2091
|
-
'field' => {'$regex' => /t/, '$gt' => 0}
|
|
2092
|
-
]]
|
|
2093
|
-
|
|
1972
|
+
selection.selector.should eq(
|
|
1973
|
+
'$and' => [ { '$nor' => [
|
|
1974
|
+
{ 'field' => { '$regex' => /t/, '$gt' => 0 } }
|
|
1975
|
+
] } ]
|
|
1976
|
+
)
|
|
2094
1977
|
end
|
|
2095
1978
|
end
|
|
2096
1979
|
end
|
|
2097
1980
|
|
|
2098
1981
|
# This test confirms that MONGOID-5097 has been repaired.
|
|
2099
|
-
context
|
|
1982
|
+
context 'when using exists on a field of type Time' do
|
|
2100
1983
|
let(:criteria) do
|
|
2101
|
-
Dictionary.any_of({:published.exists => true}, published: nil)
|
|
1984
|
+
Dictionary.any_of({ :published.exists => true }, published: nil)
|
|
2102
1985
|
end
|
|
2103
1986
|
|
|
2104
1987
|
it "doesn't raise an error" do
|
|
2105
1988
|
expect do
|
|
2106
1989
|
criteria
|
|
2107
|
-
end.
|
|
1990
|
+
end.not_to raise_error
|
|
2108
1991
|
end
|
|
2109
1992
|
|
|
2110
|
-
it
|
|
1993
|
+
it 'generates the correct selector' do
|
|
2111
1994
|
expect(criteria.selector).to eq({
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
1995
|
+
'$or' => [ {
|
|
1996
|
+
'published' => { '$exists' => true }
|
|
1997
|
+
}, {
|
|
1998
|
+
'published' => nil
|
|
1999
|
+
} ]
|
|
2000
|
+
})
|
|
2117
2001
|
end
|
|
2118
2002
|
end
|
|
2119
2003
|
end
|
|
2120
2004
|
|
|
2121
|
-
describe
|
|
2005
|
+
describe '#none_of' do
|
|
2122
2006
|
context 'when argument is a mix of Criteria and hashes' do
|
|
2123
2007
|
let(:query) { Mongoid::Query.new.where(hello: 'world') }
|
|
2124
2008
|
let(:other1) { Mongoid::Query.new.where(foo: 'bar') }
|
|
@@ -2131,72 +2015,72 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2131
2015
|
expect(result.selector).to eq(
|
|
2132
2016
|
'hello' => 'world',
|
|
2133
2017
|
'$nor' => [
|
|
2134
|
-
{'foo' => 'bar'},
|
|
2135
|
-
{'bar' => 42},
|
|
2136
|
-
{'a' => 2}
|
|
2137
|
-
]
|
|
2018
|
+
{ 'foo' => 'bar' },
|
|
2019
|
+
{ 'bar' => 42 },
|
|
2020
|
+
{ 'a' => 2 }
|
|
2021
|
+
]
|
|
2138
2022
|
)
|
|
2139
2023
|
end
|
|
2140
2024
|
end
|
|
2141
2025
|
|
|
2142
|
-
context
|
|
2026
|
+
context 'when provided no arguments' do
|
|
2143
2027
|
let(:selection) { query.none_of }
|
|
2144
2028
|
|
|
2145
2029
|
it_behaves_like 'returns a cloned query'
|
|
2146
2030
|
|
|
2147
|
-
it
|
|
2031
|
+
it 'does not add any criteria' do
|
|
2148
2032
|
expect(selection.selector).to eq({})
|
|
2149
2033
|
end
|
|
2150
2034
|
|
|
2151
|
-
it
|
|
2035
|
+
it 'returns the query' do
|
|
2152
2036
|
expect(selection).to eq(query)
|
|
2153
2037
|
end
|
|
2154
2038
|
end
|
|
2155
2039
|
|
|
2156
|
-
context
|
|
2040
|
+
context 'when provided nil' do
|
|
2157
2041
|
let(:selection) { query.none_of(nil) }
|
|
2158
2042
|
|
|
2159
2043
|
it_behaves_like 'returns a cloned query'
|
|
2160
2044
|
|
|
2161
|
-
it
|
|
2045
|
+
it 'does not add any criteria' do
|
|
2162
2046
|
expect(selection.selector).to eq({})
|
|
2163
2047
|
end
|
|
2164
2048
|
|
|
2165
|
-
it
|
|
2049
|
+
it 'returns the query' do
|
|
2166
2050
|
expect(selection).to eq(query)
|
|
2167
2051
|
end
|
|
2168
2052
|
end
|
|
2169
2053
|
|
|
2170
|
-
context
|
|
2054
|
+
context 'when provided a single criterion' do
|
|
2171
2055
|
let(:selection) { query.none_of(field: [ 1, 2 ]) }
|
|
2172
2056
|
|
|
2173
2057
|
it_behaves_like 'returns a cloned query'
|
|
2174
2058
|
|
|
2175
2059
|
it 'adds the $nor selector' do
|
|
2176
2060
|
expect(selection.selector).to eq(
|
|
2177
|
-
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2061
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2178
2062
|
)
|
|
2179
2063
|
end
|
|
2180
2064
|
|
|
2181
2065
|
context 'when the criterion is wrapped in array' do
|
|
2182
|
-
let(:selection) { query.none_of([{ field: [ 1, 2 ] }]) }
|
|
2066
|
+
let(:selection) { query.none_of([ { field: [ 1, 2 ] } ]) }
|
|
2183
2067
|
|
|
2184
2068
|
it_behaves_like 'returns a cloned query'
|
|
2185
2069
|
|
|
2186
2070
|
it 'adds the condition' do
|
|
2187
2071
|
expect(selection.selector).to eq(
|
|
2188
|
-
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2072
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2189
2073
|
)
|
|
2190
2074
|
end
|
|
2191
2075
|
|
|
2192
2076
|
context 'when the array has nil as one of the elements' do
|
|
2193
|
-
let(:selection) { query.none_of([{ field: [ 1, 2 ] }, nil]) }
|
|
2077
|
+
let(:selection) { query.none_of([ { field: [ 1, 2 ] }, nil ]) }
|
|
2194
2078
|
|
|
2195
2079
|
it_behaves_like 'returns a cloned query'
|
|
2196
2080
|
|
|
2197
2081
|
it 'adds the $nor selector ignoring the nil element' do
|
|
2198
2082
|
expect(selection.selector).to eq(
|
|
2199
|
-
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2083
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2200
2084
|
)
|
|
2201
2085
|
end
|
|
2202
2086
|
end
|
|
@@ -2209,7 +2093,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2209
2093
|
it 'adds the new condition' do
|
|
2210
2094
|
expect(selection.selector).to eq(
|
|
2211
2095
|
'foo' => 'bar',
|
|
2212
|
-
'$nor' => [ { 'field' => [1, 2] } ]
|
|
2096
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ]
|
|
2213
2097
|
)
|
|
2214
2098
|
end
|
|
2215
2099
|
end
|
|
@@ -2223,9 +2107,9 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2223
2107
|
expect(selection.selector).to eq(
|
|
2224
2108
|
'foo' => 'bar',
|
|
2225
2109
|
'$nor' => [
|
|
2226
|
-
{ 'field' => [1, 2] },
|
|
2227
|
-
{ 'hello' => 'world' }
|
|
2228
|
-
]
|
|
2110
|
+
{ 'field' => [ 1, 2 ] },
|
|
2111
|
+
{ 'hello' => 'world' }
|
|
2112
|
+
]
|
|
2229
2113
|
)
|
|
2230
2114
|
end
|
|
2231
2115
|
end
|
|
@@ -2238,7 +2122,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2238
2122
|
|
|
2239
2123
|
it 'adds the new condition' do
|
|
2240
2124
|
expect(selection.selector).to eq(
|
|
2241
|
-
'$nor' => [ { 'field' => [1, 2] } ],
|
|
2125
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ],
|
|
2242
2126
|
'foo' => 'bar',
|
|
2243
2127
|
'$and' => [ { '$nor' => [ { 'test' => 1 } ] } ]
|
|
2244
2128
|
)
|
|
@@ -2247,65 +2131,65 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2247
2131
|
|
|
2248
2132
|
context 'when none_of has multiple arguments' do
|
|
2249
2133
|
let(:selection) do
|
|
2250
|
-
query.nor(field: [ 1, 2 ]).where(foo: 'bar').none_of({a: 1}, {b: 2})
|
|
2134
|
+
query.nor(field: [ 1, 2 ]).where(foo: 'bar').none_of({ a: 1 }, { b: 2 })
|
|
2251
2135
|
end
|
|
2252
2136
|
|
|
2253
2137
|
it 'adds the new condition to top level' do
|
|
2254
2138
|
expect(selection.selector).to eq(
|
|
2255
2139
|
'foo' => 'bar',
|
|
2256
|
-
'$nor' => [ { 'field' => [1, 2] } ],
|
|
2140
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ],
|
|
2257
2141
|
'$and' => [ { '$nor' => [ { 'a' => 1 }, { 'b' => 2 } ] } ]
|
|
2258
2142
|
)
|
|
2259
2143
|
end
|
|
2260
2144
|
|
|
2261
2145
|
context 'when query already has a top-level $and' do
|
|
2262
2146
|
let(:selection) do
|
|
2263
|
-
query.nor(field: [ 1, 2 ]).where('$and' => [foo: 'bar']).none_of({a: 1}, {b: 2})
|
|
2147
|
+
query.nor(field: [ 1, 2 ]).where('$and' => [ { foo: 'bar' } ]).none_of({ a: 1 }, { b: 2 })
|
|
2264
2148
|
end
|
|
2265
2149
|
|
|
2266
2150
|
it 'adds the new condition to top level $and' do
|
|
2267
2151
|
expect(selection.selector).to eq(
|
|
2268
|
-
'$nor' => [ { 'field' => [1, 2] } ],
|
|
2152
|
+
'$nor' => [ { 'field' => [ 1, 2 ] } ],
|
|
2269
2153
|
'$and' => [
|
|
2270
2154
|
{ 'foo' => 'bar' },
|
|
2271
2155
|
{ '$nor' => [ { 'a' => 1 }, { 'b' => 2 } ] }
|
|
2272
|
-
]
|
|
2156
|
+
]
|
|
2273
2157
|
)
|
|
2274
2158
|
end
|
|
2275
2159
|
end
|
|
2276
2160
|
end
|
|
2277
2161
|
end
|
|
2278
2162
|
|
|
2279
|
-
context
|
|
2280
|
-
context
|
|
2163
|
+
context 'when provided multiple criteria' do
|
|
2164
|
+
context 'when the criteria are for different fields' do
|
|
2281
2165
|
let(:selection) do
|
|
2282
2166
|
query.none_of({ first: [ 1, 2 ] }, { second: [ 3, 4 ] })
|
|
2283
2167
|
end
|
|
2284
2168
|
|
|
2285
2169
|
it_behaves_like 'returns a cloned query'
|
|
2286
2170
|
|
|
2287
|
-
it
|
|
2171
|
+
it 'adds the $nor selector' do
|
|
2288
2172
|
expect(selection.selector).to eq({
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2173
|
+
'$nor' => [
|
|
2174
|
+
{ 'first' => [ 1, 2 ] },
|
|
2175
|
+
{ 'second' => [ 3, 4 ] }
|
|
2176
|
+
]
|
|
2177
|
+
})
|
|
2294
2178
|
end
|
|
2295
2179
|
end
|
|
2296
2180
|
|
|
2297
|
-
context
|
|
2181
|
+
context 'when the criteria uses a Key instance' do
|
|
2298
2182
|
let(:selection) do
|
|
2299
2183
|
query.none_of({ first: [ 1, 2 ] }, { :second.gt => 3 })
|
|
2300
2184
|
end
|
|
2301
2185
|
|
|
2302
|
-
it
|
|
2186
|
+
it 'adds the $nor selector' do
|
|
2303
2187
|
expect(selection.selector).to eq({
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2188
|
+
'$nor' => [
|
|
2189
|
+
{ 'first' => [ 1, 2 ] },
|
|
2190
|
+
{ 'second' => { '$gt' => 3 } }
|
|
2191
|
+
]
|
|
2192
|
+
})
|
|
2309
2193
|
end
|
|
2310
2194
|
|
|
2311
2195
|
it_behaves_like 'returns a cloned query'
|
|
@@ -2313,23 +2197,23 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2313
2197
|
|
|
2314
2198
|
context 'when criteria are simple and handled via Key' do
|
|
2315
2199
|
shared_examples_for 'adds conditions with $nor' do
|
|
2316
|
-
it
|
|
2200
|
+
it 'adds conditions with $nor' do
|
|
2317
2201
|
expect(selection.selector).to eq({
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2202
|
+
'$nor' => [
|
|
2203
|
+
{ 'field' => 3 },
|
|
2204
|
+
{ 'field' => { '$lt' => 5 } }
|
|
2205
|
+
]
|
|
2206
|
+
})
|
|
2323
2207
|
end
|
|
2324
2208
|
|
|
2325
2209
|
it_behaves_like 'returns a cloned query'
|
|
2326
2210
|
end
|
|
2327
2211
|
|
|
2328
2212
|
shared_examples_for 'combines conditions with $eq' do
|
|
2329
|
-
it
|
|
2213
|
+
it 'combines conditions with $eq' do
|
|
2330
2214
|
expect(selection.selector).to eq({
|
|
2331
|
-
|
|
2332
|
-
|
|
2215
|
+
'$nor' => [ { 'field' => { '$eq' => 3, '$lt' => 5 } } ]
|
|
2216
|
+
})
|
|
2333
2217
|
end
|
|
2334
2218
|
|
|
2335
2219
|
it_behaves_like 'returns a cloned query'
|
|
@@ -2338,8 +2222,8 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2338
2222
|
shared_examples_for 'combines conditions with $regex' do
|
|
2339
2223
|
it 'combines conditions with $regex' do
|
|
2340
2224
|
expect(selection.selector).to eq({
|
|
2341
|
-
|
|
2342
|
-
|
|
2225
|
+
'$nor' => [ { 'field' => { '$regex' => /t/, '$lt' => 5 } } ]
|
|
2226
|
+
})
|
|
2343
2227
|
end
|
|
2344
2228
|
|
|
2345
2229
|
it_behaves_like 'returns a cloned query'
|
|
@@ -2348,22 +2232,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2348
2232
|
context 'criteria are provided in the same hash' do
|
|
2349
2233
|
context 'non-regexp argument' do
|
|
2350
2234
|
let(:selection) { query.none_of(:field => 3, :field.lt => 5) }
|
|
2235
|
+
|
|
2351
2236
|
it_behaves_like 'combines conditions with $eq'
|
|
2352
2237
|
end
|
|
2353
2238
|
|
|
2354
2239
|
context 'regexp argument' do
|
|
2355
2240
|
let(:selection) { query.none_of(:field => /t/, :field.lt => 5) }
|
|
2241
|
+
|
|
2356
2242
|
it_behaves_like 'combines conditions with $regex'
|
|
2357
2243
|
end
|
|
2358
2244
|
end
|
|
2359
2245
|
|
|
2360
2246
|
context 'criteria are provided in separate hashes' do
|
|
2361
|
-
let(:selection) { query.none_of({:
|
|
2247
|
+
let(:selection) { query.none_of({ field: 3 }, { :field.lt => 5 }) }
|
|
2248
|
+
|
|
2362
2249
|
it_behaves_like 'adds conditions with $nor'
|
|
2363
2250
|
end
|
|
2364
2251
|
|
|
2365
2252
|
context 'when the criterion is wrapped in an array' do
|
|
2366
|
-
let(:selection) { query.none_of([:
|
|
2253
|
+
let(:selection) { query.none_of([ { field: 3 } ], [ { :field.lt => 5 } ]) }
|
|
2254
|
+
|
|
2367
2255
|
it_behaves_like 'adds conditions with $nor'
|
|
2368
2256
|
end
|
|
2369
2257
|
end
|
|
@@ -2372,11 +2260,11 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2372
2260
|
shared_examples_for 'adds conditions with $nor' do
|
|
2373
2261
|
it 'adds conditions with $nor' do
|
|
2374
2262
|
expect(selection.selector).to eq({
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2263
|
+
'$nor' => [
|
|
2264
|
+
{ 'field' => { '$gt' => 3 } },
|
|
2265
|
+
{ 'field' => 5 }
|
|
2266
|
+
]
|
|
2267
|
+
})
|
|
2380
2268
|
end
|
|
2381
2269
|
|
|
2382
2270
|
it_behaves_like 'returns a cloned query'
|
|
@@ -2385,7 +2273,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2385
2273
|
shared_examples_for 'combines conditions with $eq' do
|
|
2386
2274
|
it 'combines conditions with $eq' do
|
|
2387
2275
|
expect(selection.selector).to eq(
|
|
2388
|
-
'$nor' => [ { 'field' => {'$gt' => 3, '$eq' => 5} } ]
|
|
2276
|
+
'$nor' => [ { 'field' => { '$gt' => 3, '$eq' => 5 } } ]
|
|
2389
2277
|
)
|
|
2390
2278
|
end
|
|
2391
2279
|
|
|
@@ -2395,7 +2283,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2395
2283
|
shared_examples_for 'combines conditions with $regex' do
|
|
2396
2284
|
it 'combines conditions with $regex' do
|
|
2397
2285
|
expect(selection.selector).to eq(
|
|
2398
|
-
'$nor' => [ { 'field' => {'$gt' => 3, '$regex' => /t/} } ]
|
|
2286
|
+
'$nor' => [ { 'field' => { '$gt' => 3, '$regex' => /t/ } } ]
|
|
2399
2287
|
)
|
|
2400
2288
|
end
|
|
2401
2289
|
|
|
@@ -2405,22 +2293,26 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2405
2293
|
context 'criteria are provided in the same hash' do
|
|
2406
2294
|
context 'non-regexp argument' do
|
|
2407
2295
|
let(:selection) { query.none_of(:field.gt => 3, :field => 5) }
|
|
2296
|
+
|
|
2408
2297
|
it_behaves_like 'combines conditions with $eq'
|
|
2409
2298
|
end
|
|
2410
2299
|
|
|
2411
2300
|
context 'regexp argument' do
|
|
2412
2301
|
let(:selection) { query.none_of(:field.gt => 3, :field => /t/) }
|
|
2302
|
+
|
|
2413
2303
|
it_behaves_like 'combines conditions with $regex'
|
|
2414
2304
|
end
|
|
2415
2305
|
end
|
|
2416
2306
|
|
|
2417
2307
|
context 'criteria are provided in separate hashes' do
|
|
2418
|
-
let(:selection) { query.none_of({:field.gt => 3}, {:
|
|
2308
|
+
let(:selection) { query.none_of({ :field.gt => 3 }, { field: 5 }) }
|
|
2309
|
+
|
|
2419
2310
|
it_behaves_like 'adds conditions with $nor'
|
|
2420
2311
|
end
|
|
2421
2312
|
|
|
2422
2313
|
context 'when the criterion is wrapped in an array' do
|
|
2423
|
-
let(:selection) { query.none_of([:field.gt => 3], [:
|
|
2314
|
+
let(:selection) { query.none_of([ { :field.gt => 3 } ], [ { field: 5 } ]) }
|
|
2315
|
+
|
|
2424
2316
|
it_behaves_like 'adds conditions with $nor'
|
|
2425
2317
|
end
|
|
2426
2318
|
end
|
|
@@ -2429,7 +2321,7 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2429
2321
|
let(:selection) { query.none_of({ id: 1 }) }
|
|
2430
2322
|
|
|
2431
2323
|
it 'adds the $nor selector and aliases the field' do
|
|
2432
|
-
expect(selection.selector).to eq('$nor' => [{ '_id' => 1 }])
|
|
2324
|
+
expect(selection.selector).to eq('$nor' => [ { '_id' => 1 } ])
|
|
2433
2325
|
end
|
|
2434
2326
|
|
|
2435
2327
|
it_behaves_like 'returns a cloned query'
|
|
@@ -2437,22 +2329,22 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2437
2329
|
|
|
2438
2330
|
context 'when a criterion is wrapped in an array' do
|
|
2439
2331
|
let(:selection) do
|
|
2440
|
-
query.none_of([{ first: [ 1, 2 ] }, { :second.gt => 3 }])
|
|
2332
|
+
query.none_of([ { first: [ 1, 2 ] }, { :second.gt => 3 } ])
|
|
2441
2333
|
end
|
|
2442
2334
|
|
|
2443
2335
|
it_behaves_like 'returns a cloned query'
|
|
2444
2336
|
|
|
2445
2337
|
it 'adds the $ nor selector' do
|
|
2446
2338
|
expect(selection.selector).to eq({
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2339
|
+
'$nor' => [
|
|
2340
|
+
{ 'first' => [ 1, 2 ] },
|
|
2341
|
+
{ 'second' => { '$gt' => 3 } }
|
|
2342
|
+
]
|
|
2343
|
+
})
|
|
2452
2344
|
end
|
|
2453
2345
|
end
|
|
2454
2346
|
|
|
2455
|
-
context
|
|
2347
|
+
context 'when the criteria are on the same field' do
|
|
2456
2348
|
let(:selection) do
|
|
2457
2349
|
query.none_of({ first: [ 1, 2 ] }, { first: [ 3, 4 ] })
|
|
2458
2350
|
end
|
|
@@ -2461,11 +2353,11 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2461
2353
|
|
|
2462
2354
|
it 'appends both $nor expressions' do
|
|
2463
2355
|
expect(selection.selector).to eq({
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2356
|
+
'$nor' => [
|
|
2357
|
+
{ 'first' => [ 1, 2 ] },
|
|
2358
|
+
{ 'first' => [ 3, 4 ] }
|
|
2359
|
+
]
|
|
2360
|
+
})
|
|
2469
2361
|
end
|
|
2470
2362
|
end
|
|
2471
2363
|
end
|
|
@@ -2481,12 +2373,12 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2481
2373
|
it 'adds the conditions separately' do
|
|
2482
2374
|
expect(selection.selector).to eq(
|
|
2483
2375
|
'$nor' => [ { 'first' => [ 1, 2 ] } ],
|
|
2484
|
-
'$and' => [ { '$nor' => [ { 'second' => [ 3, 4 ] } ] } ]
|
|
2376
|
+
'$and' => [ { '$nor' => [ { 'second' => [ 3, 4 ] } ] } ]
|
|
2485
2377
|
)
|
|
2486
2378
|
end
|
|
2487
2379
|
end
|
|
2488
2380
|
|
|
2489
|
-
context
|
|
2381
|
+
context 'when the criteria are on the same field' do
|
|
2490
2382
|
let(:selection) do
|
|
2491
2383
|
query.none_of(first: [ 1, 2 ]).none_of(first: [ 3, 4 ])
|
|
2492
2384
|
end
|
|
@@ -2505,33 +2397,37 @@ describe Mongoid::Criteria::Queryable::Selectable do
|
|
|
2505
2397
|
context 'when using multiple criteria and symbol operators' do
|
|
2506
2398
|
context 'when using fields that meaningfully evolve values' do
|
|
2507
2399
|
let(:query) do
|
|
2508
|
-
Dictionary.none_of({a: 1}, :published.gt => Date.new(2020, 2, 3))
|
|
2400
|
+
Dictionary.none_of({ a: 1 }, :published.gt => Date.new(2020, 2, 3))
|
|
2509
2401
|
end
|
|
2510
2402
|
|
|
2511
2403
|
it 'generates the expected query' do
|
|
2512
|
-
query.selector.should
|
|
2513
|
-
{'
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2404
|
+
query.selector.should eq(
|
|
2405
|
+
{ '$nor' => [
|
|
2406
|
+
{ 'a' => 1 },
|
|
2407
|
+
# Date instance is converted to a Time instance in local time,
|
|
2408
|
+
# because we are querying on a Time field and dates are interpreted
|
|
2409
|
+
# in local time when assigning to Time fields
|
|
2410
|
+
{ 'published' => { '$gt' => Time.zone.local(2020, 2, 3) } }
|
|
2411
|
+
] }
|
|
2412
|
+
)
|
|
2519
2413
|
end
|
|
2520
2414
|
end
|
|
2521
2415
|
|
|
2522
2416
|
context 'when using fields that do not meaningfully evolve values' do
|
|
2523
2417
|
let(:query) do
|
|
2524
|
-
Dictionary.none_of({a: 1}, :submitted_on.gt => Date.new(2020, 2, 3))
|
|
2418
|
+
Dictionary.none_of({ a: 1 }, :submitted_on.gt => Date.new(2020, 2, 3))
|
|
2525
2419
|
end
|
|
2526
2420
|
|
|
2527
2421
|
it 'generates the expected query' do
|
|
2528
|
-
query.selector.should
|
|
2529
|
-
{'
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2422
|
+
query.selector.should eq(
|
|
2423
|
+
{ '$nor' => [
|
|
2424
|
+
{ 'a' => 1 },
|
|
2425
|
+
# Date instance is converted to a Time instance in UTC,
|
|
2426
|
+
# because we are querying on a Date field and dates are interpreted
|
|
2427
|
+
# in UTC when persisted as dates by Mongoid
|
|
2428
|
+
{ 'submitted_on' => { '$gt' => Time.utc(2020, 2, 3) } }
|
|
2429
|
+
] }
|
|
2430
|
+
)
|
|
2535
2431
|
end
|
|
2536
2432
|
end
|
|
2537
2433
|
end
|