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