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