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,60 +1,54 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# rubocop:todo all
|
|
3
2
|
|
|
4
|
-
require
|
|
3
|
+
require 'spec_helper'
|
|
5
4
|
|
|
6
5
|
describe Mongoid::Criteria::Modifiable do
|
|
7
|
-
|
|
8
|
-
describe "#create" do
|
|
9
|
-
|
|
6
|
+
describe '#create' do
|
|
10
7
|
let(:criteria) do
|
|
11
|
-
Band.where(name:
|
|
8
|
+
Band.where(name: 'Depeche Mode')
|
|
12
9
|
end
|
|
13
10
|
|
|
14
|
-
context
|
|
11
|
+
context 'when provided valid attributes' do
|
|
15
12
|
let(:band) do
|
|
16
|
-
criteria.create!(genres: [
|
|
13
|
+
criteria.create!(genres: [ 'electro' ])
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
it
|
|
16
|
+
it 'returns the created document' do
|
|
20
17
|
expect(band).to be_persisted
|
|
21
18
|
end
|
|
22
19
|
|
|
23
|
-
it
|
|
24
|
-
expect(band.name).to eq(
|
|
20
|
+
it 'sets the criteria attributes' do
|
|
21
|
+
expect(band.name).to eq('Depeche Mode')
|
|
25
22
|
end
|
|
26
23
|
|
|
27
|
-
it
|
|
28
|
-
expect(band.genres).to eq([
|
|
24
|
+
it 'sets the attributes passed to build' do
|
|
25
|
+
expect(band.genres).to eq([ 'electro' ])
|
|
29
26
|
end
|
|
30
27
|
end
|
|
31
28
|
|
|
32
|
-
context
|
|
33
|
-
|
|
34
|
-
context "when provided valid attributes & using block" do
|
|
35
|
-
|
|
29
|
+
context 'when provided a block' do
|
|
30
|
+
context 'when provided valid attributes & using block' do
|
|
36
31
|
let(:band) do
|
|
37
32
|
criteria.create! do |c|
|
|
38
|
-
c.genres = [
|
|
33
|
+
c.genres = [ 'electro' ]
|
|
39
34
|
end
|
|
40
35
|
end
|
|
41
36
|
|
|
42
|
-
it
|
|
37
|
+
it 'returns the created document' do
|
|
43
38
|
expect(band).to be_persisted
|
|
44
39
|
end
|
|
45
40
|
|
|
46
|
-
it
|
|
47
|
-
expect(band.name).to eq(
|
|
41
|
+
it 'sets the criteria attributes' do
|
|
42
|
+
expect(band.name).to eq('Depeche Mode')
|
|
48
43
|
end
|
|
49
44
|
|
|
50
|
-
it
|
|
51
|
-
expect(band.genres).to eq([
|
|
45
|
+
it 'sets the attributes passed to build' do
|
|
46
|
+
expect(band.genres).to eq([ 'electro' ])
|
|
52
47
|
end
|
|
53
48
|
end
|
|
54
49
|
end
|
|
55
50
|
|
|
56
51
|
context 'when the object is polymorphic' do
|
|
57
|
-
|
|
58
52
|
let(:movie) do
|
|
59
53
|
Movie.new
|
|
60
54
|
end
|
|
@@ -77,23 +71,20 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
77
71
|
end
|
|
78
72
|
end
|
|
79
73
|
|
|
80
|
-
describe
|
|
81
|
-
|
|
74
|
+
describe '#create!' do
|
|
82
75
|
let(:criteria) do
|
|
83
|
-
Account.where(number:
|
|
76
|
+
Account.where(number: '11123213')
|
|
84
77
|
end
|
|
85
78
|
|
|
86
|
-
context
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect {
|
|
79
|
+
context 'when provided invalid attributes' do
|
|
80
|
+
it 'raises an error' do
|
|
81
|
+
expect do
|
|
90
82
|
criteria.create!
|
|
91
|
-
|
|
83
|
+
end.to raise_error(Mongoid::Errors::Validations)
|
|
92
84
|
end
|
|
93
85
|
end
|
|
94
86
|
|
|
95
87
|
context 'when the object is polymorphic' do
|
|
96
|
-
|
|
97
88
|
let(:movie) do
|
|
98
89
|
Movie.new
|
|
99
90
|
end
|
|
@@ -116,81 +107,75 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
116
107
|
end
|
|
117
108
|
end
|
|
118
109
|
|
|
119
|
-
[
|
|
120
|
-
|
|
110
|
+
%i[delete delete_all destroy destroy_all].each do |method|
|
|
121
111
|
describe "##{method}" do
|
|
122
|
-
|
|
123
112
|
let(:name) do
|
|
124
|
-
Name.new(first_name:
|
|
113
|
+
Name.new(first_name: 'Durran')
|
|
125
114
|
end
|
|
126
115
|
|
|
127
116
|
let(:address_one) do
|
|
128
|
-
Address.new(street:
|
|
117
|
+
Address.new(street: 'Forsterstr')
|
|
129
118
|
end
|
|
130
119
|
|
|
131
120
|
let(:address_two) do
|
|
132
|
-
Address.new(street:
|
|
121
|
+
Address.new(street: 'Hobrechtstr')
|
|
133
122
|
end
|
|
134
123
|
|
|
135
124
|
before do
|
|
136
|
-
Person.create!(title:
|
|
137
|
-
2.times do |
|
|
125
|
+
Person.create!(title: 'Madam')
|
|
126
|
+
2.times do |_n|
|
|
138
127
|
Person.create!(
|
|
139
|
-
title:
|
|
128
|
+
title: 'Sir',
|
|
140
129
|
name: name,
|
|
141
130
|
addresses: [ address_one, address_two ]
|
|
142
131
|
)
|
|
143
132
|
end
|
|
144
133
|
end
|
|
145
134
|
|
|
146
|
-
context
|
|
147
|
-
|
|
135
|
+
context 'when removing root documents' do
|
|
148
136
|
let(:criteria) do
|
|
149
|
-
Person.where(title:
|
|
137
|
+
Person.where(title: 'Sir', :age.gt => 5)
|
|
150
138
|
end
|
|
151
139
|
|
|
152
140
|
let!(:removed) do
|
|
153
141
|
criteria.send(method)
|
|
154
142
|
end
|
|
155
143
|
|
|
156
|
-
it
|
|
144
|
+
it 'deletes the removes the documents from the database' do
|
|
157
145
|
expect(Person.count).to eq(1)
|
|
158
146
|
end
|
|
159
147
|
|
|
160
|
-
it
|
|
148
|
+
it 'returns the number removed' do
|
|
161
149
|
expect(removed).to eq(2)
|
|
162
150
|
end
|
|
163
151
|
end
|
|
164
152
|
|
|
165
|
-
context
|
|
166
|
-
|
|
167
|
-
context "when removing a single document" do
|
|
168
|
-
|
|
153
|
+
context 'when removing embedded documents' do
|
|
154
|
+
context 'when removing a single document' do
|
|
169
155
|
let(:person) do
|
|
170
|
-
Person.where(title:
|
|
156
|
+
Person.where(title: 'Sir').first
|
|
171
157
|
end
|
|
172
158
|
|
|
173
159
|
let(:criteria) do
|
|
174
|
-
person.addresses.where(street:
|
|
160
|
+
person.addresses.where(street: 'Forsterstr')
|
|
175
161
|
end
|
|
176
162
|
|
|
177
163
|
let!(:removed) do
|
|
178
164
|
criteria.send(method)
|
|
179
165
|
end
|
|
180
166
|
|
|
181
|
-
it
|
|
167
|
+
it 'deletes the removes the documents from the database' do
|
|
182
168
|
expect(person.addresses.count).to eq(1)
|
|
183
169
|
end
|
|
184
170
|
|
|
185
|
-
it
|
|
171
|
+
it 'returns the number removed' do
|
|
186
172
|
expect(removed).to eq(1)
|
|
187
173
|
end
|
|
188
174
|
end
|
|
189
175
|
|
|
190
|
-
context
|
|
191
|
-
|
|
176
|
+
context 'when removing multiple documents' do
|
|
192
177
|
let(:person) do
|
|
193
|
-
Person.where(title:
|
|
178
|
+
Person.where(title: 'Sir').first
|
|
194
179
|
end
|
|
195
180
|
|
|
196
181
|
let(:criteria) do
|
|
@@ -201,11 +186,11 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
201
186
|
criteria.send(method)
|
|
202
187
|
end
|
|
203
188
|
|
|
204
|
-
it
|
|
189
|
+
it 'deletes the removes the documents from the database' do
|
|
205
190
|
expect(person.addresses.count).to eq(0)
|
|
206
191
|
end
|
|
207
192
|
|
|
208
|
-
it
|
|
193
|
+
it 'returns the number removed' do
|
|
209
194
|
expect(removed).to eq(2)
|
|
210
195
|
end
|
|
211
196
|
end
|
|
@@ -213,25 +198,20 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
213
198
|
end
|
|
214
199
|
end
|
|
215
200
|
|
|
216
|
-
describe
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
context "when providing an attribute" do
|
|
221
|
-
|
|
201
|
+
describe '.find_or_create_by' do
|
|
202
|
+
context 'when the document is found' do
|
|
203
|
+
context 'when providing an attribute' do
|
|
222
204
|
let!(:person) do
|
|
223
|
-
Person.create!(title:
|
|
205
|
+
Person.create!(title: 'Senior')
|
|
224
206
|
end
|
|
225
207
|
|
|
226
|
-
it
|
|
227
|
-
expect(Person.find_or_create_by(title:
|
|
208
|
+
it 'returns the document' do
|
|
209
|
+
expect(Person.find_or_create_by(title: 'Senior')).to eq(person)
|
|
228
210
|
end
|
|
229
211
|
end
|
|
230
212
|
|
|
231
|
-
context
|
|
232
|
-
|
|
233
|
-
context "with an owner with a BSON identity type" do
|
|
234
|
-
|
|
213
|
+
context 'when providing a document' do
|
|
214
|
+
context 'with an owner with a BSON identity type' do
|
|
235
215
|
let!(:person) do
|
|
236
216
|
Person.create!
|
|
237
217
|
end
|
|
@@ -240,31 +220,28 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
240
220
|
Game.create!(person: person)
|
|
241
221
|
end
|
|
242
222
|
|
|
243
|
-
context
|
|
244
|
-
|
|
223
|
+
context 'when providing the object directly' do
|
|
245
224
|
let(:from_db) do
|
|
246
225
|
Game.find_or_create_by(person: person)
|
|
247
226
|
end
|
|
248
227
|
|
|
249
|
-
it
|
|
228
|
+
it 'returns the document' do
|
|
250
229
|
expect(from_db).to eq(game)
|
|
251
230
|
end
|
|
252
231
|
end
|
|
253
232
|
|
|
254
|
-
context
|
|
255
|
-
|
|
233
|
+
context 'when providing the proxy relation' do
|
|
256
234
|
let(:from_db) do
|
|
257
235
|
Game.find_or_create_by(person: game.person)
|
|
258
236
|
end
|
|
259
237
|
|
|
260
|
-
it
|
|
238
|
+
it 'returns the document' do
|
|
261
239
|
expect(from_db).to eq(game)
|
|
262
240
|
end
|
|
263
241
|
end
|
|
264
242
|
end
|
|
265
243
|
|
|
266
|
-
context
|
|
267
|
-
|
|
244
|
+
context 'with an owner with an Integer identity type' do
|
|
268
245
|
let!(:jar) do
|
|
269
246
|
Jar.create!
|
|
270
247
|
end
|
|
@@ -277,17 +254,15 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
277
254
|
Cookie.find_or_create_by(jar: jar)
|
|
278
255
|
end
|
|
279
256
|
|
|
280
|
-
it
|
|
257
|
+
it 'returns the document' do
|
|
281
258
|
expect(from_db).to eq(cookie)
|
|
282
259
|
end
|
|
283
260
|
end
|
|
284
261
|
end
|
|
285
262
|
end
|
|
286
263
|
|
|
287
|
-
context
|
|
288
|
-
|
|
289
|
-
context "when providing a document" do
|
|
290
|
-
|
|
264
|
+
context 'when the document is not found' do
|
|
265
|
+
context 'when providing a document' do
|
|
291
266
|
let!(:person) do
|
|
292
267
|
Person.create!
|
|
293
268
|
end
|
|
@@ -300,53 +275,50 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
300
275
|
Game.find_or_create_by(person: person)
|
|
301
276
|
end
|
|
302
277
|
|
|
303
|
-
it
|
|
278
|
+
it 'returns the new document' do
|
|
304
279
|
expect(from_db.person).to eq(person)
|
|
305
280
|
end
|
|
306
281
|
|
|
307
|
-
it
|
|
308
|
-
expect(from_db).
|
|
282
|
+
it 'does not return an existing false document' do
|
|
283
|
+
expect(from_db).not_to eq(game)
|
|
309
284
|
end
|
|
310
285
|
end
|
|
311
286
|
|
|
312
|
-
context
|
|
313
|
-
|
|
287
|
+
context 'when not providing a block' do
|
|
314
288
|
let!(:person) do
|
|
315
|
-
Person.find_or_create_by(title:
|
|
289
|
+
Person.find_or_create_by(title: 'Senorita')
|
|
316
290
|
end
|
|
317
291
|
|
|
318
|
-
it
|
|
292
|
+
it 'creates a persisted document' do
|
|
319
293
|
expect(person).to be_persisted
|
|
320
294
|
end
|
|
321
295
|
|
|
322
|
-
it
|
|
323
|
-
expect(person.title).to eq(
|
|
296
|
+
it 'sets the attributes' do
|
|
297
|
+
expect(person.title).to eq('Senorita')
|
|
324
298
|
end
|
|
325
299
|
end
|
|
326
300
|
|
|
327
|
-
context
|
|
328
|
-
|
|
301
|
+
context 'when providing a block' do
|
|
329
302
|
let!(:person) do
|
|
330
|
-
Person.find_or_create_by(title:
|
|
303
|
+
Person.find_or_create_by(title: 'Senorita') do |person|
|
|
331
304
|
person.pets = true
|
|
332
305
|
end
|
|
333
306
|
end
|
|
334
307
|
|
|
335
|
-
it
|
|
308
|
+
it 'creates a persisted document' do
|
|
336
309
|
expect(person).to be_persisted
|
|
337
310
|
end
|
|
338
311
|
|
|
339
|
-
it
|
|
340
|
-
expect(person.title).to eq(
|
|
312
|
+
it 'sets the attributes' do
|
|
313
|
+
expect(person.title).to eq('Senorita')
|
|
341
314
|
end
|
|
342
315
|
|
|
343
|
-
it
|
|
316
|
+
it 'calls the block' do
|
|
344
317
|
expect(person.pets).to be true
|
|
345
318
|
end
|
|
346
319
|
end
|
|
347
320
|
|
|
348
321
|
context 'when the object is polymorphic' do
|
|
349
|
-
|
|
350
322
|
let(:movie) do
|
|
351
323
|
Movie.new
|
|
352
324
|
end
|
|
@@ -366,25 +338,20 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
366
338
|
end
|
|
367
339
|
end
|
|
368
340
|
|
|
369
|
-
describe
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
context "when providing an attribute" do
|
|
374
|
-
|
|
341
|
+
describe '.find_or_create_by!' do
|
|
342
|
+
context 'when the document is found' do
|
|
343
|
+
context 'when providing an attribute' do
|
|
375
344
|
let!(:person) do
|
|
376
|
-
Person.create!(title:
|
|
345
|
+
Person.create!(title: 'Senior')
|
|
377
346
|
end
|
|
378
347
|
|
|
379
|
-
it
|
|
380
|
-
expect(Person.find_or_create_by!(title:
|
|
348
|
+
it 'returns the document' do
|
|
349
|
+
expect(Person.find_or_create_by!(title: 'Senior')).to eq(person)
|
|
381
350
|
end
|
|
382
351
|
end
|
|
383
352
|
|
|
384
|
-
context
|
|
385
|
-
|
|
386
|
-
context "with an owner with a BSON identity type" do
|
|
387
|
-
|
|
353
|
+
context 'when providing a document' do
|
|
354
|
+
context 'with an owner with a BSON identity type' do
|
|
388
355
|
let!(:person) do
|
|
389
356
|
Person.create!
|
|
390
357
|
end
|
|
@@ -393,31 +360,28 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
393
360
|
Game.create!(person: person)
|
|
394
361
|
end
|
|
395
362
|
|
|
396
|
-
context
|
|
397
|
-
|
|
363
|
+
context 'when providing the object directly' do
|
|
398
364
|
let(:from_db) do
|
|
399
365
|
Game.find_or_create_by!(person: person)
|
|
400
366
|
end
|
|
401
367
|
|
|
402
|
-
it
|
|
368
|
+
it 'returns the document' do
|
|
403
369
|
expect(from_db).to eq(game)
|
|
404
370
|
end
|
|
405
371
|
end
|
|
406
372
|
|
|
407
|
-
context
|
|
408
|
-
|
|
373
|
+
context 'when providing the proxy relation' do
|
|
409
374
|
let(:from_db) do
|
|
410
375
|
Game.find_or_create_by!(person: game.person)
|
|
411
376
|
end
|
|
412
377
|
|
|
413
|
-
it
|
|
378
|
+
it 'returns the document' do
|
|
414
379
|
expect(from_db).to eq(game)
|
|
415
380
|
end
|
|
416
381
|
end
|
|
417
382
|
end
|
|
418
383
|
|
|
419
|
-
context
|
|
420
|
-
|
|
384
|
+
context 'with an owner with an Integer identity type' do
|
|
421
385
|
let!(:jar) do
|
|
422
386
|
Jar.create!
|
|
423
387
|
end
|
|
@@ -430,17 +394,15 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
430
394
|
Cookie.find_or_create_by!(jar: jar)
|
|
431
395
|
end
|
|
432
396
|
|
|
433
|
-
it
|
|
397
|
+
it 'returns the document' do
|
|
434
398
|
expect(from_db).to eq(cookie)
|
|
435
399
|
end
|
|
436
400
|
end
|
|
437
401
|
end
|
|
438
402
|
end
|
|
439
403
|
|
|
440
|
-
context
|
|
441
|
-
|
|
442
|
-
context "when providing a document" do
|
|
443
|
-
|
|
404
|
+
context 'when the document is not found' do
|
|
405
|
+
context 'when providing a document' do
|
|
444
406
|
let!(:person) do
|
|
445
407
|
Person.create!
|
|
446
408
|
end
|
|
@@ -453,32 +415,30 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
453
415
|
Game.find_or_create_by!(person: person)
|
|
454
416
|
end
|
|
455
417
|
|
|
456
|
-
it
|
|
418
|
+
it 'returns the new document' do
|
|
457
419
|
expect(from_db.person).to eq(person)
|
|
458
420
|
end
|
|
459
421
|
|
|
460
|
-
it
|
|
461
|
-
expect(from_db).
|
|
422
|
+
it 'does not return an existing false document' do
|
|
423
|
+
expect(from_db).not_to eq(game)
|
|
462
424
|
end
|
|
463
425
|
end
|
|
464
426
|
|
|
465
|
-
context
|
|
466
|
-
|
|
427
|
+
context 'when not providing a block' do
|
|
467
428
|
let!(:person) do
|
|
468
|
-
Person.find_or_create_by!(title:
|
|
429
|
+
Person.find_or_create_by!(title: 'Senorita')
|
|
469
430
|
end
|
|
470
431
|
|
|
471
|
-
it
|
|
432
|
+
it 'creates a persisted document' do
|
|
472
433
|
expect(person).to be_persisted
|
|
473
434
|
end
|
|
474
435
|
|
|
475
|
-
it
|
|
476
|
-
expect(person.title).to eq(
|
|
436
|
+
it 'sets the attributes' do
|
|
437
|
+
expect(person.title).to eq('Senorita')
|
|
477
438
|
end
|
|
478
439
|
end
|
|
479
440
|
|
|
480
|
-
context
|
|
481
|
-
|
|
441
|
+
context 'when validation fails' do
|
|
482
442
|
before do
|
|
483
443
|
Person.validates_presence_of(:title)
|
|
484
444
|
end
|
|
@@ -487,37 +447,35 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
487
447
|
Person.reset_callbacks(:validate)
|
|
488
448
|
end
|
|
489
449
|
|
|
490
|
-
it
|
|
491
|
-
expect
|
|
492
|
-
Person.find_or_create_by!(ssn:
|
|
493
|
-
|
|
450
|
+
it 'raises an exception' do
|
|
451
|
+
expect do
|
|
452
|
+
Person.find_or_create_by!(ssn: 'test')
|
|
453
|
+
end.to raise_error(Mongoid::Errors::Validations)
|
|
494
454
|
end
|
|
495
455
|
end
|
|
496
456
|
|
|
497
|
-
context
|
|
498
|
-
|
|
457
|
+
context 'when providing a block' do
|
|
499
458
|
let!(:person) do
|
|
500
|
-
Person.find_or_create_by!(title:
|
|
459
|
+
Person.find_or_create_by!(title: 'Senorita') do |person|
|
|
501
460
|
person.pets = true
|
|
502
461
|
end
|
|
503
462
|
end
|
|
504
463
|
|
|
505
|
-
it
|
|
464
|
+
it 'creates a persisted document' do
|
|
506
465
|
expect(person).to be_persisted
|
|
507
466
|
end
|
|
508
467
|
|
|
509
|
-
it
|
|
510
|
-
expect(person.title).to eq(
|
|
468
|
+
it 'sets the attributes' do
|
|
469
|
+
expect(person.title).to eq('Senorita')
|
|
511
470
|
end
|
|
512
471
|
|
|
513
|
-
it
|
|
472
|
+
it 'calls the block' do
|
|
514
473
|
expect(person.pets).to be true
|
|
515
474
|
end
|
|
516
475
|
end
|
|
517
476
|
end
|
|
518
477
|
|
|
519
478
|
context 'when the object is polymorphic' do
|
|
520
|
-
|
|
521
479
|
let(:movie) do
|
|
522
480
|
Movie.new
|
|
523
481
|
end
|
|
@@ -536,60 +494,54 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
536
494
|
end
|
|
537
495
|
end
|
|
538
496
|
|
|
539
|
-
describe
|
|
540
|
-
|
|
541
|
-
context "when the document is found" do
|
|
542
|
-
|
|
497
|
+
describe '.find_or_initialize_by' do
|
|
498
|
+
context 'when the document is found' do
|
|
543
499
|
let!(:person) do
|
|
544
|
-
Person.create!(title:
|
|
500
|
+
Person.create!(title: 'Senior')
|
|
545
501
|
end
|
|
546
502
|
|
|
547
|
-
it
|
|
548
|
-
expect(Person.find_or_initialize_by(title:
|
|
503
|
+
it 'returns the document' do
|
|
504
|
+
expect(Person.find_or_initialize_by(title: 'Senior')).to eq(person)
|
|
549
505
|
end
|
|
550
506
|
end
|
|
551
507
|
|
|
552
|
-
context
|
|
553
|
-
|
|
554
|
-
context "when not providing a block" do
|
|
555
|
-
|
|
508
|
+
context 'when the document is not found' do
|
|
509
|
+
context 'when not providing a block' do
|
|
556
510
|
let!(:person) do
|
|
557
|
-
Person.find_or_initialize_by(title:
|
|
511
|
+
Person.find_or_initialize_by(title: 'Senorita')
|
|
558
512
|
end
|
|
559
513
|
|
|
560
|
-
it
|
|
514
|
+
it 'creates a new document' do
|
|
561
515
|
expect(person).to be_new_record
|
|
562
516
|
end
|
|
563
517
|
|
|
564
|
-
it
|
|
565
|
-
expect(person.title).to eq(
|
|
518
|
+
it 'sets the attributes' do
|
|
519
|
+
expect(person.title).to eq('Senorita')
|
|
566
520
|
end
|
|
567
521
|
end
|
|
568
522
|
|
|
569
|
-
context
|
|
570
|
-
|
|
523
|
+
context 'when providing a block' do
|
|
571
524
|
let!(:person) do
|
|
572
|
-
Person.find_or_initialize_by(title:
|
|
525
|
+
Person.find_or_initialize_by(title: 'Senorita') do |person|
|
|
573
526
|
person.pets = true
|
|
574
527
|
end
|
|
575
528
|
end
|
|
576
529
|
|
|
577
|
-
it
|
|
530
|
+
it 'creates a new document' do
|
|
578
531
|
expect(person).to be_new_record
|
|
579
532
|
end
|
|
580
533
|
|
|
581
|
-
it
|
|
582
|
-
expect(person.title).to eq(
|
|
534
|
+
it 'sets the attributes' do
|
|
535
|
+
expect(person.title).to eq('Senorita')
|
|
583
536
|
end
|
|
584
537
|
|
|
585
|
-
it
|
|
538
|
+
it 'calls the block' do
|
|
586
539
|
expect(person.pets).to be true
|
|
587
540
|
end
|
|
588
541
|
end
|
|
589
542
|
end
|
|
590
543
|
|
|
591
544
|
context 'when the object is polymorphic' do
|
|
592
|
-
|
|
593
545
|
let(:movie) do
|
|
594
546
|
Movie.new
|
|
595
547
|
end
|
|
@@ -608,49 +560,42 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
608
560
|
end
|
|
609
561
|
end
|
|
610
562
|
|
|
611
|
-
describe
|
|
612
|
-
|
|
563
|
+
describe 'first_or_create' do
|
|
613
564
|
let!(:band) do
|
|
614
|
-
Band.create!(name:
|
|
565
|
+
Band.create!(name: 'Depeche Mode')
|
|
615
566
|
end
|
|
616
567
|
|
|
617
|
-
context
|
|
618
|
-
|
|
568
|
+
context 'when the document is found' do
|
|
619
569
|
let(:found) do
|
|
620
|
-
Band.where(name:
|
|
570
|
+
Band.where(name: 'Depeche Mode').first_or_create
|
|
621
571
|
end
|
|
622
572
|
|
|
623
|
-
it
|
|
573
|
+
it 'returns the document' do
|
|
624
574
|
expect(found).to eq(band)
|
|
625
575
|
end
|
|
626
576
|
end
|
|
627
577
|
|
|
628
|
-
context
|
|
629
|
-
|
|
630
|
-
context "when attributes are provided" do
|
|
631
|
-
|
|
578
|
+
context 'when the document is not found' do
|
|
579
|
+
context 'when attributes are provided' do
|
|
632
580
|
let(:document) do
|
|
633
|
-
Band.where(name:
|
|
581
|
+
Band.where(name: 'Tool').first_or_create(origin: 'Essex')
|
|
634
582
|
end
|
|
635
583
|
|
|
636
|
-
it
|
|
637
|
-
expect(document.name).to eq(
|
|
584
|
+
it 'returns a new document' do
|
|
585
|
+
expect(document.name).to eq('Tool')
|
|
638
586
|
end
|
|
639
587
|
|
|
640
|
-
it
|
|
588
|
+
it 'returns a persisted document' do
|
|
641
589
|
expect(document).to be_persisted
|
|
642
590
|
end
|
|
643
591
|
|
|
644
|
-
it
|
|
645
|
-
expect(document.origin).to eq(
|
|
592
|
+
it 'sets the additional attributes' do
|
|
593
|
+
expect(document.origin).to eq('Essex')
|
|
646
594
|
end
|
|
647
595
|
|
|
648
596
|
context 'when attributes contain keys also in the criteria selector' do
|
|
649
|
-
|
|
650
597
|
context 'when the selector has symbol keys' do
|
|
651
|
-
|
|
652
598
|
context 'when the attributes use symbol keys' do
|
|
653
|
-
|
|
654
599
|
let(:document) do
|
|
655
600
|
Band.where(name: 'Tool').first_or_create(name: 'Essex')
|
|
656
601
|
end
|
|
@@ -661,7 +606,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
661
606
|
end
|
|
662
607
|
|
|
663
608
|
context 'when the attributes use string keys' do
|
|
664
|
-
|
|
665
609
|
let(:document) do
|
|
666
610
|
Band.where(name: 'Tool').first_or_create('name' => 'Essex')
|
|
667
611
|
end
|
|
@@ -673,9 +617,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
673
617
|
end
|
|
674
618
|
|
|
675
619
|
context 'when the selector has string keys' do
|
|
676
|
-
|
|
677
620
|
context 'when the attributes use symbol keys' do
|
|
678
|
-
|
|
679
621
|
let(:document) do
|
|
680
622
|
Band.where('name' => 'Tool').first_or_create(name: 'Essex')
|
|
681
623
|
end
|
|
@@ -686,7 +628,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
686
628
|
end
|
|
687
629
|
|
|
688
630
|
context 'when the attributes use string keys' do
|
|
689
|
-
|
|
690
631
|
let(:document) do
|
|
691
632
|
Band.where('name' => 'Tool').first_or_create('name' => 'Essex')
|
|
692
633
|
end
|
|
@@ -699,20 +640,18 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
699
640
|
end
|
|
700
641
|
|
|
701
642
|
context 'when the query criteria is on a hash attribute' do
|
|
702
|
-
|
|
703
643
|
let(:document) do
|
|
704
644
|
Person.where(map: { foo: :bar }).first_or_create
|
|
705
645
|
end
|
|
706
646
|
|
|
707
647
|
it 'uses the values from the attributes' do
|
|
708
|
-
expect(document.map).to eq('foo' => :bar
|
|
648
|
+
expect(document.map).to eq('foo' => :bar)
|
|
709
649
|
end
|
|
710
650
|
end
|
|
711
651
|
|
|
712
652
|
context 'when the criteria has a selector with query operators' do
|
|
713
|
-
|
|
714
653
|
let(:document) do
|
|
715
|
-
Band.in(genres: [
|
|
654
|
+
Band.in(genres: %w[Hiphop Soul]).first_or_create(name: 'Smooth')
|
|
716
655
|
end
|
|
717
656
|
|
|
718
657
|
it 'does not create a document with the query operators' do
|
|
@@ -721,14 +660,13 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
721
660
|
end
|
|
722
661
|
|
|
723
662
|
context 'when the criteria has a nested selector with query operators' do
|
|
724
|
-
|
|
725
663
|
let(:band) do
|
|
726
|
-
record = Record.new(producers: ['testing'])
|
|
727
|
-
|
|
664
|
+
record = Record.new(producers: [ 'testing' ])
|
|
665
|
+
Band.create!(records: [ record ])
|
|
728
666
|
end
|
|
729
667
|
|
|
730
668
|
let(:document) do
|
|
731
|
-
band.records.in(producers: ['nonexistent']).first_or_create(name: 'new-embedded-doc')
|
|
669
|
+
band.records.in(producers: [ 'nonexistent' ]).first_or_create(name: 'new-embedded-doc')
|
|
732
670
|
band.reload
|
|
733
671
|
end
|
|
734
672
|
|
|
@@ -737,7 +675,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
737
675
|
end
|
|
738
676
|
|
|
739
677
|
it 'does not alter the existing embedded document' do
|
|
740
|
-
expect(document.records[0].producers).to eq(['testing'])
|
|
678
|
+
expect(document.records[0].producers).to eq([ 'testing' ])
|
|
741
679
|
end
|
|
742
680
|
|
|
743
681
|
it 'does not create a document with the query operators as attributes' do
|
|
@@ -750,14 +688,13 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
750
688
|
end
|
|
751
689
|
|
|
752
690
|
context 'when the criteria has a deeply-nested selector with query operators' do
|
|
753
|
-
|
|
754
691
|
let(:criteria) do
|
|
755
692
|
band = Band.create!
|
|
756
693
|
Mongoid::Criteria.new(Record) do |criteria|
|
|
757
694
|
criteria.embedded = true
|
|
758
695
|
criteria.association = Band.reflect_on_association(:records)
|
|
759
696
|
criteria.parent_document = band
|
|
760
|
-
criteria.selector = {
|
|
697
|
+
criteria.selector = { 'records' => { 'producers' => { '$in' => [ 'nonexistent' ] } } }
|
|
761
698
|
end
|
|
762
699
|
end
|
|
763
700
|
|
|
@@ -775,42 +712,39 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
775
712
|
end
|
|
776
713
|
end
|
|
777
714
|
|
|
778
|
-
context
|
|
779
|
-
|
|
715
|
+
context 'when attributes are not provided' do
|
|
780
716
|
let(:document) do
|
|
781
|
-
Band.where(name:
|
|
717
|
+
Band.where(name: 'Tool').first_or_create
|
|
782
718
|
end
|
|
783
719
|
|
|
784
|
-
it
|
|
785
|
-
expect(document.name).to eq(
|
|
720
|
+
it 'returns a new document' do
|
|
721
|
+
expect(document.name).to eq('Tool')
|
|
786
722
|
end
|
|
787
723
|
|
|
788
|
-
it
|
|
724
|
+
it 'returns a persisted document' do
|
|
789
725
|
expect(document).to be_persisted
|
|
790
726
|
end
|
|
791
727
|
end
|
|
792
728
|
|
|
793
|
-
context
|
|
794
|
-
|
|
729
|
+
context 'when the criteria is on an embedded relation' do
|
|
795
730
|
let!(:band) do
|
|
796
|
-
Band.create!(name:
|
|
731
|
+
Band.create!(name: 'Placebo')
|
|
797
732
|
end
|
|
798
733
|
|
|
799
734
|
let(:document) do
|
|
800
|
-
band.notes.permanent.first_or_create(text:
|
|
735
|
+
band.notes.permanent.first_or_create(text: 'test')
|
|
801
736
|
end
|
|
802
737
|
|
|
803
|
-
it
|
|
804
|
-
expect(document.text).to eq(
|
|
738
|
+
it 'returns a new document' do
|
|
739
|
+
expect(document.text).to eq('test')
|
|
805
740
|
end
|
|
806
741
|
|
|
807
|
-
it
|
|
742
|
+
it 'returns a persisted document' do
|
|
808
743
|
expect(document).to be_persisted
|
|
809
744
|
end
|
|
810
745
|
end
|
|
811
746
|
|
|
812
747
|
context 'when the object is polymorphic' do
|
|
813
|
-
|
|
814
748
|
let(:movie) do
|
|
815
749
|
Movie.new
|
|
816
750
|
end
|
|
@@ -832,40 +766,37 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
832
766
|
end
|
|
833
767
|
end
|
|
834
768
|
|
|
835
|
-
context
|
|
836
|
-
|
|
769
|
+
context 'when a block is provided' do
|
|
837
770
|
let(:document) do
|
|
838
|
-
Band.where(name:
|
|
771
|
+
Band.where(name: 'Tool').first_or_create do |doc|
|
|
839
772
|
doc.active = false
|
|
840
773
|
end
|
|
841
774
|
end
|
|
842
775
|
|
|
843
|
-
it
|
|
844
|
-
expect(document.name).to eq(
|
|
776
|
+
it 'returns a new document' do
|
|
777
|
+
expect(document.name).to eq('Tool')
|
|
845
778
|
end
|
|
846
779
|
|
|
847
|
-
it
|
|
780
|
+
it 'returns a persisted document' do
|
|
848
781
|
expect(document).to be_persisted
|
|
849
782
|
end
|
|
850
783
|
|
|
851
|
-
it
|
|
784
|
+
it 'yields to the block' do
|
|
852
785
|
expect(document.active).to be false
|
|
853
786
|
end
|
|
854
787
|
end
|
|
855
788
|
|
|
856
|
-
context
|
|
857
|
-
|
|
858
|
-
context "when the document is not found" do
|
|
859
|
-
|
|
789
|
+
context 'when the criteria is complex' do
|
|
790
|
+
context 'when the document is not found' do
|
|
860
791
|
let(:document) do
|
|
861
|
-
Band.in(name: [
|
|
792
|
+
Band.in(name: [ 'New Order' ]).first_or_create(active: false)
|
|
862
793
|
end
|
|
863
794
|
|
|
864
|
-
it
|
|
795
|
+
it 'returns a new document' do
|
|
865
796
|
expect(document.active).to be false
|
|
866
797
|
end
|
|
867
798
|
|
|
868
|
-
it
|
|
799
|
+
it 'returns a persisted document' do
|
|
869
800
|
expect(document).to be_persisted
|
|
870
801
|
end
|
|
871
802
|
end
|
|
@@ -873,134 +804,121 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
873
804
|
end
|
|
874
805
|
end
|
|
875
806
|
|
|
876
|
-
describe
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
Account.where(number: "12345").first_or_create!
|
|
883
|
-
}.to raise_error(Mongoid::Errors::Validations)
|
|
807
|
+
describe 'first_or_create!' do
|
|
808
|
+
context 'when validation fails on the new document' do
|
|
809
|
+
it 'raises an error' do
|
|
810
|
+
expect do
|
|
811
|
+
Account.where(number: '12345').first_or_create!
|
|
812
|
+
end.to raise_error(Mongoid::Errors::Validations)
|
|
884
813
|
end
|
|
885
814
|
end
|
|
886
815
|
|
|
887
|
-
context
|
|
888
|
-
|
|
816
|
+
context 'when passing a block' do
|
|
889
817
|
let(:account) do
|
|
890
|
-
Account.where(number:
|
|
891
|
-
account.name =
|
|
818
|
+
Account.where(number: '12345').first_or_create! do |account|
|
|
819
|
+
account.name = 'testing'
|
|
892
820
|
end
|
|
893
821
|
end
|
|
894
822
|
|
|
895
|
-
it
|
|
896
|
-
expect(account.name).to eq(
|
|
823
|
+
it 'passes the block to the create call' do
|
|
824
|
+
expect(account.name).to eq('testing')
|
|
897
825
|
end
|
|
898
826
|
|
|
899
|
-
it
|
|
827
|
+
it 'persists the new document' do
|
|
900
828
|
expect(account).to be_persisted
|
|
901
829
|
end
|
|
902
830
|
end
|
|
903
831
|
|
|
904
|
-
context
|
|
905
|
-
|
|
832
|
+
context 'when the document is found' do
|
|
906
833
|
let!(:band) do
|
|
907
|
-
Band.create!(name:
|
|
834
|
+
Band.create!(name: 'Depeche Mode')
|
|
908
835
|
end
|
|
909
836
|
|
|
910
837
|
let(:found) do
|
|
911
|
-
Band.where(name:
|
|
838
|
+
Band.where(name: 'Depeche Mode').first_or_create!
|
|
912
839
|
end
|
|
913
840
|
|
|
914
|
-
it
|
|
841
|
+
it 'returns the document' do
|
|
915
842
|
expect(found).to eq(band)
|
|
916
843
|
end
|
|
917
844
|
end
|
|
918
845
|
|
|
919
|
-
context
|
|
920
|
-
|
|
846
|
+
context 'when the document is not found' do
|
|
921
847
|
let!(:band) do
|
|
922
|
-
Band.create!(name:
|
|
848
|
+
Band.create!(name: 'Depeche Mode')
|
|
923
849
|
end
|
|
924
850
|
|
|
925
|
-
context
|
|
926
|
-
|
|
851
|
+
context 'when attributes are provided' do
|
|
927
852
|
let(:document) do
|
|
928
|
-
Band.where(name:
|
|
853
|
+
Band.where(name: 'Tool').first_or_create!(origin: 'Essex')
|
|
929
854
|
end
|
|
930
855
|
|
|
931
|
-
it
|
|
932
|
-
expect(document.name).to eq(
|
|
856
|
+
it 'returns a new document' do
|
|
857
|
+
expect(document.name).to eq('Tool')
|
|
933
858
|
end
|
|
934
859
|
|
|
935
|
-
it
|
|
860
|
+
it 'returns a persisted document' do
|
|
936
861
|
expect(document).to be_persisted
|
|
937
862
|
end
|
|
938
863
|
|
|
939
|
-
it
|
|
940
|
-
expect(document.origin).to eq(
|
|
864
|
+
it 'sets the additional attributes' do
|
|
865
|
+
expect(document.origin).to eq('Essex')
|
|
941
866
|
end
|
|
942
867
|
end
|
|
943
868
|
|
|
944
|
-
context
|
|
945
|
-
|
|
869
|
+
context 'when attributes are not provided' do
|
|
946
870
|
let(:document) do
|
|
947
|
-
Band.where(name:
|
|
871
|
+
Band.where(name: 'Tool').first_or_create!
|
|
948
872
|
end
|
|
949
873
|
|
|
950
|
-
it
|
|
951
|
-
expect(document.name).to eq(
|
|
874
|
+
it 'returns a new document' do
|
|
875
|
+
expect(document.name).to eq('Tool')
|
|
952
876
|
end
|
|
953
877
|
|
|
954
|
-
it
|
|
878
|
+
it 'returns a persisted document' do
|
|
955
879
|
expect(document).to be_persisted
|
|
956
880
|
end
|
|
957
881
|
end
|
|
958
882
|
|
|
959
|
-
context
|
|
960
|
-
|
|
883
|
+
context 'when a block is provided' do
|
|
961
884
|
let(:document) do
|
|
962
|
-
Band.where(name:
|
|
885
|
+
Band.where(name: 'Tool').first_or_create! do |doc|
|
|
963
886
|
doc.active = false
|
|
964
887
|
end
|
|
965
888
|
end
|
|
966
889
|
|
|
967
|
-
it
|
|
968
|
-
expect(document.name).to eq(
|
|
890
|
+
it 'returns a new document' do
|
|
891
|
+
expect(document.name).to eq('Tool')
|
|
969
892
|
end
|
|
970
893
|
|
|
971
|
-
it
|
|
894
|
+
it 'returns a persisted document' do
|
|
972
895
|
expect(document).to be_persisted
|
|
973
896
|
end
|
|
974
897
|
|
|
975
|
-
it
|
|
898
|
+
it 'yields to the block' do
|
|
976
899
|
expect(document.active).to be false
|
|
977
900
|
end
|
|
978
901
|
end
|
|
979
902
|
|
|
980
|
-
context
|
|
981
|
-
|
|
982
|
-
context "when the document is not found" do
|
|
983
|
-
|
|
903
|
+
context 'when the criteria is complex' do
|
|
904
|
+
context 'when the document is not found' do
|
|
984
905
|
let(:document) do
|
|
985
|
-
Band.in(name: [
|
|
906
|
+
Band.in(name: [ 'New Order' ]).first_or_create!(active: false)
|
|
986
907
|
end
|
|
987
908
|
|
|
988
|
-
it
|
|
909
|
+
it 'returns a new document' do
|
|
989
910
|
expect(document.active).to be false
|
|
990
911
|
end
|
|
991
912
|
|
|
992
|
-
it
|
|
913
|
+
it 'returns a persisted document' do
|
|
993
914
|
expect(document).to be_persisted
|
|
994
915
|
end
|
|
995
916
|
end
|
|
996
917
|
end
|
|
997
918
|
|
|
998
919
|
context 'when attributes contain keys also in the criteria selector' do
|
|
999
|
-
|
|
1000
920
|
context 'when the selector has symbol keys' do
|
|
1001
|
-
|
|
1002
921
|
context 'when the attributes use symbol keys' do
|
|
1003
|
-
|
|
1004
922
|
let(:document) do
|
|
1005
923
|
Band.where(name: 'Tool').first_or_create!(name: 'Essex')
|
|
1006
924
|
end
|
|
@@ -1011,7 +929,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1011
929
|
end
|
|
1012
930
|
|
|
1013
931
|
context 'when the attributes use string keys' do
|
|
1014
|
-
|
|
1015
932
|
let(:document) do
|
|
1016
933
|
Band.where(name: 'Tool').first_or_create!('name' => 'Essex')
|
|
1017
934
|
end
|
|
@@ -1023,9 +940,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1023
940
|
end
|
|
1024
941
|
|
|
1025
942
|
context 'when the selector has string keys' do
|
|
1026
|
-
|
|
1027
943
|
context 'when the attributes use symbol keys' do
|
|
1028
|
-
|
|
1029
944
|
let(:document) do
|
|
1030
945
|
Band.where('name' => 'Tool').first_or_create!(name: 'Essex')
|
|
1031
946
|
end
|
|
@@ -1036,7 +951,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1036
951
|
end
|
|
1037
952
|
|
|
1038
953
|
context 'when the attributes use string keys' do
|
|
1039
|
-
|
|
1040
954
|
let(:document) do
|
|
1041
955
|
Band.where('name' => 'Tool').first_or_create!('name' => 'Essex')
|
|
1042
956
|
end
|
|
@@ -1050,7 +964,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1050
964
|
end
|
|
1051
965
|
|
|
1052
966
|
context 'when the object is polymorphic' do
|
|
1053
|
-
|
|
1054
967
|
let(:movie) do
|
|
1055
968
|
Movie.new
|
|
1056
969
|
end
|
|
@@ -1073,25 +986,22 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1073
986
|
end
|
|
1074
987
|
end
|
|
1075
988
|
|
|
1076
|
-
describe
|
|
1077
|
-
|
|
989
|
+
describe 'first_or_initialize' do
|
|
1078
990
|
let!(:band) do
|
|
1079
|
-
Band.create!(name:
|
|
991
|
+
Band.create!(name: 'Depeche Mode')
|
|
1080
992
|
end
|
|
1081
993
|
|
|
1082
|
-
context
|
|
1083
|
-
|
|
994
|
+
context 'when the document is found' do
|
|
1084
995
|
let(:found) do
|
|
1085
|
-
Band.where(name:
|
|
996
|
+
Band.where(name: 'Depeche Mode').first_or_initialize
|
|
1086
997
|
end
|
|
1087
998
|
|
|
1088
|
-
it
|
|
999
|
+
it 'returns the document' do
|
|
1089
1000
|
expect(found).to eq(band)
|
|
1090
1001
|
end
|
|
1091
1002
|
end
|
|
1092
1003
|
|
|
1093
1004
|
context 'when the object is polymorphic' do
|
|
1094
|
-
|
|
1095
1005
|
let(:movie) do
|
|
1096
1006
|
Movie.new
|
|
1097
1007
|
end
|
|
@@ -1113,87 +1023,78 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1113
1023
|
end
|
|
1114
1024
|
end
|
|
1115
1025
|
|
|
1116
|
-
context
|
|
1117
|
-
|
|
1118
|
-
context "when attributes are provided" do
|
|
1119
|
-
|
|
1026
|
+
context 'when the document is not found' do
|
|
1027
|
+
context 'when attributes are provided' do
|
|
1120
1028
|
let(:document) do
|
|
1121
|
-
Band.where(name:
|
|
1029
|
+
Band.where(name: 'Tool').first_or_initialize(origin: 'Essex')
|
|
1122
1030
|
end
|
|
1123
1031
|
|
|
1124
|
-
it
|
|
1125
|
-
expect(document.name).to eq(
|
|
1032
|
+
it 'returns a new document' do
|
|
1033
|
+
expect(document.name).to eq('Tool')
|
|
1126
1034
|
end
|
|
1127
1035
|
|
|
1128
|
-
it
|
|
1129
|
-
expect(document).
|
|
1036
|
+
it 'returns a non persisted document' do
|
|
1037
|
+
expect(document).not_to be_persisted
|
|
1130
1038
|
end
|
|
1131
1039
|
|
|
1132
|
-
it
|
|
1133
|
-
expect(document.origin).to eq(
|
|
1040
|
+
it 'sets the additional attributes' do
|
|
1041
|
+
expect(document.origin).to eq('Essex')
|
|
1134
1042
|
end
|
|
1135
1043
|
end
|
|
1136
1044
|
|
|
1137
|
-
context
|
|
1138
|
-
|
|
1045
|
+
context 'when attributes are not provided' do
|
|
1139
1046
|
let(:document) do
|
|
1140
|
-
Band.where(name:
|
|
1047
|
+
Band.where(name: 'Tool').first_or_initialize
|
|
1141
1048
|
end
|
|
1142
1049
|
|
|
1143
|
-
it
|
|
1144
|
-
expect(document.name).to eq(
|
|
1050
|
+
it 'returns a new document' do
|
|
1051
|
+
expect(document.name).to eq('Tool')
|
|
1145
1052
|
end
|
|
1146
1053
|
|
|
1147
|
-
it
|
|
1148
|
-
expect(document).
|
|
1054
|
+
it 'returns a non persisted document' do
|
|
1055
|
+
expect(document).not_to be_persisted
|
|
1149
1056
|
end
|
|
1150
1057
|
end
|
|
1151
1058
|
|
|
1152
|
-
context
|
|
1153
|
-
|
|
1059
|
+
context 'when a block is provided' do
|
|
1154
1060
|
let(:document) do
|
|
1155
|
-
Band.where(name:
|
|
1061
|
+
Band.where(name: 'Tool').first_or_initialize do |doc|
|
|
1156
1062
|
doc.active = false
|
|
1157
1063
|
end
|
|
1158
1064
|
end
|
|
1159
1065
|
|
|
1160
|
-
it
|
|
1161
|
-
expect(document.name).to eq(
|
|
1066
|
+
it 'returns a new document' do
|
|
1067
|
+
expect(document.name).to eq('Tool')
|
|
1162
1068
|
end
|
|
1163
1069
|
|
|
1164
|
-
it
|
|
1165
|
-
expect(document).
|
|
1070
|
+
it 'returns a non persisted document' do
|
|
1071
|
+
expect(document).not_to be_persisted
|
|
1166
1072
|
end
|
|
1167
1073
|
|
|
1168
|
-
it
|
|
1074
|
+
it 'yields to the block' do
|
|
1169
1075
|
expect(document.active).to be false
|
|
1170
1076
|
end
|
|
1171
1077
|
end
|
|
1172
1078
|
|
|
1173
|
-
context
|
|
1174
|
-
|
|
1175
|
-
context "when the document is not found" do
|
|
1176
|
-
|
|
1079
|
+
context 'when the criteria is complex' do
|
|
1080
|
+
context 'when the document is not found' do
|
|
1177
1081
|
let(:document) do
|
|
1178
|
-
Band.in(name: [
|
|
1082
|
+
Band.in(name: [ 'New Order' ]).first_or_initialize(active: false)
|
|
1179
1083
|
end
|
|
1180
1084
|
|
|
1181
|
-
it
|
|
1085
|
+
it 'returns a new document' do
|
|
1182
1086
|
expect(document.active).to be false
|
|
1183
1087
|
end
|
|
1184
1088
|
|
|
1185
|
-
it
|
|
1186
|
-
expect(document).
|
|
1089
|
+
it 'returns a non persisted document' do
|
|
1090
|
+
expect(document).not_to be_persisted
|
|
1187
1091
|
end
|
|
1188
1092
|
end
|
|
1189
1093
|
end
|
|
1190
1094
|
|
|
1191
1095
|
context 'when attributes contain keys also in the criteria selector' do
|
|
1192
|
-
|
|
1193
1096
|
context 'when the selector has symbol keys' do
|
|
1194
|
-
|
|
1195
1097
|
context 'when the attributes use symbol keys' do
|
|
1196
|
-
|
|
1197
1098
|
let(:document) do
|
|
1198
1099
|
Band.where(name: 'Tool').first_or_initialize(name: 'Essex')
|
|
1199
1100
|
end
|
|
@@ -1204,7 +1105,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1204
1105
|
end
|
|
1205
1106
|
|
|
1206
1107
|
context 'when the attributes use string keys' do
|
|
1207
|
-
|
|
1208
1108
|
let(:document) do
|
|
1209
1109
|
Band.where(name: 'Tool').first_or_initialize('name' => 'Essex')
|
|
1210
1110
|
end
|
|
@@ -1216,9 +1116,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1216
1116
|
end
|
|
1217
1117
|
|
|
1218
1118
|
context 'when the selector has string keys' do
|
|
1219
|
-
|
|
1220
1119
|
context 'when the attributes use symbol keys' do
|
|
1221
|
-
|
|
1222
1120
|
let(:document) do
|
|
1223
1121
|
Band.where('name' => 'Tool').first_or_initialize(name: 'Essex')
|
|
1224
1122
|
end
|
|
@@ -1229,7 +1127,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1229
1127
|
end
|
|
1230
1128
|
|
|
1231
1129
|
context 'when the attributes use string keys' do
|
|
1232
|
-
|
|
1233
1130
|
let(:document) do
|
|
1234
1131
|
Band.where('name' => 'Tool').first_or_initialize('name' => 'Essex')
|
|
1235
1132
|
end
|
|
@@ -1243,50 +1140,45 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1243
1140
|
end
|
|
1244
1141
|
end
|
|
1245
1142
|
|
|
1246
|
-
describe
|
|
1247
|
-
|
|
1143
|
+
describe '#update' do
|
|
1248
1144
|
let!(:person) do
|
|
1249
|
-
Person.create!(title:
|
|
1145
|
+
Person.create!(title: 'Sir')
|
|
1250
1146
|
end
|
|
1251
1147
|
|
|
1252
1148
|
let!(:address_one) do
|
|
1253
|
-
person.addresses.create!(street:
|
|
1149
|
+
person.addresses.create!(street: 'Oranienstr')
|
|
1254
1150
|
end
|
|
1255
1151
|
|
|
1256
1152
|
let!(:address_two) do
|
|
1257
|
-
person.addresses.create!(street:
|
|
1153
|
+
person.addresses.create!(street: 'Wienerstr')
|
|
1258
1154
|
end
|
|
1259
1155
|
|
|
1260
|
-
context
|
|
1261
|
-
|
|
1262
|
-
context "when updating with a criteria" do
|
|
1263
|
-
|
|
1156
|
+
context 'when updating the root document' do
|
|
1157
|
+
context 'when updating with a criteria' do
|
|
1264
1158
|
before do
|
|
1265
|
-
Person.where(title:
|
|
1159
|
+
Person.where(title: 'Sir').update(title: 'Madam')
|
|
1266
1160
|
end
|
|
1267
1161
|
|
|
1268
|
-
it
|
|
1269
|
-
expect(person.reload.title).to eq(
|
|
1162
|
+
it 'updates all the matching documents' do
|
|
1163
|
+
expect(person.reload.title).to eq('Madam')
|
|
1270
1164
|
end
|
|
1271
1165
|
end
|
|
1272
1166
|
|
|
1273
|
-
context
|
|
1274
|
-
|
|
1167
|
+
context 'when updating all directly' do
|
|
1275
1168
|
before do
|
|
1276
|
-
Person.update(title:
|
|
1169
|
+
Person.update(title: 'Madam')
|
|
1277
1170
|
end
|
|
1278
1171
|
|
|
1279
|
-
it
|
|
1280
|
-
expect(person.reload.title).to eq(
|
|
1172
|
+
it 'updates all the matching documents' do
|
|
1173
|
+
expect(person.reload.title).to eq('Madam')
|
|
1281
1174
|
end
|
|
1282
1175
|
end
|
|
1283
1176
|
end
|
|
1284
1177
|
|
|
1285
|
-
context
|
|
1286
|
-
|
|
1178
|
+
context 'when updating an embedded document' do
|
|
1287
1179
|
before do
|
|
1288
|
-
Person.where(title:
|
|
1289
|
-
|
|
1180
|
+
Person.where(title: 'Sir').update(
|
|
1181
|
+
'addresses.0.city' => 'Berlin'
|
|
1290
1182
|
)
|
|
1291
1183
|
end
|
|
1292
1184
|
|
|
@@ -1294,199 +1186,184 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1294
1186
|
Person.first
|
|
1295
1187
|
end
|
|
1296
1188
|
|
|
1297
|
-
it
|
|
1298
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1189
|
+
it 'updates all the matching documents' do
|
|
1190
|
+
expect(from_db.addresses.first.city).to eq('Berlin')
|
|
1299
1191
|
end
|
|
1300
1192
|
|
|
1301
|
-
it
|
|
1193
|
+
it 'does not update non matching documents' do
|
|
1302
1194
|
expect(from_db.addresses.last.city).to be_nil
|
|
1303
1195
|
end
|
|
1304
1196
|
end
|
|
1305
1197
|
|
|
1306
|
-
context
|
|
1307
|
-
|
|
1308
|
-
context "when the relation is an embeds many" do
|
|
1309
|
-
|
|
1198
|
+
context 'when updating a relation' do
|
|
1199
|
+
context 'when the relation is an embeds many' do
|
|
1310
1200
|
let(:from_db) do
|
|
1311
1201
|
Person.first
|
|
1312
1202
|
end
|
|
1313
1203
|
|
|
1314
|
-
context
|
|
1315
|
-
|
|
1204
|
+
context 'when updating the relation directly' do
|
|
1316
1205
|
before do
|
|
1317
|
-
person.addresses.update(city:
|
|
1206
|
+
person.addresses.update(city: 'London')
|
|
1318
1207
|
end
|
|
1319
1208
|
|
|
1320
|
-
it
|
|
1321
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1209
|
+
it 'updates the first document' do
|
|
1210
|
+
expect(from_db.addresses.first.city).to eq('London')
|
|
1322
1211
|
end
|
|
1323
1212
|
|
|
1324
|
-
it
|
|
1213
|
+
it 'does not update the last document' do
|
|
1325
1214
|
expect(from_db.addresses.last.city).to be_nil
|
|
1326
1215
|
end
|
|
1327
1216
|
end
|
|
1328
1217
|
|
|
1329
|
-
context
|
|
1330
|
-
|
|
1218
|
+
context 'when updating the relation through a criteria' do
|
|
1331
1219
|
before do
|
|
1332
|
-
person.addresses.where(street:
|
|
1220
|
+
person.addresses.where(street: 'Oranienstr').update(city: 'Berlin')
|
|
1333
1221
|
end
|
|
1334
1222
|
|
|
1335
|
-
it
|
|
1336
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1223
|
+
it 'updates the matching documents' do
|
|
1224
|
+
expect(from_db.addresses.first.city).to eq('Berlin')
|
|
1337
1225
|
end
|
|
1338
1226
|
|
|
1339
|
-
it
|
|
1227
|
+
it 'does not update non matching documents' do
|
|
1340
1228
|
expect(from_db.addresses.last.city).to be_nil
|
|
1341
1229
|
end
|
|
1342
1230
|
end
|
|
1343
1231
|
end
|
|
1344
1232
|
|
|
1345
|
-
context
|
|
1346
|
-
|
|
1233
|
+
context 'when the relation is a references many' do
|
|
1347
1234
|
before do
|
|
1348
|
-
person.posts.create!(title:
|
|
1349
|
-
person.posts.create!(title:
|
|
1235
|
+
person.posts.create!(title: 'First')
|
|
1236
|
+
person.posts.create!(title: 'Second')
|
|
1350
1237
|
end
|
|
1351
1238
|
|
|
1352
|
-
context
|
|
1353
|
-
|
|
1239
|
+
context 'when updating the relation directly' do
|
|
1354
1240
|
before do
|
|
1355
|
-
person.posts.update(title:
|
|
1241
|
+
person.posts.update(title: 'London')
|
|
1356
1242
|
end
|
|
1357
1243
|
|
|
1358
1244
|
let(:from_db) do
|
|
1359
1245
|
Person.first
|
|
1360
1246
|
end
|
|
1361
1247
|
|
|
1362
|
-
it
|
|
1363
|
-
expect(from_db.posts.map(&:title)).to eq([
|
|
1248
|
+
it 'updates the first document' do
|
|
1249
|
+
expect(from_db.posts.map(&:title)).to eq(%w[London Second])
|
|
1364
1250
|
end
|
|
1365
1251
|
|
|
1366
|
-
it
|
|
1367
|
-
expect(from_db.posts[1].title).to eq(
|
|
1252
|
+
it 'does not update the last document' do
|
|
1253
|
+
expect(from_db.posts[1].title).to eq('Second')
|
|
1368
1254
|
end
|
|
1369
1255
|
end
|
|
1370
1256
|
|
|
1371
|
-
context
|
|
1372
|
-
|
|
1257
|
+
context 'when updating the relation through a criteria' do
|
|
1373
1258
|
before do
|
|
1374
|
-
person.posts.where(title:
|
|
1259
|
+
person.posts.where(title: 'First').update(title: 'Berlin')
|
|
1375
1260
|
end
|
|
1376
1261
|
|
|
1377
1262
|
let!(:from_db) do
|
|
1378
1263
|
Person.first
|
|
1379
1264
|
end
|
|
1380
1265
|
|
|
1381
|
-
it
|
|
1382
|
-
expect(from_db.posts.where(title:
|
|
1266
|
+
it 'updates the matching documents' do
|
|
1267
|
+
expect(from_db.posts.where(title: 'Berlin').count).to eq(1)
|
|
1383
1268
|
end
|
|
1384
1269
|
|
|
1385
|
-
it
|
|
1386
|
-
expect(from_db.posts.where(title:
|
|
1270
|
+
it 'does not update non matching documents' do
|
|
1271
|
+
expect(from_db.posts.where(title: 'Second').count).to eq(1)
|
|
1387
1272
|
end
|
|
1388
1273
|
end
|
|
1389
1274
|
end
|
|
1390
1275
|
|
|
1391
|
-
context
|
|
1392
|
-
|
|
1276
|
+
context 'when the relation is a references many to many' do
|
|
1393
1277
|
let(:from_db) do
|
|
1394
1278
|
Person.first
|
|
1395
1279
|
end
|
|
1396
1280
|
|
|
1397
1281
|
let!(:preference_one) do
|
|
1398
|
-
person.preferences.create!(name:
|
|
1282
|
+
person.preferences.create!(name: 'First')
|
|
1399
1283
|
end
|
|
1400
1284
|
|
|
1401
1285
|
let!(:preference_two) do
|
|
1402
|
-
person.preferences.create!(name:
|
|
1286
|
+
person.preferences.create!(name: 'Second')
|
|
1403
1287
|
end
|
|
1404
1288
|
|
|
1405
|
-
context
|
|
1406
|
-
|
|
1289
|
+
context 'when updating the relation directly' do
|
|
1407
1290
|
before do
|
|
1408
|
-
person.preferences.update(name:
|
|
1291
|
+
person.preferences.update(name: 'London')
|
|
1409
1292
|
end
|
|
1410
1293
|
|
|
1411
|
-
it
|
|
1412
|
-
expect(from_db.preferences[0].name).to eq(
|
|
1294
|
+
it 'updates the first document' do
|
|
1295
|
+
expect(from_db.preferences[0].name).to eq('London')
|
|
1413
1296
|
end
|
|
1414
1297
|
|
|
1415
|
-
it
|
|
1416
|
-
expect(from_db.preferences[1].name).to eq(
|
|
1298
|
+
it 'does not update the last document' do
|
|
1299
|
+
expect(from_db.preferences[1].name).to eq('Second')
|
|
1417
1300
|
end
|
|
1418
1301
|
end
|
|
1419
1302
|
|
|
1420
|
-
context
|
|
1421
|
-
|
|
1303
|
+
context 'when updating the relation through a criteria' do
|
|
1422
1304
|
before do
|
|
1423
|
-
person.preferences.where(name:
|
|
1305
|
+
person.preferences.where(name: 'First').update(name: 'Berlin')
|
|
1424
1306
|
end
|
|
1425
1307
|
|
|
1426
|
-
it
|
|
1427
|
-
expect(from_db.preferences[0].name).to eq(
|
|
1308
|
+
it 'updates the matching documents' do
|
|
1309
|
+
expect(from_db.preferences[0].name).to eq('Berlin')
|
|
1428
1310
|
end
|
|
1429
1311
|
|
|
1430
|
-
it
|
|
1431
|
-
expect(from_db.preferences[1].name).to eq(
|
|
1312
|
+
it 'does not update non matching documents' do
|
|
1313
|
+
expect(from_db.preferences[1].name).to eq('Second')
|
|
1432
1314
|
end
|
|
1433
1315
|
end
|
|
1434
1316
|
end
|
|
1435
1317
|
end
|
|
1436
1318
|
end
|
|
1437
1319
|
|
|
1438
|
-
describe
|
|
1439
|
-
|
|
1320
|
+
describe '#update_all' do
|
|
1440
1321
|
let!(:person) do
|
|
1441
|
-
Person.create!(title:
|
|
1322
|
+
Person.create!(title: 'Sir')
|
|
1442
1323
|
end
|
|
1443
1324
|
|
|
1444
1325
|
let!(:address_one) do
|
|
1445
|
-
person.addresses.create!(street:
|
|
1326
|
+
person.addresses.create!(street: 'Oranienstr')
|
|
1446
1327
|
end
|
|
1447
1328
|
|
|
1448
1329
|
let!(:address_two) do
|
|
1449
|
-
person.addresses.create!(street:
|
|
1330
|
+
person.addresses.create!(street: 'Wienerstr')
|
|
1450
1331
|
end
|
|
1451
1332
|
|
|
1452
|
-
context
|
|
1453
|
-
|
|
1454
|
-
context "when updating with a criteria" do
|
|
1455
|
-
|
|
1333
|
+
context 'when updating the root document' do
|
|
1334
|
+
context 'when updating with a criteria' do
|
|
1456
1335
|
let(:from_db) do
|
|
1457
1336
|
Person.first
|
|
1458
1337
|
end
|
|
1459
1338
|
|
|
1460
1339
|
before do
|
|
1461
|
-
Person.where(title:
|
|
1340
|
+
Person.where(title: 'Sir').update_all(title: 'Madam')
|
|
1462
1341
|
end
|
|
1463
1342
|
|
|
1464
|
-
it
|
|
1465
|
-
expect(from_db.title).to eq(
|
|
1343
|
+
it 'updates all the matching documents' do
|
|
1344
|
+
expect(from_db.title).to eq('Madam')
|
|
1466
1345
|
end
|
|
1467
1346
|
end
|
|
1468
1347
|
|
|
1469
|
-
context
|
|
1470
|
-
|
|
1348
|
+
context 'when updating all directly' do
|
|
1471
1349
|
let(:from_db) do
|
|
1472
1350
|
Person.first
|
|
1473
1351
|
end
|
|
1474
1352
|
|
|
1475
1353
|
before do
|
|
1476
|
-
Person.update_all(title:
|
|
1354
|
+
Person.update_all(title: 'Madam')
|
|
1477
1355
|
end
|
|
1478
1356
|
|
|
1479
|
-
it
|
|
1480
|
-
expect(from_db.title).to eq(
|
|
1357
|
+
it 'updates all the matching documents' do
|
|
1358
|
+
expect(from_db.title).to eq('Madam')
|
|
1481
1359
|
end
|
|
1482
1360
|
end
|
|
1483
1361
|
end
|
|
1484
1362
|
|
|
1485
|
-
context
|
|
1486
|
-
|
|
1363
|
+
context 'when updating an embedded document' do
|
|
1487
1364
|
before do
|
|
1488
|
-
Person.where(title:
|
|
1489
|
-
|
|
1365
|
+
Person.where(title: 'Sir').update_all(
|
|
1366
|
+
'addresses.0.city' => 'Berlin'
|
|
1490
1367
|
)
|
|
1491
1368
|
end
|
|
1492
1369
|
|
|
@@ -1494,144 +1371,134 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1494
1371
|
Person.first
|
|
1495
1372
|
end
|
|
1496
1373
|
|
|
1497
|
-
it
|
|
1498
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1374
|
+
it 'updates all the matching documents' do
|
|
1375
|
+
expect(from_db.addresses.first.city).to eq('Berlin')
|
|
1499
1376
|
end
|
|
1500
1377
|
|
|
1501
|
-
it
|
|
1378
|
+
it 'does not update non matching documents' do
|
|
1502
1379
|
expect(from_db.addresses.last.city).to be_nil
|
|
1503
1380
|
end
|
|
1504
1381
|
end
|
|
1505
1382
|
|
|
1506
|
-
context
|
|
1507
|
-
|
|
1508
|
-
context "when the relation is an embeds many" do
|
|
1509
|
-
|
|
1383
|
+
context 'when updating a relation' do
|
|
1384
|
+
context 'when the relation is an embeds many' do
|
|
1510
1385
|
let(:from_db) do
|
|
1511
1386
|
Person.first
|
|
1512
1387
|
end
|
|
1513
1388
|
|
|
1514
|
-
context
|
|
1515
|
-
|
|
1389
|
+
context 'when updating the relation directly' do
|
|
1516
1390
|
before do
|
|
1517
|
-
person.addresses.update_all(city:
|
|
1391
|
+
person.addresses.update_all(city: 'London')
|
|
1518
1392
|
end
|
|
1519
1393
|
|
|
1520
|
-
it
|
|
1521
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1394
|
+
it 'updates the first document' do
|
|
1395
|
+
expect(from_db.addresses.first.city).to eq('London')
|
|
1522
1396
|
end
|
|
1523
1397
|
|
|
1524
|
-
it
|
|
1525
|
-
expect(from_db.addresses.last.city).to eq(
|
|
1398
|
+
it 'updates the last document' do
|
|
1399
|
+
expect(from_db.addresses.last.city).to eq('London')
|
|
1526
1400
|
end
|
|
1527
1401
|
end
|
|
1528
1402
|
|
|
1529
|
-
context
|
|
1530
|
-
|
|
1403
|
+
context 'when updating the relation through a criteria' do
|
|
1531
1404
|
before do
|
|
1532
|
-
person.addresses.where(street:
|
|
1405
|
+
person.addresses.where(street: 'Oranienstr').update_all(city: 'Berlin')
|
|
1533
1406
|
end
|
|
1534
1407
|
|
|
1535
|
-
it
|
|
1536
|
-
expect(from_db.addresses.first.city).to eq(
|
|
1408
|
+
it 'updates the matching documents' do
|
|
1409
|
+
expect(from_db.addresses.first.city).to eq('Berlin')
|
|
1537
1410
|
end
|
|
1538
1411
|
|
|
1539
|
-
it
|
|
1412
|
+
it 'does not update non matching documents' do
|
|
1540
1413
|
expect(from_db.addresses.last.city).to be_nil
|
|
1541
1414
|
end
|
|
1542
1415
|
end
|
|
1543
1416
|
end
|
|
1544
1417
|
|
|
1545
|
-
context
|
|
1546
|
-
|
|
1418
|
+
context 'when the relation is a references many' do
|
|
1547
1419
|
let!(:post_one) do
|
|
1548
|
-
person.posts.create!(title:
|
|
1420
|
+
person.posts.create!(title: 'First')
|
|
1549
1421
|
end
|
|
1550
1422
|
|
|
1551
1423
|
let!(:post_two) do
|
|
1552
|
-
person.posts.create!(title:
|
|
1424
|
+
person.posts.create!(title: 'Second')
|
|
1553
1425
|
end
|
|
1554
1426
|
|
|
1555
|
-
context
|
|
1556
|
-
|
|
1427
|
+
context 'when updating the relation directly' do
|
|
1557
1428
|
before do
|
|
1558
|
-
person.posts.update_all(title:
|
|
1429
|
+
person.posts.update_all(title: 'London')
|
|
1559
1430
|
end
|
|
1560
1431
|
|
|
1561
1432
|
let!(:from_db) do
|
|
1562
1433
|
Person.first
|
|
1563
1434
|
end
|
|
1564
1435
|
|
|
1565
|
-
it
|
|
1566
|
-
expect(from_db.posts.first.title).to eq(
|
|
1436
|
+
it 'updates the first document' do
|
|
1437
|
+
expect(from_db.posts.first.title).to eq('London')
|
|
1567
1438
|
end
|
|
1568
1439
|
|
|
1569
|
-
it
|
|
1570
|
-
expect(from_db.posts.last.title).to eq(
|
|
1440
|
+
it 'updates the last document' do
|
|
1441
|
+
expect(from_db.posts.last.title).to eq('London')
|
|
1571
1442
|
end
|
|
1572
1443
|
end
|
|
1573
1444
|
|
|
1574
|
-
context
|
|
1575
|
-
|
|
1445
|
+
context 'when updating the relation through a criteria' do
|
|
1576
1446
|
before do
|
|
1577
|
-
person.posts.where(title:
|
|
1447
|
+
person.posts.where(title: 'First').update_all(title: 'Berlin')
|
|
1578
1448
|
end
|
|
1579
1449
|
|
|
1580
1450
|
let!(:from_db) do
|
|
1581
1451
|
Person.first
|
|
1582
1452
|
end
|
|
1583
1453
|
|
|
1584
|
-
it
|
|
1585
|
-
expect(from_db.posts.where(title:
|
|
1454
|
+
it 'updates the matching documents' do
|
|
1455
|
+
expect(from_db.posts.where(title: 'Berlin').count).to eq(1)
|
|
1586
1456
|
end
|
|
1587
1457
|
|
|
1588
|
-
it
|
|
1589
|
-
expect(from_db.posts.where(title:
|
|
1458
|
+
it 'does not update non matching documents' do
|
|
1459
|
+
expect(from_db.posts.where(title: 'Second').count).to eq(1)
|
|
1590
1460
|
end
|
|
1591
1461
|
end
|
|
1592
1462
|
end
|
|
1593
1463
|
|
|
1594
|
-
context
|
|
1595
|
-
|
|
1464
|
+
context 'when the relation is a references many to many' do
|
|
1596
1465
|
let(:from_db) do
|
|
1597
1466
|
Person.first
|
|
1598
1467
|
end
|
|
1599
1468
|
|
|
1600
1469
|
let!(:preference_one) do
|
|
1601
|
-
person.preferences.create!(name:
|
|
1470
|
+
person.preferences.create!(name: 'First')
|
|
1602
1471
|
end
|
|
1603
1472
|
|
|
1604
1473
|
let!(:preference_two) do
|
|
1605
|
-
person.preferences.create!(name:
|
|
1474
|
+
person.preferences.create!(name: 'Second')
|
|
1606
1475
|
end
|
|
1607
1476
|
|
|
1608
|
-
context
|
|
1609
|
-
|
|
1477
|
+
context 'when updating the relation directly' do
|
|
1610
1478
|
before do
|
|
1611
|
-
person.preferences.update_all(name:
|
|
1479
|
+
person.preferences.update_all(name: 'London')
|
|
1612
1480
|
end
|
|
1613
1481
|
|
|
1614
|
-
it
|
|
1615
|
-
expect(from_db.preferences.first.name).to eq(
|
|
1482
|
+
it 'updates the first document' do
|
|
1483
|
+
expect(from_db.preferences.first.name).to eq('London')
|
|
1616
1484
|
end
|
|
1617
1485
|
|
|
1618
|
-
it
|
|
1619
|
-
expect(from_db.preferences.last.name).to eq(
|
|
1486
|
+
it 'updates the last document' do
|
|
1487
|
+
expect(from_db.preferences.last.name).to eq('London')
|
|
1620
1488
|
end
|
|
1621
1489
|
end
|
|
1622
1490
|
|
|
1623
|
-
context
|
|
1624
|
-
|
|
1491
|
+
context 'when updating the relation through a criteria' do
|
|
1625
1492
|
before do
|
|
1626
|
-
person.preferences.where(name:
|
|
1493
|
+
person.preferences.where(name: 'First').update_all(name: 'Berlin')
|
|
1627
1494
|
end
|
|
1628
1495
|
|
|
1629
|
-
it
|
|
1630
|
-
expect(from_db.preferences[0].name).to eq(
|
|
1496
|
+
it 'updates the matching documents' do
|
|
1497
|
+
expect(from_db.preferences[0].name).to eq('Berlin')
|
|
1631
1498
|
end
|
|
1632
1499
|
|
|
1633
|
-
it
|
|
1634
|
-
expect(from_db.preferences[1].name).to eq(
|
|
1500
|
+
it 'does not update non matching documents' do
|
|
1501
|
+
expect(from_db.preferences[1].name).to eq('Second')
|
|
1635
1502
|
end
|
|
1636
1503
|
end
|
|
1637
1504
|
end
|
|
@@ -1639,9 +1506,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1639
1506
|
end
|
|
1640
1507
|
|
|
1641
1508
|
describe '#create_with' do
|
|
1642
|
-
|
|
1643
1509
|
context 'when called on the class' do
|
|
1644
|
-
|
|
1645
1510
|
let(:attrs) do
|
|
1646
1511
|
{ 'username' => 'Turnip' }
|
|
1647
1512
|
end
|
|
@@ -1655,16 +1520,13 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1655
1520
|
end
|
|
1656
1521
|
|
|
1657
1522
|
context 'when a create is chained' do
|
|
1658
|
-
|
|
1659
1523
|
context 'when a write method is chained' do
|
|
1660
|
-
|
|
1661
1524
|
it 'executes the method' do
|
|
1662
1525
|
expect(Person.create_with(attrs).new.username).to eq('Turnip')
|
|
1663
1526
|
end
|
|
1664
1527
|
end
|
|
1665
1528
|
|
|
1666
1529
|
context 'when a write method is chained' do
|
|
1667
|
-
|
|
1668
1530
|
let(:query) do
|
|
1669
1531
|
{ 'age' => 50 }
|
|
1670
1532
|
end
|
|
@@ -1698,7 +1560,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1698
1560
|
end
|
|
1699
1561
|
|
|
1700
1562
|
context 'when the attributes are shared with the write method args' do
|
|
1701
|
-
|
|
1702
1563
|
let(:query) do
|
|
1703
1564
|
{ 'username' => 'Beet', 'age' => 50 }
|
|
1704
1565
|
end
|
|
@@ -1717,7 +1578,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1717
1578
|
end
|
|
1718
1579
|
|
|
1719
1580
|
context 'when called on a criteria' do
|
|
1720
|
-
|
|
1721
1581
|
let(:criteria_selector) do
|
|
1722
1582
|
{ 'username' => 'Artichoke', 'age' => 25 }
|
|
1723
1583
|
end
|
|
@@ -1727,9 +1587,7 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1727
1587
|
end
|
|
1728
1588
|
|
|
1729
1589
|
context 'when the original criteria shares attributes with the attribute args' do
|
|
1730
|
-
|
|
1731
1590
|
context 'when all the original attributes are shared with the new attributes' do
|
|
1732
|
-
|
|
1733
1591
|
let(:attrs) do
|
|
1734
1592
|
{ 'username' => 'Beet', 'age' => 50 }
|
|
1735
1593
|
end
|
|
@@ -1745,7 +1603,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1745
1603
|
end
|
|
1746
1604
|
|
|
1747
1605
|
context 'when only some of the original attributes are shared with the attribute args' do
|
|
1748
|
-
|
|
1749
1606
|
let(:attrs) do
|
|
1750
1607
|
{ 'username' => 'Beet' }
|
|
1751
1608
|
end
|
|
@@ -1760,7 +1617,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1760
1617
|
end
|
|
1761
1618
|
|
|
1762
1619
|
context 'when a method is chained' do
|
|
1763
|
-
|
|
1764
1620
|
let(:attrs) do
|
|
1765
1621
|
{ 'username' => 'Turnip' }
|
|
1766
1622
|
end
|
|
@@ -1769,7 +1625,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1769
1625
|
end
|
|
1770
1626
|
|
|
1771
1627
|
context 'when a create method is chained' do
|
|
1772
|
-
|
|
1773
1628
|
it 'executes the method' do
|
|
1774
1629
|
expect(criteria.create_with(attrs).new.username).to eq('Turnip')
|
|
1775
1630
|
expect(criteria.create_with(attrs).new.age).to eq(25)
|
|
@@ -1777,7 +1632,6 @@ describe Mongoid::Criteria::Modifiable do
|
|
|
1777
1632
|
end
|
|
1778
1633
|
|
|
1779
1634
|
context 'when a write method is chained producing conflicting criteria' do
|
|
1780
|
-
|
|
1781
1635
|
let(:new_person) do
|
|
1782
1636
|
criteria.create_with(attrs).find_or_create_by(query)
|
|
1783
1637
|
end
|