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