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,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
4
|
+
require_relative "../has_and_belongs_to_many_models"
|
2
5
|
|
3
6
|
describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
4
7
|
|
@@ -24,7 +27,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
24
27
|
context "when the inverse_of is nil" do
|
25
28
|
|
26
29
|
let!(:article) do
|
27
|
-
Article.create
|
30
|
+
Article.create!
|
28
31
|
end
|
29
32
|
|
30
33
|
context "when the child document is new" do
|
@@ -45,7 +48,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
45
48
|
context "when the child document is not new" do
|
46
49
|
|
47
50
|
let(:preference) do
|
48
|
-
Preference.create
|
51
|
+
Preference.create!
|
49
52
|
end
|
50
53
|
|
51
54
|
it "does not persist the child document" do
|
@@ -77,7 +80,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
77
80
|
context "when the parent is not a new record" do
|
78
81
|
|
79
82
|
let(:person) do
|
80
|
-
Person.create
|
83
|
+
Person.create!
|
81
84
|
end
|
82
85
|
|
83
86
|
let!(:preference) do
|
@@ -121,11 +124,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
121
124
|
context "when appending in a parent create block" do
|
122
125
|
|
123
126
|
let!(:preference) do
|
124
|
-
Preference.create(name: "testing")
|
127
|
+
Preference.create!(name: "testing")
|
125
128
|
end
|
126
129
|
|
127
130
|
let!(:person) do
|
128
|
-
Person.create do |doc|
|
131
|
+
Person.create! do |doc|
|
129
132
|
doc.preferences << preference
|
130
133
|
end
|
131
134
|
end
|
@@ -210,7 +213,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
210
213
|
context "when the child is already persisted" do
|
211
214
|
|
212
215
|
let!(:persisted) do
|
213
|
-
Preference.create(name: "testy")
|
216
|
+
Preference.create!(name: "testy")
|
214
217
|
end
|
215
218
|
|
216
219
|
let(:preference) do
|
@@ -219,7 +222,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
219
222
|
|
220
223
|
before do
|
221
224
|
person.preferences.send(method, preference)
|
222
|
-
person.save
|
225
|
+
person.save!
|
223
226
|
end
|
224
227
|
|
225
228
|
it "adds the documents to the relation" do
|
@@ -250,7 +253,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
250
253
|
context "when setting via the associated ids" do
|
251
254
|
|
252
255
|
let!(:persisted) do
|
253
|
-
Preference.create(name: "testy")
|
256
|
+
Preference.create!(name: "testy")
|
254
257
|
end
|
255
258
|
|
256
259
|
let(:preference) do
|
@@ -262,7 +265,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
262
265
|
end
|
263
266
|
|
264
267
|
before do
|
265
|
-
person.save
|
268
|
+
person.save!
|
266
269
|
end
|
267
270
|
|
268
271
|
it "adds the documents to the relation" do
|
@@ -290,7 +293,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
290
293
|
context "when the parent is not a new record" do
|
291
294
|
|
292
295
|
let(:person) do
|
293
|
-
Person.create
|
296
|
+
Person.create!
|
294
297
|
end
|
295
298
|
|
296
299
|
let(:preference) do
|
@@ -372,11 +375,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
372
375
|
context "when both sides have been persisted" do
|
373
376
|
|
374
377
|
let(:person) do
|
375
|
-
Person.create
|
378
|
+
Person.create!
|
376
379
|
end
|
377
380
|
|
378
381
|
let(:event) do
|
379
|
-
Event.create
|
382
|
+
Event.create!
|
380
383
|
end
|
381
384
|
|
382
385
|
before do
|
@@ -425,15 +428,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
425
428
|
context "when the relation also includes a has_many relation" do
|
426
429
|
|
427
430
|
let(:artwork) do
|
428
|
-
Artwork.create
|
431
|
+
Artwork.create!
|
429
432
|
end
|
430
433
|
|
431
434
|
let(:exhibition) do
|
432
|
-
Exhibition.create
|
435
|
+
Exhibition.create!
|
433
436
|
end
|
434
437
|
|
435
438
|
let(:exhibitor) do
|
436
|
-
Exhibitor.create(exhibition: exhibition)
|
439
|
+
Exhibitor.create!(exhibition: exhibition)
|
437
440
|
end
|
438
441
|
|
439
442
|
before do
|
@@ -448,11 +451,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
448
451
|
context "when the relation is self referencing" do
|
449
452
|
|
450
453
|
let(:tag_one) do
|
451
|
-
Tag.create(text: "one")
|
454
|
+
Tag.create!(text: "one")
|
452
455
|
end
|
453
456
|
|
454
457
|
let(:tag_two) do
|
455
|
-
Tag.create(text: "two")
|
458
|
+
Tag.create!(text: "two")
|
456
459
|
end
|
457
460
|
|
458
461
|
before do
|
@@ -561,7 +564,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
561
564
|
end
|
562
565
|
|
563
566
|
let(:preference) do
|
564
|
-
Preference.create(name: "one")
|
567
|
+
Preference.create!(name: "one")
|
565
568
|
end
|
566
569
|
|
567
570
|
before do
|
@@ -582,7 +585,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
582
585
|
context "when the document is persisted" do
|
583
586
|
|
584
587
|
before do
|
585
|
-
person.save
|
588
|
+
person.save!
|
586
589
|
end
|
587
590
|
|
588
591
|
it "does not add the duplicates" do
|
@@ -653,7 +656,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
653
656
|
end
|
654
657
|
|
655
658
|
let!(:preference) do
|
656
|
-
Preference.create
|
659
|
+
Preference.create!
|
657
660
|
end
|
658
661
|
|
659
662
|
before do
|
@@ -700,7 +703,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
700
703
|
context "when the parent is not a new record" do
|
701
704
|
|
702
705
|
let(:person) do
|
703
|
-
Person.create
|
706
|
+
Person.create!
|
704
707
|
end
|
705
708
|
|
706
709
|
let(:preference) do
|
@@ -784,7 +787,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
784
787
|
expect(person.preferences).to eq([ another_preference ])
|
785
788
|
end
|
786
789
|
|
787
|
-
it "persists the relation between
|
790
|
+
it "persists the relation between another_preference and person" do
|
788
791
|
expect(another_preference.people).to eq([ person ])
|
789
792
|
end
|
790
793
|
|
@@ -796,7 +799,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
796
799
|
context "and person is saved" do
|
797
800
|
|
798
801
|
before do
|
799
|
-
person.save
|
802
|
+
person.save!
|
800
803
|
person.reload
|
801
804
|
another_preference.reload
|
802
805
|
end
|
@@ -805,7 +808,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
805
808
|
expect(person.preferences).to eq([ another_preference ])
|
806
809
|
end
|
807
810
|
|
808
|
-
it "persists the relation between
|
811
|
+
it "persists the relation between another_preference and person" do
|
809
812
|
expect(another_preference.people).to eq([ person ])
|
810
813
|
end
|
811
814
|
|
@@ -820,11 +823,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
820
823
|
|
821
824
|
describe "when self-referencing" do
|
822
825
|
let!(:parent) do
|
823
|
-
Vertex.create
|
826
|
+
Vertex.create!
|
824
827
|
end
|
825
828
|
|
826
829
|
let!(:child) do
|
827
|
-
Vertex.create(parents: [parent])
|
830
|
+
Vertex.create!(parents: [parent])
|
828
831
|
end
|
829
832
|
|
830
833
|
before do
|
@@ -961,7 +964,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
961
964
|
context "when the relation has been loaded" do
|
962
965
|
|
963
966
|
let(:person) do
|
964
|
-
Person.create
|
967
|
+
Person.create!
|
965
968
|
end
|
966
969
|
|
967
970
|
let(:preference) do
|
@@ -1001,7 +1004,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1001
1004
|
end
|
1002
1005
|
|
1003
1006
|
let(:person) do
|
1004
|
-
Person.create
|
1007
|
+
Person.create!.tap do |p|
|
1005
1008
|
p.preferences = [ preference ]
|
1006
1009
|
end
|
1007
1010
|
end
|
@@ -1071,7 +1074,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1071
1074
|
context "when the parent is not a new record" do
|
1072
1075
|
|
1073
1076
|
let(:person) do
|
1074
|
-
Person.create
|
1077
|
+
Person.create!
|
1075
1078
|
end
|
1076
1079
|
|
1077
1080
|
let!(:preference) do
|
@@ -1109,7 +1112,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1109
1112
|
context "when saving the target" do
|
1110
1113
|
|
1111
1114
|
before do
|
1112
|
-
preference.save
|
1115
|
+
preference.save!
|
1113
1116
|
end
|
1114
1117
|
|
1115
1118
|
it "persists the parent keys" do
|
@@ -1128,13 +1131,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1128
1131
|
context "when the parent has been persisted" do
|
1129
1132
|
|
1130
1133
|
let!(:person) do
|
1131
|
-
Person.create
|
1134
|
+
Person.create!
|
1132
1135
|
end
|
1133
1136
|
|
1134
1137
|
context "when the children are persisted" do
|
1135
1138
|
|
1136
1139
|
let!(:preference) do
|
1137
|
-
person.preferences.create(name: "settings")
|
1140
|
+
person.preferences.create!(name: "settings")
|
1138
1141
|
end
|
1139
1142
|
|
1140
1143
|
let!(:relation) do
|
@@ -1306,7 +1309,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1306
1309
|
context "when the parent is not a new record" do
|
1307
1310
|
|
1308
1311
|
let(:person) do
|
1309
|
-
Person.create
|
1312
|
+
Person.create!
|
1310
1313
|
end
|
1311
1314
|
|
1312
1315
|
let!(:preference) do
|
@@ -1350,11 +1353,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1350
1353
|
context "when appending in a parent create block" do
|
1351
1354
|
|
1352
1355
|
let!(:preference) do
|
1353
|
-
Preference.create(name: "testing")
|
1356
|
+
Preference.create!(name: "testing")
|
1354
1357
|
end
|
1355
1358
|
|
1356
1359
|
let!(:person) do
|
1357
|
-
Person.create do |doc|
|
1360
|
+
Person.create! do |doc|
|
1358
1361
|
doc.preferences.concat([ preference ])
|
1359
1362
|
end
|
1360
1363
|
end
|
@@ -1439,7 +1442,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1439
1442
|
context "when the child is already persisted" do
|
1440
1443
|
|
1441
1444
|
let!(:persisted) do
|
1442
|
-
Preference.create(name: "testy")
|
1445
|
+
Preference.create!(name: "testy")
|
1443
1446
|
end
|
1444
1447
|
|
1445
1448
|
let(:preference) do
|
@@ -1448,7 +1451,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1448
1451
|
|
1449
1452
|
before do
|
1450
1453
|
person.preferences.concat([ preference ])
|
1451
|
-
person.save
|
1454
|
+
person.save!
|
1452
1455
|
end
|
1453
1456
|
|
1454
1457
|
it "adds the documents to the relation" do
|
@@ -1479,7 +1482,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1479
1482
|
context "when setting via the associated ids" do
|
1480
1483
|
|
1481
1484
|
let!(:persisted) do
|
1482
|
-
Preference.create(name: "testy")
|
1485
|
+
Preference.create!(name: "testy")
|
1483
1486
|
end
|
1484
1487
|
|
1485
1488
|
let(:preference) do
|
@@ -1491,7 +1494,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1491
1494
|
end
|
1492
1495
|
|
1493
1496
|
before do
|
1494
|
-
person.save
|
1497
|
+
person.save!
|
1495
1498
|
end
|
1496
1499
|
|
1497
1500
|
it "adds the documents to the relation" do
|
@@ -1519,7 +1522,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1519
1522
|
context "when the parent is not a new record" do
|
1520
1523
|
|
1521
1524
|
let(:person) do
|
1522
|
-
Person.create
|
1525
|
+
Person.create!
|
1523
1526
|
end
|
1524
1527
|
|
1525
1528
|
let(:preference) do
|
@@ -1601,11 +1604,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1601
1604
|
context "when both sides have been persisted" do
|
1602
1605
|
|
1603
1606
|
let(:person) do
|
1604
|
-
Person.create
|
1607
|
+
Person.create!
|
1605
1608
|
end
|
1606
1609
|
|
1607
1610
|
let(:event) do
|
1608
|
-
Event.create
|
1611
|
+
Event.create!
|
1609
1612
|
end
|
1610
1613
|
|
1611
1614
|
before do
|
@@ -1654,15 +1657,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1654
1657
|
context "when the relation also includes a has_many relation" do
|
1655
1658
|
|
1656
1659
|
let(:artwork) do
|
1657
|
-
Artwork.create
|
1660
|
+
Artwork.create!
|
1658
1661
|
end
|
1659
1662
|
|
1660
1663
|
let(:exhibition) do
|
1661
|
-
Exhibition.create
|
1664
|
+
Exhibition.create!
|
1662
1665
|
end
|
1663
1666
|
|
1664
1667
|
let(:exhibitor) do
|
1665
|
-
Exhibitor.create(exhibition: exhibition)
|
1668
|
+
Exhibitor.create!(exhibition: exhibition)
|
1666
1669
|
end
|
1667
1670
|
|
1668
1671
|
before do
|
@@ -1677,11 +1680,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1677
1680
|
context "when the relation is self referencing" do
|
1678
1681
|
|
1679
1682
|
let(:tag_one) do
|
1680
|
-
Tag.create(text: "one")
|
1683
|
+
Tag.create!(text: "one")
|
1681
1684
|
end
|
1682
1685
|
|
1683
1686
|
let(:tag_two) do
|
1684
|
-
Tag.create(text: "two")
|
1687
|
+
Tag.create!(text: "two")
|
1685
1688
|
end
|
1686
1689
|
|
1687
1690
|
before do
|
@@ -1732,7 +1735,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1732
1735
|
describe "#count" do
|
1733
1736
|
|
1734
1737
|
let(:person) do
|
1735
|
-
Person.create
|
1738
|
+
Person.create!
|
1736
1739
|
end
|
1737
1740
|
|
1738
1741
|
context "when nothing exists on the relation" do
|
@@ -1757,7 +1760,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1757
1760
|
describe "#any?" do
|
1758
1761
|
|
1759
1762
|
let(:person) do
|
1760
|
-
Person.create
|
1763
|
+
Person.create!
|
1761
1764
|
end
|
1762
1765
|
|
1763
1766
|
context "when nothing exists on the relation" do
|
@@ -1794,7 +1797,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1794
1797
|
context "when documents have been persisted" do
|
1795
1798
|
|
1796
1799
|
let!(:preference) do
|
1797
|
-
person.preferences.create(name: "setting")
|
1800
|
+
person.preferences.create!(name: "setting")
|
1798
1801
|
end
|
1799
1802
|
|
1800
1803
|
it "returns the number of persisted documents" do
|
@@ -1805,12 +1808,12 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1805
1808
|
context "when appending to a loaded relation" do
|
1806
1809
|
|
1807
1810
|
let!(:preference) do
|
1808
|
-
person.preferences.create(name: "setting")
|
1811
|
+
person.preferences.create!(name: "setting")
|
1809
1812
|
end
|
1810
1813
|
|
1811
1814
|
before do
|
1812
1815
|
person.preferences.count
|
1813
|
-
person.preferences << Preference.create(name: "two")
|
1816
|
+
person.preferences << Preference.create!(name: "two")
|
1814
1817
|
end
|
1815
1818
|
|
1816
1819
|
it "returns the number of persisted documents" do
|
@@ -1834,7 +1837,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1834
1837
|
context "when the documents are part of the relation" do
|
1835
1838
|
|
1836
1839
|
before do
|
1837
|
-
Preference.create(person_ids: [ person.id ])
|
1840
|
+
Preference.create!(person_ids: [ person.id ])
|
1838
1841
|
end
|
1839
1842
|
|
1840
1843
|
it "returns the count from the db" do
|
@@ -1845,7 +1848,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1845
1848
|
context "when the documents are not part of the relation" do
|
1846
1849
|
|
1847
1850
|
before do
|
1848
|
-
Preference.create
|
1851
|
+
Preference.create!
|
1849
1852
|
end
|
1850
1853
|
|
1851
1854
|
it "returns the count from the db" do
|
@@ -1859,7 +1862,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1859
1862
|
context "when documents have been persisted" do
|
1860
1863
|
|
1861
1864
|
let!(:house) do
|
1862
|
-
person.houses.create(name: "Wayne Manor")
|
1865
|
+
person.houses.create!(name: "Wayne Manor")
|
1863
1866
|
end
|
1864
1867
|
|
1865
1868
|
it "returns the number of persisted documents" do
|
@@ -1883,7 +1886,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1883
1886
|
describe "#any?" do
|
1884
1887
|
|
1885
1888
|
let(:sandwich) do
|
1886
|
-
Sandwich.create
|
1889
|
+
Sandwich.create!
|
1887
1890
|
end
|
1888
1891
|
|
1889
1892
|
context "when nothing exists on the relation" do
|
@@ -1951,7 +1954,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1951
1954
|
context "when documents have been persisted" do
|
1952
1955
|
|
1953
1956
|
let!(:meat) do
|
1954
|
-
sandwich.meats.create
|
1957
|
+
sandwich.meats.create!
|
1955
1958
|
end
|
1956
1959
|
|
1957
1960
|
it "returns true" do
|
@@ -1972,7 +1975,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1972
1975
|
|
1973
1976
|
context "when new documents exist in the database" do
|
1974
1977
|
before do
|
1975
|
-
Meat.create(sandwiches: [sandwich])
|
1978
|
+
Meat.create!(sandwiches: [sandwich])
|
1976
1979
|
end
|
1977
1980
|
|
1978
1981
|
it "returns true" do
|
@@ -1990,15 +1993,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1990
1993
|
context "when using string keys" do
|
1991
1994
|
|
1992
1995
|
let(:agent) do
|
1993
|
-
Agent.create(number: "007")
|
1996
|
+
Agent.create!(number: "007")
|
1994
1997
|
end
|
1995
1998
|
|
1996
1999
|
before do
|
1997
|
-
agent.accounts.
|
2000
|
+
agent.accounts.send(method, name: "test again")
|
1998
2001
|
end
|
1999
2002
|
|
2000
2003
|
it "does not convert the string key to an object id" do
|
2001
|
-
expect(agent.account_ids).to eq([ "
|
2004
|
+
expect(agent.account_ids).to eq([ "test-again" ])
|
2002
2005
|
end
|
2003
2006
|
end
|
2004
2007
|
|
@@ -2070,7 +2073,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2070
2073
|
context "when validation fails" do
|
2071
2074
|
|
2072
2075
|
let(:person) do
|
2073
|
-
Person.create
|
2076
|
+
Person.create!
|
2074
2077
|
end
|
2075
2078
|
|
2076
2079
|
context "when the relation is not polymorphic" do
|
@@ -2084,290 +2087,236 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2084
2087
|
end
|
2085
2088
|
end
|
2086
2089
|
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2090
|
+
%i[ delete delete_one ].each do |method|
|
2091
|
+
describe "\##{method}" do
|
2092
|
+
let(:person) { Person.create! }
|
2093
|
+
let(:preference_one) { Preference.create!(name: "Testing") }
|
2094
|
+
let(:preference_two) { Preference.create!(name: "Test") }
|
2092
2095
|
|
2093
|
-
|
2094
|
-
|
2095
|
-
end
|
2096
|
-
|
2097
|
-
let(:preference_two) do
|
2098
|
-
Preference.create(name: "Test")
|
2099
|
-
end
|
2100
|
-
|
2101
|
-
before do
|
2102
|
-
person.preferences << [ preference_one, preference_two ]
|
2103
|
-
end
|
2104
|
-
|
2105
|
-
context "when the document exists" do
|
2106
|
-
|
2107
|
-
let!(:deleted) do
|
2108
|
-
person.preferences.delete(preference_one)
|
2109
|
-
end
|
2110
|
-
|
2111
|
-
it "removes the document from the relation" do
|
2112
|
-
expect(person.preferences).to eq([ preference_two ])
|
2113
|
-
end
|
2114
|
-
|
2115
|
-
it "returns the document" do
|
2116
|
-
expect(deleted).to eq(preference_one)
|
2117
|
-
end
|
2118
|
-
|
2119
|
-
it "removes the document key from the foreign key" do
|
2120
|
-
expect(person.preference_ids).to eq([ preference_two.id ])
|
2121
|
-
end
|
2122
|
-
|
2123
|
-
it "removes the inverse reference" do
|
2124
|
-
expect(deleted.reload.people).to be_empty
|
2125
|
-
end
|
2126
|
-
|
2127
|
-
it "removes the base id from the inverse keys" do
|
2128
|
-
expect(deleted.reload.person_ids).to be_empty
|
2096
|
+
before do
|
2097
|
+
person.preferences << [ preference_one, preference_two ]
|
2129
2098
|
end
|
2130
2099
|
|
2131
|
-
context
|
2132
|
-
|
2133
|
-
|
2134
|
-
person.reload
|
2135
|
-
preference_one.reload
|
2136
|
-
preference_two.reload
|
2100
|
+
context 'when the document exists' do
|
2101
|
+
let!(:deleted) do
|
2102
|
+
person.preferences.send(method, preference_one)
|
2137
2103
|
end
|
2138
2104
|
|
2139
|
-
it
|
2105
|
+
it 'removes the document from the relation' do
|
2140
2106
|
expect(person.preferences).to eq([ preference_two ])
|
2141
2107
|
end
|
2142
2108
|
|
2143
|
-
it
|
2144
|
-
expect(
|
2109
|
+
it 'returns the document' do
|
2110
|
+
expect(deleted).to eq(preference_one)
|
2145
2111
|
end
|
2146
|
-
end
|
2147
|
-
end
|
2148
|
-
|
2149
|
-
context "when the document does not exist" do
|
2150
|
-
|
2151
|
-
let!(:deleted) do
|
2152
|
-
person.preferences.delete(Preference.new)
|
2153
|
-
end
|
2154
|
-
|
2155
|
-
it "returns nil" do
|
2156
|
-
expect(deleted).to be_nil
|
2157
|
-
end
|
2158
|
-
|
2159
|
-
it "does not modify the relation" do
|
2160
|
-
expect(person.preferences).to eq([ preference_one, preference_two ])
|
2161
|
-
end
|
2162
|
-
|
2163
|
-
it "does not modify the keys" do
|
2164
|
-
expect(person.preference_ids).to eq([ preference_one.id, preference_two.id ])
|
2165
|
-
end
|
2166
|
-
end
|
2167
|
-
|
2168
|
-
context "when :dependent => :nullify is set" do
|
2169
|
-
|
2170
|
-
context "when :inverse_of is set" do
|
2171
2112
|
|
2172
|
-
|
2173
|
-
|
2113
|
+
it 'removes the document key from the foreign key' do
|
2114
|
+
expect(person.preference_ids).to eq([ preference_two.id ])
|
2174
2115
|
end
|
2175
2116
|
|
2176
|
-
|
2177
|
-
|
2117
|
+
it 'removes the inverse reference' do
|
2118
|
+
expect(deleted.reload.people).to be_empty
|
2178
2119
|
end
|
2179
2120
|
|
2180
|
-
it
|
2181
|
-
expect(
|
2121
|
+
it 'removes the base id from the inverse keys' do
|
2122
|
+
expect(deleted.reload.person_ids).to be_empty
|
2182
2123
|
end
|
2183
|
-
end
|
2184
|
-
end
|
2185
2124
|
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2125
|
+
context 'and person and preferences are reloaded' do
|
2126
|
+
before do
|
2127
|
+
person.reload
|
2128
|
+
preference_one.reload
|
2129
|
+
preference_two.reload
|
2130
|
+
end
|
2191
2131
|
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2132
|
+
it 'nullifies the deleted preference' do
|
2133
|
+
expect(person.preferences).to eq([ preference_two ])
|
2134
|
+
end
|
2195
2135
|
|
2196
|
-
|
2197
|
-
|
2136
|
+
it 'retains the ids for one preference' do
|
2137
|
+
expect(person.preference_ids).to eq([ preference_two.id ])
|
2138
|
+
end
|
2139
|
+
end
|
2198
2140
|
end
|
2199
2141
|
|
2200
|
-
context
|
2201
|
-
|
2142
|
+
context 'when the document does not exist' do
|
2202
2143
|
let!(:deleted) do
|
2203
|
-
|
2204
|
-
end
|
2205
|
-
|
2206
|
-
it "deletes the document from the relation" do
|
2207
|
-
expect(tag_one.related).to be_empty
|
2144
|
+
person.preferences.send(method, Preference.new)
|
2208
2145
|
end
|
2209
2146
|
|
2210
|
-
it
|
2211
|
-
expect(
|
2147
|
+
it 'returns nil' do
|
2148
|
+
expect(deleted).to be_nil
|
2212
2149
|
end
|
2213
2150
|
|
2214
|
-
it
|
2215
|
-
expect(
|
2151
|
+
it 'does not modify the relation' do
|
2152
|
+
expect(person.preferences).to eq([ preference_one, preference_two ])
|
2216
2153
|
end
|
2217
2154
|
|
2218
|
-
it
|
2219
|
-
expect(
|
2155
|
+
it 'does not modify the keys' do
|
2156
|
+
expect(person.preference_ids).to eq([ preference_one.id, preference_two.id ])
|
2220
2157
|
end
|
2221
2158
|
end
|
2222
2159
|
|
2223
|
-
context
|
2160
|
+
context 'when :dependent => :nullify is set' do
|
2161
|
+
context 'when :inverse_of is set' do
|
2162
|
+
let(:event) { Event.create! }
|
2224
2163
|
|
2225
|
-
|
2226
|
-
|
2227
|
-
let(:reloaded) do
|
2228
|
-
tag_one.reload
|
2229
|
-
end
|
2230
|
-
|
2231
|
-
let!(:deleted) do
|
2232
|
-
reloaded.related.delete(tag_two)
|
2233
|
-
end
|
2234
|
-
|
2235
|
-
it "deletes the document from the relation" do
|
2236
|
-
expect(reloaded.related).to be_empty
|
2164
|
+
before do
|
2165
|
+
person.administrated_events << [ event ]
|
2237
2166
|
end
|
2238
2167
|
|
2239
|
-
it
|
2240
|
-
expect(
|
2168
|
+
it 'deletes the document' do
|
2169
|
+
expect(event.delete).to be true
|
2241
2170
|
end
|
2171
|
+
end
|
2172
|
+
end
|
2242
2173
|
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2174
|
+
context 'when the relationships are self referencing' do
|
2175
|
+
let(:tag_one) { Tag.create!(text: "one") }
|
2176
|
+
let(:tag_two) { Tag.create!(text: "two") }
|
2246
2177
|
|
2247
|
-
|
2248
|
-
|
2249
|
-
end
|
2178
|
+
before do
|
2179
|
+
tag_one.related << tag_two
|
2250
2180
|
end
|
2251
2181
|
|
2252
|
-
context
|
2182
|
+
context 'when deleting without reloading' do
|
2183
|
+
let!(:deleted) { tag_one.related.send(method, tag_two) }
|
2253
2184
|
|
2254
|
-
|
2255
|
-
|
2185
|
+
it 'deletes the document from the relation' do
|
2186
|
+
expect(tag_one.related).to be_empty
|
2256
2187
|
end
|
2257
2188
|
|
2258
|
-
|
2259
|
-
|
2260
|
-
end
|
2261
|
-
|
2262
|
-
it "deletes the document from the relation" do
|
2263
|
-
expect(reloaded.related).to be_empty
|
2189
|
+
it 'deletes the foreign key from the relation' do
|
2190
|
+
expect(tag_one.related_ids).to be_empty
|
2264
2191
|
end
|
2265
2192
|
|
2266
|
-
it
|
2267
|
-
expect(
|
2193
|
+
it 'removes the reference from the inverse' do
|
2194
|
+
expect(deleted.related).to be_empty
|
2268
2195
|
end
|
2269
2196
|
|
2270
|
-
it
|
2197
|
+
it 'removes the foreign keys from the inverse' do
|
2271
2198
|
expect(deleted.related_ids).to be_empty
|
2272
2199
|
end
|
2273
2200
|
end
|
2274
|
-
end
|
2275
|
-
end
|
2276
2201
|
|
2277
|
-
|
2202
|
+
context 'when deleting with reloading' do
|
2203
|
+
context "when deleting from the front side" do
|
2204
|
+
let(:reloaded) { tag_one.reload }
|
2205
|
+
let!(:deleted) { reloaded.related.send(method, tag_two) }
|
2278
2206
|
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2207
|
+
it 'deletes the document from the relation' do
|
2208
|
+
expect(reloaded.related).to be_empty
|
2209
|
+
end
|
2282
2210
|
|
2283
|
-
|
2284
|
-
|
2285
|
-
|
2211
|
+
it 'deletes the foreign key from the relation' do
|
2212
|
+
expect(reloaded.related_ids).to be_empty
|
2213
|
+
end
|
2286
2214
|
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2215
|
+
it 'removes the reference from the inverse' do
|
2216
|
+
expect(deleted.related).to be_empty
|
2217
|
+
end
|
2290
2218
|
|
2291
|
-
|
2219
|
+
it 'removes the foreign keys from the inverse' do
|
2220
|
+
expect(deleted.related_ids).to be_empty
|
2221
|
+
end
|
2222
|
+
end
|
2292
2223
|
|
2293
|
-
|
2224
|
+
context 'when deleting from the inverse side' do
|
2225
|
+
let(:reloaded) { tag_two.reload }
|
2226
|
+
let!(:deleted) { reloaded.related.send(method, tag_one) }
|
2294
2227
|
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2228
|
+
it 'deletes the document from the relation' do
|
2229
|
+
expect(reloaded.related).to be_empty
|
2230
|
+
end
|
2298
2231
|
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2232
|
+
it 'deletes the foreign key from the relation' do
|
2233
|
+
expect(reloaded.related_ids).to be_empty
|
2234
|
+
end
|
2302
2235
|
|
2303
|
-
|
2304
|
-
|
2236
|
+
it 'removes the foreign keys from the inverse' do
|
2237
|
+
expect(deleted.related_ids).to be_empty
|
2238
|
+
end
|
2305
2239
|
end
|
2306
2240
|
end
|
2241
|
+
end
|
2307
2242
|
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
expect(post).to receive(:before_remove_tag).and_raise
|
2312
|
-
begin; post.tags.delete(tag); rescue; end
|
2313
|
-
end
|
2243
|
+
context 'when the association has callbacks' do
|
2244
|
+
let(:post) { Post.new }
|
2245
|
+
let(:tag) { Tag.new }
|
2314
2246
|
|
2315
|
-
|
2316
|
-
|
2317
|
-
end
|
2247
|
+
before do
|
2248
|
+
post.tags << tag
|
2318
2249
|
end
|
2319
|
-
end
|
2320
2250
|
|
2321
|
-
|
2251
|
+
context 'when the callback is a before_remove' do
|
2252
|
+
context 'when there are no errors' do
|
2253
|
+
before do
|
2254
|
+
post.tags.send(method, tag)
|
2255
|
+
end
|
2322
2256
|
|
2323
|
-
|
2257
|
+
it 'executes the callback' do
|
2258
|
+
expect(post.before_remove_called).to be true
|
2259
|
+
end
|
2324
2260
|
|
2325
|
-
|
2326
|
-
|
2261
|
+
it 'removes the document from the relation' do
|
2262
|
+
expect(post.tags).to be_empty
|
2263
|
+
end
|
2327
2264
|
end
|
2328
2265
|
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2266
|
+
context "when errors are raised" do
|
2267
|
+
before do
|
2268
|
+
expect(post).to receive(:before_remove_tag).and_raise
|
2269
|
+
begin; post.tags.send(method, tag); rescue; end
|
2270
|
+
end
|
2332
2271
|
|
2333
|
-
|
2334
|
-
|
2272
|
+
it 'does not remove the document from the relation' do
|
2273
|
+
expect(post.tags).to eq([ tag ])
|
2274
|
+
end
|
2335
2275
|
end
|
2336
2276
|
end
|
2337
2277
|
|
2338
|
-
context
|
2278
|
+
context 'when the callback is an after_remove' do
|
2279
|
+
context 'when no errors are raised' do
|
2280
|
+
before do
|
2281
|
+
post.tags.send(method, tag)
|
2282
|
+
end
|
2339
2283
|
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2284
|
+
it 'executes the callback' do
|
2285
|
+
expect(post.after_remove_called).to be true
|
2286
|
+
end
|
2287
|
+
|
2288
|
+
it 'removes the document from the relation' do
|
2289
|
+
expect(post.tags).to be_empty
|
2290
|
+
end
|
2343
2291
|
end
|
2344
2292
|
|
2345
|
-
|
2346
|
-
|
2293
|
+
context 'when errors are raised' do
|
2294
|
+
before do
|
2295
|
+
expect(post).to receive(:after_remove_tag).and_raise
|
2296
|
+
begin; post.tags.send(method, tag); rescue; end
|
2297
|
+
end
|
2298
|
+
|
2299
|
+
it 'removes the document from the relation' do
|
2300
|
+
expect(post.tags).to be_empty
|
2301
|
+
end
|
2347
2302
|
end
|
2348
2303
|
end
|
2349
2304
|
end
|
2350
2305
|
end
|
2351
2306
|
end
|
2352
2307
|
|
2353
|
-
[
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
context "when conditions are provided" do
|
2360
|
-
|
2361
|
-
let(:person) do
|
2362
|
-
Person.create
|
2363
|
-
end
|
2308
|
+
%i[ delete_all destroy_all ].each do |method|
|
2309
|
+
describe "\##{method}" do
|
2310
|
+
context 'when the relation is not polymorphic' do
|
2311
|
+
context 'when conditions are provided' do
|
2312
|
+
let(:person) { Person.create! }
|
2364
2313
|
|
2365
2314
|
let!(:preference_one) do
|
2366
|
-
person.preferences.create(name: "Testing")
|
2315
|
+
person.preferences.create!(name: "Testing")
|
2367
2316
|
end
|
2368
2317
|
|
2369
2318
|
let!(:preference_two) do
|
2370
|
-
person.preferences.create(name: "Test")
|
2319
|
+
person.preferences.create!(name: "Test")
|
2371
2320
|
end
|
2372
2321
|
|
2373
2322
|
let!(:deleted) do
|
@@ -2392,14 +2341,18 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2392
2341
|
it "removes the ids from the foreign key" do
|
2393
2342
|
expect(person.preference_ids).to eq([ preference_two.id ])
|
2394
2343
|
end
|
2344
|
+
|
2345
|
+
it "sets the association locally" do
|
2346
|
+
expect(person.preferences).to eq([preference_two])
|
2347
|
+
end
|
2395
2348
|
end
|
2396
2349
|
|
2397
2350
|
context "when conditions are not provided" do
|
2398
2351
|
|
2399
2352
|
let(:person) do
|
2400
|
-
Person.create
|
2401
|
-
person.preferences.create(name: "Testing")
|
2402
|
-
person.preferences.create(name: "Test")
|
2353
|
+
Person.create!.tap do |person|
|
2354
|
+
person.preferences.create!(name: "Testing")
|
2355
|
+
person.preferences.create!(name: "Test")
|
2403
2356
|
end
|
2404
2357
|
end
|
2405
2358
|
|
@@ -2418,6 +2371,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2418
2371
|
it "returns the number of documents deleted" do
|
2419
2372
|
expect(deleted).to eq(2)
|
2420
2373
|
end
|
2374
|
+
|
2375
|
+
it "sets the association locally" do
|
2376
|
+
expect(person.preferences).to eq([])
|
2377
|
+
end
|
2421
2378
|
end
|
2422
2379
|
end
|
2423
2380
|
end
|
@@ -2433,13 +2390,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2433
2390
|
describe "#exists?" do
|
2434
2391
|
|
2435
2392
|
let!(:person) do
|
2436
|
-
Person.create
|
2393
|
+
Person.create!
|
2437
2394
|
end
|
2438
2395
|
|
2439
2396
|
context "when documents exist in the database" do
|
2440
2397
|
|
2441
2398
|
before do
|
2442
|
-
person.preferences.create
|
2399
|
+
person.preferences.create!
|
2443
2400
|
end
|
2444
2401
|
|
2445
2402
|
it "returns true" do
|
@@ -2464,23 +2421,23 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2464
2421
|
context "when the relation is not polymorphic" do
|
2465
2422
|
|
2466
2423
|
let(:person) do
|
2467
|
-
Person.create
|
2424
|
+
Person.create!
|
2468
2425
|
end
|
2469
2426
|
|
2470
2427
|
let!(:preference_one) do
|
2471
|
-
person.preferences.create(name: "Test")
|
2428
|
+
person.preferences.create!(name: "Test")
|
2472
2429
|
end
|
2473
2430
|
|
2474
2431
|
let!(:preference_two) do
|
2475
|
-
person.preferences.create(name: "OMG I has relations")
|
2432
|
+
person.preferences.create!(name: "OMG I has relations")
|
2476
2433
|
end
|
2477
2434
|
|
2478
2435
|
let!(:unrelated_pref) do
|
2479
|
-
Preference.create(name: "orphan annie")
|
2436
|
+
Preference.create!(name: "orphan annie")
|
2480
2437
|
end
|
2481
2438
|
|
2482
2439
|
let!(:unrelated_pref_two) do
|
2483
|
-
Preference.create(name: "orphan two")
|
2440
|
+
Preference.create!(name: "orphan two")
|
2484
2441
|
end
|
2485
2442
|
|
2486
2443
|
context "when providing an id" do
|
@@ -2505,7 +2462,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2505
2462
|
it "raises an error" do
|
2506
2463
|
expect {
|
2507
2464
|
preference
|
2508
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2465
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2509
2466
|
end
|
2510
2467
|
end
|
2511
2468
|
|
@@ -2520,7 +2477,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2520
2477
|
it "raises an error" do
|
2521
2478
|
expect {
|
2522
2479
|
person.preferences.find(BSON::ObjectId.new)
|
2523
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2480
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2524
2481
|
end
|
2525
2482
|
end
|
2526
2483
|
|
@@ -2558,7 +2515,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2558
2515
|
end
|
2559
2516
|
end
|
2560
2517
|
|
2561
|
-
context "when the ids
|
2518
|
+
context "when the ids match unreferenced documents" do
|
2562
2519
|
|
2563
2520
|
let(:preferences) do
|
2564
2521
|
person.preferences.find(
|
@@ -2569,7 +2526,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2569
2526
|
it "raises an error" do
|
2570
2527
|
expect {
|
2571
2528
|
preferences
|
2572
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2529
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2573
2530
|
end
|
2574
2531
|
end
|
2575
2532
|
|
@@ -2584,7 +2541,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2584
2541
|
it "raises an error" do
|
2585
2542
|
expect {
|
2586
2543
|
person.preferences.find([ BSON::ObjectId.new ])
|
2587
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2544
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2588
2545
|
end
|
2589
2546
|
end
|
2590
2547
|
|
@@ -2616,11 +2573,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2616
2573
|
context "when the relation is not polymorphic" do
|
2617
2574
|
|
2618
2575
|
let(:person) do
|
2619
|
-
Person.create
|
2576
|
+
Person.create!
|
2620
2577
|
end
|
2621
2578
|
|
2622
2579
|
let!(:preference) do
|
2623
|
-
person.preferences.create(name: "Testing")
|
2580
|
+
person.preferences.create!(name: "Testing")
|
2624
2581
|
end
|
2625
2582
|
|
2626
2583
|
context "when the document exists" do
|
@@ -2656,11 +2613,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2656
2613
|
context "when the relation is not polymorphic" do
|
2657
2614
|
|
2658
2615
|
let(:person) do
|
2659
|
-
Person.create
|
2616
|
+
Person.create!
|
2660
2617
|
end
|
2661
2618
|
|
2662
2619
|
let!(:preference) do
|
2663
|
-
person.preferences.create(name: "Testing")
|
2620
|
+
person.preferences.create!(name: "Testing")
|
2664
2621
|
end
|
2665
2622
|
|
2666
2623
|
context "when the document exists" do
|
@@ -2705,11 +2662,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2705
2662
|
context "when the relation is not polymorphic" do
|
2706
2663
|
|
2707
2664
|
let(:person) do
|
2708
|
-
Person.create
|
2665
|
+
Person.create!
|
2709
2666
|
end
|
2710
2667
|
|
2711
2668
|
let!(:preference) do
|
2712
|
-
person.preferences.create(name: "Testing")
|
2669
|
+
person.preferences.create!(name: "Testing")
|
2713
2670
|
end
|
2714
2671
|
|
2715
2672
|
context "when the document exists" do
|
@@ -2743,15 +2700,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2743
2700
|
describe "#max" do
|
2744
2701
|
|
2745
2702
|
let(:person) do
|
2746
|
-
Person.create
|
2703
|
+
Person.create!
|
2747
2704
|
end
|
2748
2705
|
|
2749
2706
|
let(:preference_one) do
|
2750
|
-
Preference.create(ranking: 5)
|
2707
|
+
Preference.create!(ranking: 5)
|
2751
2708
|
end
|
2752
2709
|
|
2753
2710
|
let(:preference_two) do
|
2754
|
-
Preference.create(ranking: 10)
|
2711
|
+
Preference.create!(ranking: 10)
|
2755
2712
|
end
|
2756
2713
|
|
2757
2714
|
before do
|
@@ -2772,15 +2729,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2772
2729
|
describe "#max_by" do
|
2773
2730
|
|
2774
2731
|
let(:person) do
|
2775
|
-
Person.create
|
2732
|
+
Person.create!
|
2776
2733
|
end
|
2777
2734
|
|
2778
2735
|
let(:preference_one) do
|
2779
|
-
Preference.create(ranking: 5)
|
2736
|
+
Preference.create!(ranking: 5)
|
2780
2737
|
end
|
2781
2738
|
|
2782
2739
|
let(:preference_two) do
|
2783
|
-
Preference.create(ranking: 10)
|
2740
|
+
Preference.create!(ranking: 10)
|
2784
2741
|
end
|
2785
2742
|
|
2786
2743
|
before do
|
@@ -2799,19 +2756,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2799
2756
|
describe "#method_missing" do
|
2800
2757
|
|
2801
2758
|
let!(:person) do
|
2802
|
-
Person.create
|
2759
|
+
Person.create!
|
2803
2760
|
end
|
2804
2761
|
|
2805
2762
|
let!(:preference_one) do
|
2806
|
-
person.preferences.create(name: "First", value: "Posting")
|
2763
|
+
person.preferences.create!(name: "First", value: "Posting")
|
2807
2764
|
end
|
2808
2765
|
|
2809
2766
|
let!(:preference_two) do
|
2810
|
-
person.preferences.create(name: "Second", value: "Testing")
|
2767
|
+
person.preferences.create!(name: "Second", value: "Testing")
|
2811
2768
|
end
|
2812
2769
|
|
2813
2770
|
let!(:unrelated) do
|
2814
|
-
Preference.create(name: "Third")
|
2771
|
+
Preference.create!(name: "Third")
|
2815
2772
|
end
|
2816
2773
|
|
2817
2774
|
context "when providing a single criteria" do
|
@@ -2886,7 +2843,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2886
2843
|
context "when the inverse relation is not defined" do
|
2887
2844
|
|
2888
2845
|
let!(:house) do
|
2889
|
-
person.houses.create(name: "Wayne Manor")
|
2846
|
+
person.houses.create!(name: "Wayne Manor")
|
2890
2847
|
end
|
2891
2848
|
|
2892
2849
|
it "returns the distinct values for the fields" do
|
@@ -2900,15 +2857,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2900
2857
|
describe "#min" do
|
2901
2858
|
|
2902
2859
|
let(:person) do
|
2903
|
-
Person.create
|
2860
|
+
Person.create!
|
2904
2861
|
end
|
2905
2862
|
|
2906
2863
|
let(:preference_one) do
|
2907
|
-
Preference.create(ranking: 5)
|
2864
|
+
Preference.create!(ranking: 5)
|
2908
2865
|
end
|
2909
2866
|
|
2910
2867
|
let(:preference_two) do
|
2911
|
-
Preference.create(ranking: 10)
|
2868
|
+
Preference.create!(ranking: 10)
|
2912
2869
|
end
|
2913
2870
|
|
2914
2871
|
before do
|
@@ -2929,15 +2886,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2929
2886
|
describe "#min_by" do
|
2930
2887
|
|
2931
2888
|
let(:person) do
|
2932
|
-
Person.create
|
2889
|
+
Person.create!
|
2933
2890
|
end
|
2934
2891
|
|
2935
2892
|
let(:preference_one) do
|
2936
|
-
Preference.create(ranking: 5)
|
2893
|
+
Preference.create!(ranking: 5)
|
2937
2894
|
end
|
2938
2895
|
|
2939
2896
|
let(:preference_two) do
|
2940
|
-
Preference.create(ranking: 10)
|
2897
|
+
Preference.create!(ranking: 10)
|
2941
2898
|
end
|
2942
2899
|
|
2943
2900
|
before do
|
@@ -2963,15 +2920,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2963
2920
|
describe "#nullify_all" do
|
2964
2921
|
|
2965
2922
|
let(:person) do
|
2966
|
-
Person.create
|
2923
|
+
Person.create!
|
2967
2924
|
end
|
2968
2925
|
|
2969
2926
|
let!(:preference_one) do
|
2970
|
-
person.preferences.create(name: "One")
|
2927
|
+
person.preferences.create!(name: "One")
|
2971
2928
|
end
|
2972
2929
|
|
2973
2930
|
let!(:preference_two) do
|
2974
|
-
person.preferences.create(name: "Two")
|
2931
|
+
person.preferences.create!(name: "Two")
|
2975
2932
|
end
|
2976
2933
|
|
2977
2934
|
before do
|
@@ -3017,9 +2974,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3017
2974
|
person.preferences
|
3018
2975
|
end
|
3019
2976
|
|
3020
|
-
Array.public_instance_methods.each do |method|
|
2977
|
+
Array.public_instance_methods.sort.each do |method|
|
2978
|
+
|
2979
|
+
context "when checking Array##{method}" do
|
3021
2980
|
|
3022
|
-
|
2981
|
+
before do
|
2982
|
+
expect([].respond_to?(method)).to be true
|
2983
|
+
end
|
3023
2984
|
|
3024
2985
|
it "returns true" do
|
3025
2986
|
expect(preferences.respond_to?(method)).to be true
|
@@ -3027,9 +2988,9 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3027
2988
|
end
|
3028
2989
|
end
|
3029
2990
|
|
3030
|
-
Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy.public_instance_methods.each do |method|
|
2991
|
+
Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy.public_instance_methods.sort.each do |method|
|
3031
2992
|
|
3032
|
-
context "when checking
|
2993
|
+
context "when checking Proxy##{method}" do
|
3033
2994
|
|
3034
2995
|
it "returns true" do
|
3035
2996
|
expect(preferences.respond_to?(method)).to be true
|
@@ -3037,9 +2998,9 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3037
2998
|
end
|
3038
2999
|
end
|
3039
3000
|
|
3040
|
-
Preference.scopes.keys.each do |method|
|
3001
|
+
Preference.scopes.keys.sort.each do |method|
|
3041
3002
|
|
3042
|
-
context "when checking #{method}" do
|
3003
|
+
context "when checking scope #{method}" do
|
3043
3004
|
|
3044
3005
|
it "returns true" do
|
3045
3006
|
expect(preferences.respond_to?(method)).to be true
|
@@ -3050,20 +3011,36 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3050
3011
|
|
3051
3012
|
describe "#scoped" do
|
3052
3013
|
|
3053
|
-
let(:person) do
|
3054
|
-
Person.new
|
3055
|
-
end
|
3056
|
-
|
3057
3014
|
let(:scoped) do
|
3058
3015
|
person.preferences.scoped
|
3059
3016
|
end
|
3060
3017
|
|
3061
|
-
|
3062
|
-
|
3018
|
+
context 'when association is empty' do
|
3019
|
+
|
3020
|
+
let(:person) do
|
3021
|
+
Person.new
|
3022
|
+
end
|
3023
|
+
|
3024
|
+
it "returns the relation criteria" do
|
3025
|
+
expect(scoped).to be_a(Mongoid::Criteria)
|
3026
|
+
end
|
3027
|
+
|
3028
|
+
it "returns with an empty selector" do
|
3029
|
+
expect(scoped.selector).to eq("_id" => { "$in" => [] })
|
3030
|
+
end
|
3063
3031
|
end
|
3064
3032
|
|
3065
|
-
|
3066
|
-
|
3033
|
+
context 'when association is not empty' do
|
3034
|
+
|
3035
|
+
let(:person) do
|
3036
|
+
Person.create!(preferences: [
|
3037
|
+
Preference.new(id: 123),
|
3038
|
+
])
|
3039
|
+
end
|
3040
|
+
|
3041
|
+
it "returns with a selector including association element ids" do
|
3042
|
+
expect(scoped.selector).to eq("_id" => { "$in" => [123] })
|
3043
|
+
end
|
3067
3044
|
end
|
3068
3045
|
end
|
3069
3046
|
|
@@ -3072,13 +3049,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3072
3049
|
describe "##{method}" do
|
3073
3050
|
|
3074
3051
|
let(:person) do
|
3075
|
-
Person.create
|
3052
|
+
Person.create!
|
3076
3053
|
end
|
3077
3054
|
|
3078
3055
|
context "when documents have been persisted" do
|
3079
3056
|
|
3080
3057
|
let!(:preference) do
|
3081
|
-
person.preferences.create(name: "Testing")
|
3058
|
+
person.preferences.create!(name: "Testing")
|
3082
3059
|
end
|
3083
3060
|
|
3084
3061
|
it "returns the number of documents" do
|
@@ -3090,7 +3067,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3090
3067
|
|
3091
3068
|
before do
|
3092
3069
|
person.preferences.build(name: "Test")
|
3093
|
-
person.preferences.create(name: "Test 2")
|
3070
|
+
person.preferences.create!(name: "Test 2")
|
3094
3071
|
end
|
3095
3072
|
|
3096
3073
|
it "returns the total number of documents" do
|
@@ -3105,15 +3082,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3105
3082
|
context "when the relation has no default scope" do
|
3106
3083
|
|
3107
3084
|
let!(:person) do
|
3108
|
-
Person.create
|
3085
|
+
Person.create!
|
3109
3086
|
end
|
3110
3087
|
|
3111
3088
|
let!(:preference_one) do
|
3112
|
-
person.preferences.create(name: "first")
|
3089
|
+
person.preferences.create!(name: "first")
|
3113
3090
|
end
|
3114
3091
|
|
3115
3092
|
let!(:preference_two) do
|
3116
|
-
Preference.create(name: "second")
|
3093
|
+
Preference.create!(name: "second")
|
3117
3094
|
end
|
3118
3095
|
|
3119
3096
|
let(:unscoped) do
|
@@ -3128,15 +3105,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3128
3105
|
context "when the relation has a default scope" do
|
3129
3106
|
|
3130
3107
|
let!(:person) do
|
3131
|
-
Person.create
|
3108
|
+
Person.create!
|
3132
3109
|
end
|
3133
3110
|
|
3134
3111
|
let!(:house_one) do
|
3135
|
-
person.houses.create(name: "first")
|
3112
|
+
person.houses.create!(name: "first")
|
3136
3113
|
end
|
3137
3114
|
|
3138
3115
|
let!(:house_two) do
|
3139
|
-
House.create(name: "second")
|
3116
|
+
House.create!(name: "second")
|
3140
3117
|
end
|
3141
3118
|
|
3142
3119
|
let(:unscoped) do
|
@@ -3172,10 +3149,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3172
3149
|
end
|
3173
3150
|
|
3174
3151
|
before do
|
3175
|
-
person.update_attributes(
|
3152
|
+
person.update_attributes!(
|
3176
3153
|
houses: [ wife_house, exwife_house, girlfriend_house ]
|
3177
3154
|
)
|
3178
|
-
person.update_attributes(house_ids: [ girlfriend_house.id ])
|
3155
|
+
person.update_attributes!(house_ids: [ girlfriend_house.id ])
|
3179
3156
|
end
|
3180
3157
|
|
3181
3158
|
context "when reloading" do
|
@@ -3222,7 +3199,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3222
3199
|
end
|
3223
3200
|
|
3224
3201
|
let!(:business) do
|
3225
|
-
Business.create(name: "serious", owners: [ user ])
|
3202
|
+
Business.create!(name: "serious", owners: [ user ])
|
3226
3203
|
end
|
3227
3204
|
|
3228
3205
|
before do
|
@@ -3265,11 +3242,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3265
3242
|
context "when the documents are persisted" do
|
3266
3243
|
|
3267
3244
|
let(:user) do
|
3268
|
-
User.create(name: "tst")
|
3245
|
+
User.create!(name: "tst")
|
3269
3246
|
end
|
3270
3247
|
|
3271
3248
|
let(:business) do
|
3272
|
-
Business.create(name: "srs", owners: [ user ])
|
3249
|
+
Business.create!(name: "srs", owners: [ user ])
|
3273
3250
|
end
|
3274
3251
|
|
3275
3252
|
before do
|
@@ -3313,11 +3290,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3313
3290
|
context "when binding the relation multiple times" do
|
3314
3291
|
|
3315
3292
|
let(:person) do
|
3316
|
-
Person.create
|
3293
|
+
Person.create!
|
3317
3294
|
end
|
3318
3295
|
|
3319
3296
|
let(:preference) do
|
3320
|
-
person.preferences.create(name: "testing")
|
3297
|
+
person.preferences.create!(name: "testing")
|
3321
3298
|
end
|
3322
3299
|
|
3323
3300
|
before do
|
@@ -3336,19 +3313,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3336
3313
|
context "when the association has order criteria" do
|
3337
3314
|
|
3338
3315
|
let(:person) do
|
3339
|
-
Person.create
|
3316
|
+
Person.create!
|
3340
3317
|
end
|
3341
3318
|
|
3342
3319
|
let(:preference_one) do
|
3343
|
-
OrderedPreference.create(name: 'preference-1', value: 10)
|
3320
|
+
OrderedPreference.create!(name: 'preference-1', value: 10)
|
3344
3321
|
end
|
3345
3322
|
|
3346
3323
|
let(:preference_two) do
|
3347
|
-
OrderedPreference.create(name: 'preference-2', value: 20)
|
3324
|
+
OrderedPreference.create!(name: 'preference-2', value: 20)
|
3348
3325
|
end
|
3349
3326
|
|
3350
3327
|
let(:preference_three) do
|
3351
|
-
OrderedPreference.create(name: 'preference-3', value: 20)
|
3328
|
+
OrderedPreference.create!(name: 'preference-3', value: 20)
|
3352
3329
|
end
|
3353
3330
|
|
3354
3331
|
before do
|
@@ -3372,7 +3349,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3372
3349
|
context "when the parent is not a new record and freshly loaded" do
|
3373
3350
|
|
3374
3351
|
let(:person) do
|
3375
|
-
Person.create
|
3352
|
+
Person.create!
|
3376
3353
|
end
|
3377
3354
|
|
3378
3355
|
let(:preference) do
|
@@ -3381,7 +3358,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3381
3358
|
|
3382
3359
|
before do
|
3383
3360
|
person.preferences = [ preference ]
|
3384
|
-
person.save
|
3361
|
+
person.save!
|
3385
3362
|
person.reload
|
3386
3363
|
person.preferences = nil
|
3387
3364
|
end
|
@@ -3404,15 +3381,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3404
3381
|
context "when reloading the relation" do
|
3405
3382
|
|
3406
3383
|
let!(:person) do
|
3407
|
-
Person.create
|
3384
|
+
Person.create!
|
3408
3385
|
end
|
3409
3386
|
|
3410
3387
|
let!(:preference_one) do
|
3411
|
-
Preference.create(name: "one")
|
3388
|
+
Preference.create!(name: "one")
|
3412
3389
|
end
|
3413
3390
|
|
3414
3391
|
let!(:preference_two) do
|
3415
|
-
Preference.create(name: "two")
|
3392
|
+
Preference.create!(name: "two")
|
3416
3393
|
end
|
3417
3394
|
|
3418
3395
|
before do
|
@@ -3456,7 +3433,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3456
3433
|
context "when the document is new" do
|
3457
3434
|
|
3458
3435
|
let!(:person) do
|
3459
|
-
Person.create(preference_names: "one, two")
|
3436
|
+
Person.create!(preference_names: "one, two")
|
3460
3437
|
end
|
3461
3438
|
|
3462
3439
|
let(:preference_one) do
|
@@ -3492,23 +3469,23 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3492
3469
|
end
|
3493
3470
|
|
3494
3471
|
let(:preference_one) do
|
3495
|
-
Preference.create(name: "one")
|
3472
|
+
Preference.create!(name: "one")
|
3496
3473
|
end
|
3497
3474
|
|
3498
3475
|
let(:preference_two) do
|
3499
|
-
Preference.create(name: "two")
|
3476
|
+
Preference.create!(name: "two")
|
3500
3477
|
end
|
3501
3478
|
|
3502
3479
|
before do
|
3503
3480
|
person.preference_ids = [ preference_one.id, preference_two.id ]
|
3504
|
-
person.save
|
3481
|
+
person.save!
|
3505
3482
|
end
|
3506
3483
|
|
3507
3484
|
context "and the order is changed" do
|
3508
3485
|
|
3509
3486
|
before do
|
3510
3487
|
person.preference_ids = [ preference_two.id, preference_one.id ]
|
3511
|
-
person.save
|
3488
|
+
person.save!
|
3512
3489
|
end
|
3513
3490
|
|
3514
3491
|
let(:reloaded) do
|
@@ -3525,13 +3502,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3525
3502
|
context "and the order is changed and an element is added" do
|
3526
3503
|
|
3527
3504
|
let(:preference_three) do
|
3528
|
-
Preference.create(name: "three")
|
3505
|
+
Preference.create!(name: "three")
|
3529
3506
|
end
|
3530
3507
|
|
3531
3508
|
before do
|
3532
3509
|
person.preference_ids =
|
3533
3510
|
[ preference_two.id, preference_one.id, preference_three.id ]
|
3534
|
-
person.save
|
3511
|
+
person.save!
|
3535
3512
|
end
|
3536
3513
|
|
3537
3514
|
let(:reloaded) do
|
@@ -3548,16 +3525,16 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3548
3525
|
context "and the order is changed and an element is removed" do
|
3549
3526
|
|
3550
3527
|
let(:preference_three) do
|
3551
|
-
Preference.create(name: "three")
|
3528
|
+
Preference.create!(name: "three")
|
3552
3529
|
end
|
3553
3530
|
|
3554
3531
|
before do
|
3555
3532
|
person.preference_ids =
|
3556
3533
|
[ preference_one.id, preference_two.id, preference_three.id ]
|
3557
|
-
person.save
|
3534
|
+
person.save!
|
3558
3535
|
person.preference_ids =
|
3559
3536
|
[ preference_three.id, preference_two.id ]
|
3560
|
-
person.save
|
3537
|
+
person.save!
|
3561
3538
|
end
|
3562
3539
|
|
3563
3540
|
let(:reloaded) do
|
@@ -3607,15 +3584,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3607
3584
|
context "when the relation exists" do
|
3608
3585
|
|
3609
3586
|
let!(:person) do
|
3610
|
-
Person.create
|
3587
|
+
Person.create!
|
3611
3588
|
end
|
3612
3589
|
|
3613
3590
|
let!(:pref_one) do
|
3614
|
-
person.preferences.create
|
3591
|
+
person.preferences.create!
|
3615
3592
|
end
|
3616
3593
|
|
3617
3594
|
let!(:pref_two) do
|
3618
|
-
Preference.create
|
3595
|
+
Preference.create!
|
3619
3596
|
end
|
3620
3597
|
|
3621
3598
|
before do
|
@@ -3631,15 +3608,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3631
3608
|
context "when using a different primary key" do
|
3632
3609
|
|
3633
3610
|
let(:dog) do
|
3634
|
-
Dog.create(name: 'Doggie')
|
3611
|
+
Dog.create!(name: 'Doggie')
|
3635
3612
|
end
|
3636
3613
|
|
3637
3614
|
let(:cat) do
|
3638
|
-
Cat.create(name: 'Kitty')
|
3615
|
+
Cat.create!(name: 'Kitty')
|
3616
|
+
end
|
3617
|
+
|
3618
|
+
let(:another_cat) do
|
3619
|
+
Cat.create!(name: 'Kitten')
|
3639
3620
|
end
|
3640
3621
|
|
3641
3622
|
let(:fire_hydrant) do
|
3642
|
-
FireHydrant.create(location: '221B Baker Street')
|
3623
|
+
FireHydrant.create!(location: '221B Baker Street')
|
3643
3624
|
end
|
3644
3625
|
|
3645
3626
|
context "when adding to a one-way many to many" do
|
@@ -3653,6 +3634,28 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3653
3634
|
end
|
3654
3635
|
end
|
3655
3636
|
|
3637
|
+
context "when adding multiple documents to a one-way many to many" do
|
3638
|
+
|
3639
|
+
before do
|
3640
|
+
fire_hydrant.cats.push([cat, another_cat])
|
3641
|
+
end
|
3642
|
+
|
3643
|
+
it "adds the pk values to the fk set" do
|
3644
|
+
expect(fire_hydrant.cat_ids).to eq([cat.name, another_cat.name])
|
3645
|
+
end
|
3646
|
+
end
|
3647
|
+
|
3648
|
+
context "when adding a new document to a one-way many to many" do
|
3649
|
+
|
3650
|
+
before do
|
3651
|
+
fire_hydrant.cats.build name: 'Kitten'
|
3652
|
+
end
|
3653
|
+
|
3654
|
+
it "adds the pk values to the fk set" do
|
3655
|
+
expect(fire_hydrant.cat_ids).to eq(['Kitten'])
|
3656
|
+
end
|
3657
|
+
end
|
3658
|
+
|
3656
3659
|
context "when adding to a two-way many to many" do
|
3657
3660
|
|
3658
3661
|
before do
|
@@ -3709,10 +3712,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3709
3712
|
end
|
3710
3713
|
|
3711
3714
|
it "should assign relation from both sides" do
|
3712
|
-
p1 = Project.create name: 'Foo'
|
3713
|
-
p2 = Project.create name: 'Bar'
|
3714
|
-
d1 = Distributor.create name: 'Rock'
|
3715
|
-
d2 = Distributor.create name: 'Soul'
|
3715
|
+
p1 = Project.create! name: 'Foo'
|
3716
|
+
p2 = Project.create! name: 'Bar'
|
3717
|
+
d1 = Distributor.create! name: 'Rock'
|
3718
|
+
d2 = Distributor.create! name: 'Soul'
|
3716
3719
|
|
3717
3720
|
p1.distributors << d1
|
3718
3721
|
expect(p1.d_ids).to match_array([d1.id])
|
@@ -3722,4 +3725,58 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3722
3725
|
expect(p2.d_ids).to match_array([d2.id])
|
3723
3726
|
end
|
3724
3727
|
end
|
3728
|
+
|
3729
|
+
context "when accesing own _id from parent's foreign key in default" do
|
3730
|
+
let!(:contract) { HabtmmContract.create! }
|
3731
|
+
let!(:signature) { contract.signatures.create! }
|
3732
|
+
|
3733
|
+
it "is nil" do
|
3734
|
+
expect(signature.favorite_signature).to be nil
|
3735
|
+
end
|
3736
|
+
end
|
3737
|
+
|
3738
|
+
context "when setting an association on a model that uses the class_name option" do
|
3739
|
+
let!(:contract) { HabtmmContract.create! }
|
3740
|
+
let!(:signature) { HabtmmSignature.create!(contracts: [contract]) }
|
3741
|
+
|
3742
|
+
it "populates the inverse foreign key" do
|
3743
|
+
expect(signature.contracts.first.signature_ids).to eq([signature.id])
|
3744
|
+
end
|
3745
|
+
end
|
3746
|
+
|
3747
|
+
context "when there is a foreign key in the aliased associations" do
|
3748
|
+
it "has the correct aliases" do
|
3749
|
+
expect(Dog.aliased_associations["breed_ids"]).to eq("breeds")
|
3750
|
+
expect(Breed.aliased_associations["dog_ids"]).to eq("dogs")
|
3751
|
+
end
|
3752
|
+
end
|
3753
|
+
|
3754
|
+
# This test is for MONGOID-5344 which tests that the initial call to
|
3755
|
+
# signature_ids refers to the same array as subsequent calls to signature_ids.
|
3756
|
+
# Prior to the change in that ticket, this test broke because the array
|
3757
|
+
# returned from write_attribute (which is triggered the first time the
|
3758
|
+
# foreign key array is referenced, to set the default), refers to a different
|
3759
|
+
# array to the one stored in the attributes hash. This happened because,
|
3760
|
+
# when retrieving a document from the database, the attributes hash is actually
|
3761
|
+
# a BSON::Document, which applies a transformation to the array before
|
3762
|
+
# storing it.
|
3763
|
+
context "when executing concat on foreign key array from the db" do
|
3764
|
+
config_override :legacy_attributes, false
|
3765
|
+
|
3766
|
+
before do
|
3767
|
+
HabtmmContract.create!
|
3768
|
+
HabtmmSignature.create!
|
3769
|
+
end
|
3770
|
+
|
3771
|
+
let!(:contract) { HabtmmContract.first }
|
3772
|
+
let!(:signature) { HabtmmSignature.first }
|
3773
|
+
|
3774
|
+
before do
|
3775
|
+
contract.signature_ids.concat([signature.id])
|
3776
|
+
end
|
3777
|
+
|
3778
|
+
it "works on the first attempt" do
|
3779
|
+
expect(contract.signature_ids).to eq([signature.id])
|
3780
|
+
end
|
3781
|
+
end
|
3725
3782
|
end
|