mongoid 7.0.13 → 9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -41
- data/LICENSE +1 -1
- data/README.md +29 -25
- data/Rakefile +150 -40
- data/lib/config/locales/en.yml +364 -108
- data/lib/mongoid/association/accessors.rb +205 -107
- data/lib/mongoid/association/bindable.rb +102 -56
- data/lib/mongoid/association/builders.rb +24 -26
- data/lib/mongoid/association/constrainable.rb +8 -11
- data/lib/mongoid/association/depending.rb +65 -59
- data/lib/mongoid/association/eager.rb +203 -0
- data/lib/mongoid/association/eager_load/discriminated_inclusion.rb +88 -0
- data/lib/mongoid/association/eager_load/embedded_distributor.rb +151 -0
- data/lib/mongoid/association/eager_load/inclusion.rb +173 -0
- data/lib/mongoid/association/eager_load/inclusion_tree.rb +96 -0
- data/lib/mongoid/association/eager_load/lookup_pipeline.rb +121 -0
- data/lib/mongoid/association/eager_load/polymorphic_preloader.rb +61 -0
- data/lib/mongoid/association/eager_load/polymorphic_targets.rb +151 -0
- data/lib/mongoid/association/eager_loadable.rb +135 -15
- data/lib/mongoid/association/embedded/batchable.rb +87 -75
- data/lib/mongoid/association/embedded/cyclic.rb +16 -25
- data/lib/mongoid/association/embedded/eager.rb +18 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +30 -14
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +10 -7
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +39 -32
- data/lib/mongoid/association/embedded/embedded_in.rb +37 -46
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +7 -11
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +11 -7
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +309 -243
- data/lib/mongoid/association/embedded/embeds_many.rb +32 -56
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +6 -11
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +25 -11
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +145 -53
- data/lib/mongoid/association/embedded/embeds_one.rb +30 -50
- data/lib/mongoid/association/embedded.rb +3 -0
- data/lib/mongoid/association/macros.rb +97 -56
- data/lib/mongoid/association/many.rb +99 -36
- data/lib/mongoid/association/marshalable.rb +5 -7
- data/lib/mongoid/association/nested/many.rb +86 -47
- data/lib/mongoid/association/nested/nested_buildable.rb +58 -21
- data/lib/mongoid/association/nested/one.rb +81 -36
- data/lib/mongoid/association/nested.rb +4 -5
- data/lib/mongoid/association/one.rb +5 -14
- data/lib/mongoid/association/options.rb +48 -53
- data/lib/mongoid/association/proxy.rb +65 -54
- data/lib/mongoid/association/referenced/auto_save.rb +59 -20
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +21 -22
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +32 -11
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +47 -6
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +35 -42
- data/lib/mongoid/association/referenced/belongs_to.rb +77 -77
- data/lib/mongoid/association/referenced/counter_cache.rb +24 -35
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +26 -15
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +12 -7
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +3 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +202 -133
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +81 -83
- data/lib/mongoid/association/referenced/has_many/binding.rb +3 -7
- data/lib/mongoid/association/referenced/has_many/buildable.rb +15 -8
- data/lib/mongoid/association/referenced/has_many/eager.rb +3 -4
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +601 -456
- data/lib/mongoid/association/referenced/has_many/proxy.rb +344 -216
- data/lib/mongoid/association/referenced/has_many.rb +58 -74
- data/lib/mongoid/association/referenced/has_many_through/eager.rb +99 -0
- data/lib/mongoid/association/referenced/has_many_through/proxy.rb +68 -0
- data/lib/mongoid/association/referenced/has_many_through.rb +201 -0
- data/lib/mongoid/association/referenced/has_one/binding.rb +4 -10
- data/lib/mongoid/association/referenced/has_one/buildable.rb +29 -17
- data/lib/mongoid/association/referenced/has_one/eager.rb +4 -6
- data/lib/mongoid/association/referenced/has_one/proxy.rb +51 -47
- data/lib/mongoid/association/referenced/has_one.rb +45 -55
- data/lib/mongoid/association/referenced/has_one_through/eager.rb +65 -0
- data/lib/mongoid/association/referenced/has_one_through/proxy.rb +30 -0
- data/lib/mongoid/association/referenced/has_one_through.rb +167 -0
- data/lib/mongoid/association/referenced/syncable.rb +44 -62
- data/lib/mongoid/association/referenced/with_polymorphic_criteria.rb +41 -0
- data/lib/mongoid/association/referenced.rb +4 -0
- data/lib/mongoid/association/reflections.rb +11 -12
- data/lib/mongoid/association/relatable.rb +173 -146
- data/lib/mongoid/association.rb +35 -40
- data/lib/mongoid/atomic/modifiers.rb +91 -74
- data/lib/mongoid/atomic/paths/embedded/many.rb +25 -11
- data/lib/mongoid/atomic/paths/embedded/one.rb +6 -10
- data/lib/mongoid/atomic/paths/embedded.rb +5 -8
- data/lib/mongoid/atomic/paths/root.rb +5 -10
- data/lib/mongoid/atomic/paths.rb +4 -3
- data/lib/mongoid/atomic.rb +41 -89
- data/lib/mongoid/atomic_update_preparer.rb +89 -0
- data/lib/mongoid/attributes/dynamic.rb +12 -27
- data/lib/mongoid/attributes/embedded.rb +34 -0
- data/lib/mongoid/attributes/nested.rb +22 -25
- data/lib/mongoid/attributes/processing.rb +51 -34
- data/lib/mongoid/attributes/projector.rb +107 -0
- data/lib/mongoid/attributes/readonly.rb +15 -17
- data/lib/mongoid/attributes.rb +119 -126
- data/lib/mongoid/cacheable.rb +30 -14
- data/lib/mongoid/changeable.rb +196 -99
- data/lib/mongoid/clients/factory.rb +73 -17
- data/lib/mongoid/clients/options.rb +140 -19
- data/lib/mongoid/clients/sessions.rb +239 -87
- data/lib/mongoid/clients/storage_options.rb +42 -17
- data/lib/mongoid/clients/validators/storage.rb +6 -25
- data/lib/mongoid/clients/validators.rb +3 -2
- data/lib/mongoid/clients.rb +44 -22
- data/lib/mongoid/collection_configurable.rb +63 -0
- data/lib/mongoid/composable.rb +40 -39
- data/lib/mongoid/config/defaults.rb +46 -0
- data/lib/mongoid/config/encryption.rb +228 -0
- data/lib/mongoid/config/environment.rb +26 -13
- data/lib/mongoid/config/introspection.rb +150 -0
- data/lib/mongoid/config/options.rb +37 -26
- data/lib/mongoid/config/validators/async_query_executor.rb +31 -0
- data/lib/mongoid/config/validators/client.rb +20 -37
- data/lib/mongoid/config/validators/option.rb +5 -7
- data/lib/mongoid/config/validators.rb +5 -3
- data/lib/mongoid/config.rb +418 -60
- data/lib/mongoid/contextual/aggregable/memory.rb +45 -28
- data/lib/mongoid/contextual/aggregable/mongo.rb +49 -47
- data/lib/mongoid/contextual/aggregable/none.rb +64 -0
- data/lib/mongoid/contextual/aggregable.rb +16 -0
- data/lib/mongoid/contextual/atomic.rb +126 -45
- data/lib/mongoid/contextual/command.rb +3 -6
- data/lib/mongoid/contextual/map_reduce.rb +23 -49
- data/lib/mongoid/contextual/memory.rb +448 -121
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +707 -351
- data/lib/mongoid/contextual/none.rb +249 -33
- data/lib/mongoid/contextual/queryable.rb +6 -6
- data/lib/mongoid/contextual.rb +40 -15
- data/lib/mongoid/copyable.rb +45 -21
- data/lib/mongoid/criteria/findable.rb +65 -27
- data/lib/mongoid/criteria/includable.rb +97 -45
- data/lib/mongoid/criteria/inspectable.rb +6 -6
- data/lib/mongoid/criteria/marshalable.rb +15 -10
- data/lib/mongoid/criteria/modifiable.rb +8 -28
- data/lib/mongoid/criteria/options.rb +2 -5
- data/lib/mongoid/criteria/permission.rb +40 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +13 -24
- data/lib/mongoid/criteria/queryable/expandable.rb +64 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +14 -50
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +29 -13
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/date.rb +13 -16
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +14 -18
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +5 -44
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +23 -24
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +31 -29
- data/lib/mongoid/criteria/queryable/extensions/object.rb +15 -37
- data/lib/mongoid/criteria/queryable/extensions/range.rb +52 -22
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +22 -25
- data/lib/mongoid/criteria/queryable/extensions/set.rb +8 -10
- data/lib/mongoid/criteria/queryable/extensions/string.rb +24 -41
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +10 -28
- data/lib/mongoid/criteria/queryable/extensions/time.rb +11 -14
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +12 -20
- data/lib/mongoid/criteria/queryable/extensions.rb +19 -24
- data/lib/mongoid/criteria/queryable/key.rb +49 -30
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -6
- data/lib/mongoid/criteria/queryable/mergeable.rb +203 -46
- data/lib/mongoid/criteria/queryable/optional.rb +32 -81
- data/lib/mongoid/criteria/queryable/options.rb +24 -29
- data/lib/mongoid/criteria/queryable/pipeline.rb +11 -23
- data/lib/mongoid/criteria/queryable/selectable.rb +558 -242
- data/lib/mongoid/criteria/queryable/selector.rb +134 -43
- data/lib/mongoid/criteria/queryable/smash.rb +41 -21
- data/lib/mongoid/criteria/queryable/storable.rb +219 -0
- data/lib/mongoid/criteria/queryable.rb +41 -27
- data/lib/mongoid/criteria/scopable.rb +37 -30
- data/lib/mongoid/criteria/translator.rb +43 -0
- data/lib/mongoid/criteria.rb +257 -152
- data/lib/mongoid/deprecable.rb +78 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +277 -171
- data/lib/mongoid/encryptable.rb +98 -0
- data/lib/mongoid/equality.rb +29 -31
- data/lib/mongoid/errors/ambiguous_relationship.rb +6 -9
- data/lib/mongoid/errors/attribute_not_loaded.rb +31 -0
- data/lib/mongoid/errors/callback.rb +3 -6
- data/lib/mongoid/errors/config_redactor.rb +43 -0
- data/lib/mongoid/errors/create_collection_failure.rb +31 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +16 -0
- data/lib/mongoid/errors/delete_restriction.rb +11 -16
- data/lib/mongoid/errors/document_not_destroyed.rb +5 -10
- data/lib/mongoid/errors/document_not_found.rb +37 -27
- data/lib/mongoid/errors/drop_collection_failure.rb +25 -0
- data/lib/mongoid/errors/empty_config_file.rb +23 -0
- data/lib/mongoid/errors/immutable_attribute.rb +24 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +3 -6
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +26 -0
- data/lib/mongoid/errors/invalid_around_callback.rb +16 -0
- data/lib/mongoid/errors/invalid_async_query_executor.rb +23 -0
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +30 -0
- data/lib/mongoid/errors/invalid_collection.rb +3 -3
- data/lib/mongoid/errors/invalid_config_file.rb +23 -0
- data/lib/mongoid/errors/invalid_config_option.rb +5 -8
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +9 -13
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +23 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +21 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +29 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +24 -0
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +24 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +24 -0
- data/lib/mongoid/errors/invalid_field.rb +10 -11
- data/lib/mongoid/errors/invalid_field_operator.rb +29 -0
- data/lib/mongoid/errors/invalid_field_option.rb +4 -7
- data/lib/mongoid/errors/invalid_field_type.rb +24 -0
- data/lib/mongoid/errors/invalid_find.rb +3 -6
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +20 -0
- data/lib/mongoid/errors/invalid_includes.rb +5 -8
- data/lib/mongoid/errors/invalid_index.rb +3 -6
- data/lib/mongoid/errors/invalid_options.rb +5 -8
- data/lib/mongoid/errors/invalid_path.rb +3 -6
- data/lib/mongoid/errors/invalid_persistence_option.rb +6 -11
- data/lib/mongoid/errors/invalid_query.rb +36 -0
- data/lib/mongoid/errors/invalid_relation.rb +15 -22
- data/lib/mongoid/errors/invalid_relation_option.rb +8 -11
- data/lib/mongoid/errors/invalid_scope.rb +3 -6
- data/lib/mongoid/errors/invalid_session_nesting.rb +14 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +8 -9
- data/lib/mongoid/errors/invalid_storage_options.rb +4 -7
- data/lib/mongoid/errors/invalid_time.rb +3 -6
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +14 -0
- data/lib/mongoid/errors/inverse_not_found.rb +4 -7
- data/lib/mongoid/errors/mixed_client_configuration.rb +4 -7
- data/lib/mongoid/errors/mixed_relations.rb +3 -5
- data/lib/mongoid/errors/mongoid_error.rb +13 -23
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +4 -7
- data/lib/mongoid/errors/no_client_config.rb +5 -8
- data/lib/mongoid/errors/no_client_database.rb +5 -8
- data/lib/mongoid/errors/no_client_hosts.rb +5 -8
- data/lib/mongoid/errors/no_clients_config.rb +3 -6
- data/lib/mongoid/errors/no_default_client.rb +4 -7
- data/lib/mongoid/errors/no_encryption_schema.rb +28 -0
- data/lib/mongoid/errors/no_environment.rb +3 -6
- data/lib/mongoid/errors/no_map_reduce_output.rb +3 -6
- data/lib/mongoid/errors/no_metadata.rb +3 -6
- data/lib/mongoid/errors/no_parent.rb +3 -6
- data/lib/mongoid/errors/readonly_association.rb +29 -0
- data/lib/mongoid/errors/readonly_attribute.rb +4 -7
- data/lib/mongoid/errors/readonly_document.rb +4 -9
- data/lib/mongoid/errors/rollback.rb +13 -0
- data/lib/mongoid/errors/scope_overwrite.rb +4 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +14 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +4 -3
- data/lib/mongoid/errors/transaction_error.rb +22 -0
- data/lib/mongoid/errors/transactions_not_supported.rb +14 -0
- data/lib/mongoid/errors/unknown_attribute.rb +4 -7
- data/lib/mongoid/errors/unknown_model.rb +3 -6
- data/lib/mongoid/errors/unrecognized_model_alias.rb +53 -0
- data/lib/mongoid/errors/unrecognized_resolver.rb +27 -0
- data/lib/mongoid/errors/unregistered_class.rb +47 -0
- data/lib/mongoid/errors/unsaved_document.rb +4 -4
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +3 -6
- data/lib/mongoid/errors/validations.rb +5 -5
- data/lib/mongoid/errors.rb +82 -51
- data/lib/mongoid/evolvable.rb +4 -7
- data/lib/mongoid/extensions/array.rb +32 -55
- data/lib/mongoid/extensions/big_decimal.rb +45 -24
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +12 -8
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +38 -30
- data/lib/mongoid/extensions/date_time.rb +8 -22
- data/lib/mongoid/extensions/decimal128.rb +4 -8
- data/lib/mongoid/extensions/false_class.rb +11 -13
- data/lib/mongoid/extensions/float.rb +15 -19
- data/lib/mongoid/extensions/hash.rb +31 -116
- data/lib/mongoid/extensions/integer.rb +17 -21
- data/lib/mongoid/extensions/module.rb +6 -7
- data/lib/mongoid/extensions/nil_class.rb +6 -7
- data/lib/mongoid/extensions/object.rb +42 -84
- data/lib/mongoid/extensions/object_id.rb +5 -11
- data/lib/mongoid/extensions/range.rb +49 -25
- data/lib/mongoid/extensions/raw_value.rb +31 -0
- data/lib/mongoid/extensions/regexp.rb +16 -10
- data/lib/mongoid/extensions/set.rb +27 -15
- data/lib/mongoid/extensions/string.rb +40 -67
- data/lib/mongoid/extensions/symbol.rb +11 -26
- data/lib/mongoid/extensions/time.rb +49 -47
- data/lib/mongoid/extensions/time_with_zone.rb +30 -12
- data/lib/mongoid/extensions/true_class.rb +11 -13
- data/lib/mongoid/extensions/vector.rb +64 -0
- data/lib/mongoid/extensions.rb +28 -41
- data/lib/mongoid/factory.rb +205 -28
- data/lib/mongoid/field_readable.rb +69 -0
- data/lib/mongoid/fields/encrypted.rb +47 -0
- data/lib/mongoid/fields/foreign_key.rb +48 -35
- data/lib/mongoid/fields/localized.rb +33 -21
- data/lib/mongoid/fields/standard.rb +31 -48
- data/lib/mongoid/fields/validators/macro.rb +48 -45
- data/lib/mongoid/fields/validators.rb +3 -2
- data/lib/mongoid/fields.rb +499 -117
- data/lib/mongoid/findable.rb +174 -64
- data/lib/mongoid/identifiable.rb +28 -0
- data/lib/mongoid/indexable/specification.rb +76 -39
- data/lib/mongoid/indexable/validators/options.rb +36 -43
- data/lib/mongoid/indexable.rb +57 -58
- data/lib/mongoid/inspectable.rb +37 -15
- data/lib/mongoid/interceptable.rb +235 -66
- data/lib/mongoid/loadable.rb +146 -0
- data/lib/mongoid/loggable.rb +12 -18
- data/lib/mongoid/matchable.rb +7 -154
- data/lib/mongoid/matcher/all.rb +34 -0
- data/lib/mongoid/matcher/and.rb +32 -0
- data/lib/mongoid/matcher/bits.rb +65 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +39 -0
- data/lib/mongoid/matcher/bits_all_set.rb +39 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +39 -0
- data/lib/mongoid/matcher/bits_any_set.rb +39 -0
- data/lib/mongoid/matcher/elem_match.rb +49 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +29 -0
- data/lib/mongoid/matcher/eq.rb +23 -0
- data/lib/mongoid/matcher/eq_impl.rb +79 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +33 -0
- data/lib/mongoid/matcher/exists.rb +27 -0
- data/lib/mongoid/matcher/expression.rb +43 -0
- data/lib/mongoid/matcher/expression_operator.rb +31 -0
- data/lib/mongoid/matcher/field_expression.rb +74 -0
- data/lib/mongoid/matcher/field_operator.rb +76 -0
- data/lib/mongoid/matcher/gt.rb +29 -0
- data/lib/mongoid/matcher/gte.rb +29 -0
- data/lib/mongoid/matcher/in.rb +37 -0
- data/lib/mongoid/matcher/lt.rb +29 -0
- data/lib/mongoid/matcher/lte.rb +29 -0
- data/lib/mongoid/matcher/mod.rb +29 -0
- data/lib/mongoid/matcher/ne.rb +28 -0
- data/lib/mongoid/matcher/nin.rb +23 -0
- data/lib/mongoid/matcher/nor.rb +34 -0
- data/lib/mongoid/matcher/not.rb +42 -0
- data/lib/mongoid/matcher/or.rb +32 -0
- data/lib/mongoid/matcher/regex.rb +61 -0
- data/lib/mongoid/matcher/regexp_budget.rb +372 -0
- data/lib/mongoid/matcher/size.rb +39 -0
- data/lib/mongoid/matcher/type.rb +119 -0
- data/lib/mongoid/matcher.rb +141 -0
- data/lib/mongoid/model_resolver.rb +155 -0
- data/lib/mongoid/persistable/creatable.rb +50 -36
- data/lib/mongoid/persistable/deletable.rb +18 -30
- data/lib/mongoid/persistable/destroyable.rb +38 -14
- data/lib/mongoid/persistable/incrementable.rb +8 -10
- data/lib/mongoid/persistable/logical.rb +7 -10
- data/lib/mongoid/persistable/maxable.rb +35 -0
- data/lib/mongoid/persistable/minable.rb +35 -0
- data/lib/mongoid/persistable/multipliable.rb +34 -0
- data/lib/mongoid/persistable/poppable.rb +5 -9
- data/lib/mongoid/persistable/pullable.rb +6 -12
- data/lib/mongoid/persistable/pushable.rb +8 -14
- data/lib/mongoid/persistable/renamable.rb +11 -10
- data/lib/mongoid/persistable/savable.rb +16 -11
- data/lib/mongoid/persistable/settable.rb +7 -18
- data/lib/mongoid/persistable/unsettable.rb +11 -12
- data/lib/mongoid/persistable/updatable.rb +113 -35
- data/lib/mongoid/persistable/upsertable.rb +37 -12
- data/lib/mongoid/persistable.rb +169 -60
- data/lib/mongoid/persistence_context.rb +189 -75
- data/lib/mongoid/pluckable.rb +130 -0
- data/lib/mongoid/positional.rb +7 -15
- data/lib/mongoid/railtie.rb +36 -32
- data/lib/mongoid/railties/bson_object_id_serializer.rb +46 -0
- data/lib/mongoid/railties/console_sandbox.rb +40 -0
- data/lib/mongoid/railties/controller_runtime.rb +34 -20
- data/lib/mongoid/railties/database.rake +53 -29
- data/lib/mongoid/reloadable.rb +56 -45
- data/lib/mongoid/scopable.rb +50 -79
- data/lib/mongoid/search_indexable.rb +538 -0
- data/lib/mongoid/selectable.rb +8 -19
- data/lib/mongoid/serializable.rb +46 -40
- data/lib/mongoid/shardable.rb +102 -23
- data/lib/mongoid/stateful.rb +67 -26
- data/lib/mongoid/stringified_symbol.rb +61 -0
- data/lib/mongoid/tasks/database.rake +46 -15
- data/lib/mongoid/tasks/database.rb +204 -31
- data/lib/mongoid/tasks/encryption.rake +59 -0
- data/lib/mongoid/tasks/encryption.rb +103 -0
- data/lib/mongoid/threaded/lifecycle.rb +13 -34
- data/lib/mongoid/threaded.rb +353 -108
- data/lib/mongoid/timestamps/created/short.rb +4 -3
- data/lib/mongoid/timestamps/created.rb +15 -7
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +127 -29
- data/lib/mongoid/timestamps/updated/short.rb +4 -3
- data/lib/mongoid/timestamps/updated.rb +6 -9
- data/lib/mongoid/timestamps.rb +7 -7
- data/lib/mongoid/touchable.rb +176 -40
- data/lib/mongoid/traversable.rb +309 -106
- data/lib/mongoid/utils.rb +52 -0
- data/lib/mongoid/validatable/associated.rb +115 -22
- data/lib/mongoid/validatable/format.rb +2 -2
- data/lib/mongoid/validatable/length.rb +2 -2
- data/lib/mongoid/validatable/localizable.rb +3 -6
- data/lib/mongoid/validatable/macros.rb +25 -14
- data/lib/mongoid/validatable/numericality.rb +40 -0
- data/lib/mongoid/validatable/presence.rb +15 -21
- data/lib/mongoid/validatable/queryable.rb +9 -4
- data/lib/mongoid/validatable/uniqueness.rb +40 -53
- data/lib/mongoid/validatable.rb +41 -52
- data/lib/mongoid/version.rb +6 -2
- data/lib/mongoid/warnings.rb +40 -0
- data/lib/mongoid.rb +105 -44
- data/lib/rails/generators/mongoid/config/config_generator.rb +18 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +24 -0
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +51 -56
- data/lib/rails/generators/mongoid/model/model_generator.rb +10 -8
- data/lib/rails/generators/mongoid_generator.rb +17 -7
- data/lib/rails/mongoid.rb +4 -32
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +17 -1
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/active_job_spec.rb +35 -0
- data/spec/integration/app_spec.rb +327 -144
- data/spec/integration/associations/belongs_to_spec.rb +165 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +241 -67
- data/spec/integration/associations/embeds_many_spec.rb +347 -0
- data/spec/integration/associations/embeds_one_spec.rb +62 -0
- data/spec/integration/associations/foreign_key_spec.rb +107 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +161 -0
- data/spec/integration/associations/has_many_spec.rb +184 -0
- data/spec/integration/associations/has_one_spec.rb +322 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +113 -0
- data/spec/integration/associations/reverse_population_spec.rb +34 -0
- data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
- data/spec/integration/associations/scope_option_spec.rb +100 -0
- data/spec/integration/atomic/modifiers_spec.rb +137 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +149 -3
- data/spec/integration/callbacks_spec.rb +422 -34
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +91 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +78 -0
- data/spec/integration/criteria/logical_spec.rb +105 -0
- data/spec/integration/criteria/range_spec.rb +349 -0
- data/spec/integration/criteria/raw_value_spec.rb +538 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +135 -15
- data/spec/integration/discriminator_key_spec.rb +392 -0
- data/spec/integration/discriminator_value_spec.rb +204 -0
- data/spec/integration/document_spec.rb +32 -3
- data/spec/integration/dots_and_dollars_spec.rb +273 -0
- data/spec/integration/encryption_spec.rb +248 -0
- data/spec/integration/i18n_fallbacks_spec.rb +47 -0
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +743 -0
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +144 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +144 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +195 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +171 -0
- data/spec/integration/matcher_operator_data/type.yml +64 -0
- data/spec/integration/matcher_operator_data/type_array.yml +15 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +37 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +113 -0
- data/spec/integration/matcher_regexp_timeout_spec.rb +215 -0
- data/spec/integration/matcher_spec.rb +237 -0
- data/spec/integration/persistence/collection_options_spec.rb +34 -0
- data/spec/integration/persistence/range_field_spec.rb +373 -0
- data/spec/integration/query_operator_guard_spec.rb +89 -0
- data/spec/integration/server_query_spec.rb +148 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +189 -0
- data/spec/lite_spec_helper.rb +56 -19
- data/spec/mongoid/association/accessors_spec.rb +375 -273
- data/spec/mongoid/association/auto_save_spec.rb +215 -106
- data/spec/mongoid/association/builders_spec.rb +124 -74
- data/spec/mongoid/association/constrainable_spec.rb +11 -21
- data/spec/mongoid/association/counter_cache_spec.rb +101 -131
- data/spec/mongoid/association/depending_spec.rb +454 -402
- data/spec/mongoid/association/eager_loadable_spec.rb +47 -0
- data/spec/mongoid/association/eager_spec.rb +471 -60
- data/spec/mongoid/association/embedded/cyclic_spec.rb +40 -49
- data/spec/mongoid/association/embedded/dirty_spec.rb +19 -21
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +39 -53
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +58 -8
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +208 -158
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +46 -134
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +11 -13
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +137 -35
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1716 -1327
- data/spec/mongoid/association/embedded/embeds_many_models.rb +191 -2
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +68 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +77 -119
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +17 -22
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +44 -24
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +234 -287
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +27 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +50 -134
- data/spec/mongoid/association/fallback_spec.rb +425 -0
- data/spec/mongoid/association/macros_spec.rb +250 -308
- data/spec/mongoid/association/nested/many_spec.rb +53 -72
- data/spec/mongoid/association/nested/one_spec.rb +68 -85
- data/spec/mongoid/association/options_spec.rb +189 -309
- data/spec/mongoid/association/polymorphic_spec.rb +36 -51
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +58 -75
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +131 -40
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +280 -52
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +345 -370
- data/spec/mongoid/association/referenced/belongs_to_models.rb +13 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +171 -329
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +45 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +66 -29
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +75 -36
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +28 -8
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +1151 -1283
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +69 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +176 -166
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +32 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +161 -24
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +169 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +1021 -689
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +1743 -1955
- data/spec/mongoid/association/referenced/has_many_models.rb +85 -1
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +83 -178
- data/spec/mongoid/association/referenced/has_many_through/eager_spec.rb +58 -0
- data/spec/mongoid/association/referenced/has_many_through/proxy_spec.rb +62 -0
- data/spec/mongoid/association/referenced/has_many_through_spec.rb +399 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +28 -37
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +74 -28
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +60 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +380 -333
- data/spec/mongoid/association/referenced/has_one_models.rb +73 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +61 -185
- data/spec/mongoid/association/referenced/has_one_through/eager_spec.rb +58 -0
- data/spec/mongoid/association/referenced/has_one_through/proxy_spec.rb +49 -0
- data/spec/mongoid/association/referenced/has_one_through_spec.rb +211 -0
- data/spec/mongoid/association/reflections_spec.rb +16 -23
- data/spec/mongoid/association/syncable_spec.rb +132 -138
- data/spec/mongoid/association_spec.rb +59 -65
- data/spec/mongoid/atomic/modifiers_spec.rb +217 -180
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +41 -51
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +37 -48
- data/spec/mongoid/atomic/paths/root_spec.rb +11 -14
- data/spec/mongoid/atomic/paths_spec.rb +133 -128
- data/spec/mongoid/atomic_spec.rb +187 -154
- data/spec/mongoid/atomic_update_preparer_spec.rb +83 -0
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/embedded_spec.rb +118 -0
- data/spec/mongoid/attributes/nested_spec.rb +1604 -1737
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +37 -0
- data/spec/mongoid/attributes/readonly_spec.rb +106 -108
- data/spec/mongoid/attributes_spec.rb +1217 -715
- data/spec/mongoid/cacheable_spec.rb +78 -45
- data/spec/mongoid/changeable_spec.rb +914 -638
- data/spec/mongoid/clients/factory_spec.rb +314 -137
- data/spec/mongoid/clients/options_spec.rb +205 -76
- data/spec/mongoid/clients/sessions_spec.rb +73 -116
- data/spec/mongoid/clients/transactions_spec.rb +1128 -186
- data/spec/mongoid/clients/transactions_spec_models.rb +251 -0
- data/spec/mongoid/clients_spec.rb +433 -312
- data/spec/mongoid/collection_configurable_spec.rb +156 -0
- data/spec/mongoid/composable_spec.rb +4 -8
- data/spec/mongoid/config/defaults_spec.rb +125 -0
- data/spec/mongoid/config/encryption_spec.rb +377 -0
- data/spec/mongoid/config/environment_spec.rb +129 -49
- data/spec/mongoid/config/introspection_spec.rb +119 -0
- data/spec/mongoid/config/options_spec.rb +36 -23
- data/spec/mongoid/config_spec.rb +497 -148
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +507 -161
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +60 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +242 -158
- data/spec/mongoid/contextual/aggregable/none_spec.rb +47 -0
- data/spec/mongoid/contextual/atomic_spec.rb +510 -229
- data/spec/mongoid/contextual/map_reduce_spec.rb +114 -153
- data/spec/mongoid/contextual/memory_spec.rb +1947 -563
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +193 -0
- data/spec/mongoid/contextual/mongo_spec.rb +3317 -1268
- data/spec/mongoid/contextual/none_spec.rb +98 -89
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +769 -191
- data/spec/mongoid/copyable_spec_models.rb +30 -0
- data/spec/mongoid/criteria/findable_spec.rb +565 -506
- data/spec/mongoid/criteria/includable_spec.rb +2417 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +64 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +13 -13
- data/spec/mongoid/criteria/marshalable_spec.rb +29 -12
- data/spec/mongoid/criteria/modifiable_spec.rb +388 -530
- data/spec/mongoid/criteria/options_spec.rb +4 -6
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +114 -140
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +59 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +132 -198
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +199 -25
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +86 -116
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +69 -67
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +121 -113
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +96 -32
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +105 -152
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +97 -33
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +27 -37
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +79 -15
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +34 -53
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +259 -191
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +18 -34
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +16 -33
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +14 -18
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +91 -189
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +34 -100
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +99 -103
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +78 -85
- data/spec/mongoid/criteria/queryable/key_spec.rb +34 -35
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +150 -21
- data/spec/mongoid/criteria/queryable/optional_spec.rb +375 -954
- data/spec/mongoid/criteria/queryable/options_spec.rb +175 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +67 -86
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +43 -52
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2101 -414
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +35 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1283 -3140
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +754 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +404 -317
- data/spec/mongoid/criteria/queryable/smash_spec.rb +8 -10
- data/spec/mongoid/criteria/queryable/storable_spec.rb +249 -0
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +212 -118
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +389 -0
- data/spec/mongoid/criteria_spec.rb +1942 -2301
- data/spec/mongoid/document_fields_spec.rb +187 -14
- data/spec/mongoid/document_persistence_context_spec.rb +80 -6
- data/spec/mongoid/document_query_spec.rb +87 -0
- data/spec/mongoid/document_spec.rb +394 -538
- data/spec/mongoid/encryptable_spec.rb +61 -0
- data/spec/mongoid/equality_spec.rb +77 -103
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +10 -10
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +29 -0
- data/spec/mongoid/errors/callback_spec.rb +10 -10
- data/spec/mongoid/errors/config_redactor_spec.rb +112 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +9 -9
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +9 -9
- data/spec/mongoid/errors/document_not_found_spec.rb +108 -32
- data/spec/mongoid/errors/invalid_collection_spec.rb +11 -12
- data/spec/mongoid/errors/invalid_config_file_spec.rb +29 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_field_option_spec.rb +9 -9
- data/spec/mongoid/errors/invalid_field_spec.rb +13 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +53 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_includes_spec.rb +11 -12
- data/spec/mongoid/errors/invalid_index_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_options_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_path_spec.rb +9 -9
- data/spec/mongoid/errors/invalid_relation_spec.rb +17 -15
- data/spec/mongoid/errors/invalid_scope_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -5
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +10 -10
- data/spec/mongoid/errors/invalid_time_spec.rb +10 -10
- data/spec/mongoid/errors/inverse_not_found_spec.rb +11 -11
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +42 -11
- data/spec/mongoid/errors/mixed_relations_spec.rb +10 -10
- data/spec/mongoid/errors/mongoid_error_spec.rb +23 -23
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +10 -10
- data/spec/mongoid/errors/no_client_config_spec.rb +11 -11
- data/spec/mongoid/errors/no_client_database_spec.rb +40 -11
- data/spec/mongoid/errors/no_client_hosts_spec.rb +37 -11
- data/spec/mongoid/errors/no_clients_config_spec.rb +9 -9
- data/spec/mongoid/errors/no_environment_spec.rb +10 -10
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +10 -10
- data/spec/mongoid/errors/no_metadata_spec.rb +9 -9
- data/spec/mongoid/errors/no_parent_spec.rb +10 -10
- data/spec/mongoid/errors/readonly_association_spec.rb +34 -0
- data/spec/mongoid/errors/readonly_attribute_spec.rb +9 -9
- data/spec/mongoid/errors/readonly_document_spec.rb +9 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +11 -11
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +11 -11
- data/spec/mongoid/errors/unknown_attribute_spec.rb +9 -9
- data/spec/mongoid/errors/unsaved_document_spec.rb +10 -10
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +11 -11
- data/spec/mongoid/errors/validations_spec.rb +13 -13
- data/spec/mongoid/extensions/array_spec.rb +92 -377
- data/spec/mongoid/extensions/big_decimal_spec.rb +640 -217
- data/spec/mongoid/extensions/binary_spec.rb +50 -23
- data/spec/mongoid/extensions/boolean_spec.rb +73 -107
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +329 -0
- data/spec/mongoid/extensions/date_spec.rb +62 -173
- data/spec/mongoid/extensions/date_time_spec.rb +42 -95
- data/spec/mongoid/extensions/decimal128_spec.rb +14 -17
- data/spec/mongoid/extensions/false_class_spec.rb +13 -24
- data/spec/mongoid/extensions/float_spec.rb +66 -100
- data/spec/mongoid/extensions/hash_spec.rb +79 -165
- data/spec/mongoid/extensions/integer_spec.rb +63 -91
- data/spec/mongoid/extensions/module_spec.rb +15 -17
- data/spec/mongoid/extensions/nil_class_spec.rb +4 -4
- data/spec/mongoid/extensions/object_id_spec.rb +161 -246
- data/spec/mongoid/extensions/object_spec.rb +36 -238
- data/spec/mongoid/extensions/range_spec.rb +259 -69
- data/spec/mongoid/extensions/raw_value_spec.rb +65 -0
- data/spec/mongoid/extensions/regexp_spec.rb +56 -41
- data/spec/mongoid/extensions/set_spec.rb +110 -14
- data/spec/mongoid/extensions/string_spec.rb +139 -237
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +71 -0
- data/spec/mongoid/extensions/symbol_spec.rb +19 -62
- data/spec/mongoid/extensions/time_spec.rb +394 -192
- data/spec/mongoid/extensions/time_with_zone_spec.rb +111 -176
- data/spec/mongoid/extensions/true_class_spec.rb +13 -24
- data/spec/mongoid/extensions/vector_spec.rb +175 -0
- data/spec/mongoid/factory_spec.rb +378 -80
- data/spec/mongoid/fields/foreign_key_spec.rb +387 -267
- data/spec/mongoid/fields/localized_spec.rb +197 -196
- data/spec/mongoid/fields/standard_spec.rb +45 -58
- data/spec/mongoid/fields_spec.rb +1448 -525
- data/spec/mongoid/findable_spec.rb +659 -230
- data/spec/mongoid/indexable/specification_spec.rb +145 -40
- data/spec/mongoid/indexable_spec.rb +551 -188
- data/spec/mongoid/inspectable_spec.rb +126 -18
- data/spec/mongoid/interceptable_spec.rb +1431 -573
- data/spec/mongoid/interceptable_spec_models.rb +244 -0
- data/spec/mongoid/loadable_spec.rb +86 -0
- data/spec/mongoid/loading_spec.rb +114 -0
- data/spec/mongoid/loggable_spec.rb +5 -5
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +33 -0
- data/spec/mongoid/matcher/regexp_budget_spec.rb +570 -0
- data/spec/mongoid/model_resolver_spec.rb +167 -0
- data/spec/mongoid/mongoizable_spec.rb +277 -0
- data/spec/mongoid/monkey_patches_spec.rb +215 -0
- data/spec/mongoid/persistable/creatable_spec.rb +256 -209
- data/spec/mongoid/persistable/deletable_spec.rb +369 -80
- data/spec/mongoid/persistable/destroyable_spec.rb +439 -80
- data/spec/mongoid/persistable/incrementable_spec.rb +112 -77
- data/spec/mongoid/persistable/logical_spec.rb +92 -51
- data/spec/mongoid/persistable/maxable_spec.rb +148 -0
- data/spec/mongoid/persistable/minable_spec.rb +148 -0
- data/spec/mongoid/persistable/multipliable_spec.rb +212 -0
- data/spec/mongoid/persistable/poppable_spec.rb +87 -47
- data/spec/mongoid/persistable/pullable_spec.rb +161 -82
- data/spec/mongoid/persistable/pushable_spec.rb +188 -110
- data/spec/mongoid/persistable/renamable_spec.rb +91 -51
- data/spec/mongoid/persistable/savable_spec.rb +373 -155
- data/spec/mongoid/persistable/settable_spec.rb +164 -134
- data/spec/mongoid/persistable/unsettable_spec.rb +94 -58
- data/spec/mongoid/persistable/updatable_spec.rb +235 -267
- data/spec/mongoid/persistable/upsertable_spec.rb +150 -38
- data/spec/mongoid/persistable_spec.rb +198 -128
- data/spec/mongoid/persistence_context_spec.rb +133 -137
- data/spec/mongoid/positional_spec.rb +69 -78
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +27 -0
- data/spec/mongoid/railties/console_sandbox_spec.rb +43 -0
- data/spec/mongoid/relations/proxy_spec.rb +8 -6
- data/spec/mongoid/reloadable_spec.rb +552 -123
- data/spec/mongoid/scopable_spec.rb +522 -455
- data/spec/mongoid/search_indexable_spec.rb +838 -0
- data/spec/mongoid/selectable_spec.rb +41 -53
- data/spec/mongoid/serializable_spec.rb +394 -319
- data/spec/mongoid/shardable_models.rb +76 -0
- data/spec/mongoid/shardable_spec.rb +245 -41
- data/spec/mongoid/stateful_spec.rb +170 -45
- data/spec/mongoid/tasks/database_rake_spec.rb +284 -133
- data/spec/mongoid/tasks/database_spec.rb +245 -51
- data/spec/mongoid/tasks/encryption_spec.rb +189 -0
- data/spec/mongoid/threaded_spec.rb +118 -85
- data/spec/mongoid/timestamps/created/short_spec.rb +15 -16
- data/spec/mongoid/timestamps/created_spec.rb +36 -14
- data/spec/mongoid/timestamps/timeless_spec.rb +230 -47
- data/spec/mongoid/timestamps/updated/short_spec.rb +26 -30
- data/spec/mongoid/timestamps/updated_spec.rb +23 -27
- data/spec/mongoid/timestamps_spec.rb +408 -34
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +1235 -136
- data/spec/mongoid/touchable_spec_models.rb +178 -0
- data/spec/mongoid/traversable_spec.rb +1188 -79
- data/spec/mongoid/validatable/associated_spec.rb +86 -89
- data/spec/mongoid/validatable/format_spec.rb +26 -33
- data/spec/mongoid/validatable/length_spec.rb +64 -85
- data/spec/mongoid/validatable/numericality_spec.rb +124 -14
- data/spec/mongoid/validatable/presence_spec.rb +168 -215
- data/spec/mongoid/validatable/uniqueness_spec.rb +702 -826
- data/spec/mongoid/validatable_spec.rb +76 -105
- data/spec/mongoid/warnings_spec.rb +32 -0
- data/spec/mongoid_spec.rb +67 -30
- data/spec/rails/controller_extension/controller_runtime_spec.rb +59 -60
- data/spec/rails/mongoid_spec.rb +38 -139
- data/spec/shared/CANDIDATE.md +28 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/cluster_config.rb +16 -41
- data/spec/shared/lib/mrss/constraints.rb +44 -59
- data/spec/shared/lib/mrss/docker_runner.rb +42 -20
- data/spec/shared/lib/mrss/eg_config_utils.rb +20 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +48 -1
- data/spec/shared/lib/mrss/release/candidate.rb +287 -0
- data/spec/shared/lib/mrss/release/product_data.rb +144 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +18 -24
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +48 -2
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/lib/tasks/candidate.rake +64 -0
- data/spec/shared/share/Dockerfile.erb +114 -96
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +12 -1
- data/spec/shared/shlib/server.sh +148 -65
- data/spec/shared/shlib/set_env.sh +56 -80
- data/spec/spec_helper.rb +104 -72
- data/spec/support/authorization.rb +2 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +37 -22
- data/spec/support/crypt/models.rb +206 -0
- data/spec/support/crypt.rb +77 -0
- data/spec/support/expectations.rb +38 -17
- data/spec/support/feature_sandbox.rb +69 -0
- data/spec/support/helpers.rb +11 -0
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +106 -1
- data/spec/support/models/account.rb +38 -0
- data/spec/support/models/acolyte.rb +20 -0
- data/spec/support/models/actor.rb +21 -0
- data/spec/support/models/actress.rb +4 -0
- data/spec/support/models/address.rb +88 -0
- data/spec/support/models/address_component.rb +8 -0
- data/spec/support/models/address_number.rb +9 -0
- data/spec/support/models/agency.rb +8 -0
- data/spec/support/models/agent.rb +19 -0
- data/spec/support/models/album.rb +20 -0
- data/spec/support/models/alert.rb +10 -0
- data/spec/support/models/animal.rb +28 -0
- data/spec/support/models/answer.rb +9 -0
- data/spec/support/models/appointment.rb +10 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/support/models/article.rb +14 -0
- data/spec/support/models/artist.rb +95 -0
- data/spec/support/models/artwork.rb +7 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/support/models/audio.rb +8 -0
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/support/models/author.rb +9 -0
- data/spec/support/models/baby.rb +7 -0
- data/spec/support/models/band.rb +46 -0
- data/spec/support/models/bar.rb +13 -0
- data/spec/support/models/basic.rb +8 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/support/models/big_palette.rb +4 -0
- data/spec/support/models/birthday.rb +14 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/support/models/bomb.rb +7 -0
- data/spec/support/models/book.rb +20 -0
- data/spec/support/models/breed.rb +7 -0
- data/spec/support/models/browser.rb +8 -0
- data/spec/support/models/building.rb +10 -0
- data/spec/support/models/building_address.rb +10 -0
- data/spec/support/models/bus.rb +10 -0
- data/spec/support/models/business.rb +8 -0
- data/spec/support/models/callback_test.rb +12 -0
- data/spec/support/models/canvas.rb +27 -0
- data/spec/support/models/car.rb +3 -0
- data/spec/support/models/cat.rb +9 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/category.rb +11 -0
- data/spec/support/models/child.rb +7 -0
- data/spec/support/models/child_doc.rb +24 -0
- data/spec/support/models/church.rb +9 -0
- data/spec/support/models/circle.rb +5 -0
- data/spec/support/models/circuit.rb +7 -0
- data/spec/support/models/circus.rb +12 -0
- data/spec/support/models/code.rb +17 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/support/models/comment.rb +18 -0
- data/spec/support/models/company.rb +9 -0
- data/spec/support/models/consumption_period.rb +9 -0
- data/spec/support/models/contextable_item.rb +8 -0
- data/spec/support/models/contractor.rb +8 -0
- data/spec/support/models/cookie.rb +8 -0
- data/spec/support/models/country_code.rb +12 -0
- data/spec/support/models/courier_job.rb +7 -0
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +8 -0
- data/spec/support/models/definition.rb +12 -0
- data/spec/support/models/delegating_patient.rb +15 -0
- data/spec/support/models/description.rb +13 -0
- data/spec/support/models/dictionary.rb +19 -0
- data/spec/support/models/division.rb +13 -0
- data/spec/support/models/doctor.rb +14 -0
- data/spec/support/models/dog.rb +10 -0
- data/spec/support/models/dokument.rb +9 -0
- data/spec/support/models/draft.rb +11 -0
- data/spec/support/models/dragon.rb +7 -0
- data/spec/support/models/driver.rb +10 -0
- data/spec/support/models/drug.rb +9 -0
- data/spec/support/models/dungeon.rb +7 -0
- data/spec/support/models/edit.rb +8 -0
- data/spec/support/models/email.rb +9 -0
- data/spec/support/models/employer.rb +7 -0
- data/spec/support/models/entry.rb +9 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/support/models/even.rb +10 -0
- data/spec/support/models/event.rb +24 -0
- data/spec/support/models/exhibition.rb +7 -0
- data/spec/support/models/exhibitor.rb +9 -0
- data/spec/support/models/explosion.rb +7 -0
- data/spec/support/models/eye.rb +11 -0
- data/spec/support/models/eye_bowl.rb +11 -0
- data/spec/support/models/face.rb +10 -0
- data/spec/support/models/fanatic.rb +9 -0
- data/spec/support/models/favorite.rb +15 -0
- data/spec/support/models/filesystem.rb +8 -0
- data/spec/support/models/fire_hydrant.rb +9 -0
- data/spec/support/models/firefox.rb +6 -0
- data/spec/support/models/fish.rb +9 -0
- data/spec/support/models/folder.rb +8 -0
- data/spec/support/models/folder_item.rb +10 -0
- data/spec/support/models/fruits.rb +41 -0
- data/spec/support/models/game.rb +21 -0
- data/spec/support/models/ghost.rb +9 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/support/models/home.rb +7 -0
- data/spec/support/models/house.rb +9 -0
- data/spec/support/models/html_writer.rb +5 -0
- data/spec/support/models/id_key.rb +9 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/support/models/image.rb +24 -0
- data/spec/support/models/implant.rb +27 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/support/models/item.rb +11 -0
- data/spec/support/models/jar.rb +9 -0
- data/spec/support/models/kaleidoscope.rb +9 -0
- data/spec/support/models/kangaroo.rb +7 -0
- data/spec/support/models/label.rb +53 -0
- data/spec/support/models/language.rb +8 -0
- data/spec/support/models/lat_lng.rb +23 -0
- data/spec/support/models/league.rb +14 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/support/models/line_item.rb +9 -0
- data/spec/support/models/location.rb +11 -0
- data/spec/support/models/login.rb +10 -0
- data/spec/support/models/manufacturer.rb +9 -0
- data/spec/support/models/meat.rb +7 -0
- data/spec/support/models/membership.rb +8 -0
- data/spec/support/models/message.rb +13 -0
- data/spec/support/models/minim.rb +6 -0
- data/spec/support/models/mixed_drink.rb +7 -0
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/support/models/movie.rb +16 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/support/models/name.rb +36 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/support/models/node.rb +8 -0
- data/spec/support/models/note.rb +20 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/support/models/odd.rb +10 -0
- data/spec/support/models/order.rb +13 -0
- data/spec/support/models/ordered_post.rb +14 -0
- data/spec/support/models/ordered_preference.rb +9 -0
- data/spec/support/models/oscar.rb +17 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/support/models/override.rb +11 -0
- data/spec/support/models/ownable.rb +9 -0
- data/spec/support/models/owner.rb +11 -0
- data/spec/support/models/pack.rb +5 -0
- data/spec/support/models/page.rb +19 -0
- data/spec/support/models/page_question.rb +7 -0
- data/spec/support/models/palette.rb +10 -0
- data/spec/support/models/parent.rb +8 -0
- data/spec/support/models/parent_doc.rb +9 -0
- data/spec/support/models/passport.rb +23 -0
- data/spec/support/models/patient.rb +12 -0
- data/spec/support/models/pdf_writer.rb +5 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/support/models/person.rb +237 -0
- data/spec/support/models/pet.rb +26 -0
- data/spec/support/models/pet_owner.rb +9 -0
- data/spec/support/models/phone.rb +13 -0
- data/spec/support/models/piano.rb +4 -0
- data/spec/support/models/pizza.rb +10 -0
- data/spec/support/models/player.rb +40 -0
- data/spec/support/models/post.rb +53 -0
- data/spec/support/models/post_genre.rb +9 -0
- data/spec/support/models/powerup.rb +25 -0
- data/spec/support/models/preference.rb +12 -0
- data/spec/support/models/princess.rb +13 -0
- data/spec/support/models/product.rb +23 -0
- data/spec/support/models/profile.rb +19 -0
- data/spec/support/models/pronunciation.rb +8 -0
- data/spec/support/models/pub.rb +9 -0
- data/spec/support/models/publication/encyclopedia.rb +11 -0
- data/spec/support/models/publication/review.rb +13 -0
- data/spec/support/models/publication.rb +4 -0
- data/spec/support/models/purchase.rb +7 -0
- data/spec/support/models/purchased_item.rb +11 -0
- data/spec/support/models/purse.rb +9 -0
- data/spec/support/models/question.rb +11 -0
- data/spec/support/models/quiz.rb +10 -0
- data/spec/support/models/rating.rb +11 -0
- data/spec/support/models/record.rb +54 -0
- data/spec/support/models/registry.rb +8 -0
- data/spec/support/models/role.rb +10 -0
- data/spec/support/models/root_category.rb +7 -0
- data/spec/support/models/sandbox/app/models/app_models_message.rb +3 -0
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +3 -0
- data/spec/support/models/sandbox/sandbox_message.rb +3 -0
- data/spec/support/models/sandbox/sandbox_user.rb +3 -0
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +3 -0
- data/spec/support/models/sandwich.rb +12 -0
- data/spec/support/models/scheduler.rb +9 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/scribe.rb +8 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/support/models/seo.rb +12 -0
- data/spec/support/models/series.rb +8 -0
- data/spec/support/models/server.rb +16 -0
- data/spec/support/models/service.rb +25 -0
- data/spec/support/models/shape.rb +15 -0
- data/spec/support/models/shelf.rb +8 -0
- data/spec/support/models/shield.rb +19 -0
- data/spec/support/models/shipment_address.rb +5 -0
- data/spec/support/models/shipping_container.rb +8 -0
- data/spec/support/models/shipping_pack.rb +5 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/support/models/shop.rb +9 -0
- data/spec/support/models/short_agent.rb +6 -0
- data/spec/support/models/short_quiz.rb +8 -0
- data/spec/support/models/simple.rb +8 -0
- data/spec/support/models/slave.rb +9 -0
- data/spec/support/models/song.rb +10 -0
- data/spec/support/models/sound.rb +8 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/support/models/square.rb +6 -0
- data/spec/support/models/staff.rb +9 -0
- data/spec/support/models/store_as_dup_test1.rb +8 -0
- data/spec/support/models/store_as_dup_test2.rb +8 -0
- data/spec/support/models/store_as_dup_test3.rb +8 -0
- data/spec/support/models/store_as_dup_test4.rb +8 -0
- data/spec/support/models/strategy.rb +5 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/sub_item.rb +5 -0
- data/spec/support/models/subscription.rb +8 -0
- data/spec/support/models/survey.rb +8 -0
- data/spec/support/models/symptom.rb +9 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/support/models/tag.rb +11 -0
- data/spec/support/models/target.rb +8 -0
- data/spec/support/models/template.rb +8 -0
- data/spec/support/models/thing.rb +12 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/support/models/title.rb +5 -0
- data/spec/support/models/tool.rb +11 -0
- data/spec/support/models/topping.rb +8 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/support/models/track.rb +41 -0
- data/spec/support/models/translation.rb +8 -0
- data/spec/support/models/tree.rb +11 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/support/models/user.rb +23 -0
- data/spec/support/models/user_account.rb +13 -0
- data/spec/support/models/validation_callback.rb +13 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/support/models/version.rb +8 -0
- data/spec/support/models/vertex.rb +8 -0
- data/spec/support/models/vet_visit.rb +8 -0
- data/spec/support/models/video.rb +16 -0
- data/spec/support/models/video_game.rb +3 -0
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/support/models/wiki_page.rb +17 -0
- data/spec/support/models/word.rb +18 -0
- data/spec/support/models/word_origin.rb +13 -0
- data/spec/support/models/writer.rb +14 -0
- data/spec/support/rails_mock.rb +27 -0
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +34 -0
- data/spec/support/sinatra_mock.rb +9 -0
- data/spec/support/spec_config.rb +45 -14
- metadata +1341 -780
- checksums.yaml.gz.sig +0 -0
- data/lib/mongoid/association/referenced/eager.rb +0 -162
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +0 -126
- data/lib/mongoid/contextual/geo_near.rb +0 -267
- data/lib/mongoid/criteria/queryable/forwardable.rb +0 -65
- data/lib/mongoid/errors/eager_load.rb +0 -22
- data/lib/mongoid/errors/invalid_session_use.rb +0 -24
- data/lib/mongoid/errors/invalid_storage_parent.rb +0 -26
- data/lib/mongoid/errors/invalid_value.rb +0 -16
- data/lib/mongoid/matchable/all.rb +0 -28
- data/lib/mongoid/matchable/and.rb +0 -30
- data/lib/mongoid/matchable/default.rb +0 -119
- data/lib/mongoid/matchable/elem_match.rb +0 -34
- data/lib/mongoid/matchable/eq.rb +0 -22
- data/lib/mongoid/matchable/exists.rb +0 -23
- data/lib/mongoid/matchable/gt.rb +0 -23
- data/lib/mongoid/matchable/gte.rb +0 -23
- data/lib/mongoid/matchable/in.rb +0 -24
- data/lib/mongoid/matchable/lt.rb +0 -23
- data/lib/mongoid/matchable/lte.rb +0 -23
- data/lib/mongoid/matchable/ne.rb +0 -21
- data/lib/mongoid/matchable/nin.rb +0 -22
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/matchable/or.rb +0 -33
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/lib/mongoid/matchable/size.rb +0 -21
- data/lib/mongoid/query_cache.rb +0 -331
- data/lib/support/ruby_version.rb +0 -26
- data/spec/app/models/account.rb +0 -36
- data/spec/app/models/acolyte.rb +0 -17
- data/spec/app/models/actor.rb +0 -18
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/address.rb +0 -79
- data/spec/app/models/address_component.rb +0 -5
- data/spec/app/models/address_number.rb +0 -6
- data/spec/app/models/agency.rb +0 -5
- data/spec/app/models/agent.rb +0 -16
- data/spec/app/models/album.rb +0 -18
- data/spec/app/models/alert.rb +0 -7
- data/spec/app/models/animal.rb +0 -26
- data/spec/app/models/answer.rb +0 -6
- data/spec/app/models/appointment.rb +0 -7
- data/spec/app/models/article.rb +0 -12
- data/spec/app/models/artist.rb +0 -87
- data/spec/app/models/artwork.rb +0 -4
- data/spec/app/models/audio.rb +0 -5
- data/spec/app/models/augmentation.rb +0 -11
- data/spec/app/models/author.rb +0 -6
- data/spec/app/models/baby.rb +0 -4
- data/spec/app/models/band.rb +0 -31
- data/spec/app/models/bar.rb +0 -10
- data/spec/app/models/basic.rb +0 -6
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/big_palette.rb +0 -2
- data/spec/app/models/birthday.rb +0 -13
- data/spec/app/models/bomb.rb +0 -4
- data/spec/app/models/book.rb +0 -16
- data/spec/app/models/breed.rb +0 -4
- data/spec/app/models/browser.rb +0 -6
- data/spec/app/models/building.rb +0 -6
- data/spec/app/models/building_address.rb +0 -7
- data/spec/app/models/bus.rb +0 -7
- data/spec/app/models/business.rb +0 -5
- data/spec/app/models/callback_test.rb +0 -9
- data/spec/app/models/canvas.rb +0 -25
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/cat.rb +0 -8
- data/spec/app/models/category.rb +0 -8
- data/spec/app/models/child.rb +0 -4
- data/spec/app/models/child_doc.rb +0 -22
- data/spec/app/models/church.rb +0 -6
- data/spec/app/models/circle.rb +0 -3
- data/spec/app/models/circuit.rb +0 -4
- data/spec/app/models/circus.rb +0 -7
- data/spec/app/models/code.rb +0 -11
- data/spec/app/models/comment.rb +0 -16
- data/spec/app/models/company.rb +0 -5
- data/spec/app/models/consumption_period.rb +0 -7
- data/spec/app/models/contextable_item.rb +0 -5
- data/spec/app/models/contractor.rb +0 -5
- data/spec/app/models/cookie.rb +0 -6
- data/spec/app/models/country_code.rb +0 -8
- data/spec/app/models/courier_job.rb +0 -4
- data/spec/app/models/customer.rb +0 -11
- data/spec/app/models/customer_address.rb +0 -12
- data/spec/app/models/definition.rb +0 -9
- data/spec/app/models/delegating_patient.rb +0 -16
- data/spec/app/models/description.rb +0 -11
- data/spec/app/models/dictionary.rb +0 -10
- data/spec/app/models/division.rb +0 -10
- data/spec/app/models/doctor.rb +0 -12
- data/spec/app/models/dog.rb +0 -7
- data/spec/app/models/dokument.rb +0 -6
- data/spec/app/models/draft.rb +0 -9
- data/spec/app/models/dragon.rb +0 -4
- data/spec/app/models/driver.rb +0 -7
- data/spec/app/models/drug.rb +0 -6
- data/spec/app/models/dungeon.rb +0 -4
- data/spec/app/models/edit.rb +0 -5
- data/spec/app/models/email.rb +0 -6
- data/spec/app/models/employer.rb +0 -5
- data/spec/app/models/entry.rb +0 -6
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/even.rb +0 -7
- data/spec/app/models/event.rb +0 -22
- data/spec/app/models/exhibition.rb +0 -4
- data/spec/app/models/exhibitor.rb +0 -6
- data/spec/app/models/explosion.rb +0 -4
- data/spec/app/models/eye.rb +0 -9
- data/spec/app/models/eye_bowl.rb +0 -9
- data/spec/app/models/face.rb +0 -8
- data/spec/app/models/favorite.rb +0 -6
- data/spec/app/models/filesystem.rb +0 -5
- data/spec/app/models/fire_hydrant.rb +0 -6
- data/spec/app/models/firefox.rb +0 -4
- data/spec/app/models/fish.rb +0 -7
- data/spec/app/models/folder.rb +0 -7
- data/spec/app/models/folder_item.rb +0 -9
- data/spec/app/models/fruits.rb +0 -34
- data/spec/app/models/game.rb +0 -19
- data/spec/app/models/ghost.rb +0 -7
- data/spec/app/models/home.rb +0 -4
- data/spec/app/models/house.rb +0 -6
- data/spec/app/models/html_writer.rb +0 -3
- data/spec/app/models/id_key.rb +0 -6
- data/spec/app/models/image.rb +0 -22
- data/spec/app/models/implant.rb +0 -16
- data/spec/app/models/item.rb +0 -8
- data/spec/app/models/jar.rb +0 -7
- data/spec/app/models/kaleidoscope.rb +0 -6
- data/spec/app/models/kangaroo.rb +0 -4
- data/spec/app/models/label.rb +0 -47
- data/spec/app/models/language.rb +0 -5
- data/spec/app/models/lat_lng.rb +0 -15
- data/spec/app/models/league.rb +0 -11
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/line_item.rb +0 -6
- data/spec/app/models/location.rb +0 -8
- data/spec/app/models/login.rb +0 -8
- data/spec/app/models/manufacturer.rb +0 -7
- data/spec/app/models/meat.rb +0 -4
- data/spec/app/models/membership.rb +0 -4
- data/spec/app/models/message.rb +0 -11
- data/spec/app/models/minim.rb +0 -7
- data/spec/app/models/mixed_drink.rb +0 -4
- data/spec/app/models/movie.rb +0 -13
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/name.rb +0 -24
- data/spec/app/models/node.rb +0 -5
- data/spec/app/models/note.rb +0 -17
- data/spec/app/models/odd.rb +0 -7
- data/spec/app/models/ordered_post.rb +0 -11
- data/spec/app/models/ordered_preference.rb +0 -6
- data/spec/app/models/oscar.rb +0 -14
- data/spec/app/models/other_owner_object.rb +0 -2
- data/spec/app/models/override.rb +0 -16
- data/spec/app/models/ownable.rb +0 -6
- data/spec/app/models/owner.rb +0 -6
- data/spec/app/models/pack.rb +0 -3
- data/spec/app/models/page.rb +0 -16
- data/spec/app/models/page_question.rb +0 -4
- data/spec/app/models/palette.rb +0 -7
- data/spec/app/models/parent.rb +0 -5
- data/spec/app/models/parent_doc.rb +0 -6
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/patient.rb +0 -9
- data/spec/app/models/pdf_writer.rb +0 -3
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/person.rb +0 -210
- data/spec/app/models/pet.rb +0 -23
- data/spec/app/models/pet_owner.rb +0 -6
- data/spec/app/models/phone.rb +0 -9
- data/spec/app/models/pizza.rb +0 -7
- data/spec/app/models/player.rb +0 -35
- data/spec/app/models/post.rb +0 -50
- data/spec/app/models/post_genre.rb +0 -6
- data/spec/app/models/powerup.rb +0 -11
- data/spec/app/models/preference.rb +0 -9
- data/spec/app/models/princess.rb +0 -10
- data/spec/app/models/product.rb +0 -17
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/pronunciation.rb +0 -5
- data/spec/app/models/pub.rb +0 -6
- data/spec/app/models/purchase.rb +0 -4
- data/spec/app/models/question.rb +0 -8
- data/spec/app/models/quiz.rb +0 -7
- data/spec/app/models/rating.rb +0 -8
- data/spec/app/models/record.rb +0 -52
- data/spec/app/models/registry.rb +0 -4
- data/spec/app/models/role.rb +0 -7
- data/spec/app/models/root_category.rb +0 -4
- data/spec/app/models/sandwich.rb +0 -9
- data/spec/app/models/scheduler.rb +0 -7
- data/spec/app/models/seo.rb +0 -7
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/server.rb +0 -13
- data/spec/app/models/service.rb +0 -22
- data/spec/app/models/shape.rb +0 -12
- data/spec/app/models/shelf.rb +0 -5
- data/spec/app/models/shipment_address.rb +0 -3
- data/spec/app/models/shipping_container.rb +0 -5
- data/spec/app/models/shipping_pack.rb +0 -3
- data/spec/app/models/shop.rb +0 -6
- data/spec/app/models/short_agent.rb +0 -4
- data/spec/app/models/short_quiz.rb +0 -5
- data/spec/app/models/simple.rb +0 -5
- data/spec/app/models/slave.rb +0 -6
- data/spec/app/models/song.rb +0 -8
- data/spec/app/models/sound.rb +0 -5
- data/spec/app/models/square.rb +0 -4
- data/spec/app/models/staff.rb +0 -7
- data/spec/app/models/store_as_dup_test1.rb +0 -5
- data/spec/app/models/store_as_dup_test2.rb +0 -5
- data/spec/app/models/store_as_dup_test3.rb +0 -7
- data/spec/app/models/store_as_dup_test4.rb +0 -7
- data/spec/app/models/strategy.rb +0 -3
- data/spec/app/models/sub_item.rb +0 -3
- data/spec/app/models/subscription.rb +0 -5
- data/spec/app/models/survey.rb +0 -5
- data/spec/app/models/symptom.rb +0 -6
- data/spec/app/models/tag.rb +0 -8
- data/spec/app/models/target.rb +0 -5
- data/spec/app/models/template.rb +0 -5
- data/spec/app/models/thing.rb +0 -9
- data/spec/app/models/title.rb +0 -3
- data/spec/app/models/tool.rb +0 -8
- data/spec/app/models/topping.rb +0 -5
- data/spec/app/models/track.rb +0 -38
- data/spec/app/models/translation.rb +0 -5
- data/spec/app/models/tree.rb +0 -9
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/user.rb +0 -21
- data/spec/app/models/user_account.rb +0 -10
- data/spec/app/models/validation_callback.rb +0 -10
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/version.rb +0 -5
- data/spec/app/models/vertex.rb +0 -6
- data/spec/app/models/vet_visit.rb +0 -5
- data/spec/app/models/video.rb +0 -13
- data/spec/app/models/video_game.rb +0 -1
- data/spec/app/models/weapon.rb +0 -11
- data/spec/app/models/wiki_page.rb +0 -14
- data/spec/app/models/word.rb +0 -15
- data/spec/app/models/word_origin.rb +0 -11
- data/spec/app/models/writer.rb +0 -11
- data/spec/integration/matchable_spec.rb +0 -680
- data/spec/mongoid/contextual/geo_near_spec.rb +0 -469
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -58
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -58
- data/spec/mongoid/criteria/queryable/forwardable_spec.rb +0 -87
- data/spec/mongoid/errors/eager_load_spec.rb +0 -29
- data/spec/mongoid/extensions_spec.rb +0 -29
- data/spec/mongoid/matchable/all_spec.rb +0 -31
- data/spec/mongoid/matchable/and_spec.rb +0 -187
- data/spec/mongoid/matchable/default_spec.rb +0 -137
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -106
- data/spec/mongoid/matchable/eq_spec.rb +0 -48
- data/spec/mongoid/matchable/exists_spec.rb +0 -57
- data/spec/mongoid/matchable/gt_spec.rb +0 -86
- data/spec/mongoid/matchable/gte_spec.rb +0 -84
- data/spec/mongoid/matchable/in_spec.rb +0 -49
- data/spec/mongoid/matchable/lt_spec.rb +0 -85
- data/spec/mongoid/matchable/lte_spec.rb +0 -85
- data/spec/mongoid/matchable/ne_spec.rb +0 -46
- data/spec/mongoid/matchable/nin_spec.rb +0 -48
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/matchable/or_spec.rb +0 -131
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
- data/spec/mongoid/matchable/size_spec.rb +0 -25
- data/spec/mongoid/matchable_spec.rb +0 -853
- data/spec/mongoid/query_cache_spec.rb +0 -618
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/session_registry.rb +0 -50
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -1
- /data/spec/{app → support}/models/array_field.rb +0 -0
- /data/spec/{app → support}/models/updatable.rb +0 -0
|
@@ -1,1462 +1,909 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'spec_helper'
|
|
4
4
|
|
|
5
|
+
describe Mongoid::Criteria::Queryable::Optional do
|
|
5
6
|
let(:query) do
|
|
6
7
|
Mongoid::Query.new
|
|
7
8
|
end
|
|
8
9
|
|
|
9
|
-
shared_examples_for
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
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)
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
[
|
|
17
|
-
|
|
16
|
+
%i[asc ascending].each do |method|
|
|
18
17
|
describe "##{method}" do
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
context "when the query is aggregating" do
|
|
23
|
-
|
|
18
|
+
context 'when using the official mongodb driver syntax' do
|
|
19
|
+
context 'when the query is aggregating' do
|
|
24
20
|
let(:selection) do
|
|
25
21
|
query.project(name: 1).send(method, :field_one, :field_two)
|
|
26
22
|
end
|
|
27
23
|
|
|
28
|
-
it
|
|
24
|
+
it 'adds the sorting criteria' do
|
|
29
25
|
expect(selection.options).to eq(
|
|
30
|
-
{ sort: {
|
|
26
|
+
{ sort: { 'field_one' => 1, 'field_two' => 1 } }
|
|
31
27
|
)
|
|
32
28
|
end
|
|
33
29
|
|
|
34
|
-
it
|
|
30
|
+
it 'adds the sort to the aggregation' do
|
|
35
31
|
expect(selection.pipeline).to include(
|
|
36
|
-
{
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "does not add multiple entries to the pipeline" do
|
|
41
|
-
expect(selection.pipeline).to_not include(
|
|
42
|
-
{ "$sort" => { "field_one" => 1 }}
|
|
43
|
-
)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it_behaves_like "a cloning option"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "when provided symbols" do
|
|
50
|
-
|
|
51
|
-
let(:selection) do
|
|
52
|
-
query.send(method, :field_one, :field_two)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "adds the sorting criteria" do
|
|
56
|
-
expect(selection.options).to eq(
|
|
57
|
-
{ sort: { "field_one" => 1, "field_two" => 1 }}
|
|
32
|
+
{ '$sort' => { 'field_one' => 1, 'field_two' => 1 } }
|
|
58
33
|
)
|
|
59
34
|
end
|
|
60
35
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
context "when provided an array of symbols" do
|
|
65
|
-
|
|
66
|
-
let(:selection) do
|
|
67
|
-
query.send(method, [ :field_one, :field_two ])
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "adds the sorting criteria" do
|
|
71
|
-
expect(selection.options).to eq(
|
|
72
|
-
{ sort: { "field_one" => 1, "field_two" => 1 }}
|
|
36
|
+
it 'does not add multiple entries to the pipeline' do
|
|
37
|
+
expect(selection.pipeline).not_to include(
|
|
38
|
+
{ '$sort' => { 'field_one' => 1 } }
|
|
73
39
|
)
|
|
74
40
|
end
|
|
75
41
|
|
|
76
|
-
it_behaves_like
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
context "when provided strings" do
|
|
80
|
-
|
|
81
|
-
let(:selection) do
|
|
82
|
-
query.send(method, "field_one", "field_two")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "adds the sorting criteria" do
|
|
86
|
-
expect(selection.options).to eq(
|
|
87
|
-
{ sort: { "field_one" => 1, "field_two" => 1 }}
|
|
88
|
-
)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
it_behaves_like "a cloning option"
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
context "when provided an array of strings" do
|
|
95
|
-
|
|
96
|
-
let(:selection) do
|
|
97
|
-
query.send(method, [ "field_one", "field_two" ])
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "adds the sorting criteria" do
|
|
101
|
-
expect(selection.options).to eq(
|
|
102
|
-
{ sort: { "field_one" => 1, "field_two" => 1 }}
|
|
103
|
-
)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it_behaves_like "a cloning option"
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
context "when provided no options" do
|
|
110
|
-
|
|
111
|
-
let(:selection) do
|
|
112
|
-
query.send(method)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "does not add any sorting criteria" do
|
|
116
|
-
expect(selection.options).to be_empty
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "returns the query" do
|
|
120
|
-
expect(selection).to eq(query)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it_behaves_like "a cloning option"
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
context "when provided nil" do
|
|
127
|
-
|
|
128
|
-
let(:selection) do
|
|
129
|
-
query.send(method, nil)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
it "does not add any sorting criteria" do
|
|
133
|
-
expect(selection.options).to be_empty
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "returns the query" do
|
|
137
|
-
expect(selection).to eq(query)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it_behaves_like "a cloning option"
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context "when using the mongo-1.x driver syntax" do
|
|
145
|
-
|
|
146
|
-
let(:query) do
|
|
147
|
-
Mongoid::Query.new({}, {}, :mongo1x)
|
|
42
|
+
it_behaves_like 'a cloning option'
|
|
148
43
|
end
|
|
149
44
|
|
|
150
|
-
context
|
|
151
|
-
|
|
45
|
+
context 'when provided symbols' do
|
|
152
46
|
let(:selection) do
|
|
153
47
|
query.send(method, :field_one, :field_two)
|
|
154
48
|
end
|
|
155
49
|
|
|
156
|
-
it
|
|
50
|
+
it 'adds the sorting criteria' do
|
|
157
51
|
expect(selection.options).to eq(
|
|
158
|
-
{ sort:
|
|
52
|
+
{ sort: { 'field_one' => 1, 'field_two' => 1 } }
|
|
159
53
|
)
|
|
160
54
|
end
|
|
161
55
|
|
|
162
|
-
it_behaves_like
|
|
56
|
+
it_behaves_like 'a cloning option'
|
|
163
57
|
end
|
|
164
58
|
|
|
165
|
-
context
|
|
166
|
-
|
|
59
|
+
context 'when provided an array of symbols' do
|
|
167
60
|
let(:selection) do
|
|
168
|
-
query.send(method, [
|
|
61
|
+
query.send(method, %i[field_one field_two])
|
|
169
62
|
end
|
|
170
63
|
|
|
171
|
-
it
|
|
64
|
+
it 'adds the sorting criteria' do
|
|
172
65
|
expect(selection.options).to eq(
|
|
173
|
-
{ sort:
|
|
66
|
+
{ sort: { 'field_one' => 1, 'field_two' => 1 } }
|
|
174
67
|
)
|
|
175
68
|
end
|
|
176
69
|
|
|
177
|
-
it_behaves_like
|
|
70
|
+
it_behaves_like 'a cloning option'
|
|
178
71
|
end
|
|
179
72
|
|
|
180
|
-
context
|
|
181
|
-
|
|
73
|
+
context 'when provided strings' do
|
|
182
74
|
let(:selection) do
|
|
183
|
-
query.send(method,
|
|
75
|
+
query.send(method, 'field_one', 'field_two')
|
|
184
76
|
end
|
|
185
77
|
|
|
186
|
-
it
|
|
78
|
+
it 'adds the sorting criteria' do
|
|
187
79
|
expect(selection.options).to eq(
|
|
188
|
-
{ sort:
|
|
80
|
+
{ sort: { 'field_one' => 1, 'field_two' => 1 } }
|
|
189
81
|
)
|
|
190
82
|
end
|
|
191
83
|
|
|
192
|
-
it_behaves_like
|
|
84
|
+
it_behaves_like 'a cloning option'
|
|
193
85
|
end
|
|
194
86
|
|
|
195
|
-
context
|
|
196
|
-
|
|
87
|
+
context 'when provided an array of strings' do
|
|
197
88
|
let(:selection) do
|
|
198
|
-
query.send(method, [
|
|
89
|
+
query.send(method, %w[field_one field_two])
|
|
199
90
|
end
|
|
200
91
|
|
|
201
|
-
it
|
|
92
|
+
it 'adds the sorting criteria' do
|
|
202
93
|
expect(selection.options).to eq(
|
|
203
|
-
{ sort:
|
|
94
|
+
{ sort: { 'field_one' => 1, 'field_two' => 1 } }
|
|
204
95
|
)
|
|
205
96
|
end
|
|
206
97
|
|
|
207
|
-
it_behaves_like
|
|
98
|
+
it_behaves_like 'a cloning option'
|
|
208
99
|
end
|
|
209
100
|
|
|
210
|
-
context
|
|
211
|
-
|
|
101
|
+
context 'when provided no options' do
|
|
212
102
|
let(:selection) do
|
|
213
103
|
query.send(method)
|
|
214
104
|
end
|
|
215
105
|
|
|
216
|
-
it
|
|
106
|
+
it 'does not add any sorting criteria' do
|
|
217
107
|
expect(selection.options).to be_empty
|
|
218
108
|
end
|
|
219
109
|
|
|
220
|
-
it
|
|
110
|
+
it 'returns the query' do
|
|
221
111
|
expect(selection).to eq(query)
|
|
222
112
|
end
|
|
223
113
|
|
|
224
|
-
it_behaves_like
|
|
114
|
+
it_behaves_like 'a cloning option'
|
|
225
115
|
end
|
|
226
116
|
|
|
227
|
-
context
|
|
228
|
-
|
|
117
|
+
context 'when provided nil' do
|
|
229
118
|
let(:selection) do
|
|
230
119
|
query.send(method, nil)
|
|
231
120
|
end
|
|
232
121
|
|
|
233
|
-
it
|
|
122
|
+
it 'does not add any sorting criteria' do
|
|
234
123
|
expect(selection.options).to be_empty
|
|
235
124
|
end
|
|
236
125
|
|
|
237
|
-
it
|
|
126
|
+
it 'returns the query' do
|
|
238
127
|
expect(selection).to eq(query)
|
|
239
128
|
end
|
|
240
129
|
|
|
241
|
-
it_behaves_like
|
|
130
|
+
it_behaves_like 'a cloning option'
|
|
242
131
|
end
|
|
243
132
|
end
|
|
244
133
|
end
|
|
245
134
|
end
|
|
246
135
|
|
|
247
|
-
describe
|
|
248
|
-
|
|
249
|
-
context "when provided no options" do
|
|
250
|
-
|
|
136
|
+
describe '#batch_size' do
|
|
137
|
+
context 'when provided no options' do
|
|
251
138
|
let(:selection) do
|
|
252
139
|
query.batch_size
|
|
253
140
|
end
|
|
254
141
|
|
|
255
|
-
it
|
|
142
|
+
it 'does not add any options' do
|
|
256
143
|
expect(selection.options).to eq({})
|
|
257
144
|
end
|
|
258
145
|
|
|
259
|
-
it_behaves_like
|
|
146
|
+
it_behaves_like 'a cloning option'
|
|
260
147
|
end
|
|
261
148
|
|
|
262
|
-
context
|
|
263
|
-
|
|
149
|
+
context 'when provided nil' do
|
|
264
150
|
let(:selection) do
|
|
265
151
|
query.batch_size(nil)
|
|
266
152
|
end
|
|
267
153
|
|
|
268
|
-
it
|
|
154
|
+
it 'does not add any options' do
|
|
269
155
|
expect(selection.options).to eq({})
|
|
270
156
|
end
|
|
271
157
|
|
|
272
|
-
it_behaves_like
|
|
158
|
+
it_behaves_like 'a cloning option'
|
|
273
159
|
end
|
|
274
160
|
|
|
275
|
-
context
|
|
276
|
-
|
|
161
|
+
context 'when provided arguments' do
|
|
277
162
|
let(:selection) do
|
|
278
163
|
query.batch_size(500)
|
|
279
164
|
end
|
|
280
165
|
|
|
281
|
-
it
|
|
166
|
+
it 'adds the field options' do
|
|
282
167
|
expect(selection.options).to eq({ batch_size: 500 })
|
|
283
168
|
end
|
|
284
169
|
|
|
285
|
-
it_behaves_like
|
|
170
|
+
it_behaves_like 'a cloning option'
|
|
286
171
|
end
|
|
287
172
|
end
|
|
288
173
|
|
|
289
|
-
[
|
|
290
|
-
|
|
174
|
+
%i[desc descending].each do |method|
|
|
291
175
|
describe "##{method}" do
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
context "when the query is aggregating" do
|
|
296
|
-
|
|
176
|
+
context 'when using the official mongodb driver syntax' do
|
|
177
|
+
context 'when the query is aggregating' do
|
|
297
178
|
let(:selection) do
|
|
298
179
|
query.project(name: 1).send(method, :field_one, :field_two)
|
|
299
180
|
end
|
|
300
181
|
|
|
301
|
-
it
|
|
182
|
+
it 'adds the sorting criteria' do
|
|
302
183
|
expect(selection.options).to eq(
|
|
303
|
-
{ sort: {
|
|
184
|
+
{ sort: { 'field_one' => -1, 'field_two' => -1 } }
|
|
304
185
|
)
|
|
305
186
|
end
|
|
306
187
|
|
|
307
|
-
it
|
|
188
|
+
it 'adds the sort to the aggregation' do
|
|
308
189
|
expect(selection.pipeline).to include(
|
|
309
|
-
{
|
|
310
|
-
)
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
it "does not add multiple entries to the pipeline" do
|
|
314
|
-
expect(selection.pipeline).to_not include(
|
|
315
|
-
{ "$sort" => { "field_one" => -1 }}
|
|
316
|
-
)
|
|
317
|
-
end
|
|
318
|
-
|
|
319
|
-
it_behaves_like "a cloning option"
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
context "when provided symbols" do
|
|
323
|
-
|
|
324
|
-
let(:selection) do
|
|
325
|
-
query.send(method, :field_one, :field_two)
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
it "adds the sorting criteria" do
|
|
329
|
-
expect(selection.options).to eq(
|
|
330
|
-
{ sort: { "field_one" => -1, "field_two" => -1 }}
|
|
331
|
-
)
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
it_behaves_like "a cloning option"
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
context "when provided an array of symbols" do
|
|
338
|
-
|
|
339
|
-
let(:selection) do
|
|
340
|
-
query.send(method, [ :field_one, :field_two ])
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
it "adds the sorting criteria" do
|
|
344
|
-
expect(selection.options).to eq(
|
|
345
|
-
{ sort: { "field_one" => -1, "field_two" => -1 }}
|
|
346
|
-
)
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
it_behaves_like "a cloning option"
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
context "when provided strings" do
|
|
353
|
-
|
|
354
|
-
let(:selection) do
|
|
355
|
-
query.send(method, "field_one", "field_two")
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
it "adds the sorting criteria" do
|
|
359
|
-
expect(selection.options).to eq(
|
|
360
|
-
{ sort: { "field_one" => -1, "field_two" => -1 }}
|
|
190
|
+
{ '$sort' => { 'field_one' => -1, 'field_two' => -1 } }
|
|
361
191
|
)
|
|
362
192
|
end
|
|
363
193
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
context "when provided an array of strings" do
|
|
368
|
-
|
|
369
|
-
let(:selection) do
|
|
370
|
-
query.send(method, [ "field_one", "field_two" ])
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
it "adds the sorting criteria" do
|
|
374
|
-
expect(selection.options).to eq(
|
|
375
|
-
{ sort: { "field_one" => -1, "field_two" => -1 }}
|
|
194
|
+
it 'does not add multiple entries to the pipeline' do
|
|
195
|
+
expect(selection.pipeline).not_to include(
|
|
196
|
+
{ '$sort' => { 'field_one' => -1 } }
|
|
376
197
|
)
|
|
377
198
|
end
|
|
378
199
|
|
|
379
|
-
it_behaves_like
|
|
200
|
+
it_behaves_like 'a cloning option'
|
|
380
201
|
end
|
|
381
202
|
|
|
382
|
-
context
|
|
383
|
-
|
|
384
|
-
let(:selection) do
|
|
385
|
-
query.send(method)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
it "does not add any sorting criteria" do
|
|
389
|
-
expect(selection.options).to be_empty
|
|
390
|
-
end
|
|
391
|
-
|
|
392
|
-
it "returns the query" do
|
|
393
|
-
expect(selection).to eq(query)
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
it_behaves_like "a cloning option"
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
context "when provided nil" do
|
|
400
|
-
|
|
401
|
-
let(:selection) do
|
|
402
|
-
query.send(method, nil)
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
it "does not add any sorting criteria" do
|
|
406
|
-
expect(selection.options).to be_empty
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
it "returns the query" do
|
|
410
|
-
expect(selection).to eq(query)
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
it_behaves_like "a cloning option"
|
|
414
|
-
end
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
context "when using the mongo-1.x driver syntax" do
|
|
418
|
-
|
|
419
|
-
let(:query) do
|
|
420
|
-
Mongoid::Query.new({}, {}, :mongo1x)
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
context "when provided symbols" do
|
|
424
|
-
|
|
203
|
+
context 'when provided symbols' do
|
|
425
204
|
let(:selection) do
|
|
426
205
|
query.send(method, :field_one, :field_two)
|
|
427
206
|
end
|
|
428
207
|
|
|
429
|
-
it
|
|
208
|
+
it 'adds the sorting criteria' do
|
|
430
209
|
expect(selection.options).to eq(
|
|
431
|
-
{ sort:
|
|
210
|
+
{ sort: { 'field_one' => -1, 'field_two' => -1 } }
|
|
432
211
|
)
|
|
433
212
|
end
|
|
434
213
|
|
|
435
|
-
it_behaves_like
|
|
214
|
+
it_behaves_like 'a cloning option'
|
|
436
215
|
end
|
|
437
216
|
|
|
438
|
-
context
|
|
439
|
-
|
|
217
|
+
context 'when provided an array of symbols' do
|
|
440
218
|
let(:selection) do
|
|
441
|
-
query.send(method, [
|
|
219
|
+
query.send(method, %i[field_one field_two])
|
|
442
220
|
end
|
|
443
221
|
|
|
444
|
-
it
|
|
222
|
+
it 'adds the sorting criteria' do
|
|
445
223
|
expect(selection.options).to eq(
|
|
446
|
-
{ sort:
|
|
224
|
+
{ sort: { 'field_one' => -1, 'field_two' => -1 } }
|
|
447
225
|
)
|
|
448
226
|
end
|
|
449
227
|
|
|
450
|
-
it_behaves_like
|
|
228
|
+
it_behaves_like 'a cloning option'
|
|
451
229
|
end
|
|
452
230
|
|
|
453
|
-
context
|
|
454
|
-
|
|
231
|
+
context 'when provided strings' do
|
|
455
232
|
let(:selection) do
|
|
456
|
-
query.send(method,
|
|
233
|
+
query.send(method, 'field_one', 'field_two')
|
|
457
234
|
end
|
|
458
235
|
|
|
459
|
-
it
|
|
236
|
+
it 'adds the sorting criteria' do
|
|
460
237
|
expect(selection.options).to eq(
|
|
461
|
-
{ sort:
|
|
238
|
+
{ sort: { 'field_one' => -1, 'field_two' => -1 } }
|
|
462
239
|
)
|
|
463
240
|
end
|
|
464
241
|
|
|
465
|
-
it_behaves_like
|
|
242
|
+
it_behaves_like 'a cloning option'
|
|
466
243
|
end
|
|
467
244
|
|
|
468
|
-
context
|
|
469
|
-
|
|
245
|
+
context 'when provided an array of strings' do
|
|
470
246
|
let(:selection) do
|
|
471
|
-
query.send(method, [
|
|
247
|
+
query.send(method, %w[field_one field_two])
|
|
472
248
|
end
|
|
473
249
|
|
|
474
|
-
it
|
|
250
|
+
it 'adds the sorting criteria' do
|
|
475
251
|
expect(selection.options).to eq(
|
|
476
|
-
{ sort:
|
|
252
|
+
{ sort: { 'field_one' => -1, 'field_two' => -1 } }
|
|
477
253
|
)
|
|
478
254
|
end
|
|
479
255
|
|
|
480
|
-
it_behaves_like
|
|
256
|
+
it_behaves_like 'a cloning option'
|
|
481
257
|
end
|
|
482
258
|
|
|
483
|
-
context
|
|
484
|
-
|
|
259
|
+
context 'when provided no options' do
|
|
485
260
|
let(:selection) do
|
|
486
261
|
query.send(method)
|
|
487
262
|
end
|
|
488
263
|
|
|
489
|
-
it
|
|
264
|
+
it 'does not add any sorting criteria' do
|
|
490
265
|
expect(selection.options).to be_empty
|
|
491
266
|
end
|
|
492
267
|
|
|
493
|
-
it
|
|
268
|
+
it 'returns the query' do
|
|
494
269
|
expect(selection).to eq(query)
|
|
495
270
|
end
|
|
496
271
|
|
|
497
|
-
it_behaves_like
|
|
272
|
+
it_behaves_like 'a cloning option'
|
|
498
273
|
end
|
|
499
274
|
|
|
500
|
-
context
|
|
501
|
-
|
|
275
|
+
context 'when provided nil' do
|
|
502
276
|
let(:selection) do
|
|
503
277
|
query.send(method, nil)
|
|
504
278
|
end
|
|
505
279
|
|
|
506
|
-
it
|
|
280
|
+
it 'does not add any sorting criteria' do
|
|
507
281
|
expect(selection.options).to be_empty
|
|
508
282
|
end
|
|
509
283
|
|
|
510
|
-
it
|
|
284
|
+
it 'returns the query' do
|
|
511
285
|
expect(selection).to eq(query)
|
|
512
286
|
end
|
|
513
287
|
|
|
514
|
-
it_behaves_like
|
|
288
|
+
it_behaves_like 'a cloning option'
|
|
515
289
|
end
|
|
516
290
|
end
|
|
517
291
|
end
|
|
518
292
|
end
|
|
519
293
|
|
|
520
|
-
describe
|
|
521
|
-
|
|
522
|
-
context "when provided no options" do
|
|
523
|
-
|
|
294
|
+
describe '#hint' do
|
|
295
|
+
context 'when provided no options' do
|
|
524
296
|
let(:selection) do
|
|
525
297
|
query.hint
|
|
526
298
|
end
|
|
527
299
|
|
|
528
|
-
it
|
|
300
|
+
it 'does not add any options' do
|
|
529
301
|
expect(selection.options).to eq({})
|
|
530
302
|
end
|
|
531
303
|
|
|
532
|
-
it
|
|
304
|
+
it 'returns the query' do
|
|
533
305
|
expect(selection).to eq(query)
|
|
534
306
|
end
|
|
535
307
|
|
|
536
|
-
it_behaves_like
|
|
308
|
+
it_behaves_like 'a cloning option'
|
|
537
309
|
end
|
|
538
310
|
|
|
539
|
-
context
|
|
540
|
-
|
|
311
|
+
context 'when provided nil' do
|
|
541
312
|
let(:selection) do
|
|
542
313
|
query.hint(nil)
|
|
543
314
|
end
|
|
544
315
|
|
|
545
|
-
it
|
|
316
|
+
it 'does not add any options' do
|
|
546
317
|
expect(selection.options).to eq({})
|
|
547
318
|
end
|
|
548
319
|
|
|
549
|
-
it
|
|
320
|
+
it 'returns the query' do
|
|
550
321
|
expect(selection).to eq(query)
|
|
551
322
|
end
|
|
552
323
|
|
|
553
|
-
it_behaves_like
|
|
324
|
+
it_behaves_like 'a cloning option'
|
|
554
325
|
end
|
|
555
326
|
|
|
556
|
-
context
|
|
557
|
-
|
|
558
|
-
context "when the argument is a hash" do
|
|
559
|
-
|
|
327
|
+
context 'when provided arguments' do
|
|
328
|
+
context 'when the argument is a hash' do
|
|
560
329
|
let(:selection) do
|
|
561
|
-
query.hint(
|
|
330
|
+
query.hint('$natural' => 1)
|
|
562
331
|
end
|
|
563
332
|
|
|
564
|
-
it
|
|
565
|
-
expect(selection.options).to eq({ hint: {
|
|
333
|
+
it 'adds the field options' do
|
|
334
|
+
expect(selection.options).to eq({ hint: { '$natural' => 1 } })
|
|
566
335
|
end
|
|
567
336
|
|
|
568
|
-
it_behaves_like
|
|
337
|
+
it_behaves_like 'a cloning option'
|
|
569
338
|
end
|
|
570
339
|
end
|
|
571
340
|
end
|
|
572
341
|
|
|
573
|
-
describe
|
|
574
|
-
|
|
575
|
-
context "when provided no options" do
|
|
576
|
-
|
|
342
|
+
describe '#limit' do
|
|
343
|
+
context 'when provided no options' do
|
|
577
344
|
let(:selection) do
|
|
578
345
|
query.limit
|
|
579
346
|
end
|
|
580
347
|
|
|
581
|
-
it
|
|
348
|
+
it 'does not add any options' do
|
|
582
349
|
expect(selection.options).to eq({})
|
|
583
350
|
end
|
|
584
351
|
|
|
585
|
-
it
|
|
352
|
+
it 'returns the query' do
|
|
586
353
|
expect(selection).to eq(query)
|
|
587
354
|
end
|
|
588
355
|
|
|
589
|
-
it_behaves_like
|
|
356
|
+
it_behaves_like 'a cloning option'
|
|
590
357
|
end
|
|
591
358
|
|
|
592
|
-
context
|
|
593
|
-
|
|
359
|
+
context 'when provided nil' do
|
|
594
360
|
let(:selection) do
|
|
595
361
|
query.limit(nil)
|
|
596
362
|
end
|
|
597
363
|
|
|
598
|
-
it
|
|
364
|
+
it 'does not add any options' do
|
|
599
365
|
expect(selection.options).to eq({})
|
|
600
366
|
end
|
|
601
367
|
|
|
602
|
-
it
|
|
368
|
+
it 'returns the query' do
|
|
603
369
|
expect(selection).to eq(query)
|
|
604
370
|
end
|
|
605
371
|
|
|
606
|
-
it_behaves_like
|
|
372
|
+
it_behaves_like 'a cloning option'
|
|
607
373
|
end
|
|
608
374
|
|
|
609
|
-
context
|
|
610
|
-
|
|
375
|
+
context 'when the query is aggregating' do
|
|
611
376
|
let(:selection) do
|
|
612
377
|
query.project(name: 1).limit(10)
|
|
613
378
|
end
|
|
614
379
|
|
|
615
|
-
it
|
|
380
|
+
it 'adds the field options' do
|
|
616
381
|
expect(selection.options).to eq({ limit: 10 })
|
|
617
382
|
end
|
|
618
383
|
|
|
619
|
-
it
|
|
620
|
-
expect(selection.pipeline).to include({
|
|
384
|
+
it 'adds the limit to the aggregation' do
|
|
385
|
+
expect(selection.pipeline).to include({ '$limit' => 10 })
|
|
621
386
|
end
|
|
622
387
|
|
|
623
|
-
it_behaves_like
|
|
388
|
+
it_behaves_like 'a cloning option'
|
|
624
389
|
end
|
|
625
390
|
|
|
626
|
-
context
|
|
627
|
-
|
|
628
|
-
context "when the argument is an integer" do
|
|
629
|
-
|
|
391
|
+
context 'when provided arguments' do
|
|
392
|
+
context 'when the argument is an integer' do
|
|
630
393
|
let(:selection) do
|
|
631
394
|
query.limit(10)
|
|
632
395
|
end
|
|
633
396
|
|
|
634
|
-
it
|
|
397
|
+
it 'adds the field options' do
|
|
635
398
|
expect(selection.options).to eq({ limit: 10 })
|
|
636
399
|
end
|
|
637
400
|
|
|
638
|
-
it_behaves_like
|
|
401
|
+
it_behaves_like 'a cloning option'
|
|
639
402
|
end
|
|
640
403
|
|
|
641
|
-
context
|
|
642
|
-
|
|
404
|
+
context 'when the argument is a float' do
|
|
643
405
|
let(:selection) do
|
|
644
406
|
query.limit(10.25)
|
|
645
407
|
end
|
|
646
408
|
|
|
647
|
-
it
|
|
409
|
+
it 'adds the field options as an integer' do
|
|
648
410
|
expect(selection.options).to eq({ limit: 10 })
|
|
649
411
|
end
|
|
650
412
|
|
|
651
|
-
it_behaves_like
|
|
413
|
+
it_behaves_like 'a cloning option'
|
|
652
414
|
end
|
|
653
415
|
|
|
654
|
-
context
|
|
655
|
-
|
|
416
|
+
context 'when the argument is a string' do
|
|
656
417
|
let(:selection) do
|
|
657
|
-
query.limit(
|
|
418
|
+
query.limit('10')
|
|
658
419
|
end
|
|
659
420
|
|
|
660
|
-
it
|
|
421
|
+
it 'adds the field options as an integer' do
|
|
661
422
|
expect(selection.options).to eq({ limit: 10 })
|
|
662
423
|
end
|
|
663
424
|
|
|
664
|
-
it_behaves_like
|
|
425
|
+
it_behaves_like 'a cloning option'
|
|
665
426
|
end
|
|
666
427
|
end
|
|
667
428
|
end
|
|
668
429
|
|
|
669
|
-
describe
|
|
670
|
-
|
|
671
|
-
context "when provided no options" do
|
|
672
|
-
|
|
430
|
+
describe '#max_scan' do
|
|
431
|
+
context 'when provided no options' do
|
|
673
432
|
let(:selection) do
|
|
674
433
|
query.max_scan
|
|
675
434
|
end
|
|
676
435
|
|
|
677
|
-
it
|
|
436
|
+
it 'does not add any options' do
|
|
678
437
|
expect(selection.options).to eq({})
|
|
679
438
|
end
|
|
680
439
|
|
|
681
|
-
it
|
|
440
|
+
it 'returns the query' do
|
|
682
441
|
expect(selection).to eq(query)
|
|
683
442
|
end
|
|
684
443
|
|
|
685
|
-
it_behaves_like
|
|
444
|
+
it_behaves_like 'a cloning option'
|
|
686
445
|
end
|
|
687
446
|
|
|
688
|
-
context
|
|
689
|
-
|
|
447
|
+
context 'when provided nil' do
|
|
690
448
|
let(:selection) do
|
|
691
449
|
query.max_scan(nil)
|
|
692
450
|
end
|
|
693
451
|
|
|
694
|
-
it
|
|
452
|
+
it 'does not add any options' do
|
|
695
453
|
expect(selection.options).to eq({})
|
|
696
454
|
end
|
|
697
455
|
|
|
698
|
-
it
|
|
456
|
+
it 'returns the query' do
|
|
699
457
|
expect(selection).to eq(query)
|
|
700
458
|
end
|
|
701
459
|
|
|
702
|
-
it_behaves_like
|
|
460
|
+
it_behaves_like 'a cloning option'
|
|
703
461
|
end
|
|
704
462
|
|
|
705
|
-
context
|
|
706
|
-
|
|
463
|
+
context 'when provided arguments' do
|
|
707
464
|
let(:selection) do
|
|
708
465
|
query.max_scan(500)
|
|
709
466
|
end
|
|
710
467
|
|
|
711
|
-
it
|
|
468
|
+
it 'adds the field options' do
|
|
712
469
|
expect(selection.options).to eq({ max_scan: 500 })
|
|
713
470
|
end
|
|
714
471
|
|
|
715
|
-
it_behaves_like
|
|
472
|
+
it_behaves_like 'a cloning option'
|
|
716
473
|
end
|
|
717
474
|
end
|
|
718
475
|
|
|
719
|
-
describe
|
|
720
|
-
|
|
721
|
-
context "when provided no options" do
|
|
722
|
-
|
|
476
|
+
describe '#max_time_ms' do
|
|
477
|
+
context 'when provided no options' do
|
|
723
478
|
let(:selection) do
|
|
724
479
|
query.max_time_ms
|
|
725
480
|
end
|
|
726
481
|
|
|
727
|
-
it
|
|
482
|
+
it 'does not add any options' do
|
|
728
483
|
expect(selection.options).to eq({})
|
|
729
484
|
end
|
|
730
485
|
|
|
731
|
-
it
|
|
486
|
+
it 'returns the query' do
|
|
732
487
|
expect(selection).to eq(query)
|
|
733
488
|
end
|
|
734
489
|
|
|
735
|
-
it_behaves_like
|
|
490
|
+
it_behaves_like 'a cloning option'
|
|
736
491
|
end
|
|
737
492
|
|
|
738
|
-
context
|
|
739
|
-
|
|
493
|
+
context 'when provided nil' do
|
|
740
494
|
let(:selection) do
|
|
741
495
|
query.max_time_ms(nil)
|
|
742
496
|
end
|
|
743
497
|
|
|
744
|
-
it
|
|
498
|
+
it 'does not add any options' do
|
|
745
499
|
expect(selection.options).to eq({})
|
|
746
500
|
end
|
|
747
501
|
|
|
748
|
-
it
|
|
502
|
+
it 'returns the query' do
|
|
749
503
|
expect(selection).to eq(query)
|
|
750
504
|
end
|
|
751
505
|
|
|
752
|
-
it_behaves_like
|
|
506
|
+
it_behaves_like 'a cloning option'
|
|
753
507
|
end
|
|
754
508
|
|
|
755
|
-
context
|
|
756
|
-
|
|
509
|
+
context 'when provided arguments' do
|
|
757
510
|
let(:selection) do
|
|
758
511
|
query.max_time_ms(500)
|
|
759
512
|
end
|
|
760
513
|
|
|
761
|
-
it
|
|
514
|
+
it 'adds the field options' do
|
|
762
515
|
expect(selection.options).to eq({ max_time_ms: 500 })
|
|
763
516
|
end
|
|
764
517
|
|
|
765
|
-
it_behaves_like
|
|
518
|
+
it_behaves_like 'a cloning option'
|
|
766
519
|
end
|
|
767
520
|
end
|
|
768
521
|
|
|
769
|
-
describe
|
|
770
|
-
|
|
522
|
+
describe '#no_timeout' do
|
|
771
523
|
let(:selection) do
|
|
772
524
|
query.no_timeout
|
|
773
525
|
end
|
|
774
526
|
|
|
775
|
-
it
|
|
527
|
+
it 'adds the timeout option' do
|
|
776
528
|
expect(selection.options).to eq({ timeout: false })
|
|
777
529
|
end
|
|
778
530
|
|
|
779
|
-
it_behaves_like
|
|
531
|
+
it_behaves_like 'a cloning option'
|
|
780
532
|
end
|
|
781
533
|
|
|
782
|
-
describe
|
|
783
|
-
|
|
784
|
-
context "when provided no options" do
|
|
785
|
-
|
|
534
|
+
describe '#only' do
|
|
535
|
+
context 'when provided no options' do
|
|
786
536
|
let(:selection) do
|
|
787
537
|
query.only
|
|
788
538
|
end
|
|
789
539
|
|
|
790
|
-
it
|
|
540
|
+
it 'does not add any options' do
|
|
791
541
|
expect(selection.options).to eq({})
|
|
792
542
|
end
|
|
793
543
|
|
|
794
|
-
it
|
|
544
|
+
it 'returns the query' do
|
|
795
545
|
expect(selection).to eq(query)
|
|
796
546
|
end
|
|
797
547
|
|
|
798
|
-
it_behaves_like
|
|
548
|
+
it_behaves_like 'a cloning option'
|
|
799
549
|
end
|
|
800
550
|
|
|
801
|
-
context
|
|
802
|
-
|
|
551
|
+
context 'when provided nil' do
|
|
803
552
|
let(:selection) do
|
|
804
553
|
query.only(nil)
|
|
805
554
|
end
|
|
806
555
|
|
|
807
|
-
it
|
|
556
|
+
it 'does not add any options' do
|
|
808
557
|
expect(selection.options).to eq({})
|
|
809
558
|
end
|
|
810
559
|
|
|
811
|
-
it
|
|
560
|
+
it 'returns the query' do
|
|
812
561
|
expect(selection).to eq(query)
|
|
813
562
|
end
|
|
814
563
|
|
|
815
|
-
it_behaves_like
|
|
564
|
+
it_behaves_like 'a cloning option'
|
|
816
565
|
end
|
|
817
566
|
|
|
818
|
-
context
|
|
819
|
-
|
|
820
|
-
context "as several arguments" do
|
|
821
|
-
|
|
567
|
+
context 'when provided fields' do
|
|
568
|
+
context 'as several arguments' do
|
|
822
569
|
let(:selection) do
|
|
823
570
|
query.only(:first, :second)
|
|
824
571
|
end
|
|
825
572
|
|
|
826
|
-
it
|
|
573
|
+
it 'adds the field options' do
|
|
827
574
|
expect(selection.options).to eq(
|
|
828
|
-
{ fields: {
|
|
575
|
+
{ fields: { 'first' => 1, 'second' => 1 } }
|
|
829
576
|
)
|
|
830
577
|
end
|
|
831
578
|
|
|
832
|
-
it_behaves_like
|
|
579
|
+
it_behaves_like 'a cloning option'
|
|
833
580
|
end
|
|
834
581
|
|
|
835
|
-
context
|
|
836
|
-
|
|
582
|
+
context 'as one argument - array' do
|
|
837
583
|
let(:selection) do
|
|
838
|
-
query.only([
|
|
584
|
+
query.only(%i[first second])
|
|
839
585
|
end
|
|
840
586
|
|
|
841
|
-
it
|
|
587
|
+
it 'adds the field options' do
|
|
842
588
|
expect(selection.options).to eq(
|
|
843
|
-
{ fields: {
|
|
589
|
+
{ fields: { 'first' => 1, 'second' => 1 } }
|
|
844
590
|
)
|
|
845
591
|
end
|
|
846
592
|
|
|
847
|
-
it_behaves_like
|
|
593
|
+
it_behaves_like 'a cloning option'
|
|
848
594
|
end
|
|
849
595
|
end
|
|
850
596
|
|
|
851
|
-
context
|
|
852
|
-
|
|
597
|
+
context 'when #without was called first' do
|
|
853
598
|
let(:selection) do
|
|
854
599
|
query.without(:id).only(:first)
|
|
855
600
|
end
|
|
856
601
|
|
|
857
|
-
it
|
|
602
|
+
it 'adds both fields to option' do
|
|
858
603
|
expect(selection.options).to eq(
|
|
859
|
-
{ fields: {
|
|
604
|
+
{ fields: { 'id' => 0, 'first' => 1 } }
|
|
860
605
|
)
|
|
861
606
|
end
|
|
862
607
|
end
|
|
863
608
|
end
|
|
864
609
|
|
|
865
|
-
[
|
|
866
|
-
|
|
610
|
+
%i[order order_by].each do |method|
|
|
867
611
|
describe "##{method}" do
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
context "when provided a hash" do
|
|
872
|
-
|
|
873
|
-
context "when the query is aggregating" do
|
|
874
|
-
|
|
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
|
|
875
615
|
let(:selection) do
|
|
876
616
|
query.project(name: 1).send("#{method}", field_one: 1, field_two: -1)
|
|
877
617
|
end
|
|
878
618
|
|
|
879
|
-
it
|
|
619
|
+
it 'adds the sorting criteria' do
|
|
880
620
|
expect(selection.options).to eq(
|
|
881
|
-
{ sort: {
|
|
621
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
882
622
|
)
|
|
883
623
|
end
|
|
884
624
|
|
|
885
|
-
it
|
|
625
|
+
it 'adds the sort to the aggregation' do
|
|
886
626
|
expect(selection.pipeline).to include(
|
|
887
|
-
{
|
|
627
|
+
{ '$sort' => { 'field_one' => 1, 'field_two' => -1 } }
|
|
888
628
|
)
|
|
889
629
|
end
|
|
890
630
|
|
|
891
|
-
it
|
|
892
|
-
expect(selection.pipeline).
|
|
893
|
-
{
|
|
631
|
+
it 'does not add multiple entries to the pipeline' do
|
|
632
|
+
expect(selection.pipeline).not_to include(
|
|
633
|
+
{ '$sort' => { 'field_one' => 1 } }
|
|
894
634
|
)
|
|
895
635
|
end
|
|
896
636
|
|
|
897
|
-
it_behaves_like
|
|
637
|
+
it_behaves_like 'a cloning option'
|
|
898
638
|
end
|
|
899
639
|
|
|
900
|
-
context
|
|
901
|
-
|
|
640
|
+
context 'when the hash has integer values' do
|
|
902
641
|
let(:selection) do
|
|
903
642
|
query.send("#{method}", field_one: 1, field_two: -1)
|
|
904
643
|
end
|
|
905
644
|
|
|
906
|
-
it
|
|
645
|
+
it 'adds the sorting criteria' do
|
|
907
646
|
expect(selection.options).to eq(
|
|
908
|
-
{ sort: {
|
|
647
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
909
648
|
)
|
|
910
649
|
end
|
|
911
650
|
|
|
912
|
-
it_behaves_like
|
|
651
|
+
it_behaves_like 'a cloning option'
|
|
913
652
|
end
|
|
914
653
|
|
|
915
|
-
context
|
|
916
|
-
|
|
654
|
+
context 'when the hash has symbol values' do
|
|
917
655
|
let(:selection) do
|
|
918
656
|
query.send("#{method}", field_one: :asc, field_two: :desc)
|
|
919
657
|
end
|
|
920
658
|
|
|
921
|
-
it
|
|
659
|
+
it 'adds the sorting criteria' do
|
|
922
660
|
expect(selection.options).to eq(
|
|
923
|
-
{ sort: {
|
|
661
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
924
662
|
)
|
|
925
663
|
end
|
|
926
664
|
|
|
927
|
-
it_behaves_like
|
|
665
|
+
it_behaves_like 'a cloning option'
|
|
928
666
|
end
|
|
929
667
|
|
|
930
|
-
context
|
|
931
|
-
|
|
668
|
+
context 'when the hash has string values' do
|
|
932
669
|
let(:selection) do
|
|
933
|
-
query.send("#{method}", field_one:
|
|
670
|
+
query.send("#{method}", field_one: 'asc', field_two: 'desc')
|
|
934
671
|
end
|
|
935
672
|
|
|
936
|
-
it
|
|
673
|
+
it 'adds the sorting criteria' do
|
|
937
674
|
expect(selection.options).to eq(
|
|
938
|
-
{ sort: {
|
|
675
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
939
676
|
)
|
|
940
677
|
end
|
|
941
678
|
|
|
942
|
-
it_behaves_like
|
|
679
|
+
it_behaves_like 'a cloning option'
|
|
943
680
|
end
|
|
944
|
-
end
|
|
945
|
-
|
|
946
|
-
context "when provided an array" do
|
|
947
|
-
|
|
948
|
-
context "when the array is multi-dimensional" do
|
|
949
|
-
|
|
950
|
-
context "when the arrays have integer values" do
|
|
951
|
-
|
|
952
|
-
let(:selection) do
|
|
953
|
-
query.send("#{method}", [[ :field_one, 1 ],[ :field_two, -1 ]])
|
|
954
|
-
end
|
|
955
|
-
|
|
956
|
-
it "adds the sorting criteria" do
|
|
957
|
-
expect(selection.options).to eq(
|
|
958
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
959
|
-
)
|
|
960
|
-
end
|
|
961
|
-
|
|
962
|
-
it_behaves_like "a cloning option"
|
|
963
|
-
end
|
|
964
|
-
|
|
965
|
-
context "when the arrays have symbol values" do
|
|
966
|
-
|
|
967
|
-
let(:selection) do
|
|
968
|
-
query.send("#{method}", [[ :field_one, :asc ],[ :field_two, :desc ]])
|
|
969
|
-
end
|
|
970
|
-
|
|
971
|
-
it "adds the sorting criteria" do
|
|
972
|
-
expect(selection.options).to eq(
|
|
973
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
974
|
-
)
|
|
975
|
-
end
|
|
976
|
-
|
|
977
|
-
it_behaves_like "a cloning option"
|
|
978
|
-
end
|
|
979
|
-
|
|
980
|
-
context "when the arrays have string values" do
|
|
981
|
-
|
|
982
|
-
let(:selection) do
|
|
983
|
-
query.send("#{method}", [[ :field_one, "asc" ],[ :field_two, "desc" ]])
|
|
984
|
-
end
|
|
985
|
-
|
|
986
|
-
it "adds the sorting criteria" do
|
|
987
|
-
expect(selection.options).to eq(
|
|
988
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
989
|
-
)
|
|
990
|
-
end
|
|
991
|
-
|
|
992
|
-
it_behaves_like "a cloning option"
|
|
993
|
-
end
|
|
994
|
-
end
|
|
995
|
-
|
|
996
|
-
context "when the array is selectable keys" do
|
|
997
681
|
|
|
682
|
+
context 'when the hash has hash values' do
|
|
998
683
|
let(:selection) do
|
|
999
|
-
query.send("#{method}",
|
|
684
|
+
query.send("#{method}", score: { '$meta' => 'textScore' })
|
|
1000
685
|
end
|
|
1001
686
|
|
|
1002
|
-
it
|
|
687
|
+
it 'adds the sorting criteria' do
|
|
1003
688
|
expect(selection.options).to eq(
|
|
1004
|
-
{ sort: {
|
|
689
|
+
{ sort: { 'score' => { '$meta' => 'textScore' } } }
|
|
1005
690
|
)
|
|
1006
691
|
end
|
|
1007
692
|
|
|
1008
|
-
it_behaves_like
|
|
693
|
+
it_behaves_like 'a cloning option'
|
|
1009
694
|
end
|
|
1010
695
|
end
|
|
1011
696
|
|
|
1012
|
-
context
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
context "when the values have integer directions" do
|
|
1017
|
-
|
|
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
|
|
1018
700
|
let(:selection) do
|
|
1019
|
-
query.send("#{method}", [ :field_one, 1 ],[ :field_two, -1 ])
|
|
701
|
+
query.send("#{method}", [ [ :field_one, 1 ], [ :field_two, -1 ] ])
|
|
1020
702
|
end
|
|
1021
703
|
|
|
1022
|
-
it
|
|
704
|
+
it 'adds the sorting criteria' do
|
|
1023
705
|
expect(selection.options).to eq(
|
|
1024
|
-
{ sort: {
|
|
706
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1025
707
|
)
|
|
1026
708
|
end
|
|
1027
709
|
|
|
1028
|
-
it_behaves_like
|
|
710
|
+
it_behaves_like 'a cloning option'
|
|
1029
711
|
end
|
|
1030
712
|
|
|
1031
|
-
context
|
|
1032
|
-
|
|
713
|
+
context 'when the arrays have symbol values' do
|
|
1033
714
|
let(:selection) do
|
|
1034
|
-
query.send("#{method}", [
|
|
715
|
+
query.send("#{method}", [ %i[field_one asc], %i[field_two desc] ])
|
|
1035
716
|
end
|
|
1036
717
|
|
|
1037
|
-
it
|
|
718
|
+
it 'adds the sorting criteria' do
|
|
1038
719
|
expect(selection.options).to eq(
|
|
1039
|
-
{ sort: {
|
|
720
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1040
721
|
)
|
|
1041
722
|
end
|
|
1042
723
|
|
|
1043
|
-
it_behaves_like
|
|
724
|
+
it_behaves_like 'a cloning option'
|
|
1044
725
|
end
|
|
1045
726
|
|
|
1046
|
-
context
|
|
1047
|
-
|
|
727
|
+
context 'when the arrays have string values' do
|
|
1048
728
|
let(:selection) do
|
|
1049
|
-
query.send("#{method}", [ :field_one,
|
|
729
|
+
query.send("#{method}", [ [ :field_one, 'asc' ], [ :field_two, 'desc' ] ])
|
|
1050
730
|
end
|
|
1051
731
|
|
|
1052
|
-
it
|
|
732
|
+
it 'adds the sorting criteria' do
|
|
1053
733
|
expect(selection.options).to eq(
|
|
1054
|
-
{ sort: {
|
|
734
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1055
735
|
)
|
|
1056
736
|
end
|
|
1057
737
|
|
|
1058
|
-
it_behaves_like
|
|
738
|
+
it_behaves_like 'a cloning option'
|
|
1059
739
|
end
|
|
1060
740
|
end
|
|
1061
741
|
|
|
1062
|
-
context
|
|
1063
|
-
|
|
1064
|
-
let(:selection) do
|
|
1065
|
-
query.send("#{method}", :field_one.asc, :field_two.desc)
|
|
1066
|
-
end
|
|
1067
|
-
|
|
1068
|
-
it "adds the sorting criteria" do
|
|
1069
|
-
expect(selection.options).to eq(
|
|
1070
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
1071
|
-
)
|
|
1072
|
-
end
|
|
1073
|
-
|
|
1074
|
-
it_behaves_like "a cloning option"
|
|
1075
|
-
end
|
|
1076
|
-
end
|
|
1077
|
-
|
|
1078
|
-
context "when provided a string" do
|
|
1079
|
-
|
|
1080
|
-
context "when the direction is lowercase" do
|
|
1081
|
-
|
|
1082
|
-
context "when abbreviated" do
|
|
1083
|
-
|
|
1084
|
-
let(:selection) do
|
|
1085
|
-
query.send("#{method}", "field_one asc, field_two desc")
|
|
1086
|
-
end
|
|
1087
|
-
|
|
1088
|
-
it "adds the sorting criteria" do
|
|
1089
|
-
expect(selection.options).to eq(
|
|
1090
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
1091
|
-
)
|
|
1092
|
-
end
|
|
1093
|
-
|
|
1094
|
-
it_behaves_like "a cloning option"
|
|
1095
|
-
end
|
|
1096
|
-
|
|
1097
|
-
context "when spelled out" do
|
|
1098
|
-
|
|
1099
|
-
let(:selection) do
|
|
1100
|
-
query.send("#{method}", "field_one ascending, field_two descending")
|
|
1101
|
-
end
|
|
1102
|
-
|
|
1103
|
-
it "adds the sorting criteria" do
|
|
1104
|
-
expect(selection.options).to eq(
|
|
1105
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
1106
|
-
)
|
|
1107
|
-
end
|
|
1108
|
-
|
|
1109
|
-
it_behaves_like "a cloning option"
|
|
1110
|
-
end
|
|
1111
|
-
end
|
|
1112
|
-
|
|
1113
|
-
context "when the direction is uppercase" do
|
|
1114
|
-
|
|
1115
|
-
context "when abbreviated" do
|
|
1116
|
-
|
|
1117
|
-
let(:selection) do
|
|
1118
|
-
query.send("#{method}", "field_one ASC, field_two DESC")
|
|
1119
|
-
end
|
|
1120
|
-
|
|
1121
|
-
it "adds the sorting criteria" do
|
|
1122
|
-
expect(selection.options).to eq(
|
|
1123
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
1124
|
-
)
|
|
1125
|
-
end
|
|
1126
|
-
|
|
1127
|
-
it_behaves_like "a cloning option"
|
|
1128
|
-
end
|
|
1129
|
-
|
|
1130
|
-
context "when spelled out" do
|
|
1131
|
-
|
|
1132
|
-
let(:selection) do
|
|
1133
|
-
query.send("#{method}", "field_one ASCENDING, field_two DESCENDING")
|
|
1134
|
-
end
|
|
1135
|
-
|
|
1136
|
-
it "adds the sorting criteria" do
|
|
1137
|
-
expect(selection.options).to eq(
|
|
1138
|
-
{ sort: { "field_one" => 1, "field_two" => -1 }}
|
|
1139
|
-
)
|
|
1140
|
-
end
|
|
1141
|
-
|
|
1142
|
-
it_behaves_like "a cloning option"
|
|
1143
|
-
end
|
|
1144
|
-
end
|
|
1145
|
-
end
|
|
1146
|
-
|
|
1147
|
-
context "when provided no options" do
|
|
1148
|
-
|
|
1149
|
-
let(:selection) do
|
|
1150
|
-
query.order_by
|
|
1151
|
-
end
|
|
1152
|
-
|
|
1153
|
-
it "returns the query" do
|
|
1154
|
-
expect(selection).to eq(query)
|
|
1155
|
-
end
|
|
1156
|
-
|
|
1157
|
-
it_behaves_like "a cloning option"
|
|
1158
|
-
end
|
|
1159
|
-
|
|
1160
|
-
context "when provided nil" do
|
|
1161
|
-
|
|
1162
|
-
let(:selection) do
|
|
1163
|
-
query.send("#{method}", nil)
|
|
1164
|
-
end
|
|
1165
|
-
|
|
1166
|
-
it "returns the query" do
|
|
1167
|
-
expect(selection).to eq(query)
|
|
1168
|
-
end
|
|
1169
|
-
|
|
1170
|
-
it_behaves_like "a cloning option"
|
|
1171
|
-
end
|
|
1172
|
-
end
|
|
1173
|
-
|
|
1174
|
-
context "when using the mongo-1.x driver syntax" do
|
|
1175
|
-
|
|
1176
|
-
let(:query) do
|
|
1177
|
-
Mongoid::Query.new({}, {}, :mongo1x)
|
|
1178
|
-
end
|
|
1179
|
-
|
|
1180
|
-
context "when provided a hash" do
|
|
1181
|
-
|
|
1182
|
-
context "when the hash has integer values" do
|
|
1183
|
-
|
|
1184
|
-
let(:selection) do
|
|
1185
|
-
query.send("#{method}", field_one: 1, field_two: -1)
|
|
1186
|
-
end
|
|
1187
|
-
|
|
1188
|
-
it "adds the sorting criteria" do
|
|
1189
|
-
expect(selection.options).to eq(
|
|
1190
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1191
|
-
)
|
|
1192
|
-
end
|
|
1193
|
-
|
|
1194
|
-
it_behaves_like "a cloning option"
|
|
1195
|
-
end
|
|
1196
|
-
|
|
1197
|
-
context "when the hash has symbol values" do
|
|
1198
|
-
|
|
1199
|
-
let(:selection) do
|
|
1200
|
-
query.send("#{method}", field_one: :asc, field_two: :desc)
|
|
1201
|
-
end
|
|
1202
|
-
|
|
1203
|
-
it "adds the sorting criteria" do
|
|
1204
|
-
expect(selection.options).to eq(
|
|
1205
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1206
|
-
)
|
|
1207
|
-
end
|
|
1208
|
-
|
|
1209
|
-
it_behaves_like "a cloning option"
|
|
1210
|
-
end
|
|
1211
|
-
|
|
1212
|
-
context "when the hash has string values" do
|
|
1213
|
-
|
|
1214
|
-
let(:selection) do
|
|
1215
|
-
query.send("#{method}", field_one: "asc", field_two: "desc")
|
|
1216
|
-
end
|
|
1217
|
-
|
|
1218
|
-
it "adds the sorting criteria" do
|
|
1219
|
-
expect(selection.options).to eq(
|
|
1220
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1221
|
-
)
|
|
1222
|
-
end
|
|
1223
|
-
|
|
1224
|
-
it_behaves_like "a cloning option"
|
|
1225
|
-
end
|
|
1226
|
-
end
|
|
1227
|
-
|
|
1228
|
-
context "when provided an array" do
|
|
1229
|
-
|
|
1230
|
-
context "when the array is multi-dimensional" do
|
|
1231
|
-
|
|
1232
|
-
context "when the arrays have integer values" do
|
|
1233
|
-
|
|
1234
|
-
let(:selection) do
|
|
1235
|
-
query.send("#{method}", [[ :field_one, 1 ],[ :field_two, -1 ]])
|
|
1236
|
-
end
|
|
1237
|
-
|
|
1238
|
-
it "adds the sorting criteria" do
|
|
1239
|
-
expect(selection.options).to eq(
|
|
1240
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1241
|
-
)
|
|
1242
|
-
end
|
|
1243
|
-
|
|
1244
|
-
it_behaves_like "a cloning option"
|
|
1245
|
-
end
|
|
1246
|
-
|
|
1247
|
-
context "when the arrays have symbol values" do
|
|
1248
|
-
|
|
1249
|
-
let(:selection) do
|
|
1250
|
-
query.send("#{method}", [[ :field_one, :asc ],[ :field_two, :desc ]])
|
|
1251
|
-
end
|
|
1252
|
-
|
|
1253
|
-
it "adds the sorting criteria" do
|
|
1254
|
-
expect(selection.options).to eq(
|
|
1255
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1256
|
-
)
|
|
1257
|
-
end
|
|
1258
|
-
|
|
1259
|
-
it_behaves_like "a cloning option"
|
|
1260
|
-
end
|
|
1261
|
-
|
|
1262
|
-
context "when the arrays have string values" do
|
|
1263
|
-
|
|
1264
|
-
let(:selection) do
|
|
1265
|
-
query.send("#{method}", [[ :field_one, "asc" ],[ :field_two, "desc" ]])
|
|
1266
|
-
end
|
|
1267
|
-
|
|
1268
|
-
it "adds the sorting criteria" do
|
|
1269
|
-
expect(selection.options).to eq(
|
|
1270
|
-
{ sort: [[ :field_one, 1 ], [ :field_two, -1 ]]}
|
|
1271
|
-
)
|
|
1272
|
-
end
|
|
1273
|
-
|
|
1274
|
-
it_behaves_like "a cloning option"
|
|
1275
|
-
end
|
|
1276
|
-
end
|
|
1277
|
-
|
|
1278
|
-
context "when the array is selectable keys" do
|
|
1279
|
-
|
|
742
|
+
context 'when the array is selectable keys' do
|
|
1280
743
|
let(:selection) do
|
|
1281
744
|
query.send("#{method}", [ :field_one.asc, :field_two.desc ])
|
|
1282
745
|
end
|
|
1283
746
|
|
|
1284
|
-
it
|
|
747
|
+
it 'adds the sorting criteria' do
|
|
1285
748
|
expect(selection.options).to eq(
|
|
1286
|
-
{ sort:
|
|
749
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1287
750
|
)
|
|
1288
751
|
end
|
|
1289
752
|
|
|
1290
|
-
it_behaves_like
|
|
753
|
+
it_behaves_like 'a cloning option'
|
|
1291
754
|
end
|
|
1292
755
|
end
|
|
1293
756
|
|
|
1294
|
-
context
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
context "when the values have integer directions" do
|
|
1299
|
-
|
|
757
|
+
context 'when provided values' do
|
|
758
|
+
context 'when the values are arrays' do
|
|
759
|
+
context 'when the values have integer directions' do
|
|
1300
760
|
let(:selection) do
|
|
1301
|
-
query.send("#{method}", [ :field_one, 1 ],[ :field_two, -1 ])
|
|
761
|
+
query.send("#{method}", [ :field_one, 1 ], [ :field_two, -1 ])
|
|
1302
762
|
end
|
|
1303
763
|
|
|
1304
|
-
it
|
|
764
|
+
it 'adds the sorting criteria' do
|
|
1305
765
|
expect(selection.options).to eq(
|
|
1306
|
-
{ sort:
|
|
766
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1307
767
|
)
|
|
1308
768
|
end
|
|
1309
769
|
|
|
1310
|
-
it_behaves_like
|
|
770
|
+
it_behaves_like 'a cloning option'
|
|
1311
771
|
end
|
|
1312
772
|
|
|
1313
|
-
context
|
|
1314
|
-
|
|
773
|
+
context 'when the values have symbol directions' do
|
|
1315
774
|
let(:selection) do
|
|
1316
|
-
query.send("#{method}", [
|
|
775
|
+
query.send("#{method}", %i[field_one asc], %i[field_two desc])
|
|
1317
776
|
end
|
|
1318
777
|
|
|
1319
|
-
it
|
|
778
|
+
it 'adds the sorting criteria' do
|
|
1320
779
|
expect(selection.options).to eq(
|
|
1321
|
-
{ sort:
|
|
780
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1322
781
|
)
|
|
1323
782
|
end
|
|
1324
783
|
|
|
1325
|
-
it_behaves_like
|
|
784
|
+
it_behaves_like 'a cloning option'
|
|
1326
785
|
end
|
|
1327
786
|
|
|
1328
|
-
context
|
|
1329
|
-
|
|
787
|
+
context 'when the values have string directions' do
|
|
1330
788
|
let(:selection) do
|
|
1331
|
-
query.send("#{method}", [ :field_one,
|
|
789
|
+
query.send("#{method}", [ :field_one, 'asc' ], [ :field_two, 'desc' ])
|
|
1332
790
|
end
|
|
1333
791
|
|
|
1334
|
-
it
|
|
792
|
+
it 'adds the sorting criteria' do
|
|
1335
793
|
expect(selection.options).to eq(
|
|
1336
|
-
{ sort:
|
|
794
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1337
795
|
)
|
|
1338
796
|
end
|
|
1339
797
|
|
|
1340
|
-
it_behaves_like
|
|
798
|
+
it_behaves_like 'a cloning option'
|
|
1341
799
|
end
|
|
1342
800
|
end
|
|
1343
801
|
|
|
1344
|
-
context
|
|
1345
|
-
|
|
802
|
+
context 'when the values are selectable keys' do
|
|
1346
803
|
let(:selection) do
|
|
1347
804
|
query.send("#{method}", :field_one.asc, :field_two.desc)
|
|
1348
805
|
end
|
|
1349
806
|
|
|
1350
|
-
it
|
|
807
|
+
it 'adds the sorting criteria' do
|
|
1351
808
|
expect(selection.options).to eq(
|
|
1352
|
-
{ sort:
|
|
809
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1353
810
|
)
|
|
1354
811
|
end
|
|
1355
812
|
|
|
1356
|
-
it_behaves_like
|
|
813
|
+
it_behaves_like 'a cloning option'
|
|
1357
814
|
end
|
|
1358
815
|
end
|
|
1359
816
|
|
|
1360
|
-
context
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
context "when abbreviated" do
|
|
1365
|
-
|
|
817
|
+
context 'when provided a string' do
|
|
818
|
+
context 'when the direction is lowercase' do
|
|
819
|
+
context 'when abbreviated' do
|
|
1366
820
|
let(:selection) do
|
|
1367
|
-
query.send("#{method}",
|
|
821
|
+
query.send("#{method}", 'field_one asc, field_two desc')
|
|
1368
822
|
end
|
|
1369
823
|
|
|
1370
|
-
it
|
|
824
|
+
it 'adds the sorting criteria' do
|
|
1371
825
|
expect(selection.options).to eq(
|
|
1372
|
-
{ sort:
|
|
826
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1373
827
|
)
|
|
1374
828
|
end
|
|
1375
829
|
|
|
1376
|
-
it_behaves_like
|
|
830
|
+
it_behaves_like 'a cloning option'
|
|
1377
831
|
end
|
|
1378
832
|
|
|
1379
|
-
context
|
|
1380
|
-
|
|
833
|
+
context 'when spelled out' do
|
|
1381
834
|
let(:selection) do
|
|
1382
|
-
query.send("#{method}",
|
|
835
|
+
query.send("#{method}", 'field_one ascending, field_two descending')
|
|
1383
836
|
end
|
|
1384
837
|
|
|
1385
|
-
it
|
|
838
|
+
it 'adds the sorting criteria' do
|
|
1386
839
|
expect(selection.options).to eq(
|
|
1387
|
-
{ sort:
|
|
840
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1388
841
|
)
|
|
1389
842
|
end
|
|
1390
843
|
|
|
1391
|
-
it_behaves_like
|
|
844
|
+
it_behaves_like 'a cloning option'
|
|
1392
845
|
end
|
|
1393
846
|
end
|
|
1394
847
|
|
|
1395
|
-
context
|
|
1396
|
-
|
|
1397
|
-
context "when abbreviated" do
|
|
1398
|
-
|
|
848
|
+
context 'when the direction is uppercase' do
|
|
849
|
+
context 'when abbreviated' do
|
|
1399
850
|
let(:selection) do
|
|
1400
|
-
query.send("#{method}",
|
|
851
|
+
query.send("#{method}", 'field_one ASC, field_two DESC')
|
|
1401
852
|
end
|
|
1402
853
|
|
|
1403
|
-
it
|
|
854
|
+
it 'adds the sorting criteria' do
|
|
1404
855
|
expect(selection.options).to eq(
|
|
1405
|
-
{ sort:
|
|
856
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1406
857
|
)
|
|
1407
858
|
end
|
|
1408
859
|
|
|
1409
|
-
it_behaves_like
|
|
860
|
+
it_behaves_like 'a cloning option'
|
|
1410
861
|
end
|
|
1411
862
|
|
|
1412
|
-
context
|
|
1413
|
-
|
|
863
|
+
context 'when spelled out' do
|
|
1414
864
|
let(:selection) do
|
|
1415
|
-
query.send("#{method}",
|
|
865
|
+
query.send("#{method}", 'field_one ASCENDING, field_two DESCENDING')
|
|
1416
866
|
end
|
|
1417
867
|
|
|
1418
|
-
it
|
|
868
|
+
it 'adds the sorting criteria' do
|
|
1419
869
|
expect(selection.options).to eq(
|
|
1420
|
-
{ sort:
|
|
870
|
+
{ sort: { 'field_one' => 1, 'field_two' => -1 } }
|
|
1421
871
|
)
|
|
1422
872
|
end
|
|
1423
873
|
|
|
1424
|
-
it_behaves_like
|
|
874
|
+
it_behaves_like 'a cloning option'
|
|
1425
875
|
end
|
|
1426
876
|
end
|
|
1427
877
|
end
|
|
1428
878
|
|
|
1429
|
-
context
|
|
1430
|
-
|
|
879
|
+
context 'when provided no options' do
|
|
1431
880
|
let(:selection) do
|
|
1432
881
|
query.order_by
|
|
1433
882
|
end
|
|
1434
883
|
|
|
1435
|
-
it
|
|
884
|
+
it 'returns the query' do
|
|
1436
885
|
expect(selection).to eq(query)
|
|
1437
886
|
end
|
|
1438
887
|
|
|
1439
|
-
it_behaves_like
|
|
888
|
+
it_behaves_like 'a cloning option'
|
|
1440
889
|
end
|
|
1441
890
|
|
|
1442
|
-
context
|
|
1443
|
-
|
|
891
|
+
context 'when provided nil' do
|
|
1444
892
|
let(:selection) do
|
|
1445
893
|
query.send("#{method}", nil)
|
|
1446
894
|
end
|
|
1447
895
|
|
|
1448
|
-
it
|
|
896
|
+
it 'returns the query' do
|
|
1449
897
|
expect(selection).to eq(query)
|
|
1450
898
|
end
|
|
1451
899
|
|
|
1452
|
-
it_behaves_like
|
|
900
|
+
it_behaves_like 'a cloning option'
|
|
1453
901
|
end
|
|
1454
902
|
end
|
|
1455
903
|
end
|
|
1456
904
|
end
|
|
1457
905
|
|
|
1458
|
-
describe
|
|
1459
|
-
|
|
906
|
+
describe '#reoder' do
|
|
1460
907
|
let(:selection) do
|
|
1461
908
|
query.order_by(field_one: 1, field_two: -1)
|
|
1462
909
|
end
|
|
@@ -1465,8 +912,8 @@ describe Mongoid::Criteria::Queryable::Optional do
|
|
|
1465
912
|
selection.reorder(field_three: 1)
|
|
1466
913
|
end
|
|
1467
914
|
|
|
1468
|
-
it
|
|
1469
|
-
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 })
|
|
1470
917
|
end
|
|
1471
918
|
|
|
1472
919
|
it 'does not alter the original criteria object' do
|
|
@@ -1474,324 +921,298 @@ describe Mongoid::Criteria::Queryable::Optional do
|
|
|
1474
921
|
end
|
|
1475
922
|
end
|
|
1476
923
|
|
|
1477
|
-
[
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
context "when provided no options" do
|
|
1482
|
-
|
|
924
|
+
%i[skip offset].each do |method|
|
|
925
|
+
describe "##{method}" do
|
|
926
|
+
context 'when provided no options' do
|
|
1483
927
|
let(:selection) do
|
|
1484
928
|
query.send(method)
|
|
1485
929
|
end
|
|
1486
930
|
|
|
1487
|
-
it
|
|
931
|
+
it 'does not add any options' do
|
|
1488
932
|
expect(selection.options).to eq({})
|
|
1489
933
|
end
|
|
1490
934
|
|
|
1491
|
-
it
|
|
935
|
+
it 'returns the query' do
|
|
1492
936
|
expect(selection).to eq(query)
|
|
1493
937
|
end
|
|
1494
938
|
|
|
1495
|
-
it_behaves_like
|
|
939
|
+
it_behaves_like 'a cloning option'
|
|
1496
940
|
end
|
|
1497
941
|
|
|
1498
|
-
context
|
|
1499
|
-
|
|
942
|
+
context 'when provided nil' do
|
|
1500
943
|
let(:selection) do
|
|
1501
944
|
query.send(method, nil)
|
|
1502
945
|
end
|
|
1503
946
|
|
|
1504
|
-
it
|
|
947
|
+
it 'does not add any options' do
|
|
1505
948
|
expect(selection.options).to eq({})
|
|
1506
949
|
end
|
|
1507
950
|
|
|
1508
|
-
it
|
|
951
|
+
it 'returns the query' do
|
|
1509
952
|
expect(selection).to eq(query)
|
|
1510
953
|
end
|
|
1511
954
|
|
|
1512
|
-
it_behaves_like
|
|
955
|
+
it_behaves_like 'a cloning option'
|
|
1513
956
|
end
|
|
1514
957
|
|
|
1515
|
-
context
|
|
1516
|
-
|
|
958
|
+
context 'when the query is aggregating' do
|
|
1517
959
|
let(:selection) do
|
|
1518
960
|
query.project(name: 1).skip(10)
|
|
1519
961
|
end
|
|
1520
962
|
|
|
1521
|
-
it
|
|
963
|
+
it 'adds the field options' do
|
|
1522
964
|
expect(selection.options).to eq({ skip: 10 })
|
|
1523
965
|
end
|
|
1524
966
|
|
|
1525
|
-
it
|
|
1526
|
-
expect(selection.pipeline).to include({
|
|
967
|
+
it 'adds the skip to the aggregation' do
|
|
968
|
+
expect(selection.pipeline).to include({ '$skip' => 10 })
|
|
1527
969
|
end
|
|
1528
970
|
|
|
1529
|
-
it_behaves_like
|
|
971
|
+
it_behaves_like 'a cloning option'
|
|
1530
972
|
end
|
|
1531
973
|
|
|
1532
|
-
context
|
|
1533
|
-
|
|
1534
|
-
context "when provided an integer" do
|
|
1535
|
-
|
|
974
|
+
context 'when provided arguments' do
|
|
975
|
+
context 'when provided an integer' do
|
|
1536
976
|
let(:selection) do
|
|
1537
977
|
query.send(method, 10)
|
|
1538
978
|
end
|
|
1539
979
|
|
|
1540
|
-
it
|
|
980
|
+
it 'adds the field options' do
|
|
1541
981
|
expect(selection.options).to eq({ skip: 10 })
|
|
1542
982
|
end
|
|
1543
983
|
|
|
1544
|
-
it_behaves_like
|
|
984
|
+
it_behaves_like 'a cloning option'
|
|
1545
985
|
end
|
|
1546
986
|
|
|
1547
|
-
context
|
|
1548
|
-
|
|
987
|
+
context 'when provided a float' do
|
|
1549
988
|
let(:selection) do
|
|
1550
989
|
query.send(method, 10.25)
|
|
1551
990
|
end
|
|
1552
991
|
|
|
1553
|
-
it
|
|
992
|
+
it 'adds the field options converted to an integer' do
|
|
1554
993
|
expect(selection.options).to eq({ skip: 10 })
|
|
1555
994
|
end
|
|
1556
995
|
|
|
1557
|
-
it_behaves_like
|
|
996
|
+
it_behaves_like 'a cloning option'
|
|
1558
997
|
end
|
|
1559
998
|
|
|
1560
|
-
context
|
|
1561
|
-
|
|
999
|
+
context 'when provided a non number' do
|
|
1562
1000
|
let(:selection) do
|
|
1563
|
-
query.send(method,
|
|
1001
|
+
query.send(method, '10')
|
|
1564
1002
|
end
|
|
1565
1003
|
|
|
1566
|
-
it
|
|
1004
|
+
it 'adds the field options converted to an integer' do
|
|
1567
1005
|
expect(selection.options).to eq({ skip: 10 })
|
|
1568
1006
|
end
|
|
1569
1007
|
|
|
1570
|
-
it_behaves_like
|
|
1008
|
+
it_behaves_like 'a cloning option'
|
|
1571
1009
|
end
|
|
1572
1010
|
end
|
|
1573
1011
|
end
|
|
1574
1012
|
end
|
|
1575
1013
|
|
|
1576
|
-
describe
|
|
1577
|
-
|
|
1578
|
-
context "when provided no options" do
|
|
1579
|
-
|
|
1014
|
+
describe '#slice' do
|
|
1015
|
+
context 'when provided no options' do
|
|
1580
1016
|
let(:selection) do
|
|
1581
1017
|
query.slice
|
|
1582
1018
|
end
|
|
1583
1019
|
|
|
1584
|
-
it
|
|
1020
|
+
it 'does not add any options' do
|
|
1585
1021
|
expect(selection.options).to eq({})
|
|
1586
1022
|
end
|
|
1587
1023
|
|
|
1588
|
-
it
|
|
1024
|
+
it 'returns the query' do
|
|
1589
1025
|
expect(selection).to eq(query)
|
|
1590
1026
|
end
|
|
1591
1027
|
|
|
1592
|
-
it_behaves_like
|
|
1028
|
+
it_behaves_like 'a cloning option'
|
|
1593
1029
|
end
|
|
1594
1030
|
|
|
1595
|
-
context
|
|
1596
|
-
|
|
1031
|
+
context 'when provided nil' do
|
|
1597
1032
|
let(:selection) do
|
|
1598
1033
|
query.slice(nil)
|
|
1599
1034
|
end
|
|
1600
1035
|
|
|
1601
|
-
it
|
|
1036
|
+
it 'does not add any options' do
|
|
1602
1037
|
expect(selection.options).to eq({})
|
|
1603
1038
|
end
|
|
1604
1039
|
|
|
1605
|
-
it
|
|
1040
|
+
it 'returns the query' do
|
|
1606
1041
|
expect(selection).to eq(query)
|
|
1607
1042
|
end
|
|
1608
1043
|
|
|
1609
|
-
it_behaves_like
|
|
1044
|
+
it_behaves_like 'a cloning option'
|
|
1610
1045
|
end
|
|
1611
1046
|
|
|
1612
|
-
context
|
|
1613
|
-
|
|
1047
|
+
context 'when provided a single argument' do
|
|
1614
1048
|
let(:selection) do
|
|
1615
|
-
query.slice(:
|
|
1049
|
+
query.slice(first: 5)
|
|
1616
1050
|
end
|
|
1617
1051
|
|
|
1618
|
-
it
|
|
1052
|
+
it 'adds the field options' do
|
|
1619
1053
|
expect(selection.options).to eq(
|
|
1620
|
-
{ fields: {
|
|
1054
|
+
{ fields: { 'first' => { '$slice' => 5 } } }
|
|
1621
1055
|
)
|
|
1622
1056
|
end
|
|
1623
1057
|
|
|
1624
|
-
it_behaves_like
|
|
1058
|
+
it_behaves_like 'a cloning option'
|
|
1625
1059
|
end
|
|
1626
1060
|
|
|
1627
|
-
context
|
|
1628
|
-
|
|
1061
|
+
context 'when provided a multiple arguments' do
|
|
1629
1062
|
let(:selection) do
|
|
1630
|
-
query.slice(:
|
|
1063
|
+
query.slice(first: 5, second: [ 0, 3 ])
|
|
1631
1064
|
end
|
|
1632
1065
|
|
|
1633
|
-
it
|
|
1066
|
+
it 'adds the field options' do
|
|
1634
1067
|
expect(selection.options).to eq({ fields:
|
|
1635
|
-
{
|
|
1636
|
-
})
|
|
1068
|
+
{ 'first' => { '$slice' => 5 }, 'second' => { '$slice' => [ 0, 3 ] } } })
|
|
1637
1069
|
end
|
|
1638
1070
|
|
|
1639
|
-
it_behaves_like
|
|
1071
|
+
it_behaves_like 'a cloning option'
|
|
1640
1072
|
end
|
|
1641
1073
|
|
|
1642
|
-
context
|
|
1643
|
-
|
|
1074
|
+
context 'when existing field arguments exist' do
|
|
1644
1075
|
let(:limited) do
|
|
1645
1076
|
query.only(:name)
|
|
1646
1077
|
end
|
|
1647
1078
|
|
|
1648
1079
|
let(:selection) do
|
|
1649
|
-
limited.slice(:
|
|
1080
|
+
limited.slice(first: 5, second: [ 0, 3 ])
|
|
1650
1081
|
end
|
|
1651
1082
|
|
|
1652
|
-
it
|
|
1083
|
+
it 'adds the field options' do
|
|
1653
1084
|
expect(selection.options).to eq({
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1085
|
+
fields: {
|
|
1086
|
+
'name' => 1,
|
|
1087
|
+
'first' => { '$slice' => 5 },
|
|
1088
|
+
'second' => { '$slice' => [ 0, 3 ] }
|
|
1089
|
+
}
|
|
1090
|
+
})
|
|
1660
1091
|
end
|
|
1661
1092
|
|
|
1662
|
-
it_behaves_like
|
|
1093
|
+
it_behaves_like 'a cloning option'
|
|
1663
1094
|
end
|
|
1664
1095
|
end
|
|
1665
1096
|
|
|
1666
|
-
describe
|
|
1667
|
-
|
|
1097
|
+
describe '#snapshot' do
|
|
1668
1098
|
let(:selection) do
|
|
1669
1099
|
query.snapshot
|
|
1670
1100
|
end
|
|
1671
1101
|
|
|
1672
|
-
it
|
|
1102
|
+
it 'adds the snapshot option' do
|
|
1673
1103
|
expect(selection.options).to eq({ snapshot: true })
|
|
1674
1104
|
end
|
|
1675
1105
|
|
|
1676
|
-
it_behaves_like
|
|
1106
|
+
it_behaves_like 'a cloning option'
|
|
1677
1107
|
end
|
|
1678
1108
|
|
|
1679
|
-
describe
|
|
1680
|
-
|
|
1109
|
+
describe '#comment' do
|
|
1681
1110
|
let(:selection) do
|
|
1682
1111
|
query.comment('slow query')
|
|
1683
1112
|
end
|
|
1684
1113
|
|
|
1685
|
-
it
|
|
1114
|
+
it 'adds the comment option' do
|
|
1686
1115
|
expect(selection.options).to eq({ comment: 'slow query' })
|
|
1687
1116
|
end
|
|
1688
1117
|
|
|
1689
|
-
it_behaves_like
|
|
1118
|
+
it_behaves_like 'a cloning option'
|
|
1690
1119
|
end
|
|
1691
1120
|
|
|
1692
|
-
describe
|
|
1693
|
-
|
|
1121
|
+
describe '#cursor_type' do
|
|
1694
1122
|
let(:selection) do
|
|
1695
1123
|
query.cursor_type(:tailable)
|
|
1696
1124
|
end
|
|
1697
1125
|
|
|
1698
|
-
it
|
|
1126
|
+
it 'adds the cursor type option' do
|
|
1699
1127
|
expect(selection.options).to eq({ cursor_type: :tailable })
|
|
1700
1128
|
end
|
|
1701
1129
|
|
|
1702
|
-
it_behaves_like
|
|
1130
|
+
it_behaves_like 'a cloning option'
|
|
1703
1131
|
end
|
|
1704
1132
|
|
|
1705
|
-
describe
|
|
1706
|
-
|
|
1133
|
+
describe '#collation' do
|
|
1707
1134
|
let(:selection) do
|
|
1708
1135
|
query.collation(locale: 'fr', strength: 2)
|
|
1709
1136
|
end
|
|
1710
1137
|
|
|
1711
|
-
it
|
|
1712
|
-
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 })
|
|
1713
1140
|
end
|
|
1714
1141
|
|
|
1715
|
-
it_behaves_like
|
|
1142
|
+
it_behaves_like 'a cloning option'
|
|
1716
1143
|
end
|
|
1717
1144
|
|
|
1718
|
-
describe
|
|
1719
|
-
|
|
1720
|
-
context "when provided no options" do
|
|
1721
|
-
|
|
1145
|
+
describe '#without' do
|
|
1146
|
+
context 'when provided no options' do
|
|
1722
1147
|
let(:selection) do
|
|
1723
1148
|
query.without
|
|
1724
1149
|
end
|
|
1725
1150
|
|
|
1726
|
-
it
|
|
1151
|
+
it 'does not add any options' do
|
|
1727
1152
|
expect(selection.options).to eq({})
|
|
1728
1153
|
end
|
|
1729
1154
|
|
|
1730
|
-
it
|
|
1155
|
+
it 'returns the query' do
|
|
1731
1156
|
expect(selection).to eq(query)
|
|
1732
1157
|
end
|
|
1733
1158
|
|
|
1734
|
-
it_behaves_like
|
|
1159
|
+
it_behaves_like 'a cloning option'
|
|
1735
1160
|
end
|
|
1736
1161
|
|
|
1737
|
-
context
|
|
1738
|
-
|
|
1162
|
+
context 'when provided nil' do
|
|
1739
1163
|
let(:selection) do
|
|
1740
1164
|
query.without(nil)
|
|
1741
1165
|
end
|
|
1742
1166
|
|
|
1743
|
-
it
|
|
1167
|
+
it 'does not add any options' do
|
|
1744
1168
|
expect(selection.options).to eq({})
|
|
1745
1169
|
end
|
|
1746
1170
|
|
|
1747
|
-
it
|
|
1171
|
+
it 'returns the query' do
|
|
1748
1172
|
expect(selection).to eq(query)
|
|
1749
1173
|
end
|
|
1750
1174
|
|
|
1751
|
-
it_behaves_like
|
|
1175
|
+
it_behaves_like 'a cloning option'
|
|
1752
1176
|
end
|
|
1753
1177
|
|
|
1754
|
-
context
|
|
1755
|
-
|
|
1756
|
-
context "as sevaral arguments" do
|
|
1757
|
-
|
|
1178
|
+
context 'when provided fields' do
|
|
1179
|
+
context 'as several arguments' do
|
|
1758
1180
|
let(:selection) do
|
|
1759
1181
|
query.without(:first, :second)
|
|
1760
1182
|
end
|
|
1761
1183
|
|
|
1762
|
-
it
|
|
1184
|
+
it 'adds the field options' do
|
|
1763
1185
|
expect(selection.options).to eq(
|
|
1764
|
-
{ fields: {
|
|
1186
|
+
{ fields: { 'first' => 0, 'second' => 0 } }
|
|
1765
1187
|
)
|
|
1766
1188
|
end
|
|
1767
1189
|
|
|
1768
|
-
it_behaves_like
|
|
1190
|
+
it_behaves_like 'a cloning option'
|
|
1769
1191
|
end
|
|
1770
1192
|
|
|
1771
|
-
context
|
|
1772
|
-
|
|
1193
|
+
context 'as one argument - array' do
|
|
1773
1194
|
let(:selection) do
|
|
1774
|
-
query.without([
|
|
1195
|
+
query.without(%i[first second])
|
|
1775
1196
|
end
|
|
1776
1197
|
|
|
1777
|
-
it
|
|
1198
|
+
it 'adds the field options' do
|
|
1778
1199
|
expect(selection.options).to eq(
|
|
1779
|
-
{ fields: {
|
|
1200
|
+
{ fields: { 'first' => 0, 'second' => 0 } }
|
|
1780
1201
|
)
|
|
1781
1202
|
end
|
|
1782
1203
|
|
|
1783
|
-
it_behaves_like
|
|
1204
|
+
it_behaves_like 'a cloning option'
|
|
1784
1205
|
end
|
|
1785
1206
|
end
|
|
1786
1207
|
|
|
1787
|
-
context
|
|
1208
|
+
context 'when #only was called before' do
|
|
1788
1209
|
let(:selection) do
|
|
1789
1210
|
query.only(:first).without(:id)
|
|
1790
1211
|
end
|
|
1791
1212
|
|
|
1792
|
-
it
|
|
1213
|
+
it 'adds both fields to options' do
|
|
1793
1214
|
expect(selection.options).to eq(
|
|
1794
|
-
{ fields: {
|
|
1215
|
+
{ fields: { 'first' => 1, 'id' => 0 } }
|
|
1795
1216
|
)
|
|
1796
1217
|
end
|
|
1797
1218
|
end
|