mongoid 7.1.1 → 8.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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +20 -20
- data/README.md +15 -8
- data/Rakefile +61 -5
- data/lib/config/locales/en.yml +162 -56
- data/lib/mongoid/association/accessors.rb +89 -40
- data/lib/mongoid/association/bindable.rb +50 -23
- data/lib/mongoid/association/builders.rb +5 -12
- data/lib/mongoid/association/constrainable.rb +1 -5
- data/lib/mongoid/association/depending.rb +5 -17
- data/lib/mongoid/association/eager_loadable.rb +29 -10
- data/lib/mongoid/association/embedded/batchable.rb +64 -52
- data/lib/mongoid/association/embedded/cyclic.rb +3 -12
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -5
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +4 -16
- data/lib/mongoid/association/embedded/embedded_in.rb +4 -26
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -7
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +4 -6
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +110 -92
- data/lib/mongoid/association/embedded/embeds_many.rb +4 -34
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -7
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +19 -8
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +50 -19
- data/lib/mongoid/association/embedded/embeds_one.rb +5 -31
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +27 -5
- data/lib/mongoid/association/many.rb +14 -27
- data/lib/mongoid/association/marshalable.rb +0 -5
- data/lib/mongoid/association/nested/many.rb +6 -16
- data/lib/mongoid/association/nested/nested_buildable.rb +4 -13
- data/lib/mongoid/association/nested/one.rb +48 -23
- data/lib/mongoid/association/nested.rb +0 -3
- data/lib/mongoid/association/one.rb +2 -11
- data/lib/mongoid/association/options.rb +9 -42
- data/lib/mongoid/association/proxy.rb +22 -27
- data/lib/mongoid/association/referenced/auto_save.rb +6 -14
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +2 -8
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +5 -6
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +0 -1
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -19
- data/lib/mongoid/association/referenced/belongs_to.rb +11 -36
- data/lib/mongoid/association/referenced/counter_cache.rb +12 -25
- data/lib/mongoid/association/referenced/eager.rb +5 -26
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -5
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +81 -51
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +17 -41
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +438 -461
- data/lib/mongoid/association/referenced/has_many/proxy.rb +58 -84
- data/lib/mongoid/association/referenced/has_many.rb +15 -42
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -7
- data/lib/mongoid/association/referenced/has_one/buildable.rb +12 -5
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +7 -22
- data/lib/mongoid/association/referenced/has_one/proxy.rb +9 -16
- data/lib/mongoid/association/referenced/has_one.rb +12 -35
- data/lib/mongoid/association/referenced/syncable.rb +4 -21
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +4 -5
- data/lib/mongoid/association/relatable.rb +46 -71
- data/lib/mongoid/association.rb +5 -22
- data/lib/mongoid/atomic/modifiers.rb +7 -54
- data/lib/mongoid/atomic/paths/embedded/many.rb +19 -5
- data/lib/mongoid/atomic/paths/embedded/one.rb +0 -5
- data/lib/mongoid/atomic/paths/embedded.rb +0 -3
- data/lib/mongoid/atomic/paths/root.rb +0 -5
- data/lib/mongoid/atomic/paths.rb +0 -1
- data/lib/mongoid/atomic.rb +40 -47
- data/lib/mongoid/attributes/dynamic.rb +5 -22
- data/lib/mongoid/attributes/nested.rb +6 -11
- data/lib/mongoid/attributes/processing.rb +11 -21
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +3 -8
- data/lib/mongoid/attributes.rb +82 -88
- data/lib/mongoid/cacheable.rb +4 -9
- data/lib/mongoid/changeable.rb +148 -69
- data/lib/mongoid/clients/factory.rb +41 -17
- data/lib/mongoid/clients/options.rb +13 -14
- data/lib/mongoid/clients/sessions.rb +8 -11
- data/lib/mongoid/clients/storage_options.rb +7 -17
- data/lib/mongoid/clients/validators/storage.rb +3 -24
- data/lib/mongoid/clients/validators.rb +0 -1
- data/lib/mongoid/clients.rb +1 -10
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +3 -7
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/environment.rb +28 -5
- data/lib/mongoid/config/options.rb +0 -11
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators/client.rb +6 -23
- data/lib/mongoid/config/validators/option.rb +0 -3
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config.rb +183 -39
- data/lib/mongoid/contextual/aggregable/memory.rb +37 -26
- data/lib/mongoid/contextual/aggregable/mongo.rb +29 -32
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +7 -27
- data/lib/mongoid/contextual/command.rb +0 -5
- data/lib/mongoid/contextual/geo_near.rb +8 -41
- data/lib/mongoid/contextual/map_reduce.rb +2 -33
- data/lib/mongoid/contextual/memory.rb +383 -79
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +636 -283
- data/lib/mongoid/contextual/none.rb +262 -31
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +14 -7
- data/lib/mongoid/copyable.rb +39 -16
- data/lib/mongoid/criteria/findable.rb +9 -19
- data/lib/mongoid/criteria/includable.rb +27 -31
- data/lib/mongoid/criteria/inspectable.rb +0 -3
- data/lib/mongoid/criteria/marshalable.rb +10 -7
- data/lib/mongoid/criteria/modifiable.rb +2 -20
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +1 -2
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -15
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -25
- data/lib/mongoid/criteria/queryable/extensions/array.rb +4 -40
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -7
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +3 -6
- data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -8
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -6
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -40
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +0 -13
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -20
- data/lib/mongoid/criteria/queryable/extensions/object.rb +3 -29
- data/lib/mongoid/criteria/queryable/extensions/range.rb +46 -16
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +9 -18
- data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/string.rb +4 -31
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +4 -21
- data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -8
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +16 -6
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -5
- data/lib/mongoid/criteria/queryable/key.rb +6 -19
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +123 -38
- data/lib/mongoid/criteria/queryable/optional.rb +11 -62
- data/lib/mongoid/criteria/queryable/options.rb +2 -21
- data/lib/mongoid/criteria/queryable/pipeline.rb +1 -14
- data/lib/mongoid/criteria/queryable/selectable.rb +138 -125
- data/lib/mongoid/criteria/queryable/selector.rb +94 -30
- data/lib/mongoid/criteria/queryable/smash.rb +40 -18
- data/lib/mongoid/criteria/queryable/storable.rb +14 -10
- data/lib/mongoid/criteria/queryable.rb +11 -13
- data/lib/mongoid/criteria/scopable.rb +27 -21
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +88 -108
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +149 -99
- data/lib/mongoid/equality.rb +32 -16
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/callback.rb +0 -3
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +0 -1
- data/lib/mongoid/errors/delete_restriction.rb +8 -12
- data/lib/mongoid/errors/document_not_destroyed.rb +2 -7
- data/lib/mongoid/errors/document_not_found.rb +33 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -3
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_collection.rb +0 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +1 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -4
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +6 -7
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +0 -3
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_find.rb +0 -3
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_includes.rb +0 -3
- data/lib/mongoid/errors/invalid_index.rb +0 -3
- data/lib/mongoid/errors/invalid_options.rb +0 -3
- data/lib/mongoid/errors/invalid_path.rb +0 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +0 -5
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +1 -8
- data/lib/mongoid/errors/invalid_relation_option.rb +1 -4
- data/lib/mongoid/errors/invalid_scope.rb +0 -3
- data/lib/mongoid/errors/invalid_session_use.rb +1 -6
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +0 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -3
- data/lib/mongoid/errors/invalid_time.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +0 -3
- data/lib/mongoid/errors/mixed_client_configuration.rb +0 -3
- data/lib/mongoid/errors/mixed_relations.rb +0 -3
- data/lib/mongoid/errors/mongoid_error.rb +4 -13
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +2 -5
- 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 +0 -3
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +0 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +0 -3
- data/lib/mongoid/errors/no_metadata.rb +0 -3
- data/lib/mongoid/errors/no_parent.rb +0 -3
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -6
- data/lib/mongoid/errors/scope_overwrite.rb +0 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -2
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +0 -3
- data/lib/mongoid/errors/unsaved_document.rb +1 -2
- data/lib/mongoid/errors/unsupported_javascript.rb +0 -3
- data/lib/mongoid/errors/validations.rb +0 -1
- data/lib/mongoid/errors.rb +15 -4
- data/lib/mongoid/evolvable.rb +1 -4
- data/lib/mongoid/extensions/array.rb +12 -36
- data/lib/mongoid/extensions/big_decimal.rb +33 -21
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +8 -6
- data/lib/mongoid/extensions/date.rb +26 -29
- data/lib/mongoid/extensions/date_time.rb +1 -10
- data/lib/mongoid/extensions/decimal128.rb +0 -5
- data/lib/mongoid/extensions/false_class.rb +3 -8
- data/lib/mongoid/extensions/float.rb +7 -11
- data/lib/mongoid/extensions/hash.rb +19 -37
- data/lib/mongoid/extensions/integer.rb +7 -13
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -5
- data/lib/mongoid/extensions/object.rb +11 -48
- data/lib/mongoid/extensions/object_id.rb +0 -7
- data/lib/mongoid/extensions/range.rb +40 -20
- data/lib/mongoid/extensions/regexp.rb +12 -8
- data/lib/mongoid/extensions/set.rb +11 -11
- data/lib/mongoid/extensions/string.rb +12 -52
- data/lib/mongoid/extensions/symbol.rb +4 -22
- data/lib/mongoid/extensions/time.rb +28 -26
- data/lib/mongoid/extensions/time_with_zone.rb +14 -11
- data/lib/mongoid/extensions/true_class.rb +3 -8
- data/lib/mongoid/extensions.rb +17 -3
- data/lib/mongoid/factory.rb +80 -16
- data/lib/mongoid/fields/foreign_key.rb +11 -25
- data/lib/mongoid/fields/localized.rb +19 -15
- data/lib/mongoid/fields/standard.rb +17 -40
- data/lib/mongoid/fields/validators/macro.rb +25 -24
- data/lib/mongoid/fields/validators.rb +0 -1
- data/lib/mongoid/fields.rb +346 -75
- data/lib/mongoid/findable.rb +107 -31
- data/lib/mongoid/indexable/specification.rb +2 -17
- data/lib/mongoid/indexable/validators/options.rb +6 -9
- data/lib/mongoid/indexable.rb +3 -20
- data/lib/mongoid/inspectable.rb +2 -11
- data/lib/mongoid/interceptable.rb +79 -41
- data/lib/mongoid/loggable.rb +0 -9
- data/lib/mongoid/matchable.rb +2 -155
- data/lib/mongoid/matcher/all.rb +22 -0
- data/lib/mongoid/matcher/and.rb +21 -0
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +36 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
- data/lib/mongoid/matcher/eq.rb +11 -0
- data/lib/mongoid/matcher/eq_impl.rb +67 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
- data/lib/mongoid/matcher/exists.rb +15 -0
- data/lib/mongoid/matcher/expression.rb +35 -0
- data/lib/mongoid/matcher/expression_operator.rb +19 -0
- data/lib/mongoid/matcher/field_expression.rb +62 -0
- data/lib/mongoid/matcher/field_operator.rb +54 -0
- data/lib/mongoid/matcher/gt.rb +17 -0
- data/lib/mongoid/matcher/gte.rb +17 -0
- data/lib/mongoid/matcher/in.rb +25 -0
- data/lib/mongoid/matcher/lt.rb +17 -0
- data/lib/mongoid/matcher/lte.rb +17 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/ne.rb +16 -0
- data/lib/mongoid/matcher/nin.rb +11 -0
- data/lib/mongoid/matcher/nor.rb +25 -0
- data/lib/mongoid/matcher/not.rb +29 -0
- data/lib/mongoid/matcher/or.rb +21 -0
- data/lib/mongoid/matcher/regex.rb +41 -0
- data/lib/mongoid/matcher/size.rb +26 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +130 -0
- data/lib/mongoid/persistable/creatable.rb +20 -29
- data/lib/mongoid/persistable/deletable.rb +4 -22
- data/lib/mongoid/persistable/destroyable.rb +9 -10
- data/lib/mongoid/persistable/incrementable.rb +0 -5
- data/lib/mongoid/persistable/logical.rb +0 -5
- data/lib/mongoid/persistable/poppable.rb +0 -5
- data/lib/mongoid/persistable/pullable.rb +0 -7
- data/lib/mongoid/persistable/pushable.rb +4 -8
- data/lib/mongoid/persistable/renamable.rb +0 -5
- data/lib/mongoid/persistable/savable.rb +13 -8
- data/lib/mongoid/persistable/settable.rb +0 -5
- data/lib/mongoid/persistable/unsettable.rb +2 -7
- data/lib/mongoid/persistable/updatable.rb +96 -29
- data/lib/mongoid/persistable/upsertable.rb +20 -8
- data/lib/mongoid/persistable.rb +6 -26
- data/lib/mongoid/persistence_context.rb +71 -43
- data/lib/mongoid/positional.rb +0 -5
- data/lib/mongoid/query_cache.rb +16 -236
- data/lib/mongoid/railtie.rb +0 -15
- data/lib/mongoid/railties/controller_runtime.rb +1 -2
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +17 -20
- data/lib/mongoid/scopable.rb +32 -56
- data/lib/mongoid/selectable.rb +5 -17
- data/lib/mongoid/serializable.rb +11 -22
- data/lib/mongoid/shardable.rb +49 -16
- data/lib/mongoid/stateful.rb +57 -19
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +59 -11
- data/lib/mongoid/threaded/lifecycle.rb +5 -26
- data/lib/mongoid/threaded.rb +42 -67
- data/lib/mongoid/timestamps/created/short.rb +0 -1
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +0 -7
- data/lib/mongoid/timestamps/updated/short.rb +0 -1
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +0 -1
- data/lib/mongoid/touchable.rb +34 -13
- data/lib/mongoid/traversable.rb +181 -59
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +1 -4
- data/lib/mongoid/validatable/format.rb +0 -1
- data/lib/mongoid/validatable/length.rb +0 -1
- data/lib/mongoid/validatable/localizable.rb +1 -4
- data/lib/mongoid/validatable/macros.rb +5 -14
- data/lib/mongoid/validatable/presence.rb +6 -13
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +26 -40
- data/lib/mongoid/validatable.rb +9 -27
- data/lib/mongoid/version.rb +1 -2
- data/lib/mongoid/warnings.rb +44 -0
- data/lib/mongoid.rb +42 -18
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -6
- data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/mongoid_generator.rb +0 -1
- data/lib/rails/mongoid.rb +0 -3
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +16 -0
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +345 -0
- data/spec/integration/associations/belongs_to_spec.rb +18 -1
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +163 -1
- data/spec/integration/associations/embeds_many_spec.rb +219 -0
- data/spec/integration/associations/embeds_one_spec.rb +41 -0
- data/spec/integration/associations/foreign_key_spec.rb +9 -1
- data/spec/integration/associations/foreign_key_spec_models.rb +0 -1
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +272 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
- data/spec/integration/associations/reverse_population_spec.rb +0 -1
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +101 -0
- data/spec/integration/atomic/modifiers_spec.rb +116 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/callbacks_models.rb +192 -0
- data/spec/integration/callbacks_spec.rb +584 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +40 -0
- data/spec/integration/criteria/default_scope_spec.rb +51 -0
- data/spec/integration/criteria/logical_spec.rb +43 -0
- data/spec/integration/criteria/range_spec.rb +359 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +125 -15
- data/spec/integration/discriminator_key_spec.rb +391 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +30 -1
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +3 -19
- data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +130 -45
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +20 -5
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +25 -9
- data/spec/mongoid/association/accessors_spec.rb +282 -78
- data/spec/mongoid/association/auto_save_spec.rb +72 -34
- data/spec/mongoid/association/builders_spec.rb +1 -2
- data/spec/mongoid/association/constrainable_spec.rb +0 -1
- data/spec/mongoid/association/counter_cache_spec.rb +33 -34
- data/spec/mongoid/association/depending_spec.rb +429 -339
- data/spec/mongoid/association/eager_spec.rb +6 -6
- data/spec/mongoid/association/embedded/cyclic_spec.rb +2 -3
- data/spec/mongoid/association/embedded/dirty_spec.rb +2 -3
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -2
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -1
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +150 -14
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -1
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +704 -198
- data/spec/mongoid/association/embedded/embeds_many_models.rb +194 -1
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -1
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +78 -1
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -1
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +36 -24
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +20 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -3
- data/spec/mongoid/association/macros_spec.rb +9 -10
- data/spec/mongoid/association/nested/many_spec.rb +0 -1
- data/spec/mongoid/association/nested/one_spec.rb +16 -13
- data/spec/mongoid/association/options_spec.rb +0 -1
- data/spec/mongoid/association/polymorphic_spec.rb +0 -1
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -2
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +109 -17
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +50 -15
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +112 -59
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +20 -1
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +26 -22
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +26 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +31 -3
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +523 -372
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +43 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +56 -3
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +130 -1
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +23 -7
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +413 -130
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +857 -503
- data/spec/mongoid/association/referenced/has_many_models.rb +59 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_many_spec.rb +46 -1
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +53 -10
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +17 -2
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +133 -28
- data/spec/mongoid/association/referenced/has_one_models.rb +63 -1
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_one_spec.rb +22 -2
- data/spec/mongoid/association/reflections_spec.rb +0 -1
- data/spec/mongoid/association/syncable_spec.rb +46 -33
- data/spec/mongoid/association_spec.rb +0 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +47 -1
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +0 -1
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +0 -1
- data/spec/mongoid/atomic/paths/root_spec.rb +0 -1
- data/spec/mongoid/atomic/paths_spec.rb +91 -13
- data/spec/mongoid/atomic_spec.rb +51 -7
- data/spec/mongoid/attributes/dynamic_spec.rb +0 -1
- data/spec/mongoid/attributes/nested_spec.rb +147 -79
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +40 -0
- data/spec/mongoid/attributes/readonly_spec.rb +22 -23
- data/spec/mongoid/attributes_spec.rb +888 -62
- data/spec/mongoid/cacheable_spec.rb +4 -5
- data/spec/mongoid/changeable_spec.rb +464 -73
- data/spec/mongoid/clients/factory_spec.rb +91 -9
- data/spec/mongoid/clients/options_spec.rb +27 -19
- data/spec/mongoid/clients/sessions_spec.rb +27 -67
- data/spec/mongoid/clients/transactions_spec.rb +69 -35
- data/spec/mongoid/clients_spec.rb +187 -24
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/composable_spec.rb +0 -1
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config/environment_spec.rb +124 -9
- data/spec/mongoid/config/options_spec.rb +0 -1
- data/spec/mongoid/config_spec.rb +465 -1
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +431 -154
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +120 -21
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +148 -86
- data/spec/mongoid/contextual/geo_near_spec.rb +28 -20
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -20
- data/spec/mongoid/contextual/memory_spec.rb +1826 -304
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +3501 -1272
- data/spec/mongoid/contextual/none_spec.rb +78 -68
- data/spec/mongoid/copyable_spec.rb +657 -37
- data/spec/mongoid/copyable_spec_models.rb +28 -1
- data/spec/mongoid/criteria/findable_spec.rb +109 -234
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +0 -1
- data/spec/mongoid/criteria/marshalable_spec.rb +18 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +37 -38
- data/spec/mongoid/criteria/options_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -74
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -20
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -27
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -1
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -1
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -16
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -8
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +237 -179
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -8
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +5 -71
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +30 -8
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +39 -2
- data/spec/mongoid/criteria/queryable/key_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +143 -13
- data/spec/mongoid/criteria/queryable/optional_spec.rb +16 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1186 -195
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +307 -705
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +15 -4
- data/spec/mongoid/criteria/queryable/smash_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/storable_spec.rb +37 -1
- data/spec/mongoid/criteria/scopable_spec.rb +127 -1
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +406 -0
- data/spec/mongoid/criteria_spec.rb +1267 -1739
- data/spec/mongoid/document_fields_spec.rb +179 -5
- data/spec/mongoid/document_persistence_context_spec.rb +32 -0
- data/spec/mongoid/document_query_spec.rb +51 -1
- data/spec/mongoid/document_spec.rb +151 -88
- data/spec/mongoid/equality_spec.rb +142 -42
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +0 -1
- data/spec/mongoid/errors/callback_spec.rb +0 -1
- data/spec/mongoid/errors/delete_restriction_spec.rb +2 -3
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +0 -1
- data/spec/mongoid/errors/document_not_found_spec.rb +76 -1
- data/spec/mongoid/errors/invalid_collection_spec.rb +0 -1
- data/spec/mongoid/errors/{eager_load_spec.rb → invalid_config_file_spec.rb} +5 -6
- data/spec/mongoid/errors/invalid_config_option_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_field_option_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_field_spec.rb +1 -2
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_includes_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_index_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_options_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_path_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_relation_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_scope_spec.rb +1 -2
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_time_spec.rb +0 -1
- data/spec/mongoid/errors/inverse_not_found_spec.rb +0 -1
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +0 -1
- data/spec/mongoid/errors/mixed_relations_spec.rb +0 -1
- data/spec/mongoid/errors/mongoid_error_spec.rb +22 -9
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +0 -1
- data/spec/mongoid/errors/no_client_config_spec.rb +2 -3
- data/spec/mongoid/errors/no_client_database_spec.rb +3 -4
- data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -4
- data/spec/mongoid/errors/no_clients_config_spec.rb +0 -1
- data/spec/mongoid/errors/no_environment_spec.rb +3 -4
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +0 -1
- data/spec/mongoid/errors/no_metadata_spec.rb +0 -1
- data/spec/mongoid/errors/no_parent_spec.rb +0 -1
- data/spec/mongoid/errors/readonly_attribute_spec.rb +0 -1
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -3
- data/spec/mongoid/errors/scope_overwrite_spec.rb +0 -1
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -2
- data/spec/mongoid/errors/unknown_attribute_spec.rb +2 -3
- data/spec/mongoid/errors/unsaved_document_spec.rb +0 -1
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +0 -1
- data/spec/mongoid/errors/validations_spec.rb +0 -1
- data/spec/mongoid/extensions/array_spec.rb +16 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +712 -213
- data/spec/mongoid/extensions/binary_spec.rb +44 -10
- data/spec/mongoid/extensions/boolean_spec.rb +68 -83
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -4
- data/spec/mongoid/extensions/date_spec.rb +71 -2
- data/spec/mongoid/extensions/date_time_spec.rb +15 -10
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -1
- data/spec/mongoid/extensions/false_class_spec.rb +1 -2
- data/spec/mongoid/extensions/float_spec.rb +53 -75
- data/spec/mongoid/extensions/hash_spec.rb +30 -1
- data/spec/mongoid/extensions/integer_spec.rb +50 -65
- data/spec/mongoid/extensions/module_spec.rb +0 -1
- data/spec/mongoid/extensions/nil_class_spec.rb +0 -1
- data/spec/mongoid/extensions/object_id_spec.rb +0 -1
- data/spec/mongoid/extensions/object_spec.rb +0 -1
- data/spec/mongoid/extensions/range_spec.rb +255 -55
- data/spec/mongoid/extensions/regexp_spec.rb +58 -34
- data/spec/mongoid/extensions/set_spec.rb +106 -1
- data/spec/mongoid/extensions/string_spec.rb +58 -31
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +18 -26
- data/spec/mongoid/extensions/time_spec.rb +639 -107
- data/spec/mongoid/extensions/time_with_zone_spec.rb +24 -84
- data/spec/mongoid/extensions/true_class_spec.rb +1 -2
- data/spec/mongoid/extensions_spec.rb +14 -3
- data/spec/mongoid/factory_spec.rb +323 -30
- data/spec/mongoid/fields/foreign_key_spec.rb +0 -1
- data/spec/mongoid/fields/localized_spec.rb +84 -42
- data/spec/mongoid/fields/standard_spec.rb +0 -1
- data/spec/mongoid/fields_spec.rb +855 -118
- data/spec/mongoid/findable_spec.rb +518 -65
- data/spec/mongoid/indexable/specification_spec.rb +2 -3
- data/spec/mongoid/indexable_spec.rb +85 -33
- data/spec/mongoid/inspectable_spec.rb +37 -3
- data/spec/mongoid/interceptable_spec.rb +702 -104
- data/spec/mongoid/interceptable_spec_models.rb +235 -4
- data/spec/mongoid/loggable_spec.rb +0 -1
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +36 -0
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +112 -30
- data/spec/mongoid/persistable/deletable_spec.rb +298 -19
- data/spec/mongoid/persistable/destroyable_spec.rb +226 -19
- data/spec/mongoid/persistable/incrementable_spec.rb +45 -9
- data/spec/mongoid/persistable/logical_spec.rb +41 -5
- data/spec/mongoid/persistable/poppable_spec.rb +40 -5
- data/spec/mongoid/persistable/pullable_spec.rb +80 -9
- data/spec/mongoid/persistable/pushable_spec.rb +80 -9
- data/spec/mongoid/persistable/renamable_spec.rb +39 -4
- data/spec/mongoid/persistable/savable_spec.rb +282 -26
- data/spec/mongoid/persistable/settable_spec.rb +76 -10
- data/spec/mongoid/persistable/unsettable_spec.rb +40 -5
- data/spec/mongoid/persistable/updatable_spec.rb +61 -50
- data/spec/mongoid/persistable/upsertable_spec.rb +91 -4
- data/spec/mongoid/persistable_spec.rb +3 -4
- data/spec/mongoid/persistence_context_spec.rb +57 -59
- data/spec/mongoid/positional_spec.rb +0 -1
- data/spec/mongoid/query_cache_middleware_spec.rb +7 -5
- data/spec/mongoid/query_cache_spec.rb +424 -68
- data/spec/mongoid/relations/proxy_spec.rb +7 -8
- data/spec/mongoid/reloadable_spec.rb +355 -27
- data/spec/mongoid/scopable_spec.rb +191 -39
- data/spec/mongoid/selectable_spec.rb +6 -7
- data/spec/mongoid/serializable_spec.rb +35 -39
- data/spec/mongoid/shardable_models.rb +15 -1
- data/spec/mongoid/shardable_spec.rb +181 -32
- data/spec/mongoid/stateful_spec.rb +151 -10
- data/spec/mongoid/tasks/database_rake_spec.rb +87 -14
- data/spec/mongoid/tasks/database_spec.rb +128 -2
- data/spec/mongoid/threaded_spec.rb +2 -3
- data/spec/mongoid/timestamps/created/short_spec.rb +1 -2
- data/spec/mongoid/timestamps/created_spec.rb +1 -2
- data/spec/mongoid/timestamps/timeless_spec.rb +2 -3
- data/spec/mongoid/timestamps/updated/short_spec.rb +3 -4
- data/spec/mongoid/timestamps/updated_spec.rb +3 -4
- data/spec/mongoid/timestamps_spec.rb +398 -11
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +525 -36
- data/spec/mongoid/touchable_spec_models.rb +59 -0
- data/spec/mongoid/traversable_spec.rb +1143 -2
- data/spec/mongoid/validatable/associated_spec.rb +0 -1
- data/spec/mongoid/validatable/format_spec.rb +0 -1
- data/spec/mongoid/validatable/length_spec.rb +0 -1
- data/spec/mongoid/validatable/numericality_spec.rb +0 -1
- data/spec/mongoid/validatable/presence_spec.rb +26 -23
- data/spec/mongoid/validatable/uniqueness_spec.rb +125 -99
- data/spec/mongoid/validatable_spec.rb +3 -4
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +35 -10
- data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -3
- data/spec/rails/mongoid_spec.rb +4 -17
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/share/Dockerfile.erb +321 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +416 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +24 -54
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +34 -197
- data/spec/support/expectations.rb +0 -1
- data/spec/support/helpers.rb +1 -1
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +109 -1
- data/spec/{app → support}/models/account.rb +1 -2
- data/spec/{app → support}/models/acolyte.rb +0 -1
- data/spec/{app → support}/models/actor.rb +1 -2
- data/spec/{app → support}/models/actress.rb +0 -1
- data/spec/{app → support}/models/address.rb +4 -1
- data/spec/{app → support}/models/address_component.rb +0 -1
- data/spec/{app → support}/models/address_number.rb +0 -1
- data/spec/{app → support}/models/agency.rb +0 -1
- data/spec/{app → support}/models/agent.rb +0 -1
- data/spec/{app → support}/models/album.rb +0 -1
- data/spec/{app → support}/models/alert.rb +0 -1
- data/spec/{app → support}/models/animal.rb +0 -1
- data/spec/{app → support}/models/answer.rb +0 -1
- data/spec/{app → support}/models/appointment.rb +0 -1
- data/spec/support/models/armrest.rb +9 -0
- data/spec/{app → support}/models/array_field.rb +0 -1
- data/spec/{app → support}/models/article.rb +0 -1
- data/spec/{app → support}/models/artist.rb +2 -2
- data/spec/{app → support}/models/artwork.rb +0 -1
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/{app → support}/models/audio.rb +0 -1
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/{app → support}/models/author.rb +0 -1
- data/spec/{app → support}/models/baby.rb +0 -1
- data/spec/{app → support}/models/band.rb +8 -1
- data/spec/{app → support}/models/bar.rb +0 -1
- data/spec/{app → support}/models/basic.rb +0 -1
- data/spec/{app → support}/models/bed.rb +0 -1
- data/spec/{app → support}/models/big_palette.rb +0 -1
- data/spec/{app → support}/models/birthday.rb +0 -1
- data/spec/support/models/bolt.rb +7 -0
- data/spec/{app → support}/models/bomb.rb +0 -1
- data/spec/{app → support}/models/book.rb +1 -1
- data/spec/{app → support}/models/breed.rb +0 -1
- data/spec/{app → support}/models/browser.rb +1 -2
- data/spec/{app → support}/models/building.rb +2 -1
- data/spec/{app → support}/models/building_address.rb +0 -1
- data/spec/{app → support}/models/bus.rb +0 -1
- data/spec/{app → support}/models/business.rb +0 -1
- data/spec/{app → support}/models/callback_test.rb +0 -1
- data/spec/{app → support}/models/canvas.rb +1 -2
- data/spec/{app → support}/models/car.rb +0 -1
- data/spec/{app → support}/models/cat.rb +0 -1
- data/spec/support/models/catalog.rb +24 -0
- data/spec/{app → support}/models/category.rb +0 -1
- data/spec/{app → support}/models/child.rb +0 -1
- data/spec/{app → support}/models/child_doc.rb +3 -4
- data/spec/{app → support}/models/church.rb +0 -1
- data/spec/{app → support}/models/circle.rb +0 -1
- data/spec/{app → support}/models/circuit.rb +0 -1
- data/spec/{app → support}/models/circus.rb +3 -1
- data/spec/{app → support}/models/code.rb +2 -1
- data/spec/{app → support}/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +3 -0
- data/spec/{app → support}/models/comment.rb +0 -1
- data/spec/{app → support}/models/company.rb +0 -1
- data/spec/{app → support}/models/consumption_period.rb +0 -1
- data/spec/{app → support}/models/contextable_item.rb +0 -1
- data/spec/{app → support}/models/contractor.rb +0 -1
- data/spec/{app → support}/models/cookie.rb +0 -1
- data/spec/{app → support}/models/country_code.rb +2 -1
- data/spec/{app → support}/models/courier_job.rb +0 -1
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +7 -0
- data/spec/{app → support}/models/definition.rb +0 -1
- data/spec/{app → support}/models/delegating_patient.rb +0 -1
- data/spec/{app → support}/models/description.rb +0 -1
- data/spec/{app → support}/models/dictionary.rb +6 -1
- data/spec/{app → support}/models/division.rb +0 -1
- data/spec/{app → support}/models/doctor.rb +0 -1
- data/spec/{app → support}/models/dog.rb +0 -1
- data/spec/{app → support}/models/dokument.rb +0 -1
- data/spec/{app → support}/models/draft.rb +0 -1
- data/spec/{app → support}/models/dragon.rb +0 -1
- data/spec/{app → support}/models/driver.rb +1 -2
- data/spec/{app → support}/models/drug.rb +0 -1
- data/spec/{app → support}/models/dungeon.rb +0 -1
- data/spec/{app → support}/models/edit.rb +0 -1
- data/spec/{app → support}/models/email.rb +0 -1
- data/spec/{app → support}/models/employer.rb +0 -1
- data/spec/{app → support}/models/entry.rb +0 -1
- data/spec/{app → support}/models/eraser.rb +0 -1
- data/spec/{app → support}/models/even.rb +0 -1
- data/spec/{app → support}/models/event.rb +0 -1
- data/spec/{app → support}/models/exhibition.rb +0 -1
- data/spec/{app → support}/models/exhibitor.rb +0 -1
- data/spec/{app → support}/models/explosion.rb +0 -1
- data/spec/{app → support}/models/eye.rb +0 -1
- data/spec/{app → support}/models/eye_bowl.rb +0 -1
- data/spec/{app → support}/models/face.rb +0 -1
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/{app → support}/models/favorite.rb +0 -1
- data/spec/{app → support}/models/filesystem.rb +0 -1
- data/spec/{app → support}/models/fire_hydrant.rb +0 -1
- data/spec/{app → support}/models/firefox.rb +0 -1
- data/spec/{app → support}/models/fish.rb +0 -1
- data/spec/{app → support}/models/folder.rb +0 -1
- data/spec/{app → support}/models/folder_item.rb +0 -1
- data/spec/{app → support}/models/fruits.rb +0 -1
- data/spec/{app → support}/models/game.rb +0 -1
- data/spec/{app → support}/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/{app → support}/models/home.rb +0 -1
- data/spec/{app → support}/models/house.rb +0 -1
- data/spec/{app → support}/models/html_writer.rb +0 -1
- data/spec/{app → support}/models/id_key.rb +0 -1
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/{app → support}/models/image.rb +0 -1
- data/spec/{app → support}/models/implant.rb +9 -1
- data/spec/support/models/instrument.rb +8 -0
- data/spec/{app → support}/models/item.rb +1 -2
- data/spec/{app → support}/models/jar.rb +0 -1
- data/spec/{app → support}/models/kaleidoscope.rb +0 -1
- data/spec/{app → support}/models/kangaroo.rb +0 -1
- data/spec/{app → support}/models/label.rb +4 -2
- data/spec/{app → support}/models/language.rb +0 -1
- data/spec/{app → support}/models/lat_lng.rb +0 -1
- data/spec/{app → support}/models/league.rb +0 -1
- data/spec/{app → support}/models/learner.rb +0 -1
- data/spec/{app → support}/models/line_item.rb +0 -1
- data/spec/{app → support}/models/location.rb +0 -1
- data/spec/{app → support}/models/login.rb +0 -1
- data/spec/{app → support}/models/manufacturer.rb +0 -1
- data/spec/{app → support}/models/meat.rb +0 -1
- data/spec/{app → support}/models/membership.rb +1 -1
- data/spec/{app → support}/models/message.rb +0 -1
- data/spec/{app → support}/models/minim.rb +0 -1
- data/spec/{app → support}/models/mixed_drink.rb +0 -1
- data/spec/support/models/mop.rb +24 -0
- data/spec/{app → support}/models/movie.rb +0 -1
- data/spec/{app → support}/models/my_hash.rb +0 -1
- data/spec/{app → support}/models/name.rb +0 -1
- data/spec/{app → support}/models/name_only.rb +0 -1
- data/spec/{app → support}/models/node.rb +0 -1
- data/spec/{app → support}/models/note.rb +0 -1
- data/spec/support/models/nut.rb +7 -0
- data/spec/{app → support}/models/odd.rb +0 -1
- data/spec/support/models/order.rb +12 -0
- data/spec/{app → support}/models/ordered_post.rb +1 -2
- data/spec/{app → support}/models/ordered_preference.rb +0 -1
- data/spec/{app → support}/models/oscar.rb +0 -1
- data/spec/{app → support}/models/other_owner_object.rb +0 -1
- data/spec/{app → support}/models/override.rb +0 -1
- data/spec/{app → support}/models/ownable.rb +0 -1
- data/spec/{app → support}/models/owner.rb +2 -1
- data/spec/{app → support}/models/pack.rb +0 -1
- data/spec/{app → support}/models/page.rb +0 -1
- data/spec/{app → support}/models/page_question.rb +0 -1
- data/spec/{app → support}/models/palette.rb +1 -2
- data/spec/{app → support}/models/parent.rb +0 -1
- data/spec/{app → support}/models/parent_doc.rb +0 -1
- data/spec/support/models/passport.rb +22 -0
- data/spec/{app → support}/models/patient.rb +0 -1
- data/spec/{app → support}/models/pdf_writer.rb +0 -1
- data/spec/{app → support}/models/pencil.rb +0 -1
- data/spec/{app → support}/models/person.rb +20 -2
- data/spec/{app → support}/models/pet.rb +0 -1
- data/spec/{app → support}/models/pet_owner.rb +0 -1
- data/spec/{app → support}/models/phone.rb +3 -2
- data/spec/support/models/piano.rb +4 -0
- data/spec/{app → support}/models/pizza.rb +0 -1
- data/spec/{app → support}/models/player.rb +2 -1
- data/spec/{app → support}/models/post.rb +0 -1
- data/spec/{app → support}/models/post_genre.rb +0 -1
- data/spec/support/models/powerup.rb +25 -0
- data/spec/{app → support}/models/preference.rb +0 -1
- data/spec/{app → support}/models/princess.rb +0 -1
- data/spec/{app → support}/models/product.rb +1 -1
- data/spec/support/models/profile.rb +17 -0
- data/spec/{app → support}/models/pronunciation.rb +0 -1
- data/spec/{app → support}/models/pub.rb +0 -1
- data/spec/{app → support}/models/publication/encyclopedia.rb +0 -1
- data/spec/{app → support}/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +4 -0
- data/spec/{app → support}/models/purchase.rb +0 -1
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/{app → support}/models/question.rb +0 -1
- data/spec/{app → support}/models/quiz.rb +0 -1
- data/spec/{app → support}/models/rating.rb +0 -1
- data/spec/{app → support}/models/record.rb +0 -1
- data/spec/{app → support}/models/registry.rb +1 -1
- data/spec/{app → support}/models/role.rb +0 -1
- data/spec/{app → support}/models/root_category.rb +0 -1
- data/spec/{app → support}/models/sandwich.rb +0 -1
- data/spec/{app → support}/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +14 -0
- data/spec/{app/models/profile.rb → support/models/scribe.rb} +2 -3
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/{app → support}/models/seo.rb +0 -1
- data/spec/{app → support}/models/series.rb +1 -1
- data/spec/{app → support}/models/server.rb +0 -1
- data/spec/{app → support}/models/service.rb +0 -1
- data/spec/{app → support}/models/shape.rb +2 -3
- data/spec/{app → support}/models/shelf.rb +0 -1
- data/spec/support/models/shield.rb +18 -0
- data/spec/{app → support}/models/shipment_address.rb +0 -1
- data/spec/{app → support}/models/shipping_container.rb +0 -1
- data/spec/{app → support}/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +11 -0
- data/spec/{app → support}/models/shop.rb +0 -1
- data/spec/{app → support}/models/short_agent.rb +0 -1
- data/spec/{app → support}/models/short_quiz.rb +0 -1
- data/spec/{app → support}/models/simple.rb +0 -1
- data/spec/{app → support}/models/slave.rb +0 -1
- data/spec/{app → support}/models/song.rb +0 -1
- data/spec/{app → support}/models/sound.rb +0 -1
- data/spec/support/models/spacer.rb +7 -0
- data/spec/{app → support}/models/square.rb +0 -1
- data/spec/{app → support}/models/staff.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test1.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test2.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test3.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test4.rb +0 -1
- data/spec/{app → support}/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +14 -0
- data/spec/{app → support}/models/sub_item.rb +0 -1
- data/spec/{app → support}/models/subscription.rb +0 -1
- data/spec/{app → support}/models/survey.rb +0 -1
- data/spec/{app → support}/models/symptom.rb +0 -1
- data/spec/support/models/system_role.rb +7 -0
- data/spec/{app → support}/models/tag.rb +0 -1
- data/spec/{app → support}/models/target.rb +0 -1
- data/spec/{app → support}/models/template.rb +0 -1
- data/spec/{app → support}/models/thing.rb +0 -1
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/{app → support}/models/title.rb +0 -1
- data/spec/{app → support}/models/tool.rb +2 -3
- data/spec/{app → support}/models/topping.rb +0 -1
- data/spec/support/models/toy.rb +9 -0
- data/spec/{app → support}/models/track.rb +0 -1
- data/spec/{app → support}/models/translation.rb +0 -1
- data/spec/{app → support}/models/tree.rb +0 -1
- data/spec/{app → support}/models/truck.rb +2 -1
- data/spec/{app → support}/models/updatable.rb +0 -1
- data/spec/{app → support}/models/user.rb +0 -1
- data/spec/{app → support}/models/user_account.rb +0 -1
- data/spec/{app → support}/models/validation_callback.rb +0 -1
- data/spec/{app → support}/models/vehicle.rb +7 -3
- data/spec/{app → support}/models/version.rb +0 -1
- data/spec/{app → support}/models/vertex.rb +0 -1
- data/spec/{app → support}/models/vet_visit.rb +0 -1
- data/spec/{app → support}/models/video.rb +0 -1
- data/spec/{app → support}/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/{app → support}/models/wiki_page.rb +1 -1
- data/spec/{app → support}/models/word.rb +0 -1
- data/spec/{app → support}/models/word_origin.rb +0 -1
- data/spec/{app → support}/models/writer.rb +2 -3
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/spec_config.rb +28 -6
- data.tar.gz.sig +0 -0
- metadata +1216 -799
- metadata.gz.sig +0 -0
- data/lib/mongoid/errors/eager_load.rb +0 -26
- data/lib/mongoid/errors/invalid_value.rb +0 -18
- data/lib/mongoid/matchable/all.rb +0 -30
- data/lib/mongoid/matchable/and.rb +0 -32
- data/lib/mongoid/matchable/default.rb +0 -121
- data/lib/mongoid/matchable/elem_match.rb +0 -36
- data/lib/mongoid/matchable/eq.rb +0 -23
- data/lib/mongoid/matchable/exists.rb +0 -25
- data/lib/mongoid/matchable/gt.rb +0 -25
- data/lib/mongoid/matchable/gte.rb +0 -25
- data/lib/mongoid/matchable/in.rb +0 -26
- data/lib/mongoid/matchable/lt.rb +0 -25
- data/lib/mongoid/matchable/lte.rb +0 -25
- data/lib/mongoid/matchable/ne.rb +0 -23
- data/lib/mongoid/matchable/nin.rb +0 -24
- data/lib/mongoid/matchable/nor.rb +0 -38
- data/lib/mongoid/matchable/or.rb +0 -35
- data/lib/mongoid/matchable/regexp.rb +0 -30
- data/lib/mongoid/matchable/size.rb +0 -23
- data/lib/support/ruby_version.rb +0 -29
- data/spec/app/models/augmentation.rb +0 -14
- data/spec/app/models/coding.rb +0 -4
- data/spec/app/models/passport.rb +0 -8
- data/spec/app/models/powerup.rb +0 -14
- data/spec/app/models/publication.rb +0 -5
- data/spec/app/models/weapon.rb +0 -14
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -61
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -61
- data/spec/mongoid/matchable/all_spec.rb +0 -34
- data/spec/mongoid/matchable/and_spec.rb +0 -190
- data/spec/mongoid/matchable/default_spec.rb +0 -140
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -109
- data/spec/mongoid/matchable/eq_spec.rb +0 -49
- data/spec/mongoid/matchable/exists_spec.rb +0 -60
- data/spec/mongoid/matchable/gt_spec.rb +0 -89
- data/spec/mongoid/matchable/gte_spec.rb +0 -87
- data/spec/mongoid/matchable/in_spec.rb +0 -52
- data/spec/mongoid/matchable/lt_spec.rb +0 -88
- data/spec/mongoid/matchable/lte_spec.rb +0 -88
- data/spec/mongoid/matchable/ne_spec.rb +0 -49
- data/spec/mongoid/matchable/nin_spec.rb +0 -51
- data/spec/mongoid/matchable/nor_spec.rb +0 -210
- data/spec/mongoid/matchable/or_spec.rb +0 -134
- data/spec/mongoid/matchable/regexp_spec.rb +0 -62
- data/spec/mongoid/matchable/size_spec.rb +0 -28
- data/spec/mongoid/matchable_spec.rb +0 -856
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/lite_constraints.rb +0 -22
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
# encoding: utf-8
|
|
3
2
|
|
|
4
3
|
require "spec_helper"
|
|
5
4
|
|
|
5
|
+
module RefHasManySpec
|
|
6
|
+
module OverrideInitialize
|
|
7
|
+
class Parent
|
|
8
|
+
include Mongoid::Document
|
|
9
|
+
has_many :children, inverse_of: :parent
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Child
|
|
13
|
+
include Mongoid::Document
|
|
14
|
+
belongs_to :parent
|
|
15
|
+
field :name, type: String
|
|
16
|
+
|
|
17
|
+
def initialize(*args)
|
|
18
|
+
super
|
|
19
|
+
self.name ||= "default"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
6
25
|
describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
26
|
+
config_override :raise_not_found_error, true
|
|
7
27
|
|
|
8
28
|
before :all do
|
|
9
|
-
Mongoid.raise_not_found_error = true
|
|
10
|
-
|
|
11
29
|
Drug.belongs_to :person, primary_key: :username
|
|
12
30
|
Person.has_many :drugs, validate: false, primary_key: :username
|
|
13
31
|
end
|
|
@@ -21,26 +39,26 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
21
39
|
|
|
22
40
|
describe "##{method}" do
|
|
23
41
|
|
|
24
|
-
context "when providing the base class in child
|
|
42
|
+
context "when providing the base class in child constructor" do
|
|
25
43
|
|
|
26
44
|
let(:person) do
|
|
27
|
-
Person.create
|
|
45
|
+
Person.create!
|
|
28
46
|
end
|
|
29
47
|
|
|
30
48
|
let!(:post) do
|
|
31
49
|
person.posts.send(method, Post.new(person: person))
|
|
32
50
|
end
|
|
33
51
|
|
|
34
|
-
it "only adds the
|
|
52
|
+
it "only adds the association once" do
|
|
35
53
|
expect(person.posts.size).to eq(1)
|
|
36
54
|
end
|
|
37
55
|
|
|
38
|
-
it "only persists the
|
|
56
|
+
it "only persists the association once" do
|
|
39
57
|
expect(person.reload.posts.size).to eq(1)
|
|
40
58
|
end
|
|
41
59
|
end
|
|
42
60
|
|
|
43
|
-
context "when the
|
|
61
|
+
context "when the associations are not polymorphic" do
|
|
44
62
|
|
|
45
63
|
context "when the parent is a new record" do
|
|
46
64
|
|
|
@@ -58,15 +76,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
58
76
|
person.posts.send(method, post)
|
|
59
77
|
end
|
|
60
78
|
|
|
61
|
-
it "sets the foreign key on the
|
|
79
|
+
it "sets the foreign key on the association" do
|
|
62
80
|
expect(post.person_id).to eq(person.id)
|
|
63
81
|
end
|
|
64
82
|
|
|
65
|
-
it "sets the base on the inverse
|
|
83
|
+
it "sets the base on the inverse association" do
|
|
66
84
|
expect(post.person).to eq(person)
|
|
67
85
|
end
|
|
68
86
|
|
|
69
|
-
it "sets the same instance on the inverse
|
|
87
|
+
it "sets the same instance on the inverse association" do
|
|
70
88
|
expect(post.person).to eql(person)
|
|
71
89
|
end
|
|
72
90
|
|
|
@@ -78,7 +96,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
78
96
|
expect(person.posts.size).to eq(1)
|
|
79
97
|
end
|
|
80
98
|
|
|
81
|
-
it "returns the
|
|
99
|
+
it "returns the association" do
|
|
82
100
|
expect(added).to eq(person.posts)
|
|
83
101
|
end
|
|
84
102
|
end
|
|
@@ -86,22 +104,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
86
104
|
context "when the child is persisted" do
|
|
87
105
|
|
|
88
106
|
let(:post) do
|
|
89
|
-
Post.create
|
|
107
|
+
Post.create!
|
|
90
108
|
end
|
|
91
109
|
|
|
92
110
|
before do
|
|
93
111
|
person.posts.send(method, post)
|
|
94
112
|
end
|
|
95
113
|
|
|
96
|
-
it "sets the foreign key on the
|
|
114
|
+
it "sets the foreign key on the association" do
|
|
97
115
|
expect(post.person_id).to eq(person.id)
|
|
98
116
|
end
|
|
99
117
|
|
|
100
|
-
it "sets the base on the inverse
|
|
118
|
+
it "sets the base on the inverse association" do
|
|
101
119
|
expect(post.person).to eq(person)
|
|
102
120
|
end
|
|
103
121
|
|
|
104
|
-
it "sets the same instance on the inverse
|
|
122
|
+
it "sets the same instance on the inverse association" do
|
|
105
123
|
expect(post.person).to eql(person)
|
|
106
124
|
end
|
|
107
125
|
|
|
@@ -116,11 +134,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
116
134
|
context "when subsequently saving the parent" do
|
|
117
135
|
|
|
118
136
|
before do
|
|
119
|
-
person.save
|
|
120
|
-
post.save
|
|
137
|
+
person.save!
|
|
138
|
+
post.save!
|
|
121
139
|
end
|
|
122
140
|
|
|
123
|
-
it "returns the correct count of the
|
|
141
|
+
it "returns the correct count of the association" do
|
|
124
142
|
expect(person.posts.count).to eq(1)
|
|
125
143
|
end
|
|
126
144
|
end
|
|
@@ -130,20 +148,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
130
148
|
context "when appending in a parent create block" do
|
|
131
149
|
|
|
132
150
|
let!(:post) do
|
|
133
|
-
Post.create(title: "testing")
|
|
151
|
+
Post.create!(title: "testing")
|
|
134
152
|
end
|
|
135
153
|
|
|
136
154
|
let!(:person) do
|
|
137
|
-
Person.create do |doc|
|
|
155
|
+
Person.create! do |doc|
|
|
138
156
|
doc.posts << post
|
|
139
157
|
end
|
|
140
158
|
end
|
|
141
159
|
|
|
142
|
-
it "adds the documents to the
|
|
160
|
+
it "adds the documents to the association" do
|
|
143
161
|
expect(person.posts).to eq([ post ])
|
|
144
162
|
end
|
|
145
163
|
|
|
146
|
-
it "sets the foreign key on the inverse
|
|
164
|
+
it "sets the foreign key on the inverse association" do
|
|
147
165
|
expect(post.person_id).to eq(person.id)
|
|
148
166
|
end
|
|
149
167
|
|
|
@@ -163,7 +181,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
163
181
|
context "when the parent is not a new record" do
|
|
164
182
|
|
|
165
183
|
let(:person) do
|
|
166
|
-
Person.create
|
|
184
|
+
Person.create!
|
|
167
185
|
end
|
|
168
186
|
|
|
169
187
|
let(:post) do
|
|
@@ -174,15 +192,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
174
192
|
person.posts.send(method, post)
|
|
175
193
|
end
|
|
176
194
|
|
|
177
|
-
it "sets the foreign key on the
|
|
195
|
+
it "sets the foreign key on the association" do
|
|
178
196
|
expect(post.person_id).to eq(person.id)
|
|
179
197
|
end
|
|
180
198
|
|
|
181
|
-
it "sets the base on the inverse
|
|
199
|
+
it "sets the base on the inverse association" do
|
|
182
200
|
expect(post.person).to eq(person)
|
|
183
201
|
end
|
|
184
202
|
|
|
185
|
-
it "sets the same instance on the inverse
|
|
203
|
+
it "sets the same instance on the inverse association" do
|
|
186
204
|
expect(post.person).to eql(person)
|
|
187
205
|
end
|
|
188
206
|
|
|
@@ -203,16 +221,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
203
221
|
expect(person.changed).to eq([])
|
|
204
222
|
end
|
|
205
223
|
|
|
206
|
-
context "when the related item has embedded
|
|
224
|
+
context "when the related item has embedded associations" do
|
|
207
225
|
|
|
208
226
|
let!(:user) do
|
|
209
|
-
User.create
|
|
227
|
+
User.create!
|
|
210
228
|
end
|
|
211
229
|
|
|
212
230
|
before do
|
|
213
|
-
p = Post.create(roles: [ Role.create ])
|
|
231
|
+
p = Post.create!(roles: [ Role.create! ])
|
|
214
232
|
user.posts = [ p ]
|
|
215
|
-
user.save
|
|
233
|
+
user.save!
|
|
216
234
|
end
|
|
217
235
|
|
|
218
236
|
it "add the document to the target" do
|
|
@@ -232,7 +250,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
232
250
|
end
|
|
233
251
|
end
|
|
234
252
|
|
|
235
|
-
context "when documents already exist on the
|
|
253
|
+
context "when documents already exist on the association" do
|
|
236
254
|
|
|
237
255
|
let(:post_two) do
|
|
238
256
|
Post.new(title: "Test")
|
|
@@ -242,15 +260,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
242
260
|
person.posts.send(method, post_two)
|
|
243
261
|
end
|
|
244
262
|
|
|
245
|
-
it "sets the foreign key on the
|
|
263
|
+
it "sets the foreign key on the association" do
|
|
246
264
|
expect(post_two.person_id).to eq(person.id)
|
|
247
265
|
end
|
|
248
266
|
|
|
249
|
-
it "sets the base on the inverse
|
|
267
|
+
it "sets the base on the inverse association" do
|
|
250
268
|
expect(post_two.person).to eq(person)
|
|
251
269
|
end
|
|
252
270
|
|
|
253
|
-
it "sets the same instance on the inverse
|
|
271
|
+
it "sets the same instance on the inverse association" do
|
|
254
272
|
expect(post_two.person).to eql(person)
|
|
255
273
|
end
|
|
256
274
|
|
|
@@ -277,10 +295,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
277
295
|
end
|
|
278
296
|
end
|
|
279
297
|
|
|
280
|
-
context "when.adding to the
|
|
298
|
+
context "when.adding to the association" do
|
|
281
299
|
|
|
282
300
|
let(:person) do
|
|
283
|
-
Person.create
|
|
301
|
+
Person.create!
|
|
284
302
|
end
|
|
285
303
|
|
|
286
304
|
context "when the operation succeeds" do
|
|
@@ -293,7 +311,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
293
311
|
person.posts.send(method, post)
|
|
294
312
|
end
|
|
295
313
|
|
|
296
|
-
it "adds the document to the
|
|
314
|
+
it "adds the document to the association" do
|
|
297
315
|
expect(person.posts).to eq([ post ])
|
|
298
316
|
end
|
|
299
317
|
end
|
|
@@ -301,7 +319,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
301
319
|
context "when the operation fails" do
|
|
302
320
|
|
|
303
321
|
let!(:existing) do
|
|
304
|
-
Post.create
|
|
322
|
+
Post.create!
|
|
305
323
|
end
|
|
306
324
|
|
|
307
325
|
let(:post) do
|
|
@@ -318,7 +336,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
318
336
|
end
|
|
319
337
|
end
|
|
320
338
|
|
|
321
|
-
context "when the
|
|
339
|
+
context "when the associations are polymorphic" do
|
|
322
340
|
|
|
323
341
|
context "when the parent is a new record" do
|
|
324
342
|
|
|
@@ -334,11 +352,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
334
352
|
movie.ratings.send(method, rating)
|
|
335
353
|
end
|
|
336
354
|
|
|
337
|
-
it "sets the foreign key on the
|
|
355
|
+
it "sets the foreign key on the association" do
|
|
338
356
|
expect(rating.ratable_id).to eq(movie.id)
|
|
339
357
|
end
|
|
340
358
|
|
|
341
|
-
it "sets the base on the inverse
|
|
359
|
+
it "sets the base on the inverse association" do
|
|
342
360
|
expect(rating.ratable).to eq(movie)
|
|
343
361
|
end
|
|
344
362
|
|
|
@@ -354,7 +372,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
354
372
|
context "when the parent is not a new record" do
|
|
355
373
|
|
|
356
374
|
let(:movie) do
|
|
357
|
-
Movie.create
|
|
375
|
+
Movie.create!
|
|
358
376
|
end
|
|
359
377
|
|
|
360
378
|
let(:rating) do
|
|
@@ -365,11 +383,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
365
383
|
movie.ratings.send(method, rating)
|
|
366
384
|
end
|
|
367
385
|
|
|
368
|
-
it "sets the foreign key on the
|
|
386
|
+
it "sets the foreign key on the association" do
|
|
369
387
|
expect(rating.ratable_id).to eq(movie.id)
|
|
370
388
|
end
|
|
371
389
|
|
|
372
|
-
it "sets the base on the inverse
|
|
390
|
+
it "sets the base on the inverse association" do
|
|
373
391
|
expect(rating.ratable).to eq(movie)
|
|
374
392
|
end
|
|
375
393
|
|
|
@@ -387,7 +405,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
387
405
|
|
|
388
406
|
describe "#=" do
|
|
389
407
|
|
|
390
|
-
context "when the
|
|
408
|
+
context "when the association is not polymorphic" do
|
|
391
409
|
|
|
392
410
|
context "when the parent is a new record" do
|
|
393
411
|
|
|
@@ -403,15 +421,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
403
421
|
person.posts = [ post ]
|
|
404
422
|
end
|
|
405
423
|
|
|
406
|
-
it "sets the target of the
|
|
424
|
+
it "sets the target of the association" do
|
|
407
425
|
expect(person.posts._target).to eq([ post ])
|
|
408
426
|
end
|
|
409
427
|
|
|
410
|
-
it "sets the foreign key on the
|
|
428
|
+
it "sets the foreign key on the association" do
|
|
411
429
|
expect(post.person_id).to eq(person.id)
|
|
412
430
|
end
|
|
413
431
|
|
|
414
|
-
it "sets the base on the inverse
|
|
432
|
+
it "sets the base on the inverse association" do
|
|
415
433
|
expect(post.person).to eq(person)
|
|
416
434
|
end
|
|
417
435
|
|
|
@@ -423,7 +441,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
423
441
|
context "when the parent is not a new record" do
|
|
424
442
|
|
|
425
443
|
let(:person) do
|
|
426
|
-
Person.create
|
|
444
|
+
Person.create!
|
|
427
445
|
end
|
|
428
446
|
|
|
429
447
|
let(:post) do
|
|
@@ -434,15 +452,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
434
452
|
person.posts = [ post ]
|
|
435
453
|
end
|
|
436
454
|
|
|
437
|
-
it "sets the target of the
|
|
455
|
+
it "sets the target of the association" do
|
|
438
456
|
expect(person.posts._target).to eq([ post ])
|
|
439
457
|
end
|
|
440
458
|
|
|
441
|
-
it "sets the foreign key of the
|
|
459
|
+
it "sets the foreign key of the association" do
|
|
442
460
|
expect(post.person_id).to eq(person.id)
|
|
443
461
|
end
|
|
444
462
|
|
|
445
|
-
it "sets the base on the inverse
|
|
463
|
+
it "sets the base on the inverse association" do
|
|
446
464
|
expect(post.person).to eq(person)
|
|
447
465
|
end
|
|
448
466
|
|
|
@@ -450,7 +468,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
450
468
|
expect(post).to be_persisted
|
|
451
469
|
end
|
|
452
470
|
|
|
453
|
-
context "when replacing the
|
|
471
|
+
context "when replacing the association with the same documents" do
|
|
454
472
|
|
|
455
473
|
context "when using the same in memory instance" do
|
|
456
474
|
|
|
@@ -458,11 +476,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
458
476
|
person.posts = [ post ]
|
|
459
477
|
end
|
|
460
478
|
|
|
461
|
-
it "keeps the
|
|
479
|
+
it "keeps the association intact" do
|
|
462
480
|
expect(person.posts).to eq([ post ])
|
|
463
481
|
end
|
|
464
482
|
|
|
465
|
-
it "does not delete the
|
|
483
|
+
it "does not delete the association" do
|
|
466
484
|
expect(person.reload.posts).to eq([ post ])
|
|
467
485
|
end
|
|
468
486
|
end
|
|
@@ -477,11 +495,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
477
495
|
from_db.posts = [ post ]
|
|
478
496
|
end
|
|
479
497
|
|
|
480
|
-
it "keeps the
|
|
498
|
+
it "keeps the association intact" do
|
|
481
499
|
expect(from_db.posts).to eq([ post ])
|
|
482
500
|
end
|
|
483
501
|
|
|
484
|
-
it "does not delete the
|
|
502
|
+
it "does not delete the association" do
|
|
485
503
|
expect(from_db.reload.posts).to eq([ post ])
|
|
486
504
|
end
|
|
487
505
|
end
|
|
@@ -490,7 +508,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
490
508
|
context "when replacing the with a combination of old and new docs" do
|
|
491
509
|
|
|
492
510
|
let(:new_post) do
|
|
493
|
-
Post.create(title: "new post")
|
|
511
|
+
Post.create!(title: "new post")
|
|
494
512
|
end
|
|
495
513
|
|
|
496
514
|
context "when using the same in memory instance" do
|
|
@@ -499,7 +517,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
499
517
|
person.posts = [ post, new_post ]
|
|
500
518
|
end
|
|
501
519
|
|
|
502
|
-
it "keeps the
|
|
520
|
+
it "keeps the association intact" do
|
|
503
521
|
expect(person.posts.size).to eq(2)
|
|
504
522
|
end
|
|
505
523
|
|
|
@@ -511,7 +529,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
511
529
|
expect(person.posts).to include(new_post)
|
|
512
530
|
end
|
|
513
531
|
|
|
514
|
-
it "does not delete the
|
|
532
|
+
it "does not delete the association" do
|
|
515
533
|
expect(person.reload.posts).to eq([ post, new_post ])
|
|
516
534
|
end
|
|
517
535
|
end
|
|
@@ -526,11 +544,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
526
544
|
from_db.posts = [ post, new_post ]
|
|
527
545
|
end
|
|
528
546
|
|
|
529
|
-
it "keeps the
|
|
547
|
+
it "keeps the association intact" do
|
|
530
548
|
expect(from_db.posts).to eq([ post, new_post ])
|
|
531
549
|
end
|
|
532
550
|
|
|
533
|
-
it "does not delete the
|
|
551
|
+
it "does not delete the association" do
|
|
534
552
|
expect(from_db.reload.posts).to eq([ post, new_post ])
|
|
535
553
|
end
|
|
536
554
|
end
|
|
@@ -539,7 +557,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
539
557
|
context "when replacing the with a combination of only new docs" do
|
|
540
558
|
|
|
541
559
|
let(:new_post) do
|
|
542
|
-
Post.create(title: "new post")
|
|
560
|
+
Post.create!(title: "new post")
|
|
543
561
|
end
|
|
544
562
|
|
|
545
563
|
context "when using the same in memory instance" do
|
|
@@ -548,11 +566,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
548
566
|
person.posts = [ new_post ]
|
|
549
567
|
end
|
|
550
568
|
|
|
551
|
-
it "keeps the
|
|
569
|
+
it "keeps the association intact" do
|
|
552
570
|
expect(person.posts).to eq([ new_post ])
|
|
553
571
|
end
|
|
554
572
|
|
|
555
|
-
it "does not delete the
|
|
573
|
+
it "does not delete the association" do
|
|
556
574
|
expect(person.reload.posts).to eq([ new_post ])
|
|
557
575
|
end
|
|
558
576
|
end
|
|
@@ -567,11 +585,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
567
585
|
from_db.posts = [ new_post ]
|
|
568
586
|
end
|
|
569
587
|
|
|
570
|
-
it "keeps the
|
|
588
|
+
it "keeps the association intact" do
|
|
571
589
|
expect(from_db.posts).to eq([ new_post ])
|
|
572
590
|
end
|
|
573
591
|
|
|
574
|
-
it "does not delete the
|
|
592
|
+
it "does not delete the association" do
|
|
575
593
|
expect(from_db.reload.posts).to eq([ new_post ])
|
|
576
594
|
end
|
|
577
595
|
end
|
|
@@ -579,7 +597,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
579
597
|
end
|
|
580
598
|
end
|
|
581
599
|
|
|
582
|
-
context "when the
|
|
600
|
+
context "when the association is polymorphic" do
|
|
583
601
|
|
|
584
602
|
context "when the parent is a new record" do
|
|
585
603
|
|
|
@@ -595,15 +613,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
595
613
|
movie.ratings = [ rating ]
|
|
596
614
|
end
|
|
597
615
|
|
|
598
|
-
it "sets the target of the
|
|
616
|
+
it "sets the target of the association" do
|
|
599
617
|
expect(movie.ratings._target).to eq([ rating ])
|
|
600
618
|
end
|
|
601
619
|
|
|
602
|
-
it "sets the foreign key on the
|
|
620
|
+
it "sets the foreign key on the association" do
|
|
603
621
|
expect(rating.ratable_id).to eq(movie.id)
|
|
604
622
|
end
|
|
605
623
|
|
|
606
|
-
it "sets the base on the inverse
|
|
624
|
+
it "sets the base on the inverse association" do
|
|
607
625
|
expect(rating.ratable).to eq(movie)
|
|
608
626
|
end
|
|
609
627
|
|
|
@@ -615,7 +633,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
615
633
|
context "when the parent is not a new record" do
|
|
616
634
|
|
|
617
635
|
let(:movie) do
|
|
618
|
-
Movie.create
|
|
636
|
+
Movie.create!
|
|
619
637
|
end
|
|
620
638
|
|
|
621
639
|
let(:rating) do
|
|
@@ -626,15 +644,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
626
644
|
movie.ratings = [ rating ]
|
|
627
645
|
end
|
|
628
646
|
|
|
629
|
-
it "sets the target of the
|
|
647
|
+
it "sets the target of the association" do
|
|
630
648
|
expect(movie.ratings._target).to eq([ rating ])
|
|
631
649
|
end
|
|
632
650
|
|
|
633
|
-
it "sets the foreign key of the
|
|
651
|
+
it "sets the foreign key of the association" do
|
|
634
652
|
expect(rating.ratable_id).to eq(movie.id)
|
|
635
653
|
end
|
|
636
654
|
|
|
637
|
-
it "sets the base on the inverse
|
|
655
|
+
it "sets the base on the inverse association" do
|
|
638
656
|
expect(rating.ratable).to eq(movie)
|
|
639
657
|
end
|
|
640
658
|
|
|
@@ -650,11 +668,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
650
668
|
context "when the parent is persisted" do
|
|
651
669
|
|
|
652
670
|
let(:posts) do
|
|
653
|
-
[ Post.create(title: "1"), Post.create(title: "2") ]
|
|
671
|
+
[ Post.create!(title: "1"), Post.create!(title: "2") ]
|
|
654
672
|
end
|
|
655
673
|
|
|
656
674
|
let(:person) do
|
|
657
|
-
Person.create(posts: posts)
|
|
675
|
+
Person.create!(posts: posts)
|
|
658
676
|
end
|
|
659
677
|
|
|
660
678
|
context "when the parent has multiple children" do
|
|
@@ -676,7 +694,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
676
694
|
|
|
677
695
|
describe "#= nil" do
|
|
678
696
|
|
|
679
|
-
context "when the
|
|
697
|
+
context "when the association is not polymorphic" do
|
|
680
698
|
|
|
681
699
|
context "when the parent is a new record" do
|
|
682
700
|
|
|
@@ -693,11 +711,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
693
711
|
person.posts = nil
|
|
694
712
|
end
|
|
695
713
|
|
|
696
|
-
it "sets the
|
|
714
|
+
it "sets the association to an empty array" do
|
|
697
715
|
expect(person.posts).to be_empty
|
|
698
716
|
end
|
|
699
717
|
|
|
700
|
-
it "removed the inverse
|
|
718
|
+
it "removed the inverse association" do
|
|
701
719
|
expect(post.person).to be_nil
|
|
702
720
|
end
|
|
703
721
|
|
|
@@ -709,7 +727,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
709
727
|
context "when the parent is not a new record" do
|
|
710
728
|
|
|
711
729
|
let(:person) do
|
|
712
|
-
Person.create
|
|
730
|
+
Person.create!
|
|
713
731
|
end
|
|
714
732
|
|
|
715
733
|
context "when dependent is destructive" do
|
|
@@ -723,11 +741,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
723
741
|
person.posts = nil
|
|
724
742
|
end
|
|
725
743
|
|
|
726
|
-
it "sets the
|
|
744
|
+
it "sets the association to empty" do
|
|
727
745
|
expect(person.posts).to be_empty
|
|
728
746
|
end
|
|
729
747
|
|
|
730
|
-
it "removed the inverse
|
|
748
|
+
it "removed the inverse association" do
|
|
731
749
|
expect(post.person).to be_nil
|
|
732
750
|
end
|
|
733
751
|
|
|
@@ -751,11 +769,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
751
769
|
person.drugs = nil
|
|
752
770
|
end
|
|
753
771
|
|
|
754
|
-
it "sets the
|
|
772
|
+
it "sets the association to empty" do
|
|
755
773
|
expect(person.drugs).to be_empty
|
|
756
774
|
end
|
|
757
775
|
|
|
758
|
-
it "removed the inverse
|
|
776
|
+
it "removed the inverse association" do
|
|
759
777
|
expect(drug.person).to be_nil
|
|
760
778
|
end
|
|
761
779
|
|
|
@@ -763,14 +781,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
763
781
|
expect(drug.person_id).to be_nil
|
|
764
782
|
end
|
|
765
783
|
|
|
766
|
-
it "nullifies the
|
|
784
|
+
it "nullifies the association" do
|
|
767
785
|
expect(drug).to_not be_destroyed
|
|
768
786
|
end
|
|
769
787
|
end
|
|
770
788
|
end
|
|
771
789
|
end
|
|
772
790
|
|
|
773
|
-
context "when the
|
|
791
|
+
context "when the association is polymorphic" do
|
|
774
792
|
|
|
775
793
|
context "when the parent is a new record" do
|
|
776
794
|
|
|
@@ -787,11 +805,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
787
805
|
movie.ratings = nil
|
|
788
806
|
end
|
|
789
807
|
|
|
790
|
-
it "sets the
|
|
808
|
+
it "sets the association to an empty array" do
|
|
791
809
|
expect(movie.ratings).to be_empty
|
|
792
810
|
end
|
|
793
811
|
|
|
794
|
-
it "removed the inverse
|
|
812
|
+
it "removed the inverse association" do
|
|
795
813
|
expect(rating.ratable).to be_nil
|
|
796
814
|
end
|
|
797
815
|
|
|
@@ -803,7 +821,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
803
821
|
context "when the parent is not a new record" do
|
|
804
822
|
|
|
805
823
|
let(:movie) do
|
|
806
|
-
Movie.create
|
|
824
|
+
Movie.create!
|
|
807
825
|
end
|
|
808
826
|
|
|
809
827
|
let(:rating) do
|
|
@@ -815,11 +833,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
815
833
|
movie.ratings = nil
|
|
816
834
|
end
|
|
817
835
|
|
|
818
|
-
it "sets the
|
|
836
|
+
it "sets the association to empty" do
|
|
819
837
|
expect(movie.ratings).to be_empty
|
|
820
838
|
end
|
|
821
839
|
|
|
822
|
-
it "removed the inverse
|
|
840
|
+
it "removed the inverse association" do
|
|
823
841
|
expect(rating.ratable).to be_nil
|
|
824
842
|
end
|
|
825
843
|
|
|
@@ -844,11 +862,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
844
862
|
end
|
|
845
863
|
|
|
846
864
|
let(:post_one) do
|
|
847
|
-
Post.create
|
|
865
|
+
Post.create!
|
|
848
866
|
end
|
|
849
867
|
|
|
850
868
|
let(:post_two) do
|
|
851
|
-
Post.create
|
|
869
|
+
Post.create!
|
|
852
870
|
end
|
|
853
871
|
|
|
854
872
|
before do
|
|
@@ -863,14 +881,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
863
881
|
describe "#\{name}_ids" do
|
|
864
882
|
|
|
865
883
|
let(:posts) do
|
|
866
|
-
[ Post.create
|
|
884
|
+
[ Post.create!, Post.create! ]
|
|
867
885
|
end
|
|
868
886
|
|
|
869
887
|
let(:person) do
|
|
870
|
-
Person.create(posts: posts)
|
|
888
|
+
Person.create!(posts: posts)
|
|
871
889
|
end
|
|
872
890
|
|
|
873
|
-
it "returns ids of documents that are in the
|
|
891
|
+
it "returns ids of documents that are in the association" do
|
|
874
892
|
expect(person.post_ids).to eq(posts.map(&:id))
|
|
875
893
|
end
|
|
876
894
|
end
|
|
@@ -878,8 +896,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
878
896
|
[ :build, :new ].each do |method|
|
|
879
897
|
|
|
880
898
|
describe "##{method}" do
|
|
899
|
+
context 'when model has #initialize' do
|
|
900
|
+
let(:parent) { RefHasManySpec::OverrideInitialize::Parent.create }
|
|
901
|
+
let(:child) { parent.children.send(method) }
|
|
902
|
+
|
|
903
|
+
it 'should call #initialize' do
|
|
904
|
+
expect(child.name).to be == "default"
|
|
905
|
+
end
|
|
906
|
+
end
|
|
881
907
|
|
|
882
|
-
context "when the
|
|
908
|
+
context "when the association is not polymorphic" do
|
|
883
909
|
|
|
884
910
|
context "when the parent is a new record" do
|
|
885
911
|
|
|
@@ -891,11 +917,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
891
917
|
person.posts.send(method, title: "$$$")
|
|
892
918
|
end
|
|
893
919
|
|
|
894
|
-
it "sets the foreign key on the
|
|
920
|
+
it "sets the foreign key on the association" do
|
|
895
921
|
expect(post.person_id).to eq(person.id)
|
|
896
922
|
end
|
|
897
923
|
|
|
898
|
-
it "sets the base on the inverse
|
|
924
|
+
it "sets the base on the inverse association" do
|
|
899
925
|
expect(post.person).to eq(person)
|
|
900
926
|
end
|
|
901
927
|
|
|
@@ -923,18 +949,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
923
949
|
context "when the parent is not a new record" do
|
|
924
950
|
|
|
925
951
|
let(:person) do
|
|
926
|
-
Person.create
|
|
952
|
+
Person.create!
|
|
927
953
|
end
|
|
928
954
|
|
|
929
955
|
let!(:post) do
|
|
930
956
|
person.posts.send(method, text: "Testing")
|
|
931
957
|
end
|
|
932
958
|
|
|
933
|
-
it "sets the foreign key on the
|
|
959
|
+
it "sets the foreign key on the association" do
|
|
934
960
|
expect(post.person_id).to eq(person.id)
|
|
935
961
|
end
|
|
936
962
|
|
|
937
|
-
it "sets the base on the inverse
|
|
963
|
+
it "sets the base on the inverse association" do
|
|
938
964
|
expect(post.person).to eq(person)
|
|
939
965
|
end
|
|
940
966
|
|
|
@@ -952,12 +978,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
952
978
|
end
|
|
953
979
|
end
|
|
954
980
|
|
|
955
|
-
context "when the
|
|
981
|
+
context "when the association is polymorphic" do
|
|
956
982
|
|
|
957
983
|
context "when the parent is a subclass" do
|
|
958
984
|
|
|
959
985
|
let(:video_game) do
|
|
960
|
-
VideoGame.create
|
|
986
|
+
VideoGame.create!
|
|
961
987
|
end
|
|
962
988
|
|
|
963
989
|
let(:rating) do
|
|
@@ -983,11 +1009,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
983
1009
|
movie.ratings.send(method, value: 3)
|
|
984
1010
|
end
|
|
985
1011
|
|
|
986
|
-
it "sets the foreign key on the
|
|
1012
|
+
it "sets the foreign key on the association" do
|
|
987
1013
|
expect(rating.ratable_id).to eq(movie.id)
|
|
988
1014
|
end
|
|
989
1015
|
|
|
990
|
-
it "sets the base on the inverse
|
|
1016
|
+
it "sets the base on the inverse association" do
|
|
991
1017
|
expect(rating.ratable).to eq(movie)
|
|
992
1018
|
end
|
|
993
1019
|
|
|
@@ -1011,18 +1037,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1011
1037
|
context "when the parent is not a new record" do
|
|
1012
1038
|
|
|
1013
1039
|
let(:movie) do
|
|
1014
|
-
Movie.create
|
|
1040
|
+
Movie.create!
|
|
1015
1041
|
end
|
|
1016
1042
|
|
|
1017
1043
|
let!(:rating) do
|
|
1018
1044
|
movie.ratings.send(method, value: 4)
|
|
1019
1045
|
end
|
|
1020
1046
|
|
|
1021
|
-
it "sets the foreign key on the
|
|
1047
|
+
it "sets the foreign key on the association" do
|
|
1022
1048
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1023
1049
|
end
|
|
1024
1050
|
|
|
1025
|
-
it "sets the base on the inverse
|
|
1051
|
+
it "sets the base on the inverse association" do
|
|
1026
1052
|
expect(rating.ratable).to eq(movie)
|
|
1027
1053
|
end
|
|
1028
1054
|
|
|
@@ -1044,25 +1070,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1044
1070
|
|
|
1045
1071
|
describe "#clear" do
|
|
1046
1072
|
|
|
1047
|
-
context "when the
|
|
1073
|
+
context "when the association is not polymorphic" do
|
|
1048
1074
|
|
|
1049
1075
|
context "when the parent has been persisted" do
|
|
1050
1076
|
|
|
1051
1077
|
let!(:person) do
|
|
1052
|
-
Person.create
|
|
1078
|
+
Person.create!
|
|
1053
1079
|
end
|
|
1054
1080
|
|
|
1055
1081
|
context "when the children are persisted" do
|
|
1056
1082
|
|
|
1057
1083
|
let!(:post) do
|
|
1058
|
-
person.posts.create(title: "Testing")
|
|
1084
|
+
person.posts.create!(title: "Testing")
|
|
1059
1085
|
end
|
|
1060
1086
|
|
|
1061
|
-
let!(:
|
|
1087
|
+
let!(:association) do
|
|
1062
1088
|
person.posts.clear
|
|
1063
1089
|
end
|
|
1064
1090
|
|
|
1065
|
-
it "clears out the
|
|
1091
|
+
it "clears out the association" do
|
|
1066
1092
|
expect(person.posts).to be_empty
|
|
1067
1093
|
end
|
|
1068
1094
|
|
|
@@ -1074,8 +1100,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1074
1100
|
expect(person.reload.posts).to be_empty
|
|
1075
1101
|
end
|
|
1076
1102
|
|
|
1077
|
-
it "returns the
|
|
1078
|
-
expect(
|
|
1103
|
+
it "returns the association" do
|
|
1104
|
+
expect(association).to be_empty
|
|
1079
1105
|
end
|
|
1080
1106
|
end
|
|
1081
1107
|
|
|
@@ -1085,11 +1111,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1085
1111
|
person.posts.build(title: "Testing")
|
|
1086
1112
|
end
|
|
1087
1113
|
|
|
1088
|
-
let!(:
|
|
1114
|
+
let!(:association) do
|
|
1089
1115
|
person.posts.clear
|
|
1090
1116
|
end
|
|
1091
1117
|
|
|
1092
|
-
it "clears out the
|
|
1118
|
+
it "clears out the association" do
|
|
1093
1119
|
expect(person.posts).to be_empty
|
|
1094
1120
|
end
|
|
1095
1121
|
end
|
|
@@ -1105,35 +1131,35 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1105
1131
|
person.posts.build(title: "Testing")
|
|
1106
1132
|
end
|
|
1107
1133
|
|
|
1108
|
-
let!(:
|
|
1134
|
+
let!(:association) do
|
|
1109
1135
|
person.posts.clear
|
|
1110
1136
|
end
|
|
1111
1137
|
|
|
1112
|
-
it "clears out the
|
|
1138
|
+
it "clears out the association" do
|
|
1113
1139
|
expect(person.posts).to be_empty
|
|
1114
1140
|
end
|
|
1115
1141
|
end
|
|
1116
1142
|
end
|
|
1117
1143
|
|
|
1118
|
-
context "when the
|
|
1144
|
+
context "when the association is polymorphic" do
|
|
1119
1145
|
|
|
1120
1146
|
context "when the parent has been persisted" do
|
|
1121
1147
|
|
|
1122
1148
|
let!(:movie) do
|
|
1123
|
-
Movie.create
|
|
1149
|
+
Movie.create!
|
|
1124
1150
|
end
|
|
1125
1151
|
|
|
1126
1152
|
context "when the children are persisted" do
|
|
1127
1153
|
|
|
1128
1154
|
let!(:rating) do
|
|
1129
|
-
movie.ratings.create(value: 1)
|
|
1155
|
+
movie.ratings.create!(value: 1)
|
|
1130
1156
|
end
|
|
1131
1157
|
|
|
1132
|
-
let!(:
|
|
1158
|
+
let!(:association) do
|
|
1133
1159
|
movie.ratings.clear
|
|
1134
1160
|
end
|
|
1135
1161
|
|
|
1136
|
-
it "clears out the
|
|
1162
|
+
it "clears out the association" do
|
|
1137
1163
|
expect(movie.ratings).to be_empty
|
|
1138
1164
|
end
|
|
1139
1165
|
|
|
@@ -1145,8 +1171,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1145
1171
|
expect(movie.reload.ratings).to be_empty
|
|
1146
1172
|
end
|
|
1147
1173
|
|
|
1148
|
-
it "returns the
|
|
1149
|
-
expect(
|
|
1174
|
+
it "returns the association" do
|
|
1175
|
+
expect(association).to be_empty
|
|
1150
1176
|
end
|
|
1151
1177
|
end
|
|
1152
1178
|
|
|
@@ -1156,11 +1182,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1156
1182
|
movie.ratings.build(value: 3)
|
|
1157
1183
|
end
|
|
1158
1184
|
|
|
1159
|
-
let!(:
|
|
1185
|
+
let!(:association) do
|
|
1160
1186
|
movie.ratings.clear
|
|
1161
1187
|
end
|
|
1162
1188
|
|
|
1163
|
-
it "clears out the
|
|
1189
|
+
it "clears out the association" do
|
|
1164
1190
|
expect(movie.ratings).to be_empty
|
|
1165
1191
|
end
|
|
1166
1192
|
end
|
|
@@ -1176,11 +1202,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1176
1202
|
movie.ratings.build(value: 2)
|
|
1177
1203
|
end
|
|
1178
1204
|
|
|
1179
|
-
let!(:
|
|
1205
|
+
let!(:association) do
|
|
1180
1206
|
movie.ratings.clear
|
|
1181
1207
|
end
|
|
1182
1208
|
|
|
1183
|
-
it "clears out the
|
|
1209
|
+
it "clears out the association" do
|
|
1184
1210
|
expect(movie.ratings).to be_empty
|
|
1185
1211
|
end
|
|
1186
1212
|
end
|
|
@@ -1189,7 +1215,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1189
1215
|
|
|
1190
1216
|
describe "#concat" do
|
|
1191
1217
|
|
|
1192
|
-
context "when the
|
|
1218
|
+
context "when the associations are not polymorphic" do
|
|
1193
1219
|
|
|
1194
1220
|
context "when the parent is a new record" do
|
|
1195
1221
|
|
|
@@ -1205,15 +1231,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1205
1231
|
person.posts.concat([ post ])
|
|
1206
1232
|
end
|
|
1207
1233
|
|
|
1208
|
-
it "sets the foreign key on the
|
|
1234
|
+
it "sets the foreign key on the association" do
|
|
1209
1235
|
expect(post.person_id).to eq(person.id)
|
|
1210
1236
|
end
|
|
1211
1237
|
|
|
1212
|
-
it "sets the base on the inverse
|
|
1238
|
+
it "sets the base on the inverse association" do
|
|
1213
1239
|
expect(post.person).to eq(person)
|
|
1214
1240
|
end
|
|
1215
1241
|
|
|
1216
|
-
it "sets the same instance on the inverse
|
|
1242
|
+
it "sets the same instance on the inverse association" do
|
|
1217
1243
|
expect(post.person).to eql(person)
|
|
1218
1244
|
end
|
|
1219
1245
|
|
|
@@ -1229,20 +1255,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1229
1255
|
context "when appending in a parent create block" do
|
|
1230
1256
|
|
|
1231
1257
|
let!(:post) do
|
|
1232
|
-
Post.create(title: "testing")
|
|
1258
|
+
Post.create!(title: "testing")
|
|
1233
1259
|
end
|
|
1234
1260
|
|
|
1235
1261
|
let!(:person) do
|
|
1236
|
-
Person.create do |doc|
|
|
1262
|
+
Person.create! do |doc|
|
|
1237
1263
|
doc.posts.concat([ post ])
|
|
1238
1264
|
end
|
|
1239
1265
|
end
|
|
1240
1266
|
|
|
1241
|
-
it "adds the documents to the
|
|
1267
|
+
it "adds the documents to the association" do
|
|
1242
1268
|
expect(person.posts).to eq([ post ])
|
|
1243
1269
|
end
|
|
1244
1270
|
|
|
1245
|
-
it "sets the foreign key on the inverse
|
|
1271
|
+
it "sets the foreign key on the inverse association" do
|
|
1246
1272
|
expect(post.person_id).to eq(person.id)
|
|
1247
1273
|
end
|
|
1248
1274
|
|
|
@@ -1262,7 +1288,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1262
1288
|
context "when the parent is not a new record" do
|
|
1263
1289
|
|
|
1264
1290
|
let(:person) do
|
|
1265
|
-
Person.create
|
|
1291
|
+
Person.create!
|
|
1266
1292
|
end
|
|
1267
1293
|
|
|
1268
1294
|
let(:post) do
|
|
@@ -1277,15 +1303,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1277
1303
|
person.posts.concat([ post, post_three ])
|
|
1278
1304
|
end
|
|
1279
1305
|
|
|
1280
|
-
it "sets the foreign key on the
|
|
1306
|
+
it "sets the foreign key on the association" do
|
|
1281
1307
|
expect(post.person_id).to eq(person.id)
|
|
1282
1308
|
end
|
|
1283
1309
|
|
|
1284
|
-
it "sets the base on the inverse
|
|
1310
|
+
it "sets the base on the inverse association" do
|
|
1285
1311
|
expect(post.person).to eq(person)
|
|
1286
1312
|
end
|
|
1287
1313
|
|
|
1288
|
-
it "sets the same instance on the inverse
|
|
1314
|
+
it "sets the same instance on the inverse association" do
|
|
1289
1315
|
expect(post.person).to eql(person)
|
|
1290
1316
|
end
|
|
1291
1317
|
|
|
@@ -1297,7 +1323,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1297
1323
|
expect(person.posts.count).to eq(2)
|
|
1298
1324
|
end
|
|
1299
1325
|
|
|
1300
|
-
context "when documents already exist on the
|
|
1326
|
+
context "when documents already exist on the association" do
|
|
1301
1327
|
|
|
1302
1328
|
let(:post_two) do
|
|
1303
1329
|
Post.new(title: "Test")
|
|
@@ -1307,15 +1333,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1307
1333
|
person.posts.concat([ post_two ])
|
|
1308
1334
|
end
|
|
1309
1335
|
|
|
1310
|
-
it "sets the foreign key on the
|
|
1336
|
+
it "sets the foreign key on the association" do
|
|
1311
1337
|
expect(post_two.person_id).to eq(person.id)
|
|
1312
1338
|
end
|
|
1313
1339
|
|
|
1314
|
-
it "sets the base on the inverse
|
|
1340
|
+
it "sets the base on the inverse association" do
|
|
1315
1341
|
expect(post_two.person).to eq(person)
|
|
1316
1342
|
end
|
|
1317
1343
|
|
|
1318
|
-
it "sets the same instance on the inverse
|
|
1344
|
+
it "sets the same instance on the inverse association" do
|
|
1319
1345
|
expect(post_two.person).to eql(person)
|
|
1320
1346
|
end
|
|
1321
1347
|
|
|
@@ -1339,7 +1365,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1339
1365
|
end
|
|
1340
1366
|
end
|
|
1341
1367
|
|
|
1342
|
-
context "when the
|
|
1368
|
+
context "when the associations are polymorphic" do
|
|
1343
1369
|
|
|
1344
1370
|
context "when the parent is a new record" do
|
|
1345
1371
|
|
|
@@ -1355,11 +1381,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1355
1381
|
movie.ratings.concat([ rating ])
|
|
1356
1382
|
end
|
|
1357
1383
|
|
|
1358
|
-
it "sets the foreign key on the
|
|
1384
|
+
it "sets the foreign key on the association" do
|
|
1359
1385
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1360
1386
|
end
|
|
1361
1387
|
|
|
1362
|
-
it "sets the base on the inverse
|
|
1388
|
+
it "sets the base on the inverse association" do
|
|
1363
1389
|
expect(rating.ratable).to eq(movie)
|
|
1364
1390
|
end
|
|
1365
1391
|
|
|
@@ -1375,7 +1401,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1375
1401
|
context "when the parent is not a new record" do
|
|
1376
1402
|
|
|
1377
1403
|
let(:movie) do
|
|
1378
|
-
Movie.create
|
|
1404
|
+
Movie.create!
|
|
1379
1405
|
end
|
|
1380
1406
|
|
|
1381
1407
|
let(:rating) do
|
|
@@ -1386,11 +1412,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1386
1412
|
movie.ratings.concat([ rating ])
|
|
1387
1413
|
end
|
|
1388
1414
|
|
|
1389
|
-
it "sets the foreign key on the
|
|
1415
|
+
it "sets the foreign key on the association" do
|
|
1390
1416
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1391
1417
|
end
|
|
1392
1418
|
|
|
1393
|
-
it "sets the base on the inverse
|
|
1419
|
+
it "sets the base on the inverse association" do
|
|
1394
1420
|
expect(rating.ratable).to eq(movie)
|
|
1395
1421
|
end
|
|
1396
1422
|
|
|
@@ -1407,18 +1433,23 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1407
1433
|
describe "#count" do
|
|
1408
1434
|
|
|
1409
1435
|
let(:movie) do
|
|
1410
|
-
Movie.create
|
|
1436
|
+
Movie.create!
|
|
1411
1437
|
end
|
|
1412
1438
|
|
|
1413
1439
|
context "when documents have been persisted" do
|
|
1414
1440
|
|
|
1415
1441
|
let!(:rating) do
|
|
1416
|
-
movie.ratings.create(value: 1)
|
|
1442
|
+
movie.ratings.create!(value: 1)
|
|
1417
1443
|
end
|
|
1418
1444
|
|
|
1419
1445
|
it "returns the number of persisted documents" do
|
|
1420
1446
|
expect(movie.ratings.count).to eq(1)
|
|
1421
1447
|
end
|
|
1448
|
+
|
|
1449
|
+
it "block form includes persisted results" do
|
|
1450
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
|
1451
|
+
expect(movie.ratings.count {|r| r.value >= 2 }).to eq(0)
|
|
1452
|
+
end
|
|
1422
1453
|
end
|
|
1423
1454
|
|
|
1424
1455
|
context "when documents have not been persisted" do
|
|
@@ -1430,14 +1461,42 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1430
1461
|
it "returns 0" do
|
|
1431
1462
|
expect(movie.ratings.count).to eq(0)
|
|
1432
1463
|
end
|
|
1464
|
+
|
|
1465
|
+
it "block form does not include unpersisted results" do
|
|
1466
|
+
expect(movie.ratings.count {|r| r.value == 1 }).to eq(0)
|
|
1467
|
+
end
|
|
1468
|
+
end
|
|
1469
|
+
|
|
1470
|
+
context "when mixed persisted and unpersisted documents" do
|
|
1471
|
+
|
|
1472
|
+
before do
|
|
1473
|
+
movie.ratings.create(value: 1)
|
|
1474
|
+
movie.ratings.build(value: 2)
|
|
1475
|
+
end
|
|
1476
|
+
|
|
1477
|
+
it "returns 1" do
|
|
1478
|
+
expect(movie.ratings.count).to eq(1)
|
|
1479
|
+
end
|
|
1480
|
+
|
|
1481
|
+
it "block form includes only persisted results" do
|
|
1482
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
|
1483
|
+
expect(movie.ratings.count {|r| r.value == 2 }).to eq(0)
|
|
1484
|
+
end
|
|
1485
|
+
end
|
|
1486
|
+
|
|
1487
|
+
context "when no document is added" do
|
|
1488
|
+
|
|
1489
|
+
it "returns false" do
|
|
1490
|
+
expect(movie.ratings.any?).to be false
|
|
1491
|
+
end
|
|
1433
1492
|
end
|
|
1434
1493
|
|
|
1435
1494
|
context "when new documents exist in the database" do
|
|
1436
1495
|
|
|
1437
|
-
context "when the documents are part of the
|
|
1496
|
+
context "when the documents are part of the association" do
|
|
1438
1497
|
|
|
1439
1498
|
before do
|
|
1440
|
-
Rating.create(ratable: movie)
|
|
1499
|
+
Rating.create!(ratable: movie)
|
|
1441
1500
|
end
|
|
1442
1501
|
|
|
1443
1502
|
it "returns the count from the db" do
|
|
@@ -1445,10 +1504,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1445
1504
|
end
|
|
1446
1505
|
end
|
|
1447
1506
|
|
|
1448
|
-
context "when the documents are not part of the
|
|
1507
|
+
context "when the documents are not part of the association" do
|
|
1449
1508
|
|
|
1450
1509
|
before do
|
|
1451
|
-
Rating.create
|
|
1510
|
+
Rating.create!
|
|
1452
1511
|
end
|
|
1453
1512
|
|
|
1454
1513
|
it "returns the count from the db" do
|
|
@@ -1458,16 +1517,198 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1458
1517
|
end
|
|
1459
1518
|
end
|
|
1460
1519
|
|
|
1520
|
+
describe "#any?" do
|
|
1521
|
+
|
|
1522
|
+
shared_examples 'does not query database when association is loaded' do
|
|
1523
|
+
|
|
1524
|
+
let(:fresh_movie) { Movie.find(movie.id) }
|
|
1525
|
+
|
|
1526
|
+
context 'when association is not loaded' do
|
|
1527
|
+
it 'queries database on each call' do
|
|
1528
|
+
fresh_movie
|
|
1529
|
+
|
|
1530
|
+
expect_query(1) do
|
|
1531
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1532
|
+
end
|
|
1533
|
+
|
|
1534
|
+
expect_query(1) do
|
|
1535
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1536
|
+
end
|
|
1537
|
+
end
|
|
1538
|
+
|
|
1539
|
+
context 'when using a block' do
|
|
1540
|
+
it 'queries database on first call only' do
|
|
1541
|
+
fresh_movie
|
|
1542
|
+
|
|
1543
|
+
expect_query(1) do
|
|
1544
|
+
fresh_movie.ratings.any? { false }.should be false
|
|
1545
|
+
end
|
|
1546
|
+
|
|
1547
|
+
expect_no_queries do
|
|
1548
|
+
fresh_movie.ratings.any? { false }.should be false
|
|
1549
|
+
end
|
|
1550
|
+
end
|
|
1551
|
+
end
|
|
1552
|
+
end
|
|
1553
|
+
|
|
1554
|
+
context 'when association is loaded' do
|
|
1555
|
+
it 'does not query database' do
|
|
1556
|
+
fresh_movie
|
|
1557
|
+
|
|
1558
|
+
expect_query(1) do
|
|
1559
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1560
|
+
end
|
|
1561
|
+
|
|
1562
|
+
fresh_movie.ratings.to_a
|
|
1563
|
+
|
|
1564
|
+
expect_no_queries do
|
|
1565
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1566
|
+
end
|
|
1567
|
+
end
|
|
1568
|
+
end
|
|
1569
|
+
end
|
|
1570
|
+
|
|
1571
|
+
let(:movie) do
|
|
1572
|
+
Movie.create!
|
|
1573
|
+
end
|
|
1574
|
+
|
|
1575
|
+
context "when nothing exists on the association" do
|
|
1576
|
+
|
|
1577
|
+
context "when no document is added" do
|
|
1578
|
+
|
|
1579
|
+
let!(:movie) do
|
|
1580
|
+
Movie.create!
|
|
1581
|
+
end
|
|
1582
|
+
|
|
1583
|
+
it "returns false" do
|
|
1584
|
+
expect(movie.ratings.any?).to be false
|
|
1585
|
+
end
|
|
1586
|
+
|
|
1587
|
+
let(:expected_result) { false }
|
|
1588
|
+
include_examples 'does not query database when association is loaded'
|
|
1589
|
+
end
|
|
1590
|
+
|
|
1591
|
+
context "when the document is destroyed" do
|
|
1592
|
+
|
|
1593
|
+
before do
|
|
1594
|
+
Rating.create!
|
|
1595
|
+
end
|
|
1596
|
+
|
|
1597
|
+
let!(:movie) do
|
|
1598
|
+
Movie.create!
|
|
1599
|
+
end
|
|
1600
|
+
|
|
1601
|
+
it "returns false" do
|
|
1602
|
+
movie.destroy
|
|
1603
|
+
expect(movie.ratings.any?).to be false
|
|
1604
|
+
end
|
|
1605
|
+
end
|
|
1606
|
+
end
|
|
1607
|
+
|
|
1608
|
+
context "when appending to a association and _loaded/_unloaded are empty" do
|
|
1609
|
+
|
|
1610
|
+
let!(:movie) do
|
|
1611
|
+
Movie.create!
|
|
1612
|
+
end
|
|
1613
|
+
|
|
1614
|
+
before do
|
|
1615
|
+
movie.ratings << Rating.new
|
|
1616
|
+
end
|
|
1617
|
+
|
|
1618
|
+
it "returns true" do
|
|
1619
|
+
expect(movie.ratings.any?).to be true
|
|
1620
|
+
end
|
|
1621
|
+
|
|
1622
|
+
context 'when association is not loaded' do
|
|
1623
|
+
before do
|
|
1624
|
+
movie.ratings._loaded?.should be false
|
|
1625
|
+
end
|
|
1626
|
+
|
|
1627
|
+
it 'does not query the database because it knows about the added models' do
|
|
1628
|
+
expect_no_queries do
|
|
1629
|
+
movie.ratings.any?.should be true
|
|
1630
|
+
end
|
|
1631
|
+
end
|
|
1632
|
+
end
|
|
1633
|
+
|
|
1634
|
+
context 'when association is loaded' do
|
|
1635
|
+
it 'does not query database' do
|
|
1636
|
+
expect_no_queries do
|
|
1637
|
+
movie.ratings.any?.should be true
|
|
1638
|
+
end
|
|
1639
|
+
|
|
1640
|
+
movie.ratings.to_a
|
|
1641
|
+
|
|
1642
|
+
expect_no_queries do
|
|
1643
|
+
movie.ratings.any?.should be true
|
|
1644
|
+
end
|
|
1645
|
+
end
|
|
1646
|
+
end
|
|
1647
|
+
end
|
|
1648
|
+
|
|
1649
|
+
context "when appending to a association in a transaction" do
|
|
1650
|
+
require_transaction_support
|
|
1651
|
+
|
|
1652
|
+
let!(:movie) do
|
|
1653
|
+
Movie.create!
|
|
1654
|
+
end
|
|
1655
|
+
|
|
1656
|
+
it "returns true" do
|
|
1657
|
+
movie.with_session do |session|
|
|
1658
|
+
session.with_transaction do
|
|
1659
|
+
expect{ movie.ratings << Rating.new }.to_not raise_error
|
|
1660
|
+
expect(movie.ratings.any?).to be true
|
|
1661
|
+
end
|
|
1662
|
+
end
|
|
1663
|
+
end
|
|
1664
|
+
end
|
|
1665
|
+
|
|
1666
|
+
context "when documents have been persisted" do
|
|
1667
|
+
|
|
1668
|
+
let!(:rating) do
|
|
1669
|
+
movie.ratings.create!(value: 1)
|
|
1670
|
+
end
|
|
1671
|
+
|
|
1672
|
+
it "returns true" do
|
|
1673
|
+
expect(movie.ratings.any?).to be true
|
|
1674
|
+
end
|
|
1675
|
+
|
|
1676
|
+
let(:expected_result) { true }
|
|
1677
|
+
include_examples 'does not query database when association is loaded'
|
|
1678
|
+
end
|
|
1679
|
+
|
|
1680
|
+
context "when documents have not been persisted" do
|
|
1681
|
+
|
|
1682
|
+
let!(:rating) do
|
|
1683
|
+
movie.ratings.build(value: 1)
|
|
1684
|
+
end
|
|
1685
|
+
|
|
1686
|
+
it "returns false" do
|
|
1687
|
+
expect(movie.ratings.any?).to be true
|
|
1688
|
+
end
|
|
1689
|
+
end
|
|
1690
|
+
|
|
1691
|
+
context "when new documents exist in the database" do
|
|
1692
|
+
before do
|
|
1693
|
+
Rating.create!(ratable: movie)
|
|
1694
|
+
end
|
|
1695
|
+
|
|
1696
|
+
it "returns true" do
|
|
1697
|
+
expect(movie.ratings.any?).to be true
|
|
1698
|
+
end
|
|
1699
|
+
end
|
|
1700
|
+
end
|
|
1701
|
+
|
|
1461
1702
|
describe "#create" do
|
|
1462
1703
|
|
|
1463
1704
|
context "when providing multiple attributes" do
|
|
1464
1705
|
|
|
1465
1706
|
let(:person) do
|
|
1466
|
-
Person.create
|
|
1707
|
+
Person.create!
|
|
1467
1708
|
end
|
|
1468
1709
|
|
|
1469
1710
|
let!(:posts) do
|
|
1470
|
-
person.posts.create([{ text: "Test1" }, { text: "Test2" }])
|
|
1711
|
+
person.posts.create!([{ text: "Test1" }, { text: "Test2" }])
|
|
1471
1712
|
end
|
|
1472
1713
|
|
|
1473
1714
|
it "creates multiple documents" do
|
|
@@ -1487,7 +1728,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1487
1728
|
end
|
|
1488
1729
|
end
|
|
1489
1730
|
|
|
1490
|
-
context "when the
|
|
1731
|
+
context "when the association is not polymorphic" do
|
|
1491
1732
|
|
|
1492
1733
|
context "when the parent is a new record" do
|
|
1493
1734
|
|
|
@@ -1496,7 +1737,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1496
1737
|
end
|
|
1497
1738
|
|
|
1498
1739
|
let(:post) do
|
|
1499
|
-
person.posts.create(text: "Testing")
|
|
1740
|
+
person.posts.create!(text: "Testing")
|
|
1500
1741
|
end
|
|
1501
1742
|
|
|
1502
1743
|
it "raises an unsaved document error" do
|
|
@@ -1509,11 +1750,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1509
1750
|
context "when the operation is successful" do
|
|
1510
1751
|
|
|
1511
1752
|
let(:person) do
|
|
1512
|
-
Person.create
|
|
1753
|
+
Person.create!
|
|
1513
1754
|
end
|
|
1514
1755
|
|
|
1515
1756
|
let!(:post) do
|
|
1516
|
-
person.posts.create(text: "Testing")
|
|
1757
|
+
person.posts.create!(text: "Testing")
|
|
1517
1758
|
end
|
|
1518
1759
|
|
|
1519
1760
|
it "creates the document" do
|
|
@@ -1524,16 +1765,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1524
1765
|
context "when the operation fails" do
|
|
1525
1766
|
|
|
1526
1767
|
let(:person) do
|
|
1527
|
-
Person.create
|
|
1768
|
+
Person.create!
|
|
1528
1769
|
end
|
|
1529
1770
|
|
|
1530
1771
|
let!(:existing) do
|
|
1531
|
-
Post.create
|
|
1772
|
+
Post.create!
|
|
1532
1773
|
end
|
|
1533
1774
|
|
|
1534
1775
|
it "raises an error" do
|
|
1535
1776
|
expect {
|
|
1536
|
-
person.posts.create do |doc|
|
|
1777
|
+
person.posts.create! do |doc|
|
|
1537
1778
|
doc._id = existing.id
|
|
1538
1779
|
end
|
|
1539
1780
|
}.to raise_error(Mongo::Error::OperationFailure)
|
|
@@ -1544,20 +1785,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1544
1785
|
context "when the parent is not a new record" do
|
|
1545
1786
|
|
|
1546
1787
|
let(:person) do
|
|
1547
|
-
Person.create
|
|
1788
|
+
Person.create!
|
|
1548
1789
|
end
|
|
1549
1790
|
|
|
1550
1791
|
let!(:post) do
|
|
1551
|
-
person.posts.create(text: "Testing") do |post|
|
|
1792
|
+
person.posts.create!(text: "Testing") do |post|
|
|
1552
1793
|
post.content = "The Content"
|
|
1553
1794
|
end
|
|
1554
1795
|
end
|
|
1555
1796
|
|
|
1556
|
-
it "sets the foreign key on the
|
|
1797
|
+
it "sets the foreign key on the association" do
|
|
1557
1798
|
expect(post.person_id).to eq(person.id)
|
|
1558
1799
|
end
|
|
1559
1800
|
|
|
1560
|
-
it "sets the base on the inverse
|
|
1801
|
+
it "sets the base on the inverse association" do
|
|
1561
1802
|
expect(post.person).to eq(person)
|
|
1562
1803
|
end
|
|
1563
1804
|
|
|
@@ -1581,11 +1822,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1581
1822
|
context "when passing a new object" do
|
|
1582
1823
|
|
|
1583
1824
|
let!(:odd) do
|
|
1584
|
-
Odd.create(name: 'one')
|
|
1825
|
+
Odd.create!(name: 'one')
|
|
1585
1826
|
end
|
|
1586
1827
|
|
|
1587
1828
|
let!(:even) do
|
|
1588
|
-
odd.evens.create(name: 'two', odds: [Odd.new(name: 'three')])
|
|
1829
|
+
odd.evens.create!(name: 'two', odds: [Odd.new(name: 'three')])
|
|
1589
1830
|
end
|
|
1590
1831
|
|
|
1591
1832
|
it "only push one even to the list" do
|
|
@@ -1606,7 +1847,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1606
1847
|
end
|
|
1607
1848
|
end
|
|
1608
1849
|
|
|
1609
|
-
context "when the
|
|
1850
|
+
context "when the association is polymorphic" do
|
|
1610
1851
|
|
|
1611
1852
|
context "when the parent is a new record" do
|
|
1612
1853
|
|
|
@@ -1615,7 +1856,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1615
1856
|
end
|
|
1616
1857
|
|
|
1617
1858
|
let(:rating) do
|
|
1618
|
-
movie.ratings.create(value: 1)
|
|
1859
|
+
movie.ratings.create!(value: 1)
|
|
1619
1860
|
end
|
|
1620
1861
|
|
|
1621
1862
|
it "raises an unsaved document error" do
|
|
@@ -1626,18 +1867,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1626
1867
|
context "when the parent is not a new record" do
|
|
1627
1868
|
|
|
1628
1869
|
let(:movie) do
|
|
1629
|
-
Movie.create
|
|
1870
|
+
Movie.create!
|
|
1630
1871
|
end
|
|
1631
1872
|
|
|
1632
1873
|
let!(:rating) do
|
|
1633
|
-
movie.ratings.create(value: 3)
|
|
1874
|
+
movie.ratings.create!(value: 3)
|
|
1634
1875
|
end
|
|
1635
1876
|
|
|
1636
|
-
it "sets the foreign key on the
|
|
1877
|
+
it "sets the foreign key on the association" do
|
|
1637
1878
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1638
1879
|
end
|
|
1639
1880
|
|
|
1640
|
-
it "sets the base on the inverse
|
|
1881
|
+
it "sets the base on the inverse association" do
|
|
1641
1882
|
expect(rating.ratable).to eq(movie)
|
|
1642
1883
|
end
|
|
1643
1884
|
|
|
@@ -1655,7 +1896,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1655
1896
|
end
|
|
1656
1897
|
end
|
|
1657
1898
|
|
|
1658
|
-
context "when using a
|
|
1899
|
+
context "when using a different primary_key" do
|
|
1659
1900
|
|
|
1660
1901
|
let(:person) do
|
|
1661
1902
|
Person.create!(username: 'arthurnn')
|
|
@@ -1676,7 +1917,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1676
1917
|
context "when providing multiple attributes" do
|
|
1677
1918
|
|
|
1678
1919
|
let(:person) do
|
|
1679
|
-
Person.create
|
|
1920
|
+
Person.create!
|
|
1680
1921
|
end
|
|
1681
1922
|
|
|
1682
1923
|
let!(:posts) do
|
|
@@ -1700,7 +1941,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1700
1941
|
end
|
|
1701
1942
|
end
|
|
1702
1943
|
|
|
1703
|
-
context "when the
|
|
1944
|
+
context "when the association is not polymorphic" do
|
|
1704
1945
|
|
|
1705
1946
|
context "when the parent is a new record" do
|
|
1706
1947
|
|
|
@@ -1720,18 +1961,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1720
1961
|
context "when the parent is not a new record" do
|
|
1721
1962
|
|
|
1722
1963
|
let(:person) do
|
|
1723
|
-
Person.create
|
|
1964
|
+
Person.create!
|
|
1724
1965
|
end
|
|
1725
1966
|
|
|
1726
1967
|
let!(:post) do
|
|
1727
1968
|
person.posts.create!(title: "Testing")
|
|
1728
1969
|
end
|
|
1729
1970
|
|
|
1730
|
-
it "sets the foreign key on the
|
|
1971
|
+
it "sets the foreign key on the association" do
|
|
1731
1972
|
expect(post.person_id).to eq(person.id)
|
|
1732
1973
|
end
|
|
1733
1974
|
|
|
1734
|
-
it "sets the base on the inverse
|
|
1975
|
+
it "sets the base on the inverse association" do
|
|
1735
1976
|
expect(post.person).to eq(person)
|
|
1736
1977
|
end
|
|
1737
1978
|
|
|
@@ -1758,7 +1999,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1758
1999
|
end
|
|
1759
2000
|
end
|
|
1760
2001
|
|
|
1761
|
-
context "when the
|
|
2002
|
+
context "when the association is polymorphic" do
|
|
1762
2003
|
|
|
1763
2004
|
context "when the parent is a new record" do
|
|
1764
2005
|
|
|
@@ -1778,18 +2019,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1778
2019
|
context "when the parent is not a new record" do
|
|
1779
2020
|
|
|
1780
2021
|
let(:movie) do
|
|
1781
|
-
Movie.create
|
|
2022
|
+
Movie.create!
|
|
1782
2023
|
end
|
|
1783
2024
|
|
|
1784
2025
|
let!(:rating) do
|
|
1785
2026
|
movie.ratings.create!(value: 4)
|
|
1786
2027
|
end
|
|
1787
2028
|
|
|
1788
|
-
it "sets the foreign key on the
|
|
2029
|
+
it "sets the foreign key on the association" do
|
|
1789
2030
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1790
2031
|
end
|
|
1791
2032
|
|
|
1792
|
-
it "sets the base on the inverse
|
|
2033
|
+
it "sets the base on the inverse association" do
|
|
1793
2034
|
expect(rating.ratable).to eq(movie)
|
|
1794
2035
|
end
|
|
1795
2036
|
|
|
@@ -1823,7 +2064,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1823
2064
|
Movie.new
|
|
1824
2065
|
end
|
|
1825
2066
|
|
|
1826
|
-
context "when the
|
|
2067
|
+
context "when the association is polymorphic" do
|
|
1827
2068
|
|
|
1828
2069
|
let(:association) do
|
|
1829
2070
|
Movie.relations["ratings"]
|
|
@@ -1843,7 +2084,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1843
2084
|
end
|
|
1844
2085
|
end
|
|
1845
2086
|
|
|
1846
|
-
context "when the
|
|
2087
|
+
context "when the association is not polymorphic" do
|
|
1847
2088
|
|
|
1848
2089
|
let(:association) do
|
|
1849
2090
|
Person.relations["posts"]
|
|
@@ -1863,172 +2104,130 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1863
2104
|
end
|
|
1864
2105
|
end
|
|
1865
2106
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
Person.create(username: 'arthurnn')
|
|
1870
|
-
end
|
|
2107
|
+
%i[ delete delete_one ].each do |method|
|
|
2108
|
+
describe "##{method}" do
|
|
2109
|
+
let!(:person) { Person.create!(username: 'arthurnn') }
|
|
1871
2110
|
|
|
1872
|
-
|
|
2111
|
+
context 'when the document is found' do
|
|
2112
|
+
context 'when no dependent option is set' do
|
|
2113
|
+
context 'when we are assigning attributes' do
|
|
2114
|
+
let!(:drug) { person.drugs.create! }
|
|
2115
|
+
let(:deleted) { person.drugs.send(method, drug) }
|
|
1873
2116
|
|
|
1874
|
-
|
|
2117
|
+
before do
|
|
2118
|
+
Mongoid::Threaded.begin_execution(:assign)
|
|
2119
|
+
end
|
|
1875
2120
|
|
|
1876
|
-
|
|
2121
|
+
after do
|
|
2122
|
+
Mongoid::Threaded.exit_execution(:assign)
|
|
2123
|
+
end
|
|
1877
2124
|
|
|
1878
|
-
|
|
1879
|
-
|
|
2125
|
+
it 'does not cascade' do
|
|
2126
|
+
expect(deleted.changes.keys).to eq([ 'person_id' ])
|
|
2127
|
+
end
|
|
1880
2128
|
end
|
|
1881
2129
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
2130
|
+
context 'when the document is loaded' do
|
|
2131
|
+
let!(:drug) { person.drugs.create! }
|
|
2132
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
|
1885
2133
|
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
2134
|
+
it 'returns the document' do
|
|
2135
|
+
expect(deleted).to eq(drug)
|
|
2136
|
+
end
|
|
1889
2137
|
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
2138
|
+
it 'deletes the foreign key' do
|
|
2139
|
+
expect(drug.person_id).to be_nil
|
|
2140
|
+
end
|
|
1893
2141
|
|
|
1894
|
-
|
|
1895
|
-
|
|
2142
|
+
it 'removes the document from the association' do
|
|
2143
|
+
expect(person.drugs).not_to include(drug)
|
|
2144
|
+
end
|
|
1896
2145
|
end
|
|
1897
|
-
end
|
|
1898
2146
|
|
|
1899
|
-
|
|
2147
|
+
context 'when the document is not loaded' do
|
|
2148
|
+
let!(:drug) { Drug.create!(person_id: person.username) }
|
|
2149
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
|
1900
2150
|
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
2151
|
+
it 'returns the document' do
|
|
2152
|
+
expect(deleted).to eq(drug)
|
|
2153
|
+
end
|
|
1904
2154
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2155
|
+
it 'deletes the foreign key' do
|
|
2156
|
+
expect(drug.person_id).to be_nil
|
|
2157
|
+
end
|
|
1908
2158
|
|
|
1909
|
-
|
|
1910
|
-
|
|
2159
|
+
it 'removes the document from the association' do
|
|
2160
|
+
expect(person.drugs).not_to include(drug)
|
|
2161
|
+
end
|
|
1911
2162
|
end
|
|
2163
|
+
end
|
|
1912
2164
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
2165
|
+
context 'when dependent is delete' do
|
|
2166
|
+
context 'when the document is loaded' do
|
|
2167
|
+
let!(:post) { person.posts.create!(title: 'test') }
|
|
2168
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
1916
2169
|
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
end
|
|
2170
|
+
it 'returns the document' do
|
|
2171
|
+
expect(deleted).to eq(post)
|
|
2172
|
+
end
|
|
1921
2173
|
|
|
1922
|
-
|
|
2174
|
+
it 'deletes the document' do
|
|
2175
|
+
expect(post).to be_destroyed
|
|
2176
|
+
end
|
|
1923
2177
|
|
|
1924
|
-
|
|
1925
|
-
|
|
2178
|
+
it 'removes the document from the association' do
|
|
2179
|
+
expect(person.posts).not_to include(post)
|
|
2180
|
+
end
|
|
1926
2181
|
end
|
|
1927
2182
|
|
|
1928
|
-
|
|
1929
|
-
person.
|
|
1930
|
-
|
|
2183
|
+
context 'when the document is not loaded' do
|
|
2184
|
+
let!(:post) { Post.create!(title: 'foo', person_id: person.id) }
|
|
2185
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
1931
2186
|
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2187
|
+
it 'returns the document' do
|
|
2188
|
+
expect(deleted).to eq(post)
|
|
2189
|
+
end
|
|
1935
2190
|
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2191
|
+
it 'deletes the document' do
|
|
2192
|
+
expect(post).to be_destroyed
|
|
2193
|
+
end
|
|
1939
2194
|
|
|
1940
|
-
|
|
1941
|
-
|
|
2195
|
+
it 'removes the document from the association' do
|
|
2196
|
+
expect(person.posts).not_to include(post)
|
|
2197
|
+
end
|
|
1942
2198
|
end
|
|
1943
2199
|
end
|
|
1944
2200
|
end
|
|
1945
2201
|
|
|
1946
|
-
context
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
let!(:post) do
|
|
1951
|
-
person.posts.create(title: "test")
|
|
1952
|
-
end
|
|
1953
|
-
|
|
1954
|
-
let!(:deleted) do
|
|
1955
|
-
person.posts.delete(post)
|
|
1956
|
-
end
|
|
2202
|
+
context 'when the document is not found' do
|
|
2203
|
+
let!(:post) { Post.create!(title: 'foo') }
|
|
2204
|
+
let!(:deleted) { person.posts.send(method, post) }
|
|
1957
2205
|
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
end
|
|
1961
|
-
|
|
1962
|
-
it "deletes the document" do
|
|
1963
|
-
expect(post).to be_destroyed
|
|
1964
|
-
end
|
|
1965
|
-
|
|
1966
|
-
it "removes the document from the relation" do
|
|
1967
|
-
expect(person.posts).to_not include(post)
|
|
1968
|
-
end
|
|
2206
|
+
it 'returns nil' do
|
|
2207
|
+
expect(deleted).to be_nil
|
|
1969
2208
|
end
|
|
1970
2209
|
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
let!(:post) do
|
|
1974
|
-
Post.create(title: "foo", person_id: person.id)
|
|
1975
|
-
end
|
|
1976
|
-
|
|
1977
|
-
let!(:deleted) do
|
|
1978
|
-
person.posts.delete(post)
|
|
1979
|
-
end
|
|
1980
|
-
|
|
1981
|
-
it "returns the document" do
|
|
1982
|
-
expect(deleted).to eq(post)
|
|
1983
|
-
end
|
|
1984
|
-
|
|
1985
|
-
it "deletes the document" do
|
|
1986
|
-
expect(post).to be_destroyed
|
|
1987
|
-
end
|
|
1988
|
-
|
|
1989
|
-
it "removes the document from the relation" do
|
|
1990
|
-
expect(person.posts).to_not include(post)
|
|
1991
|
-
end
|
|
2210
|
+
it 'does not delete the document' do
|
|
2211
|
+
expect(post).to be_persisted
|
|
1992
2212
|
end
|
|
1993
2213
|
end
|
|
1994
2214
|
end
|
|
1995
|
-
|
|
1996
|
-
context "when the document is not found" do
|
|
1997
|
-
|
|
1998
|
-
let!(:post) do
|
|
1999
|
-
Post.create(title: "foo")
|
|
2000
|
-
end
|
|
2001
|
-
|
|
2002
|
-
let!(:deleted) do
|
|
2003
|
-
person.posts.delete(post)
|
|
2004
|
-
end
|
|
2005
|
-
|
|
2006
|
-
it "returns nil" do
|
|
2007
|
-
expect(deleted).to be_nil
|
|
2008
|
-
end
|
|
2009
|
-
|
|
2010
|
-
it "does not delete the document" do
|
|
2011
|
-
expect(post).to be_persisted
|
|
2012
|
-
end
|
|
2013
|
-
end
|
|
2014
2215
|
end
|
|
2015
2216
|
|
|
2016
2217
|
[ :delete_all, :destroy_all ].each do |method|
|
|
2017
2218
|
|
|
2018
2219
|
describe "##{method}" do
|
|
2019
2220
|
|
|
2020
|
-
context "when the
|
|
2221
|
+
context "when the association is not polymorphic" do
|
|
2021
2222
|
|
|
2022
2223
|
context "when conditions are provided" do
|
|
2023
2224
|
|
|
2024
2225
|
let(:person) do
|
|
2025
|
-
Person.create(username: 'durran')
|
|
2226
|
+
Person.create!(username: 'durran')
|
|
2026
2227
|
end
|
|
2027
2228
|
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
person.posts.create(title: "Test")
|
|
2031
|
-
end
|
|
2229
|
+
let!(:post1) { person.posts.create!(title: "Testing") }
|
|
2230
|
+
let!(:post2) { person.posts.create!(title: "Test") }
|
|
2032
2231
|
|
|
2033
2232
|
it "removes the correct posts" do
|
|
2034
2233
|
person.posts.send(method, { title: "Testing" })
|
|
@@ -2044,17 +2243,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2044
2243
|
it "returns the number of documents deleted" do
|
|
2045
2244
|
expect(person.posts.send(method, { title: "Testing" })).to eq(1)
|
|
2046
2245
|
end
|
|
2246
|
+
|
|
2247
|
+
it "sets the association locally" do
|
|
2248
|
+
person.posts.send(method, { title: "Testing" })
|
|
2249
|
+
expect(person.posts).to eq([post2])
|
|
2250
|
+
end
|
|
2047
2251
|
end
|
|
2048
2252
|
|
|
2049
2253
|
context "when conditions are not provided" do
|
|
2050
2254
|
|
|
2051
2255
|
let(:person) do
|
|
2052
|
-
Person.create
|
|
2256
|
+
Person.create!
|
|
2053
2257
|
end
|
|
2054
2258
|
|
|
2055
2259
|
before do
|
|
2056
|
-
person.posts.create(title: "Testing")
|
|
2057
|
-
person.posts.create(title: "Test")
|
|
2260
|
+
person.posts.create!(title: "Testing")
|
|
2261
|
+
person.posts.create!(title: "Test")
|
|
2058
2262
|
end
|
|
2059
2263
|
|
|
2060
2264
|
it "removes the correct posts" do
|
|
@@ -2070,21 +2274,24 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2070
2274
|
it "returns the number of documents deleted" do
|
|
2071
2275
|
expect(person.posts.send(method)).to eq(2)
|
|
2072
2276
|
end
|
|
2277
|
+
|
|
2278
|
+
it "sets the association locally" do
|
|
2279
|
+
person.posts.send(method)
|
|
2280
|
+
expect(person.posts).to eq([])
|
|
2281
|
+
end
|
|
2073
2282
|
end
|
|
2074
2283
|
end
|
|
2075
2284
|
|
|
2076
|
-
context "when the
|
|
2285
|
+
context "when the association is polymorphic" do
|
|
2077
2286
|
|
|
2078
2287
|
context "when conditions are provided" do
|
|
2079
2288
|
|
|
2080
2289
|
let(:movie) do
|
|
2081
|
-
Movie.create(title: "Bladerunner")
|
|
2290
|
+
Movie.create!(title: "Bladerunner")
|
|
2082
2291
|
end
|
|
2083
2292
|
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
movie.ratings.create(value: 2)
|
|
2087
|
-
end
|
|
2293
|
+
let!(:rating1) { movie.ratings.create!(value: 1) }
|
|
2294
|
+
let!(:rating2) { movie.ratings.create!(value: 2) }
|
|
2088
2295
|
|
|
2089
2296
|
it "removes the correct ratings" do
|
|
2090
2297
|
movie.ratings.send(method, { value: 1 })
|
|
@@ -2099,17 +2306,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2099
2306
|
it "returns the number of documents deleted" do
|
|
2100
2307
|
expect(movie.ratings.send(method, { value: 1 })).to eq(1)
|
|
2101
2308
|
end
|
|
2309
|
+
|
|
2310
|
+
it "sets the association locally" do
|
|
2311
|
+
movie.ratings.send(method, { value: 1 })
|
|
2312
|
+
expect(movie.ratings).to eq([rating2])
|
|
2313
|
+
end
|
|
2102
2314
|
end
|
|
2103
2315
|
|
|
2104
2316
|
context "when conditions are not provided" do
|
|
2105
2317
|
|
|
2106
2318
|
let(:movie) do
|
|
2107
|
-
Movie.create(title: "Bladerunner")
|
|
2319
|
+
Movie.create!(title: "Bladerunner")
|
|
2108
2320
|
end
|
|
2109
2321
|
|
|
2110
2322
|
before do
|
|
2111
|
-
movie.ratings.create(value: 1)
|
|
2112
|
-
movie.ratings.create(value: 2)
|
|
2323
|
+
movie.ratings.create!(value: 1)
|
|
2324
|
+
movie.ratings.create!(value: 2)
|
|
2113
2325
|
end
|
|
2114
2326
|
|
|
2115
2327
|
it "removes the correct ratings" do
|
|
@@ -2125,6 +2337,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2125
2337
|
it "returns the number of documents deleted" do
|
|
2126
2338
|
expect(movie.ratings.send(method)).to eq(2)
|
|
2127
2339
|
end
|
|
2340
|
+
|
|
2341
|
+
it "sets the association locally" do
|
|
2342
|
+
movie.ratings.send(method)
|
|
2343
|
+
expect(movie.ratings).to eq([])
|
|
2344
|
+
end
|
|
2128
2345
|
end
|
|
2129
2346
|
end
|
|
2130
2347
|
end
|
|
@@ -2140,21 +2357,47 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2140
2357
|
describe "#exists?" do
|
|
2141
2358
|
|
|
2142
2359
|
let!(:person) do
|
|
2143
|
-
Person.create
|
|
2360
|
+
Person.create!
|
|
2144
2361
|
end
|
|
2145
2362
|
|
|
2146
2363
|
context "when documents exist in the database" do
|
|
2147
2364
|
|
|
2148
2365
|
before do
|
|
2149
|
-
person.posts.create
|
|
2366
|
+
person.posts.create!
|
|
2150
2367
|
end
|
|
2151
2368
|
|
|
2152
2369
|
it "returns true" do
|
|
2153
2370
|
expect(person.posts.exists?).to be true
|
|
2154
2371
|
end
|
|
2372
|
+
|
|
2373
|
+
context 'when association is not loaded' do
|
|
2374
|
+
it 'queries database on each call' do
|
|
2375
|
+
expect_query(1) do
|
|
2376
|
+
person.posts.exists?.should be true
|
|
2377
|
+
end
|
|
2378
|
+
|
|
2379
|
+
expect_query(1) do
|
|
2380
|
+
person.posts.exists?.should be true
|
|
2381
|
+
end
|
|
2382
|
+
end
|
|
2383
|
+
end
|
|
2384
|
+
|
|
2385
|
+
context 'when association is loaded' do
|
|
2386
|
+
it 'queries database on each call' do
|
|
2387
|
+
expect_query(1) do
|
|
2388
|
+
person.posts.exists?.should be true
|
|
2389
|
+
end
|
|
2390
|
+
|
|
2391
|
+
person.posts.to_a
|
|
2392
|
+
|
|
2393
|
+
expect_query(1) do
|
|
2394
|
+
person.posts.exists?.should be true
|
|
2395
|
+
end
|
|
2396
|
+
end
|
|
2397
|
+
end
|
|
2155
2398
|
end
|
|
2156
2399
|
|
|
2157
|
-
context "when
|
|
2400
|
+
context "when documents exist in application but not in database" do
|
|
2158
2401
|
|
|
2159
2402
|
before do
|
|
2160
2403
|
person.posts.build
|
|
@@ -2163,6 +2406,65 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2163
2406
|
it "returns false" do
|
|
2164
2407
|
expect(person.posts.exists?).to be false
|
|
2165
2408
|
end
|
|
2409
|
+
|
|
2410
|
+
context 'when association is not loaded' do
|
|
2411
|
+
it 'queries database on each call' do
|
|
2412
|
+
expect_query(1) do
|
|
2413
|
+
person.posts.exists?.should be false
|
|
2414
|
+
end
|
|
2415
|
+
|
|
2416
|
+
expect_query(1) do
|
|
2417
|
+
person.posts.exists?.should be false
|
|
2418
|
+
end
|
|
2419
|
+
end
|
|
2420
|
+
end
|
|
2421
|
+
|
|
2422
|
+
context 'when association is loaded' do
|
|
2423
|
+
it 'queries database on each call' do
|
|
2424
|
+
expect_query(1) do
|
|
2425
|
+
person.posts.exists?.should be false
|
|
2426
|
+
end
|
|
2427
|
+
|
|
2428
|
+
person.posts.to_a
|
|
2429
|
+
|
|
2430
|
+
expect_query(1) do
|
|
2431
|
+
person.posts.exists?.should be false
|
|
2432
|
+
end
|
|
2433
|
+
end
|
|
2434
|
+
end
|
|
2435
|
+
end
|
|
2436
|
+
|
|
2437
|
+
context "when no documents exist" do
|
|
2438
|
+
|
|
2439
|
+
it "returns false" do
|
|
2440
|
+
expect(person.posts.exists?).to be false
|
|
2441
|
+
end
|
|
2442
|
+
|
|
2443
|
+
context 'when association is not loaded' do
|
|
2444
|
+
it 'queries database on each call' do
|
|
2445
|
+
expect_query(1) do
|
|
2446
|
+
person.posts.exists?.should be false
|
|
2447
|
+
end
|
|
2448
|
+
|
|
2449
|
+
expect_query(1) do
|
|
2450
|
+
person.posts.exists?.should be false
|
|
2451
|
+
end
|
|
2452
|
+
end
|
|
2453
|
+
end
|
|
2454
|
+
|
|
2455
|
+
context 'when association is loaded' do
|
|
2456
|
+
it 'queries database on each call' do
|
|
2457
|
+
expect_query(1) do
|
|
2458
|
+
person.posts.exists?.should be false
|
|
2459
|
+
end
|
|
2460
|
+
|
|
2461
|
+
person.posts.to_a
|
|
2462
|
+
|
|
2463
|
+
expect_query(1) do
|
|
2464
|
+
person.posts.exists?.should be false
|
|
2465
|
+
end
|
|
2466
|
+
end
|
|
2467
|
+
end
|
|
2166
2468
|
end
|
|
2167
2469
|
end
|
|
2168
2470
|
|
|
@@ -2189,18 +2491,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2189
2491
|
end
|
|
2190
2492
|
end
|
|
2191
2493
|
|
|
2192
|
-
context "when the
|
|
2494
|
+
context "when the association is not polymorphic" do
|
|
2193
2495
|
|
|
2194
2496
|
let(:person) do
|
|
2195
|
-
Person.create
|
|
2497
|
+
Person.create!
|
|
2196
2498
|
end
|
|
2197
2499
|
|
|
2198
2500
|
let!(:post_one) do
|
|
2199
|
-
person.posts.create(title: "Test")
|
|
2501
|
+
person.posts.create!(title: "Test")
|
|
2200
2502
|
end
|
|
2201
2503
|
|
|
2202
2504
|
let!(:post_two) do
|
|
2203
|
-
person.posts.create(title: "OMG I has
|
|
2505
|
+
person.posts.create!(title: "OMG I has associations")
|
|
2204
2506
|
end
|
|
2205
2507
|
|
|
2206
2508
|
context "when providing an id" do
|
|
@@ -2216,48 +2518,38 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2216
2518
|
end
|
|
2217
2519
|
end
|
|
2218
2520
|
|
|
2219
|
-
context "when the id matches but is not scoped to the
|
|
2521
|
+
context "when the id matches but is not scoped to the association" do
|
|
2220
2522
|
|
|
2221
2523
|
let(:post) do
|
|
2222
|
-
Post.create(title: "Unscoped")
|
|
2524
|
+
Post.create!(title: "Unscoped")
|
|
2223
2525
|
end
|
|
2224
2526
|
|
|
2225
2527
|
it "raises an error" do
|
|
2226
2528
|
expect {
|
|
2227
2529
|
person.posts.find(post.id)
|
|
2228
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
2530
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
|
2229
2531
|
end
|
|
2230
2532
|
end
|
|
2231
2533
|
|
|
2232
2534
|
context "when the id does not match" do
|
|
2233
2535
|
|
|
2234
2536
|
context "when config set to raise error" do
|
|
2235
|
-
|
|
2236
|
-
before do
|
|
2237
|
-
Mongoid.raise_not_found_error = true
|
|
2238
|
-
end
|
|
2537
|
+
config_override :raise_not_found_error, true
|
|
2239
2538
|
|
|
2240
2539
|
it "raises an error" do
|
|
2241
2540
|
expect {
|
|
2242
2541
|
person.posts.find(BSON::ObjectId.new)
|
|
2243
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
2542
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
|
2244
2543
|
end
|
|
2245
2544
|
end
|
|
2246
2545
|
|
|
2247
2546
|
context "when config set not to raise error" do
|
|
2547
|
+
config_override :raise_not_found_error, false
|
|
2248
2548
|
|
|
2249
2549
|
let(:post) do
|
|
2250
2550
|
person.posts.find(BSON::ObjectId.new)
|
|
2251
2551
|
end
|
|
2252
2552
|
|
|
2253
|
-
before do
|
|
2254
|
-
Mongoid.raise_not_found_error = false
|
|
2255
|
-
end
|
|
2256
|
-
|
|
2257
|
-
after do
|
|
2258
|
-
Mongoid.raise_not_found_error = true
|
|
2259
|
-
end
|
|
2260
|
-
|
|
2261
2553
|
it "returns nil" do
|
|
2262
2554
|
expect(post).to be_nil
|
|
2263
2555
|
end
|
|
@@ -2281,32 +2573,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2281
2573
|
context "when the ids do not match" do
|
|
2282
2574
|
|
|
2283
2575
|
context "when config set to raise error" do
|
|
2284
|
-
|
|
2285
|
-
before do
|
|
2286
|
-
Mongoid.raise_not_found_error = true
|
|
2287
|
-
end
|
|
2576
|
+
config_override :raise_not_found_error, true
|
|
2288
2577
|
|
|
2289
2578
|
it "raises an error" do
|
|
2290
2579
|
expect {
|
|
2291
2580
|
person.posts.find([ BSON::ObjectId.new ])
|
|
2292
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
2581
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
|
2293
2582
|
end
|
|
2294
2583
|
end
|
|
2295
2584
|
|
|
2296
2585
|
context "when config set not to raise error" do
|
|
2586
|
+
config_override :raise_not_found_error, false
|
|
2297
2587
|
|
|
2298
2588
|
let(:posts) do
|
|
2299
2589
|
person.posts.find([ BSON::ObjectId.new ])
|
|
2300
2590
|
end
|
|
2301
2591
|
|
|
2302
|
-
before do
|
|
2303
|
-
Mongoid.raise_not_found_error = false
|
|
2304
|
-
end
|
|
2305
|
-
|
|
2306
|
-
after do
|
|
2307
|
-
Mongoid.raise_not_found_error = true
|
|
2308
|
-
end
|
|
2309
|
-
|
|
2310
2592
|
it "returns an empty array" do
|
|
2311
2593
|
expect(posts).to be_empty
|
|
2312
2594
|
end
|
|
@@ -2315,18 +2597,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2315
2597
|
end
|
|
2316
2598
|
end
|
|
2317
2599
|
|
|
2318
|
-
context "when the
|
|
2600
|
+
context "when the association is polymorphic" do
|
|
2319
2601
|
|
|
2320
2602
|
let(:movie) do
|
|
2321
|
-
Movie.create
|
|
2603
|
+
Movie.create!
|
|
2322
2604
|
end
|
|
2323
2605
|
|
|
2324
2606
|
let!(:rating_one) do
|
|
2325
|
-
movie.ratings.create(value: 1)
|
|
2607
|
+
movie.ratings.create!(value: 1)
|
|
2326
2608
|
end
|
|
2327
2609
|
|
|
2328
2610
|
let!(:rating_two) do
|
|
2329
|
-
movie.ratings.create(value: 5)
|
|
2611
|
+
movie.ratings.create!(value: 5)
|
|
2330
2612
|
end
|
|
2331
2613
|
|
|
2332
2614
|
context "when providing an id" do
|
|
@@ -2345,32 +2627,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2345
2627
|
context "when the id does not match" do
|
|
2346
2628
|
|
|
2347
2629
|
context "when config set to raise error" do
|
|
2348
|
-
|
|
2349
|
-
before do
|
|
2350
|
-
Mongoid.raise_not_found_error = true
|
|
2351
|
-
end
|
|
2630
|
+
config_override :raise_not_found_error, true
|
|
2352
2631
|
|
|
2353
2632
|
it "raises an error" do
|
|
2354
2633
|
expect {
|
|
2355
2634
|
movie.ratings.find(BSON::ObjectId.new)
|
|
2356
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
2635
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
|
|
2357
2636
|
end
|
|
2358
2637
|
end
|
|
2359
2638
|
|
|
2360
2639
|
context "when config set not to raise error" do
|
|
2640
|
+
config_override :raise_not_found_error, false
|
|
2361
2641
|
|
|
2362
2642
|
let(:rating) do
|
|
2363
2643
|
movie.ratings.find(BSON::ObjectId.new)
|
|
2364
2644
|
end
|
|
2365
2645
|
|
|
2366
|
-
before do
|
|
2367
|
-
Mongoid.raise_not_found_error = false
|
|
2368
|
-
end
|
|
2369
|
-
|
|
2370
|
-
after do
|
|
2371
|
-
Mongoid.raise_not_found_error = true
|
|
2372
|
-
end
|
|
2373
|
-
|
|
2374
2646
|
it "returns nil" do
|
|
2375
2647
|
expect(rating).to be_nil
|
|
2376
2648
|
end
|
|
@@ -2402,32 +2674,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2402
2674
|
context "when the ids do not match" do
|
|
2403
2675
|
|
|
2404
2676
|
context "when config set to raise error" do
|
|
2405
|
-
|
|
2406
|
-
before do
|
|
2407
|
-
Mongoid.raise_not_found_error = true
|
|
2408
|
-
end
|
|
2677
|
+
config_override :raise_not_found_error, true
|
|
2409
2678
|
|
|
2410
2679
|
it "raises an error" do
|
|
2411
2680
|
expect {
|
|
2412
2681
|
movie.ratings.find([ BSON::ObjectId.new ])
|
|
2413
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
|
2682
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
|
|
2414
2683
|
end
|
|
2415
2684
|
end
|
|
2416
2685
|
|
|
2417
2686
|
context "when config set not to raise error" do
|
|
2687
|
+
config_override :raise_not_found_error, false
|
|
2418
2688
|
|
|
2419
2689
|
let(:ratings) do
|
|
2420
2690
|
movie.ratings.find([ BSON::ObjectId.new ])
|
|
2421
2691
|
end
|
|
2422
2692
|
|
|
2423
|
-
before do
|
|
2424
|
-
Mongoid.raise_not_found_error = false
|
|
2425
|
-
end
|
|
2426
|
-
|
|
2427
|
-
after do
|
|
2428
|
-
Mongoid.raise_not_found_error = true
|
|
2429
|
-
end
|
|
2430
|
-
|
|
2431
2693
|
it "returns an empty array" do
|
|
2432
2694
|
expect(ratings).to be_empty
|
|
2433
2695
|
end
|
|
@@ -2435,18 +2697,56 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2435
2697
|
end
|
|
2436
2698
|
end
|
|
2437
2699
|
end
|
|
2700
|
+
|
|
2701
|
+
context "with block" do
|
|
2702
|
+
let!(:author) do
|
|
2703
|
+
Person.create!(title: 'Person')
|
|
2704
|
+
end
|
|
2705
|
+
|
|
2706
|
+
let!(:post_one) do
|
|
2707
|
+
author.posts.create!(title: 'post one')
|
|
2708
|
+
end
|
|
2709
|
+
|
|
2710
|
+
let!(:post_two) do
|
|
2711
|
+
author.posts.create!(title: 'post two')
|
|
2712
|
+
end
|
|
2713
|
+
|
|
2714
|
+
it "finds one" do
|
|
2715
|
+
expect(
|
|
2716
|
+
author.posts.find do |post|
|
|
2717
|
+
post.title == 'post one'
|
|
2718
|
+
end
|
|
2719
|
+
).to be_a(Post)
|
|
2720
|
+
end
|
|
2721
|
+
|
|
2722
|
+
it "returns first match of multiple" do
|
|
2723
|
+
expect(
|
|
2724
|
+
author.posts.find do |post|
|
|
2725
|
+
['post one', 'post two'].include?(post.title)
|
|
2726
|
+
end
|
|
2727
|
+
).to eq(post_one)
|
|
2728
|
+
end
|
|
2729
|
+
|
|
2730
|
+
it "returns nil when not found" do
|
|
2731
|
+
expect(
|
|
2732
|
+
author.posts.find do |post|
|
|
2733
|
+
post.title == 'non exiting one'
|
|
2734
|
+
end
|
|
2735
|
+
).to be_nil
|
|
2736
|
+
end
|
|
2737
|
+
end
|
|
2438
2738
|
end
|
|
2439
2739
|
|
|
2440
2740
|
describe "#find_or_create_by" do
|
|
2441
2741
|
|
|
2442
|
-
context "when the
|
|
2742
|
+
context "when the association is not polymorphic" do
|
|
2443
2743
|
|
|
2444
2744
|
let(:person) do
|
|
2445
|
-
Person.create
|
|
2745
|
+
Person.create!
|
|
2446
2746
|
end
|
|
2447
2747
|
|
|
2448
2748
|
let!(:post) do
|
|
2449
|
-
person.posts.create(title: "Testing")
|
|
2749
|
+
person.posts.create!(title: "Testing")
|
|
2450
2750
|
end
|
|
2451
2751
|
|
|
2452
2752
|
context "when the document exists" do
|
|
@@ -2459,7 +2759,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2459
2759
|
expect(found).to eq(post)
|
|
2460
2760
|
end
|
|
2461
2761
|
|
|
2462
|
-
it "keeps the document in the
|
|
2762
|
+
it "keeps the document in the association" do
|
|
2463
2763
|
expect(found.person).to eq(person)
|
|
2464
2764
|
end
|
|
2465
2765
|
end
|
|
@@ -2486,7 +2786,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2486
2786
|
expect(found.content).to eq("The Content")
|
|
2487
2787
|
end
|
|
2488
2788
|
|
|
2489
|
-
it "keeps the document in the
|
|
2789
|
+
it "keeps the document in the association" do
|
|
2490
2790
|
expect(found.person).to eq(person)
|
|
2491
2791
|
end
|
|
2492
2792
|
end
|
|
@@ -2505,21 +2805,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2505
2805
|
expect(found).to be_persisted
|
|
2506
2806
|
end
|
|
2507
2807
|
|
|
2508
|
-
it "keeps the document in the
|
|
2808
|
+
it "keeps the document in the association" do
|
|
2509
2809
|
expect(found.person).to eq(person)
|
|
2510
2810
|
end
|
|
2511
2811
|
end
|
|
2512
2812
|
end
|
|
2513
2813
|
end
|
|
2514
2814
|
|
|
2515
|
-
context "when the
|
|
2815
|
+
context "when the association is polymorphic" do
|
|
2516
2816
|
|
|
2517
2817
|
let(:movie) do
|
|
2518
|
-
Movie.create
|
|
2818
|
+
Movie.create!
|
|
2519
2819
|
end
|
|
2520
2820
|
|
|
2521
2821
|
let!(:rating) do
|
|
2522
|
-
movie.ratings.create(value: 1)
|
|
2822
|
+
movie.ratings.create!(value: 1)
|
|
2523
2823
|
end
|
|
2524
2824
|
|
|
2525
2825
|
context "when the document exists" do
|
|
@@ -2532,7 +2832,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2532
2832
|
expect(found).to eq(rating)
|
|
2533
2833
|
end
|
|
2534
2834
|
|
|
2535
|
-
it "keeps the document in the
|
|
2835
|
+
it "keeps the document in the association" do
|
|
2536
2836
|
expect(found.ratable).to eq(movie)
|
|
2537
2837
|
end
|
|
2538
2838
|
end
|
|
@@ -2551,7 +2851,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2551
2851
|
expect(found).to be_persisted
|
|
2552
2852
|
end
|
|
2553
2853
|
|
|
2554
|
-
it "keeps the document in the
|
|
2854
|
+
it "keeps the document in the association" do
|
|
2555
2855
|
expect(found.ratable).to eq(movie)
|
|
2556
2856
|
end
|
|
2557
2857
|
end
|
|
@@ -2560,14 +2860,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2560
2860
|
|
|
2561
2861
|
describe "#find_or_create_by!" do
|
|
2562
2862
|
|
|
2563
|
-
context "when the
|
|
2863
|
+
context "when the association is not polymorphic" do
|
|
2564
2864
|
|
|
2565
2865
|
let(:person) do
|
|
2566
|
-
Person.create
|
|
2866
|
+
Person.create!
|
|
2567
2867
|
end
|
|
2568
2868
|
|
|
2569
2869
|
let!(:post) do
|
|
2570
|
-
person.posts.create(title: "Testing")
|
|
2870
|
+
person.posts.create!(title: "Testing")
|
|
2571
2871
|
end
|
|
2572
2872
|
|
|
2573
2873
|
context "when the document exists" do
|
|
@@ -2580,7 +2880,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2580
2880
|
expect(found).to eq(post)
|
|
2581
2881
|
end
|
|
2582
2882
|
|
|
2583
|
-
it "keeps the document in the
|
|
2883
|
+
it "keeps the document in the association" do
|
|
2584
2884
|
expect(found.person).to eq(person)
|
|
2585
2885
|
end
|
|
2586
2886
|
end
|
|
@@ -2607,7 +2907,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2607
2907
|
expect(found.content).to eq("The Content")
|
|
2608
2908
|
end
|
|
2609
2909
|
|
|
2610
|
-
it "keeps the document in the
|
|
2910
|
+
it "keeps the document in the association" do
|
|
2611
2911
|
expect(found.person).to eq(person)
|
|
2612
2912
|
end
|
|
2613
2913
|
end
|
|
@@ -2626,21 +2926,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2626
2926
|
expect(found).to be_persisted
|
|
2627
2927
|
end
|
|
2628
2928
|
|
|
2629
|
-
it "keeps the document in the
|
|
2929
|
+
it "keeps the document in the association" do
|
|
2630
2930
|
expect(found.person).to eq(person)
|
|
2631
2931
|
end
|
|
2632
2932
|
end
|
|
2633
2933
|
end
|
|
2634
2934
|
end
|
|
2635
2935
|
|
|
2636
|
-
context "when the
|
|
2936
|
+
context "when the association is polymorphic" do
|
|
2637
2937
|
|
|
2638
2938
|
let(:movie) do
|
|
2639
|
-
Movie.create
|
|
2939
|
+
Movie.create!
|
|
2640
2940
|
end
|
|
2641
2941
|
|
|
2642
2942
|
let!(:rating) do
|
|
2643
|
-
movie.ratings.create(value: 1)
|
|
2943
|
+
movie.ratings.create!(value: 1)
|
|
2644
2944
|
end
|
|
2645
2945
|
|
|
2646
2946
|
context "when the document exists" do
|
|
@@ -2653,7 +2953,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2653
2953
|
expect(found).to eq(rating)
|
|
2654
2954
|
end
|
|
2655
2955
|
|
|
2656
|
-
it "keeps the document in the
|
|
2956
|
+
it "keeps the document in the association" do
|
|
2657
2957
|
expect(found.ratable).to eq(movie)
|
|
2658
2958
|
end
|
|
2659
2959
|
end
|
|
@@ -2672,7 +2972,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2672
2972
|
expect(found).to be_persisted
|
|
2673
2973
|
end
|
|
2674
2974
|
|
|
2675
|
-
it "keeps the document in the
|
|
2975
|
+
it "keeps the document in the association" do
|
|
2676
2976
|
expect(found.ratable).to eq(movie)
|
|
2677
2977
|
end
|
|
2678
2978
|
|
|
@@ -2690,14 +2990,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2690
2990
|
|
|
2691
2991
|
describe "#find_or_initialize_by" do
|
|
2692
2992
|
|
|
2693
|
-
context "when the
|
|
2993
|
+
context "when the association is not polymorphic" do
|
|
2694
2994
|
|
|
2695
2995
|
let(:person) do
|
|
2696
|
-
Person.create
|
|
2996
|
+
Person.create!
|
|
2697
2997
|
end
|
|
2698
2998
|
|
|
2699
2999
|
let!(:post) do
|
|
2700
|
-
person.posts.create(title: "Testing")
|
|
3000
|
+
person.posts.create!(title: "Testing")
|
|
2701
3001
|
end
|
|
2702
3002
|
|
|
2703
3003
|
context "when the document exists" do
|
|
@@ -2733,14 +3033,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2733
3033
|
end
|
|
2734
3034
|
end
|
|
2735
3035
|
|
|
2736
|
-
context "when the
|
|
3036
|
+
context "when the association is polymorphic" do
|
|
2737
3037
|
|
|
2738
3038
|
let(:movie) do
|
|
2739
|
-
Movie.create
|
|
3039
|
+
Movie.create!
|
|
2740
3040
|
end
|
|
2741
3041
|
|
|
2742
3042
|
let!(:rating) do
|
|
2743
|
-
movie.ratings.create(value: 1)
|
|
3043
|
+
movie.ratings.create!(value: 1)
|
|
2744
3044
|
end
|
|
2745
3045
|
|
|
2746
3046
|
context "when the document exists" do
|
|
@@ -2773,7 +3073,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2773
3073
|
|
|
2774
3074
|
describe "#initialize" do
|
|
2775
3075
|
|
|
2776
|
-
context "when an illegal mixed
|
|
3076
|
+
context "when an illegal mixed association exists" do
|
|
2777
3077
|
|
|
2778
3078
|
let(:post) do
|
|
2779
3079
|
Post.new
|
|
@@ -2786,7 +3086,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2786
3086
|
end
|
|
2787
3087
|
end
|
|
2788
3088
|
|
|
2789
|
-
context "when a cyclic
|
|
3089
|
+
context "when a cyclic association exists" do
|
|
2790
3090
|
|
|
2791
3091
|
let(:post) do
|
|
2792
3092
|
Post.new
|
|
@@ -2830,15 +3130,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2830
3130
|
describe "#max" do
|
|
2831
3131
|
|
|
2832
3132
|
let(:person) do
|
|
2833
|
-
Person.create
|
|
3133
|
+
Person.create!
|
|
2834
3134
|
end
|
|
2835
3135
|
|
|
2836
3136
|
let(:post_one) do
|
|
2837
|
-
Post.create(rating: 5)
|
|
3137
|
+
Post.create!(rating: 5)
|
|
2838
3138
|
end
|
|
2839
3139
|
|
|
2840
3140
|
let(:post_two) do
|
|
2841
|
-
Post.create(rating: 10)
|
|
3141
|
+
Post.create!(rating: 10)
|
|
2842
3142
|
end
|
|
2843
3143
|
|
|
2844
3144
|
before do
|
|
@@ -2859,15 +3159,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2859
3159
|
describe "#max_by" do
|
|
2860
3160
|
|
|
2861
3161
|
let(:person) do
|
|
2862
|
-
Person.create
|
|
3162
|
+
Person.create!
|
|
2863
3163
|
end
|
|
2864
3164
|
|
|
2865
3165
|
let(:post_one) do
|
|
2866
|
-
Post.create(rating: 5)
|
|
3166
|
+
Post.create!(rating: 5)
|
|
2867
3167
|
end
|
|
2868
3168
|
|
|
2869
3169
|
let(:post_two) do
|
|
2870
|
-
Post.create(rating: 10)
|
|
3170
|
+
Post.create!(rating: 10)
|
|
2871
3171
|
end
|
|
2872
3172
|
|
|
2873
3173
|
before do
|
|
@@ -2886,15 +3186,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2886
3186
|
describe "#method_missing" do
|
|
2887
3187
|
|
|
2888
3188
|
let!(:person) do
|
|
2889
|
-
Person.create
|
|
3189
|
+
Person.create!
|
|
2890
3190
|
end
|
|
2891
3191
|
|
|
2892
3192
|
let!(:post_one) do
|
|
2893
|
-
person.posts.create(title: "First", content: "Posting")
|
|
3193
|
+
person.posts.create!(title: "First", content: "Posting")
|
|
2894
3194
|
end
|
|
2895
3195
|
|
|
2896
3196
|
let!(:post_two) do
|
|
2897
|
-
person.posts.create(title: "Second", content: "Testing")
|
|
3197
|
+
person.posts.create!(title: "Second", content: "Testing")
|
|
2898
3198
|
end
|
|
2899
3199
|
|
|
2900
3200
|
context "when providing a single criteria" do
|
|
@@ -2907,7 +3207,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2907
3207
|
expect(posts).to eq([ post_one ])
|
|
2908
3208
|
end
|
|
2909
3209
|
|
|
2910
|
-
context 'when providing a collation'
|
|
3210
|
+
context 'when providing a collation' do
|
|
3211
|
+
min_server_version '3.4'
|
|
2911
3212
|
|
|
2912
3213
|
let(:posts) do
|
|
2913
3214
|
person.posts.where(title: "FIRST").collation(locale: 'en_US', strength: 2)
|
|
@@ -2960,15 +3261,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2960
3261
|
describe "#min" do
|
|
2961
3262
|
|
|
2962
3263
|
let(:person) do
|
|
2963
|
-
Person.create
|
|
3264
|
+
Person.create!
|
|
2964
3265
|
end
|
|
2965
3266
|
|
|
2966
3267
|
let(:post_one) do
|
|
2967
|
-
Post.create(rating: 5)
|
|
3268
|
+
Post.create!(rating: 5)
|
|
2968
3269
|
end
|
|
2969
3270
|
|
|
2970
3271
|
let(:post_two) do
|
|
2971
|
-
Post.create(rating: 10)
|
|
3272
|
+
Post.create!(rating: 10)
|
|
2972
3273
|
end
|
|
2973
3274
|
|
|
2974
3275
|
before do
|
|
@@ -2989,15 +3290,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2989
3290
|
describe "#min_by" do
|
|
2990
3291
|
|
|
2991
3292
|
let(:person) do
|
|
2992
|
-
Person.create
|
|
3293
|
+
Person.create!
|
|
2993
3294
|
end
|
|
2994
3295
|
|
|
2995
3296
|
let(:post_one) do
|
|
2996
|
-
Post.create(rating: 5)
|
|
3297
|
+
Post.create!(rating: 5)
|
|
2997
3298
|
end
|
|
2998
3299
|
|
|
2999
3300
|
let(:post_two) do
|
|
3000
|
-
Post.create(rating: 10)
|
|
3301
|
+
Post.create!(rating: 10)
|
|
3001
3302
|
end
|
|
3002
3303
|
|
|
3003
3304
|
before do
|
|
@@ -3018,15 +3319,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3018
3319
|
context "when the inverse has not been loaded" do
|
|
3019
3320
|
|
|
3020
3321
|
let(:person) do
|
|
3021
|
-
Person.create
|
|
3322
|
+
Person.create!
|
|
3022
3323
|
end
|
|
3023
3324
|
|
|
3024
3325
|
let!(:post_one) do
|
|
3025
|
-
person.posts.create(title: "One")
|
|
3326
|
+
person.posts.create!(title: "One")
|
|
3026
3327
|
end
|
|
3027
3328
|
|
|
3028
3329
|
let!(:post_two) do
|
|
3029
|
-
person.posts.create(title: "Two")
|
|
3330
|
+
person.posts.create!(title: "Two")
|
|
3030
3331
|
end
|
|
3031
3332
|
|
|
3032
3333
|
let(:from_db) do
|
|
@@ -3052,18 +3353,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3052
3353
|
end
|
|
3053
3354
|
end
|
|
3054
3355
|
|
|
3055
|
-
context "when the
|
|
3356
|
+
context "when the association is not polymorphic" do
|
|
3056
3357
|
|
|
3057
3358
|
let(:person) do
|
|
3058
|
-
Person.create
|
|
3359
|
+
Person.create!
|
|
3059
3360
|
end
|
|
3060
3361
|
|
|
3061
3362
|
let!(:post_one) do
|
|
3062
|
-
person.posts.create(title: "One")
|
|
3363
|
+
person.posts.create!(title: "One")
|
|
3063
3364
|
end
|
|
3064
3365
|
|
|
3065
3366
|
let!(:post_two) do
|
|
3066
|
-
person.posts.create(title: "Two")
|
|
3367
|
+
person.posts.create!(title: "Two")
|
|
3067
3368
|
end
|
|
3068
3369
|
|
|
3069
3370
|
before do
|
|
@@ -3086,30 +3387,30 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3086
3387
|
expect(post_one.reload.person).to be_nil
|
|
3087
3388
|
end
|
|
3088
3389
|
|
|
3089
|
-
context "when adding a nullified document back to the
|
|
3390
|
+
context "when adding a nullified document back to the association" do
|
|
3090
3391
|
|
|
3091
3392
|
before do
|
|
3092
3393
|
person.posts.push(post_one)
|
|
3093
3394
|
end
|
|
3094
3395
|
|
|
3095
|
-
it "persists the
|
|
3396
|
+
it "persists the association" do
|
|
3096
3397
|
expect(person.posts(true)).to eq([ post_one ])
|
|
3097
3398
|
end
|
|
3098
3399
|
end
|
|
3099
3400
|
end
|
|
3100
3401
|
|
|
3101
|
-
context "when the
|
|
3402
|
+
context "when the association is polymorphic" do
|
|
3102
3403
|
|
|
3103
3404
|
let(:movie) do
|
|
3104
|
-
Movie.create(title: "Oldboy")
|
|
3405
|
+
Movie.create!(title: "Oldboy")
|
|
3105
3406
|
end
|
|
3106
3407
|
|
|
3107
3408
|
let!(:rating_one) do
|
|
3108
|
-
movie.ratings.create(value: 10)
|
|
3409
|
+
movie.ratings.create!(value: 10)
|
|
3109
3410
|
end
|
|
3110
3411
|
|
|
3111
3412
|
let!(:rating_two) do
|
|
3112
|
-
movie.ratings.create(value: 9)
|
|
3413
|
+
movie.ratings.create!(value: 9)
|
|
3113
3414
|
end
|
|
3114
3415
|
|
|
3115
3416
|
before do
|
|
@@ -3181,7 +3482,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3181
3482
|
person.posts.scoped
|
|
3182
3483
|
end
|
|
3183
3484
|
|
|
3184
|
-
it "returns the
|
|
3485
|
+
it "returns the association criteria" do
|
|
3185
3486
|
expect(scoped).to be_a(Mongoid::Criteria)
|
|
3186
3487
|
end
|
|
3187
3488
|
|
|
@@ -3195,13 +3496,13 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3195
3496
|
describe "##{method}" do
|
|
3196
3497
|
|
|
3197
3498
|
let(:movie) do
|
|
3198
|
-
Movie.create
|
|
3499
|
+
Movie.create!
|
|
3199
3500
|
end
|
|
3200
3501
|
|
|
3201
3502
|
context "when documents have been persisted" do
|
|
3202
3503
|
|
|
3203
3504
|
let!(:rating) do
|
|
3204
|
-
movie.ratings.create(value: 1)
|
|
3505
|
+
movie.ratings.create!(value: 1)
|
|
3205
3506
|
end
|
|
3206
3507
|
|
|
3207
3508
|
it "returns 1" do
|
|
@@ -3213,7 +3514,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3213
3514
|
|
|
3214
3515
|
before do
|
|
3215
3516
|
movie.ratings.build(value: 1)
|
|
3216
|
-
movie.ratings.create(value: 2)
|
|
3517
|
+
movie.ratings.create!(value: 2)
|
|
3217
3518
|
end
|
|
3218
3519
|
|
|
3219
3520
|
it "returns the total number of documents" do
|
|
@@ -3225,18 +3526,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3225
3526
|
|
|
3226
3527
|
describe "#unscoped" do
|
|
3227
3528
|
|
|
3228
|
-
context "when the
|
|
3529
|
+
context "when the association has no default scope" do
|
|
3229
3530
|
|
|
3230
3531
|
let!(:person) do
|
|
3231
|
-
Person.create
|
|
3532
|
+
Person.create!
|
|
3232
3533
|
end
|
|
3233
3534
|
|
|
3234
3535
|
let!(:post_one) do
|
|
3235
|
-
person.posts.create(title: "first")
|
|
3536
|
+
person.posts.create!(title: "first")
|
|
3236
3537
|
end
|
|
3237
3538
|
|
|
3238
3539
|
let!(:post_two) do
|
|
3239
|
-
Post.create(title: "second")
|
|
3540
|
+
Post.create!(title: "second")
|
|
3240
3541
|
end
|
|
3241
3542
|
|
|
3242
3543
|
let(:unscoped) do
|
|
@@ -3248,18 +3549,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3248
3549
|
end
|
|
3249
3550
|
end
|
|
3250
3551
|
|
|
3251
|
-
context "when the
|
|
3552
|
+
context "when the association has a default scope" do
|
|
3252
3553
|
|
|
3253
3554
|
let!(:church) do
|
|
3254
|
-
Church.create
|
|
3555
|
+
Church.create!
|
|
3255
3556
|
end
|
|
3256
3557
|
|
|
3257
3558
|
let!(:acolyte_one) do
|
|
3258
|
-
church.acolytes.create(name: "first")
|
|
3559
|
+
church.acolytes.create!(name: "first")
|
|
3259
3560
|
end
|
|
3260
3561
|
|
|
3261
3562
|
let!(:acolyte_two) do
|
|
3262
|
-
Acolyte.create(name: "second")
|
|
3563
|
+
Acolyte.create!(name: "second")
|
|
3263
3564
|
end
|
|
3264
3565
|
|
|
3265
3566
|
let(:unscoped) do
|
|
@@ -3279,19 +3580,19 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3279
3580
|
context "when the association has an order defined" do
|
|
3280
3581
|
|
|
3281
3582
|
let(:person) do
|
|
3282
|
-
Person.create
|
|
3583
|
+
Person.create!
|
|
3283
3584
|
end
|
|
3284
3585
|
|
|
3285
3586
|
let(:post_one) do
|
|
3286
|
-
OrderedPost.create(rating: 10, title: '1')
|
|
3587
|
+
OrderedPost.create!(rating: 10, title: '1')
|
|
3287
3588
|
end
|
|
3288
3589
|
|
|
3289
3590
|
let(:post_two) do
|
|
3290
|
-
OrderedPost.create(rating: 20, title: '2')
|
|
3591
|
+
OrderedPost.create!(rating: 20, title: '2')
|
|
3291
3592
|
end
|
|
3292
3593
|
|
|
3293
3594
|
let(:post_three) do
|
|
3294
|
-
OrderedPost.create(rating: 20, title: '3')
|
|
3595
|
+
OrderedPost.create!(rating: 20, title: '3')
|
|
3295
3596
|
end
|
|
3296
3597
|
|
|
3297
3598
|
before do
|
|
@@ -3305,32 +3606,32 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3305
3606
|
)
|
|
3306
3607
|
end
|
|
3307
3608
|
|
|
3308
|
-
it "chaining order
|
|
3609
|
+
it "chaining order criteria" do
|
|
3309
3610
|
expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
|
|
3310
3611
|
[post_three, post_two, post_one]
|
|
3311
3612
|
)
|
|
3312
3613
|
end
|
|
3313
3614
|
end
|
|
3314
3615
|
|
|
3315
|
-
context "when reloading the
|
|
3616
|
+
context "when reloading the association" do
|
|
3316
3617
|
|
|
3317
3618
|
let!(:person) do
|
|
3318
|
-
Person.create
|
|
3619
|
+
Person.create!
|
|
3319
3620
|
end
|
|
3320
3621
|
|
|
3321
3622
|
let!(:post_one) do
|
|
3322
|
-
Post.create(title: "one")
|
|
3623
|
+
Post.create!(title: "one")
|
|
3323
3624
|
end
|
|
3324
3625
|
|
|
3325
3626
|
let!(:post_two) do
|
|
3326
|
-
Post.create(title: "two")
|
|
3627
|
+
Post.create!(title: "two")
|
|
3327
3628
|
end
|
|
3328
3629
|
|
|
3329
3630
|
before do
|
|
3330
3631
|
person.posts << post_one
|
|
3331
3632
|
end
|
|
3332
3633
|
|
|
3333
|
-
context "when the
|
|
3634
|
+
context "when the association references the same documents" do
|
|
3334
3635
|
|
|
3335
3636
|
before do
|
|
3336
3637
|
Post.collection.find({ _id: post_one.id }).
|
|
@@ -3346,7 +3647,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3346
3647
|
end
|
|
3347
3648
|
end
|
|
3348
3649
|
|
|
3349
|
-
context "when the
|
|
3650
|
+
context "when the association references different documents" do
|
|
3350
3651
|
|
|
3351
3652
|
before do
|
|
3352
3653
|
person.posts << post_two
|
|
@@ -3369,7 +3670,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3369
3670
|
context "when the parent is using integer ids" do
|
|
3370
3671
|
|
|
3371
3672
|
let(:jar) do
|
|
3372
|
-
Jar.create do |doc|
|
|
3673
|
+
Jar.create! do |doc|
|
|
3373
3674
|
doc._id = 1
|
|
3374
3675
|
end
|
|
3375
3676
|
end
|
|
@@ -3433,7 +3734,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3433
3734
|
expect(album.before_add_called).to be true
|
|
3434
3735
|
end
|
|
3435
3736
|
|
|
3436
|
-
it "adds the document to the
|
|
3737
|
+
it "adds the document to the association" do
|
|
3437
3738
|
expect(artist.albums).to eq([ album ])
|
|
3438
3739
|
end
|
|
3439
3740
|
end
|
|
@@ -3445,7 +3746,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3445
3746
|
begin; artist.albums << album; rescue; end
|
|
3446
3747
|
end
|
|
3447
3748
|
|
|
3448
|
-
it "does not add the document to the
|
|
3749
|
+
it "does not add the document to the association" do
|
|
3449
3750
|
expect(artist.albums).to be_empty
|
|
3450
3751
|
end
|
|
3451
3752
|
end
|
|
@@ -3473,17 +3774,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3473
3774
|
begin; artist.albums << album; rescue; end
|
|
3474
3775
|
end
|
|
3475
3776
|
|
|
3476
|
-
it "adds the document to the
|
|
3777
|
+
it "adds the document to the association" do
|
|
3477
3778
|
expect(artist.albums).to eq([ album ])
|
|
3478
3779
|
end
|
|
3479
3780
|
end
|
|
3480
3781
|
|
|
3481
|
-
context 'when the
|
|
3782
|
+
context 'when the association already exists' do
|
|
3482
3783
|
|
|
3483
3784
|
before do
|
|
3484
3785
|
artist.albums << album
|
|
3485
|
-
album.save
|
|
3486
|
-
artist.save
|
|
3786
|
+
album.save!
|
|
3787
|
+
artist.save!
|
|
3487
3788
|
expect(artist).not_to receive(:after_add_album)
|
|
3488
3789
|
end
|
|
3489
3790
|
|
|
@@ -3491,7 +3792,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3491
3792
|
Album.where(artist_id: artist.id).first
|
|
3492
3793
|
end
|
|
3493
3794
|
|
|
3494
|
-
it 'does not execute the callback when the
|
|
3795
|
+
it 'does not execute the callback when the association is accessed' do
|
|
3495
3796
|
expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
|
|
3496
3797
|
end
|
|
3497
3798
|
end
|
|
@@ -3523,7 +3824,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3523
3824
|
expect(artist.before_remove_referenced_called).to be true
|
|
3524
3825
|
end
|
|
3525
3826
|
|
|
3526
|
-
it "removes the document from the
|
|
3827
|
+
it "removes the document from the association" do
|
|
3527
3828
|
expect(artist.albums).to be_empty
|
|
3528
3829
|
end
|
|
3529
3830
|
end
|
|
@@ -3538,7 +3839,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3538
3839
|
expect(artist.before_remove_referenced_called).to be true
|
|
3539
3840
|
end
|
|
3540
3841
|
|
|
3541
|
-
it "clears the
|
|
3842
|
+
it "clears the association" do
|
|
3542
3843
|
expect(artist.albums).to be_empty
|
|
3543
3844
|
end
|
|
3544
3845
|
end
|
|
@@ -3555,7 +3856,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3555
3856
|
begin; artist.albums.delete(album); rescue; end
|
|
3556
3857
|
end
|
|
3557
3858
|
|
|
3558
|
-
it "does not remove the document from the
|
|
3859
|
+
it "does not remove the document from the association" do
|
|
3559
3860
|
expect(artist.albums).to eq([ album ])
|
|
3560
3861
|
end
|
|
3561
3862
|
end
|
|
@@ -3566,7 +3867,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3566
3867
|
begin; artist.albums.clear; rescue; end
|
|
3567
3868
|
end
|
|
3568
3869
|
|
|
3569
|
-
it "does not clear the
|
|
3870
|
+
it "does not clear the association" do
|
|
3570
3871
|
expect(artist.albums).to eq([ album ])
|
|
3571
3872
|
end
|
|
3572
3873
|
end
|
|
@@ -3626,7 +3927,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3626
3927
|
begin; artist.albums.delete(album); rescue; end
|
|
3627
3928
|
end
|
|
3628
3929
|
|
|
3629
|
-
it "removes the documents from the
|
|
3930
|
+
it "removes the documents from the association" do
|
|
3630
3931
|
expect(artist.albums).to be_empty
|
|
3631
3932
|
end
|
|
3632
3933
|
end
|
|
@@ -3637,25 +3938,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3637
3938
|
begin; artist.albums.clear; rescue; end
|
|
3638
3939
|
end
|
|
3639
3940
|
|
|
3640
|
-
it "removes the documents from the
|
|
3941
|
+
it "removes the documents from the association" do
|
|
3641
3942
|
expect(artist.albums).to be_empty
|
|
3642
3943
|
end
|
|
3643
3944
|
end
|
|
3644
3945
|
end
|
|
3645
3946
|
end
|
|
3646
3947
|
|
|
3647
|
-
context "when executing a criteria call on an ordered
|
|
3948
|
+
context "when executing a criteria call on an ordered association" do
|
|
3648
3949
|
|
|
3649
3950
|
let(:person) do
|
|
3650
|
-
Person.create
|
|
3951
|
+
Person.create!
|
|
3651
3952
|
end
|
|
3652
3953
|
|
|
3653
3954
|
let!(:post_one) do
|
|
3654
|
-
person.ordered_posts.create(rating: 1)
|
|
3955
|
+
person.ordered_posts.create!(rating: 1)
|
|
3655
3956
|
end
|
|
3656
3957
|
|
|
3657
3958
|
let!(:post_two) do
|
|
3658
|
-
person.ordered_posts.create(rating: 5)
|
|
3959
|
+
person.ordered_posts.create!(rating: 5)
|
|
3659
3960
|
end
|
|
3660
3961
|
|
|
3661
3962
|
let(:criteria) do
|
|
@@ -3670,11 +3971,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3670
3971
|
context "when accessing a scope named open" do
|
|
3671
3972
|
|
|
3672
3973
|
let(:person) do
|
|
3673
|
-
Person.create
|
|
3974
|
+
Person.create!
|
|
3674
3975
|
end
|
|
3675
3976
|
|
|
3676
3977
|
let!(:post) do
|
|
3677
|
-
person.posts.create(title: "open")
|
|
3978
|
+
person.posts.create!(title: "open")
|
|
3678
3979
|
end
|
|
3679
3980
|
|
|
3680
3981
|
it "returns the appropriate documents" do
|
|
@@ -3682,18 +3983,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3682
3983
|
end
|
|
3683
3984
|
end
|
|
3684
3985
|
|
|
3685
|
-
context "when accessing a
|
|
3986
|
+
context "when accessing a association named parent" do
|
|
3686
3987
|
|
|
3687
3988
|
let!(:parent) do
|
|
3688
|
-
Odd.create(name: "odd parent")
|
|
3989
|
+
Odd.create!(name: "odd parent")
|
|
3689
3990
|
end
|
|
3690
3991
|
|
|
3691
3992
|
let(:child) do
|
|
3692
|
-
Even.create(parent_id: parent.id, name: "original even child")
|
|
3993
|
+
Even.create!(parent_id: parent.id, name: "original even child")
|
|
3693
3994
|
end
|
|
3694
3995
|
|
|
3695
3996
|
it "updates the child after accessing the parent" do
|
|
3696
|
-
# Access parent
|
|
3997
|
+
# Access parent association on the child to make sure it is loaded
|
|
3697
3998
|
child.parent
|
|
3698
3999
|
|
|
3699
4000
|
new_child_name = "updated even child"
|
|
@@ -3706,7 +4007,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3706
4007
|
end
|
|
3707
4008
|
end
|
|
3708
4009
|
|
|
3709
|
-
context 'when a document has referenced and embedded
|
|
4010
|
+
context 'when a document has referenced and embedded associations' do
|
|
3710
4011
|
|
|
3711
4012
|
let(:agent) do
|
|
3712
4013
|
Agent.new
|
|
@@ -3726,11 +4027,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3726
4027
|
end
|
|
3727
4028
|
|
|
3728
4029
|
it 'saves the document correctly' do
|
|
3729
|
-
expect(agent.save).to be(true)
|
|
4030
|
+
expect(agent.save!).to be(true)
|
|
3730
4031
|
end
|
|
3731
4032
|
end
|
|
3732
4033
|
|
|
3733
|
-
context 'when the two models use the same name to refer to the
|
|
4034
|
+
context 'when the two models use the same name to refer to the association' do
|
|
3734
4035
|
|
|
3735
4036
|
let(:agent) do
|
|
3736
4037
|
Agent.new
|
|
@@ -3742,8 +4043,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3742
4043
|
|
|
3743
4044
|
before do
|
|
3744
4045
|
agent.same_name = band
|
|
3745
|
-
agent.save
|
|
3746
|
-
band.save
|
|
4046
|
+
agent.save!
|
|
4047
|
+
band.save!
|
|
3747
4048
|
band.reload
|
|
3748
4049
|
end
|
|
3749
4050
|
|
|
@@ -3751,4 +4052,57 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3751
4052
|
expect(band.same_name).to eq([agent])
|
|
3752
4053
|
end
|
|
3753
4054
|
end
|
|
4055
|
+
|
|
4056
|
+
context "when removing a document with counter_cache on" do
|
|
4057
|
+
let(:post) { Post.create! }
|
|
4058
|
+
let(:person1) { Person.create! }
|
|
4059
|
+
let(:person2) { Person.create! }
|
|
4060
|
+
|
|
4061
|
+
before do
|
|
4062
|
+
post.update_attribute(:person, person1)
|
|
4063
|
+
expect(person1.posts_count).to eq 1
|
|
4064
|
+
|
|
4065
|
+
person2
|
|
4066
|
+
post.update_attribute(:person, person2)
|
|
4067
|
+
person1.reload
|
|
4068
|
+
expect(person1.posts_count).to eq 0
|
|
4069
|
+
expect(person2.posts_count).to eq 1
|
|
4070
|
+
|
|
4071
|
+
post.update_attribute(:person, nil)
|
|
4072
|
+
person1.reload
|
|
4073
|
+
person2.reload
|
|
4074
|
+
end
|
|
4075
|
+
|
|
4076
|
+
it "the count field is updated" do
|
|
4077
|
+
expect(person2.posts_count).to eq 0
|
|
4078
|
+
end
|
|
4079
|
+
end
|
|
4080
|
+
|
|
4081
|
+
context "when there is a foreign key in the aliased associations" do
|
|
4082
|
+
it "has the correct aliases" do
|
|
4083
|
+
expect(Band.aliased_associations["artist_ids"]).to eq("artists")
|
|
4084
|
+
expect(Artist.aliased_associations.key?("band_id")).to be false
|
|
4085
|
+
expect(Artist.aliased_fields["band"]).to eq("band_id")
|
|
4086
|
+
end
|
|
4087
|
+
end
|
|
4088
|
+
|
|
4089
|
+
context "when executing concat on foreign key array from the db" do
|
|
4090
|
+
config_override :legacy_attributes, false
|
|
4091
|
+
|
|
4092
|
+
before do
|
|
4093
|
+
Agent.create!
|
|
4094
|
+
Basic.create!
|
|
4095
|
+
end
|
|
4096
|
+
|
|
4097
|
+
let!(:agent) { Agent.first }
|
|
4098
|
+
let!(:basic) { Basic.first }
|
|
4099
|
+
|
|
4100
|
+
before do
|
|
4101
|
+
agent.basic_ids.concat([basic.id])
|
|
4102
|
+
end
|
|
4103
|
+
|
|
4104
|
+
it "works on the first attempt" do
|
|
4105
|
+
expect(agent.basic_ids).to eq([basic.id])
|
|
4106
|
+
end
|
|
4107
|
+
end
|
|
3754
4108
|
end
|