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