mongoid 9.0.11 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -8
- data/README.md +5 -11
- data/Rakefile +35 -38
- data/lib/config/locales/en.yml +11 -0
- data/lib/mongoid/association/accessors.rb +19 -26
- data/lib/mongoid/association/bindable.rb +43 -45
- data/lib/mongoid/association/builders.rb +18 -15
- data/lib/mongoid/association/constrainable.rb +3 -5
- data/lib/mongoid/association/depending.rb +34 -38
- data/lib/mongoid/association/eager.rb +47 -13
- data/lib/mongoid/association/eager_loadable.rb +152 -24
- data/lib/mongoid/association/embedded/batchable.rb +28 -30
- data/lib/mongoid/association/embedded/cyclic.rb +8 -11
- data/lib/mongoid/association/embedded/eager.rb +1 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +6 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +2 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +25 -22
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +2 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +1 -1
- data/lib/mongoid/association/embedded/embeds_many.rb +24 -21
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +2 -6
- data/lib/mongoid/association/embedded/embeds_one.rb +20 -18
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +3 -7
- data/lib/mongoid/association/many.rb +75 -3
- data/lib/mongoid/association/marshalable.rb +0 -3
- data/lib/mongoid/association/nested/many.rb +18 -13
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -9
- data/lib/mongoid/association/nested/one.rb +4 -7
- data/lib/mongoid/association/nested.rb +1 -3
- data/lib/mongoid/association/one.rb +0 -3
- data/lib/mongoid/association/options.rb +8 -7
- data/lib/mongoid/association/referenced/auto_save.rb +0 -2
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +11 -15
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +23 -5
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +1 -3
- data/lib/mongoid/association/referenced/belongs_to.rb +48 -43
- data/lib/mongoid/association/referenced/counter_cache.rb +5 -10
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +8 -4
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +52 -47
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_many/buildable.rb +11 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +107 -38
- data/lib/mongoid/association/referenced/has_many/proxy.rb +10 -6
- data/lib/mongoid/association/referenced/has_many.rb +30 -24
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -3
- data/lib/mongoid/association/referenced/has_one.rb +26 -21
- data/lib/mongoid/association/referenced/syncable.rb +30 -34
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +0 -3
- data/lib/mongoid/association/relatable.rb +69 -66
- data/lib/mongoid/association.rb +12 -15
- data/lib/mongoid/atomic/modifiers.rb +65 -25
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +2 -4
- data/lib/mongoid/atomic/paths/embedded.rb +3 -6
- data/lib/mongoid/atomic/paths/root.rb +1 -4
- data/lib/mongoid/atomic/paths.rb +2 -3
- data/lib/mongoid/atomic.rb +0 -3
- data/lib/mongoid/attributes/dynamic.rb +6 -7
- data/lib/mongoid/attributes/nested.rb +8 -10
- data/lib/mongoid/attributes/projector.rb +7 -20
- data/lib/mongoid/attributes/readonly.rb +6 -11
- data/lib/mongoid/attributes.rb +18 -34
- data/lib/mongoid/cacheable.rb +24 -6
- data/lib/mongoid/clients/factory.rb +12 -15
- data/lib/mongoid/clients/options.rb +2 -5
- data/lib/mongoid/clients/sessions.rb +50 -60
- data/lib/mongoid/clients/storage_options.rb +1 -4
- data/lib/mongoid/clients/validators/storage.rb +2 -3
- data/lib/mongoid/clients/validators.rb +1 -2
- data/lib/mongoid/clients.rb +8 -11
- data/lib/mongoid/collection_configurable.rb +10 -14
- data/lib/mongoid/composable.rb +30 -34
- data/lib/mongoid/config/defaults.rb +7 -4
- data/lib/mongoid/config/encryption.rb +1 -3
- data/lib/mongoid/config/environment.rb +7 -16
- data/lib/mongoid/config/introspection.rb +14 -16
- data/lib/mongoid/config/options.rb +16 -10
- data/lib/mongoid/config/validators/async_query_executor.rb +3 -6
- data/lib/mongoid/config/validators/client.rb +12 -15
- data/lib/mongoid/config/validators/option.rb +3 -5
- data/lib/mongoid/config/validators.rb +3 -4
- data/lib/mongoid/config.rb +132 -42
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -4
- data/lib/mongoid/contextual/aggregable/mongo.rb +20 -22
- data/lib/mongoid/contextual/aggregable/none.rb +2 -4
- data/lib/mongoid/contextual/aggregable.rb +5 -7
- data/lib/mongoid/contextual/atomic.rb +20 -24
- data/lib/mongoid/contextual/command.rb +0 -3
- data/lib/mongoid/contextual/map_reduce.rb +12 -16
- data/lib/mongoid/contextual/memory.rb +72 -65
- data/lib/mongoid/contextual/mongo/documents_loader.rb +2 -3
- data/lib/mongoid/contextual/mongo.rb +169 -85
- data/lib/mongoid/contextual/none.rb +9 -9
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +18 -7
- data/lib/mongoid/copyable.rb +7 -9
- data/lib/mongoid/criteria/findable.rb +5 -7
- data/lib/mongoid/criteria/includable.rb +37 -8
- data/lib/mongoid/criteria/inspectable.rb +2 -5
- data/lib/mongoid/criteria/marshalable.rb +4 -8
- data/lib/mongoid/criteria/modifiable.rb +3 -11
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +34 -37
- data/lib/mongoid/criteria/queryable/aggregable.rb +9 -10
- data/lib/mongoid/criteria/queryable/expandable.rb +4 -9
- data/lib/mongoid/criteria/queryable/extensions/array.rb +7 -10
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -5
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +20 -11
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +15 -11
- data/lib/mongoid/criteria/queryable/extensions/object.rb +7 -8
- data/lib/mongoid/criteria/queryable/extensions/range.rb +6 -9
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +10 -12
- data/lib/mongoid/criteria/queryable/extensions/set.rb +4 -6
- data/lib/mongoid/criteria/queryable/extensions/string.rb +5 -9
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -7
- data/lib/mongoid/criteria/queryable/extensions/time.rb +2 -6
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +2 -12
- data/lib/mongoid/criteria/queryable/extensions.rb +18 -21
- data/lib/mongoid/criteria/queryable/key.rb +12 -18
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +31 -39
- data/lib/mongoid/criteria/queryable/optional.rb +17 -18
- data/lib/mongoid/criteria/queryable/options.rb +20 -9
- data/lib/mongoid/criteria/queryable/pipeline.rb +6 -9
- data/lib/mongoid/criteria/queryable/selectable.rb +131 -193
- data/lib/mongoid/criteria/queryable/selector.rb +20 -29
- data/lib/mongoid/criteria/queryable/smash.rb +1 -6
- data/lib/mongoid/criteria/queryable/storable.rb +20 -39
- data/lib/mongoid/criteria/queryable.rb +25 -15
- data/lib/mongoid/criteria/scopable.rb +5 -11
- data/lib/mongoid/criteria/translator.rb +5 -8
- data/lib/mongoid/criteria.rb +109 -54
- data/lib/mongoid/deprecable.rb +1 -4
- data/lib/mongoid/deprecation.rb +2 -6
- data/lib/mongoid/document.rb +1 -1
- data/lib/mongoid/encryptable.rb +1 -2
- data/lib/mongoid/equality.rb +4 -5
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/attribute_not_loaded.rb +1 -4
- data/lib/mongoid/errors/callback.rb +1 -4
- data/lib/mongoid/errors/create_collection_failure.rb +8 -11
- data/lib/mongoid/errors/criteria_argument_required.rb +2 -5
- data/lib/mongoid/errors/delete_restriction.rb +1 -4
- data/lib/mongoid/errors/document_not_destroyed.rb +1 -4
- data/lib/mongoid/errors/document_not_found.rb +16 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +7 -10
- data/lib/mongoid/errors/empty_config_file.rb +1 -4
- data/lib/mongoid/errors/immutable_attribute.rb +1 -4
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +1 -4
- data/lib/mongoid/errors/invalid_async_query_executor.rb +2 -5
- data/lib/mongoid/errors/invalid_auto_encryption_configuration.rb +2 -5
- data/lib/mongoid/errors/invalid_collection.rb +1 -3
- data/lib/mongoid/errors/invalid_config_file.rb +1 -4
- data/lib/mongoid/errors/invalid_config_option.rb +2 -5
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +6 -10
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +2 -4
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +1 -4
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +1 -4
- data/lib/mongoid/errors/invalid_estimated_count_scoping.rb +1 -4
- data/lib/mongoid/errors/invalid_expression_operator.rb +3 -7
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +5 -9
- data/lib/mongoid/errors/invalid_field_option.rb +2 -5
- data/lib/mongoid/errors/invalid_field_type.rb +1 -4
- data/lib/mongoid/errors/invalid_find.rb +1 -4
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +1 -4
- data/lib/mongoid/errors/invalid_includes.rb +3 -6
- data/lib/mongoid/errors/invalid_index.rb +1 -4
- data/lib/mongoid/errors/invalid_options.rb +1 -4
- data/lib/mongoid/errors/invalid_path.rb +1 -4
- data/lib/mongoid/errors/invalid_persistence_option.rb +4 -7
- data/lib/mongoid/errors/invalid_query.rb +6 -11
- data/lib/mongoid/errors/invalid_relation.rb +10 -13
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -7
- data/lib/mongoid/errors/invalid_scope.rb +1 -4
- data/lib/mongoid/errors/invalid_session_nesting.rb +0 -3
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +2 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_time.rb +1 -4
- data/lib/mongoid/errors/invalid_transaction_nesting.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +1 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +1 -4
- data/lib/mongoid/errors/mixed_relations.rb +1 -3
- data/lib/mongoid/errors/mongoid_error.rb +7 -11
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +1 -4
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +1 -4
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +1 -4
- data/lib/mongoid/errors/no_map_reduce_output.rb +1 -4
- data/lib/mongoid/errors/no_metadata.rb +1 -4
- data/lib/mongoid/errors/no_parent.rb +1 -4
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -4
- data/lib/mongoid/errors/rollback.rb +0 -2
- data/lib/mongoid/errors/scope_overwrite.rb +2 -4
- data/lib/mongoid/errors/sessions_not_supported.rb +0 -3
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -3
- data/lib/mongoid/errors/transaction_error.rb +0 -3
- data/lib/mongoid/errors/transactions_not_supported.rb +0 -3
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +1 -4
- data/lib/mongoid/errors/unregistered_class.rb +1 -1
- data/lib/mongoid/errors/unsaved_document.rb +1 -3
- data/lib/mongoid/errors/unsupported_isolation_level.rb +22 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +1 -4
- data/lib/mongoid/errors/validations.rb +3 -5
- data/lib/mongoid/errors.rb +72 -72
- data/lib/mongoid/evolvable.rb +0 -3
- data/lib/mongoid/extensions/array.rb +5 -7
- data/lib/mongoid/extensions/big_decimal.rb +6 -7
- data/lib/mongoid/extensions/binary.rb +3 -6
- data/lib/mongoid/extensions/boolean.rb +4 -7
- data/lib/mongoid/extensions/bson_document.rb +28 -0
- data/lib/mongoid/extensions/date.rb +10 -14
- data/lib/mongoid/extensions/date_time.rb +2 -6
- data/lib/mongoid/extensions/decimal128.rb +1 -5
- data/lib/mongoid/extensions/false_class.rb +3 -5
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +5 -10
- data/lib/mongoid/extensions/integer.rb +5 -10
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -1
- data/lib/mongoid/extensions/object.rb +9 -14
- data/lib/mongoid/extensions/object_id.rb +2 -6
- data/lib/mongoid/extensions/range.rb +14 -15
- data/lib/mongoid/extensions/raw_value.rb +0 -3
- data/lib/mongoid/extensions/regexp.rb +3 -6
- data/lib/mongoid/extensions/set.rb +3 -4
- data/lib/mongoid/extensions/string.rb +8 -12
- data/lib/mongoid/extensions/symbol.rb +3 -7
- data/lib/mongoid/extensions/time.rb +24 -26
- data/lib/mongoid/extensions/time_with_zone.rb +4 -7
- data/lib/mongoid/extensions/true_class.rb +3 -5
- data/lib/mongoid/extensions.rb +26 -26
- data/lib/mongoid/factory.rb +5 -9
- data/lib/mongoid/fields/encrypted.rb +0 -1
- data/lib/mongoid/fields/foreign_key.rb +9 -10
- data/lib/mongoid/fields/localized.rb +12 -12
- data/lib/mongoid/fields/standard.rb +5 -7
- data/lib/mongoid/fields/validators/macro.rb +23 -34
- data/lib/mongoid/fields/validators.rb +1 -2
- data/lib/mongoid/fields.rb +151 -58
- data/lib/mongoid/findable.rb +82 -53
- data/lib/mongoid/indexable/specification.rb +20 -6
- data/lib/mongoid/indexable/validators/options.rb +33 -40
- data/lib/mongoid/indexable.rb +26 -25
- data/lib/mongoid/inspectable.rb +4 -7
- data/lib/mongoid/interceptable.rb +41 -40
- data/lib/mongoid/loadable.rb +17 -18
- data/lib/mongoid/loggable.rb +4 -8
- data/lib/mongoid/matchable.rb +0 -2
- data/lib/mongoid/matcher/all.rb +2 -5
- data/lib/mongoid/matcher/and.rb +0 -3
- data/lib/mongoid/matcher/bits.rb +13 -8
- data/lib/mongoid/matcher/bits_all_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_all_set.rb +1 -3
- data/lib/mongoid/matcher/bits_any_clear.rb +1 -3
- data/lib/mongoid/matcher/bits_any_set.rb +1 -3
- data/lib/mongoid/matcher/elem_match.rb +13 -15
- data/lib/mongoid/matcher/elem_match_expression.rb +0 -3
- data/lib/mongoid/matcher/eq.rb +0 -3
- data/lib/mongoid/matcher/eq_impl.rb +12 -17
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +4 -7
- data/lib/mongoid/matcher/exists.rb +1 -4
- data/lib/mongoid/matcher/expression.rb +5 -10
- data/lib/mongoid/matcher/expression_operator.rb +1 -3
- data/lib/mongoid/matcher/field_expression.rb +10 -13
- data/lib/mongoid/matcher/field_operator.rb +4 -6
- data/lib/mongoid/matcher/gt.rb +0 -3
- data/lib/mongoid/matcher/gte.rb +0 -3
- data/lib/mongoid/matcher/in.rb +9 -12
- data/lib/mongoid/matcher/lt.rb +0 -3
- data/lib/mongoid/matcher/lte.rb +0 -3
- data/lib/mongoid/matcher/mod.rb +4 -8
- data/lib/mongoid/matcher/ne.rb +0 -3
- data/lib/mongoid/matcher/nin.rb +0 -3
- data/lib/mongoid/matcher/nor.rb +1 -6
- data/lib/mongoid/matcher/not.rb +0 -3
- data/lib/mongoid/matcher/or.rb +0 -3
- data/lib/mongoid/matcher/regex.rb +11 -14
- data/lib/mongoid/matcher/size.rb +2 -5
- data/lib/mongoid/matcher/type.rb +32 -37
- data/lib/mongoid/matcher.rb +7 -15
- data/lib/mongoid/model_resolver.rb +1 -0
- data/lib/mongoid/persistable/creatable.rb +23 -7
- data/lib/mongoid/persistable/deletable.rb +6 -7
- data/lib/mongoid/persistable/destroyable.rb +2 -6
- data/lib/mongoid/persistable/incrementable.rb +1 -3
- data/lib/mongoid/persistable/logical.rb +3 -5
- data/lib/mongoid/persistable/maxable.rb +2 -4
- data/lib/mongoid/persistable/minable.rb +2 -4
- data/lib/mongoid/persistable/multipliable.rb +1 -3
- data/lib/mongoid/persistable/poppable.rb +2 -4
- data/lib/mongoid/persistable/pullable.rb +3 -5
- data/lib/mongoid/persistable/pushable.rb +5 -7
- data/lib/mongoid/persistable/renamable.rb +1 -3
- data/lib/mongoid/persistable/savable.rb +0 -3
- data/lib/mongoid/persistable/settable.rb +4 -13
- data/lib/mongoid/persistable/unsettable.rb +1 -3
- data/lib/mongoid/persistable/updatable.rb +16 -24
- data/lib/mongoid/persistable/upsertable.rb +8 -10
- data/lib/mongoid/persistable.rb +28 -27
- data/lib/mongoid/persistence_context.rb +34 -41
- data/lib/mongoid/pluckable.rb +0 -2
- data/lib/mongoid/positional.rb +5 -11
- data/lib/mongoid/railtie.rb +16 -22
- data/lib/mongoid/railties/console_sandbox.rb +6 -8
- data/lib/mongoid/railties/controller_runtime.rb +7 -11
- data/lib/mongoid/railties/database.rake +42 -44
- data/lib/mongoid/scopable.rb +23 -31
- data/lib/mongoid/search_indexable.rb +330 -0
- data/lib/mongoid/selectable.rb +1 -3
- data/lib/mongoid/serializable.rb +6 -8
- data/lib/mongoid/shardable.rb +8 -17
- data/lib/mongoid/stateful.rb +5 -10
- data/lib/mongoid/stringified_symbol.rb +5 -9
- data/lib/mongoid/tasks/database.rake +31 -32
- data/lib/mongoid/tasks/database.rb +28 -30
- data/lib/mongoid/tasks/encryption.rb +10 -15
- data/lib/mongoid/threaded/lifecycle.rb +6 -9
- data/lib/mongoid/threaded.rb +132 -32
- data/lib/mongoid/timestamps/created/short.rb +2 -3
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +8 -13
- data/lib/mongoid/timestamps/updated/short.rb +2 -3
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +4 -6
- data/lib/mongoid/touchable.rb +19 -11
- data/lib/mongoid/traversable.rb +3 -2
- data/lib/mongoid/validatable/associated.rb +1 -5
- data/lib/mongoid/validatable/format.rb +0 -2
- data/lib/mongoid/validatable/length.rb +0 -2
- data/lib/mongoid/validatable/localizable.rb +0 -3
- data/lib/mongoid/validatable/macros.rb +0 -2
- data/lib/mongoid/validatable/numericality.rb +24 -3
- data/lib/mongoid/validatable/presence.rb +8 -10
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +12 -14
- data/lib/mongoid/validatable.rb +15 -20
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/warnings.rb +10 -11
- data/lib/mongoid.rb +30 -34
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -4
- data/lib/rails/generators/mongoid/config/templates/mongoid.rb +4 -5
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +2 -2
- data/lib/rails/generators/mongoid/model/model_generator.rb +5 -8
- data/lib/rails/generators/mongoid_generator.rb +6 -10
- data/lib/rails/mongoid.rb +1 -3
- data/spec/integration/active_job_spec.rb +1 -2
- data/spec/integration/app_spec.rb +142 -178
- data/spec/integration/associations/belongs_to_spec.rb +30 -28
- data/spec/integration/associations/embedded_dirty_spec.rb +0 -1
- data/spec/integration/associations/embedded_spec.rb +41 -43
- data/spec/integration/associations/embeds_many_spec.rb +46 -29
- data/spec/integration/associations/embeds_one_spec.rb +2 -1
- data/spec/integration/associations/foreign_key_spec.rb +10 -11
- data/spec/integration/associations/foreign_key_spec_models.rb +8 -9
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +16 -13
- data/spec/integration/associations/has_many_spec.rb +17 -18
- data/spec/integration/associations/has_one_spec.rb +42 -45
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +36 -39
- data/spec/integration/associations/reverse_population_spec.rb +4 -5
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +18 -20
- data/spec/integration/atomic/modifiers_spec.rb +72 -52
- data/spec/integration/bson_regexp_raw_spec.rb +2 -3
- data/spec/integration/caching_spec.rb +68 -0
- data/spec/integration/callbacks_models.rb +11 -9
- data/spec/integration/callbacks_spec.rb +78 -80
- data/spec/integration/contextual/empty_spec.rb +19 -20
- data/spec/integration/criteria/alias_query_spec.rb +12 -19
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +23 -18
- data/spec/integration/criteria/logical_spec.rb +18 -19
- data/spec/integration/criteria/range_spec.rb +77 -86
- data/spec/integration/criteria/raw_value_spec.rb +122 -109
- data/spec/integration/criteria/time_with_zone_spec.rb +33 -24
- data/spec/integration/discriminator_key_spec.rb +85 -85
- data/spec/integration/discriminator_value_spec.rb +70 -73
- data/spec/integration/document_spec.rb +9 -10
- data/spec/integration/dots_and_dollars_spec.rb +104 -119
- data/spec/integration/encryption_spec.rb +8 -11
- data/spec/integration/i18n_fallbacks_spec.rb +7 -8
- data/spec/integration/isolation_state_spec.rb +241 -0
- data/spec/integration/matcher_examples_spec.rb +145 -168
- data/spec/integration/matcher_operator_data/in.yml +6 -6
- data/spec/integration/matcher_operator_spec.rb +16 -26
- data/spec/integration/matcher_spec.rb +31 -32
- data/spec/integration/persistence/collection_options_spec.rb +0 -2
- data/spec/integration/persistence/range_field_spec.rb +24 -2
- data/spec/integration/server_query_spec.rb +43 -37
- data/spec/integration/shardable_spec.rb +10 -11
- data/spec/integration/stringified_symbol_field_spec.rb +28 -43
- data/spec/lite_spec_helper.rb +11 -12
- data/spec/mongoid/association/accessors_spec.rb +197 -285
- data/spec/mongoid/association/auto_save_spec.rb +62 -93
- data/spec/mongoid/association/builders_spec.rb +121 -74
- data/spec/mongoid/association/constrainable_spec.rb +9 -22
- data/spec/mongoid/association/counter_cache_spec.rb +71 -104
- data/spec/mongoid/association/depending_spec.rb +166 -208
- data/spec/mongoid/association/eager_spec.rb +416 -80
- data/spec/mongoid/association/embedded/cyclic_spec.rb +36 -48
- data/spec/mongoid/association/embedded/dirty_spec.rb +15 -20
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +36 -54
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +8 -15
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +135 -175
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +25 -127
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +9 -14
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +38 -51
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +1151 -1340
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -17
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +11 -11
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +25 -138
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +15 -23
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +18 -26
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +204 -273
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +5 -6
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -143
- data/spec/mongoid/association/macros_spec.rb +213 -300
- data/spec/mongoid/association/nested/many_spec.rb +51 -73
- data/spec/mongoid/association/nested/one_spec.rb +56 -80
- data/spec/mongoid/association/options_spec.rb +187 -310
- data/spec/mongoid/association/polymorphic_spec.rb +35 -53
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +55 -76
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +36 -41
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +81 -101
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +258 -345
- data/spec/mongoid/association/referenced/belongs_to_models.rb +4 -3
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +91 -294
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +42 -56
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +41 -32
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +36 -42
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +8 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +771 -975
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +9 -9
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +5 -6
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +59 -177
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +29 -43
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +53 -53
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +104 -67
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +431 -675
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +173 -11
- data/spec/mongoid/association/referenced/has_many_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_many_spec.rb +44 -188
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +26 -38
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +28 -29
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +29 -42
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +270 -332
- data/spec/mongoid/association/referenced/has_one_models.rb +1 -2
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +3 -4
- data/spec/mongoid/association/referenced/has_one_spec.rb +40 -188
- data/spec/mongoid/association/reflections_spec.rb +14 -24
- data/spec/mongoid/association/syncable_spec.rb +102 -125
- data/spec/mongoid/association_spec.rb +47 -70
- data/spec/mongoid/atomic/modifiers_spec.rb +184 -197
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +39 -52
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +35 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +9 -15
- data/spec/mongoid/atomic/paths_spec.rb +81 -117
- data/spec/mongoid/atomic_spec.rb +156 -171
- data/spec/mongoid/attributes/dynamic_spec.rb +5 -6
- data/spec/mongoid/attributes/nested_spec.rb +1219 -1692
- data/spec/mongoid/attributes/nested_spec_models.rb +8 -9
- data/spec/mongoid/attributes/projector_spec.rb +2 -6
- data/spec/mongoid/attributes/readonly_spec.rb +73 -97
- data/spec/mongoid/attributes_spec.rb +669 -826
- data/spec/mongoid/cacheable_spec.rb +74 -44
- data/spec/mongoid/changeable_spec.rb +591 -733
- data/spec/mongoid/clients/factory_spec.rb +122 -154
- data/spec/mongoid/clients/options_spec.rb +40 -59
- data/spec/mongoid/clients/sessions_spec.rb +25 -44
- data/spec/mongoid/clients/transactions_spec.rb +33 -50
- data/spec/mongoid/clients/transactions_spec_models.rb +3 -4
- data/spec/mongoid/clients_spec.rb +265 -355
- data/spec/mongoid/collection_configurable_spec.rb +9 -12
- data/spec/mongoid/composable_spec.rb +2 -9
- data/spec/mongoid/config/defaults_spec.rb +24 -31
- data/spec/mongoid/config/encryption_spec.rb +54 -57
- data/spec/mongoid/config/environment_spec.rb +30 -40
- data/spec/mongoid/config/introspection_spec.rb +42 -37
- data/spec/mongoid/config/options_spec.rb +14 -21
- data/spec/mongoid/config_spec.rb +145 -195
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +98 -135
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +4 -7
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +149 -187
- data/spec/mongoid/contextual/aggregable/none_spec.rb +14 -16
- data/spec/mongoid/contextual/atomic_spec.rb +223 -271
- data/spec/mongoid/contextual/map_reduce_spec.rb +110 -138
- data/spec/mongoid/contextual/memory_spec.rb +706 -854
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +12 -13
- data/spec/mongoid/contextual/mongo_spec.rb +1008 -1213
- data/spec/mongoid/contextual/none_spec.rb +54 -59
- data/spec/mongoid/contextual/short_circuit_spec.rb +139 -0
- data/spec/mongoid/copyable_spec.rb +254 -300
- data/spec/mongoid/copyable_spec_models.rb +0 -1
- data/spec/mongoid/criteria/findable_spec.rb +322 -387
- data/spec/mongoid/criteria/includable_spec.rb +421 -372
- data/spec/mongoid/criteria/includable_spec_models.rb +16 -7
- data/spec/mongoid/criteria/inspectable_spec.rb +11 -14
- data/spec/mongoid/criteria/marshalable_spec.rb +11 -14
- data/spec/mongoid/criteria/modifiable_spec.rb +366 -512
- data/spec/mongoid/criteria/options_spec.rb +2 -7
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +112 -141
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +8 -11
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +127 -184
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +123 -60
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +84 -117
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +44 -65
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +86 -108
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +94 -33
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +103 -138
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +95 -34
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +25 -38
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +26 -28
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +32 -54
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +136 -130
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +16 -24
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +15 -24
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +12 -19
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +46 -63
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +28 -42
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +73 -96
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +71 -92
- data/spec/mongoid/criteria/queryable/key_spec.rb +32 -36
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +44 -49
- data/spec/mongoid/criteria/queryable/optional_spec.rb +373 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +172 -123
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +65 -87
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +41 -53
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +576 -680
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +7 -11
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +807 -998
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +154 -191
- data/spec/mongoid/criteria/queryable/selector_spec.rb +294 -390
- data/spec/mongoid/criteria/queryable/smash_spec.rb +6 -11
- data/spec/mongoid/criteria/queryable/storable_spec.rb +54 -81
- data/spec/mongoid/criteria/queryable_mql_spec.rb +92 -0
- data/spec/mongoid/criteria/scopable_spec.rb +102 -138
- data/spec/mongoid/criteria/translator_spec.rb +59 -60
- data/spec/mongoid/criteria_projection_spec.rb +81 -99
- data/spec/mongoid/criteria_spec.rb +935 -950
- data/spec/mongoid/document_fields_spec.rb +28 -30
- data/spec/mongoid/document_persistence_context_spec.rb +13 -15
- data/spec/mongoid/document_query_spec.rb +9 -12
- data/spec/mongoid/document_spec.rb +317 -409
- data/spec/mongoid/equality_spec.rb +69 -102
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -11
- data/spec/mongoid/errors/attribute_not_loaded_spec.rb +7 -10
- data/spec/mongoid/errors/callback_spec.rb +8 -11
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -8
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +7 -10
- data/spec/mongoid/errors/document_not_found_spec.rb +51 -61
- data/spec/mongoid/errors/invalid_collection_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_config_file_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_config_option_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_field_option_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_field_spec.rb +10 -11
- data/spec/mongoid/errors/invalid_field_type_spec.rb +9 -12
- data/spec/mongoid/errors/invalid_find_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_includes_spec.rb +9 -13
- data/spec/mongoid/errors/invalid_index_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_path_spec.rb +7 -10
- data/spec/mongoid/errors/invalid_relation_spec.rb +15 -16
- data/spec/mongoid/errors/invalid_scope_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -6
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +8 -11
- data/spec/mongoid/errors/invalid_time_spec.rb +8 -11
- data/spec/mongoid/errors/inverse_not_found_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +9 -12
- data/spec/mongoid/errors/mixed_relations_spec.rb +8 -11
- data/spec/mongoid/errors/mongoid_error_spec.rb +21 -24
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -9
- data/spec/mongoid/errors/no_client_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_client_database_spec.rb +9 -12
- data/spec/mongoid/errors/no_client_hosts_spec.rb +9 -12
- data/spec/mongoid/errors/no_clients_config_spec.rb +7 -10
- data/spec/mongoid/errors/no_environment_spec.rb +8 -11
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +8 -11
- data/spec/mongoid/errors/no_metadata_spec.rb +7 -10
- data/spec/mongoid/errors/no_parent_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_attribute_spec.rb +7 -10
- data/spec/mongoid/errors/readonly_document_spec.rb +6 -9
- data/spec/mongoid/errors/scope_overwrite_spec.rb +9 -12
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +9 -12
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -8
- data/spec/mongoid/errors/unsaved_document_spec.rb +8 -11
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +9 -12
- data/spec/mongoid/errors/validations_spec.rb +11 -14
- data/spec/mongoid/extensions/array_spec.rb +70 -92
- data/spec/mongoid/extensions/big_decimal_spec.rb +233 -313
- data/spec/mongoid/extensions/binary_spec.rb +21 -32
- data/spec/mongoid/extensions/boolean_spec.rb +52 -75
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +43 -54
- data/spec/mongoid/extensions/date_spec.rb +26 -38
- data/spec/mongoid/extensions/date_time_spec.rb +22 -32
- data/spec/mongoid/extensions/decimal128_spec.rb +12 -18
- data/spec/mongoid/extensions/false_class_spec.rb +10 -17
- data/spec/mongoid/extensions/float_spec.rb +40 -61
- data/spec/mongoid/extensions/hash_spec.rb +46 -64
- data/spec/mongoid/extensions/integer_spec.rb +40 -61
- data/spec/mongoid/extensions/module_spec.rb +13 -18
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -5
- data/spec/mongoid/extensions/object_id_spec.rb +159 -247
- data/spec/mongoid/extensions/object_spec.rb +31 -47
- data/spec/mongoid/extensions/range_spec.rb +112 -115
- data/spec/mongoid/extensions/raw_value_spec.rb +10 -12
- data/spec/mongoid/extensions/regexp_spec.rb +23 -36
- data/spec/mongoid/extensions/set_spec.rb +38 -49
- data/spec/mongoid/extensions/string_spec.rb +118 -167
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +29 -43
- data/spec/mongoid/extensions/symbol_spec.rb +12 -20
- data/spec/mongoid/extensions/time_spec.rb +160 -202
- data/spec/mongoid/extensions/time_with_zone_spec.rb +79 -105
- data/spec/mongoid/extensions/true_class_spec.rb +10 -17
- data/spec/mongoid/factory_spec.rb +125 -148
- data/spec/mongoid/fields/foreign_key_spec.rb +124 -169
- data/spec/mongoid/fields/localized_spec.rb +140 -185
- data/spec/mongoid/fields/standard_spec.rb +43 -59
- data/spec/mongoid/fields_spec.rb +751 -620
- data/spec/mongoid/findable_spec.rb +260 -228
- data/spec/mongoid/indexable/specification_spec.rb +42 -58
- data/spec/mongoid/indexable_spec.rb +260 -264
- data/spec/mongoid/inspectable_spec.rb +45 -55
- data/spec/mongoid/interceptable_spec.rb +784 -922
- data/spec/mongoid/interceptable_spec_models.rb +35 -35
- data/spec/mongoid/loading_spec.rb +47 -43
- data/spec/mongoid/loggable_spec.rb +3 -6
- data/spec/mongoid/matcher/extract_attribute_spec.rb +2 -6
- data/spec/mongoid/mongoizable_spec.rb +81 -90
- data/spec/mongoid/monkey_patches_spec.rb +4 -0
- data/spec/mongoid/persistable/creatable_spec.rb +181 -220
- data/spec/mongoid/persistable/deletable_spec.rb +139 -179
- data/spec/mongoid/persistable/destroyable_spec.rb +135 -164
- data/spec/mongoid/persistable/incrementable_spec.rb +65 -84
- data/spec/mongoid/persistable/logical_spec.rb +48 -61
- data/spec/mongoid/persistable/maxable_spec.rb +45 -44
- data/spec/mongoid/persistable/minable_spec.rb +45 -44
- data/spec/mongoid/persistable/multipliable_spec.rb +54 -69
- data/spec/mongoid/persistable/poppable_spec.rb +47 -60
- data/spec/mongoid/persistable/pullable_spec.rb +79 -103
- data/spec/mongoid/persistable/pushable_spec.rb +106 -131
- data/spec/mongoid/persistable/renamable_spec.rb +52 -65
- data/spec/mongoid/persistable/savable_spec.rb +152 -189
- data/spec/mongoid/persistable/settable_spec.rb +121 -145
- data/spec/mongoid/persistable/unsettable_spec.rb +56 -73
- data/spec/mongoid/persistable/updatable_spec.rb +185 -232
- data/spec/mongoid/persistable/upsertable_spec.rb +66 -77
- data/spec/mongoid/persistable_spec.rb +132 -139
- data/spec/mongoid/persistence_context_spec.rb +31 -89
- data/spec/mongoid/positional_spec.rb +67 -79
- data/spec/mongoid/railties/bson_object_id_serializer_spec.rb +0 -3
- data/spec/mongoid/railties/console_sandbox_spec.rb +0 -1
- data/spec/mongoid/relations/proxy_spec.rb +0 -1
- data/spec/mongoid/reloadable_spec.rb +250 -145
- data/spec/mongoid/scopable_spec.rb +319 -398
- data/spec/mongoid/search_indexable_spec.rb +446 -41
- data/spec/mongoid/selectable_spec.rb +36 -51
- data/spec/mongoid/serializable_spec.rb +269 -312
- data/spec/mongoid/shardable_models.rb +5 -5
- data/spec/mongoid/shardable_spec.rb +44 -46
- data/spec/mongoid/stateful_spec.rb +55 -75
- data/spec/mongoid/tasks/database_rake_spec.rb +138 -141
- data/spec/mongoid/tasks/database_spec.rb +80 -80
- data/spec/mongoid/tasks/encryption_spec.rb +22 -20
- data/spec/mongoid/threaded_spec.rb +57 -83
- data/spec/mongoid/timestamps/created/short_spec.rb +12 -16
- data/spec/mongoid/timestamps/created_spec.rb +16 -20
- data/spec/mongoid/timestamps/timeless_spec.rb +31 -43
- data/spec/mongoid/timestamps/updated/short_spec.rb +21 -28
- data/spec/mongoid/timestamps/updated_spec.rb +18 -25
- data/spec/mongoid/timestamps_spec.rb +171 -188
- data/spec/mongoid/timestamps_spec_models.rb +12 -13
- data/spec/mongoid/touchable_spec.rb +330 -294
- data/spec/mongoid/touchable_spec_models.rb +35 -37
- data/spec/mongoid/traversable_spec.rb +435 -471
- data/spec/mongoid/validatable/associated_spec.rb +42 -60
- data/spec/mongoid/validatable/format_spec.rb +24 -34
- data/spec/mongoid/validatable/length_spec.rb +62 -86
- data/spec/mongoid/validatable/numericality_spec.rb +114 -23
- data/spec/mongoid/validatable/presence_spec.rb +149 -203
- data/spec/mongoid/validatable/uniqueness_spec.rb +632 -830
- data/spec/mongoid/validatable_spec.rb +71 -103
- data/spec/mongoid/warnings_spec.rb +5 -9
- data/spec/mongoid_spec.rb +25 -41
- data/spec/rails/controller_extension/controller_runtime_spec.rb +45 -49
- data/spec/rails/mongoid_spec.rb +15 -15
- data/spec/shared/lib/mrss/cluster_config.rb +5 -40
- data/spec/shared/lib/mrss/constraints.rb +7 -46
- data/spec/shared/lib/mrss/docker_runner.rb +10 -21
- data/spec/shared/lib/mrss/eg_config_utils.rb +0 -31
- data/spec/shared/lib/mrss/release/candidate.rb +18 -12
- data/spec/shared/lib/mrss/server_version_registry.rb +1 -5
- data/spec/shared/share/Dockerfile.erb +6 -8
- data/spec/shared/shlib/server.sh +0 -50
- data/spec/shared/shlib/set_env.sh +4 -10
- data/spec/spec_helper.rb +54 -31
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +1 -2
- data/spec/support/constraints.rb +8 -25
- data/spec/support/crypt/models.rb +7 -8
- data/spec/support/crypt.rb +6 -9
- data/spec/support/expectations.rb +21 -7
- data/spec/support/feature_sandbox.rb +1 -4
- data/spec/support/helpers.rb +0 -1
- data/spec/support/immutable_ids.rb +20 -21
- data/spec/support/macros.rb +1 -3
- data/spec/support/models/account.rb +4 -5
- data/spec/support/models/acolyte.rb +5 -5
- data/spec/support/models/actor.rb +3 -3
- data/spec/support/models/actress.rb +0 -1
- data/spec/support/models/address.rb +11 -11
- data/spec/support/models/address_component.rb +1 -1
- data/spec/support/models/address_number.rb +1 -1
- data/spec/support/models/agency.rb +1 -1
- data/spec/support/models/agent.rb +1 -1
- data/spec/support/models/album.rb +1 -2
- data/spec/support/models/alert.rb +1 -1
- data/spec/support/models/animal.rb +4 -5
- data/spec/support/models/answer.rb +1 -1
- data/spec/support/models/appointment.rb +2 -2
- data/spec/support/models/armrest.rb +0 -1
- data/spec/support/models/array_field.rb +0 -1
- data/spec/support/models/article.rb +0 -1
- data/spec/support/models/artist.rb +16 -12
- data/spec/support/models/artwork.rb +1 -1
- data/spec/support/models/audible_sound.rb +0 -1
- data/spec/support/models/audio.rb +2 -2
- data/spec/support/models/augmentation.rb +1 -2
- data/spec/support/models/author.rb +1 -1
- data/spec/support/models/baby.rb +1 -1
- data/spec/support/models/band.rb +0 -1
- data/spec/support/models/bar.rb +2 -2
- data/spec/support/models/basic.rb +0 -1
- data/spec/support/models/bed.rb +0 -1
- data/spec/support/models/big_palette.rb +0 -1
- data/spec/support/models/birthday.rb +3 -5
- data/spec/support/models/bolt.rb +0 -1
- data/spec/support/models/bomb.rb +1 -1
- data/spec/support/models/book.rb +1 -1
- data/spec/support/models/breed.rb +1 -1
- data/spec/support/models/browser.rb +1 -2
- data/spec/support/models/building.rb +0 -1
- data/spec/support/models/building_address.rb +1 -1
- data/spec/support/models/bus.rb +1 -1
- data/spec/support/models/business.rb +2 -2
- data/spec/support/models/callback_test.rb +1 -1
- data/spec/support/models/canvas.rb +5 -6
- data/spec/support/models/car.rb +0 -1
- data/spec/support/models/cat.rb +0 -2
- data/spec/support/models/catalog.rb +0 -1
- data/spec/support/models/category.rb +1 -1
- data/spec/support/models/child.rb +1 -1
- data/spec/support/models/child_doc.rb +5 -6
- data/spec/support/models/church.rb +1 -1
- data/spec/support/models/circle.rb +0 -1
- data/spec/support/models/circuit.rb +2 -2
- data/spec/support/models/circus.rb +0 -1
- data/spec/support/models/code.rb +2 -1
- data/spec/support/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +0 -1
- data/spec/support/models/comment.rb +0 -1
- data/spec/support/models/company.rb +0 -1
- data/spec/support/models/consumption_period.rb +0 -1
- data/spec/support/models/contextable_item.rb +1 -1
- data/spec/support/models/contractor.rb +1 -1
- data/spec/support/models/cookie.rb +0 -1
- data/spec/support/models/country_code.rb +2 -3
- data/spec/support/models/courier_job.rb +2 -2
- data/spec/support/models/cover.rb +0 -1
- data/spec/support/models/crate.rb +0 -1
- data/spec/support/models/customer.rb +0 -1
- data/spec/support/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +1 -1
- data/spec/support/models/definition.rb +1 -1
- data/spec/support/models/delegating_patient.rb +0 -1
- data/spec/support/models/description.rb +0 -1
- data/spec/support/models/dictionary.rb +1 -1
- data/spec/support/models/division.rb +2 -2
- data/spec/support/models/doctor.rb +0 -1
- data/spec/support/models/dog.rb +2 -2
- data/spec/support/models/dokument.rb +1 -1
- data/spec/support/models/draft.rb +0 -1
- data/spec/support/models/dragon.rb +1 -1
- data/spec/support/models/driver.rb +2 -2
- data/spec/support/models/drug.rb +1 -1
- data/spec/support/models/dungeon.rb +1 -1
- data/spec/support/models/edit.rb +1 -1
- data/spec/support/models/email.rb +1 -1
- data/spec/support/models/employer.rb +1 -2
- data/spec/support/models/entry.rb +1 -1
- data/spec/support/models/eraser.rb +0 -1
- data/spec/support/models/even.rb +1 -1
- data/spec/support/models/event.rb +3 -4
- data/spec/support/models/exhibition.rb +1 -1
- data/spec/support/models/exhibitor.rb +1 -1
- data/spec/support/models/explosion.rb +1 -1
- data/spec/support/models/eye.rb +0 -1
- data/spec/support/models/eye_bowl.rb +2 -3
- data/spec/support/models/face.rb +2 -3
- data/spec/support/models/fanatic.rb +1 -1
- data/spec/support/models/favorite.rb +1 -1
- data/spec/support/models/filesystem.rb +1 -1
- data/spec/support/models/fire_hydrant.rb +1 -1
- data/spec/support/models/firefox.rb +0 -1
- data/spec/support/models/fish.rb +0 -1
- data/spec/support/models/folder.rb +0 -2
- data/spec/support/models/folder_item.rb +1 -3
- data/spec/support/models/fruits.rb +9 -5
- data/spec/support/models/game.rb +3 -4
- data/spec/support/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +0 -1
- data/spec/support/models/hole.rb +0 -1
- data/spec/support/models/home.rb +1 -1
- data/spec/support/models/house.rb +2 -2
- data/spec/support/models/html_writer.rb +0 -1
- data/spec/support/models/id_key.rb +3 -3
- data/spec/support/models/idnodef.rb +0 -1
- data/spec/support/models/image.rb +0 -1
- data/spec/support/models/implant.rb +1 -2
- data/spec/support/models/instrument.rb +2 -3
- data/spec/support/models/item.rb +2 -2
- data/spec/support/models/jar.rb +1 -2
- data/spec/support/models/kaleidoscope.rb +1 -1
- data/spec/support/models/kangaroo.rb +1 -1
- data/spec/support/models/label.rb +2 -2
- data/spec/support/models/language.rb +1 -1
- data/spec/support/models/lat_lng.rb +0 -1
- data/spec/support/models/league.rb +1 -1
- data/spec/support/models/learner.rb +0 -1
- data/spec/support/models/line_item.rb +1 -1
- data/spec/support/models/location.rb +1 -1
- data/spec/support/models/login.rb +1 -2
- data/spec/support/models/manufacturer.rb +0 -1
- data/spec/support/models/meat.rb +1 -1
- data/spec/support/models/membership.rb +1 -1
- data/spec/support/models/message.rb +1 -2
- data/spec/support/models/minim.rb +0 -1
- data/spec/support/models/mixed_drink.rb +1 -1
- data/spec/support/models/modifier_models.rb +25 -0
- data/spec/support/models/mop.rb +0 -1
- data/spec/support/models/movie.rb +1 -1
- data/spec/support/models/my_hash.rb +1 -2
- data/spec/support/models/name.rb +4 -5
- data/spec/support/models/name_only.rb +0 -1
- data/spec/support/models/node.rb +1 -1
- data/spec/support/models/note.rb +3 -3
- data/spec/support/models/nut.rb +0 -1
- data/spec/support/models/odd.rb +1 -1
- data/spec/support/models/order.rb +1 -1
- data/spec/support/models/ordered_post.rb +1 -1
- data/spec/support/models/ordered_preference.rb +1 -1
- data/spec/support/models/oscar.rb +1 -1
- data/spec/support/models/other_owner_object.rb +0 -1
- data/spec/support/models/override.rb +3 -11
- data/spec/support/models/ownable.rb +1 -1
- data/spec/support/models/owner.rb +1 -1
- data/spec/support/models/pack.rb +0 -1
- data/spec/support/models/page.rb +3 -3
- data/spec/support/models/page_question.rb +1 -1
- data/spec/support/models/palette.rb +2 -2
- data/spec/support/models/parent.rb +2 -2
- data/spec/support/models/parent_doc.rb +1 -1
- data/spec/support/models/passport.rb +0 -1
- data/spec/support/models/patient.rb +2 -2
- data/spec/support/models/pdf_writer.rb +0 -1
- data/spec/support/models/pencil.rb +0 -1
- data/spec/support/models/person.rb +32 -28
- data/spec/support/models/pet.rb +1 -1
- data/spec/support/models/pet_owner.rb +1 -1
- data/spec/support/models/phone.rb +1 -2
- data/spec/support/models/piano.rb +0 -1
- data/spec/support/models/pizza.rb +1 -1
- data/spec/support/models/player.rb +5 -5
- data/spec/support/models/post.rb +12 -12
- data/spec/support/models/post_genre.rb +1 -1
- data/spec/support/models/powerup.rb +1 -2
- data/spec/support/models/preference.rb +2 -2
- data/spec/support/models/princess.rb +1 -1
- data/spec/support/models/product.rb +3 -3
- data/spec/support/models/profile.rb +2 -1
- data/spec/support/models/pronunciation.rb +1 -1
- data/spec/support/models/pub.rb +2 -2
- data/spec/support/models/publication/encyclopedia.rb +0 -1
- data/spec/support/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +0 -1
- data/spec/support/models/purchase.rb +1 -1
- data/spec/support/models/purchased_item.rb +1 -1
- data/spec/support/models/question.rb +2 -2
- data/spec/support/models/quiz.rb +1 -1
- data/spec/support/models/rating.rb +1 -1
- data/spec/support/models/record.rb +2 -3
- data/spec/support/models/registry.rb +1 -1
- data/spec/support/models/role.rb +1 -1
- data/spec/support/models/root_category.rb +1 -1
- data/spec/support/models/sandbox/app/models/app_models_message.rb +0 -1
- data/spec/support/models/sandbox/lib/models/lib_models_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_message.rb +0 -1
- data/spec/support/models/sandbox/sandbox_user.rb +0 -1
- data/spec/support/models/sandbox/subdir/sandbox_comment.rb +0 -1
- data/spec/support/models/sandwich.rb +1 -1
- data/spec/support/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +0 -1
- data/spec/support/models/scribe.rb +1 -1
- data/spec/support/models/sealer.rb +0 -1
- data/spec/support/models/seat.rb +0 -1
- data/spec/support/models/seo.rb +1 -1
- data/spec/support/models/series.rb +1 -1
- data/spec/support/models/server.rb +1 -1
- data/spec/support/models/service.rb +2 -2
- data/spec/support/models/shape.rb +3 -3
- data/spec/support/models/shelf.rb +1 -1
- data/spec/support/models/shield.rb +2 -2
- data/spec/support/models/shipment_address.rb +0 -1
- data/spec/support/models/shipping_container.rb +1 -1
- data/spec/support/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +0 -1
- data/spec/support/models/shop.rb +2 -2
- data/spec/support/models/short_agent.rb +0 -1
- data/spec/support/models/short_quiz.rb +1 -1
- data/spec/support/models/simple.rb +1 -1
- data/spec/support/models/slave.rb +1 -1
- data/spec/support/models/song.rb +1 -2
- data/spec/support/models/sound.rb +2 -2
- data/spec/support/models/spacer.rb +0 -1
- data/spec/support/models/square.rb +0 -1
- data/spec/support/models/staff.rb +0 -1
- data/spec/support/models/store_as_dup_test1.rb +2 -2
- data/spec/support/models/store_as_dup_test2.rb +1 -1
- data/spec/support/models/store_as_dup_test3.rb +2 -2
- data/spec/support/models/store_as_dup_test4.rb +1 -1
- data/spec/support/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +1 -2
- data/spec/support/models/sub_item.rb +0 -1
- data/spec/support/models/subscription.rb +2 -2
- data/spec/support/models/survey.rb +2 -2
- data/spec/support/models/symptom.rb +2 -2
- data/spec/support/models/system_role.rb +2 -3
- data/spec/support/models/tag.rb +2 -2
- data/spec/support/models/target.rb +1 -1
- data/spec/support/models/template.rb +1 -1
- data/spec/support/models/thing.rb +1 -1
- data/spec/support/models/threadlocker.rb +0 -1
- data/spec/support/models/title.rb +0 -1
- data/spec/support/models/tool.rb +3 -3
- data/spec/support/models/topping.rb +1 -1
- data/spec/support/models/toy.rb +0 -1
- data/spec/support/models/track.rb +1 -1
- data/spec/support/models/translation.rb +1 -1
- data/spec/support/models/tree.rb +2 -3
- data/spec/support/models/truck.rb +0 -1
- data/spec/support/models/updatable.rb +0 -1
- data/spec/support/models/user.rb +3 -4
- data/spec/support/models/user_account.rb +3 -3
- data/spec/support/models/validation_callback.rb +4 -4
- data/spec/support/models/vehicle.rb +2 -3
- data/spec/support/models/version.rb +1 -1
- data/spec/support/models/vertex.rb +0 -1
- data/spec/support/models/vet_visit.rb +1 -1
- data/spec/support/models/video.rb +2 -2
- data/spec/support/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +0 -1
- data/spec/support/models/weapon.rb +1 -2
- data/spec/support/models/wiki_page.rb +2 -3
- data/spec/support/models/word.rb +2 -2
- data/spec/support/models/word_origin.rb +1 -2
- data/spec/support/models/writer.rb +3 -3
- data/spec/support/rails_mock.rb +7 -12
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/sinatra_mock.rb +4 -2
- data/spec/support/spec_config.rb +19 -18
- metadata +14 -2
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context "when comparing with an enumerable" do
|
|
11
|
-
|
|
6
|
+
describe '#==' do
|
|
7
|
+
context 'when comparing with an enumerable' do
|
|
12
8
|
let(:person) do
|
|
13
9
|
Person.create!
|
|
14
10
|
end
|
|
@@ -17,8 +13,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
17
13
|
Post.create!(person_id: person.id)
|
|
18
14
|
end
|
|
19
15
|
|
|
20
|
-
context
|
|
21
|
-
|
|
16
|
+
context 'when only a criteria target exists' do
|
|
22
17
|
let(:criteria) do
|
|
23
18
|
Post.where(person_id: person.id)
|
|
24
19
|
end
|
|
@@ -27,24 +22,22 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
27
22
|
described_class.new(criteria)
|
|
28
23
|
end
|
|
29
24
|
|
|
30
|
-
it
|
|
25
|
+
it 'returns the equality check' do
|
|
31
26
|
expect(enumerable).to eq([ post ])
|
|
32
27
|
end
|
|
33
28
|
end
|
|
34
29
|
|
|
35
|
-
context
|
|
36
|
-
|
|
30
|
+
context 'when only an array target exists' do
|
|
37
31
|
let!(:enumerable) do
|
|
38
32
|
described_class.new([ post ])
|
|
39
33
|
end
|
|
40
34
|
|
|
41
|
-
it
|
|
35
|
+
it 'returns the equality check' do
|
|
42
36
|
expect(enumerable._loaded.values).to eq([ post ])
|
|
43
37
|
end
|
|
44
38
|
end
|
|
45
39
|
|
|
46
|
-
context
|
|
47
|
-
|
|
40
|
+
context 'when a criteria and added exist' do
|
|
48
41
|
let(:criteria) do
|
|
49
42
|
Post.where(person_id: person.id)
|
|
50
43
|
end
|
|
@@ -57,42 +50,38 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
57
50
|
Post.new
|
|
58
51
|
end
|
|
59
52
|
|
|
60
|
-
context
|
|
61
|
-
|
|
53
|
+
context 'when the added does not contain unloaded docs' do
|
|
62
54
|
before do
|
|
63
55
|
enumerable << post_two
|
|
64
56
|
end
|
|
65
57
|
|
|
66
|
-
it
|
|
58
|
+
it 'returns the equality check' do
|
|
67
59
|
expect(enumerable).to eq([ post, post_two ])
|
|
68
60
|
end
|
|
69
61
|
end
|
|
70
62
|
|
|
71
|
-
context
|
|
72
|
-
|
|
63
|
+
context 'when the added contains unloaded docs' do
|
|
73
64
|
before do
|
|
74
65
|
enumerable << post
|
|
75
66
|
end
|
|
76
67
|
|
|
77
|
-
it
|
|
68
|
+
it 'returns the equality check' do
|
|
78
69
|
expect(enumerable).to eq([ post ])
|
|
79
70
|
end
|
|
80
71
|
end
|
|
81
72
|
|
|
82
|
-
context
|
|
83
|
-
|
|
73
|
+
context 'when the enumerable is loaded' do
|
|
84
74
|
before do
|
|
85
75
|
enumerable.instance_variable_set(:@executed, true)
|
|
86
76
|
end
|
|
87
77
|
|
|
88
|
-
context
|
|
89
|
-
|
|
78
|
+
context 'when the loaded has no docs and added is persisted' do
|
|
90
79
|
before do
|
|
91
80
|
post.save!
|
|
92
81
|
enumerable._added[post.id] = post
|
|
93
82
|
end
|
|
94
83
|
|
|
95
|
-
it
|
|
84
|
+
it 'returns the equality check' do
|
|
96
85
|
expect(enumerable).to eq([ post ])
|
|
97
86
|
end
|
|
98
87
|
end
|
|
@@ -100,79 +89,70 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
100
89
|
end
|
|
101
90
|
end
|
|
102
91
|
|
|
103
|
-
context
|
|
104
|
-
|
|
92
|
+
context 'when comparing with a non enumerable' do
|
|
105
93
|
let(:enumerable) do
|
|
106
94
|
described_class.new([])
|
|
107
95
|
end
|
|
108
96
|
|
|
109
|
-
it
|
|
110
|
-
expect(enumerable).
|
|
97
|
+
it 'returns false' do
|
|
98
|
+
expect(enumerable).not_to eq('person')
|
|
111
99
|
end
|
|
112
100
|
end
|
|
113
101
|
end
|
|
114
102
|
|
|
115
|
-
describe
|
|
116
|
-
|
|
103
|
+
describe '#===' do
|
|
117
104
|
let(:data) { [] }
|
|
118
105
|
|
|
119
106
|
shared_examples 'standard library-compatible enumerable' do
|
|
120
|
-
context
|
|
121
|
-
|
|
122
|
-
it "returns false" do
|
|
107
|
+
context 'when compared to an array class' do
|
|
108
|
+
it 'returns false' do
|
|
123
109
|
expect(enumerable === Array).to be false
|
|
124
110
|
end
|
|
125
111
|
end
|
|
126
112
|
|
|
127
|
-
context
|
|
128
|
-
|
|
129
|
-
it "returns false" do
|
|
113
|
+
context 'when compared to an enumerable class' do
|
|
114
|
+
it 'returns false' do
|
|
130
115
|
expect(enumerable === described_class).to be false
|
|
131
116
|
end
|
|
132
117
|
end
|
|
133
118
|
|
|
134
|
-
context
|
|
135
|
-
|
|
136
|
-
it "returns false" do
|
|
119
|
+
context 'when compared to a different class' do
|
|
120
|
+
it 'returns false' do
|
|
137
121
|
expect(enumerable === Mongoid::Document).to be false
|
|
138
122
|
end
|
|
139
123
|
end
|
|
140
124
|
|
|
141
|
-
context
|
|
142
|
-
|
|
143
|
-
context "when the entries are equal" do
|
|
144
|
-
|
|
125
|
+
context 'when compared to an array instance' do
|
|
126
|
+
context 'when the entries are equal' do
|
|
145
127
|
let(:data) do
|
|
146
|
-
[Post.new(id: 2)]
|
|
128
|
+
[ Post.new(id: 2) ]
|
|
147
129
|
end
|
|
148
130
|
|
|
149
131
|
let(:other) do
|
|
150
|
-
described_class.new([Post.new(id: 2)])
|
|
132
|
+
described_class.new([ Post.new(id: 2) ])
|
|
151
133
|
end
|
|
152
134
|
|
|
153
|
-
it
|
|
135
|
+
it 'returns true' do
|
|
154
136
|
expect(enumerable === other).to be true
|
|
155
137
|
end
|
|
156
138
|
end
|
|
157
139
|
|
|
158
|
-
context
|
|
159
|
-
|
|
140
|
+
context 'when the entries are both empty' do
|
|
160
141
|
let(:other) do
|
|
161
142
|
described_class.new([])
|
|
162
143
|
end
|
|
163
144
|
|
|
164
|
-
it
|
|
145
|
+
it 'returns true' do
|
|
165
146
|
expect(enumerable === other).to be true
|
|
166
147
|
end
|
|
167
148
|
end
|
|
168
149
|
|
|
169
|
-
context
|
|
170
|
-
|
|
150
|
+
context 'when the entries are not equal' do
|
|
171
151
|
let(:other) do
|
|
172
152
|
described_class.new([ Band.new ])
|
|
173
153
|
end
|
|
174
154
|
|
|
175
|
-
it
|
|
155
|
+
it 'returns false' do
|
|
176
156
|
expect(enumerable === other).to be false
|
|
177
157
|
end
|
|
178
158
|
end
|
|
@@ -196,8 +176,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
196
176
|
end
|
|
197
177
|
end
|
|
198
178
|
|
|
199
|
-
describe
|
|
200
|
-
|
|
179
|
+
describe '#<<' do
|
|
201
180
|
let(:person) do
|
|
202
181
|
Person.create!
|
|
203
182
|
end
|
|
@@ -210,21 +189,20 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
210
189
|
described_class.new([])
|
|
211
190
|
end
|
|
212
191
|
|
|
213
|
-
context
|
|
214
|
-
|
|
192
|
+
context 'when the association is empty' do
|
|
215
193
|
let!(:added) do
|
|
216
194
|
enumerable << post
|
|
217
195
|
end
|
|
218
196
|
|
|
219
|
-
it
|
|
197
|
+
it 'adds the document to the added target' do
|
|
220
198
|
expect(enumerable._added).to eq({ post.id => post })
|
|
221
199
|
end
|
|
222
200
|
|
|
223
|
-
it
|
|
201
|
+
it 'returns the added documents' do
|
|
224
202
|
expect(added).to eq([ post ])
|
|
225
203
|
end
|
|
226
204
|
|
|
227
|
-
it
|
|
205
|
+
it 'sets the base on the new document' do
|
|
228
206
|
expect_query(0) do
|
|
229
207
|
added.collect(&:person)
|
|
230
208
|
end
|
|
@@ -232,8 +210,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
232
210
|
end
|
|
233
211
|
end
|
|
234
212
|
|
|
235
|
-
describe
|
|
236
|
-
|
|
213
|
+
describe '#empty?' do
|
|
237
214
|
let(:person) do
|
|
238
215
|
Person.create!
|
|
239
216
|
end
|
|
@@ -246,8 +223,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
246
223
|
Post.create!(person_id: person.id)
|
|
247
224
|
end
|
|
248
225
|
|
|
249
|
-
context
|
|
250
|
-
|
|
226
|
+
context 'when only a criteria target exists' do
|
|
251
227
|
let(:criteria) do
|
|
252
228
|
Post.where(person_id: person.id)
|
|
253
229
|
end
|
|
@@ -260,40 +236,38 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
260
236
|
enumerable.empty?
|
|
261
237
|
end
|
|
262
238
|
|
|
263
|
-
it
|
|
239
|
+
it 'returns false' do
|
|
264
240
|
expect(empty).to be false
|
|
265
241
|
end
|
|
266
242
|
|
|
267
243
|
context 'when #empty? is called' do
|
|
268
|
-
|
|
269
244
|
before { empty }
|
|
270
245
|
|
|
271
|
-
it
|
|
246
|
+
it 'retains the correct length' do
|
|
272
247
|
expect(enumerable.length).to eq(2)
|
|
273
248
|
end
|
|
274
249
|
|
|
275
|
-
it
|
|
250
|
+
it 'retains the correct length when calling to_a' do
|
|
276
251
|
expect(enumerable.to_a.length).to eq(2)
|
|
277
252
|
end
|
|
278
253
|
|
|
279
|
-
context
|
|
280
|
-
|
|
254
|
+
context 'when iterating over the association a second time' do
|
|
281
255
|
before do
|
|
282
256
|
enumerable.each { |post| post }
|
|
283
257
|
end
|
|
284
258
|
|
|
285
|
-
it
|
|
259
|
+
it 'retains the correct length' do
|
|
286
260
|
expect(enumerable.length).to eq(2)
|
|
287
261
|
end
|
|
288
262
|
|
|
289
|
-
it
|
|
263
|
+
it 'retains the correct length when calling to_a' do
|
|
290
264
|
expect(enumerable.to_a.length).to eq(2)
|
|
291
265
|
end
|
|
292
266
|
end
|
|
293
267
|
end
|
|
294
268
|
end
|
|
295
269
|
|
|
296
|
-
context
|
|
270
|
+
context 'when the documents have been loaded' do
|
|
297
271
|
let(:criteria) do
|
|
298
272
|
Post.where(person_id: person.id)
|
|
299
273
|
end
|
|
@@ -306,18 +280,17 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
306
280
|
enumerable.load_all!
|
|
307
281
|
end
|
|
308
282
|
|
|
309
|
-
it
|
|
283
|
+
it 'is _loaded' do
|
|
310
284
|
expect(enumerable._loaded?).to be true
|
|
311
285
|
end
|
|
312
286
|
|
|
313
|
-
it
|
|
314
|
-
expect(enumerable._unloaded).
|
|
287
|
+
it 'does not call #exists? on the unloaded scope' do
|
|
288
|
+
expect(enumerable._unloaded).not_to receive(:exists?)
|
|
315
289
|
expect(enumerable.empty?).to be false
|
|
316
290
|
end
|
|
317
291
|
end
|
|
318
292
|
|
|
319
|
-
context
|
|
320
|
-
|
|
293
|
+
context 'when the documents are not loaded' do
|
|
321
294
|
let(:criteria) do
|
|
322
295
|
Post.where(person_id: person.id)
|
|
323
296
|
end
|
|
@@ -326,35 +299,33 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
326
299
|
described_class.new(criteria)
|
|
327
300
|
end
|
|
328
301
|
|
|
329
|
-
it
|
|
302
|
+
it 'is not _loaded' do
|
|
330
303
|
expect(enumerable._loaded?).to be false
|
|
331
304
|
end
|
|
332
305
|
|
|
333
|
-
it
|
|
306
|
+
it 'calls #exists? on the unloaded scope' do
|
|
334
307
|
expect(enumerable._unloaded).to receive(:exists?)
|
|
335
308
|
expect(enumerable.empty?).to be true
|
|
336
309
|
end
|
|
337
310
|
|
|
338
|
-
context
|
|
339
|
-
|
|
311
|
+
context 'when documents are added' do
|
|
340
312
|
before do
|
|
341
313
|
enumerable << post_one
|
|
342
314
|
end
|
|
343
315
|
|
|
344
|
-
it
|
|
316
|
+
it 'is not _loaded' do
|
|
345
317
|
expect(enumerable._loaded?).to be false
|
|
346
318
|
end
|
|
347
319
|
|
|
348
|
-
it
|
|
349
|
-
expect(enumerable._unloaded).
|
|
320
|
+
it 'does not call #exists? on the unloaded scope' do
|
|
321
|
+
expect(enumerable._unloaded).not_to receive(:exists?)
|
|
350
322
|
expect(enumerable.empty?).to be false
|
|
351
323
|
end
|
|
352
324
|
end
|
|
353
325
|
end
|
|
354
326
|
end
|
|
355
327
|
|
|
356
|
-
describe
|
|
357
|
-
|
|
328
|
+
describe '#any?' do
|
|
358
329
|
let(:person) do
|
|
359
330
|
Person.create!
|
|
360
331
|
end
|
|
@@ -367,8 +338,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
367
338
|
Post.create!(person_id: person.id)
|
|
368
339
|
end
|
|
369
340
|
|
|
370
|
-
context
|
|
371
|
-
|
|
341
|
+
context 'when only a criteria target exists' do
|
|
372
342
|
let(:criteria) do
|
|
373
343
|
Post.where(person_id: person.id)
|
|
374
344
|
end
|
|
@@ -381,40 +351,38 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
381
351
|
enumerable.any?
|
|
382
352
|
end
|
|
383
353
|
|
|
384
|
-
it
|
|
354
|
+
it 'returns true' do
|
|
385
355
|
expect(any).to be true
|
|
386
356
|
end
|
|
387
357
|
|
|
388
358
|
context 'when #any? is called' do
|
|
389
|
-
|
|
390
359
|
before { any }
|
|
391
360
|
|
|
392
|
-
it
|
|
361
|
+
it 'retains the correct length' do
|
|
393
362
|
expect(enumerable.length).to eq(2)
|
|
394
363
|
end
|
|
395
364
|
|
|
396
|
-
it
|
|
365
|
+
it 'retains the correct length when calling to_a' do
|
|
397
366
|
expect(enumerable.to_a.length).to eq(2)
|
|
398
367
|
end
|
|
399
368
|
|
|
400
|
-
context
|
|
401
|
-
|
|
369
|
+
context 'when iterating over the association a second time' do
|
|
402
370
|
before do
|
|
403
371
|
enumerable.each { |post| post }
|
|
404
372
|
end
|
|
405
373
|
|
|
406
|
-
it
|
|
374
|
+
it 'retains the correct length' do
|
|
407
375
|
expect(enumerable.length).to eq(2)
|
|
408
376
|
end
|
|
409
377
|
|
|
410
|
-
it
|
|
378
|
+
it 'retains the correct length when calling to_a' do
|
|
411
379
|
expect(enumerable.to_a.length).to eq(2)
|
|
412
380
|
end
|
|
413
381
|
end
|
|
414
382
|
end
|
|
415
383
|
end
|
|
416
384
|
|
|
417
|
-
context
|
|
385
|
+
context 'when the documents have been loaded' do
|
|
418
386
|
let(:criteria) do
|
|
419
387
|
Post.where(person_id: person.id)
|
|
420
388
|
end
|
|
@@ -427,52 +395,49 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
427
395
|
enumerable.load_all!
|
|
428
396
|
end
|
|
429
397
|
|
|
430
|
-
it
|
|
398
|
+
it 'is _loaded' do
|
|
431
399
|
expect(enumerable._loaded?).to be true
|
|
432
400
|
end
|
|
433
401
|
|
|
434
|
-
it
|
|
435
|
-
expect(enumerable._unloaded).
|
|
402
|
+
it 'does not call #exists? on the unloaded scope' do
|
|
403
|
+
expect(enumerable._unloaded).not_to receive(:exists?)
|
|
436
404
|
expect(enumerable.any?).to be true
|
|
437
405
|
end
|
|
438
406
|
|
|
439
|
-
context
|
|
440
|
-
it
|
|
407
|
+
context 'when a block is given' do
|
|
408
|
+
it 'returns true when the predicate is true' do
|
|
441
409
|
expect(
|
|
442
|
-
enumerable.any? { |
|
|
410
|
+
enumerable.any? { |_doc| true }
|
|
443
411
|
).to be true
|
|
444
412
|
end
|
|
445
413
|
|
|
446
|
-
it
|
|
414
|
+
it 'returns false when the predicate is false' do
|
|
447
415
|
expect(
|
|
448
|
-
enumerable.any? { |
|
|
416
|
+
enumerable.any? { |_doc| false }
|
|
449
417
|
).to be false
|
|
450
418
|
end
|
|
451
419
|
end
|
|
452
420
|
|
|
453
|
-
context
|
|
454
|
-
|
|
455
|
-
it "returns true when the argument is true" do
|
|
421
|
+
context 'when an argument is given' do
|
|
422
|
+
it 'returns true when the argument is true' do
|
|
456
423
|
expect(enumerable.any?(Post)).to be true
|
|
457
424
|
end
|
|
458
425
|
|
|
459
|
-
it
|
|
426
|
+
it 'returns false when the argument is false' do
|
|
460
427
|
expect(enumerable.any?(Sandwich)).to be false
|
|
461
428
|
end
|
|
462
429
|
end
|
|
463
430
|
|
|
464
|
-
context
|
|
465
|
-
|
|
466
|
-
it "gives precedence to the pattern" do
|
|
431
|
+
context 'when both an argument and a block are given' do
|
|
432
|
+
it 'gives precedence to the pattern' do
|
|
467
433
|
expect(
|
|
468
|
-
enumerable.any?(Post) { |
|
|
434
|
+
enumerable.any?(Post) { |_doc| false }
|
|
469
435
|
).to be true
|
|
470
436
|
end
|
|
471
437
|
end
|
|
472
438
|
end
|
|
473
439
|
|
|
474
|
-
context
|
|
475
|
-
|
|
440
|
+
context 'when the documents are not loaded' do
|
|
476
441
|
let(:criteria) do
|
|
477
442
|
Post.where(person_id: person.id)
|
|
478
443
|
end
|
|
@@ -481,125 +446,115 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
481
446
|
described_class.new(criteria)
|
|
482
447
|
end
|
|
483
448
|
|
|
484
|
-
it
|
|
449
|
+
it 'is not _loaded' do
|
|
485
450
|
expect(enumerable._loaded?).to be false
|
|
486
451
|
end
|
|
487
452
|
|
|
488
|
-
it
|
|
453
|
+
it 'calls #exists? on the unloaded scope' do
|
|
489
454
|
expect(enumerable._unloaded).to receive(:exists?)
|
|
490
455
|
expect(enumerable.any?).to be false
|
|
491
456
|
end
|
|
492
457
|
|
|
493
|
-
context
|
|
494
|
-
|
|
458
|
+
context 'when documents are added' do
|
|
495
459
|
before do
|
|
496
460
|
enumerable << post_one
|
|
497
461
|
end
|
|
498
462
|
|
|
499
|
-
it
|
|
463
|
+
it 'is not _loaded' do
|
|
500
464
|
expect(enumerable._loaded?).to be false
|
|
501
465
|
end
|
|
502
466
|
|
|
503
|
-
it
|
|
504
|
-
expect(enumerable._unloaded).
|
|
467
|
+
it 'does not call #exists? on the unloaded scope' do
|
|
468
|
+
expect(enumerable._unloaded).not_to receive(:exists?)
|
|
505
469
|
expect(enumerable.any?).to be true
|
|
506
470
|
end
|
|
507
471
|
end
|
|
508
472
|
|
|
509
|
-
context
|
|
510
|
-
it
|
|
473
|
+
context 'when a block is given' do
|
|
474
|
+
it 'returns true when the predicate is true' do
|
|
511
475
|
expect(
|
|
512
|
-
enumerable.any? { |
|
|
476
|
+
enumerable.any? { |_doc| true }
|
|
513
477
|
).to be true
|
|
514
478
|
end
|
|
515
479
|
|
|
516
|
-
it
|
|
480
|
+
it 'returns false when the predicate is false' do
|
|
517
481
|
expect(
|
|
518
|
-
enumerable.any? { |
|
|
482
|
+
enumerable.any? { |_doc| false }
|
|
519
483
|
).to be false
|
|
520
484
|
end
|
|
521
485
|
end
|
|
522
486
|
|
|
523
|
-
context
|
|
524
|
-
|
|
525
|
-
it "returns true when the argument is true" do
|
|
487
|
+
context 'when an argument is given' do
|
|
488
|
+
it 'returns true when the argument is true' do
|
|
526
489
|
expect(enumerable.any?(Post)).to be true
|
|
527
490
|
end
|
|
528
491
|
|
|
529
|
-
it
|
|
492
|
+
it 'returns false when the argument is false' do
|
|
530
493
|
expect(enumerable.any?(Sandwich)).to be false
|
|
531
494
|
end
|
|
532
495
|
end
|
|
533
496
|
|
|
534
|
-
context
|
|
535
|
-
|
|
536
|
-
it "gives precedence to the pattern" do
|
|
497
|
+
context 'when both an argument and a block are given' do
|
|
498
|
+
it 'gives precedence to the pattern' do
|
|
537
499
|
expect(
|
|
538
|
-
enumerable.any?(Post) { |
|
|
500
|
+
enumerable.any?(Post) { |_doc| false }
|
|
539
501
|
).to be true
|
|
540
502
|
end
|
|
541
503
|
end
|
|
542
504
|
end
|
|
543
505
|
end
|
|
544
506
|
|
|
545
|
-
describe
|
|
507
|
+
describe '#clear' do
|
|
508
|
+
let(:person) { Person.create! }
|
|
509
|
+
let(:post) { Post.create!(person_id: person.id) }
|
|
510
|
+
let(:post_two) { Post.create!(person_id: person.id) }
|
|
511
|
+
let(:criteria) { Post.where(person_id: person.id) }
|
|
512
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
546
513
|
|
|
547
|
-
let(:
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
let!(:post) do
|
|
552
|
-
Post.create!(person_id: person.id)
|
|
553
|
-
end
|
|
554
|
-
|
|
555
|
-
let!(:post_two) do
|
|
556
|
-
Post.create!(person_id: person.id)
|
|
557
|
-
end
|
|
558
|
-
|
|
559
|
-
let(:criteria) do
|
|
560
|
-
Post.where(person_id: person.id)
|
|
561
|
-
end
|
|
562
|
-
|
|
563
|
-
let(:enumerable) do
|
|
564
|
-
described_class.new(criteria)
|
|
514
|
+
let(:clear) do
|
|
515
|
+
enumerable.clear do |doc|
|
|
516
|
+
expect(doc).to be_a(Post)
|
|
517
|
+
end
|
|
565
518
|
end
|
|
566
519
|
|
|
567
520
|
before do
|
|
521
|
+
post
|
|
522
|
+
post_two
|
|
523
|
+
|
|
568
524
|
enumerable._loaded[post.id] = post
|
|
569
525
|
enumerable << post
|
|
570
|
-
end
|
|
571
526
|
|
|
572
|
-
|
|
573
|
-
enumerable.clear do |doc|
|
|
574
|
-
expect(doc).to be_a(Post)
|
|
575
|
-
end
|
|
527
|
+
clear
|
|
576
528
|
end
|
|
577
529
|
|
|
578
|
-
it
|
|
530
|
+
it 'clears out the loaded docs' do
|
|
579
531
|
expect(enumerable._loaded).to be_empty
|
|
580
532
|
end
|
|
581
533
|
|
|
582
|
-
it
|
|
534
|
+
it 'clears out the added docs' do
|
|
583
535
|
expect(enumerable._added).to be_empty
|
|
584
536
|
end
|
|
585
537
|
|
|
586
|
-
it
|
|
587
|
-
expect(enumerable).
|
|
538
|
+
it 'retains its loaded state' do
|
|
539
|
+
expect(enumerable).not_to be__loaded
|
|
588
540
|
end
|
|
589
541
|
end
|
|
590
542
|
|
|
591
|
-
describe
|
|
592
|
-
|
|
543
|
+
describe '#clone' do
|
|
593
544
|
let(:person) do
|
|
594
545
|
Person.create!
|
|
595
546
|
end
|
|
596
547
|
|
|
548
|
+
let(:cloned) do
|
|
549
|
+
enumerable.clone
|
|
550
|
+
end
|
|
551
|
+
|
|
597
552
|
let!(:post) do
|
|
598
|
-
Post.create!(title:
|
|
553
|
+
Post.create!(title: 'one', person_id: person.id)
|
|
599
554
|
end
|
|
600
555
|
|
|
601
556
|
let!(:post_two) do
|
|
602
|
-
Post.create!(title:
|
|
557
|
+
Post.create!(title: 'two', person_id: person.id)
|
|
603
558
|
end
|
|
604
559
|
|
|
605
560
|
let(:criteria) do
|
|
@@ -615,27 +570,21 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
615
570
|
enumerable << post_two
|
|
616
571
|
end
|
|
617
572
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
end
|
|
621
|
-
|
|
622
|
-
it "does not retain the first id" do
|
|
623
|
-
expect(cloned.first).to_not eq(post)
|
|
573
|
+
it 'does not retain the first id' do
|
|
574
|
+
expect(cloned.first).not_to eq(post)
|
|
624
575
|
end
|
|
625
576
|
|
|
626
|
-
it
|
|
627
|
-
expect(cloned.last).
|
|
577
|
+
it 'does not retain the last id' do
|
|
578
|
+
expect(cloned.last).not_to eq(post_two)
|
|
628
579
|
end
|
|
629
580
|
end
|
|
630
581
|
|
|
631
|
-
describe
|
|
632
|
-
|
|
582
|
+
describe '#delete' do
|
|
633
583
|
let(:person) do
|
|
634
584
|
Person.create!
|
|
635
585
|
end
|
|
636
586
|
|
|
637
|
-
context
|
|
638
|
-
|
|
587
|
+
context 'when the document is loaded' do
|
|
639
588
|
let!(:post) do
|
|
640
589
|
Post.create!(person_id: person.id)
|
|
641
590
|
end
|
|
@@ -648,75 +597,57 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
648
597
|
enumerable.delete(post)
|
|
649
598
|
end
|
|
650
599
|
|
|
651
|
-
it
|
|
600
|
+
it 'deletes the document from the enumerable' do
|
|
652
601
|
expect(enumerable._loaded).to be_empty
|
|
653
602
|
end
|
|
654
603
|
|
|
655
|
-
it
|
|
604
|
+
it 'returns the document' do
|
|
656
605
|
expect(deleted).to eq(post)
|
|
657
606
|
end
|
|
658
607
|
end
|
|
659
608
|
|
|
660
|
-
context
|
|
661
|
-
|
|
662
|
-
let
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
let(:criteria) do
|
|
667
|
-
Person.where(person_id: person.id)
|
|
668
|
-
end
|
|
669
|
-
|
|
670
|
-
let!(:enumerable) do
|
|
671
|
-
described_class.new(criteria)
|
|
672
|
-
end
|
|
609
|
+
context 'when the document is added' do
|
|
610
|
+
let(:post) { Post.new }
|
|
611
|
+
let(:deleted) { enumerable.delete(post) }
|
|
612
|
+
let(:criteria) { Person.where(person_id: person.id) }
|
|
613
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
673
614
|
|
|
674
615
|
before do
|
|
675
616
|
enumerable << post
|
|
617
|
+
deleted
|
|
676
618
|
end
|
|
677
619
|
|
|
678
|
-
|
|
679
|
-
enumerable.delete(post)
|
|
680
|
-
end
|
|
681
|
-
|
|
682
|
-
it "removes the document from the added docs" do
|
|
620
|
+
it 'removes the document from the added docs' do
|
|
683
621
|
expect(enumerable._added).to be_empty
|
|
684
622
|
end
|
|
685
623
|
|
|
686
|
-
it
|
|
624
|
+
it 'returns the document' do
|
|
687
625
|
expect(deleted).to eq(post)
|
|
688
626
|
end
|
|
689
627
|
end
|
|
690
628
|
|
|
691
|
-
context
|
|
692
|
-
|
|
693
|
-
let
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
let(:criteria) do
|
|
698
|
-
Post.where(person_id: person.id)
|
|
699
|
-
end
|
|
629
|
+
context 'when the document is unloaded' do
|
|
630
|
+
let(:post) { Post.create!(person_id: person.id) }
|
|
631
|
+
let(:criteria) { Post.where(person_id: person.id) }
|
|
632
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
633
|
+
let(:deleted) { enumerable.delete(post) }
|
|
700
634
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
let!(:deleted) do
|
|
706
|
-
enumerable.delete(post)
|
|
635
|
+
before do
|
|
636
|
+
enumerable
|
|
637
|
+
post
|
|
638
|
+
deleted
|
|
707
639
|
end
|
|
708
640
|
|
|
709
|
-
it
|
|
641
|
+
it 'does not load the document' do
|
|
710
642
|
expect(enumerable._loaded).to be_empty
|
|
711
643
|
end
|
|
712
644
|
|
|
713
|
-
it
|
|
645
|
+
it 'returns the document' do
|
|
714
646
|
expect(deleted).to eq(post)
|
|
715
647
|
end
|
|
716
648
|
end
|
|
717
649
|
|
|
718
|
-
context
|
|
719
|
-
|
|
650
|
+
context 'when the document is not found' do
|
|
720
651
|
let!(:post) do
|
|
721
652
|
Post.create!(person_id: person.id)
|
|
722
653
|
end
|
|
@@ -735,20 +666,18 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
735
666
|
end
|
|
736
667
|
end
|
|
737
668
|
|
|
738
|
-
it
|
|
669
|
+
it 'returns nil' do
|
|
739
670
|
expect(deleted).to be_nil
|
|
740
671
|
end
|
|
741
672
|
end
|
|
742
673
|
end
|
|
743
674
|
|
|
744
|
-
describe
|
|
745
|
-
|
|
675
|
+
describe '#delete_if' do
|
|
746
676
|
let(:person) do
|
|
747
677
|
Person.create!
|
|
748
678
|
end
|
|
749
679
|
|
|
750
|
-
context
|
|
751
|
-
|
|
680
|
+
context 'when the document is loaded' do
|
|
752
681
|
let!(:post) do
|
|
753
682
|
Post.create!(person_id: person.id)
|
|
754
683
|
end
|
|
@@ -761,48 +690,36 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
761
690
|
enumerable.delete_if { |doc| doc == post }
|
|
762
691
|
end
|
|
763
692
|
|
|
764
|
-
it
|
|
693
|
+
it 'deletes the document from the enumerable' do
|
|
765
694
|
expect(enumerable._loaded).to be_empty
|
|
766
695
|
end
|
|
767
696
|
|
|
768
|
-
it
|
|
697
|
+
it 'returns the remaining docs' do
|
|
769
698
|
expect(deleted).to be_empty
|
|
770
699
|
end
|
|
771
700
|
end
|
|
772
701
|
|
|
773
|
-
context
|
|
774
|
-
|
|
775
|
-
let
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
let(:criteria) do
|
|
780
|
-
Person.where(person_id: person.id)
|
|
781
|
-
end
|
|
782
|
-
|
|
783
|
-
let!(:enumerable) do
|
|
784
|
-
described_class.new(criteria)
|
|
785
|
-
end
|
|
702
|
+
context 'when the document is added' do
|
|
703
|
+
let(:post) { Post.new }
|
|
704
|
+
let(:deleted) { enumerable.delete_if { |doc| doc == post } }
|
|
705
|
+
let(:criteria) { Person.where(person_id: person.id) }
|
|
706
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
786
707
|
|
|
787
708
|
before do
|
|
788
709
|
enumerable << post
|
|
710
|
+
deleted
|
|
789
711
|
end
|
|
790
712
|
|
|
791
|
-
|
|
792
|
-
enumerable.delete_if { |doc| doc == post }
|
|
793
|
-
end
|
|
794
|
-
|
|
795
|
-
it "removes the document from the added docs" do
|
|
713
|
+
it 'removes the document from the added docs' do
|
|
796
714
|
expect(enumerable._added).to be_empty
|
|
797
715
|
end
|
|
798
716
|
|
|
799
|
-
it
|
|
717
|
+
it 'returns the remaining docs' do
|
|
800
718
|
expect(deleted).to be_empty
|
|
801
719
|
end
|
|
802
720
|
end
|
|
803
721
|
|
|
804
|
-
context
|
|
805
|
-
|
|
722
|
+
context 'when the document is unloaded' do
|
|
806
723
|
let!(:post) do
|
|
807
724
|
Post.create!(person_id: person.id)
|
|
808
725
|
end
|
|
@@ -819,17 +736,16 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
819
736
|
enumerable.delete_if { |doc| doc == post }
|
|
820
737
|
end
|
|
821
738
|
|
|
822
|
-
it
|
|
739
|
+
it 'does not load the document' do
|
|
823
740
|
expect(enumerable._loaded).to be_empty
|
|
824
741
|
end
|
|
825
742
|
|
|
826
|
-
it
|
|
743
|
+
it 'returns the remaining docs' do
|
|
827
744
|
expect(deleted).to be_empty
|
|
828
745
|
end
|
|
829
746
|
end
|
|
830
747
|
|
|
831
748
|
context "when the block doesn't match" do
|
|
832
|
-
|
|
833
749
|
let!(:post) do
|
|
834
750
|
Post.create!(person_id: person.id)
|
|
835
751
|
end
|
|
@@ -846,20 +762,19 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
846
762
|
enumerable.delete_if { |doc| doc == Post.new }
|
|
847
763
|
end
|
|
848
764
|
|
|
849
|
-
it
|
|
765
|
+
it 'returns the remaining docs' do
|
|
850
766
|
expect(deleted).to eq([ post ])
|
|
851
767
|
end
|
|
852
768
|
end
|
|
853
769
|
end
|
|
854
770
|
|
|
855
|
-
describe
|
|
856
|
-
|
|
771
|
+
describe '#detect' do
|
|
857
772
|
let(:person) do
|
|
858
773
|
Person.create!
|
|
859
774
|
end
|
|
860
775
|
|
|
861
776
|
let!(:post) do
|
|
862
|
-
Post.create!(person: person, title:
|
|
777
|
+
Post.create!(person: person, title: 'test')
|
|
863
778
|
end
|
|
864
779
|
|
|
865
780
|
let(:criteria) do
|
|
@@ -870,20 +785,18 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
870
785
|
described_class.new(criteria)
|
|
871
786
|
end
|
|
872
787
|
|
|
873
|
-
context
|
|
874
|
-
|
|
788
|
+
context 'when setting a value on the matching document' do
|
|
875
789
|
before do
|
|
876
|
-
enumerable.detect{ |post| post.title =
|
|
790
|
+
enumerable.detect { |post| post.title = 'test' }.rating = 10
|
|
877
791
|
end
|
|
878
792
|
|
|
879
|
-
it
|
|
880
|
-
expect(enumerable.detect{ |post| post.title =
|
|
793
|
+
it 'sets the value on the instance' do
|
|
794
|
+
expect(enumerable.detect { |post| post.title = 'test' }.rating).to eq(10)
|
|
881
795
|
end
|
|
882
796
|
end
|
|
883
797
|
end
|
|
884
798
|
|
|
885
|
-
describe
|
|
886
|
-
|
|
799
|
+
describe '#each' do
|
|
887
800
|
let(:person) do
|
|
888
801
|
Person.create!
|
|
889
802
|
end
|
|
@@ -892,8 +805,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
892
805
|
Post.create!(person_id: person.id)
|
|
893
806
|
end
|
|
894
807
|
|
|
895
|
-
context
|
|
896
|
-
|
|
808
|
+
context 'when only a criteria target exists' do
|
|
897
809
|
let(:criteria) do
|
|
898
810
|
Post.where(person_id: person.id)
|
|
899
811
|
end
|
|
@@ -903,21 +815,18 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
903
815
|
end
|
|
904
816
|
|
|
905
817
|
let!(:iterated) do
|
|
906
|
-
enumerable.
|
|
907
|
-
expect(doc).to be_a(Post)
|
|
908
|
-
end
|
|
818
|
+
expect(enumerable).to all(be_a(Post))
|
|
909
819
|
end
|
|
910
820
|
|
|
911
|
-
it
|
|
821
|
+
it 'loads each document' do
|
|
912
822
|
expect(enumerable._loaded).to eq({ post.id => post })
|
|
913
823
|
end
|
|
914
824
|
|
|
915
|
-
it
|
|
825
|
+
it 'becomes loaded' do
|
|
916
826
|
expect(enumerable).to be__loaded
|
|
917
827
|
end
|
|
918
828
|
|
|
919
829
|
context 'when the base association is accessed from each document' do
|
|
920
|
-
|
|
921
830
|
let(:persons) do
|
|
922
831
|
described_class.new(criteria).collect(&:person)
|
|
923
832
|
end
|
|
@@ -933,29 +842,25 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
933
842
|
end
|
|
934
843
|
end
|
|
935
844
|
|
|
936
|
-
context
|
|
937
|
-
|
|
845
|
+
context 'when only an array target exists' do
|
|
938
846
|
let!(:enumerable) do
|
|
939
847
|
described_class.new([ post ])
|
|
940
848
|
end
|
|
941
849
|
|
|
942
850
|
let!(:iterated) do
|
|
943
|
-
enumerable.
|
|
944
|
-
expect(doc).to be_a(Post)
|
|
945
|
-
end
|
|
851
|
+
expect(enumerable).to all(be_a(Post))
|
|
946
852
|
end
|
|
947
853
|
|
|
948
|
-
it
|
|
854
|
+
it 'does not alter the loaded docs' do
|
|
949
855
|
expect(enumerable._loaded).to eq({ post.id => post })
|
|
950
856
|
end
|
|
951
857
|
|
|
952
|
-
it
|
|
858
|
+
it 'stays loaded' do
|
|
953
859
|
expect(enumerable).to be__loaded
|
|
954
860
|
end
|
|
955
861
|
end
|
|
956
862
|
|
|
957
|
-
context
|
|
958
|
-
|
|
863
|
+
context 'when a criteria and added exist' do
|
|
959
864
|
let(:criteria) do
|
|
960
865
|
Post.where(person_id: person.id)
|
|
961
866
|
end
|
|
@@ -968,55 +873,48 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
968
873
|
Post.new
|
|
969
874
|
end
|
|
970
875
|
|
|
971
|
-
context
|
|
972
|
-
|
|
876
|
+
context 'when the added does not contain unloaded docs' do
|
|
973
877
|
before do
|
|
974
878
|
enumerable << post_two
|
|
975
879
|
end
|
|
976
880
|
|
|
977
881
|
let!(:iterated) do
|
|
978
|
-
enumerable.
|
|
979
|
-
expect(doc).to be_a(Post)
|
|
980
|
-
end
|
|
882
|
+
expect(enumerable).to all(be_a(Post))
|
|
981
883
|
end
|
|
982
884
|
|
|
983
|
-
it
|
|
885
|
+
it 'adds the unloaded to the loaded docs' do
|
|
984
886
|
expect(enumerable._loaded).to eq({ post.id => post })
|
|
985
887
|
end
|
|
986
888
|
|
|
987
|
-
it
|
|
889
|
+
it 'keeps the appended in the added docs' do
|
|
988
890
|
expect(enumerable._added).to eq({ post_two.id => post_two })
|
|
989
891
|
end
|
|
990
892
|
|
|
991
|
-
it
|
|
893
|
+
it 'stays loaded' do
|
|
992
894
|
expect(enumerable).to be__loaded
|
|
993
895
|
end
|
|
994
896
|
end
|
|
995
897
|
|
|
996
|
-
context
|
|
997
|
-
|
|
898
|
+
context 'when the added contains unloaded docs' do
|
|
998
899
|
before do
|
|
999
900
|
enumerable << post
|
|
1000
901
|
end
|
|
1001
902
|
|
|
1002
903
|
let!(:iterated) do
|
|
1003
|
-
enumerable.
|
|
1004
|
-
expect(doc).to be_a(Post)
|
|
1005
|
-
end
|
|
904
|
+
expect(enumerable).to all(be_a(Post))
|
|
1006
905
|
end
|
|
1007
906
|
|
|
1008
|
-
it
|
|
907
|
+
it 'adds the persisted added doc to the loaded' do
|
|
1009
908
|
expect(enumerable._loaded).to eq({ post.id => post })
|
|
1010
909
|
end
|
|
1011
910
|
|
|
1012
|
-
it
|
|
911
|
+
it 'stays loaded' do
|
|
1013
912
|
expect(enumerable).to be__loaded
|
|
1014
913
|
end
|
|
1015
914
|
end
|
|
1016
915
|
end
|
|
1017
916
|
|
|
1018
|
-
context
|
|
1019
|
-
|
|
917
|
+
context 'when no block is passed' do
|
|
1020
918
|
let(:criteria) do
|
|
1021
919
|
Post.where(person_id: person.id)
|
|
1022
920
|
end
|
|
@@ -1025,15 +923,13 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1025
923
|
described_class.new(criteria)
|
|
1026
924
|
end
|
|
1027
925
|
|
|
1028
|
-
it
|
|
926
|
+
it 'returns an enumerator' do
|
|
1029
927
|
expect(enumerable.each.class.include?(Enumerable)).to be true
|
|
1030
928
|
end
|
|
1031
|
-
|
|
1032
929
|
end
|
|
1033
930
|
end
|
|
1034
931
|
|
|
1035
|
-
describe
|
|
1036
|
-
|
|
932
|
+
describe '#entries' do
|
|
1037
933
|
let(:person) do
|
|
1038
934
|
Person.create!
|
|
1039
935
|
end
|
|
@@ -1046,34 +942,31 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1046
942
|
described_class.new(criteria)
|
|
1047
943
|
end
|
|
1048
944
|
|
|
1049
|
-
context
|
|
1050
|
-
|
|
945
|
+
context 'when the added contains a persisted document' do
|
|
1051
946
|
let!(:post) do
|
|
1052
947
|
Post.create!(person_id: person.id)
|
|
1053
948
|
end
|
|
1054
949
|
|
|
1055
|
-
before do
|
|
1056
|
-
enumerable << post
|
|
1057
|
-
end
|
|
1058
|
-
|
|
1059
950
|
let(:entries) do
|
|
1060
951
|
enumerable.entries
|
|
1061
952
|
end
|
|
1062
953
|
|
|
1063
|
-
|
|
954
|
+
before do
|
|
955
|
+
enumerable << post
|
|
956
|
+
end
|
|
957
|
+
|
|
958
|
+
it 'yields to the in memory documents first' do
|
|
1064
959
|
expect(entries.first).to equal(post)
|
|
1065
960
|
end
|
|
1066
961
|
end
|
|
1067
962
|
end
|
|
1068
963
|
|
|
1069
|
-
describe
|
|
1070
|
-
|
|
964
|
+
describe '#first' do
|
|
1071
965
|
let(:person) do
|
|
1072
966
|
Person.create!
|
|
1073
967
|
end
|
|
1074
968
|
|
|
1075
|
-
context
|
|
1076
|
-
|
|
969
|
+
context 'when the enumerable is not loaded' do
|
|
1077
970
|
let(:criteria) do
|
|
1078
971
|
Post.where(person_id: person.id)
|
|
1079
972
|
end
|
|
@@ -1082,10 +975,8 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1082
975
|
described_class.new(criteria)
|
|
1083
976
|
end
|
|
1084
977
|
|
|
1085
|
-
context
|
|
1086
|
-
|
|
1087
|
-
context "when added is empty" do
|
|
1088
|
-
|
|
978
|
+
context 'when unloaded is not empty' do
|
|
979
|
+
context 'when added is empty' do
|
|
1089
980
|
let!(:post) do
|
|
1090
981
|
Post.create!(person_id: person.id)
|
|
1091
982
|
end
|
|
@@ -1094,26 +985,29 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1094
985
|
enumerable.first
|
|
1095
986
|
end
|
|
1096
987
|
|
|
1097
|
-
it
|
|
988
|
+
it 'returns the first unloaded doc' do
|
|
1098
989
|
expect(first).to eq(post)
|
|
1099
990
|
end
|
|
1100
991
|
|
|
1101
|
-
it
|
|
1102
|
-
expect(enumerable).
|
|
992
|
+
it 'does not load the enumerable' do
|
|
993
|
+
expect(enumerable).not_to be__loaded
|
|
1103
994
|
end
|
|
1104
995
|
|
|
1105
|
-
it
|
|
996
|
+
it 'receives query only once' do
|
|
1106
997
|
expect(criteria).to receive(:first).once
|
|
1107
998
|
first
|
|
1108
999
|
end
|
|
1109
1000
|
end
|
|
1110
1001
|
|
|
1111
|
-
context
|
|
1112
|
-
|
|
1002
|
+
context 'when added is not empty' do
|
|
1113
1003
|
let!(:post) do
|
|
1114
1004
|
Post.create!(person_id: person.id)
|
|
1115
1005
|
end
|
|
1116
1006
|
|
|
1007
|
+
let(:first) do
|
|
1008
|
+
enumerable.first
|
|
1009
|
+
end
|
|
1010
|
+
|
|
1117
1011
|
let(:post_two) do
|
|
1118
1012
|
Post.new(person_id: person.id)
|
|
1119
1013
|
end
|
|
@@ -1122,66 +1016,57 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1122
1016
|
enumerable << post_two
|
|
1123
1017
|
end
|
|
1124
1018
|
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
end
|
|
1128
|
-
|
|
1129
|
-
context "when a perviously persisted unloaded doc exists" do
|
|
1130
|
-
|
|
1131
|
-
it "returns the first added doc" do
|
|
1019
|
+
context 'when a previously persisted unloaded doc exists' do
|
|
1020
|
+
it 'returns the first added doc' do
|
|
1132
1021
|
expect(first).to eq(post)
|
|
1133
1022
|
end
|
|
1134
1023
|
|
|
1135
|
-
it
|
|
1136
|
-
expect(enumerable).
|
|
1024
|
+
it 'does not load the enumerable' do
|
|
1025
|
+
expect(enumerable).not_to be__loaded
|
|
1137
1026
|
end
|
|
1138
1027
|
end
|
|
1139
1028
|
end
|
|
1140
1029
|
end
|
|
1141
1030
|
|
|
1142
|
-
context
|
|
1143
|
-
|
|
1031
|
+
context 'when unloaded is empty' do
|
|
1144
1032
|
let!(:post) do
|
|
1145
1033
|
Post.new(person_id: person.id)
|
|
1146
1034
|
end
|
|
1147
1035
|
|
|
1148
|
-
before do
|
|
1149
|
-
enumerable << post
|
|
1150
|
-
end
|
|
1151
|
-
|
|
1152
1036
|
let(:first) do
|
|
1153
1037
|
enumerable.first
|
|
1154
1038
|
end
|
|
1155
1039
|
|
|
1156
|
-
|
|
1040
|
+
before do
|
|
1041
|
+
enumerable << post
|
|
1042
|
+
end
|
|
1043
|
+
|
|
1044
|
+
it 'returns the first loaded doc' do
|
|
1157
1045
|
expect(first).to eq(post)
|
|
1158
1046
|
end
|
|
1159
1047
|
|
|
1160
|
-
it
|
|
1161
|
-
expect(enumerable).
|
|
1048
|
+
it 'does not load the enumerable' do
|
|
1049
|
+
expect(enumerable).not_to be__loaded
|
|
1162
1050
|
end
|
|
1163
1051
|
end
|
|
1164
1052
|
|
|
1165
|
-
context
|
|
1166
|
-
|
|
1053
|
+
context 'when unloaded and added are empty' do
|
|
1167
1054
|
let(:first) do
|
|
1168
1055
|
enumerable.first
|
|
1169
1056
|
end
|
|
1170
1057
|
|
|
1171
|
-
it
|
|
1058
|
+
it 'returns nil' do
|
|
1172
1059
|
expect(first).to be_nil
|
|
1173
1060
|
end
|
|
1174
1061
|
|
|
1175
|
-
it
|
|
1176
|
-
expect(enumerable).
|
|
1062
|
+
it 'does not load the enumerable' do
|
|
1063
|
+
expect(enumerable).not_to be__loaded
|
|
1177
1064
|
end
|
|
1178
1065
|
end
|
|
1179
1066
|
end
|
|
1180
1067
|
|
|
1181
|
-
context
|
|
1182
|
-
|
|
1183
|
-
context "when loaded is not empty" do
|
|
1184
|
-
|
|
1068
|
+
context 'when the enumerable is loaded' do
|
|
1069
|
+
context 'when loaded is not empty' do
|
|
1185
1070
|
let!(:post) do
|
|
1186
1071
|
Post.create!(person_id: person.id)
|
|
1187
1072
|
end
|
|
@@ -1194,17 +1079,20 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1194
1079
|
enumerable.first
|
|
1195
1080
|
end
|
|
1196
1081
|
|
|
1197
|
-
it
|
|
1082
|
+
it 'returns the first loaded doc' do
|
|
1198
1083
|
expect(first).to eq(post)
|
|
1199
1084
|
end
|
|
1200
1085
|
end
|
|
1201
1086
|
|
|
1202
|
-
context
|
|
1203
|
-
|
|
1087
|
+
context 'when loaded is empty' do
|
|
1204
1088
|
let!(:post) do
|
|
1205
1089
|
Post.create!(person_id: person.id)
|
|
1206
1090
|
end
|
|
1207
1091
|
|
|
1092
|
+
let(:first) do
|
|
1093
|
+
enumerable.first
|
|
1094
|
+
end
|
|
1095
|
+
|
|
1208
1096
|
let(:enumerable) do
|
|
1209
1097
|
described_class.new([])
|
|
1210
1098
|
end
|
|
@@ -1213,17 +1101,12 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1213
1101
|
enumerable << post
|
|
1214
1102
|
end
|
|
1215
1103
|
|
|
1216
|
-
|
|
1217
|
-
enumerable.first
|
|
1218
|
-
end
|
|
1219
|
-
|
|
1220
|
-
it "returns the first added doc" do
|
|
1104
|
+
it 'returns the first added doc' do
|
|
1221
1105
|
expect(first).to eq(post)
|
|
1222
1106
|
end
|
|
1223
1107
|
end
|
|
1224
1108
|
|
|
1225
|
-
context
|
|
1226
|
-
|
|
1109
|
+
context 'when loaded and added are empty' do
|
|
1227
1110
|
let(:enumerable) do
|
|
1228
1111
|
described_class.new([])
|
|
1229
1112
|
end
|
|
@@ -1232,14 +1115,13 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1232
1115
|
enumerable.first
|
|
1233
1116
|
end
|
|
1234
1117
|
|
|
1235
|
-
it
|
|
1118
|
+
it 'returns nil' do
|
|
1236
1119
|
expect(first).to be_nil
|
|
1237
1120
|
end
|
|
1238
1121
|
end
|
|
1239
1122
|
end
|
|
1240
1123
|
|
|
1241
1124
|
context 'when including a limit' do
|
|
1242
|
-
|
|
1243
1125
|
let(:person) do
|
|
1244
1126
|
Person.create!
|
|
1245
1127
|
end
|
|
@@ -1253,20 +1135,19 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1253
1135
|
end
|
|
1254
1136
|
|
|
1255
1137
|
let!(:first_post) do
|
|
1256
|
-
person.posts.create!(title:
|
|
1138
|
+
person.posts.create!(title: 'One')
|
|
1257
1139
|
end
|
|
1258
1140
|
|
|
1259
1141
|
let!(:second_post) do
|
|
1260
|
-
person.posts.create!(title:
|
|
1142
|
+
person.posts.create!(title: 'Two')
|
|
1261
1143
|
end
|
|
1262
1144
|
|
|
1263
1145
|
it 'returns the matching document' do
|
|
1264
|
-
expect(enumerable.first(1)).to eq([first_post])
|
|
1146
|
+
expect(enumerable.first(1)).to eq([ first_post ])
|
|
1265
1147
|
end
|
|
1266
1148
|
end
|
|
1267
1149
|
|
|
1268
1150
|
context 'when no parameters are provided' do
|
|
1269
|
-
|
|
1270
1151
|
let(:person) do
|
|
1271
1152
|
Person.create!
|
|
1272
1153
|
end
|
|
@@ -1280,11 +1161,11 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1280
1161
|
end
|
|
1281
1162
|
|
|
1282
1163
|
let!(:first_post) do
|
|
1283
|
-
person.posts.create!(title:
|
|
1164
|
+
person.posts.create!(title: 'One')
|
|
1284
1165
|
end
|
|
1285
1166
|
|
|
1286
1167
|
let!(:second_post) do
|
|
1287
|
-
person.posts.create!(title:
|
|
1168
|
+
person.posts.create!(title: 'Two')
|
|
1288
1169
|
end
|
|
1289
1170
|
|
|
1290
1171
|
it 'uses the sort on id' do
|
|
@@ -1293,8 +1174,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1293
1174
|
end
|
|
1294
1175
|
end
|
|
1295
1176
|
|
|
1296
|
-
describe
|
|
1297
|
-
|
|
1177
|
+
describe '#include?' do
|
|
1298
1178
|
let(:person) do
|
|
1299
1179
|
Person.create!
|
|
1300
1180
|
end
|
|
@@ -1307,10 +1187,8 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1307
1187
|
Post.create!(person_id: person.id)
|
|
1308
1188
|
end
|
|
1309
1189
|
|
|
1310
|
-
context
|
|
1311
|
-
|
|
1312
|
-
context "when the enumerable is loaded" do
|
|
1313
|
-
|
|
1190
|
+
context 'when no criteria exists' do
|
|
1191
|
+
context 'when the enumerable is loaded' do
|
|
1314
1192
|
let!(:enumerable) do
|
|
1315
1193
|
described_class.new([ post_one, post_two ])
|
|
1316
1194
|
end
|
|
@@ -1319,45 +1197,34 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1319
1197
|
enumerable.include?(post_two)
|
|
1320
1198
|
end
|
|
1321
1199
|
|
|
1322
|
-
it
|
|
1200
|
+
it 'returns true' do
|
|
1323
1201
|
expect(included).to be true
|
|
1324
1202
|
end
|
|
1325
1203
|
|
|
1326
|
-
it
|
|
1204
|
+
it 'retains the correct length' do
|
|
1327
1205
|
expect(enumerable.length).to eq(2)
|
|
1328
1206
|
end
|
|
1329
1207
|
|
|
1330
|
-
it
|
|
1208
|
+
it 'retains the correct length when calling to_a' do
|
|
1331
1209
|
expect(enumerable.to_a.length).to eq(2)
|
|
1332
1210
|
end
|
|
1333
1211
|
end
|
|
1334
1212
|
|
|
1335
|
-
context
|
|
1336
|
-
|
|
1337
|
-
let
|
|
1338
|
-
described_class.new([])
|
|
1339
|
-
end
|
|
1340
|
-
|
|
1341
|
-
let(:post_three) do
|
|
1342
|
-
Post.new(person_id: person)
|
|
1343
|
-
end
|
|
1213
|
+
context 'when the enumerable contains an added document' do
|
|
1214
|
+
let(:enumerable) { described_class.new([]) }
|
|
1215
|
+
let(:post_three) { Post.new(person_id: person) }
|
|
1344
1216
|
|
|
1345
1217
|
before do
|
|
1346
1218
|
enumerable.push(post_three)
|
|
1347
1219
|
end
|
|
1348
1220
|
|
|
1349
|
-
|
|
1350
|
-
enumerable.include?(post_three)
|
|
1351
|
-
end
|
|
1352
|
-
|
|
1353
|
-
it "returns true" do
|
|
1354
|
-
expect(included).to be true
|
|
1221
|
+
it 'returns true' do
|
|
1222
|
+
expect(enumerable.include?(post_three)).to be true
|
|
1355
1223
|
end
|
|
1356
1224
|
end
|
|
1357
1225
|
end
|
|
1358
1226
|
|
|
1359
|
-
context
|
|
1360
|
-
|
|
1227
|
+
context 'when the document is present and not the first' do
|
|
1361
1228
|
let(:criteria) do
|
|
1362
1229
|
Post.where(person_id: person.id)
|
|
1363
1230
|
end
|
|
@@ -1370,43 +1237,40 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1370
1237
|
enumerable.include?(post_two)
|
|
1371
1238
|
end
|
|
1372
1239
|
|
|
1373
|
-
it
|
|
1240
|
+
it 'returns true' do
|
|
1374
1241
|
expect(included).to be true
|
|
1375
1242
|
end
|
|
1376
1243
|
|
|
1377
|
-
it
|
|
1244
|
+
it 'retains the correct length' do
|
|
1378
1245
|
expect(enumerable.length).to eq(2)
|
|
1379
1246
|
end
|
|
1380
1247
|
|
|
1381
|
-
it
|
|
1248
|
+
it 'retains the correct length when calling to_a' do
|
|
1382
1249
|
expect(enumerable.to_a.length).to eq(2)
|
|
1383
1250
|
end
|
|
1384
1251
|
|
|
1385
|
-
context
|
|
1386
|
-
|
|
1252
|
+
context 'when iterating over the association a second time' do
|
|
1387
1253
|
before do
|
|
1388
1254
|
enumerable.each { |post| post }
|
|
1389
1255
|
end
|
|
1390
1256
|
|
|
1391
|
-
it
|
|
1257
|
+
it 'retains the correct length' do
|
|
1392
1258
|
expect(enumerable.length).to eq(2)
|
|
1393
1259
|
end
|
|
1394
1260
|
|
|
1395
|
-
it
|
|
1261
|
+
it 'retains the correct length when calling to_a' do
|
|
1396
1262
|
expect(enumerable.to_a.length).to eq(2)
|
|
1397
1263
|
end
|
|
1398
1264
|
end
|
|
1399
1265
|
end
|
|
1400
1266
|
end
|
|
1401
1267
|
|
|
1402
|
-
describe
|
|
1403
|
-
|
|
1268
|
+
describe '#initialize' do
|
|
1404
1269
|
let(:person) do
|
|
1405
1270
|
Person.new
|
|
1406
1271
|
end
|
|
1407
1272
|
|
|
1408
|
-
context
|
|
1409
|
-
|
|
1273
|
+
context 'when provided with a criteria' do
|
|
1410
1274
|
let(:criteria) do
|
|
1411
1275
|
Post.where(person_id: person.id)
|
|
1412
1276
|
end
|
|
@@ -1415,17 +1279,16 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1415
1279
|
described_class.new(criteria)
|
|
1416
1280
|
end
|
|
1417
1281
|
|
|
1418
|
-
it
|
|
1282
|
+
it 'sets the criteria' do
|
|
1419
1283
|
expect(enumerable._unloaded).to eq(criteria)
|
|
1420
1284
|
end
|
|
1421
1285
|
|
|
1422
|
-
it
|
|
1423
|
-
expect(enumerable).
|
|
1286
|
+
it 'is not loaded' do
|
|
1287
|
+
expect(enumerable).not_to be__loaded
|
|
1424
1288
|
end
|
|
1425
1289
|
end
|
|
1426
1290
|
|
|
1427
|
-
context
|
|
1428
|
-
|
|
1291
|
+
context 'when provided an array' do
|
|
1429
1292
|
let(:post) do
|
|
1430
1293
|
Post.new
|
|
1431
1294
|
end
|
|
@@ -1434,28 +1297,30 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1434
1297
|
described_class.new([ post ])
|
|
1435
1298
|
end
|
|
1436
1299
|
|
|
1437
|
-
it
|
|
1300
|
+
it 'does not set a criteria' do
|
|
1438
1301
|
expect(enumerable._unloaded).to be_nil
|
|
1439
1302
|
end
|
|
1440
1303
|
|
|
1441
|
-
it
|
|
1304
|
+
it 'is loaded' do
|
|
1442
1305
|
expect(enumerable).to be__loaded
|
|
1443
1306
|
end
|
|
1444
1307
|
end
|
|
1445
1308
|
end
|
|
1446
1309
|
|
|
1447
|
-
describe
|
|
1448
|
-
|
|
1310
|
+
describe '#in_memory' do
|
|
1449
1311
|
let(:person) do
|
|
1450
1312
|
Person.new
|
|
1451
1313
|
end
|
|
1452
1314
|
|
|
1453
|
-
context
|
|
1454
|
-
|
|
1315
|
+
context 'when the enumerable is loaded' do
|
|
1455
1316
|
let(:post) do
|
|
1456
1317
|
Post.new
|
|
1457
1318
|
end
|
|
1458
1319
|
|
|
1320
|
+
let(:in_memory) do
|
|
1321
|
+
enumerable.in_memory
|
|
1322
|
+
end
|
|
1323
|
+
|
|
1459
1324
|
let(:enumerable) do
|
|
1460
1325
|
described_class.new([ post ])
|
|
1461
1326
|
end
|
|
@@ -1468,21 +1333,20 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1468
1333
|
enumerable << post_two
|
|
1469
1334
|
end
|
|
1470
1335
|
|
|
1471
|
-
|
|
1472
|
-
enumerable.in_memory
|
|
1473
|
-
end
|
|
1474
|
-
|
|
1475
|
-
it "returns the loaded and added docs" do
|
|
1336
|
+
it 'returns the loaded and added docs' do
|
|
1476
1337
|
expect(in_memory).to eq([ post, post_two ])
|
|
1477
1338
|
end
|
|
1478
1339
|
end
|
|
1479
1340
|
|
|
1480
|
-
context
|
|
1481
|
-
|
|
1341
|
+
context 'when the enumerable is not loaded' do
|
|
1482
1342
|
let(:post) do
|
|
1483
1343
|
Post.new(person_id: person.id)
|
|
1484
1344
|
end
|
|
1485
1345
|
|
|
1346
|
+
let(:in_memory) do
|
|
1347
|
+
enumerable.in_memory
|
|
1348
|
+
end
|
|
1349
|
+
|
|
1486
1350
|
let(:enumerable) do
|
|
1487
1351
|
described_class.new(Post.where(person_id: person.id))
|
|
1488
1352
|
end
|
|
@@ -1495,17 +1359,12 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1495
1359
|
enumerable << post_two
|
|
1496
1360
|
end
|
|
1497
1361
|
|
|
1498
|
-
|
|
1499
|
-
enumerable.in_memory
|
|
1500
|
-
end
|
|
1501
|
-
|
|
1502
|
-
it "returns the added docs" do
|
|
1362
|
+
it 'returns the added docs' do
|
|
1503
1363
|
expect(in_memory).to eq([ post_two ])
|
|
1504
1364
|
end
|
|
1505
1365
|
end
|
|
1506
1366
|
|
|
1507
|
-
context
|
|
1508
|
-
|
|
1367
|
+
context 'when passed a block' do
|
|
1509
1368
|
let(:enumerable) do
|
|
1510
1369
|
described_class.new(Post.where(person_id: person.id))
|
|
1511
1370
|
end
|
|
@@ -1518,7 +1377,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1518
1377
|
enumerable << post_two
|
|
1519
1378
|
end
|
|
1520
1379
|
|
|
1521
|
-
it
|
|
1380
|
+
it 'yields to each in memory document' do
|
|
1522
1381
|
enumerable.in_memory do |doc|
|
|
1523
1382
|
expect(doc).to eq(post_two)
|
|
1524
1383
|
end
|
|
@@ -1526,35 +1385,30 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1526
1385
|
end
|
|
1527
1386
|
end
|
|
1528
1387
|
|
|
1529
|
-
describe
|
|
1530
|
-
|
|
1388
|
+
describe '#is_a?' do
|
|
1531
1389
|
let(:enumerable) do
|
|
1532
1390
|
described_class.new(Post.all)
|
|
1533
1391
|
end
|
|
1534
1392
|
|
|
1535
|
-
context
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
expect(enumerable.is_a?(::Enumerable)).to be true
|
|
1393
|
+
context 'when checking against enumerable' do
|
|
1394
|
+
it 'returns true' do
|
|
1395
|
+
expect(enumerable.is_a?(Enumerable)).to be true
|
|
1539
1396
|
end
|
|
1540
1397
|
end
|
|
1541
1398
|
|
|
1542
|
-
context
|
|
1543
|
-
|
|
1544
|
-
it "returns true" do
|
|
1399
|
+
context 'when checking against array' do
|
|
1400
|
+
it 'returns true' do
|
|
1545
1401
|
expect(enumerable.is_a?(Array)).to be true
|
|
1546
1402
|
end
|
|
1547
1403
|
end
|
|
1548
1404
|
end
|
|
1549
1405
|
|
|
1550
|
-
describe
|
|
1551
|
-
|
|
1406
|
+
describe '#last' do
|
|
1552
1407
|
let(:person) do
|
|
1553
1408
|
Person.create!
|
|
1554
1409
|
end
|
|
1555
1410
|
|
|
1556
|
-
context
|
|
1557
|
-
|
|
1411
|
+
context 'when the enumerable is not loaded' do
|
|
1558
1412
|
let(:criteria) do
|
|
1559
1413
|
Post.asc(:_id).where(person_id: person.id)
|
|
1560
1414
|
end
|
|
@@ -1563,8 +1417,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1563
1417
|
described_class.new(criteria)
|
|
1564
1418
|
end
|
|
1565
1419
|
|
|
1566
|
-
context
|
|
1567
|
-
|
|
1420
|
+
context 'when unloaded is not empty' do
|
|
1568
1421
|
let!(:post) do
|
|
1569
1422
|
Post.create!(person_id: person.id)
|
|
1570
1423
|
end
|
|
@@ -1573,60 +1426,57 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1573
1426
|
enumerable.last
|
|
1574
1427
|
end
|
|
1575
1428
|
|
|
1576
|
-
it
|
|
1429
|
+
it 'returns the last unloaded doc' do
|
|
1577
1430
|
expect(last).to eq(post)
|
|
1578
1431
|
end
|
|
1579
1432
|
|
|
1580
|
-
it
|
|
1581
|
-
expect(enumerable).
|
|
1433
|
+
it 'does not load the enumerable' do
|
|
1434
|
+
expect(enumerable).not_to be__loaded
|
|
1582
1435
|
end
|
|
1583
1436
|
|
|
1584
|
-
it
|
|
1437
|
+
it 'receives query only once' do
|
|
1585
1438
|
expect(criteria).to receive(:last).once
|
|
1586
1439
|
last
|
|
1587
1440
|
end
|
|
1588
1441
|
end
|
|
1589
1442
|
|
|
1590
|
-
context
|
|
1591
|
-
|
|
1443
|
+
context 'when unloaded is empty' do
|
|
1592
1444
|
let!(:post) do
|
|
1593
1445
|
Post.new(person_id: person.id)
|
|
1594
1446
|
end
|
|
1595
1447
|
|
|
1596
|
-
before do
|
|
1597
|
-
enumerable << post
|
|
1598
|
-
end
|
|
1599
|
-
|
|
1600
1448
|
let(:last) do
|
|
1601
1449
|
enumerable.last
|
|
1602
1450
|
end
|
|
1603
1451
|
|
|
1604
|
-
|
|
1452
|
+
before do
|
|
1453
|
+
enumerable << post
|
|
1454
|
+
end
|
|
1455
|
+
|
|
1456
|
+
it 'returns the last unloaded doc' do
|
|
1605
1457
|
expect(last).to eq(post)
|
|
1606
1458
|
end
|
|
1607
1459
|
|
|
1608
|
-
it
|
|
1609
|
-
expect(enumerable).
|
|
1460
|
+
it 'does not load the enumerable' do
|
|
1461
|
+
expect(enumerable).not_to be__loaded
|
|
1610
1462
|
end
|
|
1611
1463
|
end
|
|
1612
1464
|
|
|
1613
|
-
context
|
|
1614
|
-
|
|
1465
|
+
context 'when unloaded and added are empty' do
|
|
1615
1466
|
let(:last) do
|
|
1616
1467
|
enumerable.last
|
|
1617
1468
|
end
|
|
1618
1469
|
|
|
1619
|
-
it
|
|
1470
|
+
it 'returns nil' do
|
|
1620
1471
|
expect(last).to be_nil
|
|
1621
1472
|
end
|
|
1622
1473
|
|
|
1623
|
-
it
|
|
1624
|
-
expect(enumerable).
|
|
1474
|
+
it 'does not load the enumerable' do
|
|
1475
|
+
expect(enumerable).not_to be__loaded
|
|
1625
1476
|
end
|
|
1626
1477
|
end
|
|
1627
1478
|
|
|
1628
|
-
context
|
|
1629
|
-
|
|
1479
|
+
context 'when added is not empty' do
|
|
1630
1480
|
let!(:post_one) do
|
|
1631
1481
|
person.posts.create!
|
|
1632
1482
|
end
|
|
@@ -1639,19 +1489,16 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1639
1489
|
enumerable.last
|
|
1640
1490
|
end
|
|
1641
1491
|
|
|
1642
|
-
context
|
|
1643
|
-
|
|
1644
|
-
it "returns the last document" do
|
|
1492
|
+
context 'when accessing from a reloaded child' do
|
|
1493
|
+
it 'returns the last document' do
|
|
1645
1494
|
expect(post_one.reload.person.posts.asc(:_id).last).to eq(post_two)
|
|
1646
1495
|
end
|
|
1647
1496
|
end
|
|
1648
1497
|
end
|
|
1649
1498
|
end
|
|
1650
1499
|
|
|
1651
|
-
context
|
|
1652
|
-
|
|
1653
|
-
context "when loaded is not empty" do
|
|
1654
|
-
|
|
1500
|
+
context 'when the enumerable is loaded' do
|
|
1501
|
+
context 'when loaded is not empty' do
|
|
1655
1502
|
let!(:post) do
|
|
1656
1503
|
Post.create!(person_id: person.id)
|
|
1657
1504
|
end
|
|
@@ -1664,17 +1511,20 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1664
1511
|
enumerable.last
|
|
1665
1512
|
end
|
|
1666
1513
|
|
|
1667
|
-
it
|
|
1514
|
+
it 'returns the last loaded doc' do
|
|
1668
1515
|
expect(last).to eq(post)
|
|
1669
1516
|
end
|
|
1670
1517
|
end
|
|
1671
1518
|
|
|
1672
|
-
context
|
|
1673
|
-
|
|
1519
|
+
context 'when loaded is empty' do
|
|
1674
1520
|
let!(:post) do
|
|
1675
1521
|
Post.create!(person_id: person.id)
|
|
1676
1522
|
end
|
|
1677
1523
|
|
|
1524
|
+
let(:last) do
|
|
1525
|
+
enumerable.last
|
|
1526
|
+
end
|
|
1527
|
+
|
|
1678
1528
|
let(:enumerable) do
|
|
1679
1529
|
described_class.new([])
|
|
1680
1530
|
end
|
|
@@ -1683,17 +1533,12 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1683
1533
|
enumerable << post
|
|
1684
1534
|
end
|
|
1685
1535
|
|
|
1686
|
-
|
|
1687
|
-
enumerable.last
|
|
1688
|
-
end
|
|
1689
|
-
|
|
1690
|
-
it "returns the last added doc" do
|
|
1536
|
+
it 'returns the last added doc' do
|
|
1691
1537
|
expect(last).to eq(post)
|
|
1692
1538
|
end
|
|
1693
1539
|
end
|
|
1694
1540
|
|
|
1695
|
-
context
|
|
1696
|
-
|
|
1541
|
+
context 'when loaded and added are empty' do
|
|
1697
1542
|
let(:enumerable) do
|
|
1698
1543
|
described_class.new([])
|
|
1699
1544
|
end
|
|
@@ -1702,14 +1547,13 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1702
1547
|
enumerable.last
|
|
1703
1548
|
end
|
|
1704
1549
|
|
|
1705
|
-
it
|
|
1550
|
+
it 'returns nil' do
|
|
1706
1551
|
expect(last).to be_nil
|
|
1707
1552
|
end
|
|
1708
1553
|
end
|
|
1709
1554
|
end
|
|
1710
1555
|
|
|
1711
1556
|
context 'when including a limit' do
|
|
1712
|
-
|
|
1713
1557
|
let(:person) do
|
|
1714
1558
|
Person.create!
|
|
1715
1559
|
end
|
|
@@ -1723,20 +1567,19 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1723
1567
|
end
|
|
1724
1568
|
|
|
1725
1569
|
let!(:first_post) do
|
|
1726
|
-
person.posts.create!(title:
|
|
1570
|
+
person.posts.create!(title: 'One')
|
|
1727
1571
|
end
|
|
1728
1572
|
|
|
1729
1573
|
let!(:second_post) do
|
|
1730
|
-
person.posts.create!(title:
|
|
1574
|
+
person.posts.create!(title: 'Two')
|
|
1731
1575
|
end
|
|
1732
1576
|
|
|
1733
1577
|
it 'returns the matching document' do
|
|
1734
|
-
expect(enumerable.last(1)).to eq([second_post])
|
|
1578
|
+
expect(enumerable.last(1)).to eq([ second_post ])
|
|
1735
1579
|
end
|
|
1736
1580
|
end
|
|
1737
1581
|
|
|
1738
1582
|
context 'when no parameters are provided' do
|
|
1739
|
-
|
|
1740
1583
|
let(:person) do
|
|
1741
1584
|
Person.create!
|
|
1742
1585
|
end
|
|
@@ -1750,11 +1593,11 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1750
1593
|
end
|
|
1751
1594
|
|
|
1752
1595
|
let!(:first_post) do
|
|
1753
|
-
person.posts.create!(title:
|
|
1596
|
+
person.posts.create!(title: 'One')
|
|
1754
1597
|
end
|
|
1755
1598
|
|
|
1756
1599
|
let!(:second_post) do
|
|
1757
|
-
person.posts.create!(title:
|
|
1600
|
+
person.posts.create!(title: 'Two')
|
|
1758
1601
|
end
|
|
1759
1602
|
|
|
1760
1603
|
it 'uses the sort on id' do
|
|
@@ -1763,29 +1606,25 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1763
1606
|
end
|
|
1764
1607
|
end
|
|
1765
1608
|
|
|
1766
|
-
describe
|
|
1767
|
-
|
|
1609
|
+
describe '#kind_of?' do
|
|
1768
1610
|
let(:enumerable) do
|
|
1769
1611
|
described_class.new(Post.all)
|
|
1770
1612
|
end
|
|
1771
1613
|
|
|
1772
|
-
context
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
expect(enumerable.kind_of?(::Enumerable)).to be true
|
|
1614
|
+
context 'when checking against enumerable' do
|
|
1615
|
+
it 'returns true' do
|
|
1616
|
+
expect(enumerable.is_a?(Enumerable)).to be true
|
|
1776
1617
|
end
|
|
1777
1618
|
end
|
|
1778
1619
|
|
|
1779
|
-
context
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
expect(enumerable.kind_of?(Array)).to be true
|
|
1620
|
+
context 'when checking against array' do
|
|
1621
|
+
it 'returns true' do
|
|
1622
|
+
expect(enumerable.is_a?(Array)).to be true
|
|
1783
1623
|
end
|
|
1784
1624
|
end
|
|
1785
1625
|
end
|
|
1786
1626
|
|
|
1787
|
-
describe
|
|
1788
|
-
|
|
1627
|
+
describe '#load_all!' do
|
|
1789
1628
|
let(:person) do
|
|
1790
1629
|
Person.create!
|
|
1791
1630
|
end
|
|
@@ -1806,15 +1645,15 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1806
1645
|
enumerable.load_all!
|
|
1807
1646
|
end
|
|
1808
1647
|
|
|
1809
|
-
it
|
|
1648
|
+
it 'loads all the unloaded documents' do
|
|
1810
1649
|
expect(enumerable._loaded).to eq({ post.id => post })
|
|
1811
1650
|
end
|
|
1812
1651
|
|
|
1813
|
-
it
|
|
1814
|
-
expect(loaded).to eq([post])
|
|
1652
|
+
it 'returns the object' do
|
|
1653
|
+
expect(loaded).to eq([ post ])
|
|
1815
1654
|
end
|
|
1816
1655
|
|
|
1817
|
-
it
|
|
1656
|
+
it 'sets loaded to true' do
|
|
1818
1657
|
expect(enumerable).to be__loaded
|
|
1819
1658
|
end
|
|
1820
1659
|
end
|
|
@@ -1843,7 +1682,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1843
1682
|
context 'when the criteria is present' do
|
|
1844
1683
|
it 'delegates to the criteria pluck method' do
|
|
1845
1684
|
result = enumerable.pluck(:title)
|
|
1846
|
-
expect(result).to eq(['Test Title'])
|
|
1685
|
+
expect(result).to eq([ 'Test Title' ])
|
|
1847
1686
|
end
|
|
1848
1687
|
|
|
1849
1688
|
context 'when added docs are present' do
|
|
@@ -1851,9 +1690,9 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1851
1690
|
added_post = Post.new(title: 'Added Title', person_id: person.id)
|
|
1852
1691
|
enumerable << added_post
|
|
1853
1692
|
|
|
1854
|
-
expect(criteria).to receive(:pluck).with(:title).and_return(['Test Title'])
|
|
1693
|
+
expect(criteria).to receive(:pluck).with(:title).and_return([ 'Test Title' ])
|
|
1855
1694
|
result = enumerable.pluck(:title)
|
|
1856
|
-
expect(result).to eq(['Test Title', 'Added Title'])
|
|
1695
|
+
expect(result).to eq([ 'Test Title', 'Added Title' ])
|
|
1857
1696
|
end
|
|
1858
1697
|
end
|
|
1859
1698
|
end
|
|
@@ -1872,18 +1711,18 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1872
1711
|
enumerable << added_post
|
|
1873
1712
|
|
|
1874
1713
|
result = enumerable.pluck(:title)
|
|
1875
|
-
expect(result).to eq(['Added Title'])
|
|
1714
|
+
expect(result).to eq([ 'Added Title' ])
|
|
1876
1715
|
end
|
|
1877
1716
|
end
|
|
1878
1717
|
end
|
|
1879
1718
|
end
|
|
1880
1719
|
|
|
1881
1720
|
context 'when the enumerable is loaded' do
|
|
1882
|
-
let(:enumerable) { described_class.new([post], base, association) }
|
|
1721
|
+
let(:enumerable) { described_class.new([ post ], base, association) }
|
|
1883
1722
|
|
|
1884
1723
|
it 'returns the values from the loaded documents' do
|
|
1885
1724
|
result = enumerable.pluck(:title)
|
|
1886
|
-
expect(result).to eq(['Test Title'])
|
|
1725
|
+
expect(result).to eq([ 'Test Title' ])
|
|
1887
1726
|
end
|
|
1888
1727
|
|
|
1889
1728
|
context 'when added docs are present' do
|
|
@@ -1892,7 +1731,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1892
1731
|
enumerable << added_post
|
|
1893
1732
|
|
|
1894
1733
|
result = enumerable.pluck(:title)
|
|
1895
|
-
expect(result).to eq(['Test Title', 'Added Title'])
|
|
1734
|
+
expect(result).to eq([ 'Test Title', 'Added Title' ])
|
|
1896
1735
|
end
|
|
1897
1736
|
end
|
|
1898
1737
|
end
|
|
@@ -1905,7 +1744,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1905
1744
|
|
|
1906
1745
|
context 'when the field is aliased' do
|
|
1907
1746
|
let!(:expensive) do
|
|
1908
|
-
parent.products.create!(price:
|
|
1747
|
+
parent.products.create!(price: 100_000)
|
|
1909
1748
|
end
|
|
1910
1749
|
|
|
1911
1750
|
let!(:cheap) do
|
|
@@ -1913,13 +1752,12 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1913
1752
|
end
|
|
1914
1753
|
|
|
1915
1754
|
context 'when using alias_attribute' do
|
|
1916
|
-
|
|
1917
1755
|
let(:plucked) do
|
|
1918
1756
|
parent.products.pluck(:price)
|
|
1919
1757
|
end
|
|
1920
1758
|
|
|
1921
1759
|
it 'uses the aliases' do
|
|
1922
|
-
expect(plucked).to eq([
|
|
1760
|
+
expect(plucked).to eq([ 100_000, 1 ])
|
|
1923
1761
|
end
|
|
1924
1762
|
end
|
|
1925
1763
|
end
|
|
@@ -1953,16 +1791,16 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1953
1791
|
end
|
|
1954
1792
|
|
|
1955
1793
|
it 'returns the full translations hash to _translations' do
|
|
1956
|
-
expect(plucked_translations.first).to eq({'de'=>'deutsch-text', 'en'=>'english-text'})
|
|
1794
|
+
expect(plucked_translations.first).to eq({ 'de' => 'deutsch-text', 'en' => 'english-text' })
|
|
1957
1795
|
end
|
|
1958
1796
|
|
|
1959
1797
|
it 'returns both' do
|
|
1960
|
-
expect(plucked_translations_both.first).to eq([{'de'=>'deutsch-text', 'en'=>'english-text'},
|
|
1798
|
+
expect(plucked_translations_both.first).to eq([ { 'de' => 'deutsch-text', 'en' => 'english-text' },
|
|
1799
|
+
'deutsch-text' ])
|
|
1961
1800
|
end
|
|
1962
1801
|
end
|
|
1963
1802
|
|
|
1964
1803
|
context 'when plucking a specific locale' do
|
|
1965
|
-
|
|
1966
1804
|
let(:plucked) do
|
|
1967
1805
|
parent.products.all.pluck(:'name.de')
|
|
1968
1806
|
end
|
|
@@ -1973,7 +1811,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
1973
1811
|
end
|
|
1974
1812
|
|
|
1975
1813
|
context 'when plucking a specific locale from _translations field' do
|
|
1976
|
-
|
|
1977
1814
|
let(:plucked) do
|
|
1978
1815
|
parent.products.all.pluck(:'name_translations.de')
|
|
1979
1816
|
end
|
|
@@ -2042,12 +1879,12 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2042
1879
|
end
|
|
2043
1880
|
|
|
2044
1881
|
it 'returns both' do
|
|
2045
|
-
expect(plucked_translations_both.first).to eq([{ 'de' => 'deutsch-text', 'en' => 'english-text' },
|
|
1882
|
+
expect(plucked_translations_both.first).to eq([ { 'de' => 'deutsch-text', 'en' => 'english-text' },
|
|
1883
|
+
'deutsch-text' ])
|
|
2046
1884
|
end
|
|
2047
1885
|
end
|
|
2048
1886
|
|
|
2049
1887
|
context 'when plucking a specific locale' do
|
|
2050
|
-
|
|
2051
1888
|
let(:plucked) do
|
|
2052
1889
|
parent.products.all.pluck(:'tagline.de')
|
|
2053
1890
|
end
|
|
@@ -2058,7 +1895,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2058
1895
|
end
|
|
2059
1896
|
|
|
2060
1897
|
context 'when plucking a specific locale from _translations field' do
|
|
2061
|
-
|
|
2062
1898
|
let(:plucked) do
|
|
2063
1899
|
parent.products.all.pluck(:'tagline_translations.de')
|
|
2064
1900
|
end
|
|
@@ -2072,7 +1908,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2072
1908
|
require_fallbacks
|
|
2073
1909
|
|
|
2074
1910
|
before do
|
|
2075
|
-
I18n.fallbacks[:he] = [:en]
|
|
1911
|
+
I18n.fallbacks[:he] = [ :en ]
|
|
2076
1912
|
end
|
|
2077
1913
|
|
|
2078
1914
|
let(:plucked) do
|
|
@@ -2192,7 +2028,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2192
2028
|
|
|
2193
2029
|
context 'when plucking an embeds_many field' do
|
|
2194
2030
|
let(:label) { Label.new(sales: '1E2') }
|
|
2195
|
-
let!(:band) { Band.create!(labels: [label]) }
|
|
2031
|
+
let!(:band) { Band.create!(labels: [ label ]) }
|
|
2196
2032
|
|
|
2197
2033
|
let(:plucked) { Band.where(_id: band.id).pluck('labels.sales') }
|
|
2198
2034
|
|
|
@@ -2213,55 +2049,37 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2213
2049
|
end
|
|
2214
2050
|
end
|
|
2215
2051
|
|
|
2216
|
-
describe
|
|
2217
|
-
|
|
2218
|
-
let(:person)
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
let(:post) do
|
|
2223
|
-
Post.create!(person_id: person.id)
|
|
2224
|
-
end
|
|
2225
|
-
|
|
2226
|
-
let(:post_two) do
|
|
2227
|
-
Post.create!(person_id: person.id)
|
|
2228
|
-
end
|
|
2229
|
-
|
|
2230
|
-
let(:enumerable) do
|
|
2231
|
-
described_class.new([ post ])
|
|
2232
|
-
end
|
|
2052
|
+
describe '#reset' do
|
|
2053
|
+
let(:person) { Person.create! }
|
|
2054
|
+
let(:post) { Post.create!(person_id: person.id) }
|
|
2055
|
+
let(:post_two) { Post.create!(person_id: person.id) }
|
|
2056
|
+
let(:enumerable) { described_class.new([ post ]) }
|
|
2233
2057
|
|
|
2234
2058
|
before do
|
|
2235
2059
|
enumerable << post_two
|
|
2236
|
-
end
|
|
2237
|
-
|
|
2238
|
-
let!(:reset) do
|
|
2239
2060
|
enumerable.reset
|
|
2240
2061
|
end
|
|
2241
2062
|
|
|
2242
|
-
it
|
|
2243
|
-
expect(enumerable).
|
|
2063
|
+
it 'is not loaded' do
|
|
2064
|
+
expect(enumerable).not_to be__loaded
|
|
2244
2065
|
end
|
|
2245
2066
|
|
|
2246
|
-
it
|
|
2067
|
+
it 'clears out the loaded docs' do
|
|
2247
2068
|
expect(enumerable._loaded).to be_empty
|
|
2248
2069
|
end
|
|
2249
2070
|
|
|
2250
|
-
it
|
|
2071
|
+
it 'clears out the added docs' do
|
|
2251
2072
|
expect(enumerable._added).to be_empty
|
|
2252
2073
|
end
|
|
2253
2074
|
end
|
|
2254
2075
|
|
|
2255
|
-
describe
|
|
2256
|
-
|
|
2076
|
+
describe '#respond_to?' do
|
|
2257
2077
|
let(:enumerable) do
|
|
2258
2078
|
described_class.new([])
|
|
2259
2079
|
end
|
|
2260
2080
|
|
|
2261
|
-
context
|
|
2262
|
-
|
|
2081
|
+
context 'when checking against array methods' do
|
|
2263
2082
|
[].methods.each do |method|
|
|
2264
|
-
|
|
2265
2083
|
it "returns true for #{method}" do
|
|
2266
2084
|
expect(enumerable).to respond_to(method)
|
|
2267
2085
|
end
|
|
@@ -2269,8 +2087,7 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2269
2087
|
end
|
|
2270
2088
|
end
|
|
2271
2089
|
|
|
2272
|
-
describe
|
|
2273
|
-
|
|
2090
|
+
describe '#size' do
|
|
2274
2091
|
let(:person) do
|
|
2275
2092
|
Person.create!
|
|
2276
2093
|
end
|
|
@@ -2279,37 +2096,37 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2279
2096
|
Post.create!(person_id: person.id)
|
|
2280
2097
|
end
|
|
2281
2098
|
|
|
2282
|
-
context
|
|
2283
|
-
|
|
2099
|
+
context 'when the base is new' do
|
|
2284
2100
|
let!(:person) do
|
|
2285
2101
|
Person.new
|
|
2286
2102
|
end
|
|
2287
2103
|
|
|
2288
|
-
context
|
|
2289
|
-
|
|
2104
|
+
context 'when the added contains a persisted document' do
|
|
2290
2105
|
let!(:post) do
|
|
2291
2106
|
Post.create!(person_id: person.id)
|
|
2292
2107
|
end
|
|
2293
2108
|
|
|
2294
|
-
context
|
|
2295
|
-
|
|
2109
|
+
context 'when the enumerable is not loaded' do
|
|
2296
2110
|
let(:enumerable) do
|
|
2297
2111
|
described_class.new(Post.where(person_id: person.id))
|
|
2298
2112
|
end
|
|
2299
2113
|
|
|
2300
|
-
it
|
|
2114
|
+
it 'includes the number of all added documents' do
|
|
2301
2115
|
expect(enumerable.size).to eq(1)
|
|
2302
2116
|
end
|
|
2303
2117
|
end
|
|
2304
2118
|
end
|
|
2305
2119
|
end
|
|
2306
2120
|
|
|
2307
|
-
context
|
|
2308
|
-
|
|
2121
|
+
context 'when the enumerable is loaded' do
|
|
2309
2122
|
let(:enumerable) do
|
|
2310
2123
|
described_class.new([ post ])
|
|
2311
2124
|
end
|
|
2312
2125
|
|
|
2126
|
+
let(:size) do
|
|
2127
|
+
enumerable.size
|
|
2128
|
+
end
|
|
2129
|
+
|
|
2313
2130
|
let(:post_two) do
|
|
2314
2131
|
Post.new(person_id: person.id)
|
|
2315
2132
|
end
|
|
@@ -2318,104 +2135,81 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2318
2135
|
enumerable << post_two
|
|
2319
2136
|
end
|
|
2320
2137
|
|
|
2321
|
-
|
|
2322
|
-
enumerable.size
|
|
2323
|
-
end
|
|
2324
|
-
|
|
2325
|
-
it "returns the loaded size plus added size" do
|
|
2138
|
+
it 'returns the loaded size plus added size' do
|
|
2326
2139
|
expect(size).to eq(2)
|
|
2327
2140
|
end
|
|
2328
2141
|
|
|
2329
|
-
it
|
|
2142
|
+
it 'matches the size of the loaded enumerable' do
|
|
2330
2143
|
expect(size).to eq(enumerable.to_a.size)
|
|
2331
2144
|
end
|
|
2332
2145
|
end
|
|
2333
2146
|
|
|
2334
|
-
context
|
|
2335
|
-
|
|
2147
|
+
context 'when the enumerable is not loaded' do
|
|
2336
2148
|
let(:enumerable) do
|
|
2337
2149
|
described_class.new(Post.where(person_id: person.id))
|
|
2338
2150
|
end
|
|
2339
2151
|
|
|
2340
|
-
context
|
|
2341
|
-
|
|
2152
|
+
context 'when the added contains new documents' do
|
|
2342
2153
|
let(:post_two) do
|
|
2343
2154
|
Post.new(person_id: person.id)
|
|
2344
2155
|
end
|
|
2345
2156
|
|
|
2346
|
-
before do
|
|
2347
|
-
enumerable << post_two
|
|
2348
|
-
end
|
|
2349
|
-
|
|
2350
2157
|
let(:size) do
|
|
2351
2158
|
enumerable.size
|
|
2352
2159
|
end
|
|
2353
2160
|
|
|
2354
|
-
|
|
2161
|
+
before do
|
|
2162
|
+
enumerable << post_two
|
|
2163
|
+
end
|
|
2164
|
+
|
|
2165
|
+
it 'returns the unloaded count plus added new size' do
|
|
2355
2166
|
expect(size).to eq(2)
|
|
2356
2167
|
end
|
|
2357
2168
|
end
|
|
2358
2169
|
|
|
2359
|
-
context
|
|
2360
|
-
|
|
2170
|
+
context 'when the added contains persisted documents' do
|
|
2361
2171
|
let(:post_two) do
|
|
2362
2172
|
Post.create!(person_id: person.id)
|
|
2363
2173
|
end
|
|
2364
2174
|
|
|
2365
|
-
before do
|
|
2366
|
-
enumerable << post_two
|
|
2367
|
-
end
|
|
2368
|
-
|
|
2369
2175
|
let(:size) do
|
|
2370
2176
|
enumerable.size
|
|
2371
2177
|
end
|
|
2372
2178
|
|
|
2373
|
-
|
|
2179
|
+
before do
|
|
2180
|
+
enumerable << post_two
|
|
2181
|
+
end
|
|
2182
|
+
|
|
2183
|
+
it 'returns the unloaded count plus added new size' do
|
|
2374
2184
|
expect(size).to eq(2)
|
|
2375
2185
|
end
|
|
2376
2186
|
end
|
|
2377
2187
|
end
|
|
2378
2188
|
end
|
|
2379
2189
|
|
|
2380
|
-
describe
|
|
2381
|
-
|
|
2382
|
-
let(:
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
let!(:post) do
|
|
2387
|
-
Post.create!(title: "test", person_id: person.id)
|
|
2388
|
-
end
|
|
2389
|
-
|
|
2390
|
-
let(:criteria) do
|
|
2391
|
-
Post.where(person_id: person.id)
|
|
2392
|
-
end
|
|
2393
|
-
|
|
2394
|
-
let!(:enumerable) do
|
|
2395
|
-
described_class.new(criteria)
|
|
2396
|
-
end
|
|
2190
|
+
describe '#to_json' do
|
|
2191
|
+
let(:person) { Person.create! }
|
|
2192
|
+
let(:json) { enumerable.to_json }
|
|
2193
|
+
let(:post) { Post.create!(title: 'test', person_id: person.id) }
|
|
2194
|
+
let(:criteria) { Post.where(person_id: person.id) }
|
|
2195
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
2397
2196
|
|
|
2398
2197
|
before do
|
|
2399
2198
|
enumerable << post
|
|
2400
2199
|
end
|
|
2401
2200
|
|
|
2402
|
-
|
|
2403
|
-
enumerable.to_json
|
|
2404
|
-
end
|
|
2405
|
-
|
|
2406
|
-
it "serializes the enumerable" do
|
|
2201
|
+
it 'serializes the enumerable' do
|
|
2407
2202
|
expect(json).to include(post.title)
|
|
2408
2203
|
end
|
|
2409
2204
|
end
|
|
2410
2205
|
|
|
2411
|
-
describe
|
|
2412
|
-
|
|
2206
|
+
describe '#to_json(parameters)' do
|
|
2413
2207
|
let(:person) do
|
|
2414
2208
|
Person.create!
|
|
2415
2209
|
end
|
|
2416
2210
|
|
|
2417
2211
|
let!(:post) do
|
|
2418
|
-
Post.create!(title:
|
|
2212
|
+
Post.create!(title: 'test', person_id: person.id)
|
|
2419
2213
|
end
|
|
2420
2214
|
|
|
2421
2215
|
let(:criteria) do
|
|
@@ -2423,54 +2217,38 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2423
2217
|
end
|
|
2424
2218
|
|
|
2425
2219
|
let!(:json) do
|
|
2426
|
-
person.posts.to_json({except: 'title'})
|
|
2220
|
+
person.posts.to_json({ except: 'title' })
|
|
2427
2221
|
end
|
|
2428
2222
|
|
|
2429
|
-
it
|
|
2430
|
-
expect(json).
|
|
2223
|
+
it 'serializes the enumerable' do
|
|
2224
|
+
expect(json).not_to include(post.title)
|
|
2431
2225
|
end
|
|
2432
2226
|
end
|
|
2433
2227
|
|
|
2434
|
-
describe
|
|
2435
|
-
|
|
2436
|
-
let(:
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
let!(:post) do
|
|
2441
|
-
Post.create!(title: "test", person_id: person.id)
|
|
2442
|
-
end
|
|
2443
|
-
|
|
2444
|
-
let(:criteria) do
|
|
2445
|
-
Post.where(person_id: person.id)
|
|
2446
|
-
end
|
|
2447
|
-
|
|
2448
|
-
let!(:enumerable) do
|
|
2449
|
-
described_class.new(criteria)
|
|
2450
|
-
end
|
|
2228
|
+
describe '#as_json' do
|
|
2229
|
+
let(:person) { Person.create! }
|
|
2230
|
+
let(:json) { enumerable.as_json }
|
|
2231
|
+
let(:post) { Post.create!(title: 'test', person_id: person.id) }
|
|
2232
|
+
let(:criteria) { Post.where(person_id: person.id) }
|
|
2233
|
+
let(:enumerable) { described_class.new(criteria) }
|
|
2451
2234
|
|
|
2452
2235
|
before do
|
|
2453
2236
|
enumerable << post
|
|
2454
2237
|
end
|
|
2455
2238
|
|
|
2456
|
-
|
|
2457
|
-
enumerable.as_json
|
|
2458
|
-
end
|
|
2459
|
-
|
|
2460
|
-
it "serializes the enumerable" do
|
|
2239
|
+
it 'serializes the enumerable' do
|
|
2461
2240
|
expect(json.size).to eq(1)
|
|
2462
2241
|
expect(json[0]['title']).to eq(post.title)
|
|
2463
2242
|
end
|
|
2464
2243
|
end
|
|
2465
2244
|
|
|
2466
|
-
describe
|
|
2467
|
-
|
|
2245
|
+
describe '#as_json(parameters)' do
|
|
2468
2246
|
let(:person) do
|
|
2469
2247
|
Person.create!
|
|
2470
2248
|
end
|
|
2471
2249
|
|
|
2472
2250
|
let!(:post) do
|
|
2473
|
-
Post.create!(title:
|
|
2251
|
+
Post.create!(title: 'test', person_id: person.id)
|
|
2474
2252
|
end
|
|
2475
2253
|
|
|
2476
2254
|
let(:criteria) do
|
|
@@ -2478,62 +2256,45 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2478
2256
|
end
|
|
2479
2257
|
|
|
2480
2258
|
let!(:json) do
|
|
2481
|
-
person.posts.as_json({except:
|
|
2259
|
+
person.posts.as_json({ except: 'title' })
|
|
2482
2260
|
end
|
|
2483
2261
|
|
|
2484
|
-
it
|
|
2262
|
+
it 'serializes the enumerable' do
|
|
2485
2263
|
expect(json.size).to eq(1)
|
|
2486
2264
|
end
|
|
2487
2265
|
|
|
2488
|
-
it
|
|
2489
|
-
expect(json[0].keys).
|
|
2266
|
+
it 'includes the proper fields' do
|
|
2267
|
+
expect(json[0].keys).not_to include('title')
|
|
2490
2268
|
end
|
|
2491
2269
|
end
|
|
2492
2270
|
|
|
2493
|
-
describe
|
|
2494
|
-
|
|
2495
|
-
let(:person)
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
let!(:post) do
|
|
2500
|
-
Post.create!(person_id: person.id)
|
|
2501
|
-
end
|
|
2502
|
-
|
|
2503
|
-
let(:criteria) do
|
|
2504
|
-
Post.where(person_id: person.id)
|
|
2505
|
-
end
|
|
2506
|
-
|
|
2507
|
-
let!(:enumerable) do
|
|
2508
|
-
described_class.new(criteria)
|
|
2509
|
-
end
|
|
2271
|
+
describe '#uniq' do
|
|
2272
|
+
let(:person) { Person.create! }
|
|
2273
|
+
let(:post) { Post.create!(person_id: person.id) }
|
|
2274
|
+
let(:criteria) { Post.where(person_id: person.id) }
|
|
2275
|
+
let!(:enumerable) { described_class.new(criteria) }
|
|
2510
2276
|
|
|
2511
2277
|
before do
|
|
2512
2278
|
enumerable << post
|
|
2513
2279
|
enumerable._loaded[post.id] = post
|
|
2514
2280
|
end
|
|
2515
2281
|
|
|
2516
|
-
|
|
2517
|
-
enumerable.uniq
|
|
2518
|
-
end
|
|
2519
|
-
|
|
2520
|
-
it "returns the unique documents" do
|
|
2521
|
-
expect(uniq).to eq([ post ])
|
|
2282
|
+
it 'returns the unique documents' do
|
|
2283
|
+
expect(enumerable.uniq).to eq([ post ])
|
|
2522
2284
|
end
|
|
2523
2285
|
|
|
2524
|
-
it
|
|
2286
|
+
it 'sets loaded to true' do
|
|
2287
|
+
enumerable.uniq
|
|
2525
2288
|
expect(enumerable).to be__loaded
|
|
2526
2289
|
end
|
|
2527
2290
|
end
|
|
2528
2291
|
|
|
2529
2292
|
describe 'setting the same parent object on enumerated children objects' do
|
|
2530
|
-
|
|
2531
2293
|
let(:person) do
|
|
2532
2294
|
Person.create!
|
|
2533
2295
|
end
|
|
2534
2296
|
|
|
2535
2297
|
context 'when a single child is fetched' do
|
|
2536
|
-
|
|
2537
2298
|
let!(:post) do
|
|
2538
2299
|
person.posts << Post.new
|
|
2539
2300
|
person.posts.first
|
|
@@ -2547,7 +2308,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2547
2308
|
end
|
|
2548
2309
|
|
|
2549
2310
|
context 'when a single child is fetched with a scope' do
|
|
2550
|
-
|
|
2551
2311
|
let!(:post) do
|
|
2552
2312
|
person.posts << Post.new(title: 'open')
|
|
2553
2313
|
person.posts.open.first
|
|
@@ -2561,7 +2321,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2561
2321
|
end
|
|
2562
2322
|
|
|
2563
2323
|
context 'when multiple children are fetched' do
|
|
2564
|
-
|
|
2565
2324
|
let!(:posts) do
|
|
2566
2325
|
person.posts << Post.new
|
|
2567
2326
|
person.posts << Post.new
|
|
@@ -2577,7 +2336,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2577
2336
|
end
|
|
2578
2337
|
|
|
2579
2338
|
context 'when multiple children are fetched with query criteria' do
|
|
2580
|
-
|
|
2581
2339
|
let!(:posts) do
|
|
2582
2340
|
person.posts << Post.new(title: 'open')
|
|
2583
2341
|
person.posts << Post.new(title: 'open')
|
|
@@ -2593,7 +2351,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2593
2351
|
end
|
|
2594
2352
|
|
|
2595
2353
|
context 'when multiple children are fetched with a scope' do
|
|
2596
|
-
|
|
2597
2354
|
let!(:posts) do
|
|
2598
2355
|
person.posts << Post.new(title: 'open')
|
|
2599
2356
|
person.posts << Post.new(title: 'open')
|
|
@@ -2609,7 +2366,6 @@ describe Mongoid::Association::Referenced::HasMany::Enumerable do
|
|
|
2609
2366
|
end
|
|
2610
2367
|
|
|
2611
2368
|
context 'when the parent is updated in memory' do
|
|
2612
|
-
|
|
2613
2369
|
let!(:posts) do
|
|
2614
2370
|
person.posts << Post.new
|
|
2615
2371
|
person.posts << Post.new
|