mongoid 9.0.12 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -45
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +38 -46
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +23 -47
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -23
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +11 -106
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -83
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -22
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +19 -39
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +127 -84
- data/lib/mongoid/contextual/aggregable/memory.rb +4 -9
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +76 -80
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -43
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +130 -301
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -48
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -74
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +41 -52
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +1 -8
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -2
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +12 -11
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -16
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -76
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +337 -14
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +37 -53
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -69
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -185
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +18 -30
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +105 -130
- data/spec/integration/encryption_spec.rb +8 -160
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_data/regex.yml +0 -21
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -1023
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -156
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1221 -1888
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -49
- data/spec/mongoid/config/encryption_spec.rb +53 -284
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -226
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -1031
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -682
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -391
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -952
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -98
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -165
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -14
- data/lib/mongoid/errors/in_memory_regexp_timeout.rb +0 -26
- data/lib/mongoid/errors/no_encryption_schema.rb +0 -28
- data/lib/mongoid/field_readable.rb +0 -70
- data/lib/mongoid/matcher/regexp_budget.rb +0 -383
- data/spec/integration/matcher_regexp_timeout_spec.rb +0 -215
- data/spec/integration/query_operator_guard_spec.rb +0 -89
- data/spec/mongoid/encryptable_spec.rb +0 -61
- data/spec/mongoid/matcher/regexp_budget_spec.rb +0 -570
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Contextual::Memory do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
context "when there are no matching documents" do
|
|
6
|
+
shared_examples 'raises an error when no documents' do
|
|
7
|
+
context 'when there are no matching documents' do
|
|
10
8
|
let(:criteria) do
|
|
11
9
|
Address.all.tap do |crit|
|
|
12
10
|
crit.documents = []
|
|
13
11
|
end
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
it
|
|
14
|
+
it 'returns nil' do
|
|
17
15
|
expect do
|
|
18
16
|
context.send(method)
|
|
19
17
|
end.to raise_error(Mongoid::Errors::DocumentNotFound, /Could not find a document of class Address./)
|
|
@@ -21,36 +19,33 @@ describe Mongoid::Contextual::Memory do
|
|
|
21
19
|
end
|
|
22
20
|
end
|
|
23
21
|
|
|
24
|
-
shared_examples
|
|
25
|
-
context
|
|
22
|
+
shared_examples 'returns nil when no documents' do
|
|
23
|
+
context 'when there are no matching documents' do
|
|
26
24
|
let(:criteria) do
|
|
27
25
|
Address.all.tap do |crit|
|
|
28
26
|
crit.documents = []
|
|
29
27
|
end
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
it
|
|
30
|
+
it 'returns nil' do
|
|
33
31
|
expect(context.send(method)).to be_nil
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
|
|
38
|
-
[
|
|
39
|
-
|
|
36
|
+
%i[blank? empty?].each do |method|
|
|
40
37
|
describe "##{method}" do
|
|
41
|
-
|
|
42
38
|
let(:hobrecht) do
|
|
43
|
-
Address.new(street:
|
|
39
|
+
Address.new(street: 'hobrecht')
|
|
44
40
|
end
|
|
45
41
|
|
|
46
42
|
let(:friedel) do
|
|
47
|
-
Address.new(street:
|
|
43
|
+
Address.new(street: 'friedel')
|
|
48
44
|
end
|
|
49
45
|
|
|
50
|
-
context
|
|
51
|
-
|
|
46
|
+
context 'when there are matching documents' do
|
|
52
47
|
let(:criteria) do
|
|
53
|
-
Address.where(street:
|
|
48
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
54
49
|
crit.documents = [ hobrecht, friedel ]
|
|
55
50
|
end
|
|
56
51
|
end
|
|
@@ -59,15 +54,14 @@ describe Mongoid::Contextual::Memory do
|
|
|
59
54
|
described_class.new(criteria)
|
|
60
55
|
end
|
|
61
56
|
|
|
62
|
-
it
|
|
57
|
+
it 'returns false' do
|
|
63
58
|
expect(context.send(method)).to be false
|
|
64
59
|
end
|
|
65
60
|
end
|
|
66
61
|
|
|
67
|
-
context
|
|
68
|
-
|
|
62
|
+
context 'when there are no matching documents' do
|
|
69
63
|
let(:criteria) do
|
|
70
|
-
Address.where(street:
|
|
64
|
+
Address.where(street: 'pfluger').tap do |crit|
|
|
71
65
|
crit.documents = [ hobrecht, friedel ]
|
|
72
66
|
end
|
|
73
67
|
end
|
|
@@ -76,40 +70,38 @@ describe Mongoid::Contextual::Memory do
|
|
|
76
70
|
described_class.new(criteria)
|
|
77
71
|
end
|
|
78
72
|
|
|
79
|
-
it
|
|
73
|
+
it 'returns true' do
|
|
80
74
|
expect(context.send(method)).to be true
|
|
81
75
|
end
|
|
82
76
|
end
|
|
83
77
|
|
|
84
78
|
context 'when there is a collation on the criteria' do
|
|
85
|
-
|
|
86
79
|
let(:criteria) do
|
|
87
|
-
Address.where(street:
|
|
80
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
88
81
|
crit.documents = [ hobrecht, friedel ]
|
|
89
82
|
end.collation(locale: 'en_US', strength: 2)
|
|
90
83
|
end
|
|
91
84
|
|
|
92
|
-
it
|
|
93
|
-
expect
|
|
85
|
+
it 'raises an exception' do
|
|
86
|
+
expect do
|
|
94
87
|
context.send(method)
|
|
95
|
-
|
|
88
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
96
89
|
end
|
|
97
90
|
end
|
|
98
91
|
end
|
|
99
92
|
end
|
|
100
93
|
|
|
101
|
-
describe
|
|
102
|
-
|
|
94
|
+
describe '#count' do
|
|
103
95
|
let!(:hobrecht) do
|
|
104
|
-
Address.new(street:
|
|
96
|
+
Address.new(street: 'hobrecht')
|
|
105
97
|
end
|
|
106
98
|
|
|
107
99
|
let!(:friedel) do
|
|
108
|
-
Address.new(street:
|
|
100
|
+
Address.new(street: 'friedel')
|
|
109
101
|
end
|
|
110
102
|
|
|
111
103
|
let(:criteria) do
|
|
112
|
-
Address.where(street:
|
|
104
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
113
105
|
crit.documents = [ hobrecht, friedel ]
|
|
114
106
|
end
|
|
115
107
|
end
|
|
@@ -118,107 +110,96 @@ describe Mongoid::Contextual::Memory do
|
|
|
118
110
|
described_class.new(criteria)
|
|
119
111
|
end
|
|
120
112
|
|
|
121
|
-
context
|
|
122
|
-
|
|
123
|
-
it "returns the number of matches" do
|
|
113
|
+
context 'context when no arguments are provided' do
|
|
114
|
+
it 'returns the number of matches' do
|
|
124
115
|
expect(context.count).to eq(1)
|
|
125
116
|
end
|
|
126
117
|
end
|
|
127
118
|
|
|
128
119
|
context 'when there is a collation on the criteria' do
|
|
129
|
-
|
|
130
120
|
let(:criteria) do
|
|
131
|
-
Address.where(street:
|
|
121
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
132
122
|
crit.documents = [ hobrecht, friedel ]
|
|
133
123
|
end.collation(locale: 'en_US', strength: 2)
|
|
134
124
|
end
|
|
135
125
|
|
|
136
|
-
it
|
|
137
|
-
expect
|
|
126
|
+
it 'raises an exception' do
|
|
127
|
+
expect do
|
|
138
128
|
context.count
|
|
139
|
-
|
|
129
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
140
130
|
end
|
|
141
131
|
end
|
|
142
132
|
|
|
143
|
-
context
|
|
144
|
-
|
|
145
|
-
context "when the document matches" do
|
|
146
|
-
|
|
133
|
+
context 'when provided a document' do
|
|
134
|
+
context 'when the document matches' do
|
|
147
135
|
let(:count) do
|
|
148
136
|
context.count(hobrecht)
|
|
149
137
|
end
|
|
150
138
|
|
|
151
|
-
it
|
|
139
|
+
it 'returns 1' do
|
|
152
140
|
expect(count).to eq(1)
|
|
153
141
|
end
|
|
154
142
|
end
|
|
155
143
|
|
|
156
|
-
context
|
|
157
|
-
|
|
144
|
+
context 'when the document does not match' do
|
|
158
145
|
let(:count) do
|
|
159
146
|
context.count(friedel)
|
|
160
147
|
end
|
|
161
148
|
|
|
162
|
-
it
|
|
149
|
+
it 'returns 0' do
|
|
163
150
|
expect(count).to eq(0)
|
|
164
151
|
end
|
|
165
152
|
end
|
|
166
153
|
end
|
|
167
154
|
|
|
168
|
-
context
|
|
169
|
-
|
|
170
|
-
context "when the block evals 1 to true" do
|
|
171
|
-
|
|
155
|
+
context 'when provided a block' do
|
|
156
|
+
context 'when the block evals 1 to true' do
|
|
172
157
|
let(:count) do
|
|
173
158
|
context.count do |doc|
|
|
174
|
-
doc.street ==
|
|
159
|
+
doc.street == 'hobrecht'
|
|
175
160
|
end
|
|
176
161
|
end
|
|
177
162
|
|
|
178
|
-
it
|
|
163
|
+
it 'returns 1' do
|
|
179
164
|
expect(count).to eq(1)
|
|
180
165
|
end
|
|
181
166
|
end
|
|
182
167
|
|
|
183
|
-
context
|
|
184
|
-
|
|
168
|
+
context 'when the block evals none to true' do
|
|
185
169
|
let(:count) do
|
|
186
170
|
context.count do |doc|
|
|
187
|
-
doc.street ==
|
|
171
|
+
doc.street == 'friedel'
|
|
188
172
|
end
|
|
189
173
|
end
|
|
190
174
|
|
|
191
|
-
it
|
|
175
|
+
it 'returns 0' do
|
|
192
176
|
expect(count).to eq(0)
|
|
193
177
|
end
|
|
194
178
|
end
|
|
195
179
|
end
|
|
196
180
|
end
|
|
197
181
|
|
|
198
|
-
[
|
|
199
|
-
|
|
182
|
+
%i[delete delete_all].each do |method|
|
|
200
183
|
let(:person) do
|
|
201
184
|
Person.create!
|
|
202
185
|
end
|
|
203
186
|
|
|
204
187
|
let(:hobrecht) do
|
|
205
|
-
person.addresses.create!(street:
|
|
188
|
+
person.addresses.create!(street: 'hobrecht')
|
|
206
189
|
end
|
|
207
190
|
|
|
208
191
|
let(:friedel) do
|
|
209
|
-
person.addresses.create!(street:
|
|
192
|
+
person.addresses.create!(street: 'friedel')
|
|
210
193
|
end
|
|
211
194
|
|
|
212
195
|
let(:pfluger) do
|
|
213
|
-
person.addresses.create!(street:
|
|
196
|
+
person.addresses.create!(street: 'pfluger')
|
|
214
197
|
end
|
|
215
198
|
|
|
216
199
|
describe "##{method}" do
|
|
217
|
-
|
|
218
|
-
context "when embedded a single level" do
|
|
219
|
-
|
|
200
|
+
context 'when embedded a single level' do
|
|
220
201
|
let(:criteria) do
|
|
221
|
-
Address.any_in(street: [
|
|
202
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
222
203
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
223
204
|
end
|
|
224
205
|
end
|
|
@@ -231,47 +212,46 @@ describe Mongoid::Contextual::Memory do
|
|
|
231
212
|
context.send(method)
|
|
232
213
|
end
|
|
233
214
|
|
|
234
|
-
it
|
|
215
|
+
it 'deletes the first matching document' do
|
|
235
216
|
expect(hobrecht).to be_destroyed
|
|
236
217
|
end
|
|
237
218
|
|
|
238
|
-
it
|
|
219
|
+
it 'deletes the last matching document' do
|
|
239
220
|
expect(friedel).to be_destroyed
|
|
240
221
|
end
|
|
241
222
|
|
|
242
|
-
it
|
|
243
|
-
expect(pfluger).
|
|
223
|
+
it 'does not delete non matching docs' do
|
|
224
|
+
expect(pfluger).not_to be_destroyed
|
|
244
225
|
end
|
|
245
226
|
|
|
246
|
-
it
|
|
227
|
+
it 'removes the docs from the relation' do
|
|
247
228
|
expect(person.addresses).to eq([ pfluger ])
|
|
248
229
|
end
|
|
249
230
|
|
|
250
|
-
it
|
|
231
|
+
it 'removes the docs from the context' do
|
|
251
232
|
expect(context.entries).to be_empty
|
|
252
233
|
end
|
|
253
234
|
|
|
254
|
-
it
|
|
235
|
+
it 'persists the changes to the database' do
|
|
255
236
|
expect(person.reload.addresses).to eq([ pfluger ])
|
|
256
237
|
end
|
|
257
238
|
|
|
258
|
-
it
|
|
239
|
+
it 'returns the number of deleted documents' do
|
|
259
240
|
expect(deleted).to eq(2)
|
|
260
241
|
end
|
|
261
242
|
end
|
|
262
243
|
|
|
263
|
-
context
|
|
264
|
-
|
|
244
|
+
context 'when embedded multiple levels' do
|
|
265
245
|
let!(:home) do
|
|
266
|
-
hobrecht.locations.create!(name:
|
|
246
|
+
hobrecht.locations.create!(name: 'home')
|
|
267
247
|
end
|
|
268
248
|
|
|
269
249
|
let!(:work) do
|
|
270
|
-
hobrecht.locations.create!(name:
|
|
250
|
+
hobrecht.locations.create!(name: 'work')
|
|
271
251
|
end
|
|
272
252
|
|
|
273
253
|
let(:criteria) do
|
|
274
|
-
Location.where(name:
|
|
254
|
+
Location.where(name: 'work').tap do |crit|
|
|
275
255
|
crit.documents = [ home, work ]
|
|
276
256
|
end
|
|
277
257
|
end
|
|
@@ -284,68 +264,66 @@ describe Mongoid::Contextual::Memory do
|
|
|
284
264
|
context.send(method)
|
|
285
265
|
end
|
|
286
266
|
|
|
287
|
-
it
|
|
267
|
+
it 'deletes the first matching document' do
|
|
288
268
|
expect(work).to be_destroyed
|
|
289
269
|
end
|
|
290
270
|
|
|
291
|
-
it
|
|
292
|
-
expect(home).
|
|
271
|
+
it 'does not delete non matching docs' do
|
|
272
|
+
expect(home).not_to be_destroyed
|
|
293
273
|
end
|
|
294
274
|
|
|
295
|
-
it
|
|
275
|
+
it 'removes the docs from the relation' do
|
|
296
276
|
expect(person.addresses.first.locations).to eq([ home ])
|
|
297
277
|
end
|
|
298
278
|
|
|
299
|
-
it
|
|
279
|
+
it 'removes the docs from the context' do
|
|
300
280
|
expect(context.entries).to be_empty
|
|
301
281
|
end
|
|
302
282
|
|
|
303
|
-
it
|
|
283
|
+
it 'persists the changes to the database' do
|
|
304
284
|
expect(person.reload.addresses.first.locations).to eq([ home ])
|
|
305
285
|
end
|
|
306
286
|
|
|
307
|
-
it
|
|
287
|
+
it 'returns the number of deleted documents' do
|
|
308
288
|
expect(deleted).to eq(1)
|
|
309
289
|
end
|
|
310
290
|
end
|
|
311
291
|
|
|
312
292
|
context 'when there is a collation on the criteria' do
|
|
313
|
-
|
|
314
293
|
let(:criteria) do
|
|
315
|
-
Address.any_in(street: [
|
|
294
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
316
295
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
317
296
|
end.collation(locale: 'en_US', strength: 2)
|
|
318
297
|
end
|
|
319
298
|
|
|
320
|
-
it
|
|
321
|
-
expect
|
|
299
|
+
it 'raises an exception' do
|
|
300
|
+
expect do
|
|
322
301
|
context.send(method)
|
|
323
|
-
|
|
302
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
324
303
|
end
|
|
325
304
|
end
|
|
326
305
|
end
|
|
327
306
|
end
|
|
328
307
|
|
|
329
|
-
[
|
|
330
|
-
|
|
308
|
+
%i[destroy destroy_all].each do |method|
|
|
331
309
|
let(:person) do
|
|
332
310
|
Person.create!
|
|
333
311
|
end
|
|
334
312
|
|
|
335
313
|
let(:hobrecht) do
|
|
336
|
-
person.addresses.create!(street:
|
|
314
|
+
person.addresses.create!(street: 'hobrecht')
|
|
337
315
|
end
|
|
338
316
|
|
|
339
317
|
let(:friedel) do
|
|
340
|
-
person.addresses.create!(street:
|
|
318
|
+
person.addresses.create!(street: 'friedel')
|
|
341
319
|
end
|
|
342
320
|
|
|
343
321
|
let(:pfluger) do
|
|
344
|
-
person.addresses.create!(street:
|
|
322
|
+
person.addresses.create!(street: 'pfluger')
|
|
345
323
|
end
|
|
346
324
|
|
|
347
325
|
let(:criteria) do
|
|
348
|
-
Address.any_in(street: [
|
|
326
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
349
327
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
350
328
|
end
|
|
351
329
|
end
|
|
@@ -355,63 +333,60 @@ describe Mongoid::Contextual::Memory do
|
|
|
355
333
|
end
|
|
356
334
|
|
|
357
335
|
describe "##{method}" do
|
|
358
|
-
|
|
359
336
|
context 'when there is no collation on the criteria' do
|
|
360
|
-
|
|
361
337
|
let!(:destroyed) do
|
|
362
338
|
context.send(method)
|
|
363
339
|
end
|
|
364
340
|
|
|
365
|
-
it
|
|
341
|
+
it 'deletes the first matching document' do
|
|
366
342
|
expect(hobrecht).to be_destroyed
|
|
367
343
|
end
|
|
368
344
|
|
|
369
|
-
it
|
|
345
|
+
it 'deletes the last matching document' do
|
|
370
346
|
expect(friedel).to be_destroyed
|
|
371
347
|
end
|
|
372
348
|
|
|
373
|
-
it
|
|
374
|
-
expect(pfluger).
|
|
349
|
+
it 'does not delete non matching docs' do
|
|
350
|
+
expect(pfluger).not_to be_destroyed
|
|
375
351
|
end
|
|
376
352
|
|
|
377
|
-
it
|
|
353
|
+
it 'removes the docs from the relation' do
|
|
378
354
|
expect(person.addresses).to eq([ pfluger ])
|
|
379
355
|
end
|
|
380
356
|
|
|
381
|
-
it
|
|
357
|
+
it 'removes the docs from the context' do
|
|
382
358
|
expect(context.entries).to be_empty
|
|
383
359
|
end
|
|
384
360
|
|
|
385
|
-
it
|
|
361
|
+
it 'persists the changes to the database' do
|
|
386
362
|
expect(person.reload.addresses).to eq([ pfluger ])
|
|
387
363
|
end
|
|
388
364
|
|
|
389
|
-
it
|
|
365
|
+
it 'returns the number of destroyed documents' do
|
|
390
366
|
expect(destroyed).to eq(2)
|
|
391
367
|
end
|
|
392
368
|
end
|
|
393
369
|
|
|
394
370
|
context 'when there is a collation on the criteria' do
|
|
395
|
-
|
|
396
371
|
let(:criteria) do
|
|
397
|
-
Address.any_in(street: [
|
|
372
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
398
373
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
399
374
|
end.collation(locale: 'en_US', strength: 2)
|
|
400
375
|
end
|
|
401
376
|
|
|
402
|
-
it
|
|
403
|
-
expect
|
|
377
|
+
it 'raises an exception' do
|
|
378
|
+
expect do
|
|
404
379
|
context.send(method)
|
|
405
|
-
|
|
380
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
406
381
|
end
|
|
407
382
|
end
|
|
408
383
|
end
|
|
409
384
|
end
|
|
410
385
|
|
|
411
|
-
describe
|
|
412
|
-
let(:depeche) { Band.create!(name:
|
|
413
|
-
let(:new_order) { Band.create!(name:
|
|
414
|
-
let(:maniacs) { Band.create!(name:
|
|
386
|
+
describe '#distinct' do
|
|
387
|
+
let(:depeche) { Band.create!(name: 'Depeche Mode', years: 30, sales: '1E2') }
|
|
388
|
+
let(:new_order) { Band.create!(name: 'New Order', years: 25, sales: '2E3') }
|
|
389
|
+
let(:maniacs) { Band.create!(name: '10,000 Maniacs', years: 20, sales: '1E2') }
|
|
415
390
|
|
|
416
391
|
let(:criteria) do
|
|
417
392
|
Band.all.tap do |crit|
|
|
@@ -423,41 +398,37 @@ describe Mongoid::Contextual::Memory do
|
|
|
423
398
|
described_class.new(criteria)
|
|
424
399
|
end
|
|
425
400
|
|
|
426
|
-
context
|
|
427
|
-
|
|
401
|
+
context 'when limiting the result set' do
|
|
428
402
|
let(:criteria) do
|
|
429
|
-
Band.where(name:
|
|
403
|
+
Band.where(name: 'Depeche Mode').tap do |crit|
|
|
430
404
|
crit.documents = [ depeche ]
|
|
431
405
|
end
|
|
432
406
|
end
|
|
433
407
|
|
|
434
|
-
it
|
|
435
|
-
expect(context.distinct(:name)).to eq([
|
|
408
|
+
it 'returns the distinct matching fields' do
|
|
409
|
+
expect(context.distinct(:name)).to eq([ 'Depeche Mode' ])
|
|
436
410
|
end
|
|
437
411
|
end
|
|
438
412
|
|
|
439
|
-
context
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
expect(context.distinct(:name).sort).to eq([ "10,000 Maniacs", "Depeche Mode", "New Order" ].sort)
|
|
413
|
+
context 'when not limiting the result set' do
|
|
414
|
+
it 'returns the distinct field values' do
|
|
415
|
+
expect(context.distinct(:name).sort).to eq([ '10,000 Maniacs', 'Depeche Mode', 'New Order' ].sort)
|
|
443
416
|
end
|
|
444
417
|
end
|
|
445
418
|
|
|
446
|
-
context
|
|
447
|
-
|
|
448
|
-
it "returns the distinct field values" do
|
|
419
|
+
context 'when providing an aliased field' do
|
|
420
|
+
it 'returns the distinct field values' do
|
|
449
421
|
expect(context.distinct(:years).sort).to eq([ 20, 25, 30 ])
|
|
450
422
|
end
|
|
451
423
|
end
|
|
452
424
|
|
|
453
|
-
context
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
expect(context.distinct(:sales).sort).to eq([ BigDecimal("1E2"), BigDecimal("2E3") ])
|
|
425
|
+
context 'when providing a demongoizable field' do
|
|
426
|
+
it 'returns the non-demongoized distinct field values' do
|
|
427
|
+
expect(context.distinct(:sales).sort).to eq([ BigDecimal('1E2'), BigDecimal('2E3') ])
|
|
457
428
|
end
|
|
458
429
|
end
|
|
459
430
|
|
|
460
|
-
context
|
|
431
|
+
context 'when getting a localized field' do
|
|
461
432
|
with_default_i18n_configs
|
|
462
433
|
|
|
463
434
|
before do
|
|
@@ -474,38 +445,36 @@ describe Mongoid::Contextual::Memory do
|
|
|
474
445
|
end
|
|
475
446
|
end
|
|
476
447
|
|
|
477
|
-
context
|
|
478
|
-
it
|
|
448
|
+
context 'when getting the field without _translations' do
|
|
449
|
+
it 'gets the demongoized localized field' do
|
|
479
450
|
expect(context.distinct(:description)).to eq([ 'deutsch-text' ])
|
|
480
451
|
end
|
|
481
452
|
end
|
|
482
453
|
|
|
483
|
-
context
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
454
|
+
context 'when getting the field with _translations' do
|
|
455
|
+
it 'gets the full hash' do
|
|
456
|
+
expect(context.distinct(:description_translations)).to eq([ { 'de' => 'deutsch-text',
|
|
457
|
+
'en' => 'english-text' } ])
|
|
487
458
|
end
|
|
488
459
|
end
|
|
489
460
|
|
|
490
461
|
context 'when plucking a specific locale' do
|
|
491
|
-
|
|
492
462
|
let(:distinct) do
|
|
493
463
|
context.distinct(:'description.de')
|
|
494
464
|
end
|
|
495
465
|
|
|
496
466
|
it 'returns the specific translation' do
|
|
497
|
-
expect(distinct).to eq([
|
|
467
|
+
expect(distinct).to eq([ 'deutsch-text' ])
|
|
498
468
|
end
|
|
499
469
|
end
|
|
500
470
|
|
|
501
471
|
context 'when plucking a specific locale from _translations field' do
|
|
502
|
-
|
|
503
472
|
let(:distinct) do
|
|
504
473
|
context.distinct(:'description_translations.de')
|
|
505
474
|
end
|
|
506
475
|
|
|
507
476
|
it 'returns the specific translations' do
|
|
508
|
-
expect(distinct).to eq(['deutsch-text'])
|
|
477
|
+
expect(distinct).to eq([ 'deutsch-text' ])
|
|
509
478
|
end
|
|
510
479
|
end
|
|
511
480
|
|
|
@@ -521,62 +490,61 @@ describe Mongoid::Contextual::Memory do
|
|
|
521
490
|
context.distinct(:description).first
|
|
522
491
|
end
|
|
523
492
|
|
|
524
|
-
it
|
|
493
|
+
it 'correctly uses the fallback' do
|
|
525
494
|
I18n.locale = :en
|
|
526
495
|
Dictionary.create!(description: 'english-text')
|
|
527
496
|
I18n.locale = :he
|
|
528
|
-
distinct.should
|
|
497
|
+
distinct.should eq 'english-text'
|
|
529
498
|
end
|
|
530
499
|
end
|
|
531
500
|
|
|
532
|
-
context
|
|
501
|
+
context 'when the localized field is embedded' do
|
|
533
502
|
with_default_i18n_configs
|
|
534
503
|
|
|
535
504
|
let(:person) do
|
|
536
505
|
p = Passport.new
|
|
537
506
|
I18n.locale = :en
|
|
538
|
-
p.name =
|
|
507
|
+
p.name = 'Neil'
|
|
539
508
|
I18n.locale = :he
|
|
540
|
-
p.name =
|
|
509
|
+
p.name = 'Nissim'
|
|
541
510
|
|
|
542
|
-
Person.create!(passport: p, employer_id:
|
|
511
|
+
Person.create!(passport: p, employer_id: 12_345)
|
|
543
512
|
end
|
|
544
513
|
|
|
545
514
|
let(:criteria) do
|
|
546
|
-
Person.where(employer_id:
|
|
515
|
+
Person.where(employer_id: 12_345).tap do |crit|
|
|
547
516
|
crit.documents = [ person ]
|
|
548
517
|
end
|
|
549
518
|
end
|
|
550
519
|
|
|
551
520
|
let(:distinct) do
|
|
552
|
-
context.distinct(
|
|
521
|
+
context.distinct('pass.name').first
|
|
553
522
|
end
|
|
554
523
|
|
|
555
524
|
let(:distinct_translations) do
|
|
556
|
-
context.distinct(
|
|
525
|
+
context.distinct('pass.name_translations').first
|
|
557
526
|
end
|
|
558
527
|
|
|
559
528
|
let(:distinct_translations_field) do
|
|
560
|
-
context.distinct(
|
|
529
|
+
context.distinct('pass.name_translations.en').first
|
|
561
530
|
end
|
|
562
531
|
|
|
563
|
-
it
|
|
564
|
-
expect(distinct).to eq(
|
|
532
|
+
it 'returns the translation for the current locale' do
|
|
533
|
+
expect(distinct).to eq('Nissim')
|
|
565
534
|
end
|
|
566
535
|
|
|
567
|
-
it
|
|
568
|
-
expect(distinct_translations).to eq({
|
|
536
|
+
it 'returns the full _translation hash' do
|
|
537
|
+
expect(distinct_translations).to eq({ 'en' => 'Neil', 'he' => 'Nissim' })
|
|
569
538
|
end
|
|
570
539
|
|
|
571
|
-
it
|
|
572
|
-
expect(distinct_translations_field).to eq(
|
|
540
|
+
it 'returns the translation for the requested locale' do
|
|
541
|
+
expect(distinct_translations_field).to eq('Neil')
|
|
573
542
|
end
|
|
574
543
|
end
|
|
575
544
|
end
|
|
576
545
|
|
|
577
|
-
context
|
|
578
|
-
|
|
579
|
-
let(:label) { Label.new(sales: "1E2") }
|
|
546
|
+
context 'when getting an embedded field' do
|
|
547
|
+
let(:label) { Label.new(sales: '1E2') }
|
|
580
548
|
let!(:band) { Band.create!(label: label) }
|
|
581
549
|
let(:criteria) do
|
|
582
550
|
Band.where(_id: band.id).tap do |crit|
|
|
@@ -584,45 +552,23 @@ describe Mongoid::Contextual::Memory do
|
|
|
584
552
|
end
|
|
585
553
|
end
|
|
586
554
|
|
|
587
|
-
it
|
|
588
|
-
expect(context.distinct(
|
|
589
|
-
end
|
|
590
|
-
end
|
|
591
|
-
|
|
592
|
-
context 'when the field name is a method name' do
|
|
593
|
-
let!(:person) do
|
|
594
|
-
Person.create!(ssn: 'secret-ssn')
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
let!(:address) do
|
|
598
|
-
person.addresses.create!(street: 'hobrecht')
|
|
599
|
-
end
|
|
600
|
-
|
|
601
|
-
let(:criteria) do
|
|
602
|
-
Address.all.tap do |crit|
|
|
603
|
-
crit.documents = [ address ]
|
|
604
|
-
end
|
|
605
|
-
end
|
|
606
|
-
|
|
607
|
-
it 'does not call the method' do
|
|
608
|
-
expect(address).not_to receive(:destroy)
|
|
609
|
-
expect(context.distinct(:destroy)).to eq([ nil ])
|
|
555
|
+
it 'returns the distinct matching fields' do
|
|
556
|
+
expect(context.distinct('label.sales')).to eq([ BigDecimal('1E2') ])
|
|
610
557
|
end
|
|
611
558
|
end
|
|
612
559
|
end
|
|
613
560
|
|
|
614
|
-
describe
|
|
615
|
-
|
|
561
|
+
describe '#each' do
|
|
616
562
|
let(:hobrecht) do
|
|
617
|
-
Address.new(street:
|
|
563
|
+
Address.new(street: 'hobrecht')
|
|
618
564
|
end
|
|
619
565
|
|
|
620
566
|
let(:friedel) do
|
|
621
|
-
Address.new(street:
|
|
567
|
+
Address.new(street: 'friedel')
|
|
622
568
|
end
|
|
623
569
|
|
|
624
570
|
let(:criteria) do
|
|
625
|
-
Address.where(street:
|
|
571
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
626
572
|
crit.documents = [ hobrecht, friedel ]
|
|
627
573
|
end
|
|
628
574
|
end
|
|
@@ -631,65 +577,52 @@ describe Mongoid::Contextual::Memory do
|
|
|
631
577
|
described_class.new(criteria)
|
|
632
578
|
end
|
|
633
579
|
|
|
634
|
-
context
|
|
635
|
-
|
|
580
|
+
context 'when skip and limit outside of range' do
|
|
636
581
|
before do
|
|
637
582
|
context.skip(10).limit(2)
|
|
638
583
|
end
|
|
639
584
|
|
|
640
|
-
it
|
|
585
|
+
it 'contains no documents' do
|
|
641
586
|
expect(context.map(&:street)).to be_empty
|
|
642
587
|
end
|
|
643
588
|
|
|
644
|
-
context
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
expect {
|
|
589
|
+
context 'when calling next on the enumerator' do
|
|
590
|
+
it 'raises a stop iteration error' do
|
|
591
|
+
expect do
|
|
648
592
|
context.each.next
|
|
649
|
-
|
|
593
|
+
end.to raise_error(StopIteration)
|
|
650
594
|
end
|
|
651
595
|
end
|
|
652
596
|
end
|
|
653
597
|
|
|
654
|
-
context
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
context.each do |doc|
|
|
658
|
-
expect(doc).to be_a(Mongoid::Document)
|
|
659
|
-
end
|
|
598
|
+
context 'when providing a block' do
|
|
599
|
+
it 'yields mongoid documents to the block' do
|
|
600
|
+
expect(context).to all(be_a(Mongoid::Document))
|
|
660
601
|
end
|
|
661
602
|
|
|
662
|
-
it
|
|
663
|
-
context.
|
|
664
|
-
expect(doc).to eq(hobrecht)
|
|
665
|
-
end
|
|
603
|
+
it 'iterates over the matching documents' do
|
|
604
|
+
expect(context).to all(eq(hobrecht))
|
|
666
605
|
end
|
|
667
606
|
end
|
|
668
607
|
|
|
669
|
-
context
|
|
670
|
-
|
|
608
|
+
context 'when no block is provided' do
|
|
671
609
|
let(:enum) do
|
|
672
610
|
context.each
|
|
673
611
|
end
|
|
674
612
|
|
|
675
|
-
it
|
|
613
|
+
it 'returns an enumerator' do
|
|
676
614
|
expect(enum).to be_a(Enumerator)
|
|
677
615
|
end
|
|
678
616
|
|
|
679
|
-
context
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
it "yields mongoid documents to the block" do
|
|
684
|
-
enum.each do |doc|
|
|
685
|
-
expect(doc).to be_a(Mongoid::Document)
|
|
686
|
-
end
|
|
617
|
+
context 'when iterating over the enumerator' do
|
|
618
|
+
context 'when iterating with each' do
|
|
619
|
+
it 'yields mongoid documents to the block' do
|
|
620
|
+
expect(enum).to all(be_a(Mongoid::Document))
|
|
687
621
|
end
|
|
688
622
|
end
|
|
689
623
|
|
|
690
|
-
context
|
|
691
|
-
|
|
692
|
-
it "yields mongoid documents" do
|
|
624
|
+
context 'when iterating with next' do
|
|
625
|
+
it 'yields mongoid documents' do
|
|
693
626
|
expect(enum.next).to be_a(Mongoid::Document)
|
|
694
627
|
end
|
|
695
628
|
end
|
|
@@ -697,54 +630,49 @@ describe Mongoid::Contextual::Memory do
|
|
|
697
630
|
end
|
|
698
631
|
|
|
699
632
|
context 'when there is a collation on the criteria' do
|
|
700
|
-
|
|
701
633
|
let(:criteria) do
|
|
702
|
-
Address.where(street:
|
|
634
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
703
635
|
crit.documents = [ hobrecht, friedel ]
|
|
704
636
|
end.collation(locale: 'en_US', strength: 2)
|
|
705
637
|
end
|
|
706
638
|
|
|
707
|
-
it
|
|
708
|
-
expect
|
|
639
|
+
it 'raises an exception' do
|
|
640
|
+
expect do
|
|
709
641
|
context.each
|
|
710
|
-
|
|
642
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
711
643
|
end
|
|
712
644
|
end
|
|
713
645
|
end
|
|
714
646
|
|
|
715
|
-
describe
|
|
716
|
-
|
|
647
|
+
describe '#exists?' do
|
|
717
648
|
let(:hobrecht) do
|
|
718
|
-
Address.new(street:
|
|
649
|
+
Address.new(street: 'hobrecht')
|
|
719
650
|
end
|
|
720
651
|
|
|
721
652
|
let(:friedel) do
|
|
722
|
-
Address.new(street:
|
|
653
|
+
Address.new(street: 'friedel')
|
|
723
654
|
end
|
|
724
655
|
|
|
725
656
|
let(:criteria) do
|
|
726
|
-
Address.where(street:
|
|
657
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
727
658
|
crit.documents = [ hobrecht, friedel ]
|
|
728
659
|
end
|
|
729
660
|
end
|
|
730
661
|
|
|
731
|
-
context
|
|
732
|
-
|
|
733
|
-
context "when there are matching documents" do
|
|
734
|
-
|
|
662
|
+
context 'when not passing options' do
|
|
663
|
+
context 'when there are matching documents' do
|
|
735
664
|
let(:context) do
|
|
736
665
|
described_class.new(criteria)
|
|
737
666
|
end
|
|
738
667
|
|
|
739
|
-
it
|
|
668
|
+
it 'returns true' do
|
|
740
669
|
expect(context).to be_exists
|
|
741
670
|
end
|
|
742
671
|
end
|
|
743
672
|
|
|
744
|
-
context
|
|
745
|
-
|
|
673
|
+
context 'when there are no matching documents' do
|
|
746
674
|
let(:criteria) do
|
|
747
|
-
Address.where(street:
|
|
675
|
+
Address.where(street: 'pfluger').tap do |crit|
|
|
748
676
|
crit.documents = [ hobrecht, friedel ]
|
|
749
677
|
end
|
|
750
678
|
end
|
|
@@ -753,147 +681,127 @@ describe Mongoid::Contextual::Memory do
|
|
|
753
681
|
described_class.new(criteria)
|
|
754
682
|
end
|
|
755
683
|
|
|
756
|
-
it
|
|
757
|
-
expect(context).
|
|
684
|
+
it 'returns false' do
|
|
685
|
+
expect(context).not_to be_exists
|
|
758
686
|
end
|
|
759
687
|
end
|
|
760
688
|
|
|
761
689
|
context 'when there is a collation on the criteria' do
|
|
762
|
-
|
|
763
690
|
let(:criteria) do
|
|
764
|
-
Address.where(street:
|
|
691
|
+
Address.where(street: 'pfluger').tap do |crit|
|
|
765
692
|
crit.documents = [ hobrecht, friedel ]
|
|
766
693
|
end.collation(locale: 'en_US', strength: 2)
|
|
767
694
|
end
|
|
768
695
|
|
|
769
|
-
it
|
|
770
|
-
expect
|
|
696
|
+
it 'raises an exception' do
|
|
697
|
+
expect do
|
|
771
698
|
context
|
|
772
|
-
|
|
699
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
773
700
|
end
|
|
774
701
|
end
|
|
775
702
|
end
|
|
776
703
|
|
|
777
|
-
context
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
context "when calling it on an empty criteria" do
|
|
782
|
-
|
|
783
|
-
it "returns true" do
|
|
704
|
+
context 'when passing an _id' do
|
|
705
|
+
context 'when its of type BSON::ObjectId' do
|
|
706
|
+
context 'when calling it on an empty criteria' do
|
|
707
|
+
it 'returns true' do
|
|
784
708
|
expect(criteria.exists?(hobrecht._id)).to be true
|
|
785
709
|
end
|
|
786
710
|
end
|
|
787
711
|
|
|
788
|
-
context
|
|
789
|
-
|
|
790
|
-
it "returns true" do
|
|
712
|
+
context 'when calling it on a criteria that includes the object' do
|
|
713
|
+
it 'returns true' do
|
|
791
714
|
expect(criteria.where(street: hobrecht.street).exists?(hobrecht._id)).to be true
|
|
792
715
|
end
|
|
793
716
|
end
|
|
794
717
|
|
|
795
|
-
context
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
expect(criteria.where(street: "bogus").exists?(hobrecht._id)).to be false
|
|
718
|
+
context 'when calling it on a criteria that does not include the object' do
|
|
719
|
+
it 'returns false' do
|
|
720
|
+
expect(criteria.where(street: 'bogus').exists?(hobrecht._id)).to be false
|
|
799
721
|
end
|
|
800
722
|
end
|
|
801
723
|
|
|
802
|
-
context
|
|
803
|
-
|
|
804
|
-
it "returns false" do
|
|
724
|
+
context 'when the id does not exist' do
|
|
725
|
+
it 'returns false' do
|
|
805
726
|
expect(criteria.exists?(BSON::ObjectId.new)).to be false
|
|
806
727
|
end
|
|
807
728
|
end
|
|
808
729
|
end
|
|
809
730
|
|
|
810
|
-
context
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
it "returns true" do
|
|
731
|
+
context 'when its of type String' do
|
|
732
|
+
context 'when the id exists' do
|
|
733
|
+
it 'returns true' do
|
|
815
734
|
expect(criteria.exists?(hobrecht._id.to_s)).to be true
|
|
816
735
|
end
|
|
817
736
|
end
|
|
818
737
|
|
|
819
|
-
context
|
|
820
|
-
|
|
821
|
-
it "returns false" do
|
|
738
|
+
context 'when the id does not exist' do
|
|
739
|
+
it 'returns false' do
|
|
822
740
|
expect(criteria.exists?(BSON::ObjectId.new.to_s)).to be false
|
|
823
741
|
end
|
|
824
742
|
end
|
|
825
743
|
end
|
|
826
744
|
end
|
|
827
745
|
|
|
828
|
-
context
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
it "returns true" do
|
|
746
|
+
context 'when passing a hash' do
|
|
747
|
+
context 'when calling it on an empty criteria' do
|
|
748
|
+
it 'returns true' do
|
|
833
749
|
expect(criteria.exists?(street: hobrecht.street)).to be true
|
|
834
750
|
end
|
|
835
751
|
end
|
|
836
752
|
|
|
837
|
-
context
|
|
838
|
-
|
|
839
|
-
it "returns true" do
|
|
753
|
+
context 'when calling it on a criteria that includes the object' do
|
|
754
|
+
it 'returns true' do
|
|
840
755
|
expect(criteria.where(_id: hobrecht._id).exists?(street: hobrecht.street)).to be true
|
|
841
756
|
end
|
|
842
757
|
end
|
|
843
758
|
|
|
844
|
-
context
|
|
845
|
-
|
|
846
|
-
it "returns false" do
|
|
759
|
+
context 'when calling it on a criteria that does not include the object' do
|
|
760
|
+
it 'returns false' do
|
|
847
761
|
expect(criteria.where(_id: BSON::ObjectId.new).exists?(street: hobrecht.street)).to be false
|
|
848
762
|
end
|
|
849
763
|
end
|
|
850
764
|
|
|
851
765
|
context "when the conditions don't match" do
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
expect(criteria.exists?(street: "bogus")).to be false
|
|
766
|
+
it 'returns false' do
|
|
767
|
+
expect(criteria.exists?(street: 'bogus')).to be false
|
|
855
768
|
end
|
|
856
769
|
end
|
|
857
770
|
end
|
|
858
771
|
|
|
859
|
-
context
|
|
860
|
-
|
|
861
|
-
it "returns false" do
|
|
772
|
+
context 'when passing false' do
|
|
773
|
+
it 'returns false' do
|
|
862
774
|
expect(criteria.exists?(false)).to be false
|
|
863
775
|
end
|
|
864
776
|
end
|
|
865
777
|
|
|
866
|
-
context
|
|
867
|
-
|
|
868
|
-
it "returns false" do
|
|
778
|
+
context 'when passing nil' do
|
|
779
|
+
it 'returns false' do
|
|
869
780
|
expect(criteria.exists?(nil)).to be false
|
|
870
781
|
end
|
|
871
782
|
end
|
|
872
783
|
|
|
873
|
-
context
|
|
874
|
-
|
|
875
|
-
it "returns false" do
|
|
784
|
+
context 'when the limit is 0' do
|
|
785
|
+
it 'returns false' do
|
|
876
786
|
expect(criteria.limit(0).exists?).to be false
|
|
877
787
|
end
|
|
878
788
|
end
|
|
879
789
|
end
|
|
880
790
|
|
|
881
|
-
[
|
|
882
|
-
|
|
791
|
+
%i[first one].each do |method|
|
|
883
792
|
describe "##{method}" do
|
|
884
|
-
|
|
885
793
|
let(:method) { method }
|
|
886
794
|
|
|
887
795
|
let(:hobrecht) do
|
|
888
|
-
Address.new(street:
|
|
796
|
+
Address.new(street: 'hobrecht')
|
|
889
797
|
end
|
|
890
798
|
|
|
891
799
|
let(:friedel) do
|
|
892
|
-
Address.new(street:
|
|
800
|
+
Address.new(street: 'friedel')
|
|
893
801
|
end
|
|
894
802
|
|
|
895
803
|
let(:criteria) do
|
|
896
|
-
Address.where(:street.in => [
|
|
804
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
897
805
|
crit.documents = [ hobrecht, friedel ]
|
|
898
806
|
end
|
|
899
807
|
end
|
|
@@ -902,51 +810,49 @@ describe Mongoid::Contextual::Memory do
|
|
|
902
810
|
described_class.new(criteria)
|
|
903
811
|
end
|
|
904
812
|
|
|
905
|
-
it
|
|
813
|
+
it 'returns the first matching document' do
|
|
906
814
|
expect(context.send(method)).to eq(hobrecht)
|
|
907
815
|
end
|
|
908
816
|
|
|
909
|
-
it
|
|
817
|
+
it 'returns a list when passing a limit' do
|
|
910
818
|
expect(context.send(method, 2)).to eq([ hobrecht, friedel ])
|
|
911
819
|
end
|
|
912
820
|
|
|
913
|
-
it
|
|
821
|
+
it 'returns a list when passing 1' do
|
|
914
822
|
expect(context.send(method, 1)).to eq([ hobrecht ])
|
|
915
823
|
end
|
|
916
824
|
|
|
917
|
-
include_examples
|
|
825
|
+
include_examples 'returns nil when no documents'
|
|
918
826
|
|
|
919
827
|
context 'when there is a collation on the criteria' do
|
|
920
|
-
|
|
921
828
|
let(:criteria) do
|
|
922
|
-
Address.where(:street.in => [
|
|
829
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
923
830
|
crit.documents = [ hobrecht, friedel ]
|
|
924
831
|
end.collation(locale: 'en_US', strength: 2)
|
|
925
832
|
end
|
|
926
833
|
|
|
927
|
-
it
|
|
928
|
-
expect
|
|
834
|
+
it 'raises an exception' do
|
|
835
|
+
expect do
|
|
929
836
|
context.send(method)
|
|
930
|
-
|
|
837
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
931
838
|
end
|
|
932
839
|
end
|
|
933
840
|
end
|
|
934
841
|
end
|
|
935
842
|
|
|
936
|
-
describe
|
|
937
|
-
|
|
843
|
+
describe '#first!' do
|
|
938
844
|
let(:method) { :first! }
|
|
939
845
|
|
|
940
846
|
let(:hobrecht) do
|
|
941
|
-
Address.new(street:
|
|
847
|
+
Address.new(street: 'hobrecht')
|
|
942
848
|
end
|
|
943
849
|
|
|
944
850
|
let(:friedel) do
|
|
945
|
-
Address.new(street:
|
|
851
|
+
Address.new(street: 'friedel')
|
|
946
852
|
end
|
|
947
853
|
|
|
948
854
|
let(:criteria) do
|
|
949
|
-
Address.where(:street.in => [
|
|
855
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
950
856
|
crit.documents = [ hobrecht, friedel ]
|
|
951
857
|
end
|
|
952
858
|
end
|
|
@@ -955,27 +861,26 @@ describe Mongoid::Contextual::Memory do
|
|
|
955
861
|
described_class.new(criteria)
|
|
956
862
|
end
|
|
957
863
|
|
|
958
|
-
it
|
|
864
|
+
it 'returns the first matching document' do
|
|
959
865
|
expect(context.first!).to eq(hobrecht)
|
|
960
866
|
end
|
|
961
867
|
|
|
962
|
-
include_examples
|
|
868
|
+
include_examples 'raises an error when no documents'
|
|
963
869
|
end
|
|
964
870
|
|
|
965
|
-
describe
|
|
966
|
-
|
|
871
|
+
describe '#take' do
|
|
967
872
|
let(:method) { :take }
|
|
968
873
|
|
|
969
874
|
let(:hobrecht) do
|
|
970
|
-
Address.new(street:
|
|
875
|
+
Address.new(street: 'hobrecht')
|
|
971
876
|
end
|
|
972
877
|
|
|
973
878
|
let(:friedel) do
|
|
974
|
-
Address.new(street:
|
|
879
|
+
Address.new(street: 'friedel')
|
|
975
880
|
end
|
|
976
881
|
|
|
977
882
|
let(:criteria) do
|
|
978
|
-
Address.where(:street.in => [
|
|
883
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
979
884
|
crit.documents = [ hobrecht, friedel ]
|
|
980
885
|
end
|
|
981
886
|
end
|
|
@@ -984,50 +889,48 @@ describe Mongoid::Contextual::Memory do
|
|
|
984
889
|
described_class.new(criteria)
|
|
985
890
|
end
|
|
986
891
|
|
|
987
|
-
it
|
|
892
|
+
it 'returns the first matching document' do
|
|
988
893
|
expect(context.take).to eq(hobrecht)
|
|
989
894
|
end
|
|
990
895
|
|
|
991
|
-
it
|
|
896
|
+
it 'returns an array when passing a limit' do
|
|
992
897
|
expect(context.take(2)).to eq([ hobrecht, friedel ])
|
|
993
898
|
end
|
|
994
899
|
|
|
995
|
-
it
|
|
900
|
+
it 'returns an array when passing a limit as 1' do
|
|
996
901
|
expect(context.take(1)).to eq([ hobrecht ])
|
|
997
902
|
end
|
|
998
903
|
|
|
999
|
-
include_examples
|
|
904
|
+
include_examples 'returns nil when no documents'
|
|
1000
905
|
|
|
1001
906
|
context 'when there is a collation on the criteria' do
|
|
1002
|
-
|
|
1003
907
|
let(:criteria) do
|
|
1004
|
-
Address.where(:street.in => [
|
|
908
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1005
909
|
crit.documents = [ hobrecht, friedel ]
|
|
1006
910
|
end.collation(locale: 'en_US', strength: 2)
|
|
1007
911
|
end
|
|
1008
912
|
|
|
1009
|
-
it
|
|
1010
|
-
expect
|
|
913
|
+
it 'raises an exception' do
|
|
914
|
+
expect do
|
|
1011
915
|
context.take
|
|
1012
|
-
|
|
916
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1013
917
|
end
|
|
1014
918
|
end
|
|
1015
919
|
end
|
|
1016
920
|
|
|
1017
|
-
describe
|
|
1018
|
-
|
|
921
|
+
describe '#take!' do
|
|
1019
922
|
let(:method) { :take! }
|
|
1020
923
|
|
|
1021
924
|
let(:hobrecht) do
|
|
1022
|
-
Address.new(street:
|
|
925
|
+
Address.new(street: 'hobrecht')
|
|
1023
926
|
end
|
|
1024
927
|
|
|
1025
928
|
let(:friedel) do
|
|
1026
|
-
Address.new(street:
|
|
929
|
+
Address.new(street: 'friedel')
|
|
1027
930
|
end
|
|
1028
931
|
|
|
1029
932
|
let(:criteria) do
|
|
1030
|
-
Address.where(:street.in => [
|
|
933
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1031
934
|
crit.documents = [ hobrecht, friedel ]
|
|
1032
935
|
end
|
|
1033
936
|
end
|
|
@@ -1036,42 +939,39 @@ describe Mongoid::Contextual::Memory do
|
|
|
1036
939
|
described_class.new(criteria)
|
|
1037
940
|
end
|
|
1038
941
|
|
|
1039
|
-
it
|
|
942
|
+
it 'returns the first matching document' do
|
|
1040
943
|
expect(context.take!).to eq(hobrecht)
|
|
1041
944
|
end
|
|
1042
945
|
|
|
1043
|
-
include_examples
|
|
946
|
+
include_examples 'raises an error when no documents'
|
|
1044
947
|
|
|
1045
948
|
context 'when there is a collation on the criteria' do
|
|
1046
|
-
|
|
1047
949
|
let(:criteria) do
|
|
1048
|
-
Address.where(:street.in => [
|
|
950
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1049
951
|
crit.documents = [ hobrecht, friedel ]
|
|
1050
952
|
end.collation(locale: 'en_US', strength: 2)
|
|
1051
953
|
end
|
|
1052
954
|
|
|
1053
|
-
it
|
|
1054
|
-
expect
|
|
955
|
+
it 'raises an exception' do
|
|
956
|
+
expect do
|
|
1055
957
|
context.take
|
|
1056
|
-
|
|
958
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1057
959
|
end
|
|
1058
960
|
end
|
|
1059
961
|
end
|
|
1060
962
|
|
|
1061
|
-
describe
|
|
1062
|
-
|
|
1063
|
-
context "when the criteria has no options" do
|
|
1064
|
-
|
|
963
|
+
describe '#initialize' do
|
|
964
|
+
context 'when the criteria has no options' do
|
|
1065
965
|
let(:hobrecht) do
|
|
1066
|
-
Address.new(street:
|
|
966
|
+
Address.new(street: 'hobrecht')
|
|
1067
967
|
end
|
|
1068
968
|
|
|
1069
969
|
let(:friedel) do
|
|
1070
|
-
Address.new(street:
|
|
970
|
+
Address.new(street: 'friedel')
|
|
1071
971
|
end
|
|
1072
972
|
|
|
1073
973
|
let(:criteria) do
|
|
1074
|
-
Address.where(street:
|
|
974
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
1075
975
|
crit.documents = [ hobrecht, friedel ]
|
|
1076
976
|
end
|
|
1077
977
|
end
|
|
@@ -1080,27 +980,26 @@ describe Mongoid::Contextual::Memory do
|
|
|
1080
980
|
described_class.new(criteria)
|
|
1081
981
|
end
|
|
1082
982
|
|
|
1083
|
-
it
|
|
983
|
+
it 'sets the criteria' do
|
|
1084
984
|
expect(context.criteria).to eq(criteria)
|
|
1085
985
|
end
|
|
1086
986
|
|
|
1087
|
-
it
|
|
987
|
+
it 'sets the klass' do
|
|
1088
988
|
expect(context.klass).to eq(Address)
|
|
1089
989
|
end
|
|
1090
990
|
|
|
1091
|
-
it
|
|
991
|
+
it 'sets the matching documents' do
|
|
1092
992
|
expect(context.documents).to eq([ hobrecht ])
|
|
1093
993
|
end
|
|
1094
994
|
end
|
|
1095
995
|
|
|
1096
|
-
context
|
|
1097
|
-
|
|
996
|
+
context 'when the criteria skips' do
|
|
1098
997
|
let(:hobrecht) do
|
|
1099
|
-
Address.new(street:
|
|
998
|
+
Address.new(street: 'hobrecht')
|
|
1100
999
|
end
|
|
1101
1000
|
|
|
1102
1001
|
let(:friedel) do
|
|
1103
|
-
Address.new(street:
|
|
1002
|
+
Address.new(street: 'friedel')
|
|
1104
1003
|
end
|
|
1105
1004
|
|
|
1106
1005
|
let(:criteria) do
|
|
@@ -1113,19 +1012,18 @@ describe Mongoid::Contextual::Memory do
|
|
|
1113
1012
|
described_class.new(criteria)
|
|
1114
1013
|
end
|
|
1115
1014
|
|
|
1116
|
-
it
|
|
1015
|
+
it 'limits the matching documents' do
|
|
1117
1016
|
expect(context).to eq([ friedel ])
|
|
1118
1017
|
end
|
|
1119
1018
|
end
|
|
1120
1019
|
|
|
1121
|
-
context
|
|
1122
|
-
|
|
1020
|
+
context 'when the criteria limits' do
|
|
1123
1021
|
let(:hobrecht) do
|
|
1124
|
-
Address.new(street:
|
|
1022
|
+
Address.new(street: 'hobrecht')
|
|
1125
1023
|
end
|
|
1126
1024
|
|
|
1127
1025
|
let(:friedel) do
|
|
1128
|
-
Address.new(street:
|
|
1026
|
+
Address.new(street: 'friedel')
|
|
1129
1027
|
end
|
|
1130
1028
|
|
|
1131
1029
|
let(:criteria) do
|
|
@@ -1138,41 +1036,39 @@ describe Mongoid::Contextual::Memory do
|
|
|
1138
1036
|
described_class.new(criteria)
|
|
1139
1037
|
end
|
|
1140
1038
|
|
|
1141
|
-
it
|
|
1039
|
+
it 'limits the matching documents' do
|
|
1142
1040
|
expect(context).to eq([ hobrecht ])
|
|
1143
1041
|
end
|
|
1144
1042
|
end
|
|
1145
1043
|
|
|
1146
1044
|
context 'when there is a collation on the criteria' do
|
|
1147
|
-
|
|
1148
1045
|
let(:criteria) do
|
|
1149
1046
|
Address.all.limit(1).tap do |crit|
|
|
1150
1047
|
crit.documents = [ hobrecht, friedel ]
|
|
1151
1048
|
end.collation(locale: 'en_US', strength: 2)
|
|
1152
1049
|
end
|
|
1153
1050
|
|
|
1154
|
-
it
|
|
1155
|
-
expect
|
|
1051
|
+
it 'raises an exception' do
|
|
1052
|
+
expect do
|
|
1156
1053
|
context
|
|
1157
|
-
|
|
1054
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1158
1055
|
end
|
|
1159
1056
|
end
|
|
1160
1057
|
end
|
|
1161
1058
|
|
|
1162
|
-
describe
|
|
1163
|
-
|
|
1059
|
+
describe '#last' do
|
|
1164
1060
|
let(:method) { :last }
|
|
1165
1061
|
|
|
1166
1062
|
let(:hobrecht) do
|
|
1167
|
-
Address.new(street:
|
|
1063
|
+
Address.new(street: 'hobrecht')
|
|
1168
1064
|
end
|
|
1169
1065
|
|
|
1170
1066
|
let(:friedel) do
|
|
1171
|
-
Address.new(street:
|
|
1067
|
+
Address.new(street: 'friedel')
|
|
1172
1068
|
end
|
|
1173
1069
|
|
|
1174
1070
|
let(:criteria) do
|
|
1175
|
-
Address.where(:street.in => [
|
|
1071
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1176
1072
|
crit.documents = [ hobrecht, friedel ]
|
|
1177
1073
|
end
|
|
1178
1074
|
end
|
|
@@ -1181,49 +1077,48 @@ describe Mongoid::Contextual::Memory do
|
|
|
1181
1077
|
described_class.new(criteria)
|
|
1182
1078
|
end
|
|
1183
1079
|
|
|
1184
|
-
it
|
|
1080
|
+
it 'returns the last matching document' do
|
|
1185
1081
|
expect(context.last).to eq(friedel)
|
|
1186
1082
|
end
|
|
1187
1083
|
|
|
1188
|
-
it
|
|
1084
|
+
it 'returns a list when a limit is passed' do
|
|
1189
1085
|
expect(context.last(2)).to eq([ hobrecht, friedel ])
|
|
1190
1086
|
end
|
|
1191
1087
|
|
|
1192
|
-
it
|
|
1088
|
+
it 'returns a list when the limit is 1' do
|
|
1193
1089
|
expect(context.last(1)).to eq([ friedel ])
|
|
1194
1090
|
end
|
|
1195
1091
|
|
|
1196
|
-
include_examples
|
|
1092
|
+
include_examples 'returns nil when no documents'
|
|
1197
1093
|
|
|
1198
1094
|
context 'when there is a collation on the criteria' do
|
|
1199
|
-
|
|
1200
1095
|
let(:criteria) do
|
|
1201
|
-
Address.where(:street.in => [
|
|
1096
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1202
1097
|
crit.documents = [ hobrecht, friedel ]
|
|
1203
1098
|
end.collation(locale: 'en_US', strength: 2)
|
|
1204
1099
|
end
|
|
1205
1100
|
|
|
1206
|
-
it
|
|
1207
|
-
expect
|
|
1101
|
+
it 'raises an exception' do
|
|
1102
|
+
expect do
|
|
1208
1103
|
context.last
|
|
1209
|
-
|
|
1104
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1210
1105
|
end
|
|
1211
1106
|
end
|
|
1212
1107
|
end
|
|
1213
1108
|
|
|
1214
|
-
describe
|
|
1109
|
+
describe '#last!' do
|
|
1215
1110
|
let(:method) { :last! }
|
|
1216
1111
|
|
|
1217
1112
|
let(:hobrecht) do
|
|
1218
|
-
Address.new(street:
|
|
1113
|
+
Address.new(street: 'hobrecht')
|
|
1219
1114
|
end
|
|
1220
1115
|
|
|
1221
1116
|
let(:friedel) do
|
|
1222
|
-
Address.new(street:
|
|
1117
|
+
Address.new(street: 'friedel')
|
|
1223
1118
|
end
|
|
1224
1119
|
|
|
1225
1120
|
let(:criteria) do
|
|
1226
|
-
Address.where(:street.in => [
|
|
1121
|
+
Address.where(:street.in => %w[hobrecht friedel]).tap do |crit|
|
|
1227
1122
|
crit.documents = [ hobrecht, friedel ]
|
|
1228
1123
|
end
|
|
1229
1124
|
end
|
|
@@ -1232,20 +1127,19 @@ describe Mongoid::Contextual::Memory do
|
|
|
1232
1127
|
described_class.new(criteria)
|
|
1233
1128
|
end
|
|
1234
1129
|
|
|
1235
|
-
it
|
|
1130
|
+
it 'returns the last matching document' do
|
|
1236
1131
|
expect(context.last!).to eq(friedel)
|
|
1237
1132
|
end
|
|
1238
1133
|
|
|
1239
|
-
include_examples
|
|
1134
|
+
include_examples 'raises an error when no documents'
|
|
1240
1135
|
end
|
|
1241
1136
|
|
|
1242
|
-
[
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
].each do |meth|
|
|
1137
|
+
%i[second
|
|
1138
|
+
third
|
|
1139
|
+
fourth
|
|
1140
|
+
fifth
|
|
1141
|
+
second_to_last
|
|
1142
|
+
third_to_last].each do |meth|
|
|
1249
1143
|
describe "##{meth}" do
|
|
1250
1144
|
let(:method) { meth }
|
|
1251
1145
|
|
|
@@ -1255,7 +1149,7 @@ describe Mongoid::Contextual::Memory do
|
|
|
1255
1149
|
Address.new,
|
|
1256
1150
|
Address.new,
|
|
1257
1151
|
Address.new,
|
|
1258
|
-
Address.new
|
|
1152
|
+
Address.new
|
|
1259
1153
|
]
|
|
1260
1154
|
end
|
|
1261
1155
|
|
|
@@ -1269,11 +1163,11 @@ describe Mongoid::Contextual::Memory do
|
|
|
1269
1163
|
described_class.new(criteria)
|
|
1270
1164
|
end
|
|
1271
1165
|
|
|
1272
|
-
it
|
|
1166
|
+
it 'returns the matching document' do
|
|
1273
1167
|
expect(context.send(method)).to eq(addresses.send(method))
|
|
1274
1168
|
end
|
|
1275
1169
|
|
|
1276
|
-
include_examples
|
|
1170
|
+
include_examples 'returns nil when no documents'
|
|
1277
1171
|
end
|
|
1278
1172
|
|
|
1279
1173
|
describe "##{meth}!" do
|
|
@@ -1285,7 +1179,7 @@ describe Mongoid::Contextual::Memory do
|
|
|
1285
1179
|
Address.new,
|
|
1286
1180
|
Address.new,
|
|
1287
1181
|
Address.new,
|
|
1288
|
-
Address.new
|
|
1182
|
+
Address.new
|
|
1289
1183
|
]
|
|
1290
1184
|
end
|
|
1291
1185
|
|
|
@@ -1299,30 +1193,27 @@ describe Mongoid::Contextual::Memory do
|
|
|
1299
1193
|
described_class.new(criteria)
|
|
1300
1194
|
end
|
|
1301
1195
|
|
|
1302
|
-
it
|
|
1196
|
+
it 'returns the matching document' do
|
|
1303
1197
|
expect(context.send(method)).to eq(addresses.send(meth))
|
|
1304
1198
|
end
|
|
1305
1199
|
|
|
1306
|
-
include_examples
|
|
1200
|
+
include_examples 'raises an error when no documents'
|
|
1307
1201
|
end
|
|
1308
1202
|
end
|
|
1309
1203
|
|
|
1310
|
-
[
|
|
1311
|
-
|
|
1204
|
+
%i[length size].each do |method|
|
|
1312
1205
|
describe "##{method}" do
|
|
1313
|
-
|
|
1314
1206
|
let(:hobrecht) do
|
|
1315
|
-
Address.new(street:
|
|
1207
|
+
Address.new(street: 'hobrecht')
|
|
1316
1208
|
end
|
|
1317
1209
|
|
|
1318
1210
|
let(:friedel) do
|
|
1319
|
-
Address.new(street:
|
|
1211
|
+
Address.new(street: 'friedel')
|
|
1320
1212
|
end
|
|
1321
1213
|
|
|
1322
|
-
context
|
|
1323
|
-
|
|
1214
|
+
context 'when there are matching documents' do
|
|
1324
1215
|
let(:criteria) do
|
|
1325
|
-
Address.where(street:
|
|
1216
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
1326
1217
|
crit.documents = [ hobrecht, friedel ]
|
|
1327
1218
|
end
|
|
1328
1219
|
end
|
|
@@ -1331,15 +1222,14 @@ describe Mongoid::Contextual::Memory do
|
|
|
1331
1222
|
described_class.new(criteria)
|
|
1332
1223
|
end
|
|
1333
1224
|
|
|
1334
|
-
it
|
|
1225
|
+
it 'returns the number of matches' do
|
|
1335
1226
|
expect(context.send(method)).to eq(1)
|
|
1336
1227
|
end
|
|
1337
1228
|
end
|
|
1338
1229
|
|
|
1339
|
-
context
|
|
1340
|
-
|
|
1230
|
+
context 'when there are no matching documents' do
|
|
1341
1231
|
let(:criteria) do
|
|
1342
|
-
Address.where(street:
|
|
1232
|
+
Address.where(street: 'pfluger').tap do |crit|
|
|
1343
1233
|
crit.documents = [ hobrecht, friedel ]
|
|
1344
1234
|
end
|
|
1345
1235
|
end
|
|
@@ -1348,40 +1238,38 @@ describe Mongoid::Contextual::Memory do
|
|
|
1348
1238
|
described_class.new(criteria)
|
|
1349
1239
|
end
|
|
1350
1240
|
|
|
1351
|
-
it
|
|
1241
|
+
it 'returns zero' do
|
|
1352
1242
|
expect(context.send(method)).to eq(0)
|
|
1353
1243
|
end
|
|
1354
1244
|
end
|
|
1355
1245
|
|
|
1356
1246
|
context 'when there is a collation on the criteria' do
|
|
1357
|
-
|
|
1358
1247
|
let(:criteria) do
|
|
1359
|
-
Address.where(street:
|
|
1248
|
+
Address.where(street: 'hobrecht').tap do |crit|
|
|
1360
1249
|
crit.documents = [ hobrecht, friedel ]
|
|
1361
1250
|
end.collation(locale: 'en_US', strength: 2)
|
|
1362
1251
|
end
|
|
1363
1252
|
|
|
1364
|
-
it
|
|
1365
|
-
expect
|
|
1253
|
+
it 'raises an exception' do
|
|
1254
|
+
expect do
|
|
1366
1255
|
context.send(method)
|
|
1367
|
-
|
|
1256
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1368
1257
|
end
|
|
1369
1258
|
end
|
|
1370
1259
|
end
|
|
1371
1260
|
end
|
|
1372
1261
|
|
|
1373
|
-
describe
|
|
1374
|
-
|
|
1262
|
+
describe '#limit' do
|
|
1375
1263
|
let(:hobrecht) do
|
|
1376
|
-
Address.new(street:
|
|
1264
|
+
Address.new(street: 'hobrecht')
|
|
1377
1265
|
end
|
|
1378
1266
|
|
|
1379
1267
|
let(:friedel) do
|
|
1380
|
-
Address.new(street:
|
|
1268
|
+
Address.new(street: 'friedel')
|
|
1381
1269
|
end
|
|
1382
1270
|
|
|
1383
1271
|
let(:pfluger) do
|
|
1384
|
-
Address.new(street:
|
|
1272
|
+
Address.new(street: 'pfluger')
|
|
1385
1273
|
end
|
|
1386
1274
|
|
|
1387
1275
|
let(:criteria) do
|
|
@@ -1395,31 +1283,27 @@ describe Mongoid::Contextual::Memory do
|
|
|
1395
1283
|
end
|
|
1396
1284
|
|
|
1397
1285
|
context 'when there is no collation on the criteria' do
|
|
1398
|
-
|
|
1399
1286
|
let!(:limit) do
|
|
1400
1287
|
context.limit(2)
|
|
1401
1288
|
end
|
|
1402
1289
|
|
|
1403
|
-
it
|
|
1290
|
+
it 'returns the context' do
|
|
1404
1291
|
expect(limit).to eq(context)
|
|
1405
1292
|
end
|
|
1406
1293
|
|
|
1407
|
-
context
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
it "only returns the limited documents" do
|
|
1294
|
+
context 'when asking for all documents' do
|
|
1295
|
+
context 'when only a limit exists' do
|
|
1296
|
+
it 'only returns the limited documents' do
|
|
1412
1297
|
expect(context.entries).to eq([ hobrecht, friedel ])
|
|
1413
1298
|
end
|
|
1414
1299
|
end
|
|
1415
1300
|
|
|
1416
|
-
context
|
|
1417
|
-
|
|
1301
|
+
context 'when a skip and limit exist' do
|
|
1418
1302
|
before do
|
|
1419
1303
|
limit.skip(1)
|
|
1420
1304
|
end
|
|
1421
1305
|
|
|
1422
|
-
it
|
|
1306
|
+
it 'applies the skip before the limit' do
|
|
1423
1307
|
expect(context.entries).to eq([ friedel, pfluger ])
|
|
1424
1308
|
end
|
|
1425
1309
|
end
|
|
@@ -1427,41 +1311,39 @@ describe Mongoid::Contextual::Memory do
|
|
|
1427
1311
|
end
|
|
1428
1312
|
|
|
1429
1313
|
context 'when there is a collation on the criteria' do
|
|
1430
|
-
|
|
1431
1314
|
let(:criteria) do
|
|
1432
1315
|
Address.all.tap do |crit|
|
|
1433
1316
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
1434
1317
|
end.collation(locale: 'en_US', strength: 2)
|
|
1435
1318
|
end
|
|
1436
1319
|
|
|
1437
|
-
it
|
|
1438
|
-
expect
|
|
1320
|
+
it 'raises an exception' do
|
|
1321
|
+
expect do
|
|
1439
1322
|
context.limit(2)
|
|
1440
|
-
|
|
1323
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
1441
1324
|
end
|
|
1442
1325
|
end
|
|
1443
1326
|
end
|
|
1444
1327
|
|
|
1445
|
-
describe
|
|
1446
|
-
|
|
1328
|
+
describe '#pluck' do
|
|
1447
1329
|
let(:context) do
|
|
1448
1330
|
described_class.new(criteria)
|
|
1449
1331
|
end
|
|
1450
1332
|
|
|
1451
1333
|
let!(:depeche) do
|
|
1452
|
-
Band.create!(name:
|
|
1334
|
+
Band.create!(name: 'Depeche Mode', likes: 3)
|
|
1453
1335
|
end
|
|
1454
1336
|
|
|
1455
1337
|
let!(:tool) do
|
|
1456
|
-
Band.create!(name:
|
|
1338
|
+
Band.create!(name: 'Tool', likes: 3)
|
|
1457
1339
|
end
|
|
1458
1340
|
|
|
1459
1341
|
let!(:photek) do
|
|
1460
|
-
Band.create!(name:
|
|
1342
|
+
Band.create!(name: 'Photek', likes: 1)
|
|
1461
1343
|
end
|
|
1462
1344
|
|
|
1463
1345
|
let!(:maniacs) do
|
|
1464
|
-
Band.create!(name:
|
|
1346
|
+
Band.create!(name: '10,000 Maniacs', likes: 1, sales: '1E2')
|
|
1465
1347
|
end
|
|
1466
1348
|
|
|
1467
1349
|
let(:criteria) do
|
|
@@ -1470,10 +1352,9 @@ describe Mongoid::Contextual::Memory do
|
|
|
1470
1352
|
end
|
|
1471
1353
|
end
|
|
1472
1354
|
|
|
1473
|
-
context
|
|
1474
|
-
|
|
1355
|
+
context 'when the field is aliased' do
|
|
1475
1356
|
let!(:expensive) do
|
|
1476
|
-
Product.create!(price:
|
|
1357
|
+
Product.create!(price: 100_000)
|
|
1477
1358
|
end
|
|
1478
1359
|
|
|
1479
1360
|
let!(:cheap) do
|
|
@@ -1486,39 +1367,34 @@ describe Mongoid::Contextual::Memory do
|
|
|
1486
1367
|
end
|
|
1487
1368
|
end
|
|
1488
1369
|
|
|
1489
|
-
context
|
|
1490
|
-
|
|
1370
|
+
context 'when using alias_attribute' do
|
|
1491
1371
|
let(:plucked) do
|
|
1492
1372
|
context.pluck(:price)
|
|
1493
1373
|
end
|
|
1494
1374
|
|
|
1495
|
-
it
|
|
1496
|
-
expect(plucked).to eq([
|
|
1375
|
+
it 'uses the aliases' do
|
|
1376
|
+
expect(plucked).to eq([ 100_000, 1 ])
|
|
1497
1377
|
end
|
|
1498
1378
|
end
|
|
1499
1379
|
end
|
|
1500
1380
|
|
|
1501
|
-
context
|
|
1502
|
-
|
|
1503
|
-
context "when there are no duplicate values" do
|
|
1504
|
-
|
|
1381
|
+
context 'when the criteria matches' do
|
|
1382
|
+
context 'when there are no duplicate values' do
|
|
1505
1383
|
let!(:plucked) do
|
|
1506
1384
|
context.pluck(:name)
|
|
1507
1385
|
end
|
|
1508
1386
|
|
|
1509
|
-
it
|
|
1510
|
-
expect(plucked).to contain_exactly(
|
|
1387
|
+
it 'returns the values' do
|
|
1388
|
+
expect(plucked).to contain_exactly('10,000 Maniacs', 'Depeche Mode', 'Tool', 'Photek')
|
|
1511
1389
|
end
|
|
1512
1390
|
|
|
1513
|
-
context
|
|
1514
|
-
|
|
1515
|
-
it "does not limit the fields" do
|
|
1391
|
+
context 'when subsequently executing the criteria without a pluck' do
|
|
1392
|
+
it 'does not limit the fields' do
|
|
1516
1393
|
expect(context.first.likes).to eq(3)
|
|
1517
1394
|
end
|
|
1518
1395
|
end
|
|
1519
1396
|
|
|
1520
1397
|
context 'when the field is a subdocument' do
|
|
1521
|
-
|
|
1522
1398
|
context 'when a top-level field and a subdocument field are plucked' do
|
|
1523
1399
|
let(:criteria) do
|
|
1524
1400
|
Band.where(name: 'FKA Twigs').tap do |crit|
|
|
@@ -1535,8 +1411,8 @@ describe Mongoid::Contextual::Memory do
|
|
|
1535
1411
|
|
|
1536
1412
|
let(:expected) do
|
|
1537
1413
|
[
|
|
1538
|
-
[
|
|
1539
|
-
['FKA Twigs', [
|
|
1414
|
+
[ 'FKA Twigs', [] ],
|
|
1415
|
+
[ 'FKA Twigs', [ 'LP1' ] ]
|
|
1540
1416
|
]
|
|
1541
1417
|
end
|
|
1542
1418
|
|
|
@@ -1546,7 +1422,6 @@ describe Mongoid::Contextual::Memory do
|
|
|
1546
1422
|
end
|
|
1547
1423
|
|
|
1548
1424
|
context 'when only a subdocument field is plucked' do
|
|
1549
|
-
|
|
1550
1425
|
let(:criteria) do
|
|
1551
1426
|
Band.where(name: 'FKA Twigs').tap do |crit|
|
|
1552
1427
|
crit.documents = [
|
|
@@ -1563,7 +1438,7 @@ describe Mongoid::Contextual::Memory do
|
|
|
1563
1438
|
let(:expected) do
|
|
1564
1439
|
[
|
|
1565
1440
|
[],
|
|
1566
|
-
[
|
|
1441
|
+
[ 'LP1' ]
|
|
1567
1442
|
]
|
|
1568
1443
|
end
|
|
1569
1444
|
|
|
@@ -1574,72 +1449,66 @@ describe Mongoid::Contextual::Memory do
|
|
|
1574
1449
|
end
|
|
1575
1450
|
end
|
|
1576
1451
|
|
|
1577
|
-
context
|
|
1578
|
-
|
|
1452
|
+
context 'when plucking multi-fields' do
|
|
1579
1453
|
let(:plucked) do
|
|
1580
1454
|
context.pluck(:name, :likes)
|
|
1581
1455
|
end
|
|
1582
1456
|
|
|
1583
|
-
it
|
|
1584
|
-
expect(plucked).to contain_exactly([
|
|
1457
|
+
it 'returns the values' do
|
|
1458
|
+
expect(plucked).to contain_exactly([ '10,000 Maniacs', 1 ], [ 'Depeche Mode', 3 ], [ 'Tool', 3 ],
|
|
1459
|
+
[ 'Photek', 1 ])
|
|
1585
1460
|
end
|
|
1586
1461
|
end
|
|
1587
1462
|
|
|
1588
|
-
context
|
|
1589
|
-
|
|
1463
|
+
context 'when there are duplicate values' do
|
|
1590
1464
|
let(:plucked) do
|
|
1591
1465
|
context.pluck(:likes)
|
|
1592
1466
|
end
|
|
1593
1467
|
|
|
1594
|
-
it
|
|
1468
|
+
it 'returns the duplicates' do
|
|
1595
1469
|
expect(plucked).to contain_exactly(1, 3, 3, 1)
|
|
1596
1470
|
end
|
|
1597
1471
|
end
|
|
1598
1472
|
end
|
|
1599
1473
|
|
|
1600
|
-
context
|
|
1601
|
-
|
|
1474
|
+
context 'when plucking an aliased field' do
|
|
1602
1475
|
let(:plucked) do
|
|
1603
1476
|
context.pluck(:id)
|
|
1604
1477
|
end
|
|
1605
1478
|
|
|
1606
|
-
it
|
|
1479
|
+
it 'returns the field values' do
|
|
1607
1480
|
expect(plucked).to eq([ depeche.id, tool.id, photek.id, maniacs.id ])
|
|
1608
1481
|
end
|
|
1609
1482
|
end
|
|
1610
1483
|
|
|
1611
|
-
context
|
|
1612
|
-
|
|
1484
|
+
context 'when plucking existent and non-existent fields' do
|
|
1613
1485
|
let(:plucked) do
|
|
1614
1486
|
context.pluck(:id, :fooz)
|
|
1615
1487
|
end
|
|
1616
1488
|
|
|
1617
|
-
it
|
|
1618
|
-
expect(plucked).to eq([[depeche.id, nil], [tool.id, nil], [photek.id, nil], [maniacs.id, nil] ])
|
|
1489
|
+
it 'returns nil for the field that doesnt exist' do
|
|
1490
|
+
expect(plucked).to eq([ [ depeche.id, nil ], [ tool.id, nil ], [ photek.id, nil ], [ maniacs.id, nil ] ])
|
|
1619
1491
|
end
|
|
1620
1492
|
end
|
|
1621
1493
|
|
|
1622
|
-
context
|
|
1623
|
-
|
|
1624
|
-
context "when pluck one field" do
|
|
1625
|
-
|
|
1494
|
+
context 'when plucking a field that doesnt exist' do
|
|
1495
|
+
context 'when pluck one field' do
|
|
1626
1496
|
let(:plucked) do
|
|
1627
1497
|
context.pluck(:foo)
|
|
1628
1498
|
end
|
|
1629
1499
|
|
|
1630
|
-
it
|
|
1631
|
-
expect(plucked).to eq([nil, nil, nil, nil])
|
|
1500
|
+
it 'returns an array with nil values' do
|
|
1501
|
+
expect(plucked).to eq([ nil, nil, nil, nil ])
|
|
1632
1502
|
end
|
|
1633
1503
|
end
|
|
1634
1504
|
|
|
1635
|
-
context
|
|
1636
|
-
|
|
1505
|
+
context 'when pluck multiple fields' do
|
|
1637
1506
|
let(:plucked) do
|
|
1638
1507
|
context.pluck(:foo, :bar)
|
|
1639
1508
|
end
|
|
1640
1509
|
|
|
1641
|
-
it
|
|
1642
|
-
expect(plucked).to eq([[nil, nil], [nil, nil], [nil, nil], [nil, nil]])
|
|
1510
|
+
it 'returns an array of arrays with nil values' do
|
|
1511
|
+
expect(plucked).to eq([ [ nil, nil ], [ nil, nil ], [ nil, nil ], [ nil, nil ] ])
|
|
1643
1512
|
end
|
|
1644
1513
|
end
|
|
1645
1514
|
end
|
|
@@ -1662,7 +1531,6 @@ describe Mongoid::Contextual::Memory do
|
|
|
1662
1531
|
end
|
|
1663
1532
|
|
|
1664
1533
|
context 'when plucking the entire field' do
|
|
1665
|
-
|
|
1666
1534
|
let(:plucked) do
|
|
1667
1535
|
context.pluck(:description)
|
|
1668
1536
|
end
|
|
@@ -1680,16 +1548,16 @@ describe Mongoid::Contextual::Memory do
|
|
|
1680
1548
|
end
|
|
1681
1549
|
|
|
1682
1550
|
it 'returns the full translations hash to _translations' do
|
|
1683
|
-
expect(plucked_translations.first).to eq({
|
|
1551
|
+
expect(plucked_translations.first).to eq({ 'de' => 'deutsch-text', 'en' => 'english-text' })
|
|
1684
1552
|
end
|
|
1685
1553
|
|
|
1686
1554
|
it 'returns both' do
|
|
1687
|
-
expect(plucked_translations_both.first).to eq([{
|
|
1555
|
+
expect(plucked_translations_both.first).to eq([ { 'de' => 'deutsch-text', 'en' => 'english-text' },
|
|
1556
|
+
'deutsch-text' ])
|
|
1688
1557
|
end
|
|
1689
1558
|
end
|
|
1690
1559
|
|
|
1691
1560
|
context 'when plucking a specific locale' do
|
|
1692
|
-
|
|
1693
1561
|
let(:plucked) do
|
|
1694
1562
|
context.pluck(:'description.de')
|
|
1695
1563
|
end
|
|
@@ -1700,7 +1568,6 @@ describe Mongoid::Contextual::Memory do
|
|
|
1700
1568
|
end
|
|
1701
1569
|
|
|
1702
1570
|
context 'when plucking a specific locale from _translations field' do
|
|
1703
|
-
|
|
1704
1571
|
let(:plucked) do
|
|
1705
1572
|
context.pluck(:'description_translations.de')
|
|
1706
1573
|
end
|
|
@@ -1722,251 +1589,140 @@ describe Mongoid::Contextual::Memory do
|
|
|
1722
1589
|
context.pluck(:description).first
|
|
1723
1590
|
end
|
|
1724
1591
|
|
|
1725
|
-
it
|
|
1592
|
+
it 'correctly uses the fallback' do
|
|
1726
1593
|
I18n.locale = :en
|
|
1727
1594
|
Dictionary.create!(description: 'english-text')
|
|
1728
1595
|
I18n.locale = :he
|
|
1729
|
-
plucked.should
|
|
1596
|
+
plucked.should eq 'english-text'
|
|
1730
1597
|
end
|
|
1731
1598
|
end
|
|
1732
1599
|
|
|
1733
|
-
context
|
|
1600
|
+
context 'when the localized field is embedded' do
|
|
1734
1601
|
with_default_i18n_configs
|
|
1735
1602
|
|
|
1736
1603
|
before do
|
|
1737
1604
|
p = Passport.new
|
|
1738
1605
|
I18n.locale = :en
|
|
1739
|
-
p.name =
|
|
1606
|
+
p.name = 'Neil'
|
|
1740
1607
|
I18n.locale = :he
|
|
1741
|
-
p.name =
|
|
1608
|
+
p.name = 'Nissim'
|
|
1742
1609
|
|
|
1743
|
-
Person.create!(passport: p, employer_id:
|
|
1610
|
+
Person.create!(passport: p, employer_id: 12_345)
|
|
1744
1611
|
end
|
|
1745
1612
|
|
|
1746
1613
|
let(:plucked) do
|
|
1747
|
-
Person.where(employer_id:
|
|
1614
|
+
Person.where(employer_id: 12_345).pluck('pass.name').first
|
|
1748
1615
|
end
|
|
1749
1616
|
|
|
1750
1617
|
let(:plucked_translations) do
|
|
1751
|
-
Person.where(employer_id:
|
|
1618
|
+
Person.where(employer_id: 12_345).pluck('pass.name_translations').first
|
|
1752
1619
|
end
|
|
1753
1620
|
|
|
1754
1621
|
let(:plucked_translations_field) do
|
|
1755
|
-
Person.where(employer_id:
|
|
1622
|
+
Person.where(employer_id: 12_345).pluck('pass.name_translations.en').first
|
|
1756
1623
|
end
|
|
1757
1624
|
|
|
1758
|
-
it
|
|
1759
|
-
expect(plucked).to eq(
|
|
1625
|
+
it 'returns the translation for the current locale' do
|
|
1626
|
+
expect(plucked).to eq('Nissim')
|
|
1760
1627
|
end
|
|
1761
1628
|
|
|
1762
|
-
it
|
|
1763
|
-
expect(plucked_translations).to eq({
|
|
1629
|
+
it 'returns the full _translation hash' do
|
|
1630
|
+
expect(plucked_translations).to eq({ 'en' => 'Neil', 'he' => 'Nissim' })
|
|
1764
1631
|
end
|
|
1765
1632
|
|
|
1766
|
-
it
|
|
1767
|
-
expect(plucked_translations_field).to eq(
|
|
1633
|
+
it 'returns the translation for the requested locale' do
|
|
1634
|
+
expect(plucked_translations_field).to eq('Neil')
|
|
1768
1635
|
end
|
|
1769
1636
|
end
|
|
1770
1637
|
end
|
|
1771
1638
|
|
|
1772
1639
|
context 'when plucking a field to be demongoized' do
|
|
1773
|
-
|
|
1774
1640
|
let(:plucked) do
|
|
1775
1641
|
Band.where(name: maniacs.name).pluck(:sales)
|
|
1776
1642
|
end
|
|
1777
1643
|
|
|
1778
1644
|
with_config_values :map_big_decimal_to_decimal128, true, false do
|
|
1779
|
-
|
|
1780
|
-
it "demongoizes the field" do
|
|
1645
|
+
it 'demongoizes the field' do
|
|
1781
1646
|
expect(plucked.first).to be_a(BigDecimal)
|
|
1782
|
-
expect(plucked.first).to eq(BigDecimal(
|
|
1647
|
+
expect(plucked.first).to eq(BigDecimal('1E2'))
|
|
1783
1648
|
end
|
|
1784
1649
|
end
|
|
1785
1650
|
end
|
|
1786
1651
|
|
|
1787
|
-
context
|
|
1788
|
-
let(:label) { Label.new(sales:
|
|
1652
|
+
context 'when plucking an embedded field' do
|
|
1653
|
+
let(:label) { Label.new(sales: '1E2') }
|
|
1789
1654
|
let!(:band) { Band.create!(label: label) }
|
|
1790
1655
|
|
|
1791
1656
|
let(:plucked) do
|
|
1792
1657
|
Band.where(_id: band.id).tap do |crit|
|
|
1793
1658
|
crit.documents = [ band ]
|
|
1794
|
-
end.pluck(
|
|
1659
|
+
end.pluck('label.sales')
|
|
1795
1660
|
end
|
|
1796
1661
|
|
|
1797
|
-
it
|
|
1798
|
-
expect(plucked).to eq([ BigDecimal(
|
|
1662
|
+
it 'demongoizes the field' do
|
|
1663
|
+
expect(plucked).to eq([ BigDecimal('1E2') ])
|
|
1799
1664
|
end
|
|
1800
1665
|
end
|
|
1801
1666
|
|
|
1802
|
-
context
|
|
1803
|
-
let(:label) { Label.new(sales:
|
|
1804
|
-
let!(:band) { Band.create!(labels: [label]) }
|
|
1667
|
+
context 'when plucking an embeds_many field' do
|
|
1668
|
+
let(:label) { Label.new(sales: '1E2') }
|
|
1669
|
+
let!(:band) { Band.create!(labels: [ label ]) }
|
|
1805
1670
|
|
|
1806
|
-
let(:plucked) { Band.where(_id: band.id).pluck(
|
|
1671
|
+
let(:plucked) { Band.where(_id: band.id).pluck('labels.sales') }
|
|
1807
1672
|
|
|
1808
|
-
it
|
|
1809
|
-
expect(plucked.first).to eq([ BigDecimal(
|
|
1673
|
+
it 'demongoizes the field' do
|
|
1674
|
+
expect(plucked.first).to eq([ BigDecimal('1E2') ])
|
|
1810
1675
|
end
|
|
1811
1676
|
end
|
|
1812
1677
|
|
|
1813
|
-
context
|
|
1814
|
-
let(:label) { Label.new(sales:
|
|
1678
|
+
context 'when plucking a nonexistent embedded field' do
|
|
1679
|
+
let(:label) { Label.new(sales: '1E2') }
|
|
1815
1680
|
let!(:band) { Band.create!(label: label) }
|
|
1816
1681
|
|
|
1817
1682
|
let(:plucked) do
|
|
1818
1683
|
Band.where(_id: band.id).tap do |crit|
|
|
1819
1684
|
crit.documents = [ band ]
|
|
1820
|
-
end.pluck(
|
|
1685
|
+
end.pluck('label.qwerty')
|
|
1821
1686
|
end
|
|
1822
1687
|
|
|
1823
|
-
it
|
|
1688
|
+
it 'returns nil' do
|
|
1824
1689
|
expect(plucked.first).to eq(nil)
|
|
1825
1690
|
end
|
|
1826
1691
|
end
|
|
1827
1692
|
|
|
1828
|
-
context
|
|
1829
|
-
|
|
1693
|
+
context 'when plucking deeply nested arrays/embedded associations' do
|
|
1830
1694
|
let(:criteria) do
|
|
1831
1695
|
Person.all.tap do |crit|
|
|
1832
1696
|
crit.documents = [
|
|
1833
|
-
Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
1834
|
-
|
|
1835
|
-
Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
1697
|
+
Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
1698
|
+
{ y: { z: 2 } } ]))) ]),
|
|
1699
|
+
Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
1700
|
+
{ y: { z: 2 } } ]))) ]),
|
|
1701
|
+
Person.create!(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
1702
|
+
{ y: { z: 3 } } ]))) ])
|
|
1836
1703
|
]
|
|
1837
1704
|
end
|
|
1838
1705
|
end
|
|
1839
1706
|
|
|
1840
1707
|
let(:plucked) do
|
|
1841
|
-
context.pluck(
|
|
1708
|
+
context.pluck('addresses.code.deepest.array.y.z')
|
|
1842
1709
|
end
|
|
1843
1710
|
|
|
1844
|
-
it
|
|
1711
|
+
it 'returns the correct hash' do
|
|
1845
1712
|
expect(plucked).to eq([
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
end
|
|
1849
|
-
end
|
|
1850
|
-
|
|
1851
|
-
context 'when plucking a dynamic attribute' do
|
|
1852
|
-
let(:criteria) do
|
|
1853
|
-
Band.all.tap do |crit|
|
|
1854
|
-
crit.documents = [ Band.create!(name: 'Depeche Mode', mood: 'dark') ]
|
|
1855
|
-
end
|
|
1856
|
-
end
|
|
1857
|
-
|
|
1858
|
-
it 'returns the value from the attributes' do
|
|
1859
|
-
expect(context.pluck(:mood)).to eq([ 'dark' ])
|
|
1860
|
-
end
|
|
1861
|
-
end
|
|
1862
|
-
|
|
1863
|
-
context 'when the field name is a method name' do
|
|
1864
|
-
let!(:person) do
|
|
1865
|
-
Person.create!(ssn: 'secret-ssn')
|
|
1866
|
-
end
|
|
1867
|
-
|
|
1868
|
-
let!(:address) do
|
|
1869
|
-
person.addresses.create!(street: 'hobrecht')
|
|
1870
|
-
end
|
|
1871
|
-
|
|
1872
|
-
let(:criteria) do
|
|
1873
|
-
Address.all.tap do |crit|
|
|
1874
|
-
crit.documents = [ address ]
|
|
1875
|
-
end
|
|
1876
|
-
end
|
|
1877
|
-
|
|
1878
|
-
it 'does not call the method' do
|
|
1879
|
-
expect(address).not_to receive(:destroy)
|
|
1880
|
-
expect(context.pluck(:destroy)).to eq([ nil ])
|
|
1881
|
-
end
|
|
1882
|
-
|
|
1883
|
-
it 'does not return the attributes hash' do
|
|
1884
|
-
expect(context.pluck(:attributes)).to eq([ nil ])
|
|
1885
|
-
end
|
|
1886
|
-
|
|
1887
|
-
it 'does not traverse to the parent document' do
|
|
1888
|
-
expect(context.pluck('_root.ssn')).to eq([ nil ])
|
|
1889
|
-
end
|
|
1890
|
-
|
|
1891
|
-
it 'does not destroy the parent document' do
|
|
1892
|
-
expect(context.pluck('_root.destroy')).to eq([ nil ])
|
|
1893
|
-
expect(Person.where(_id: person.id).count).to eq(1)
|
|
1894
|
-
end
|
|
1895
|
-
end
|
|
1896
|
-
|
|
1897
|
-
context 'when plucking a belongs_to association' do
|
|
1898
|
-
let!(:band) do
|
|
1899
|
-
Band.create!(name: 'Depeche Mode')
|
|
1900
|
-
end
|
|
1901
|
-
|
|
1902
|
-
let!(:artist) do
|
|
1903
|
-
Artist.create!(band: band)
|
|
1904
|
-
end
|
|
1905
|
-
|
|
1906
|
-
let(:criteria) do
|
|
1907
|
-
Artist.all.tap do |crit|
|
|
1908
|
-
crit.documents = [ artist ]
|
|
1909
|
-
end
|
|
1910
|
-
end
|
|
1911
|
-
|
|
1912
|
-
it 'traverses to the associated document' do
|
|
1913
|
-
expect(context.pluck('band.name')).to eq([ 'Depeche Mode' ])
|
|
1914
|
-
end
|
|
1915
|
-
|
|
1916
|
-
it 'returns the document for the association name' do
|
|
1917
|
-
expect(context.pluck(:band)).to eq([ band ])
|
|
1918
|
-
end
|
|
1919
|
-
|
|
1920
|
-
it 'returns the id for the foreign key' do
|
|
1921
|
-
expect(context.pluck(:band_id)).to eq([ band.id ])
|
|
1922
|
-
end
|
|
1923
|
-
end
|
|
1924
|
-
|
|
1925
|
-
context 'when plucking the foreign key of a many to many association' do
|
|
1926
|
-
let!(:preference) do
|
|
1927
|
-
Preference.create!(name: 'nature')
|
|
1928
|
-
end
|
|
1929
|
-
|
|
1930
|
-
let!(:person) do
|
|
1931
|
-
Person.create!(preferences: [ preference ])
|
|
1932
|
-
end
|
|
1933
|
-
|
|
1934
|
-
let(:criteria) do
|
|
1935
|
-
Person.all.tap do |crit|
|
|
1936
|
-
crit.documents = [ person ]
|
|
1937
|
-
end
|
|
1938
|
-
end
|
|
1939
|
-
|
|
1940
|
-
it 'returns the stored ids' do
|
|
1941
|
-
expect(context.pluck(:preference_ids)).to eq([ [ preference.id ] ])
|
|
1942
|
-
end
|
|
1943
|
-
end
|
|
1944
|
-
|
|
1945
|
-
context 'when the field path has an empty segment' do
|
|
1946
|
-
let!(:band) do
|
|
1947
|
-
Band.create!(name: 'Depeche Mode', label: Label.new(name: 'Mute'))
|
|
1948
|
-
end
|
|
1949
|
-
|
|
1950
|
-
let(:criteria) do
|
|
1951
|
-
Band.all.tap do |crit|
|
|
1952
|
-
crit.documents = [ band ]
|
|
1953
|
-
end
|
|
1954
|
-
end
|
|
1955
|
-
|
|
1956
|
-
it 'returns nil' do
|
|
1957
|
-
expect(context.pluck('label..name')).to eq([ nil ])
|
|
1713
|
+
[ [ 1, 2 ] ], [ [ 1, 2 ] ], [ [ 1, 3 ] ]
|
|
1714
|
+
])
|
|
1958
1715
|
end
|
|
1959
1716
|
end
|
|
1960
1717
|
end
|
|
1961
1718
|
|
|
1962
|
-
describe
|
|
1963
|
-
|
|
1719
|
+
describe '#pick' do
|
|
1964
1720
|
let(:depeche) do
|
|
1965
|
-
Band.create!(name:
|
|
1721
|
+
Band.create!(name: 'Depeche Mode', likes: 3)
|
|
1966
1722
|
end
|
|
1967
1723
|
|
|
1968
1724
|
let(:tool) do
|
|
1969
|
-
Band.create!(name:
|
|
1725
|
+
Band.create!(name: 'Tool', likes: 3)
|
|
1970
1726
|
end
|
|
1971
1727
|
|
|
1972
1728
|
let(:criteria) do
|
|
@@ -1979,30 +1735,27 @@ describe Mongoid::Contextual::Memory do
|
|
|
1979
1735
|
described_class.new(criteria)
|
|
1980
1736
|
end
|
|
1981
1737
|
|
|
1982
|
-
context
|
|
1983
|
-
|
|
1738
|
+
context 'when picking a field' do
|
|
1984
1739
|
let(:picked) do
|
|
1985
1740
|
context.pick(:name)
|
|
1986
1741
|
end
|
|
1987
1742
|
|
|
1988
|
-
it
|
|
1989
|
-
expect(picked).to eq(
|
|
1743
|
+
it 'returns one element' do
|
|
1744
|
+
expect(picked).to eq('Depeche Mode')
|
|
1990
1745
|
end
|
|
1991
1746
|
end
|
|
1992
1747
|
|
|
1993
|
-
context
|
|
1994
|
-
|
|
1748
|
+
context 'when picking multiple fields' do
|
|
1995
1749
|
let(:picked) do
|
|
1996
1750
|
context.pick(:name, :likes)
|
|
1997
1751
|
end
|
|
1998
1752
|
|
|
1999
|
-
it
|
|
2000
|
-
expect(picked).to eq([
|
|
1753
|
+
it 'returns an array' do
|
|
1754
|
+
expect(picked).to eq([ 'Depeche Mode', 3 ])
|
|
2001
1755
|
end
|
|
2002
1756
|
end
|
|
2003
1757
|
|
|
2004
|
-
context
|
|
2005
|
-
|
|
1758
|
+
context 'when no documents to pick' do
|
|
2006
1759
|
let(:criteria) do
|
|
2007
1760
|
Band.all.tap do |crit|
|
|
2008
1761
|
crit.documents = []
|
|
@@ -2013,62 +1766,46 @@ describe Mongoid::Contextual::Memory do
|
|
|
2013
1766
|
context.pick(:name)
|
|
2014
1767
|
end
|
|
2015
1768
|
|
|
2016
|
-
it
|
|
1769
|
+
it 'returns nil' do
|
|
2017
1770
|
expect(picked).to be_nil
|
|
2018
1771
|
end
|
|
2019
1772
|
end
|
|
2020
|
-
|
|
2021
|
-
context 'when the field name is a method name' do
|
|
2022
|
-
let!(:person) do
|
|
2023
|
-
Person.create!(ssn: 'secret-ssn')
|
|
2024
|
-
end
|
|
2025
|
-
|
|
2026
|
-
let!(:address) do
|
|
2027
|
-
person.addresses.create!(street: 'hobrecht')
|
|
2028
|
-
end
|
|
2029
|
-
|
|
2030
|
-
let(:criteria) do
|
|
2031
|
-
Address.all.tap do |crit|
|
|
2032
|
-
crit.documents = [ address ]
|
|
2033
|
-
end
|
|
2034
|
-
end
|
|
2035
|
-
|
|
2036
|
-
it 'does not call the method' do
|
|
2037
|
-
expect(address).not_to receive(:destroy)
|
|
2038
|
-
expect(context.pick(:destroy)).to be_nil
|
|
2039
|
-
end
|
|
2040
|
-
end
|
|
2041
1773
|
end
|
|
2042
1774
|
|
|
2043
|
-
describe
|
|
2044
|
-
let(:fans1) { [ Fanatic.new(age:1), Fanatic.new(age:2) ] }
|
|
2045
|
-
let(:fans2) { [ Fanatic.new(age:1), Fanatic.new(age:2) ] }
|
|
2046
|
-
let(:fans3) { [ Fanatic.new(age:1), Fanatic.new(age:3) ] }
|
|
1775
|
+
describe '#tally' do
|
|
1776
|
+
let(:fans1) { [ Fanatic.new(age: 1), Fanatic.new(age: 2) ] }
|
|
1777
|
+
let(:fans2) { [ Fanatic.new(age: 1), Fanatic.new(age: 2) ] }
|
|
1778
|
+
let(:fans3) { [ Fanatic.new(age: 1), Fanatic.new(age: 3) ] }
|
|
2047
1779
|
|
|
2048
|
-
let(:genres1) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 3 } ]}
|
|
2049
|
-
let(:genres2) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 4 } ]}
|
|
2050
|
-
let(:genres3) { [ { x: 1, y: { z: 1 } }, { x: 3, y: { z: 3 } }, { y: 5 } ]}
|
|
1780
|
+
let(:genres1) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 3 } ] }
|
|
1781
|
+
let(:genres2) { [ { x: 1, y: { z: 1 } }, { x: 2, y: { z: 2 } }, { y: 4 } ] }
|
|
1782
|
+
let(:genres3) { [ { x: 1, y: { z: 1 } }, { x: 3, y: { z: 3 } }, { y: 5 } ] }
|
|
2051
1783
|
|
|
2052
|
-
let(:label1) { Label.new(name:
|
|
2053
|
-
let(:label2) { Label.new(name:
|
|
2054
|
-
let(:label3) { Label.new(name:
|
|
1784
|
+
let(:label1) { Label.new(name: 'Atlantic') }
|
|
1785
|
+
let(:label2) { Label.new(name: 'Atlantic') }
|
|
1786
|
+
let(:label3) { Label.new(name: 'Columbia') }
|
|
2055
1787
|
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
let(:
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
let(:
|
|
1788
|
+
let(:band1) do
|
|
1789
|
+
Band.new(origin: 'tally', name: 'Depeche Mode', years: 30, sales: '1E2', label: label1, genres: genres1)
|
|
1790
|
+
end
|
|
1791
|
+
let(:band2) do
|
|
1792
|
+
Band.new(origin: 'tally', name: 'New Order', years: 30, sales: '2E3', label: label2, genres: genres2)
|
|
1793
|
+
end
|
|
1794
|
+
let(:band3) do
|
|
1795
|
+
Band.new(origin: 'tally', name: '10,000 Maniacs', years: 30, sales: '1E2', label: label3, genres: genres3)
|
|
1796
|
+
end
|
|
1797
|
+
let(:band4) { Band.new(origin: 'tally2', fanatics: fans1, genres: [ 1, 2 ]) }
|
|
1798
|
+
let(:band5) { Band.new(origin: 'tally2', fanatics: fans2, genres: [ 1, 2 ]) }
|
|
1799
|
+
let(:band6) { Band.new(origin: 'tally2', fanatics: fans3, genres: [ 1, 3 ]) }
|
|
2063
1800
|
|
|
2064
1801
|
let(:criteria) do
|
|
2065
|
-
Band.where(origin:
|
|
1802
|
+
Band.where(origin: 'tally').all.tap do |crit|
|
|
2066
1803
|
crit.documents = [ band1, band2, band3 ]
|
|
2067
1804
|
end
|
|
2068
1805
|
end
|
|
2069
1806
|
|
|
2070
1807
|
let(:criteria2) do
|
|
2071
|
-
Band.where(origin:
|
|
1808
|
+
Band.where(origin: 'tally2').tap do |crit|
|
|
2072
1809
|
crit.documents = [ band4, band5, band6 ]
|
|
2073
1810
|
end
|
|
2074
1811
|
end
|
|
@@ -2081,40 +1818,45 @@ describe Mongoid::Contextual::Memory do
|
|
|
2081
1818
|
described_class.new(criteria2)
|
|
2082
1819
|
end
|
|
2083
1820
|
|
|
2084
|
-
context
|
|
1821
|
+
context 'when tallying a string' do
|
|
2085
1822
|
let(:tally) do
|
|
2086
1823
|
context.tally(:name)
|
|
2087
1824
|
end
|
|
2088
1825
|
|
|
2089
|
-
it
|
|
2090
|
-
expect(tally).to eq(
|
|
1826
|
+
it 'returns the correct hash' do
|
|
1827
|
+
expect(tally).to eq('Depeche Mode' => 1, 'New Order' => 1, '10,000 Maniacs' => 1)
|
|
2091
1828
|
end
|
|
2092
1829
|
end
|
|
2093
1830
|
|
|
2094
|
-
context
|
|
1831
|
+
context 'using an aliased field' do
|
|
2095
1832
|
let(:tally) do
|
|
2096
1833
|
context.tally(:years)
|
|
2097
1834
|
end
|
|
2098
1835
|
|
|
2099
|
-
it
|
|
1836
|
+
it 'returns the correct hash' do
|
|
2100
1837
|
expect(tally).to eq(30 => 3)
|
|
2101
1838
|
end
|
|
2102
1839
|
end
|
|
2103
1840
|
|
|
2104
|
-
context
|
|
1841
|
+
context 'when tallying a demongoizable field' do
|
|
2105
1842
|
let(:tally) do
|
|
2106
1843
|
context.tally(:sales)
|
|
2107
1844
|
end
|
|
2108
1845
|
|
|
2109
|
-
it
|
|
2110
|
-
expect(tally).to eq(BigDecimal(
|
|
1846
|
+
it 'returns the correct hash' do
|
|
1847
|
+
expect(tally).to eq(BigDecimal('1E2') => 2, BigDecimal('2E3') => 1)
|
|
2111
1848
|
end
|
|
2112
1849
|
end
|
|
2113
1850
|
|
|
2114
|
-
context
|
|
1851
|
+
context 'when tallying a localized field' do
|
|
2115
1852
|
with_default_i18n_configs
|
|
2116
1853
|
|
|
2117
1854
|
let(:d1) { Dictionary.new(description: 'en1') }
|
|
1855
|
+
let(:criteria) do
|
|
1856
|
+
Dictionary.all.tap do |crit|
|
|
1857
|
+
crit.documents = [ d1, d2, d3, d4 ]
|
|
1858
|
+
end
|
|
1859
|
+
end
|
|
2118
1860
|
let(:d2) { Dictionary.new(description: 'en1') }
|
|
2119
1861
|
let(:d3) { Dictionary.new(description: 'en1') }
|
|
2120
1862
|
let(:d4) { Dictionary.new(description: 'en2') }
|
|
@@ -2133,57 +1875,56 @@ describe Mongoid::Contextual::Memory do
|
|
|
2133
1875
|
I18n.locale = :en
|
|
2134
1876
|
end
|
|
2135
1877
|
|
|
2136
|
-
|
|
2137
|
-
Dictionary.all.tap do |crit|
|
|
2138
|
-
crit.documents = [ d1, d2, d3, d4 ]
|
|
2139
|
-
end
|
|
2140
|
-
end
|
|
2141
|
-
|
|
2142
|
-
context "when getting the demongoized field" do
|
|
1878
|
+
context 'when getting the demongoized field' do
|
|
2143
1879
|
let(:tallied) do
|
|
2144
1880
|
context.tally(:description)
|
|
2145
1881
|
end
|
|
2146
1882
|
|
|
2147
|
-
it
|
|
2148
|
-
expect(tallied).to eq(
|
|
1883
|
+
it 'returns the translation for the current locale' do
|
|
1884
|
+
expect(tallied).to eq('en1' => 3, 'en2' => 1)
|
|
2149
1885
|
end
|
|
2150
1886
|
end
|
|
2151
1887
|
|
|
2152
|
-
context
|
|
1888
|
+
context 'when getting a specific locale' do
|
|
2153
1889
|
let(:tallied) do
|
|
2154
|
-
context.tally(
|
|
1890
|
+
context.tally('description.de')
|
|
2155
1891
|
end
|
|
2156
1892
|
|
|
2157
|
-
it
|
|
2158
|
-
expect(tallied).to eq(
|
|
1893
|
+
it 'returns the translation for the the specific locale' do
|
|
1894
|
+
expect(tallied).to eq('de1' => 2, 'de2' => 1, 'de3' => 1)
|
|
2159
1895
|
end
|
|
2160
1896
|
end
|
|
2161
1897
|
|
|
2162
|
-
context
|
|
1898
|
+
context 'when getting the full hash' do
|
|
2163
1899
|
let(:tallied) do
|
|
2164
|
-
context.tally(
|
|
1900
|
+
context.tally('description_translations')
|
|
2165
1901
|
end
|
|
2166
1902
|
|
|
2167
|
-
it
|
|
1903
|
+
it 'returns the correct hash' do
|
|
2168
1904
|
expect(tallied).to eq(
|
|
2169
|
-
{
|
|
2170
|
-
{
|
|
2171
|
-
{
|
|
1905
|
+
{ 'de' => 'de1', 'en' => 'en1' } => 2,
|
|
1906
|
+
{ 'de' => 'de2', 'en' => 'en1' } => 1,
|
|
1907
|
+
{ 'de' => 'de3', 'en' => 'en2' } => 1
|
|
2172
1908
|
)
|
|
2173
1909
|
end
|
|
2174
1910
|
end
|
|
2175
1911
|
end
|
|
2176
1912
|
|
|
2177
|
-
context
|
|
1913
|
+
context 'when tallying an embedded localized field' do
|
|
2178
1914
|
with_default_i18n_configs
|
|
2179
1915
|
|
|
2180
1916
|
let(:person1) { Person.create!(addresses: [ address1a, address1b ]) }
|
|
1917
|
+
let(:criteria) do
|
|
1918
|
+
Person.all.tap do |crit|
|
|
1919
|
+
crit.documents = [ person1, person2 ]
|
|
1920
|
+
end
|
|
1921
|
+
end
|
|
2181
1922
|
let(:person2) { Person.create!(addresses: [ address2a, address2b ]) }
|
|
2182
1923
|
|
|
2183
|
-
let(:address1a) { Address.new(name:
|
|
2184
|
-
let(:address1b) { Address.new(name:
|
|
2185
|
-
let(:address2a) { Address.new(name:
|
|
2186
|
-
let(:address2b) { Address.new(name:
|
|
1924
|
+
let(:address1a) { Address.new(name: 'en1') }
|
|
1925
|
+
let(:address1b) { Address.new(name: 'en2') }
|
|
1926
|
+
let(:address2a) { Address.new(name: 'en1') }
|
|
1927
|
+
let(:address2b) { Address.new(name: 'en3') }
|
|
2187
1928
|
|
|
2188
1929
|
before do
|
|
2189
1930
|
I18n.locale = :en
|
|
@@ -2192,153 +1933,141 @@ describe Mongoid::Contextual::Memory do
|
|
|
2192
1933
|
address2a
|
|
2193
1934
|
address2b
|
|
2194
1935
|
I18n.locale = :de
|
|
2195
|
-
address1a.name =
|
|
2196
|
-
address1b.name =
|
|
2197
|
-
address2a.name =
|
|
2198
|
-
address2b.name =
|
|
1936
|
+
address1a.name = 'de1'
|
|
1937
|
+
address1b.name = 'de2'
|
|
1938
|
+
address2a.name = 'de1'
|
|
1939
|
+
address2b.name = 'de3'
|
|
2199
1940
|
person1
|
|
2200
1941
|
person2
|
|
2201
1942
|
I18n.locale = :en
|
|
2202
1943
|
end
|
|
2203
1944
|
|
|
2204
|
-
|
|
2205
|
-
Person.all.tap do |crit|
|
|
2206
|
-
crit.documents = [ person1, person2 ]
|
|
2207
|
-
end
|
|
2208
|
-
end
|
|
2209
|
-
|
|
2210
|
-
context "when getting the demongoized field" do
|
|
1945
|
+
context 'when getting the demongoized field' do
|
|
2211
1946
|
let(:tallied) do
|
|
2212
|
-
context.tally(
|
|
1947
|
+
context.tally('addresses.name')
|
|
2213
1948
|
end
|
|
2214
1949
|
|
|
2215
|
-
it
|
|
1950
|
+
it 'returns the translation for the current locale' do
|
|
2216
1951
|
expect(tallied).to eq(
|
|
2217
|
-
[
|
|
2218
|
-
[
|
|
1952
|
+
%w[en1 en2] => 1,
|
|
1953
|
+
%w[en1 en3] => 1
|
|
2219
1954
|
)
|
|
2220
1955
|
end
|
|
2221
1956
|
end
|
|
2222
1957
|
|
|
2223
|
-
context
|
|
1958
|
+
context 'when getting a specific locale' do
|
|
2224
1959
|
let(:tallied) do
|
|
2225
|
-
context.tally(
|
|
1960
|
+
context.tally('addresses.name.de')
|
|
2226
1961
|
end
|
|
2227
1962
|
|
|
2228
|
-
it
|
|
1963
|
+
it 'returns the translation for the the specific locale' do
|
|
2229
1964
|
expect(tallied).to eq(
|
|
2230
|
-
[
|
|
2231
|
-
[
|
|
1965
|
+
%w[de1 de2] => 1,
|
|
1966
|
+
%w[de1 de3] => 1
|
|
2232
1967
|
)
|
|
2233
1968
|
end
|
|
2234
1969
|
end
|
|
2235
1970
|
|
|
2236
|
-
context
|
|
1971
|
+
context 'when getting the full hash' do
|
|
2237
1972
|
let(:tallied) do
|
|
2238
|
-
context.tally(
|
|
1973
|
+
context.tally('addresses.name_translations')
|
|
2239
1974
|
end
|
|
2240
1975
|
|
|
2241
|
-
it
|
|
1976
|
+
it 'returns the correct hash' do
|
|
2242
1977
|
expect(tallied).to eq(
|
|
2243
|
-
[{
|
|
2244
|
-
[{
|
|
1978
|
+
[ { 'de' => 'de1', 'en' => 'en1' }, { 'de' => 'de2', 'en' => 'en2' } ] => 1,
|
|
1979
|
+
[ { 'de' => 'de1', 'en' => 'en1' }, { 'de' => 'de3', 'en' => 'en3' } ] => 1
|
|
2245
1980
|
)
|
|
2246
1981
|
end
|
|
2247
1982
|
end
|
|
2248
1983
|
end
|
|
2249
1984
|
|
|
2250
|
-
context
|
|
1985
|
+
context 'when tallying an embedded field' do
|
|
2251
1986
|
let(:tally) do
|
|
2252
|
-
context.tally(
|
|
1987
|
+
context.tally('label.name')
|
|
2253
1988
|
end
|
|
2254
1989
|
|
|
2255
|
-
it
|
|
2256
|
-
expect(tally).to eq(
|
|
1990
|
+
it 'returns the correct hash' do
|
|
1991
|
+
expect(tally).to eq('Atlantic' => 2, 'Columbia' => 1)
|
|
2257
1992
|
end
|
|
2258
1993
|
end
|
|
2259
1994
|
|
|
2260
|
-
context
|
|
2261
|
-
|
|
1995
|
+
context 'when tallying an element in an embeds_many field' do
|
|
2262
1996
|
let(:tally) do
|
|
2263
|
-
context2.tally(
|
|
1997
|
+
context2.tally('fanatics.age')
|
|
2264
1998
|
end
|
|
2265
1999
|
|
|
2266
|
-
it
|
|
2000
|
+
it 'returns the correct hash' do
|
|
2267
2001
|
expect(tally).to eq(
|
|
2268
|
-
[1, 2] => 2,
|
|
2269
|
-
[1, 3] => 1
|
|
2002
|
+
[ 1, 2 ] => 2,
|
|
2003
|
+
[ 1, 3 ] => 1
|
|
2270
2004
|
)
|
|
2271
2005
|
end
|
|
2272
2006
|
end
|
|
2273
2007
|
|
|
2274
|
-
context
|
|
2275
|
-
|
|
2008
|
+
context 'when tallying an embeds_many field' do
|
|
2276
2009
|
let(:tally) do
|
|
2277
|
-
context2.tally(
|
|
2010
|
+
context2.tally('fanatics')
|
|
2278
2011
|
end
|
|
2279
2012
|
|
|
2280
|
-
it
|
|
2013
|
+
it 'returns the correct hash' do
|
|
2281
2014
|
expect(tally).to eq(
|
|
2282
2015
|
fans1 => 1,
|
|
2283
2016
|
fans2 => 1,
|
|
2284
|
-
fans3 => 1
|
|
2017
|
+
fans3 => 1
|
|
2285
2018
|
)
|
|
2286
2019
|
end
|
|
2287
2020
|
end
|
|
2288
2021
|
|
|
2289
|
-
context
|
|
2290
|
-
|
|
2022
|
+
context 'when tallying a field of type array' do
|
|
2291
2023
|
let(:tally) do
|
|
2292
|
-
context2.tally(
|
|
2024
|
+
context2.tally('genres')
|
|
2293
2025
|
end
|
|
2294
2026
|
|
|
2295
|
-
it
|
|
2027
|
+
it 'returns the correct hash' do
|
|
2296
2028
|
expect(tally).to eq(
|
|
2297
|
-
[1, 2] => 2,
|
|
2298
|
-
[1, 3] => 1
|
|
2029
|
+
[ 1, 2 ] => 2,
|
|
2030
|
+
[ 1, 3 ] => 1
|
|
2299
2031
|
)
|
|
2300
2032
|
end
|
|
2301
2033
|
end
|
|
2302
2034
|
|
|
2303
|
-
context
|
|
2304
|
-
|
|
2035
|
+
context 'when tallying an element from an array of hashes' do
|
|
2305
2036
|
let(:tally) do
|
|
2306
|
-
context.tally(
|
|
2037
|
+
context.tally('genres.x')
|
|
2307
2038
|
end
|
|
2308
2039
|
|
|
2309
|
-
it
|
|
2040
|
+
it 'returns the correct hash without the nil keys' do
|
|
2310
2041
|
expect(tally).to eq(
|
|
2311
|
-
[1, 2] => 2,
|
|
2312
|
-
[1, 3] => 1
|
|
2042
|
+
[ 1, 2 ] => 2,
|
|
2043
|
+
[ 1, 3 ] => 1
|
|
2313
2044
|
)
|
|
2314
2045
|
end
|
|
2315
2046
|
end
|
|
2316
2047
|
|
|
2317
|
-
context
|
|
2318
|
-
|
|
2319
|
-
let(:band4) { Band.new(origin: "tally", genres: [ { x: 1 }, {x: 1} ] ) }
|
|
2048
|
+
context 'when tallying an element from an array of hashes; with duplicate' do
|
|
2049
|
+
let(:band4) { Band.new(origin: 'tally', genres: [ { x: 1 }, { x: 1 } ]) }
|
|
2320
2050
|
|
|
2321
2051
|
let(:criteria) do
|
|
2322
|
-
Band.where(origin:
|
|
2052
|
+
Band.where(origin: 'tally').all.tap do |crit|
|
|
2323
2053
|
crit.documents = [ band1, band2, band3, band4 ]
|
|
2324
2054
|
end
|
|
2325
2055
|
end
|
|
2326
2056
|
|
|
2327
2057
|
let(:tally) do
|
|
2328
|
-
context.tally(
|
|
2058
|
+
context.tally('genres.x')
|
|
2329
2059
|
end
|
|
2330
2060
|
|
|
2331
|
-
it
|
|
2061
|
+
it 'returns the correct hash without the nil keys' do
|
|
2332
2062
|
expect(tally).to eq(
|
|
2333
|
-
[1, 2] => 2,
|
|
2334
|
-
[1, 3] => 1,
|
|
2335
|
-
[1, 1] => 1
|
|
2063
|
+
[ 1, 2 ] => 2,
|
|
2064
|
+
[ 1, 3 ] => 1,
|
|
2065
|
+
[ 1, 1 ] => 1
|
|
2336
2066
|
)
|
|
2337
2067
|
end
|
|
2338
2068
|
end
|
|
2339
2069
|
|
|
2340
|
-
context
|
|
2341
|
-
|
|
2070
|
+
context 'when tallying an aliased field of type array' do
|
|
2342
2071
|
let(:person1) { Person.new(array: [ 1, 2 ]) }
|
|
2343
2072
|
let(:person2) { Person.new(array: [ 1, 3 ]) }
|
|
2344
2073
|
|
|
@@ -2349,50 +2078,56 @@ describe Mongoid::Contextual::Memory do
|
|
|
2349
2078
|
end
|
|
2350
2079
|
|
|
2351
2080
|
let(:tally) do
|
|
2352
|
-
context.tally(
|
|
2081
|
+
context.tally('array')
|
|
2353
2082
|
end
|
|
2354
2083
|
|
|
2355
|
-
it
|
|
2084
|
+
it 'returns the correct hash' do
|
|
2356
2085
|
expect(tally).to eq(
|
|
2357
|
-
[1, 2] => 1,
|
|
2358
|
-
[1, 3] => 1
|
|
2086
|
+
[ 1, 2 ] => 1,
|
|
2087
|
+
[ 1, 3 ] => 1
|
|
2359
2088
|
)
|
|
2360
2089
|
end
|
|
2361
2090
|
end
|
|
2362
2091
|
|
|
2363
|
-
context
|
|
2364
|
-
|
|
2092
|
+
context 'when going multiple levels deep in arrays' do
|
|
2365
2093
|
let(:tally) do
|
|
2366
|
-
context.tally(
|
|
2094
|
+
context.tally('genres.y.z')
|
|
2367
2095
|
end
|
|
2368
2096
|
|
|
2369
|
-
it
|
|
2097
|
+
it 'returns the correct hash' do
|
|
2370
2098
|
expect(tally).to eq(
|
|
2371
|
-
[1, 2] => 2,
|
|
2372
|
-
[1, 3] => 1
|
|
2099
|
+
[ 1, 2 ] => 2,
|
|
2100
|
+
[ 1, 3 ] => 1
|
|
2373
2101
|
)
|
|
2374
2102
|
end
|
|
2375
2103
|
end
|
|
2376
2104
|
|
|
2377
|
-
context
|
|
2378
|
-
|
|
2105
|
+
context 'when going multiple levels deep in an array' do
|
|
2379
2106
|
let(:tally) do
|
|
2380
|
-
context.tally(
|
|
2107
|
+
context.tally('genres.y.z')
|
|
2381
2108
|
end
|
|
2382
2109
|
|
|
2383
|
-
it
|
|
2110
|
+
it 'returns the correct hash' do
|
|
2384
2111
|
expect(tally).to eq(
|
|
2385
|
-
[1, 2] => 2,
|
|
2386
|
-
[1, 3] => 1
|
|
2112
|
+
[ 1, 2 ] => 2,
|
|
2113
|
+
[ 1, 3 ] => 1
|
|
2387
2114
|
)
|
|
2388
2115
|
end
|
|
2389
2116
|
end
|
|
2390
2117
|
|
|
2391
|
-
context
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2118
|
+
context 'when tallying deeply nested arrays/embedded associations' do
|
|
2119
|
+
let(:person1) do
|
|
2120
|
+
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2121
|
+
{ y: { z: 2 } } ]))) ])
|
|
2122
|
+
end
|
|
2123
|
+
let(:person2) do
|
|
2124
|
+
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2125
|
+
{ y: { z: 2 } } ]))) ])
|
|
2126
|
+
end
|
|
2127
|
+
let(:person3) do
|
|
2128
|
+
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2129
|
+
{ y: { z: 3 } } ]))) ])
|
|
2130
|
+
end
|
|
2396
2131
|
|
|
2397
2132
|
let(:criteria) do
|
|
2398
2133
|
Person.all.tap do |crit|
|
|
@@ -2401,10 +2136,10 @@ describe Mongoid::Contextual::Memory do
|
|
|
2401
2136
|
end
|
|
2402
2137
|
|
|
2403
2138
|
let(:tally) do
|
|
2404
|
-
context.tally(
|
|
2139
|
+
context.tally('addresses.code.deepest.array.y.z')
|
|
2405
2140
|
end
|
|
2406
2141
|
|
|
2407
|
-
it
|
|
2142
|
+
it 'returns the correct hash' do
|
|
2408
2143
|
expect(tally).to eq(
|
|
2409
2144
|
[ [ 1, 2 ] ] => 2,
|
|
2410
2145
|
[ [ 1, 3 ] ] => 1
|
|
@@ -2412,21 +2147,23 @@ describe Mongoid::Contextual::Memory do
|
|
|
2412
2147
|
end
|
|
2413
2148
|
end
|
|
2414
2149
|
|
|
2415
|
-
context
|
|
2416
|
-
|
|
2150
|
+
context 'when tallying deeply nested arrays/embedded associations' do
|
|
2417
2151
|
let(:person1) do
|
|
2418
2152
|
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))),
|
|
2419
|
-
|
|
2153
|
+
Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2154
|
+
{ y: { z: 2 } } ]))) ])
|
|
2420
2155
|
end
|
|
2421
2156
|
|
|
2422
2157
|
let(:person2) do
|
|
2423
2158
|
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 2 } } ]))),
|
|
2424
|
-
|
|
2159
|
+
Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2160
|
+
{ y: { z: 2 } } ]))) ])
|
|
2425
2161
|
end
|
|
2426
2162
|
|
|
2427
2163
|
let(:person3) do
|
|
2428
2164
|
Person.new(addresses: [ Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } }, { y: { z: 3 } } ]))),
|
|
2429
|
-
|
|
2165
|
+
Address.new(code: Code.new(deepest: Deepest.new(array: [ { y: { z: 1 } },
|
|
2166
|
+
{ y: { z: 3 } } ]))) ])
|
|
2430
2167
|
end
|
|
2431
2168
|
|
|
2432
2169
|
let(:criteria) do
|
|
@@ -2436,10 +2173,10 @@ describe Mongoid::Contextual::Memory do
|
|
|
2436
2173
|
end
|
|
2437
2174
|
|
|
2438
2175
|
let(:tally) do
|
|
2439
|
-
context.tally(
|
|
2176
|
+
context.tally('addresses.code.deepest.array.y.z')
|
|
2440
2177
|
end
|
|
2441
2178
|
|
|
2442
|
-
it
|
|
2179
|
+
it 'returns the correct hash' do
|
|
2443
2180
|
expect(tally).to eq(
|
|
2444
2181
|
[ [ 1, 2 ], [ 1, 2 ] ] => 2,
|
|
2445
2182
|
[ [ 1, 3 ], [ 1, 3 ] ] => 1
|
|
@@ -2447,12 +2184,11 @@ describe Mongoid::Contextual::Memory do
|
|
|
2447
2184
|
end
|
|
2448
2185
|
end
|
|
2449
2186
|
|
|
2450
|
-
context
|
|
2451
|
-
|
|
2187
|
+
context 'when some keys are missing' do
|
|
2452
2188
|
let(:criteria) do
|
|
2453
|
-
Band.where(origin:
|
|
2189
|
+
Band.where(origin: 'tally').all.tap do |crit|
|
|
2454
2190
|
crit.documents = [ band1, band2, band3 ]
|
|
2455
|
-
3.times{ crit.documents << Band.new(origin:
|
|
2191
|
+
3.times { crit.documents << Band.new(origin: 'tally') }
|
|
2456
2192
|
end
|
|
2457
2193
|
end
|
|
2458
2194
|
|
|
@@ -2460,20 +2196,26 @@ describe Mongoid::Contextual::Memory do
|
|
|
2460
2196
|
context.tally(:name)
|
|
2461
2197
|
end
|
|
2462
2198
|
|
|
2463
|
-
it
|
|
2199
|
+
it 'returns the correct hash' do
|
|
2464
2200
|
expect(tally).to eq(
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2201
|
+
'Depeche Mode' => 1,
|
|
2202
|
+
'New Order' => 1,
|
|
2203
|
+
'10,000 Maniacs' => 1,
|
|
2468
2204
|
nil => 3
|
|
2469
2205
|
)
|
|
2470
2206
|
end
|
|
2471
2207
|
end
|
|
2472
2208
|
|
|
2473
|
-
context
|
|
2474
|
-
let(:person1)
|
|
2475
|
-
|
|
2476
|
-
|
|
2209
|
+
context 'when the first element is an embeds_one' do
|
|
2210
|
+
let(:person1) do
|
|
2211
|
+
Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ]))
|
|
2212
|
+
end
|
|
2213
|
+
let(:person2) do
|
|
2214
|
+
Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 2) ]))
|
|
2215
|
+
end
|
|
2216
|
+
let(:person3) do
|
|
2217
|
+
Person.create!(name: Name.new(translations: [ Translation.new(language: 1), Translation.new(language: 3) ]))
|
|
2218
|
+
end
|
|
2477
2219
|
|
|
2478
2220
|
let(:criteria) do
|
|
2479
2221
|
Person.all.tap do |crit|
|
|
@@ -2482,45 +2224,19 @@ describe Mongoid::Contextual::Memory do
|
|
|
2482
2224
|
end
|
|
2483
2225
|
|
|
2484
2226
|
let(:tally) do
|
|
2485
|
-
context.tally(
|
|
2227
|
+
context.tally('name.translations.language')
|
|
2486
2228
|
end
|
|
2487
2229
|
|
|
2488
|
-
it
|
|
2230
|
+
it 'returns the correct hash' do
|
|
2489
2231
|
expect(tally).to eq(
|
|
2490
|
-
[1, 2] => 2,
|
|
2491
|
-
[1, 3] => 1
|
|
2232
|
+
[ 1, 2 ] => 2,
|
|
2233
|
+
[ 1, 3 ] => 1
|
|
2492
2234
|
)
|
|
2493
2235
|
end
|
|
2494
2236
|
end
|
|
2495
|
-
|
|
2496
|
-
context 'when the field name is a method name' do
|
|
2497
|
-
let!(:person) do
|
|
2498
|
-
Person.create!(ssn: 'secret-ssn')
|
|
2499
|
-
end
|
|
2500
|
-
|
|
2501
|
-
let!(:address) do
|
|
2502
|
-
person.addresses.create!(street: 'hobrecht')
|
|
2503
|
-
end
|
|
2504
|
-
|
|
2505
|
-
let(:criteria) do
|
|
2506
|
-
Address.all.tap do |crit|
|
|
2507
|
-
crit.documents = [ address ]
|
|
2508
|
-
end
|
|
2509
|
-
end
|
|
2510
|
-
|
|
2511
|
-
it 'does not call the method' do
|
|
2512
|
-
expect(address).not_to receive(:destroy)
|
|
2513
|
-
expect(context.tally(:destroy)).to eq(nil => 1)
|
|
2514
|
-
end
|
|
2515
|
-
|
|
2516
|
-
it 'does not disclose the parent document fields' do
|
|
2517
|
-
expect(context.tally('_root.ssn')).to eq(nil => 1)
|
|
2518
|
-
end
|
|
2519
|
-
end
|
|
2520
2237
|
end
|
|
2521
2238
|
|
|
2522
2239
|
describe '#inc' do
|
|
2523
|
-
|
|
2524
2240
|
let(:criteria) do
|
|
2525
2241
|
Address.all.tap do |crit|
|
|
2526
2242
|
crit.documents = [ Address.new(number: 1),
|
|
@@ -2534,22 +2250,21 @@ describe Mongoid::Contextual::Memory do
|
|
|
2534
2250
|
end
|
|
2535
2251
|
|
|
2536
2252
|
it 'increases each member' do
|
|
2537
|
-
expect(context.inc(number: 10).collect(&:number)).to eql([11, 12, 13])
|
|
2253
|
+
expect(context.inc(number: 10).collect(&:number)).to eql([ 11, 12, 13 ])
|
|
2538
2254
|
end
|
|
2539
2255
|
end
|
|
2540
2256
|
|
|
2541
|
-
describe
|
|
2542
|
-
|
|
2257
|
+
describe '#skip' do
|
|
2543
2258
|
let(:hobrecht) do
|
|
2544
|
-
Address.new(street:
|
|
2259
|
+
Address.new(street: 'hobrecht')
|
|
2545
2260
|
end
|
|
2546
2261
|
|
|
2547
2262
|
let(:friedel) do
|
|
2548
|
-
Address.new(street:
|
|
2263
|
+
Address.new(street: 'friedel')
|
|
2549
2264
|
end
|
|
2550
2265
|
|
|
2551
2266
|
let(:pfluger) do
|
|
2552
|
-
Address.new(street:
|
|
2267
|
+
Address.new(street: 'pfluger')
|
|
2553
2268
|
end
|
|
2554
2269
|
|
|
2555
2270
|
let(:criteria) do
|
|
@@ -2563,31 +2278,27 @@ describe Mongoid::Contextual::Memory do
|
|
|
2563
2278
|
end
|
|
2564
2279
|
|
|
2565
2280
|
context 'when there is no collation on the criteria' do
|
|
2566
|
-
|
|
2567
2281
|
let!(:skip) do
|
|
2568
2282
|
context.skip(1)
|
|
2569
2283
|
end
|
|
2570
2284
|
|
|
2571
|
-
it
|
|
2285
|
+
it 'returns the context' do
|
|
2572
2286
|
expect(skip).to eq(context)
|
|
2573
2287
|
end
|
|
2574
2288
|
|
|
2575
|
-
context
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
it "skips the correct number" do
|
|
2289
|
+
context 'when asking for all documents' do
|
|
2290
|
+
context 'when only a skip exists' do
|
|
2291
|
+
it 'skips the correct number' do
|
|
2580
2292
|
expect(context.entries).to eq([ friedel, pfluger ])
|
|
2581
2293
|
end
|
|
2582
2294
|
end
|
|
2583
2295
|
|
|
2584
|
-
context
|
|
2585
|
-
|
|
2296
|
+
context 'when a skip and limit exist' do
|
|
2586
2297
|
before do
|
|
2587
2298
|
skip.limit(1)
|
|
2588
2299
|
end
|
|
2589
2300
|
|
|
2590
|
-
it
|
|
2301
|
+
it 'applies the skip before the limit' do
|
|
2591
2302
|
expect(context.entries).to eq([ friedel ])
|
|
2592
2303
|
end
|
|
2593
2304
|
end
|
|
@@ -2595,33 +2306,31 @@ describe Mongoid::Contextual::Memory do
|
|
|
2595
2306
|
end
|
|
2596
2307
|
|
|
2597
2308
|
context 'when there is a collation on the criteria' do
|
|
2598
|
-
|
|
2599
2309
|
let(:criteria) do
|
|
2600
2310
|
Address.all.tap do |crit|
|
|
2601
2311
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
2602
2312
|
end.collation(locale: 'en_US', strength: 2)
|
|
2603
2313
|
end
|
|
2604
2314
|
|
|
2605
|
-
it
|
|
2606
|
-
expect
|
|
2315
|
+
it 'raises an exception' do
|
|
2316
|
+
expect do
|
|
2607
2317
|
context.skip(1)
|
|
2608
|
-
|
|
2318
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
2609
2319
|
end
|
|
2610
2320
|
end
|
|
2611
2321
|
end
|
|
2612
2322
|
|
|
2613
|
-
describe
|
|
2614
|
-
|
|
2323
|
+
describe '#sort' do
|
|
2615
2324
|
let(:hobrecht) do
|
|
2616
|
-
Address.new(street:
|
|
2325
|
+
Address.new(street: 'hobrecht', number: 9, name: 'hobrecht')
|
|
2617
2326
|
end
|
|
2618
2327
|
|
|
2619
2328
|
let(:friedel) do
|
|
2620
|
-
Address.new(street:
|
|
2329
|
+
Address.new(street: 'friedel', number: 1, name: 'friedel')
|
|
2621
2330
|
end
|
|
2622
2331
|
|
|
2623
2332
|
let(:pfluger) do
|
|
2624
|
-
Address.new(street:
|
|
2333
|
+
Address.new(street: 'pfluger', number: 5, name: 'pfluger')
|
|
2625
2334
|
end
|
|
2626
2335
|
|
|
2627
2336
|
let(:criteria) do
|
|
@@ -2634,42 +2343,37 @@ describe Mongoid::Contextual::Memory do
|
|
|
2634
2343
|
described_class.new(criteria)
|
|
2635
2344
|
end
|
|
2636
2345
|
|
|
2637
|
-
context
|
|
2638
|
-
|
|
2639
|
-
context "when the sort is ascending" do
|
|
2640
|
-
|
|
2346
|
+
context 'when providing a single field sort' do
|
|
2347
|
+
context 'when the sort is ascending' do
|
|
2641
2348
|
let!(:sorted) do
|
|
2642
2349
|
context.sort(street: 1)
|
|
2643
2350
|
end
|
|
2644
2351
|
|
|
2645
|
-
it
|
|
2352
|
+
it 'sorts the documents' do
|
|
2646
2353
|
expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
|
|
2647
2354
|
end
|
|
2648
2355
|
|
|
2649
|
-
it
|
|
2356
|
+
it 'returns the context' do
|
|
2650
2357
|
expect(sorted).to eq(context)
|
|
2651
2358
|
end
|
|
2652
2359
|
end
|
|
2653
2360
|
|
|
2654
|
-
context
|
|
2655
|
-
|
|
2656
|
-
context "when sorting on a string" do
|
|
2657
|
-
|
|
2361
|
+
context 'when the sort is descending' do
|
|
2362
|
+
context 'when sorting on a string' do
|
|
2658
2363
|
let!(:sorted) do
|
|
2659
2364
|
context.sort(street: -1)
|
|
2660
2365
|
end
|
|
2661
2366
|
|
|
2662
|
-
it
|
|
2367
|
+
it 'sorts the documents' do
|
|
2663
2368
|
expect(context.entries).to eq([ pfluger, hobrecht, friedel ])
|
|
2664
2369
|
end
|
|
2665
2370
|
|
|
2666
|
-
it
|
|
2371
|
+
it 'returns the context' do
|
|
2667
2372
|
expect(sorted).to eq(context)
|
|
2668
2373
|
end
|
|
2669
2374
|
end
|
|
2670
2375
|
|
|
2671
|
-
context
|
|
2672
|
-
|
|
2376
|
+
context 'when sorting on a time' do
|
|
2673
2377
|
before do
|
|
2674
2378
|
pfluger.move_in = 30.days.ago
|
|
2675
2379
|
hobrecht.move_in = 25.days.ago
|
|
@@ -2679,25 +2383,24 @@ describe Mongoid::Contextual::Memory do
|
|
|
2679
2383
|
context.sort(move_in: -1)
|
|
2680
2384
|
end
|
|
2681
2385
|
|
|
2682
|
-
it
|
|
2386
|
+
it 'sorts the documents' do
|
|
2683
2387
|
expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
|
|
2684
2388
|
end
|
|
2685
2389
|
|
|
2686
|
-
it
|
|
2390
|
+
it 'returns the context' do
|
|
2687
2391
|
expect(sorted).to eq(context)
|
|
2688
2392
|
end
|
|
2689
2393
|
end
|
|
2690
2394
|
end
|
|
2691
2395
|
end
|
|
2692
2396
|
|
|
2693
|
-
context
|
|
2694
|
-
|
|
2397
|
+
context 'when providing multiple sort fields' do
|
|
2695
2398
|
let(:lenau) do
|
|
2696
|
-
Address.new(street:
|
|
2399
|
+
Address.new(street: 'lenau', number: 5, name: 'lenau')
|
|
2697
2400
|
end
|
|
2698
2401
|
|
|
2699
2402
|
let(:kampuchea_krom) do
|
|
2700
|
-
Address.new(street:
|
|
2403
|
+
Address.new(street: 'kampuchea krom', number: 5, name: 'kampuchea krom')
|
|
2701
2404
|
end
|
|
2702
2405
|
|
|
2703
2406
|
before do
|
|
@@ -2705,101 +2408,94 @@ describe Mongoid::Contextual::Memory do
|
|
|
2705
2408
|
criteria.documents.unshift(kampuchea_krom)
|
|
2706
2409
|
end
|
|
2707
2410
|
|
|
2708
|
-
context
|
|
2709
|
-
|
|
2411
|
+
context 'when the sort is ascending' do
|
|
2710
2412
|
let!(:sorted) do
|
|
2711
2413
|
context.sort(number: 1, street: 1)
|
|
2712
2414
|
end
|
|
2713
2415
|
|
|
2714
|
-
it
|
|
2416
|
+
it 'sorts the documents' do
|
|
2715
2417
|
expect(context.entries).to eq([ friedel, kampuchea_krom, lenau, pfluger, hobrecht ])
|
|
2716
2418
|
end
|
|
2717
2419
|
|
|
2718
|
-
it
|
|
2420
|
+
it 'returns the context' do
|
|
2719
2421
|
expect(sorted).to eq(context)
|
|
2720
2422
|
end
|
|
2721
2423
|
end
|
|
2722
2424
|
|
|
2723
|
-
context
|
|
2724
|
-
|
|
2425
|
+
context 'when the sort is descending' do
|
|
2725
2426
|
let!(:sorted) do
|
|
2726
2427
|
context.sort(number: -1, street: -1)
|
|
2727
2428
|
end
|
|
2728
2429
|
|
|
2729
|
-
it
|
|
2430
|
+
it 'sorts the documents' do
|
|
2730
2431
|
expect(context.entries).to eq([ hobrecht, pfluger, lenau, kampuchea_krom, friedel ])
|
|
2731
2432
|
end
|
|
2732
2433
|
|
|
2733
|
-
it
|
|
2434
|
+
it 'returns the context' do
|
|
2734
2435
|
expect(sorted).to eq(context)
|
|
2735
2436
|
end
|
|
2736
2437
|
end
|
|
2737
2438
|
end
|
|
2738
2439
|
|
|
2739
|
-
context
|
|
2740
|
-
|
|
2440
|
+
context 'when the field is nil' do
|
|
2741
2441
|
let!(:sorted) do
|
|
2742
2442
|
context.sort(state: 1)
|
|
2743
2443
|
end
|
|
2744
2444
|
|
|
2745
|
-
it
|
|
2445
|
+
it 'does not sort the documents' do
|
|
2746
2446
|
expect(context.entries).to eq([ hobrecht, friedel, pfluger ])
|
|
2747
2447
|
end
|
|
2748
2448
|
|
|
2749
|
-
it
|
|
2449
|
+
it 'returns the context' do
|
|
2750
2450
|
expect(sorted).to eq(context)
|
|
2751
2451
|
end
|
|
2752
2452
|
end
|
|
2753
2453
|
|
|
2754
|
-
context
|
|
2755
|
-
|
|
2454
|
+
context 'with localized field' do
|
|
2756
2455
|
let!(:sorted) do
|
|
2757
|
-
context.sort(
|
|
2456
|
+
context.sort('name.en' => 1)
|
|
2758
2457
|
end
|
|
2759
2458
|
|
|
2760
|
-
it
|
|
2459
|
+
it 'sorts the documents' do
|
|
2761
2460
|
expect(context.entries).to eq([ friedel, hobrecht, pfluger ])
|
|
2762
2461
|
end
|
|
2763
2462
|
end
|
|
2764
2463
|
|
|
2765
2464
|
context 'when there is a collation on the criteria' do
|
|
2766
|
-
|
|
2767
2465
|
let(:criteria) do
|
|
2768
2466
|
Address.all.tap do |crit|
|
|
2769
2467
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
2770
2468
|
end.collation(locale: 'en_US', strength: 2)
|
|
2771
2469
|
end
|
|
2772
2470
|
|
|
2773
|
-
it
|
|
2774
|
-
expect
|
|
2471
|
+
it 'raises an exception' do
|
|
2472
|
+
expect do
|
|
2775
2473
|
context.sort(state: 1)
|
|
2776
|
-
|
|
2474
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
2777
2475
|
end
|
|
2778
2476
|
end
|
|
2779
2477
|
end
|
|
2780
2478
|
|
|
2781
|
-
describe
|
|
2782
|
-
|
|
2479
|
+
describe '#update' do
|
|
2783
2480
|
let(:person) do
|
|
2784
2481
|
Person.create!
|
|
2785
2482
|
end
|
|
2786
2483
|
|
|
2787
2484
|
let(:hobrecht) do
|
|
2788
|
-
person.addresses.create!(street:
|
|
2485
|
+
person.addresses.create!(street: 'hobrecht')
|
|
2789
2486
|
end
|
|
2790
2487
|
|
|
2791
2488
|
let(:friedel) do
|
|
2792
|
-
person.addresses.create!(street:
|
|
2489
|
+
person.addresses.create!(street: 'friedel')
|
|
2793
2490
|
end
|
|
2794
2491
|
|
|
2795
2492
|
let(:pfluger) do
|
|
2796
|
-
person.addresses.create!(street:
|
|
2493
|
+
person.addresses.create!(street: 'pfluger')
|
|
2797
2494
|
end
|
|
2798
2495
|
|
|
2799
|
-
context
|
|
2800
|
-
|
|
2496
|
+
context 'when the documents are embedded one level' do
|
|
2801
2497
|
let(:criteria) do
|
|
2802
|
-
Address.any_in(street: [
|
|
2498
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
2803
2499
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
2804
2500
|
end
|
|
2805
2501
|
end
|
|
@@ -2808,60 +2504,56 @@ describe Mongoid::Contextual::Memory do
|
|
|
2808
2504
|
described_class.new(criteria)
|
|
2809
2505
|
end
|
|
2810
2506
|
|
|
2811
|
-
context
|
|
2812
|
-
|
|
2507
|
+
context 'when attributes are provided' do
|
|
2813
2508
|
before do
|
|
2814
2509
|
context.update(number: 5)
|
|
2815
2510
|
end
|
|
2816
2511
|
|
|
2817
|
-
it
|
|
2512
|
+
it 'updates the first matching document' do
|
|
2818
2513
|
expect(hobrecht.number).to eq(5)
|
|
2819
2514
|
end
|
|
2820
2515
|
|
|
2821
|
-
it
|
|
2516
|
+
it 'does not update the last matching document' do
|
|
2822
2517
|
expect(friedel.number).to be_nil
|
|
2823
2518
|
end
|
|
2824
2519
|
|
|
2825
|
-
it
|
|
2520
|
+
it 'does not update non matching docs' do
|
|
2826
2521
|
expect(pfluger.number).to be_nil
|
|
2827
2522
|
end
|
|
2828
2523
|
|
|
2829
|
-
context
|
|
2830
|
-
|
|
2831
|
-
it "updates the first matching document" do
|
|
2524
|
+
context 'when reloading the embedded documents' do
|
|
2525
|
+
it 'updates the first matching document' do
|
|
2832
2526
|
expect(hobrecht.reload.number).to eq(5)
|
|
2833
2527
|
end
|
|
2834
2528
|
|
|
2835
|
-
it
|
|
2529
|
+
it 'updates the last matching document' do
|
|
2836
2530
|
expect(friedel.reload.number).to be_nil
|
|
2837
2531
|
end
|
|
2838
2532
|
|
|
2839
|
-
it
|
|
2533
|
+
it 'does not update non matching docs' do
|
|
2840
2534
|
expect(pfluger.reload.number).to be_nil
|
|
2841
2535
|
end
|
|
2842
2536
|
end
|
|
2843
2537
|
end
|
|
2844
2538
|
|
|
2845
|
-
context
|
|
2846
|
-
|
|
2847
|
-
it "returns false" do
|
|
2539
|
+
context 'when no attributes are provided' do
|
|
2540
|
+
it 'returns false' do
|
|
2848
2541
|
expect(context.update).to be false
|
|
2849
2542
|
end
|
|
2850
2543
|
end
|
|
2851
2544
|
end
|
|
2852
2545
|
|
|
2853
|
-
context
|
|
2854
|
-
|
|
2546
|
+
context 'when the documents are embedded multiple levels' do
|
|
2855
2547
|
let!(:home) do
|
|
2856
|
-
hobrecht.locations.create!(name:
|
|
2548
|
+
hobrecht.locations.create!(name: 'home')
|
|
2857
2549
|
end
|
|
2858
2550
|
|
|
2859
2551
|
let!(:work) do
|
|
2860
|
-
hobrecht.locations.create!(name:
|
|
2552
|
+
hobrecht.locations.create!(name: 'work')
|
|
2861
2553
|
end
|
|
2862
2554
|
|
|
2863
2555
|
let(:criteria) do
|
|
2864
|
-
Location.where(name:
|
|
2556
|
+
Location.where(name: 'work').tap do |crit|
|
|
2865
2557
|
crit.documents = [ home, work ]
|
|
2866
2558
|
end
|
|
2867
2559
|
end
|
|
@@ -2870,87 +2562,80 @@ describe Mongoid::Contextual::Memory do
|
|
|
2870
2562
|
described_class.new(criteria)
|
|
2871
2563
|
end
|
|
2872
2564
|
|
|
2873
|
-
context
|
|
2874
|
-
|
|
2565
|
+
context 'when attributes are provided' do
|
|
2875
2566
|
before do
|
|
2876
2567
|
context.update(number: 5)
|
|
2877
2568
|
end
|
|
2878
2569
|
|
|
2879
|
-
it
|
|
2570
|
+
it 'updates the first matching document' do
|
|
2880
2571
|
expect(work.number).to eq(5)
|
|
2881
2572
|
end
|
|
2882
2573
|
|
|
2883
|
-
it
|
|
2574
|
+
it 'does not update non matching docs' do
|
|
2884
2575
|
expect(home.number).to be_nil
|
|
2885
2576
|
end
|
|
2886
2577
|
|
|
2887
|
-
context
|
|
2888
|
-
|
|
2889
|
-
it "updates the first matching document" do
|
|
2578
|
+
context 'when reloading the embedded documents' do
|
|
2579
|
+
it 'updates the first matching document' do
|
|
2890
2580
|
expect(work.reload.number).to eq(5)
|
|
2891
2581
|
end
|
|
2892
2582
|
|
|
2893
|
-
it
|
|
2583
|
+
it 'does not update non matching docs' do
|
|
2894
2584
|
expect(home.reload.number).to be_nil
|
|
2895
2585
|
end
|
|
2896
2586
|
end
|
|
2897
2587
|
end
|
|
2898
2588
|
|
|
2899
|
-
context
|
|
2900
|
-
|
|
2901
|
-
it "returns false" do
|
|
2589
|
+
context 'when no attributes are provided' do
|
|
2590
|
+
it 'returns false' do
|
|
2902
2591
|
expect(context.update).to be false
|
|
2903
2592
|
end
|
|
2904
2593
|
end
|
|
2905
2594
|
end
|
|
2906
2595
|
|
|
2907
2596
|
context 'when there is a collation on the criteria' do
|
|
2908
|
-
|
|
2909
2597
|
let(:criteria) do
|
|
2910
2598
|
Address.all.collation(locale: 'en_US', strength: 2)
|
|
2911
2599
|
end
|
|
2912
2600
|
|
|
2913
|
-
it
|
|
2914
|
-
expect
|
|
2601
|
+
it 'raises an exception' do
|
|
2602
|
+
expect do
|
|
2915
2603
|
context.update
|
|
2916
|
-
|
|
2604
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
2917
2605
|
end
|
|
2918
2606
|
end
|
|
2919
2607
|
end
|
|
2920
2608
|
|
|
2921
|
-
describe
|
|
2922
|
-
|
|
2609
|
+
describe '#update_all' do
|
|
2923
2610
|
let(:person) do
|
|
2924
2611
|
Person.create!
|
|
2925
2612
|
end
|
|
2926
2613
|
|
|
2927
2614
|
let(:hobrecht) do
|
|
2928
|
-
person.addresses.create!(street:
|
|
2615
|
+
person.addresses.create!(street: 'hobrecht')
|
|
2929
2616
|
end
|
|
2930
2617
|
|
|
2931
2618
|
let(:friedel) do
|
|
2932
|
-
person.addresses.create!(street:
|
|
2619
|
+
person.addresses.create!(street: 'friedel')
|
|
2933
2620
|
end
|
|
2934
2621
|
|
|
2935
2622
|
let(:pfluger) do
|
|
2936
|
-
person.addresses.create!(street:
|
|
2623
|
+
person.addresses.create!(street: 'pfluger')
|
|
2937
2624
|
end
|
|
2938
2625
|
|
|
2939
2626
|
context 'when there is a collation on the criteria' do
|
|
2940
|
-
|
|
2941
2627
|
let(:criteria) do
|
|
2942
2628
|
Address.all.collation(locale: 'en_US', strength: 2)
|
|
2943
2629
|
end
|
|
2944
2630
|
|
|
2945
|
-
it
|
|
2946
|
-
expect
|
|
2631
|
+
it 'raises an exception' do
|
|
2632
|
+
expect do
|
|
2947
2633
|
context.update_all({})
|
|
2948
|
-
|
|
2634
|
+
end.to raise_exception(Mongoid::Errors::InMemoryCollationNotSupported)
|
|
2949
2635
|
end
|
|
2950
2636
|
end
|
|
2951
2637
|
|
|
2952
|
-
context
|
|
2953
|
-
|
|
2638
|
+
context 'when the documents are empty' do
|
|
2954
2639
|
let(:person_two) do
|
|
2955
2640
|
Person.create!
|
|
2956
2641
|
end
|
|
@@ -2963,15 +2648,14 @@ describe Mongoid::Contextual::Memory do
|
|
|
2963
2648
|
described_class.new(criteria)
|
|
2964
2649
|
end
|
|
2965
2650
|
|
|
2966
|
-
it
|
|
2651
|
+
it 'returns false' do
|
|
2967
2652
|
expect(context.update_all({})).to be false
|
|
2968
2653
|
end
|
|
2969
2654
|
end
|
|
2970
2655
|
|
|
2971
|
-
context
|
|
2972
|
-
|
|
2656
|
+
context 'when the documents are embedded one level' do
|
|
2973
2657
|
let(:criteria) do
|
|
2974
|
-
Address.any_in(street: [
|
|
2658
|
+
Address.any_in(street: %w[hobrecht friedel]).tap do |crit|
|
|
2975
2659
|
crit.documents = [ hobrecht, friedel, pfluger ]
|
|
2976
2660
|
end
|
|
2977
2661
|
end
|
|
@@ -2980,90 +2664,84 @@ describe Mongoid::Contextual::Memory do
|
|
|
2980
2664
|
described_class.new(criteria)
|
|
2981
2665
|
end
|
|
2982
2666
|
|
|
2983
|
-
context
|
|
2984
|
-
|
|
2667
|
+
context 'when providing aliased fields' do
|
|
2985
2668
|
before do
|
|
2986
|
-
context.update_all(suite:
|
|
2669
|
+
context.update_all(suite: '10B')
|
|
2987
2670
|
end
|
|
2988
2671
|
|
|
2989
|
-
it
|
|
2990
|
-
expect(hobrecht.suite).to eq(
|
|
2672
|
+
it 'updates the first matching document' do
|
|
2673
|
+
expect(hobrecht.suite).to eq('10B')
|
|
2991
2674
|
end
|
|
2992
2675
|
|
|
2993
|
-
it
|
|
2994
|
-
expect(friedel.suite).to eq(
|
|
2676
|
+
it 'updates the last matching document' do
|
|
2677
|
+
expect(friedel.suite).to eq('10B')
|
|
2995
2678
|
end
|
|
2996
2679
|
|
|
2997
|
-
it
|
|
2680
|
+
it 'does not update non matching docs' do
|
|
2998
2681
|
expect(pfluger.suite).to be_nil
|
|
2999
2682
|
end
|
|
3000
2683
|
end
|
|
3001
2684
|
|
|
3002
|
-
context
|
|
3003
|
-
|
|
2685
|
+
context 'when attributes are provided' do
|
|
3004
2686
|
before do
|
|
3005
2687
|
context.update_all(number: 5)
|
|
3006
2688
|
end
|
|
3007
2689
|
|
|
3008
|
-
it
|
|
2690
|
+
it 'updates the first matching document' do
|
|
3009
2691
|
expect(hobrecht.number).to eq(5)
|
|
3010
2692
|
end
|
|
3011
2693
|
|
|
3012
|
-
it
|
|
2694
|
+
it 'updates the last matching document' do
|
|
3013
2695
|
expect(friedel.number).to eq(5)
|
|
3014
2696
|
end
|
|
3015
2697
|
|
|
3016
|
-
it
|
|
2698
|
+
it 'does not update non matching docs' do
|
|
3017
2699
|
expect(pfluger.number).to be_nil
|
|
3018
2700
|
end
|
|
3019
2701
|
|
|
3020
|
-
context
|
|
3021
|
-
|
|
3022
|
-
it "updates the first matching document" do
|
|
2702
|
+
context 'when reloading the embedded documents' do
|
|
2703
|
+
it 'updates the first matching document' do
|
|
3023
2704
|
expect(hobrecht.reload.number).to eq(5)
|
|
3024
2705
|
end
|
|
3025
2706
|
|
|
3026
|
-
it
|
|
2707
|
+
it 'updates the last matching document' do
|
|
3027
2708
|
expect(friedel.reload.number).to eq(5)
|
|
3028
2709
|
end
|
|
3029
2710
|
|
|
3030
|
-
it
|
|
2711
|
+
it 'does not update non matching docs' do
|
|
3031
2712
|
expect(pfluger.reload.number).to be_nil
|
|
3032
2713
|
end
|
|
3033
2714
|
end
|
|
3034
2715
|
|
|
3035
|
-
context
|
|
3036
|
-
|
|
2716
|
+
context 'when updating the documents a second time' do
|
|
3037
2717
|
before do
|
|
3038
2718
|
context.update_all(number: 5)
|
|
3039
2719
|
end
|
|
3040
2720
|
|
|
3041
|
-
it
|
|
2721
|
+
it 'does not error on the update' do
|
|
3042
2722
|
expect(hobrecht.number).to eq(5)
|
|
3043
2723
|
end
|
|
3044
2724
|
end
|
|
3045
2725
|
end
|
|
3046
2726
|
|
|
3047
|
-
context
|
|
3048
|
-
|
|
3049
|
-
it "returns false" do
|
|
2727
|
+
context 'when no attributes are provided' do
|
|
2728
|
+
it 'returns false' do
|
|
3050
2729
|
expect(context.update_all).to be false
|
|
3051
2730
|
end
|
|
3052
2731
|
end
|
|
3053
2732
|
end
|
|
3054
2733
|
|
|
3055
|
-
context
|
|
3056
|
-
|
|
2734
|
+
context 'when the documents are embedded multiple levels' do
|
|
3057
2735
|
let!(:home) do
|
|
3058
|
-
hobrecht.locations.create!(name:
|
|
2736
|
+
hobrecht.locations.create!(name: 'home')
|
|
3059
2737
|
end
|
|
3060
2738
|
|
|
3061
2739
|
let!(:work) do
|
|
3062
|
-
hobrecht.locations.create!(name:
|
|
2740
|
+
hobrecht.locations.create!(name: 'work')
|
|
3063
2741
|
end
|
|
3064
2742
|
|
|
3065
2743
|
let(:criteria) do
|
|
3066
|
-
Location.where(name:
|
|
2744
|
+
Location.where(name: 'work').tap do |crit|
|
|
3067
2745
|
crit.documents = [ home, work ]
|
|
3068
2746
|
end
|
|
3069
2747
|
end
|
|
@@ -3072,35 +2750,32 @@ describe Mongoid::Contextual::Memory do
|
|
|
3072
2750
|
described_class.new(criteria)
|
|
3073
2751
|
end
|
|
3074
2752
|
|
|
3075
|
-
context
|
|
3076
|
-
|
|
2753
|
+
context 'when attributes are provided' do
|
|
3077
2754
|
before do
|
|
3078
2755
|
context.update_all(number: 5)
|
|
3079
2756
|
end
|
|
3080
2757
|
|
|
3081
|
-
it
|
|
2758
|
+
it 'updates the first matching document' do
|
|
3082
2759
|
expect(work.number).to eq(5)
|
|
3083
2760
|
end
|
|
3084
2761
|
|
|
3085
|
-
it
|
|
2762
|
+
it 'does not update non matching docs' do
|
|
3086
2763
|
expect(home.number).to be_nil
|
|
3087
2764
|
end
|
|
3088
2765
|
|
|
3089
|
-
context
|
|
3090
|
-
|
|
3091
|
-
it "updates the first matching document" do
|
|
2766
|
+
context 'when reloading the embedded documents' do
|
|
2767
|
+
it 'updates the first matching document' do
|
|
3092
2768
|
expect(work.reload.number).to eq(5)
|
|
3093
2769
|
end
|
|
3094
2770
|
|
|
3095
|
-
it
|
|
2771
|
+
it 'does not update non matching docs' do
|
|
3096
2772
|
expect(home.reload.number).to be_nil
|
|
3097
2773
|
end
|
|
3098
2774
|
end
|
|
3099
2775
|
end
|
|
3100
2776
|
|
|
3101
|
-
context
|
|
3102
|
-
|
|
3103
|
-
it "returns false" do
|
|
2777
|
+
context 'when no attributes are provided' do
|
|
2778
|
+
it 'returns false' do
|
|
3104
2779
|
expect(context.update_all).to be false
|
|
3105
2780
|
end
|
|
3106
2781
|
end
|