mongoid 7.0.13 → 8.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +30 -30
- data/README.md +32 -19
- data/Rakefile +43 -0
- data/lib/config/locales/en.yml +178 -95
- data/lib/mongoid/association/accessors.rb +175 -83
- data/lib/mongoid/association/bindable.rb +57 -28
- data/lib/mongoid/association/builders.rb +8 -14
- 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 +67 -53
- 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 +7 -4
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +14 -24
- 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 +8 -5
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +143 -122
- data/lib/mongoid/association/embedded/embeds_many.rb +8 -36
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +4 -8
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +26 -9
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +63 -29
- data/lib/mongoid/association/embedded/embeds_one.rb +9 -33
- data/lib/mongoid/association/embedded.rb +2 -0
- data/lib/mongoid/association/macros.rb +71 -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 +19 -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 +37 -38
- 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 +41 -40
- 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 +105 -68
- 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 +101 -124
- 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 +62 -84
- 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 +2 -3
- data/lib/mongoid/atomic/paths/root.rb +4 -7
- data/lib/mongoid/atomic/paths.rb +2 -1
- data/lib/mongoid/atomic.rb +45 -51
- data/lib/mongoid/attributes/dynamic.rb +6 -21
- data/lib/mongoid/attributes/nested.rb +11 -14
- data/lib/mongoid/attributes/processing.rb +46 -30
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +5 -8
- data/lib/mongoid/attributes.rb +80 -98
- data/lib/mongoid/cacheable.rb +7 -10
- data/lib/mongoid/changeable.rb +49 -70
- data/lib/mongoid/clients/factory.rb +42 -17
- data/lib/mongoid/clients/options.rb +15 -14
- data/lib/mongoid/clients/sessions.rb +4 -20
- data/lib/mongoid/clients/storage_options.rb +7 -12
- data/lib/mongoid/clients/validators/storage.rb +5 -12
- data/lib/mongoid/clients/validators.rb +2 -1
- data/lib/mongoid/clients.rb +3 -10
- data/lib/mongoid/composable.rb +5 -9
- data/lib/mongoid/config/environment.rb +30 -5
- data/lib/mongoid/config/options.rb +23 -23
- data/lib/mongoid/config/validators/client.rb +8 -23
- data/lib/mongoid/config/validators/option.rb +2 -3
- data/lib/mongoid/config/validators.rb +2 -1
- data/lib/mongoid/config.rb +164 -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 +187 -81
- data/lib/mongoid/contextual/mongo.rb +360 -239
- data/lib/mongoid/contextual/none.rb +109 -31
- data/lib/mongoid/contextual/queryable.rb +3 -4
- data/lib/mongoid/contextual.rb +9 -11
- data/lib/mongoid/copyable.rb +42 -17
- data/lib/mongoid/criteria/findable.rb +19 -19
- data/lib/mongoid/criteria/includable.rb +30 -33
- data/lib/mongoid/criteria/inspectable.rb +2 -3
- data/lib/mongoid/criteria/marshalable.rb +12 -7
- data/lib/mongoid/criteria/modifiable.rb +2 -19
- data/lib/mongoid/criteria/options.rb +2 -3
- 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 +9 -16
- 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 +9 -9
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +9 -9
- data/lib/mongoid/criteria/queryable/extensions.rb +1 -4
- data/lib/mongoid/criteria/queryable/key.rb +39 -24
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -4
- data/lib/mongoid/criteria/queryable/mergeable.rb +200 -40
- data/lib/mongoid/criteria/queryable/optional.rb +10 -59
- 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 +417 -171
- data/lib/mongoid/criteria/queryable/selector.rb +127 -30
- 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 +95 -107
- data/lib/mongoid/deprecable.rb +37 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +148 -97
- 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/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/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +2 -3
- 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_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 +2 -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 +14 -3
- 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 +87 -45
- 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 +25 -50
- data/lib/mongoid/extensions/object_id.rb +2 -7
- data/lib/mongoid/extensions/range.rb +42 -20
- data/lib/mongoid/extensions/regexp.rb +13 -7
- data/lib/mongoid/extensions/set.rb +13 -11
- data/lib/mongoid/extensions/string.rb +30 -61
- data/lib/mongoid/extensions/symbol.rb +6 -22
- data/lib/mongoid/extensions/time.rb +37 -23
- 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 +11 -15
- data/lib/mongoid/fields/standard.rb +13 -43
- data/lib/mongoid/fields/validators/macro.rb +32 -20
- data/lib/mongoid/fields/validators.rb +2 -1
- data/lib/mongoid/fields.rb +328 -85
- data/lib/mongoid/findable.rb +90 -33
- 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 +191 -41
- data/lib/mongoid/loggable.rb +13 -16
- data/lib/mongoid/matchable.rb +3 -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 +22 -30
- data/lib/mongoid/persistable/deletable.rb +6 -22
- 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 +3 -8
- data/lib/mongoid/persistable/renamable.rb +10 -8
- data/lib/mongoid/persistable/savable.rb +5 -10
- data/lib/mongoid/persistable/settable.rb +3 -6
- data/lib/mongoid/persistable/unsettable.rb +9 -9
- data/lib/mongoid/persistable/updatable.rb +50 -31
- data/lib/mongoid/persistable/upsertable.rb +5 -10
- data/lib/mongoid/persistable.rb +135 -40
- data/lib/mongoid/persistence_context.rb +85 -45
- data/lib/mongoid/positional.rb +2 -5
- data/lib/mongoid/query_cache.rb +13 -280
- data/lib/mongoid/railtie.rb +3 -16
- data/lib/mongoid/railties/controller_runtime.rb +4 -2
- data/lib/mongoid/railties/database.rake +9 -0
- data/lib/mongoid/reloadable.rb +19 -22
- data/lib/mongoid/scopable.rb +34 -57
- 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 +38 -19
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +12 -5
- data/lib/mongoid/tasks/database.rb +85 -7
- data/lib/mongoid/threaded/lifecycle.rb +7 -26
- data/lib/mongoid/threaded.rb +44 -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/validatable/associated.rb +99 -22
- 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 +2 -9
- data/lib/mongoid/validatable/presence.rb +10 -15
- data/lib/mongoid/validatable/queryable.rb +2 -3
- data/lib/mongoid/validatable/uniqueness.rb +29 -41
- data/lib/mongoid/validatable.rb +22 -33
- data/lib/mongoid/version.rb +2 -2
- data/lib/mongoid/warnings.rb +28 -0
- data/lib/mongoid.rb +34 -15
- data/lib/rails/generators/mongoid/config/config_generator.rb +2 -1
- 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_generator.rb +2 -1
- data/lib/rails/mongoid.rb +4 -5
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +17 -0
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +31 -27
- data/spec/integration/associations/belongs_to_spec.rb +20 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +162 -55
- 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 +61 -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 +107 -1
- data/spec/integration/callbacks_spec.rb +262 -8
- 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 +1 -2
- 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 +125 -15
- data/spec/integration/discriminator_key_spec.rb +392 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +30 -1
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +73 -0
- data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +130 -45
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +18 -6
- 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 +84 -22
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +3 -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 +687 -173
- data/spec/mongoid/association/embedded/embeds_many_models.rb +174 -1
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +63 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +71 -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 +23 -21
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +22 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +31 -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 +242 -12
- 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 +26 -3
- 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 +46 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +25 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +418 -361
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +68 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +81 -4
- 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 +314 -133
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +848 -451
- data/spec/mongoid/association/referenced/has_many_models.rb +61 -1
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +48 -0
- 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 +65 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +24 -1
- data/spec/mongoid/association/reflections_spec.rb +2 -0
- data/spec/mongoid/association/syncable_spec.rb +47 -31
- 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 +66 -26
- data/spec/mongoid/atomic_spec.rb +53 -6
- data/spec/mongoid/attributes/dynamic_spec.rb +0 -1
- 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 +683 -65
- data/spec/mongoid/cacheable_spec.rb +6 -4
- data/spec/mongoid/changeable_spec.rb +185 -43
- data/spec/mongoid/clients/factory_spec.rb +128 -28
- data/spec/mongoid/clients/options_spec.rb +45 -26
- data/spec/mongoid/clients/sessions_spec.rb +25 -66
- data/spec/mongoid/clients/transactions_spec.rb +54 -29
- data/spec/mongoid/clients_spec.rb +65 -8
- data/spec/mongoid/composable_spec.rb +2 -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 +377 -1
- 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 +205 -67
- data/spec/mongoid/contextual/geo_near_spec.rb +20 -18
- data/spec/mongoid/contextual/map_reduce_spec.rb +6 -18
- data/spec/mongoid/contextual/memory_spec.rb +1360 -91
- data/spec/mongoid/contextual/mongo_spec.rb +1871 -544
- data/spec/mongoid/contextual/none_spec.rb +39 -73
- data/spec/mongoid/copyable_spec.rb +657 -26
- data/spec/mongoid/copyable_spec_models.rb +30 -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 +43 -40
- 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/bignum_spec.rb +2 -0
- 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/fixnum_spec.rb +2 -0
- 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 +73 -8
- 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 +2 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +2 -59
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +2 -59
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +34 -16
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +13 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +2 -0
- 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 +2 -0
- 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 +1643 -286
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1191 -2752
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +91 -4
- data/spec/mongoid/criteria/queryable/smash_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +298 -0
- data/spec/mongoid/criteria/scopable_spec.rb +129 -0
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +409 -0
- data/spec/mongoid/criteria_spec.rb +1322 -1723
- data/spec/mongoid/document_fields_spec.rb +179 -5
- data/spec/mongoid/document_persistence_context_spec.rb +0 -1
- data/spec/mongoid/document_query_spec.rb +89 -0
- data/spec/mongoid/document_spec.rb +153 -87
- 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 +2 -0
- 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 +714 -212
- 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 +138 -3
- 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 +60 -33
- data/spec/mongoid/extensions/set_spec.rb +108 -0
- data/spec/mongoid/extensions/string_spec.rb +111 -50
- 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 +663 -66
- data/spec/mongoid/extensions/time_with_zone_spec.rb +50 -31
- 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 +43 -16
- data/spec/mongoid/fields/standard_spec.rb +2 -0
- data/spec/mongoid/fields_spec.rb +776 -80
- data/spec/mongoid/findable_spec.rb +133 -34
- data/spec/mongoid/indexable/specification_spec.rb +4 -2
- data/spec/mongoid/indexable_spec.rb +65 -18
- data/spec/mongoid/inspectable_spec.rb +39 -2
- data/spec/mongoid/interceptable_spec.rb +955 -103
- 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 +274 -12
- data/spec/mongoid/persistable/destroyable_spec.rb +202 -12
- data/spec/mongoid/persistable/incrementable_spec.rb +23 -7
- data/spec/mongoid/persistable/logical_spec.rb +19 -3
- data/spec/mongoid/persistable/poppable_spec.rb +19 -3
- data/spec/mongoid/persistable/pullable_spec.rb +36 -6
- data/spec/mongoid/persistable/pushable_spec.rb +36 -6
- data/spec/mongoid/persistable/renamable_spec.rb +18 -2
- data/spec/mongoid/persistable/savable_spec.rb +188 -25
- data/spec/mongoid/persistable/settable_spec.rb +24 -8
- data/spec/mongoid/persistable/unsettable_spec.rb +19 -3
- data/spec/mongoid/persistable/updatable_spec.rb +45 -23
- data/spec/mongoid/persistable/upsertable_spec.rb +18 -2
- data/spec/mongoid/persistable_spec.rb +85 -9
- data/spec/mongoid/persistence_context_spec.rb +52 -1
- 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 +339 -87
- data/spec/mongoid/relations/proxy_spec.rb +8 -6
- data/spec/mongoid/reloadable_spec.rb +357 -22
- data/spec/mongoid/scopable_spec.rb +121 -37
- data/spec/mongoid/selectable_spec.rb +8 -6
- data/spec/mongoid/serializable_spec.rb +160 -29
- data/spec/mongoid/shardable_models.rb +75 -0
- data/spec/mongoid/shardable_spec.rb +239 -34
- data/spec/mongoid/stateful_spec.rb +31 -1
- data/spec/mongoid/tasks/database_rake_spec.rb +2 -0
- data/spec/mongoid/tasks/database_spec.rb +2 -0
- data/spec/mongoid/threaded_spec.rb +4 -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 +398 -6
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +296 -33
- data/spec/mongoid/touchable_spec_models.rb +57 -0
- data/spec/mongoid/traversable_spec.rb +1160 -1
- data/spec/mongoid/validatable/associated_spec.rb +15 -30
- 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 +128 -98
- data/spec/mongoid/validatable_spec.rb +5 -3
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +3 -1
- data/spec/rails/controller_extension/controller_runtime_spec.rb +5 -3
- data/spec/rails/mongoid_spec.rb +8 -18
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/cluster_config.rb +14 -4
- data/spec/shared/lib/mrss/constraints.rb +51 -27
- data/spec/shared/lib/mrss/docker_runner.rb +37 -4
- 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 +48 -1
- data/spec/shared/lib/mrss/server_version_registry.rb +16 -18
- 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 +18 -1
- data/spec/shared/lib/mrss/utils.rb +28 -6
- data/spec/shared/share/Dockerfile.erb +156 -66
- 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 +2 -1
- data/spec/shared/shlib/server.sh +171 -45
- data/spec/shared/shlib/set_env.sh +47 -6
- data/spec/spec_helper.rb +38 -36
- data/spec/support/authorization.rb +2 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +39 -8
- data/spec/support/expectations.rb +5 -1
- data/spec/support/helpers.rb +11 -0
- data/spec/support/macros.rb +77 -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 -0
- 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 +9 -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 +2 -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 +2 -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/crate.rb +12 -0
- data/spec/{app → support}/models/customer.rb +0 -1
- data/spec/{app → support}/models/customer_address.rb +0 -1
- data/spec/support/models/deed.rb +7 -0
- data/spec/{app → support}/models/definition.rb +2 -0
- data/spec/{app → support}/models/delegating_patient.rb +0 -1
- 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/{app → support}/models/minim.rb +0 -1
- 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 +12 -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 +23 -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 +2 -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/support/models/purse.rb +9 -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/{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 +12 -3
- data.tar.gz.sig +0 -0
- metadata +1162 -764
- 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 -28
- data/lib/mongoid/matchable/and.rb +0 -30
- data/lib/mongoid/matchable/default.rb +0 -119
- data/lib/mongoid/matchable/elem_match.rb +0 -34
- data/lib/mongoid/matchable/eq.rb +0 -22
- data/lib/mongoid/matchable/exists.rb +0 -23
- data/lib/mongoid/matchable/gt.rb +0 -23
- data/lib/mongoid/matchable/gte.rb +0 -23
- data/lib/mongoid/matchable/in.rb +0 -24
- data/lib/mongoid/matchable/lt.rb +0 -23
- data/lib/mongoid/matchable/lte.rb +0 -23
- data/lib/mongoid/matchable/ne.rb +0 -21
- data/lib/mongoid/matchable/nin.rb +0 -22
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/matchable/or.rb +0 -33
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/lib/mongoid/matchable/size.rb +0 -21
- data/lib/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/other_owner_object.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/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 -137
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -106
- data/spec/mongoid/matchable/eq_spec.rb +0 -48
- data/spec/mongoid/matchable/exists_spec.rb +0 -57
- data/spec/mongoid/matchable/gt_spec.rb +0 -86
- data/spec/mongoid/matchable/gte_spec.rb +0 -84
- data/spec/mongoid/matchable/in_spec.rb +0 -49
- data/spec/mongoid/matchable/lt_spec.rb +0 -85
- data/spec/mongoid/matchable/lte_spec.rb +0 -85
- data/spec/mongoid/matchable/ne_spec.rb +0 -46
- data/spec/mongoid/matchable/nin_spec.rb +0 -48
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/matchable/or_spec.rb +0 -131
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
- data/spec/mongoid/matchable/size_spec.rb +0 -25
- data/spec/mongoid/matchable_spec.rb +0 -853
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/session_registry.rb +0 -50
- /data/spec/{app → support}/models/array_field.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test3.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test4.rb +0 -0
- /data/spec/{app → support}/models/updatable.rb +0 -0
@@ -1,5 +1,27 @@
|
|
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
|
4
26
|
|
5
27
|
before :all do
|
@@ -18,26 +40,26 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
18
40
|
|
19
41
|
describe "##{method}" do
|
20
42
|
|
21
|
-
context "when providing the base class in child
|
43
|
+
context "when providing the base class in child constructor" do
|
22
44
|
|
23
45
|
let(:person) do
|
24
|
-
Person.create
|
46
|
+
Person.create!
|
25
47
|
end
|
26
48
|
|
27
49
|
let!(:post) do
|
28
50
|
person.posts.send(method, Post.new(person: person))
|
29
51
|
end
|
30
52
|
|
31
|
-
it "only adds the
|
53
|
+
it "only adds the association once" do
|
32
54
|
expect(person.posts.size).to eq(1)
|
33
55
|
end
|
34
56
|
|
35
|
-
it "only persists the
|
57
|
+
it "only persists the association once" do
|
36
58
|
expect(person.reload.posts.size).to eq(1)
|
37
59
|
end
|
38
60
|
end
|
39
61
|
|
40
|
-
context "when the
|
62
|
+
context "when the associations are not polymorphic" do
|
41
63
|
|
42
64
|
context "when the parent is a new record" do
|
43
65
|
|
@@ -55,15 +77,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
55
77
|
person.posts.send(method, post)
|
56
78
|
end
|
57
79
|
|
58
|
-
it "sets the foreign key on the
|
80
|
+
it "sets the foreign key on the association" do
|
59
81
|
expect(post.person_id).to eq(person.id)
|
60
82
|
end
|
61
83
|
|
62
|
-
it "sets the base on the inverse
|
84
|
+
it "sets the base on the inverse association" do
|
63
85
|
expect(post.person).to eq(person)
|
64
86
|
end
|
65
87
|
|
66
|
-
it "sets the same instance on the inverse
|
88
|
+
it "sets the same instance on the inverse association" do
|
67
89
|
expect(post.person).to eql(person)
|
68
90
|
end
|
69
91
|
|
@@ -75,7 +97,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
75
97
|
expect(person.posts.size).to eq(1)
|
76
98
|
end
|
77
99
|
|
78
|
-
it "returns the
|
100
|
+
it "returns the association" do
|
79
101
|
expect(added).to eq(person.posts)
|
80
102
|
end
|
81
103
|
end
|
@@ -83,22 +105,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
83
105
|
context "when the child is persisted" do
|
84
106
|
|
85
107
|
let(:post) do
|
86
|
-
Post.create
|
108
|
+
Post.create!
|
87
109
|
end
|
88
110
|
|
89
111
|
before do
|
90
112
|
person.posts.send(method, post)
|
91
113
|
end
|
92
114
|
|
93
|
-
it "sets the foreign key on the
|
115
|
+
it "sets the foreign key on the association" do
|
94
116
|
expect(post.person_id).to eq(person.id)
|
95
117
|
end
|
96
118
|
|
97
|
-
it "sets the base on the inverse
|
119
|
+
it "sets the base on the inverse association" do
|
98
120
|
expect(post.person).to eq(person)
|
99
121
|
end
|
100
122
|
|
101
|
-
it "sets the same instance on the inverse
|
123
|
+
it "sets the same instance on the inverse association" do
|
102
124
|
expect(post.person).to eql(person)
|
103
125
|
end
|
104
126
|
|
@@ -113,11 +135,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
113
135
|
context "when subsequently saving the parent" do
|
114
136
|
|
115
137
|
before do
|
116
|
-
person.save
|
117
|
-
post.save
|
138
|
+
person.save!
|
139
|
+
post.save!
|
118
140
|
end
|
119
141
|
|
120
|
-
it "returns the correct count of the
|
142
|
+
it "returns the correct count of the association" do
|
121
143
|
expect(person.posts.count).to eq(1)
|
122
144
|
end
|
123
145
|
end
|
@@ -127,20 +149,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
127
149
|
context "when appending in a parent create block" do
|
128
150
|
|
129
151
|
let!(:post) do
|
130
|
-
Post.create(title: "testing")
|
152
|
+
Post.create!(title: "testing")
|
131
153
|
end
|
132
154
|
|
133
155
|
let!(:person) do
|
134
|
-
Person.create do |doc|
|
156
|
+
Person.create! do |doc|
|
135
157
|
doc.posts << post
|
136
158
|
end
|
137
159
|
end
|
138
160
|
|
139
|
-
it "adds the documents to the
|
161
|
+
it "adds the documents to the association" do
|
140
162
|
expect(person.posts).to eq([ post ])
|
141
163
|
end
|
142
164
|
|
143
|
-
it "sets the foreign key on the inverse
|
165
|
+
it "sets the foreign key on the inverse association" do
|
144
166
|
expect(post.person_id).to eq(person.id)
|
145
167
|
end
|
146
168
|
|
@@ -160,7 +182,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
160
182
|
context "when the parent is not a new record" do
|
161
183
|
|
162
184
|
let(:person) do
|
163
|
-
Person.create
|
185
|
+
Person.create!
|
164
186
|
end
|
165
187
|
|
166
188
|
let(:post) do
|
@@ -171,15 +193,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
171
193
|
person.posts.send(method, post)
|
172
194
|
end
|
173
195
|
|
174
|
-
it "sets the foreign key on the
|
196
|
+
it "sets the foreign key on the association" do
|
175
197
|
expect(post.person_id).to eq(person.id)
|
176
198
|
end
|
177
199
|
|
178
|
-
it "sets the base on the inverse
|
200
|
+
it "sets the base on the inverse association" do
|
179
201
|
expect(post.person).to eq(person)
|
180
202
|
end
|
181
203
|
|
182
|
-
it "sets the same instance on the inverse
|
204
|
+
it "sets the same instance on the inverse association" do
|
183
205
|
expect(post.person).to eql(person)
|
184
206
|
end
|
185
207
|
|
@@ -200,16 +222,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
200
222
|
expect(person.changed).to eq([])
|
201
223
|
end
|
202
224
|
|
203
|
-
context "when the related item has embedded
|
225
|
+
context "when the related item has embedded associations" do
|
204
226
|
|
205
227
|
let!(:user) do
|
206
|
-
User.create
|
228
|
+
User.create!
|
207
229
|
end
|
208
230
|
|
209
231
|
before do
|
210
|
-
p = Post.create(roles: [ Role.create ])
|
232
|
+
p = Post.create!(roles: [ Role.create! ])
|
211
233
|
user.posts = [ p ]
|
212
|
-
user.save
|
234
|
+
user.save!
|
213
235
|
end
|
214
236
|
|
215
237
|
it "add the document to the target" do
|
@@ -229,7 +251,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
229
251
|
end
|
230
252
|
end
|
231
253
|
|
232
|
-
context "when documents already exist on the
|
254
|
+
context "when documents already exist on the association" do
|
233
255
|
|
234
256
|
let(:post_two) do
|
235
257
|
Post.new(title: "Test")
|
@@ -239,15 +261,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
239
261
|
person.posts.send(method, post_two)
|
240
262
|
end
|
241
263
|
|
242
|
-
it "sets the foreign key on the
|
264
|
+
it "sets the foreign key on the association" do
|
243
265
|
expect(post_two.person_id).to eq(person.id)
|
244
266
|
end
|
245
267
|
|
246
|
-
it "sets the base on the inverse
|
268
|
+
it "sets the base on the inverse association" do
|
247
269
|
expect(post_two.person).to eq(person)
|
248
270
|
end
|
249
271
|
|
250
|
-
it "sets the same instance on the inverse
|
272
|
+
it "sets the same instance on the inverse association" do
|
251
273
|
expect(post_two.person).to eql(person)
|
252
274
|
end
|
253
275
|
|
@@ -274,10 +296,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
274
296
|
end
|
275
297
|
end
|
276
298
|
|
277
|
-
context "when.adding to the
|
299
|
+
context "when.adding to the association" do
|
278
300
|
|
279
301
|
let(:person) do
|
280
|
-
Person.create
|
302
|
+
Person.create!
|
281
303
|
end
|
282
304
|
|
283
305
|
context "when the operation succeeds" do
|
@@ -290,7 +312,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
290
312
|
person.posts.send(method, post)
|
291
313
|
end
|
292
314
|
|
293
|
-
it "adds the document to the
|
315
|
+
it "adds the document to the association" do
|
294
316
|
expect(person.posts).to eq([ post ])
|
295
317
|
end
|
296
318
|
end
|
@@ -298,7 +320,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
298
320
|
context "when the operation fails" do
|
299
321
|
|
300
322
|
let!(:existing) do
|
301
|
-
Post.create
|
323
|
+
Post.create!
|
302
324
|
end
|
303
325
|
|
304
326
|
let(:post) do
|
@@ -315,7 +337,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
315
337
|
end
|
316
338
|
end
|
317
339
|
|
318
|
-
context "when the
|
340
|
+
context "when the associations are polymorphic" do
|
319
341
|
|
320
342
|
context "when the parent is a new record" do
|
321
343
|
|
@@ -331,11 +353,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
331
353
|
movie.ratings.send(method, rating)
|
332
354
|
end
|
333
355
|
|
334
|
-
it "sets the foreign key on the
|
356
|
+
it "sets the foreign key on the association" do
|
335
357
|
expect(rating.ratable_id).to eq(movie.id)
|
336
358
|
end
|
337
359
|
|
338
|
-
it "sets the base on the inverse
|
360
|
+
it "sets the base on the inverse association" do
|
339
361
|
expect(rating.ratable).to eq(movie)
|
340
362
|
end
|
341
363
|
|
@@ -351,7 +373,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
351
373
|
context "when the parent is not a new record" do
|
352
374
|
|
353
375
|
let(:movie) do
|
354
|
-
Movie.create
|
376
|
+
Movie.create!
|
355
377
|
end
|
356
378
|
|
357
379
|
let(:rating) do
|
@@ -362,11 +384,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
362
384
|
movie.ratings.send(method, rating)
|
363
385
|
end
|
364
386
|
|
365
|
-
it "sets the foreign key on the
|
387
|
+
it "sets the foreign key on the association" do
|
366
388
|
expect(rating.ratable_id).to eq(movie.id)
|
367
389
|
end
|
368
390
|
|
369
|
-
it "sets the base on the inverse
|
391
|
+
it "sets the base on the inverse association" do
|
370
392
|
expect(rating.ratable).to eq(movie)
|
371
393
|
end
|
372
394
|
|
@@ -384,7 +406,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
384
406
|
|
385
407
|
describe "#=" do
|
386
408
|
|
387
|
-
context "when the
|
409
|
+
context "when the association is not polymorphic" do
|
388
410
|
|
389
411
|
context "when the parent is a new record" do
|
390
412
|
|
@@ -400,15 +422,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
400
422
|
person.posts = [ post ]
|
401
423
|
end
|
402
424
|
|
403
|
-
it "sets the target of the
|
425
|
+
it "sets the target of the association" do
|
404
426
|
expect(person.posts._target).to eq([ post ])
|
405
427
|
end
|
406
428
|
|
407
|
-
it "sets the foreign key on the
|
429
|
+
it "sets the foreign key on the association" do
|
408
430
|
expect(post.person_id).to eq(person.id)
|
409
431
|
end
|
410
432
|
|
411
|
-
it "sets the base on the inverse
|
433
|
+
it "sets the base on the inverse association" do
|
412
434
|
expect(post.person).to eq(person)
|
413
435
|
end
|
414
436
|
|
@@ -420,7 +442,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
420
442
|
context "when the parent is not a new record" do
|
421
443
|
|
422
444
|
let(:person) do
|
423
|
-
Person.create
|
445
|
+
Person.create!
|
424
446
|
end
|
425
447
|
|
426
448
|
let(:post) do
|
@@ -431,15 +453,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
431
453
|
person.posts = [ post ]
|
432
454
|
end
|
433
455
|
|
434
|
-
it "sets the target of the
|
456
|
+
it "sets the target of the association" do
|
435
457
|
expect(person.posts._target).to eq([ post ])
|
436
458
|
end
|
437
459
|
|
438
|
-
it "sets the foreign key of the
|
460
|
+
it "sets the foreign key of the association" do
|
439
461
|
expect(post.person_id).to eq(person.id)
|
440
462
|
end
|
441
463
|
|
442
|
-
it "sets the base on the inverse
|
464
|
+
it "sets the base on the inverse association" do
|
443
465
|
expect(post.person).to eq(person)
|
444
466
|
end
|
445
467
|
|
@@ -447,7 +469,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
447
469
|
expect(post).to be_persisted
|
448
470
|
end
|
449
471
|
|
450
|
-
context "when replacing the
|
472
|
+
context "when replacing the association with the same documents" do
|
451
473
|
|
452
474
|
context "when using the same in memory instance" do
|
453
475
|
|
@@ -455,11 +477,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
455
477
|
person.posts = [ post ]
|
456
478
|
end
|
457
479
|
|
458
|
-
it "keeps the
|
480
|
+
it "keeps the association intact" do
|
459
481
|
expect(person.posts).to eq([ post ])
|
460
482
|
end
|
461
483
|
|
462
|
-
it "does not delete the
|
484
|
+
it "does not delete the association" do
|
463
485
|
expect(person.reload.posts).to eq([ post ])
|
464
486
|
end
|
465
487
|
end
|
@@ -474,11 +496,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
474
496
|
from_db.posts = [ post ]
|
475
497
|
end
|
476
498
|
|
477
|
-
it "keeps the
|
499
|
+
it "keeps the association intact" do
|
478
500
|
expect(from_db.posts).to eq([ post ])
|
479
501
|
end
|
480
502
|
|
481
|
-
it "does not delete the
|
503
|
+
it "does not delete the association" do
|
482
504
|
expect(from_db.reload.posts).to eq([ post ])
|
483
505
|
end
|
484
506
|
end
|
@@ -487,7 +509,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
487
509
|
context "when replacing the with a combination of old and new docs" do
|
488
510
|
|
489
511
|
let(:new_post) do
|
490
|
-
Post.create(title: "new post")
|
512
|
+
Post.create!(title: "new post")
|
491
513
|
end
|
492
514
|
|
493
515
|
context "when using the same in memory instance" do
|
@@ -496,7 +518,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
496
518
|
person.posts = [ post, new_post ]
|
497
519
|
end
|
498
520
|
|
499
|
-
it "keeps the
|
521
|
+
it "keeps the association intact" do
|
500
522
|
expect(person.posts.size).to eq(2)
|
501
523
|
end
|
502
524
|
|
@@ -508,7 +530,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
508
530
|
expect(person.posts).to include(new_post)
|
509
531
|
end
|
510
532
|
|
511
|
-
it "does not delete the
|
533
|
+
it "does not delete the association" do
|
512
534
|
expect(person.reload.posts).to eq([ post, new_post ])
|
513
535
|
end
|
514
536
|
end
|
@@ -523,11 +545,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
523
545
|
from_db.posts = [ post, new_post ]
|
524
546
|
end
|
525
547
|
|
526
|
-
it "keeps the
|
548
|
+
it "keeps the association intact" do
|
527
549
|
expect(from_db.posts).to eq([ post, new_post ])
|
528
550
|
end
|
529
551
|
|
530
|
-
it "does not delete the
|
552
|
+
it "does not delete the association" do
|
531
553
|
expect(from_db.reload.posts).to eq([ post, new_post ])
|
532
554
|
end
|
533
555
|
end
|
@@ -536,7 +558,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
536
558
|
context "when replacing the with a combination of only new docs" do
|
537
559
|
|
538
560
|
let(:new_post) do
|
539
|
-
Post.create(title: "new post")
|
561
|
+
Post.create!(title: "new post")
|
540
562
|
end
|
541
563
|
|
542
564
|
context "when using the same in memory instance" do
|
@@ -545,11 +567,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
545
567
|
person.posts = [ new_post ]
|
546
568
|
end
|
547
569
|
|
548
|
-
it "keeps the
|
570
|
+
it "keeps the association intact" do
|
549
571
|
expect(person.posts).to eq([ new_post ])
|
550
572
|
end
|
551
573
|
|
552
|
-
it "does not delete the
|
574
|
+
it "does not delete the association" do
|
553
575
|
expect(person.reload.posts).to eq([ new_post ])
|
554
576
|
end
|
555
577
|
end
|
@@ -564,11 +586,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
564
586
|
from_db.posts = [ new_post ]
|
565
587
|
end
|
566
588
|
|
567
|
-
it "keeps the
|
589
|
+
it "keeps the association intact" do
|
568
590
|
expect(from_db.posts).to eq([ new_post ])
|
569
591
|
end
|
570
592
|
|
571
|
-
it "does not delete the
|
593
|
+
it "does not delete the association" do
|
572
594
|
expect(from_db.reload.posts).to eq([ new_post ])
|
573
595
|
end
|
574
596
|
end
|
@@ -576,7 +598,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
576
598
|
end
|
577
599
|
end
|
578
600
|
|
579
|
-
context "when the
|
601
|
+
context "when the association is polymorphic" do
|
580
602
|
|
581
603
|
context "when the parent is a new record" do
|
582
604
|
|
@@ -592,15 +614,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
592
614
|
movie.ratings = [ rating ]
|
593
615
|
end
|
594
616
|
|
595
|
-
it "sets the target of the
|
617
|
+
it "sets the target of the association" do
|
596
618
|
expect(movie.ratings._target).to eq([ rating ])
|
597
619
|
end
|
598
620
|
|
599
|
-
it "sets the foreign key on the
|
621
|
+
it "sets the foreign key on the association" do
|
600
622
|
expect(rating.ratable_id).to eq(movie.id)
|
601
623
|
end
|
602
624
|
|
603
|
-
it "sets the base on the inverse
|
625
|
+
it "sets the base on the inverse association" do
|
604
626
|
expect(rating.ratable).to eq(movie)
|
605
627
|
end
|
606
628
|
|
@@ -612,7 +634,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
612
634
|
context "when the parent is not a new record" do
|
613
635
|
|
614
636
|
let(:movie) do
|
615
|
-
Movie.create
|
637
|
+
Movie.create!
|
616
638
|
end
|
617
639
|
|
618
640
|
let(:rating) do
|
@@ -623,15 +645,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
623
645
|
movie.ratings = [ rating ]
|
624
646
|
end
|
625
647
|
|
626
|
-
it "sets the target of the
|
648
|
+
it "sets the target of the association" do
|
627
649
|
expect(movie.ratings._target).to eq([ rating ])
|
628
650
|
end
|
629
651
|
|
630
|
-
it "sets the foreign key of the
|
652
|
+
it "sets the foreign key of the association" do
|
631
653
|
expect(rating.ratable_id).to eq(movie.id)
|
632
654
|
end
|
633
655
|
|
634
|
-
it "sets the base on the inverse
|
656
|
+
it "sets the base on the inverse association" do
|
635
657
|
expect(rating.ratable).to eq(movie)
|
636
658
|
end
|
637
659
|
|
@@ -647,11 +669,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
647
669
|
context "when the parent is persisted" do
|
648
670
|
|
649
671
|
let(:posts) do
|
650
|
-
[ Post.create(title: "1"), Post.create(title: "2") ]
|
672
|
+
[ Post.create!(title: "1"), Post.create!(title: "2") ]
|
651
673
|
end
|
652
674
|
|
653
675
|
let(:person) do
|
654
|
-
Person.create(posts: posts)
|
676
|
+
Person.create!(posts: posts)
|
655
677
|
end
|
656
678
|
|
657
679
|
context "when the parent has multiple children" do
|
@@ -673,7 +695,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
673
695
|
|
674
696
|
describe "#= nil" do
|
675
697
|
|
676
|
-
context "when the
|
698
|
+
context "when the association is not polymorphic" do
|
677
699
|
|
678
700
|
context "when the parent is a new record" do
|
679
701
|
|
@@ -690,11 +712,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
690
712
|
person.posts = nil
|
691
713
|
end
|
692
714
|
|
693
|
-
it "sets the
|
715
|
+
it "sets the association to an empty array" do
|
694
716
|
expect(person.posts).to be_empty
|
695
717
|
end
|
696
718
|
|
697
|
-
it "removed the inverse
|
719
|
+
it "removed the inverse association" do
|
698
720
|
expect(post.person).to be_nil
|
699
721
|
end
|
700
722
|
|
@@ -706,7 +728,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
706
728
|
context "when the parent is not a new record" do
|
707
729
|
|
708
730
|
let(:person) do
|
709
|
-
Person.create
|
731
|
+
Person.create!
|
710
732
|
end
|
711
733
|
|
712
734
|
context "when dependent is destructive" do
|
@@ -720,11 +742,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
720
742
|
person.posts = nil
|
721
743
|
end
|
722
744
|
|
723
|
-
it "sets the
|
745
|
+
it "sets the association to empty" do
|
724
746
|
expect(person.posts).to be_empty
|
725
747
|
end
|
726
748
|
|
727
|
-
it "removed the inverse
|
749
|
+
it "removed the inverse association" do
|
728
750
|
expect(post.person).to be_nil
|
729
751
|
end
|
730
752
|
|
@@ -748,11 +770,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
748
770
|
person.drugs = nil
|
749
771
|
end
|
750
772
|
|
751
|
-
it "sets the
|
773
|
+
it "sets the association to empty" do
|
752
774
|
expect(person.drugs).to be_empty
|
753
775
|
end
|
754
776
|
|
755
|
-
it "removed the inverse
|
777
|
+
it "removed the inverse association" do
|
756
778
|
expect(drug.person).to be_nil
|
757
779
|
end
|
758
780
|
|
@@ -760,14 +782,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
760
782
|
expect(drug.person_id).to be_nil
|
761
783
|
end
|
762
784
|
|
763
|
-
it "nullifies the
|
785
|
+
it "nullifies the association" do
|
764
786
|
expect(drug).to_not be_destroyed
|
765
787
|
end
|
766
788
|
end
|
767
789
|
end
|
768
790
|
end
|
769
791
|
|
770
|
-
context "when the
|
792
|
+
context "when the association is polymorphic" do
|
771
793
|
|
772
794
|
context "when the parent is a new record" do
|
773
795
|
|
@@ -784,11 +806,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
784
806
|
movie.ratings = nil
|
785
807
|
end
|
786
808
|
|
787
|
-
it "sets the
|
809
|
+
it "sets the association to an empty array" do
|
788
810
|
expect(movie.ratings).to be_empty
|
789
811
|
end
|
790
812
|
|
791
|
-
it "removed the inverse
|
813
|
+
it "removed the inverse association" do
|
792
814
|
expect(rating.ratable).to be_nil
|
793
815
|
end
|
794
816
|
|
@@ -800,7 +822,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
800
822
|
context "when the parent is not a new record" do
|
801
823
|
|
802
824
|
let(:movie) do
|
803
|
-
Movie.create
|
825
|
+
Movie.create!
|
804
826
|
end
|
805
827
|
|
806
828
|
let(:rating) do
|
@@ -812,11 +834,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
812
834
|
movie.ratings = nil
|
813
835
|
end
|
814
836
|
|
815
|
-
it "sets the
|
837
|
+
it "sets the association to empty" do
|
816
838
|
expect(movie.ratings).to be_empty
|
817
839
|
end
|
818
840
|
|
819
|
-
it "removed the inverse
|
841
|
+
it "removed the inverse association" do
|
820
842
|
expect(rating.ratable).to be_nil
|
821
843
|
end
|
822
844
|
|
@@ -841,11 +863,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
841
863
|
end
|
842
864
|
|
843
865
|
let(:post_one) do
|
844
|
-
Post.create
|
866
|
+
Post.create!
|
845
867
|
end
|
846
868
|
|
847
869
|
let(:post_two) do
|
848
|
-
Post.create
|
870
|
+
Post.create!
|
849
871
|
end
|
850
872
|
|
851
873
|
before do
|
@@ -860,14 +882,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
860
882
|
describe "#\{name}_ids" do
|
861
883
|
|
862
884
|
let(:posts) do
|
863
|
-
[ Post.create
|
885
|
+
[ Post.create!, Post.create! ]
|
864
886
|
end
|
865
887
|
|
866
888
|
let(:person) do
|
867
|
-
Person.create(posts: posts)
|
889
|
+
Person.create!(posts: posts)
|
868
890
|
end
|
869
891
|
|
870
|
-
it "returns ids of documents that are in the
|
892
|
+
it "returns ids of documents that are in the association" do
|
871
893
|
expect(person.post_ids).to eq(posts.map(&:id))
|
872
894
|
end
|
873
895
|
end
|
@@ -875,8 +897,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
875
897
|
[ :build, :new ].each do |method|
|
876
898
|
|
877
899
|
describe "##{method}" do
|
900
|
+
context 'when model has #initialize' do
|
901
|
+
let(:parent) { RefHasManySpec::OverrideInitialize::Parent.create }
|
902
|
+
let(:child) { parent.children.send(method) }
|
903
|
+
|
904
|
+
it 'should call #initialize' do
|
905
|
+
expect(child.name).to be == "default"
|
906
|
+
end
|
907
|
+
end
|
878
908
|
|
879
|
-
context "when the
|
909
|
+
context "when the association is not polymorphic" do
|
880
910
|
|
881
911
|
context "when the parent is a new record" do
|
882
912
|
|
@@ -888,11 +918,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
888
918
|
person.posts.send(method, title: "$$$")
|
889
919
|
end
|
890
920
|
|
891
|
-
it "sets the foreign key on the
|
921
|
+
it "sets the foreign key on the association" do
|
892
922
|
expect(post.person_id).to eq(person.id)
|
893
923
|
end
|
894
924
|
|
895
|
-
it "sets the base on the inverse
|
925
|
+
it "sets the base on the inverse association" do
|
896
926
|
expect(post.person).to eq(person)
|
897
927
|
end
|
898
928
|
|
@@ -920,18 +950,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
920
950
|
context "when the parent is not a new record" do
|
921
951
|
|
922
952
|
let(:person) do
|
923
|
-
Person.create
|
953
|
+
Person.create!
|
924
954
|
end
|
925
955
|
|
926
956
|
let!(:post) do
|
927
957
|
person.posts.send(method, text: "Testing")
|
928
958
|
end
|
929
959
|
|
930
|
-
it "sets the foreign key on the
|
960
|
+
it "sets the foreign key on the association" do
|
931
961
|
expect(post.person_id).to eq(person.id)
|
932
962
|
end
|
933
963
|
|
934
|
-
it "sets the base on the inverse
|
964
|
+
it "sets the base on the inverse association" do
|
935
965
|
expect(post.person).to eq(person)
|
936
966
|
end
|
937
967
|
|
@@ -949,12 +979,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
949
979
|
end
|
950
980
|
end
|
951
981
|
|
952
|
-
context "when the
|
982
|
+
context "when the association is polymorphic" do
|
953
983
|
|
954
984
|
context "when the parent is a subclass" do
|
955
985
|
|
956
986
|
let(:video_game) do
|
957
|
-
VideoGame.create
|
987
|
+
VideoGame.create!
|
958
988
|
end
|
959
989
|
|
960
990
|
let(:rating) do
|
@@ -980,11 +1010,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
980
1010
|
movie.ratings.send(method, value: 3)
|
981
1011
|
end
|
982
1012
|
|
983
|
-
it "sets the foreign key on the
|
1013
|
+
it "sets the foreign key on the association" do
|
984
1014
|
expect(rating.ratable_id).to eq(movie.id)
|
985
1015
|
end
|
986
1016
|
|
987
|
-
it "sets the base on the inverse
|
1017
|
+
it "sets the base on the inverse association" do
|
988
1018
|
expect(rating.ratable).to eq(movie)
|
989
1019
|
end
|
990
1020
|
|
@@ -1008,18 +1038,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1008
1038
|
context "when the parent is not a new record" do
|
1009
1039
|
|
1010
1040
|
let(:movie) do
|
1011
|
-
Movie.create
|
1041
|
+
Movie.create!
|
1012
1042
|
end
|
1013
1043
|
|
1014
1044
|
let!(:rating) do
|
1015
1045
|
movie.ratings.send(method, value: 4)
|
1016
1046
|
end
|
1017
1047
|
|
1018
|
-
it "sets the foreign key on the
|
1048
|
+
it "sets the foreign key on the association" do
|
1019
1049
|
expect(rating.ratable_id).to eq(movie.id)
|
1020
1050
|
end
|
1021
1051
|
|
1022
|
-
it "sets the base on the inverse
|
1052
|
+
it "sets the base on the inverse association" do
|
1023
1053
|
expect(rating.ratable).to eq(movie)
|
1024
1054
|
end
|
1025
1055
|
|
@@ -1041,25 +1071,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1041
1071
|
|
1042
1072
|
describe "#clear" do
|
1043
1073
|
|
1044
|
-
context "when the
|
1074
|
+
context "when the association is not polymorphic" do
|
1045
1075
|
|
1046
1076
|
context "when the parent has been persisted" do
|
1047
1077
|
|
1048
1078
|
let!(:person) do
|
1049
|
-
Person.create
|
1079
|
+
Person.create!
|
1050
1080
|
end
|
1051
1081
|
|
1052
1082
|
context "when the children are persisted" do
|
1053
1083
|
|
1054
1084
|
let!(:post) do
|
1055
|
-
person.posts.create(title: "Testing")
|
1085
|
+
person.posts.create!(title: "Testing")
|
1056
1086
|
end
|
1057
1087
|
|
1058
|
-
let!(:
|
1088
|
+
let!(:association) do
|
1059
1089
|
person.posts.clear
|
1060
1090
|
end
|
1061
1091
|
|
1062
|
-
it "clears out the
|
1092
|
+
it "clears out the association" do
|
1063
1093
|
expect(person.posts).to be_empty
|
1064
1094
|
end
|
1065
1095
|
|
@@ -1071,8 +1101,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1071
1101
|
expect(person.reload.posts).to be_empty
|
1072
1102
|
end
|
1073
1103
|
|
1074
|
-
it "returns the
|
1075
|
-
expect(
|
1104
|
+
it "returns the association" do
|
1105
|
+
expect(association).to be_empty
|
1076
1106
|
end
|
1077
1107
|
end
|
1078
1108
|
|
@@ -1082,11 +1112,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1082
1112
|
person.posts.build(title: "Testing")
|
1083
1113
|
end
|
1084
1114
|
|
1085
|
-
let!(:
|
1115
|
+
let!(:association) do
|
1086
1116
|
person.posts.clear
|
1087
1117
|
end
|
1088
1118
|
|
1089
|
-
it "clears out the
|
1119
|
+
it "clears out the association" do
|
1090
1120
|
expect(person.posts).to be_empty
|
1091
1121
|
end
|
1092
1122
|
end
|
@@ -1102,35 +1132,35 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1102
1132
|
person.posts.build(title: "Testing")
|
1103
1133
|
end
|
1104
1134
|
|
1105
|
-
let!(:
|
1135
|
+
let!(:association) do
|
1106
1136
|
person.posts.clear
|
1107
1137
|
end
|
1108
1138
|
|
1109
|
-
it "clears out the
|
1139
|
+
it "clears out the association" do
|
1110
1140
|
expect(person.posts).to be_empty
|
1111
1141
|
end
|
1112
1142
|
end
|
1113
1143
|
end
|
1114
1144
|
|
1115
|
-
context "when the
|
1145
|
+
context "when the association is polymorphic" do
|
1116
1146
|
|
1117
1147
|
context "when the parent has been persisted" do
|
1118
1148
|
|
1119
1149
|
let!(:movie) do
|
1120
|
-
Movie.create
|
1150
|
+
Movie.create!
|
1121
1151
|
end
|
1122
1152
|
|
1123
1153
|
context "when the children are persisted" do
|
1124
1154
|
|
1125
1155
|
let!(:rating) do
|
1126
|
-
movie.ratings.create(value: 1)
|
1156
|
+
movie.ratings.create!(value: 1)
|
1127
1157
|
end
|
1128
1158
|
|
1129
|
-
let!(:
|
1159
|
+
let!(:association) do
|
1130
1160
|
movie.ratings.clear
|
1131
1161
|
end
|
1132
1162
|
|
1133
|
-
it "clears out the
|
1163
|
+
it "clears out the association" do
|
1134
1164
|
expect(movie.ratings).to be_empty
|
1135
1165
|
end
|
1136
1166
|
|
@@ -1142,8 +1172,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1142
1172
|
expect(movie.reload.ratings).to be_empty
|
1143
1173
|
end
|
1144
1174
|
|
1145
|
-
it "returns the
|
1146
|
-
expect(
|
1175
|
+
it "returns the association" do
|
1176
|
+
expect(association).to be_empty
|
1147
1177
|
end
|
1148
1178
|
end
|
1149
1179
|
|
@@ -1153,11 +1183,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1153
1183
|
movie.ratings.build(value: 3)
|
1154
1184
|
end
|
1155
1185
|
|
1156
|
-
let!(:
|
1186
|
+
let!(:association) do
|
1157
1187
|
movie.ratings.clear
|
1158
1188
|
end
|
1159
1189
|
|
1160
|
-
it "clears out the
|
1190
|
+
it "clears out the association" do
|
1161
1191
|
expect(movie.ratings).to be_empty
|
1162
1192
|
end
|
1163
1193
|
end
|
@@ -1173,11 +1203,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1173
1203
|
movie.ratings.build(value: 2)
|
1174
1204
|
end
|
1175
1205
|
|
1176
|
-
let!(:
|
1206
|
+
let!(:association) do
|
1177
1207
|
movie.ratings.clear
|
1178
1208
|
end
|
1179
1209
|
|
1180
|
-
it "clears out the
|
1210
|
+
it "clears out the association" do
|
1181
1211
|
expect(movie.ratings).to be_empty
|
1182
1212
|
end
|
1183
1213
|
end
|
@@ -1186,7 +1216,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1186
1216
|
|
1187
1217
|
describe "#concat" do
|
1188
1218
|
|
1189
|
-
context "when the
|
1219
|
+
context "when the associations are not polymorphic" do
|
1190
1220
|
|
1191
1221
|
context "when the parent is a new record" do
|
1192
1222
|
|
@@ -1202,15 +1232,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1202
1232
|
person.posts.concat([ post ])
|
1203
1233
|
end
|
1204
1234
|
|
1205
|
-
it "sets the foreign key on the
|
1235
|
+
it "sets the foreign key on the association" do
|
1206
1236
|
expect(post.person_id).to eq(person.id)
|
1207
1237
|
end
|
1208
1238
|
|
1209
|
-
it "sets the base on the inverse
|
1239
|
+
it "sets the base on the inverse association" do
|
1210
1240
|
expect(post.person).to eq(person)
|
1211
1241
|
end
|
1212
1242
|
|
1213
|
-
it "sets the same instance on the inverse
|
1243
|
+
it "sets the same instance on the inverse association" do
|
1214
1244
|
expect(post.person).to eql(person)
|
1215
1245
|
end
|
1216
1246
|
|
@@ -1226,20 +1256,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1226
1256
|
context "when appending in a parent create block" do
|
1227
1257
|
|
1228
1258
|
let!(:post) do
|
1229
|
-
Post.create(title: "testing")
|
1259
|
+
Post.create!(title: "testing")
|
1230
1260
|
end
|
1231
1261
|
|
1232
1262
|
let!(:person) do
|
1233
|
-
Person.create do |doc|
|
1263
|
+
Person.create! do |doc|
|
1234
1264
|
doc.posts.concat([ post ])
|
1235
1265
|
end
|
1236
1266
|
end
|
1237
1267
|
|
1238
|
-
it "adds the documents to the
|
1268
|
+
it "adds the documents to the association" do
|
1239
1269
|
expect(person.posts).to eq([ post ])
|
1240
1270
|
end
|
1241
1271
|
|
1242
|
-
it "sets the foreign key on the inverse
|
1272
|
+
it "sets the foreign key on the inverse association" do
|
1243
1273
|
expect(post.person_id).to eq(person.id)
|
1244
1274
|
end
|
1245
1275
|
|
@@ -1259,7 +1289,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1259
1289
|
context "when the parent is not a new record" do
|
1260
1290
|
|
1261
1291
|
let(:person) do
|
1262
|
-
Person.create
|
1292
|
+
Person.create!
|
1263
1293
|
end
|
1264
1294
|
|
1265
1295
|
let(:post) do
|
@@ -1274,15 +1304,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1274
1304
|
person.posts.concat([ post, post_three ])
|
1275
1305
|
end
|
1276
1306
|
|
1277
|
-
it "sets the foreign key on the
|
1307
|
+
it "sets the foreign key on the association" do
|
1278
1308
|
expect(post.person_id).to eq(person.id)
|
1279
1309
|
end
|
1280
1310
|
|
1281
|
-
it "sets the base on the inverse
|
1311
|
+
it "sets the base on the inverse association" do
|
1282
1312
|
expect(post.person).to eq(person)
|
1283
1313
|
end
|
1284
1314
|
|
1285
|
-
it "sets the same instance on the inverse
|
1315
|
+
it "sets the same instance on the inverse association" do
|
1286
1316
|
expect(post.person).to eql(person)
|
1287
1317
|
end
|
1288
1318
|
|
@@ -1294,7 +1324,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1294
1324
|
expect(person.posts.count).to eq(2)
|
1295
1325
|
end
|
1296
1326
|
|
1297
|
-
context "when documents already exist on the
|
1327
|
+
context "when documents already exist on the association" do
|
1298
1328
|
|
1299
1329
|
let(:post_two) do
|
1300
1330
|
Post.new(title: "Test")
|
@@ -1304,15 +1334,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1304
1334
|
person.posts.concat([ post_two ])
|
1305
1335
|
end
|
1306
1336
|
|
1307
|
-
it "sets the foreign key on the
|
1337
|
+
it "sets the foreign key on the association" do
|
1308
1338
|
expect(post_two.person_id).to eq(person.id)
|
1309
1339
|
end
|
1310
1340
|
|
1311
|
-
it "sets the base on the inverse
|
1341
|
+
it "sets the base on the inverse association" do
|
1312
1342
|
expect(post_two.person).to eq(person)
|
1313
1343
|
end
|
1314
1344
|
|
1315
|
-
it "sets the same instance on the inverse
|
1345
|
+
it "sets the same instance on the inverse association" do
|
1316
1346
|
expect(post_two.person).to eql(person)
|
1317
1347
|
end
|
1318
1348
|
|
@@ -1336,7 +1366,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1336
1366
|
end
|
1337
1367
|
end
|
1338
1368
|
|
1339
|
-
context "when the
|
1369
|
+
context "when the associations are polymorphic" do
|
1340
1370
|
|
1341
1371
|
context "when the parent is a new record" do
|
1342
1372
|
|
@@ -1352,11 +1382,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1352
1382
|
movie.ratings.concat([ rating ])
|
1353
1383
|
end
|
1354
1384
|
|
1355
|
-
it "sets the foreign key on the
|
1385
|
+
it "sets the foreign key on the association" do
|
1356
1386
|
expect(rating.ratable_id).to eq(movie.id)
|
1357
1387
|
end
|
1358
1388
|
|
1359
|
-
it "sets the base on the inverse
|
1389
|
+
it "sets the base on the inverse association" do
|
1360
1390
|
expect(rating.ratable).to eq(movie)
|
1361
1391
|
end
|
1362
1392
|
|
@@ -1372,7 +1402,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1372
1402
|
context "when the parent is not a new record" do
|
1373
1403
|
|
1374
1404
|
let(:movie) do
|
1375
|
-
Movie.create
|
1405
|
+
Movie.create!
|
1376
1406
|
end
|
1377
1407
|
|
1378
1408
|
let(:rating) do
|
@@ -1383,11 +1413,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1383
1413
|
movie.ratings.concat([ rating ])
|
1384
1414
|
end
|
1385
1415
|
|
1386
|
-
it "sets the foreign key on the
|
1416
|
+
it "sets the foreign key on the association" do
|
1387
1417
|
expect(rating.ratable_id).to eq(movie.id)
|
1388
1418
|
end
|
1389
1419
|
|
1390
|
-
it "sets the base on the inverse
|
1420
|
+
it "sets the base on the inverse association" do
|
1391
1421
|
expect(rating.ratable).to eq(movie)
|
1392
1422
|
end
|
1393
1423
|
|
@@ -1404,18 +1434,23 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1404
1434
|
describe "#count" do
|
1405
1435
|
|
1406
1436
|
let(:movie) do
|
1407
|
-
Movie.create
|
1437
|
+
Movie.create!
|
1408
1438
|
end
|
1409
1439
|
|
1410
1440
|
context "when documents have been persisted" do
|
1411
1441
|
|
1412
1442
|
let!(:rating) do
|
1413
|
-
movie.ratings.create(value: 1)
|
1443
|
+
movie.ratings.create!(value: 1)
|
1414
1444
|
end
|
1415
1445
|
|
1416
1446
|
it "returns the number of persisted documents" do
|
1417
1447
|
expect(movie.ratings.count).to eq(1)
|
1418
1448
|
end
|
1449
|
+
|
1450
|
+
it "block form includes persisted results" do
|
1451
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
1452
|
+
expect(movie.ratings.count {|r| r.value >= 2 }).to eq(0)
|
1453
|
+
end
|
1419
1454
|
end
|
1420
1455
|
|
1421
1456
|
context "when documents have not been persisted" do
|
@@ -1427,14 +1462,42 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1427
1462
|
it "returns 0" do
|
1428
1463
|
expect(movie.ratings.count).to eq(0)
|
1429
1464
|
end
|
1465
|
+
|
1466
|
+
it "block form does not include unpersisted results" do
|
1467
|
+
expect(movie.ratings.count {|r| r.value == 1 }).to eq(0)
|
1468
|
+
end
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
context "when mixed persisted and unpersisted documents" do
|
1472
|
+
|
1473
|
+
before do
|
1474
|
+
movie.ratings.create(value: 1)
|
1475
|
+
movie.ratings.build(value: 2)
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
it "returns 1" do
|
1479
|
+
expect(movie.ratings.count).to eq(1)
|
1480
|
+
end
|
1481
|
+
|
1482
|
+
it "block form includes only persisted results" do
|
1483
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
1484
|
+
expect(movie.ratings.count {|r| r.value == 2 }).to eq(0)
|
1485
|
+
end
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
context "when no document is added" do
|
1489
|
+
|
1490
|
+
it "returns false" do
|
1491
|
+
expect(movie.ratings.any?).to be false
|
1492
|
+
end
|
1430
1493
|
end
|
1431
1494
|
|
1432
1495
|
context "when new documents exist in the database" do
|
1433
1496
|
|
1434
|
-
context "when the documents are part of the
|
1497
|
+
context "when the documents are part of the association" do
|
1435
1498
|
|
1436
1499
|
before do
|
1437
|
-
Rating.create(ratable: movie)
|
1500
|
+
Rating.create!(ratable: movie)
|
1438
1501
|
end
|
1439
1502
|
|
1440
1503
|
it "returns the count from the db" do
|
@@ -1442,10 +1505,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1442
1505
|
end
|
1443
1506
|
end
|
1444
1507
|
|
1445
|
-
context "when the documents are not part of the
|
1508
|
+
context "when the documents are not part of the association" do
|
1446
1509
|
|
1447
1510
|
before do
|
1448
|
-
Rating.create
|
1511
|
+
Rating.create!
|
1449
1512
|
end
|
1450
1513
|
|
1451
1514
|
it "returns the count from the db" do
|
@@ -1455,16 +1518,198 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1455
1518
|
end
|
1456
1519
|
end
|
1457
1520
|
|
1521
|
+
describe "#any?" do
|
1522
|
+
|
1523
|
+
shared_examples 'does not query database when association is loaded' do
|
1524
|
+
|
1525
|
+
let(:fresh_movie) { Movie.find(movie.id) }
|
1526
|
+
|
1527
|
+
context 'when association is not loaded' do
|
1528
|
+
it 'queries database on each call' do
|
1529
|
+
fresh_movie
|
1530
|
+
|
1531
|
+
expect_query(1) do
|
1532
|
+
fresh_movie.ratings.any?.should be expected_result
|
1533
|
+
end
|
1534
|
+
|
1535
|
+
expect_query(1) do
|
1536
|
+
fresh_movie.ratings.any?.should be expected_result
|
1537
|
+
end
|
1538
|
+
end
|
1539
|
+
|
1540
|
+
context 'when using a block' do
|
1541
|
+
it 'queries database on first call only' do
|
1542
|
+
fresh_movie
|
1543
|
+
|
1544
|
+
expect_query(1) do
|
1545
|
+
fresh_movie.ratings.any? { false }.should be false
|
1546
|
+
end
|
1547
|
+
|
1548
|
+
expect_no_queries do
|
1549
|
+
fresh_movie.ratings.any? { false }.should be false
|
1550
|
+
end
|
1551
|
+
end
|
1552
|
+
end
|
1553
|
+
end
|
1554
|
+
|
1555
|
+
context 'when association is loaded' do
|
1556
|
+
it 'does not query database' do
|
1557
|
+
fresh_movie
|
1558
|
+
|
1559
|
+
expect_query(1) do
|
1560
|
+
fresh_movie.ratings.any?.should be expected_result
|
1561
|
+
end
|
1562
|
+
|
1563
|
+
fresh_movie.ratings.to_a
|
1564
|
+
|
1565
|
+
expect_no_queries do
|
1566
|
+
fresh_movie.ratings.any?.should be expected_result
|
1567
|
+
end
|
1568
|
+
end
|
1569
|
+
end
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
let(:movie) do
|
1573
|
+
Movie.create!
|
1574
|
+
end
|
1575
|
+
|
1576
|
+
context "when nothing exists on the association" do
|
1577
|
+
|
1578
|
+
context "when no document is added" do
|
1579
|
+
|
1580
|
+
let!(:movie) do
|
1581
|
+
Movie.create!
|
1582
|
+
end
|
1583
|
+
|
1584
|
+
it "returns false" do
|
1585
|
+
expect(movie.ratings.any?).to be false
|
1586
|
+
end
|
1587
|
+
|
1588
|
+
let(:expected_result) { false }
|
1589
|
+
include_examples 'does not query database when association is loaded'
|
1590
|
+
end
|
1591
|
+
|
1592
|
+
context "when the document is destroyed" do
|
1593
|
+
|
1594
|
+
before do
|
1595
|
+
Rating.create!
|
1596
|
+
end
|
1597
|
+
|
1598
|
+
let!(:movie) do
|
1599
|
+
Movie.create!
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
it "returns false" do
|
1603
|
+
movie.destroy
|
1604
|
+
expect(movie.ratings.any?).to be false
|
1605
|
+
end
|
1606
|
+
end
|
1607
|
+
end
|
1608
|
+
|
1609
|
+
context "when appending to a association and _loaded/_unloaded are empty" do
|
1610
|
+
|
1611
|
+
let!(:movie) do
|
1612
|
+
Movie.create!
|
1613
|
+
end
|
1614
|
+
|
1615
|
+
before do
|
1616
|
+
movie.ratings << Rating.new
|
1617
|
+
end
|
1618
|
+
|
1619
|
+
it "returns true" do
|
1620
|
+
expect(movie.ratings.any?).to be true
|
1621
|
+
end
|
1622
|
+
|
1623
|
+
context 'when association is not loaded' do
|
1624
|
+
before do
|
1625
|
+
movie.ratings._loaded?.should be false
|
1626
|
+
end
|
1627
|
+
|
1628
|
+
it 'does not query the database because it knows about the added models' do
|
1629
|
+
expect_no_queries do
|
1630
|
+
movie.ratings.any?.should be true
|
1631
|
+
end
|
1632
|
+
end
|
1633
|
+
end
|
1634
|
+
|
1635
|
+
context 'when association is loaded' do
|
1636
|
+
it 'does not query database' do
|
1637
|
+
expect_no_queries do
|
1638
|
+
movie.ratings.any?.should be true
|
1639
|
+
end
|
1640
|
+
|
1641
|
+
movie.ratings.to_a
|
1642
|
+
|
1643
|
+
expect_no_queries do
|
1644
|
+
movie.ratings.any?.should be true
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
end
|
1648
|
+
end
|
1649
|
+
|
1650
|
+
context "when appending to a association in a transaction" do
|
1651
|
+
require_transaction_support
|
1652
|
+
|
1653
|
+
let!(:movie) do
|
1654
|
+
Movie.create!
|
1655
|
+
end
|
1656
|
+
|
1657
|
+
it "returns true" do
|
1658
|
+
movie.with_session do |session|
|
1659
|
+
session.with_transaction do
|
1660
|
+
expect{ movie.ratings << Rating.new }.to_not raise_error
|
1661
|
+
expect(movie.ratings.any?).to be true
|
1662
|
+
end
|
1663
|
+
end
|
1664
|
+
end
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
context "when documents have been persisted" do
|
1668
|
+
|
1669
|
+
let!(:rating) do
|
1670
|
+
movie.ratings.create!(value: 1)
|
1671
|
+
end
|
1672
|
+
|
1673
|
+
it "returns true" do
|
1674
|
+
expect(movie.ratings.any?).to be true
|
1675
|
+
end
|
1676
|
+
|
1677
|
+
let(:expected_result) { true }
|
1678
|
+
include_examples 'does not query database when association is loaded'
|
1679
|
+
end
|
1680
|
+
|
1681
|
+
context "when documents have not been persisted" do
|
1682
|
+
|
1683
|
+
let!(:rating) do
|
1684
|
+
movie.ratings.build(value: 1)
|
1685
|
+
end
|
1686
|
+
|
1687
|
+
it "returns false" do
|
1688
|
+
expect(movie.ratings.any?).to be true
|
1689
|
+
end
|
1690
|
+
end
|
1691
|
+
|
1692
|
+
context "when new documents exist in the database" do
|
1693
|
+
before do
|
1694
|
+
Rating.create!(ratable: movie)
|
1695
|
+
end
|
1696
|
+
|
1697
|
+
it "returns true" do
|
1698
|
+
expect(movie.ratings.any?).to be true
|
1699
|
+
end
|
1700
|
+
end
|
1701
|
+
end
|
1702
|
+
|
1458
1703
|
describe "#create" do
|
1459
1704
|
|
1460
1705
|
context "when providing multiple attributes" do
|
1461
1706
|
|
1462
1707
|
let(:person) do
|
1463
|
-
Person.create
|
1708
|
+
Person.create!
|
1464
1709
|
end
|
1465
1710
|
|
1466
1711
|
let!(:posts) do
|
1467
|
-
person.posts.create([{ text: "Test1" }, { text: "Test2" }])
|
1712
|
+
person.posts.create!([{ text: "Test1" }, { text: "Test2" }])
|
1468
1713
|
end
|
1469
1714
|
|
1470
1715
|
it "creates multiple documents" do
|
@@ -1484,7 +1729,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1484
1729
|
end
|
1485
1730
|
end
|
1486
1731
|
|
1487
|
-
context "when the
|
1732
|
+
context "when the association is not polymorphic" do
|
1488
1733
|
|
1489
1734
|
context "when the parent is a new record" do
|
1490
1735
|
|
@@ -1493,7 +1738,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1493
1738
|
end
|
1494
1739
|
|
1495
1740
|
let(:post) do
|
1496
|
-
person.posts.create(text: "Testing")
|
1741
|
+
person.posts.create!(text: "Testing")
|
1497
1742
|
end
|
1498
1743
|
|
1499
1744
|
it "raises an unsaved document error" do
|
@@ -1506,11 +1751,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1506
1751
|
context "when the operation is successful" do
|
1507
1752
|
|
1508
1753
|
let(:person) do
|
1509
|
-
Person.create
|
1754
|
+
Person.create!
|
1510
1755
|
end
|
1511
1756
|
|
1512
1757
|
let!(:post) do
|
1513
|
-
person.posts.create(text: "Testing")
|
1758
|
+
person.posts.create!(text: "Testing")
|
1514
1759
|
end
|
1515
1760
|
|
1516
1761
|
it "creates the document" do
|
@@ -1521,16 +1766,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1521
1766
|
context "when the operation fails" do
|
1522
1767
|
|
1523
1768
|
let(:person) do
|
1524
|
-
Person.create
|
1769
|
+
Person.create!
|
1525
1770
|
end
|
1526
1771
|
|
1527
1772
|
let!(:existing) do
|
1528
|
-
Post.create
|
1773
|
+
Post.create!
|
1529
1774
|
end
|
1530
1775
|
|
1531
1776
|
it "raises an error" do
|
1532
1777
|
expect {
|
1533
|
-
person.posts.create do |doc|
|
1778
|
+
person.posts.create! do |doc|
|
1534
1779
|
doc._id = existing.id
|
1535
1780
|
end
|
1536
1781
|
}.to raise_error(Mongo::Error::OperationFailure)
|
@@ -1541,20 +1786,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1541
1786
|
context "when the parent is not a new record" do
|
1542
1787
|
|
1543
1788
|
let(:person) do
|
1544
|
-
Person.create
|
1789
|
+
Person.create!
|
1545
1790
|
end
|
1546
1791
|
|
1547
1792
|
let!(:post) do
|
1548
|
-
person.posts.create(text: "Testing") do |post|
|
1793
|
+
person.posts.create!(text: "Testing") do |post|
|
1549
1794
|
post.content = "The Content"
|
1550
1795
|
end
|
1551
1796
|
end
|
1552
1797
|
|
1553
|
-
it "sets the foreign key on the
|
1798
|
+
it "sets the foreign key on the association" do
|
1554
1799
|
expect(post.person_id).to eq(person.id)
|
1555
1800
|
end
|
1556
1801
|
|
1557
|
-
it "sets the base on the inverse
|
1802
|
+
it "sets the base on the inverse association" do
|
1558
1803
|
expect(post.person).to eq(person)
|
1559
1804
|
end
|
1560
1805
|
|
@@ -1578,11 +1823,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1578
1823
|
context "when passing a new object" do
|
1579
1824
|
|
1580
1825
|
let!(:odd) do
|
1581
|
-
Odd.create(name: 'one')
|
1826
|
+
Odd.create!(name: 'one')
|
1582
1827
|
end
|
1583
1828
|
|
1584
1829
|
let!(:even) do
|
1585
|
-
odd.evens.create(name: 'two', odds: [Odd.new(name: 'three')])
|
1830
|
+
odd.evens.create!(name: 'two', odds: [Odd.new(name: 'three')])
|
1586
1831
|
end
|
1587
1832
|
|
1588
1833
|
it "only push one even to the list" do
|
@@ -1603,7 +1848,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1603
1848
|
end
|
1604
1849
|
end
|
1605
1850
|
|
1606
|
-
context "when the
|
1851
|
+
context "when the association is polymorphic" do
|
1607
1852
|
|
1608
1853
|
context "when the parent is a new record" do
|
1609
1854
|
|
@@ -1612,7 +1857,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1612
1857
|
end
|
1613
1858
|
|
1614
1859
|
let(:rating) do
|
1615
|
-
movie.ratings.create(value: 1)
|
1860
|
+
movie.ratings.create!(value: 1)
|
1616
1861
|
end
|
1617
1862
|
|
1618
1863
|
it "raises an unsaved document error" do
|
@@ -1623,18 +1868,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1623
1868
|
context "when the parent is not a new record" do
|
1624
1869
|
|
1625
1870
|
let(:movie) do
|
1626
|
-
Movie.create
|
1871
|
+
Movie.create!
|
1627
1872
|
end
|
1628
1873
|
|
1629
1874
|
let!(:rating) do
|
1630
|
-
movie.ratings.create(value: 3)
|
1875
|
+
movie.ratings.create!(value: 3)
|
1631
1876
|
end
|
1632
1877
|
|
1633
|
-
it "sets the foreign key on the
|
1878
|
+
it "sets the foreign key on the association" do
|
1634
1879
|
expect(rating.ratable_id).to eq(movie.id)
|
1635
1880
|
end
|
1636
1881
|
|
1637
|
-
it "sets the base on the inverse
|
1882
|
+
it "sets the base on the inverse association" do
|
1638
1883
|
expect(rating.ratable).to eq(movie)
|
1639
1884
|
end
|
1640
1885
|
|
@@ -1652,7 +1897,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1652
1897
|
end
|
1653
1898
|
end
|
1654
1899
|
|
1655
|
-
context "when using a
|
1900
|
+
context "when using a different primary_key" do
|
1656
1901
|
|
1657
1902
|
let(:person) do
|
1658
1903
|
Person.create!(username: 'arthurnn')
|
@@ -1673,7 +1918,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1673
1918
|
context "when providing multiple attributes" do
|
1674
1919
|
|
1675
1920
|
let(:person) do
|
1676
|
-
Person.create
|
1921
|
+
Person.create!
|
1677
1922
|
end
|
1678
1923
|
|
1679
1924
|
let!(:posts) do
|
@@ -1697,7 +1942,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1697
1942
|
end
|
1698
1943
|
end
|
1699
1944
|
|
1700
|
-
context "when the
|
1945
|
+
context "when the association is not polymorphic" do
|
1701
1946
|
|
1702
1947
|
context "when the parent is a new record" do
|
1703
1948
|
|
@@ -1717,18 +1962,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1717
1962
|
context "when the parent is not a new record" do
|
1718
1963
|
|
1719
1964
|
let(:person) do
|
1720
|
-
Person.create
|
1965
|
+
Person.create!
|
1721
1966
|
end
|
1722
1967
|
|
1723
1968
|
let!(:post) do
|
1724
1969
|
person.posts.create!(title: "Testing")
|
1725
1970
|
end
|
1726
1971
|
|
1727
|
-
it "sets the foreign key on the
|
1972
|
+
it "sets the foreign key on the association" do
|
1728
1973
|
expect(post.person_id).to eq(person.id)
|
1729
1974
|
end
|
1730
1975
|
|
1731
|
-
it "sets the base on the inverse
|
1976
|
+
it "sets the base on the inverse association" do
|
1732
1977
|
expect(post.person).to eq(person)
|
1733
1978
|
end
|
1734
1979
|
|
@@ -1755,7 +2000,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1755
2000
|
end
|
1756
2001
|
end
|
1757
2002
|
|
1758
|
-
context "when the
|
2003
|
+
context "when the association is polymorphic" do
|
1759
2004
|
|
1760
2005
|
context "when the parent is a new record" do
|
1761
2006
|
|
@@ -1775,18 +2020,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1775
2020
|
context "when the parent is not a new record" do
|
1776
2021
|
|
1777
2022
|
let(:movie) do
|
1778
|
-
Movie.create
|
2023
|
+
Movie.create!
|
1779
2024
|
end
|
1780
2025
|
|
1781
2026
|
let!(:rating) do
|
1782
2027
|
movie.ratings.create!(value: 4)
|
1783
2028
|
end
|
1784
2029
|
|
1785
|
-
it "sets the foreign key on the
|
2030
|
+
it "sets the foreign key on the association" do
|
1786
2031
|
expect(rating.ratable_id).to eq(movie.id)
|
1787
2032
|
end
|
1788
2033
|
|
1789
|
-
it "sets the base on the inverse
|
2034
|
+
it "sets the base on the inverse association" do
|
1790
2035
|
expect(rating.ratable).to eq(movie)
|
1791
2036
|
end
|
1792
2037
|
|
@@ -1820,7 +2065,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1820
2065
|
Movie.new
|
1821
2066
|
end
|
1822
2067
|
|
1823
|
-
context "when the
|
2068
|
+
context "when the association is polymorphic" do
|
1824
2069
|
|
1825
2070
|
let(:association) do
|
1826
2071
|
Movie.relations["ratings"]
|
@@ -1840,7 +2085,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1840
2085
|
end
|
1841
2086
|
end
|
1842
2087
|
|
1843
|
-
context "when the
|
2088
|
+
context "when the association is not polymorphic" do
|
1844
2089
|
|
1845
2090
|
let(:association) do
|
1846
2091
|
Person.relations["posts"]
|
@@ -1860,172 +2105,130 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1860
2105
|
end
|
1861
2106
|
end
|
1862
2107
|
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
Person.create(username: 'arthurnn')
|
1867
|
-
end
|
2108
|
+
%i[ delete delete_one ].each do |method|
|
2109
|
+
describe "##{method}" do
|
2110
|
+
let!(:person) { Person.create!(username: 'arthurnn') }
|
1868
2111
|
|
1869
|
-
|
2112
|
+
context 'when the document is found' do
|
2113
|
+
context 'when no dependent option is set' do
|
2114
|
+
context 'when we are assigning attributes' do
|
2115
|
+
let!(:drug) { person.drugs.create! }
|
2116
|
+
let(:deleted) { person.drugs.send(method, drug) }
|
1870
2117
|
|
1871
|
-
|
2118
|
+
before do
|
2119
|
+
Mongoid::Threaded.begin_execution(:assign)
|
2120
|
+
end
|
1872
2121
|
|
1873
|
-
|
2122
|
+
after do
|
2123
|
+
Mongoid::Threaded.exit_execution(:assign)
|
2124
|
+
end
|
1874
2125
|
|
1875
|
-
|
1876
|
-
|
2126
|
+
it 'does not cascade' do
|
2127
|
+
expect(deleted.changes.keys).to eq([ 'person_id' ])
|
2128
|
+
end
|
1877
2129
|
end
|
1878
2130
|
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
2131
|
+
context 'when the document is loaded' do
|
2132
|
+
let!(:drug) { person.drugs.create! }
|
2133
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
1882
2134
|
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
2135
|
+
it 'returns the document' do
|
2136
|
+
expect(deleted).to eq(drug)
|
2137
|
+
end
|
1886
2138
|
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
2139
|
+
it 'deletes the foreign key' do
|
2140
|
+
expect(drug.person_id).to be_nil
|
2141
|
+
end
|
1890
2142
|
|
1891
|
-
|
1892
|
-
|
2143
|
+
it 'removes the document from the association' do
|
2144
|
+
expect(person.drugs).not_to include(drug)
|
2145
|
+
end
|
1893
2146
|
end
|
1894
|
-
end
|
1895
2147
|
|
1896
|
-
|
2148
|
+
context 'when the document is not loaded' do
|
2149
|
+
let!(:drug) { Drug.create!(person_id: person.username) }
|
2150
|
+
let!(:deleted) { person.drugs.send(method, drug) }
|
1897
2151
|
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
2152
|
+
it 'returns the document' do
|
2153
|
+
expect(deleted).to eq(drug)
|
2154
|
+
end
|
1901
2155
|
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
2156
|
+
it 'deletes the foreign key' do
|
2157
|
+
expect(drug.person_id).to be_nil
|
2158
|
+
end
|
1905
2159
|
|
1906
|
-
|
1907
|
-
|
2160
|
+
it 'removes the document from the association' do
|
2161
|
+
expect(person.drugs).not_to include(drug)
|
2162
|
+
end
|
1908
2163
|
end
|
2164
|
+
end
|
1909
2165
|
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
2166
|
+
context 'when dependent is delete' do
|
2167
|
+
context 'when the document is loaded' do
|
2168
|
+
let!(:post) { person.posts.create!(title: 'test') }
|
2169
|
+
let!(:deleted) { person.posts.send(method, post) }
|
1913
2170
|
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
end
|
2171
|
+
it 'returns the document' do
|
2172
|
+
expect(deleted).to eq(post)
|
2173
|
+
end
|
1918
2174
|
|
1919
|
-
|
2175
|
+
it 'deletes the document' do
|
2176
|
+
expect(post).to be_destroyed
|
2177
|
+
end
|
1920
2178
|
|
1921
|
-
|
1922
|
-
|
2179
|
+
it 'removes the document from the association' do
|
2180
|
+
expect(person.posts).not_to include(post)
|
2181
|
+
end
|
1923
2182
|
end
|
1924
2183
|
|
1925
|
-
|
1926
|
-
person.
|
1927
|
-
|
2184
|
+
context 'when the document is not loaded' do
|
2185
|
+
let!(:post) { Post.create!(title: 'foo', person_id: person.id) }
|
2186
|
+
let!(:deleted) { person.posts.send(method, post) }
|
1928
2187
|
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
2188
|
+
it 'returns the document' do
|
2189
|
+
expect(deleted).to eq(post)
|
2190
|
+
end
|
1932
2191
|
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
2192
|
+
it 'deletes the document' do
|
2193
|
+
expect(post).to be_destroyed
|
2194
|
+
end
|
1936
2195
|
|
1937
|
-
|
1938
|
-
|
2196
|
+
it 'removes the document from the association' do
|
2197
|
+
expect(person.posts).not_to include(post)
|
2198
|
+
end
|
1939
2199
|
end
|
1940
2200
|
end
|
1941
2201
|
end
|
1942
2202
|
|
1943
|
-
context
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
let!(:post) do
|
1948
|
-
person.posts.create(title: "test")
|
1949
|
-
end
|
2203
|
+
context 'when the document is not found' do
|
2204
|
+
let!(:post) { Post.create!(title: 'foo') }
|
2205
|
+
let!(:deleted) { person.posts.send(method, post) }
|
1950
2206
|
|
1951
|
-
|
1952
|
-
|
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
|
1962
|
-
|
1963
|
-
it "removes the document from the relation" do
|
1964
|
-
expect(person.posts).to_not include(post)
|
1965
|
-
end
|
2207
|
+
it 'returns nil' do
|
2208
|
+
expect(deleted).to be_nil
|
1966
2209
|
end
|
1967
2210
|
|
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
|
2211
|
+
it 'does not delete the document' do
|
2212
|
+
expect(post).to be_persisted
|
1989
2213
|
end
|
1990
2214
|
end
|
1991
2215
|
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
2216
|
end
|
2012
2217
|
|
2013
2218
|
[ :delete_all, :destroy_all ].each do |method|
|
2014
2219
|
|
2015
2220
|
describe "##{method}" do
|
2016
2221
|
|
2017
|
-
context "when the
|
2222
|
+
context "when the association is not polymorphic" do
|
2018
2223
|
|
2019
2224
|
context "when conditions are provided" do
|
2020
2225
|
|
2021
2226
|
let(:person) do
|
2022
|
-
Person.create(username: 'durran')
|
2227
|
+
Person.create!(username: 'durran')
|
2023
2228
|
end
|
2024
2229
|
|
2025
|
-
|
2026
|
-
|
2027
|
-
person.posts.create(title: "Test")
|
2028
|
-
end
|
2230
|
+
let!(:post1) { person.posts.create!(title: "Testing") }
|
2231
|
+
let!(:post2) { person.posts.create!(title: "Test") }
|
2029
2232
|
|
2030
2233
|
it "removes the correct posts" do
|
2031
2234
|
person.posts.send(method, { title: "Testing" })
|
@@ -2041,17 +2244,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2041
2244
|
it "returns the number of documents deleted" do
|
2042
2245
|
expect(person.posts.send(method, { title: "Testing" })).to eq(1)
|
2043
2246
|
end
|
2247
|
+
|
2248
|
+
it "sets the association locally" do
|
2249
|
+
person.posts.send(method, { title: "Testing" })
|
2250
|
+
expect(person.posts).to eq([post2])
|
2251
|
+
end
|
2044
2252
|
end
|
2045
2253
|
|
2046
2254
|
context "when conditions are not provided" do
|
2047
2255
|
|
2048
2256
|
let(:person) do
|
2049
|
-
Person.create
|
2257
|
+
Person.create!
|
2050
2258
|
end
|
2051
2259
|
|
2052
2260
|
before do
|
2053
|
-
person.posts.create(title: "Testing")
|
2054
|
-
person.posts.create(title: "Test")
|
2261
|
+
person.posts.create!(title: "Testing")
|
2262
|
+
person.posts.create!(title: "Test")
|
2055
2263
|
end
|
2056
2264
|
|
2057
2265
|
it "removes the correct posts" do
|
@@ -2067,21 +2275,24 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2067
2275
|
it "returns the number of documents deleted" do
|
2068
2276
|
expect(person.posts.send(method)).to eq(2)
|
2069
2277
|
end
|
2278
|
+
|
2279
|
+
it "sets the association locally" do
|
2280
|
+
person.posts.send(method)
|
2281
|
+
expect(person.posts).to eq([])
|
2282
|
+
end
|
2070
2283
|
end
|
2071
2284
|
end
|
2072
2285
|
|
2073
|
-
context "when the
|
2286
|
+
context "when the association is polymorphic" do
|
2074
2287
|
|
2075
2288
|
context "when conditions are provided" do
|
2076
2289
|
|
2077
2290
|
let(:movie) do
|
2078
|
-
Movie.create(title: "Bladerunner")
|
2291
|
+
Movie.create!(title: "Bladerunner")
|
2079
2292
|
end
|
2080
2293
|
|
2081
|
-
|
2082
|
-
|
2083
|
-
movie.ratings.create(value: 2)
|
2084
|
-
end
|
2294
|
+
let!(:rating1) { movie.ratings.create!(value: 1) }
|
2295
|
+
let!(:rating2) { movie.ratings.create!(value: 2) }
|
2085
2296
|
|
2086
2297
|
it "removes the correct ratings" do
|
2087
2298
|
movie.ratings.send(method, { value: 1 })
|
@@ -2096,17 +2307,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2096
2307
|
it "returns the number of documents deleted" do
|
2097
2308
|
expect(movie.ratings.send(method, { value: 1 })).to eq(1)
|
2098
2309
|
end
|
2310
|
+
|
2311
|
+
it "sets the association locally" do
|
2312
|
+
movie.ratings.send(method, { value: 1 })
|
2313
|
+
expect(movie.ratings).to eq([rating2])
|
2314
|
+
end
|
2099
2315
|
end
|
2100
2316
|
|
2101
2317
|
context "when conditions are not provided" do
|
2102
2318
|
|
2103
2319
|
let(:movie) do
|
2104
|
-
Movie.create(title: "Bladerunner")
|
2320
|
+
Movie.create!(title: "Bladerunner")
|
2105
2321
|
end
|
2106
2322
|
|
2107
2323
|
before do
|
2108
|
-
movie.ratings.create(value: 1)
|
2109
|
-
movie.ratings.create(value: 2)
|
2324
|
+
movie.ratings.create!(value: 1)
|
2325
|
+
movie.ratings.create!(value: 2)
|
2110
2326
|
end
|
2111
2327
|
|
2112
2328
|
it "removes the correct ratings" do
|
@@ -2122,6 +2338,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2122
2338
|
it "returns the number of documents deleted" do
|
2123
2339
|
expect(movie.ratings.send(method)).to eq(2)
|
2124
2340
|
end
|
2341
|
+
|
2342
|
+
it "sets the association locally" do
|
2343
|
+
movie.ratings.send(method)
|
2344
|
+
expect(movie.ratings).to eq([])
|
2345
|
+
end
|
2125
2346
|
end
|
2126
2347
|
end
|
2127
2348
|
end
|
@@ -2137,21 +2358,47 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2137
2358
|
describe "#exists?" do
|
2138
2359
|
|
2139
2360
|
let!(:person) do
|
2140
|
-
Person.create
|
2361
|
+
Person.create!
|
2141
2362
|
end
|
2142
2363
|
|
2143
2364
|
context "when documents exist in the database" do
|
2144
2365
|
|
2145
2366
|
before do
|
2146
|
-
person.posts.create
|
2367
|
+
person.posts.create!
|
2147
2368
|
end
|
2148
2369
|
|
2149
2370
|
it "returns true" do
|
2150
2371
|
expect(person.posts.exists?).to be true
|
2151
2372
|
end
|
2373
|
+
|
2374
|
+
context 'when association is not loaded' do
|
2375
|
+
it 'queries database on each call' do
|
2376
|
+
expect_query(1) do
|
2377
|
+
person.posts.exists?.should be true
|
2378
|
+
end
|
2379
|
+
|
2380
|
+
expect_query(1) do
|
2381
|
+
person.posts.exists?.should be true
|
2382
|
+
end
|
2383
|
+
end
|
2384
|
+
end
|
2385
|
+
|
2386
|
+
context 'when association is loaded' do
|
2387
|
+
it 'queries database on each call' do
|
2388
|
+
expect_query(1) do
|
2389
|
+
person.posts.exists?.should be true
|
2390
|
+
end
|
2391
|
+
|
2392
|
+
person.posts.to_a
|
2393
|
+
|
2394
|
+
expect_query(1) do
|
2395
|
+
person.posts.exists?.should be true
|
2396
|
+
end
|
2397
|
+
end
|
2398
|
+
end
|
2152
2399
|
end
|
2153
2400
|
|
2154
|
-
context "when
|
2401
|
+
context "when documents exist in application but not in database" do
|
2155
2402
|
|
2156
2403
|
before do
|
2157
2404
|
person.posts.build
|
@@ -2160,6 +2407,65 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2160
2407
|
it "returns false" do
|
2161
2408
|
expect(person.posts.exists?).to be false
|
2162
2409
|
end
|
2410
|
+
|
2411
|
+
context 'when association is not loaded' do
|
2412
|
+
it 'queries database on each call' do
|
2413
|
+
expect_query(1) do
|
2414
|
+
person.posts.exists?.should be false
|
2415
|
+
end
|
2416
|
+
|
2417
|
+
expect_query(1) do
|
2418
|
+
person.posts.exists?.should be false
|
2419
|
+
end
|
2420
|
+
end
|
2421
|
+
end
|
2422
|
+
|
2423
|
+
context 'when association is loaded' do
|
2424
|
+
it 'queries database on each call' do
|
2425
|
+
expect_query(1) do
|
2426
|
+
person.posts.exists?.should be false
|
2427
|
+
end
|
2428
|
+
|
2429
|
+
person.posts.to_a
|
2430
|
+
|
2431
|
+
expect_query(1) do
|
2432
|
+
person.posts.exists?.should be false
|
2433
|
+
end
|
2434
|
+
end
|
2435
|
+
end
|
2436
|
+
end
|
2437
|
+
|
2438
|
+
context "when no documents exist" do
|
2439
|
+
|
2440
|
+
it "returns false" do
|
2441
|
+
expect(person.posts.exists?).to be false
|
2442
|
+
end
|
2443
|
+
|
2444
|
+
context 'when association is not loaded' do
|
2445
|
+
it 'queries database on each call' do
|
2446
|
+
expect_query(1) do
|
2447
|
+
person.posts.exists?.should be false
|
2448
|
+
end
|
2449
|
+
|
2450
|
+
expect_query(1) do
|
2451
|
+
person.posts.exists?.should be false
|
2452
|
+
end
|
2453
|
+
end
|
2454
|
+
end
|
2455
|
+
|
2456
|
+
context 'when association is loaded' do
|
2457
|
+
it 'queries database on each call' do
|
2458
|
+
expect_query(1) do
|
2459
|
+
person.posts.exists?.should be false
|
2460
|
+
end
|
2461
|
+
|
2462
|
+
person.posts.to_a
|
2463
|
+
|
2464
|
+
expect_query(1) do
|
2465
|
+
person.posts.exists?.should be false
|
2466
|
+
end
|
2467
|
+
end
|
2468
|
+
end
|
2163
2469
|
end
|
2164
2470
|
end
|
2165
2471
|
|
@@ -2186,18 +2492,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2186
2492
|
end
|
2187
2493
|
end
|
2188
2494
|
|
2189
|
-
context "when the
|
2495
|
+
context "when the association is not polymorphic" do
|
2190
2496
|
|
2191
2497
|
let(:person) do
|
2192
|
-
Person.create
|
2498
|
+
Person.create!
|
2193
2499
|
end
|
2194
2500
|
|
2195
2501
|
let!(:post_one) do
|
2196
|
-
person.posts.create(title: "Test")
|
2502
|
+
person.posts.create!(title: "Test")
|
2197
2503
|
end
|
2198
2504
|
|
2199
2505
|
let!(:post_two) do
|
2200
|
-
person.posts.create(title: "OMG I has
|
2506
|
+
person.posts.create!(title: "OMG I has associations")
|
2201
2507
|
end
|
2202
2508
|
|
2203
2509
|
context "when providing an id" do
|
@@ -2213,16 +2519,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2213
2519
|
end
|
2214
2520
|
end
|
2215
2521
|
|
2216
|
-
context "when the id matches but is not scoped to the
|
2522
|
+
context "when the id matches but is not scoped to the association" do
|
2217
2523
|
|
2218
2524
|
let(:post) do
|
2219
|
-
Post.create(title: "Unscoped")
|
2525
|
+
Post.create!(title: "Unscoped")
|
2220
2526
|
end
|
2221
2527
|
|
2222
2528
|
it "raises an error" do
|
2223
2529
|
expect {
|
2224
2530
|
person.posts.find(post.id)
|
2225
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2531
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
2226
2532
|
end
|
2227
2533
|
end
|
2228
2534
|
|
@@ -2237,7 +2543,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2237
2543
|
it "raises an error" do
|
2238
2544
|
expect {
|
2239
2545
|
person.posts.find(BSON::ObjectId.new)
|
2240
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2546
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
2241
2547
|
end
|
2242
2548
|
end
|
2243
2549
|
|
@@ -2286,7 +2592,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2286
2592
|
it "raises an error" do
|
2287
2593
|
expect {
|
2288
2594
|
person.posts.find([ BSON::ObjectId.new ])
|
2289
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2595
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Post with id\(s\)/)
|
2290
2596
|
end
|
2291
2597
|
end
|
2292
2598
|
|
@@ -2312,18 +2618,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2312
2618
|
end
|
2313
2619
|
end
|
2314
2620
|
|
2315
|
-
context "when the
|
2621
|
+
context "when the association is polymorphic" do
|
2316
2622
|
|
2317
2623
|
let(:movie) do
|
2318
|
-
Movie.create
|
2624
|
+
Movie.create!
|
2319
2625
|
end
|
2320
2626
|
|
2321
2627
|
let!(:rating_one) do
|
2322
|
-
movie.ratings.create(value: 1)
|
2628
|
+
movie.ratings.create!(value: 1)
|
2323
2629
|
end
|
2324
2630
|
|
2325
2631
|
let!(:rating_two) do
|
2326
|
-
movie.ratings.create(value: 5)
|
2632
|
+
movie.ratings.create!(value: 5)
|
2327
2633
|
end
|
2328
2634
|
|
2329
2635
|
context "when providing an id" do
|
@@ -2350,7 +2656,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2350
2656
|
it "raises an error" do
|
2351
2657
|
expect {
|
2352
2658
|
movie.ratings.find(BSON::ObjectId.new)
|
2353
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2659
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
|
2354
2660
|
end
|
2355
2661
|
end
|
2356
2662
|
|
@@ -2407,7 +2713,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2407
2713
|
it "raises an error" do
|
2408
2714
|
expect {
|
2409
2715
|
movie.ratings.find([ BSON::ObjectId.new ])
|
2410
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2716
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Rating with id\(s\)/)
|
2411
2717
|
end
|
2412
2718
|
end
|
2413
2719
|
|
@@ -2432,18 +2738,56 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2432
2738
|
end
|
2433
2739
|
end
|
2434
2740
|
end
|
2741
|
+
|
2742
|
+
context "with block" do
|
2743
|
+
let!(:author) do
|
2744
|
+
Person.create!(title: 'Person')
|
2745
|
+
end
|
2746
|
+
|
2747
|
+
let!(:post_one) do
|
2748
|
+
author.posts.create!(title: 'post one')
|
2749
|
+
end
|
2750
|
+
|
2751
|
+
let!(:post_two) do
|
2752
|
+
author.posts.create!(title: 'post two')
|
2753
|
+
end
|
2754
|
+
|
2755
|
+
it "finds one" do
|
2756
|
+
expect(
|
2757
|
+
author.posts.find do |post|
|
2758
|
+
post.title == 'post one'
|
2759
|
+
end
|
2760
|
+
).to be_a(Post)
|
2761
|
+
end
|
2762
|
+
|
2763
|
+
it "returns first match of multiple" do
|
2764
|
+
expect(
|
2765
|
+
author.posts.find do |post|
|
2766
|
+
['post one', 'post two'].include?(post.title)
|
2767
|
+
end
|
2768
|
+
).to eq(post_one)
|
2769
|
+
end
|
2770
|
+
|
2771
|
+
it "returns nil when not found" do
|
2772
|
+
expect(
|
2773
|
+
author.posts.find do |post|
|
2774
|
+
post.title == 'non exiting one'
|
2775
|
+
end
|
2776
|
+
).to be_nil
|
2777
|
+
end
|
2778
|
+
end
|
2435
2779
|
end
|
2436
2780
|
|
2437
2781
|
describe "#find_or_create_by" do
|
2438
2782
|
|
2439
|
-
context "when the
|
2783
|
+
context "when the association is not polymorphic" do
|
2440
2784
|
|
2441
2785
|
let(:person) do
|
2442
|
-
Person.create
|
2786
|
+
Person.create!
|
2443
2787
|
end
|
2444
2788
|
|
2445
2789
|
let!(:post) do
|
2446
|
-
person.posts.create(title: "Testing")
|
2790
|
+
person.posts.create!(title: "Testing")
|
2447
2791
|
end
|
2448
2792
|
|
2449
2793
|
context "when the document exists" do
|
@@ -2456,7 +2800,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2456
2800
|
expect(found).to eq(post)
|
2457
2801
|
end
|
2458
2802
|
|
2459
|
-
it "keeps the document in the
|
2803
|
+
it "keeps the document in the association" do
|
2460
2804
|
expect(found.person).to eq(person)
|
2461
2805
|
end
|
2462
2806
|
end
|
@@ -2483,7 +2827,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2483
2827
|
expect(found.content).to eq("The Content")
|
2484
2828
|
end
|
2485
2829
|
|
2486
|
-
it "keeps the document in the
|
2830
|
+
it "keeps the document in the association" do
|
2487
2831
|
expect(found.person).to eq(person)
|
2488
2832
|
end
|
2489
2833
|
end
|
@@ -2502,21 +2846,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2502
2846
|
expect(found).to be_persisted
|
2503
2847
|
end
|
2504
2848
|
|
2505
|
-
it "keeps the document in the
|
2849
|
+
it "keeps the document in the association" do
|
2506
2850
|
expect(found.person).to eq(person)
|
2507
2851
|
end
|
2508
2852
|
end
|
2509
2853
|
end
|
2510
2854
|
end
|
2511
2855
|
|
2512
|
-
context "when the
|
2856
|
+
context "when the association is polymorphic" do
|
2513
2857
|
|
2514
2858
|
let(:movie) do
|
2515
|
-
Movie.create
|
2859
|
+
Movie.create!
|
2516
2860
|
end
|
2517
2861
|
|
2518
2862
|
let!(:rating) do
|
2519
|
-
movie.ratings.create(value: 1)
|
2863
|
+
movie.ratings.create!(value: 1)
|
2520
2864
|
end
|
2521
2865
|
|
2522
2866
|
context "when the document exists" do
|
@@ -2529,7 +2873,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2529
2873
|
expect(found).to eq(rating)
|
2530
2874
|
end
|
2531
2875
|
|
2532
|
-
it "keeps the document in the
|
2876
|
+
it "keeps the document in the association" do
|
2533
2877
|
expect(found.ratable).to eq(movie)
|
2534
2878
|
end
|
2535
2879
|
end
|
@@ -2548,7 +2892,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2548
2892
|
expect(found).to be_persisted
|
2549
2893
|
end
|
2550
2894
|
|
2551
|
-
it "keeps the document in the
|
2895
|
+
it "keeps the document in the association" do
|
2552
2896
|
expect(found.ratable).to eq(movie)
|
2553
2897
|
end
|
2554
2898
|
end
|
@@ -2557,14 +2901,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2557
2901
|
|
2558
2902
|
describe "#find_or_create_by!" do
|
2559
2903
|
|
2560
|
-
context "when the
|
2904
|
+
context "when the association is not polymorphic" do
|
2561
2905
|
|
2562
2906
|
let(:person) do
|
2563
|
-
Person.create
|
2907
|
+
Person.create!
|
2564
2908
|
end
|
2565
2909
|
|
2566
2910
|
let!(:post) do
|
2567
|
-
person.posts.create(title: "Testing")
|
2911
|
+
person.posts.create!(title: "Testing")
|
2568
2912
|
end
|
2569
2913
|
|
2570
2914
|
context "when the document exists" do
|
@@ -2577,7 +2921,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2577
2921
|
expect(found).to eq(post)
|
2578
2922
|
end
|
2579
2923
|
|
2580
|
-
it "keeps the document in the
|
2924
|
+
it "keeps the document in the association" do
|
2581
2925
|
expect(found.person).to eq(person)
|
2582
2926
|
end
|
2583
2927
|
end
|
@@ -2604,7 +2948,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2604
2948
|
expect(found.content).to eq("The Content")
|
2605
2949
|
end
|
2606
2950
|
|
2607
|
-
it "keeps the document in the
|
2951
|
+
it "keeps the document in the association" do
|
2608
2952
|
expect(found.person).to eq(person)
|
2609
2953
|
end
|
2610
2954
|
end
|
@@ -2623,21 +2967,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2623
2967
|
expect(found).to be_persisted
|
2624
2968
|
end
|
2625
2969
|
|
2626
|
-
it "keeps the document in the
|
2970
|
+
it "keeps the document in the association" do
|
2627
2971
|
expect(found.person).to eq(person)
|
2628
2972
|
end
|
2629
2973
|
end
|
2630
2974
|
end
|
2631
2975
|
end
|
2632
2976
|
|
2633
|
-
context "when the
|
2977
|
+
context "when the association is polymorphic" do
|
2634
2978
|
|
2635
2979
|
let(:movie) do
|
2636
|
-
Movie.create
|
2980
|
+
Movie.create!
|
2637
2981
|
end
|
2638
2982
|
|
2639
2983
|
let!(:rating) do
|
2640
|
-
movie.ratings.create(value: 1)
|
2984
|
+
movie.ratings.create!(value: 1)
|
2641
2985
|
end
|
2642
2986
|
|
2643
2987
|
context "when the document exists" do
|
@@ -2650,7 +2994,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2650
2994
|
expect(found).to eq(rating)
|
2651
2995
|
end
|
2652
2996
|
|
2653
|
-
it "keeps the document in the
|
2997
|
+
it "keeps the document in the association" do
|
2654
2998
|
expect(found.ratable).to eq(movie)
|
2655
2999
|
end
|
2656
3000
|
end
|
@@ -2669,7 +3013,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2669
3013
|
expect(found).to be_persisted
|
2670
3014
|
end
|
2671
3015
|
|
2672
|
-
it "keeps the document in the
|
3016
|
+
it "keeps the document in the association" do
|
2673
3017
|
expect(found.ratable).to eq(movie)
|
2674
3018
|
end
|
2675
3019
|
|
@@ -2687,14 +3031,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2687
3031
|
|
2688
3032
|
describe "#find_or_initialize_by" do
|
2689
3033
|
|
2690
|
-
context "when the
|
3034
|
+
context "when the association is not polymorphic" do
|
2691
3035
|
|
2692
3036
|
let(:person) do
|
2693
|
-
Person.create
|
3037
|
+
Person.create!
|
2694
3038
|
end
|
2695
3039
|
|
2696
3040
|
let!(:post) do
|
2697
|
-
person.posts.create(title: "Testing")
|
3041
|
+
person.posts.create!(title: "Testing")
|
2698
3042
|
end
|
2699
3043
|
|
2700
3044
|
context "when the document exists" do
|
@@ -2730,14 +3074,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2730
3074
|
end
|
2731
3075
|
end
|
2732
3076
|
|
2733
|
-
context "when the
|
3077
|
+
context "when the association is polymorphic" do
|
2734
3078
|
|
2735
3079
|
let(:movie) do
|
2736
|
-
Movie.create
|
3080
|
+
Movie.create!
|
2737
3081
|
end
|
2738
3082
|
|
2739
3083
|
let!(:rating) do
|
2740
|
-
movie.ratings.create(value: 1)
|
3084
|
+
movie.ratings.create!(value: 1)
|
2741
3085
|
end
|
2742
3086
|
|
2743
3087
|
context "when the document exists" do
|
@@ -2770,7 +3114,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2770
3114
|
|
2771
3115
|
describe "#initialize" do
|
2772
3116
|
|
2773
|
-
context "when an illegal mixed
|
3117
|
+
context "when an illegal mixed association exists" do
|
2774
3118
|
|
2775
3119
|
let(:post) do
|
2776
3120
|
Post.new
|
@@ -2783,7 +3127,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2783
3127
|
end
|
2784
3128
|
end
|
2785
3129
|
|
2786
|
-
context "when a cyclic
|
3130
|
+
context "when a cyclic association exists" do
|
2787
3131
|
|
2788
3132
|
let(:post) do
|
2789
3133
|
Post.new
|
@@ -2827,15 +3171,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2827
3171
|
describe "#max" do
|
2828
3172
|
|
2829
3173
|
let(:person) do
|
2830
|
-
Person.create
|
3174
|
+
Person.create!
|
2831
3175
|
end
|
2832
3176
|
|
2833
3177
|
let(:post_one) do
|
2834
|
-
Post.create(rating: 5)
|
3178
|
+
Post.create!(rating: 5)
|
2835
3179
|
end
|
2836
3180
|
|
2837
3181
|
let(:post_two) do
|
2838
|
-
Post.create(rating: 10)
|
3182
|
+
Post.create!(rating: 10)
|
2839
3183
|
end
|
2840
3184
|
|
2841
3185
|
before do
|
@@ -2856,15 +3200,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2856
3200
|
describe "#max_by" do
|
2857
3201
|
|
2858
3202
|
let(:person) do
|
2859
|
-
Person.create
|
3203
|
+
Person.create!
|
2860
3204
|
end
|
2861
3205
|
|
2862
3206
|
let(:post_one) do
|
2863
|
-
Post.create(rating: 5)
|
3207
|
+
Post.create!(rating: 5)
|
2864
3208
|
end
|
2865
3209
|
|
2866
3210
|
let(:post_two) do
|
2867
|
-
Post.create(rating: 10)
|
3211
|
+
Post.create!(rating: 10)
|
2868
3212
|
end
|
2869
3213
|
|
2870
3214
|
before do
|
@@ -2883,15 +3227,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2883
3227
|
describe "#method_missing" do
|
2884
3228
|
|
2885
3229
|
let!(:person) do
|
2886
|
-
Person.create
|
3230
|
+
Person.create!
|
2887
3231
|
end
|
2888
3232
|
|
2889
3233
|
let!(:post_one) do
|
2890
|
-
person.posts.create(title: "First", content: "Posting")
|
3234
|
+
person.posts.create!(title: "First", content: "Posting")
|
2891
3235
|
end
|
2892
3236
|
|
2893
3237
|
let!(:post_two) do
|
2894
|
-
person.posts.create(title: "Second", content: "Testing")
|
3238
|
+
person.posts.create!(title: "Second", content: "Testing")
|
2895
3239
|
end
|
2896
3240
|
|
2897
3241
|
context "when providing a single criteria" do
|
@@ -2958,15 +3302,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2958
3302
|
describe "#min" do
|
2959
3303
|
|
2960
3304
|
let(:person) do
|
2961
|
-
Person.create
|
3305
|
+
Person.create!
|
2962
3306
|
end
|
2963
3307
|
|
2964
3308
|
let(:post_one) do
|
2965
|
-
Post.create(rating: 5)
|
3309
|
+
Post.create!(rating: 5)
|
2966
3310
|
end
|
2967
3311
|
|
2968
3312
|
let(:post_two) do
|
2969
|
-
Post.create(rating: 10)
|
3313
|
+
Post.create!(rating: 10)
|
2970
3314
|
end
|
2971
3315
|
|
2972
3316
|
before do
|
@@ -2987,15 +3331,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2987
3331
|
describe "#min_by" do
|
2988
3332
|
|
2989
3333
|
let(:person) do
|
2990
|
-
Person.create
|
3334
|
+
Person.create!
|
2991
3335
|
end
|
2992
3336
|
|
2993
3337
|
let(:post_one) do
|
2994
|
-
Post.create(rating: 5)
|
3338
|
+
Post.create!(rating: 5)
|
2995
3339
|
end
|
2996
3340
|
|
2997
3341
|
let(:post_two) do
|
2998
|
-
Post.create(rating: 10)
|
3342
|
+
Post.create!(rating: 10)
|
2999
3343
|
end
|
3000
3344
|
|
3001
3345
|
before do
|
@@ -3016,15 +3360,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3016
3360
|
context "when the inverse has not been loaded" do
|
3017
3361
|
|
3018
3362
|
let(:person) do
|
3019
|
-
Person.create
|
3363
|
+
Person.create!
|
3020
3364
|
end
|
3021
3365
|
|
3022
3366
|
let!(:post_one) do
|
3023
|
-
person.posts.create(title: "One")
|
3367
|
+
person.posts.create!(title: "One")
|
3024
3368
|
end
|
3025
3369
|
|
3026
3370
|
let!(:post_two) do
|
3027
|
-
person.posts.create(title: "Two")
|
3371
|
+
person.posts.create!(title: "Two")
|
3028
3372
|
end
|
3029
3373
|
|
3030
3374
|
let(:from_db) do
|
@@ -3050,18 +3394,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3050
3394
|
end
|
3051
3395
|
end
|
3052
3396
|
|
3053
|
-
context "when the
|
3397
|
+
context "when the association is not polymorphic" do
|
3054
3398
|
|
3055
3399
|
let(:person) do
|
3056
|
-
Person.create
|
3400
|
+
Person.create!
|
3057
3401
|
end
|
3058
3402
|
|
3059
3403
|
let!(:post_one) do
|
3060
|
-
person.posts.create(title: "One")
|
3404
|
+
person.posts.create!(title: "One")
|
3061
3405
|
end
|
3062
3406
|
|
3063
3407
|
let!(:post_two) do
|
3064
|
-
person.posts.create(title: "Two")
|
3408
|
+
person.posts.create!(title: "Two")
|
3065
3409
|
end
|
3066
3410
|
|
3067
3411
|
before do
|
@@ -3084,30 +3428,30 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3084
3428
|
expect(post_one.reload.person).to be_nil
|
3085
3429
|
end
|
3086
3430
|
|
3087
|
-
context "when adding a nullified document back to the
|
3431
|
+
context "when adding a nullified document back to the association" do
|
3088
3432
|
|
3089
3433
|
before do
|
3090
3434
|
person.posts.push(post_one)
|
3091
3435
|
end
|
3092
3436
|
|
3093
|
-
it "persists the
|
3437
|
+
it "persists the association" do
|
3094
3438
|
expect(person.posts(true)).to eq([ post_one ])
|
3095
3439
|
end
|
3096
3440
|
end
|
3097
3441
|
end
|
3098
3442
|
|
3099
|
-
context "when the
|
3443
|
+
context "when the association is polymorphic" do
|
3100
3444
|
|
3101
3445
|
let(:movie) do
|
3102
|
-
Movie.create(title: "Oldboy")
|
3446
|
+
Movie.create!(title: "Oldboy")
|
3103
3447
|
end
|
3104
3448
|
|
3105
3449
|
let!(:rating_one) do
|
3106
|
-
movie.ratings.create(value: 10)
|
3450
|
+
movie.ratings.create!(value: 10)
|
3107
3451
|
end
|
3108
3452
|
|
3109
3453
|
let!(:rating_two) do
|
3110
|
-
movie.ratings.create(value: 9)
|
3454
|
+
movie.ratings.create!(value: 9)
|
3111
3455
|
end
|
3112
3456
|
|
3113
3457
|
before do
|
@@ -3179,7 +3523,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3179
3523
|
person.posts.scoped
|
3180
3524
|
end
|
3181
3525
|
|
3182
|
-
it "returns the
|
3526
|
+
it "returns the association criteria" do
|
3183
3527
|
expect(scoped).to be_a(Mongoid::Criteria)
|
3184
3528
|
end
|
3185
3529
|
|
@@ -3193,13 +3537,13 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3193
3537
|
describe "##{method}" do
|
3194
3538
|
|
3195
3539
|
let(:movie) do
|
3196
|
-
Movie.create
|
3540
|
+
Movie.create!
|
3197
3541
|
end
|
3198
3542
|
|
3199
3543
|
context "when documents have been persisted" do
|
3200
3544
|
|
3201
3545
|
let!(:rating) do
|
3202
|
-
movie.ratings.create(value: 1)
|
3546
|
+
movie.ratings.create!(value: 1)
|
3203
3547
|
end
|
3204
3548
|
|
3205
3549
|
it "returns 1" do
|
@@ -3211,7 +3555,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3211
3555
|
|
3212
3556
|
before do
|
3213
3557
|
movie.ratings.build(value: 1)
|
3214
|
-
movie.ratings.create(value: 2)
|
3558
|
+
movie.ratings.create!(value: 2)
|
3215
3559
|
end
|
3216
3560
|
|
3217
3561
|
it "returns the total number of documents" do
|
@@ -3223,18 +3567,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3223
3567
|
|
3224
3568
|
describe "#unscoped" do
|
3225
3569
|
|
3226
|
-
context "when the
|
3570
|
+
context "when the association has no default scope" do
|
3227
3571
|
|
3228
3572
|
let!(:person) do
|
3229
|
-
Person.create
|
3573
|
+
Person.create!
|
3230
3574
|
end
|
3231
3575
|
|
3232
3576
|
let!(:post_one) do
|
3233
|
-
person.posts.create(title: "first")
|
3577
|
+
person.posts.create!(title: "first")
|
3234
3578
|
end
|
3235
3579
|
|
3236
3580
|
let!(:post_two) do
|
3237
|
-
Post.create(title: "second")
|
3581
|
+
Post.create!(title: "second")
|
3238
3582
|
end
|
3239
3583
|
|
3240
3584
|
let(:unscoped) do
|
@@ -3246,18 +3590,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3246
3590
|
end
|
3247
3591
|
end
|
3248
3592
|
|
3249
|
-
context "when the
|
3593
|
+
context "when the association has a default scope" do
|
3250
3594
|
|
3251
3595
|
let!(:church) do
|
3252
|
-
Church.create
|
3596
|
+
Church.create!
|
3253
3597
|
end
|
3254
3598
|
|
3255
3599
|
let!(:acolyte_one) do
|
3256
|
-
church.acolytes.create(name: "first")
|
3600
|
+
church.acolytes.create!(name: "first")
|
3257
3601
|
end
|
3258
3602
|
|
3259
3603
|
let!(:acolyte_two) do
|
3260
|
-
Acolyte.create(name: "second")
|
3604
|
+
Acolyte.create!(name: "second")
|
3261
3605
|
end
|
3262
3606
|
|
3263
3607
|
let(:unscoped) do
|
@@ -3277,19 +3621,19 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3277
3621
|
context "when the association has an order defined" do
|
3278
3622
|
|
3279
3623
|
let(:person) do
|
3280
|
-
Person.create
|
3624
|
+
Person.create!
|
3281
3625
|
end
|
3282
3626
|
|
3283
3627
|
let(:post_one) do
|
3284
|
-
OrderedPost.create(rating: 10, title: '1')
|
3628
|
+
OrderedPost.create!(rating: 10, title: '1')
|
3285
3629
|
end
|
3286
3630
|
|
3287
3631
|
let(:post_two) do
|
3288
|
-
OrderedPost.create(rating: 20, title: '2')
|
3632
|
+
OrderedPost.create!(rating: 20, title: '2')
|
3289
3633
|
end
|
3290
3634
|
|
3291
3635
|
let(:post_three) do
|
3292
|
-
OrderedPost.create(rating: 20, title: '3')
|
3636
|
+
OrderedPost.create!(rating: 20, title: '3')
|
3293
3637
|
end
|
3294
3638
|
|
3295
3639
|
before do
|
@@ -3303,32 +3647,32 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3303
3647
|
)
|
3304
3648
|
end
|
3305
3649
|
|
3306
|
-
it "chaining order
|
3650
|
+
it "chaining order criteria" do
|
3307
3651
|
expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
|
3308
3652
|
[post_three, post_two, post_one]
|
3309
3653
|
)
|
3310
3654
|
end
|
3311
3655
|
end
|
3312
3656
|
|
3313
|
-
context "when reloading the
|
3657
|
+
context "when reloading the association" do
|
3314
3658
|
|
3315
3659
|
let!(:person) do
|
3316
|
-
Person.create
|
3660
|
+
Person.create!
|
3317
3661
|
end
|
3318
3662
|
|
3319
3663
|
let!(:post_one) do
|
3320
|
-
Post.create(title: "one")
|
3664
|
+
Post.create!(title: "one")
|
3321
3665
|
end
|
3322
3666
|
|
3323
3667
|
let!(:post_two) do
|
3324
|
-
Post.create(title: "two")
|
3668
|
+
Post.create!(title: "two")
|
3325
3669
|
end
|
3326
3670
|
|
3327
3671
|
before do
|
3328
3672
|
person.posts << post_one
|
3329
3673
|
end
|
3330
3674
|
|
3331
|
-
context "when the
|
3675
|
+
context "when the association references the same documents" do
|
3332
3676
|
|
3333
3677
|
before do
|
3334
3678
|
Post.collection.find({ _id: post_one.id }).
|
@@ -3344,7 +3688,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3344
3688
|
end
|
3345
3689
|
end
|
3346
3690
|
|
3347
|
-
context "when the
|
3691
|
+
context "when the association references different documents" do
|
3348
3692
|
|
3349
3693
|
before do
|
3350
3694
|
person.posts << post_two
|
@@ -3367,7 +3711,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3367
3711
|
context "when the parent is using integer ids" do
|
3368
3712
|
|
3369
3713
|
let(:jar) do
|
3370
|
-
Jar.create do |doc|
|
3714
|
+
Jar.create! do |doc|
|
3371
3715
|
doc._id = 1
|
3372
3716
|
end
|
3373
3717
|
end
|
@@ -3431,7 +3775,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3431
3775
|
expect(album.before_add_called).to be true
|
3432
3776
|
end
|
3433
3777
|
|
3434
|
-
it "adds the document to the
|
3778
|
+
it "adds the document to the association" do
|
3435
3779
|
expect(artist.albums).to eq([ album ])
|
3436
3780
|
end
|
3437
3781
|
end
|
@@ -3443,7 +3787,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3443
3787
|
begin; artist.albums << album; rescue; end
|
3444
3788
|
end
|
3445
3789
|
|
3446
|
-
it "does not add the document to the
|
3790
|
+
it "does not add the document to the association" do
|
3447
3791
|
expect(artist.albums).to be_empty
|
3448
3792
|
end
|
3449
3793
|
end
|
@@ -3471,17 +3815,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3471
3815
|
begin; artist.albums << album; rescue; end
|
3472
3816
|
end
|
3473
3817
|
|
3474
|
-
it "adds the document to the
|
3818
|
+
it "adds the document to the association" do
|
3475
3819
|
expect(artist.albums).to eq([ album ])
|
3476
3820
|
end
|
3477
3821
|
end
|
3478
3822
|
|
3479
|
-
context 'when the
|
3823
|
+
context 'when the association already exists' do
|
3480
3824
|
|
3481
3825
|
before do
|
3482
3826
|
artist.albums << album
|
3483
|
-
album.save
|
3484
|
-
artist.save
|
3827
|
+
album.save!
|
3828
|
+
artist.save!
|
3485
3829
|
expect(artist).not_to receive(:after_add_album)
|
3486
3830
|
end
|
3487
3831
|
|
@@ -3489,7 +3833,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3489
3833
|
Album.where(artist_id: artist.id).first
|
3490
3834
|
end
|
3491
3835
|
|
3492
|
-
it 'does not execute the callback when the
|
3836
|
+
it 'does not execute the callback when the association is accessed' do
|
3493
3837
|
expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
|
3494
3838
|
end
|
3495
3839
|
end
|
@@ -3521,7 +3865,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3521
3865
|
expect(artist.before_remove_referenced_called).to be true
|
3522
3866
|
end
|
3523
3867
|
|
3524
|
-
it "removes the document from the
|
3868
|
+
it "removes the document from the association" do
|
3525
3869
|
expect(artist.albums).to be_empty
|
3526
3870
|
end
|
3527
3871
|
end
|
@@ -3536,7 +3880,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3536
3880
|
expect(artist.before_remove_referenced_called).to be true
|
3537
3881
|
end
|
3538
3882
|
|
3539
|
-
it "clears the
|
3883
|
+
it "clears the association" do
|
3540
3884
|
expect(artist.albums).to be_empty
|
3541
3885
|
end
|
3542
3886
|
end
|
@@ -3553,7 +3897,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3553
3897
|
begin; artist.albums.delete(album); rescue; end
|
3554
3898
|
end
|
3555
3899
|
|
3556
|
-
it "does not remove the document from the
|
3900
|
+
it "does not remove the document from the association" do
|
3557
3901
|
expect(artist.albums).to eq([ album ])
|
3558
3902
|
end
|
3559
3903
|
end
|
@@ -3564,7 +3908,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3564
3908
|
begin; artist.albums.clear; rescue; end
|
3565
3909
|
end
|
3566
3910
|
|
3567
|
-
it "does not clear the
|
3911
|
+
it "does not clear the association" do
|
3568
3912
|
expect(artist.albums).to eq([ album ])
|
3569
3913
|
end
|
3570
3914
|
end
|
@@ -3624,7 +3968,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3624
3968
|
begin; artist.albums.delete(album); rescue; end
|
3625
3969
|
end
|
3626
3970
|
|
3627
|
-
it "removes the documents from the
|
3971
|
+
it "removes the documents from the association" do
|
3628
3972
|
expect(artist.albums).to be_empty
|
3629
3973
|
end
|
3630
3974
|
end
|
@@ -3635,25 +3979,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3635
3979
|
begin; artist.albums.clear; rescue; end
|
3636
3980
|
end
|
3637
3981
|
|
3638
|
-
it "removes the documents from the
|
3982
|
+
it "removes the documents from the association" do
|
3639
3983
|
expect(artist.albums).to be_empty
|
3640
3984
|
end
|
3641
3985
|
end
|
3642
3986
|
end
|
3643
3987
|
end
|
3644
3988
|
|
3645
|
-
context "when executing a criteria call on an ordered
|
3989
|
+
context "when executing a criteria call on an ordered association" do
|
3646
3990
|
|
3647
3991
|
let(:person) do
|
3648
|
-
Person.create
|
3992
|
+
Person.create!
|
3649
3993
|
end
|
3650
3994
|
|
3651
3995
|
let!(:post_one) do
|
3652
|
-
person.ordered_posts.create(rating: 1)
|
3996
|
+
person.ordered_posts.create!(rating: 1)
|
3653
3997
|
end
|
3654
3998
|
|
3655
3999
|
let!(:post_two) do
|
3656
|
-
person.ordered_posts.create(rating: 5)
|
4000
|
+
person.ordered_posts.create!(rating: 5)
|
3657
4001
|
end
|
3658
4002
|
|
3659
4003
|
let(:criteria) do
|
@@ -3668,11 +4012,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3668
4012
|
context "when accessing a scope named open" do
|
3669
4013
|
|
3670
4014
|
let(:person) do
|
3671
|
-
Person.create
|
4015
|
+
Person.create!
|
3672
4016
|
end
|
3673
4017
|
|
3674
4018
|
let!(:post) do
|
3675
|
-
person.posts.create(title: "open")
|
4019
|
+
person.posts.create!(title: "open")
|
3676
4020
|
end
|
3677
4021
|
|
3678
4022
|
it "returns the appropriate documents" do
|
@@ -3680,18 +4024,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3680
4024
|
end
|
3681
4025
|
end
|
3682
4026
|
|
3683
|
-
context "when accessing a
|
4027
|
+
context "when accessing a association named parent" do
|
3684
4028
|
|
3685
4029
|
let!(:parent) do
|
3686
|
-
Odd.create(name: "odd parent")
|
4030
|
+
Odd.create!(name: "odd parent")
|
3687
4031
|
end
|
3688
4032
|
|
3689
4033
|
let(:child) do
|
3690
|
-
Even.create(parent_id: parent.id, name: "original even child")
|
4034
|
+
Even.create!(parent_id: parent.id, name: "original even child")
|
3691
4035
|
end
|
3692
4036
|
|
3693
4037
|
it "updates the child after accessing the parent" do
|
3694
|
-
# Access parent
|
4038
|
+
# Access parent association on the child to make sure it is loaded
|
3695
4039
|
child.parent
|
3696
4040
|
|
3697
4041
|
new_child_name = "updated even child"
|
@@ -3704,7 +4048,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3704
4048
|
end
|
3705
4049
|
end
|
3706
4050
|
|
3707
|
-
context 'when a document has referenced and embedded
|
4051
|
+
context 'when a document has referenced and embedded associations' do
|
3708
4052
|
|
3709
4053
|
let(:agent) do
|
3710
4054
|
Agent.new
|
@@ -3724,11 +4068,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3724
4068
|
end
|
3725
4069
|
|
3726
4070
|
it 'saves the document correctly' do
|
3727
|
-
expect(agent.save).to be(true)
|
4071
|
+
expect(agent.save!).to be(true)
|
3728
4072
|
end
|
3729
4073
|
end
|
3730
4074
|
|
3731
|
-
context 'when the two models use the same name to refer to the
|
4075
|
+
context 'when the two models use the same name to refer to the association' do
|
3732
4076
|
|
3733
4077
|
let(:agent) do
|
3734
4078
|
Agent.new
|
@@ -3740,8 +4084,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3740
4084
|
|
3741
4085
|
before do
|
3742
4086
|
agent.same_name = band
|
3743
|
-
agent.save
|
3744
|
-
band.save
|
4087
|
+
agent.save!
|
4088
|
+
band.save!
|
3745
4089
|
band.reload
|
3746
4090
|
end
|
3747
4091
|
|
@@ -3749,4 +4093,57 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3749
4093
|
expect(band.same_name).to eq([agent])
|
3750
4094
|
end
|
3751
4095
|
end
|
4096
|
+
|
4097
|
+
context "when removing a document with counter_cache on" do
|
4098
|
+
let(:post) { Post.create! }
|
4099
|
+
let(:person1) { Person.create! }
|
4100
|
+
let(:person2) { Person.create! }
|
4101
|
+
|
4102
|
+
before do
|
4103
|
+
post.update_attribute(:person, person1)
|
4104
|
+
expect(person1.posts_count).to eq 1
|
4105
|
+
|
4106
|
+
person2
|
4107
|
+
post.update_attribute(:person, person2)
|
4108
|
+
person1.reload
|
4109
|
+
expect(person1.posts_count).to eq 0
|
4110
|
+
expect(person2.posts_count).to eq 1
|
4111
|
+
|
4112
|
+
post.update_attribute(:person, nil)
|
4113
|
+
person1.reload
|
4114
|
+
person2.reload
|
4115
|
+
end
|
4116
|
+
|
4117
|
+
it "the count field is updated" do
|
4118
|
+
expect(person2.posts_count).to eq 0
|
4119
|
+
end
|
4120
|
+
end
|
4121
|
+
|
4122
|
+
context "when there is a foreign key in the aliased associations" do
|
4123
|
+
it "has the correct aliases" do
|
4124
|
+
expect(Band.aliased_associations["artist_ids"]).to eq("artists")
|
4125
|
+
expect(Artist.aliased_associations.key?("band_id")).to be false
|
4126
|
+
expect(Artist.aliased_fields["band"]).to eq("band_id")
|
4127
|
+
end
|
4128
|
+
end
|
4129
|
+
|
4130
|
+
context "when executing concat on foreign key array from the db" do
|
4131
|
+
config_override :legacy_attributes, false
|
4132
|
+
|
4133
|
+
before do
|
4134
|
+
Agent.create!
|
4135
|
+
Basic.create!
|
4136
|
+
end
|
4137
|
+
|
4138
|
+
let!(:agent) { Agent.first }
|
4139
|
+
let!(:basic) { Basic.first }
|
4140
|
+
|
4141
|
+
before do
|
4142
|
+
agent.basic_ids.concat([basic.id])
|
4143
|
+
end
|
4144
|
+
|
4145
|
+
it "works on the first attempt" do
|
4146
|
+
expect(agent.basic_ids).to eq([basic.id])
|
4147
|
+
end
|
4148
|
+
end
|
3752
4149
|
end
|