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