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