mongoid 7.1.1 → 8.1.0
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 +20 -20
- data/README.md +15 -8
- data/Rakefile +61 -5
- data/lib/config/locales/en.yml +162 -56
- data/lib/mongoid/association/accessors.rb +89 -40
- data/lib/mongoid/association/bindable.rb +50 -23
- data/lib/mongoid/association/builders.rb +5 -12
- data/lib/mongoid/association/constrainable.rb +1 -5
- data/lib/mongoid/association/depending.rb +5 -17
- data/lib/mongoid/association/eager_loadable.rb +29 -10
- data/lib/mongoid/association/embedded/batchable.rb +64 -52
- data/lib/mongoid/association/embedded/cyclic.rb +3 -12
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +24 -9
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +2 -5
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +4 -16
- data/lib/mongoid/association/embedded/embedded_in.rb +4 -26
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +1 -7
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +4 -6
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +110 -92
- data/lib/mongoid/association/embedded/embeds_many.rb +4 -34
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +0 -7
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +19 -8
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +50 -19
- data/lib/mongoid/association/embedded/embeds_one.rb +5 -31
- data/lib/mongoid/association/embedded.rb +0 -1
- data/lib/mongoid/association/macros.rb +27 -5
- data/lib/mongoid/association/many.rb +14 -27
- data/lib/mongoid/association/marshalable.rb +0 -5
- data/lib/mongoid/association/nested/many.rb +6 -16
- data/lib/mongoid/association/nested/nested_buildable.rb +4 -13
- data/lib/mongoid/association/nested/one.rb +48 -23
- data/lib/mongoid/association/nested.rb +0 -3
- data/lib/mongoid/association/one.rb +2 -11
- data/lib/mongoid/association/options.rb +9 -42
- data/lib/mongoid/association/proxy.rb +22 -27
- data/lib/mongoid/association/referenced/auto_save.rb +6 -14
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +2 -8
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +5 -6
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +0 -1
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +5 -19
- data/lib/mongoid/association/referenced/belongs_to.rb +11 -36
- data/lib/mongoid/association/referenced/counter_cache.rb +12 -25
- data/lib/mongoid/association/referenced/eager.rb +5 -26
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +0 -5
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +0 -3
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +81 -51
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +17 -41
- data/lib/mongoid/association/referenced/has_many/binding.rb +0 -5
- data/lib/mongoid/association/referenced/has_many/buildable.rb +0 -3
- data/lib/mongoid/association/referenced/has_many/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +438 -461
- data/lib/mongoid/association/referenced/has_many/proxy.rb +58 -84
- data/lib/mongoid/association/referenced/has_many.rb +15 -42
- data/lib/mongoid/association/referenced/has_one/binding.rb +0 -7
- data/lib/mongoid/association/referenced/has_one/buildable.rb +12 -5
- data/lib/mongoid/association/referenced/has_one/eager.rb +0 -1
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +7 -22
- data/lib/mongoid/association/referenced/has_one/proxy.rb +9 -16
- data/lib/mongoid/association/referenced/has_one.rb +12 -35
- data/lib/mongoid/association/referenced/syncable.rb +4 -21
- data/lib/mongoid/association/referenced.rb +0 -1
- data/lib/mongoid/association/reflections.rb +4 -5
- data/lib/mongoid/association/relatable.rb +46 -71
- data/lib/mongoid/association.rb +5 -22
- data/lib/mongoid/atomic/modifiers.rb +7 -54
- data/lib/mongoid/atomic/paths/embedded/many.rb +19 -5
- data/lib/mongoid/atomic/paths/embedded/one.rb +0 -5
- data/lib/mongoid/atomic/paths/embedded.rb +0 -3
- data/lib/mongoid/atomic/paths/root.rb +0 -5
- data/lib/mongoid/atomic/paths.rb +0 -1
- data/lib/mongoid/atomic.rb +40 -47
- data/lib/mongoid/attributes/dynamic.rb +5 -22
- data/lib/mongoid/attributes/nested.rb +6 -11
- data/lib/mongoid/attributes/processing.rb +11 -21
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +3 -8
- data/lib/mongoid/attributes.rb +82 -88
- data/lib/mongoid/cacheable.rb +4 -9
- data/lib/mongoid/changeable.rb +148 -69
- data/lib/mongoid/clients/factory.rb +41 -17
- data/lib/mongoid/clients/options.rb +13 -14
- data/lib/mongoid/clients/sessions.rb +8 -11
- data/lib/mongoid/clients/storage_options.rb +7 -17
- data/lib/mongoid/clients/validators/storage.rb +3 -24
- data/lib/mongoid/clients/validators.rb +0 -1
- data/lib/mongoid/clients.rb +1 -10
- data/lib/mongoid/collection_configurable.rb +58 -0
- data/lib/mongoid/composable.rb +3 -7
- data/lib/mongoid/config/defaults.rb +60 -0
- data/lib/mongoid/config/environment.rb +28 -5
- data/lib/mongoid/config/options.rb +0 -11
- data/lib/mongoid/config/validators/async_query_executor.rb +24 -0
- data/lib/mongoid/config/validators/client.rb +6 -23
- data/lib/mongoid/config/validators/option.rb +0 -3
- data/lib/mongoid/config/validators.rb +1 -1
- data/lib/mongoid/config.rb +183 -39
- data/lib/mongoid/contextual/aggregable/memory.rb +37 -26
- data/lib/mongoid/contextual/aggregable/mongo.rb +29 -32
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +7 -27
- data/lib/mongoid/contextual/command.rb +0 -5
- data/lib/mongoid/contextual/geo_near.rb +8 -41
- data/lib/mongoid/contextual/map_reduce.rb +2 -33
- data/lib/mongoid/contextual/memory.rb +383 -79
- data/lib/mongoid/contextual/mongo/documents_loader.rb +177 -0
- data/lib/mongoid/contextual/mongo.rb +636 -283
- data/lib/mongoid/contextual/none.rb +262 -31
- data/lib/mongoid/contextual/queryable.rb +1 -4
- data/lib/mongoid/contextual.rb +14 -7
- data/lib/mongoid/copyable.rb +39 -16
- data/lib/mongoid/criteria/findable.rb +9 -19
- data/lib/mongoid/criteria/includable.rb +27 -31
- data/lib/mongoid/criteria/inspectable.rb +0 -3
- data/lib/mongoid/criteria/marshalable.rb +10 -7
- data/lib/mongoid/criteria/modifiable.rb +2 -20
- data/lib/mongoid/criteria/options.rb +0 -3
- data/lib/mongoid/criteria/permission.rb +1 -2
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -15
- data/lib/mongoid/criteria/queryable/expandable.rb +0 -25
- data/lib/mongoid/criteria/queryable/extensions/array.rb +4 -40
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +25 -7
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +3 -6
- data/lib/mongoid/criteria/queryable/extensions/date.rb +6 -8
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +6 -6
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +1 -40
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +0 -13
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +1 -20
- data/lib/mongoid/criteria/queryable/extensions/object.rb +3 -29
- data/lib/mongoid/criteria/queryable/extensions/range.rb +46 -16
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +9 -18
- data/lib/mongoid/criteria/queryable/extensions/set.rb +1 -4
- data/lib/mongoid/criteria/queryable/extensions/string.rb +4 -31
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +4 -21
- data/lib/mongoid/criteria/queryable/extensions/time.rb +6 -8
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +16 -6
- data/lib/mongoid/criteria/queryable/extensions.rb +0 -5
- data/lib/mongoid/criteria/queryable/key.rb +6 -19
- data/lib/mongoid/criteria/queryable/macroable.rb +0 -3
- data/lib/mongoid/criteria/queryable/mergeable.rb +123 -38
- data/lib/mongoid/criteria/queryable/optional.rb +11 -62
- data/lib/mongoid/criteria/queryable/options.rb +2 -21
- data/lib/mongoid/criteria/queryable/pipeline.rb +1 -14
- data/lib/mongoid/criteria/queryable/selectable.rb +138 -125
- data/lib/mongoid/criteria/queryable/selector.rb +94 -30
- data/lib/mongoid/criteria/queryable/smash.rb +40 -18
- data/lib/mongoid/criteria/queryable/storable.rb +14 -10
- data/lib/mongoid/criteria/queryable.rb +11 -13
- data/lib/mongoid/criteria/scopable.rb +27 -21
- data/lib/mongoid/criteria/translator.rb +45 -0
- data/lib/mongoid/criteria.rb +88 -108
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +149 -99
- data/lib/mongoid/equality.rb +32 -16
- data/lib/mongoid/errors/ambiguous_relationship.rb +2 -5
- data/lib/mongoid/errors/callback.rb +0 -3
- data/lib/mongoid/errors/create_collection_failure.rb +33 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +0 -1
- data/lib/mongoid/errors/delete_restriction.rb +8 -12
- data/lib/mongoid/errors/document_not_destroyed.rb +2 -7
- data/lib/mongoid/errors/document_not_found.rb +33 -21
- data/lib/mongoid/errors/drop_collection_failure.rb +27 -0
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/immutable_attribute.rb +26 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +0 -3
- data/lib/mongoid/errors/invalid_async_query_executor.rb +25 -0
- data/lib/mongoid/errors/invalid_collection.rb +0 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +1 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +1 -4
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +6 -7
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +0 -3
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_find.rb +0 -3
- data/lib/mongoid/errors/invalid_global_executor_concurrency.rb +22 -0
- data/lib/mongoid/errors/invalid_includes.rb +0 -3
- data/lib/mongoid/errors/invalid_index.rb +0 -3
- data/lib/mongoid/errors/invalid_options.rb +0 -3
- data/lib/mongoid/errors/invalid_path.rb +0 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +0 -5
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +1 -8
- data/lib/mongoid/errors/invalid_relation_option.rb +1 -4
- data/lib/mongoid/errors/invalid_scope.rb +0 -3
- data/lib/mongoid/errors/invalid_session_use.rb +1 -6
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +0 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -4
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -3
- data/lib/mongoid/errors/invalid_time.rb +0 -3
- data/lib/mongoid/errors/inverse_not_found.rb +0 -3
- data/lib/mongoid/errors/mixed_client_configuration.rb +0 -3
- data/lib/mongoid/errors/mixed_relations.rb +0 -3
- data/lib/mongoid/errors/mongoid_error.rb +4 -13
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +1 -4
- data/lib/mongoid/errors/no_client_config.rb +2 -5
- data/lib/mongoid/errors/no_client_database.rb +1 -4
- data/lib/mongoid/errors/no_client_hosts.rb +1 -4
- data/lib/mongoid/errors/no_clients_config.rb +0 -3
- data/lib/mongoid/errors/no_default_client.rb +1 -4
- data/lib/mongoid/errors/no_environment.rb +0 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +0 -3
- data/lib/mongoid/errors/no_metadata.rb +0 -3
- data/lib/mongoid/errors/no_parent.rb +0 -3
- data/lib/mongoid/errors/readonly_attribute.rb +1 -4
- data/lib/mongoid/errors/readonly_document.rb +1 -6
- data/lib/mongoid/errors/scope_overwrite.rb +0 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +1 -2
- data/lib/mongoid/errors/unknown_attribute.rb +1 -4
- data/lib/mongoid/errors/unknown_model.rb +0 -3
- data/lib/mongoid/errors/unsaved_document.rb +1 -2
- data/lib/mongoid/errors/unsupported_javascript.rb +0 -3
- data/lib/mongoid/errors/validations.rb +0 -1
- data/lib/mongoid/errors.rb +15 -4
- data/lib/mongoid/evolvable.rb +1 -4
- data/lib/mongoid/extensions/array.rb +12 -36
- data/lib/mongoid/extensions/big_decimal.rb +33 -21
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +8 -6
- data/lib/mongoid/extensions/date.rb +26 -29
- data/lib/mongoid/extensions/date_time.rb +1 -10
- data/lib/mongoid/extensions/decimal128.rb +0 -5
- data/lib/mongoid/extensions/false_class.rb +3 -8
- data/lib/mongoid/extensions/float.rb +7 -11
- data/lib/mongoid/extensions/hash.rb +19 -37
- data/lib/mongoid/extensions/integer.rb +7 -13
- data/lib/mongoid/extensions/module.rb +1 -4
- data/lib/mongoid/extensions/nil_class.rb +0 -5
- data/lib/mongoid/extensions/object.rb +11 -48
- data/lib/mongoid/extensions/object_id.rb +0 -7
- data/lib/mongoid/extensions/range.rb +40 -20
- data/lib/mongoid/extensions/regexp.rb +12 -8
- data/lib/mongoid/extensions/set.rb +11 -11
- data/lib/mongoid/extensions/string.rb +12 -52
- data/lib/mongoid/extensions/symbol.rb +4 -22
- data/lib/mongoid/extensions/time.rb +28 -26
- data/lib/mongoid/extensions/time_with_zone.rb +14 -11
- data/lib/mongoid/extensions/true_class.rb +3 -8
- data/lib/mongoid/extensions.rb +17 -3
- data/lib/mongoid/factory.rb +80 -16
- data/lib/mongoid/fields/foreign_key.rb +11 -25
- data/lib/mongoid/fields/localized.rb +19 -15
- data/lib/mongoid/fields/standard.rb +17 -40
- data/lib/mongoid/fields/validators/macro.rb +25 -24
- data/lib/mongoid/fields/validators.rb +0 -1
- data/lib/mongoid/fields.rb +346 -75
- data/lib/mongoid/findable.rb +107 -31
- data/lib/mongoid/indexable/specification.rb +2 -17
- data/lib/mongoid/indexable/validators/options.rb +6 -9
- data/lib/mongoid/indexable.rb +3 -20
- data/lib/mongoid/inspectable.rb +2 -11
- data/lib/mongoid/interceptable.rb +79 -41
- data/lib/mongoid/loggable.rb +0 -9
- data/lib/mongoid/matchable.rb +2 -155
- data/lib/mongoid/matcher/all.rb +22 -0
- data/lib/mongoid/matcher/and.rb +21 -0
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +36 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
- data/lib/mongoid/matcher/eq.rb +11 -0
- data/lib/mongoid/matcher/eq_impl.rb +67 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
- data/lib/mongoid/matcher/exists.rb +15 -0
- data/lib/mongoid/matcher/expression.rb +35 -0
- data/lib/mongoid/matcher/expression_operator.rb +19 -0
- data/lib/mongoid/matcher/field_expression.rb +62 -0
- data/lib/mongoid/matcher/field_operator.rb +54 -0
- data/lib/mongoid/matcher/gt.rb +17 -0
- data/lib/mongoid/matcher/gte.rb +17 -0
- data/lib/mongoid/matcher/in.rb +25 -0
- data/lib/mongoid/matcher/lt.rb +17 -0
- data/lib/mongoid/matcher/lte.rb +17 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/ne.rb +16 -0
- data/lib/mongoid/matcher/nin.rb +11 -0
- data/lib/mongoid/matcher/nor.rb +25 -0
- data/lib/mongoid/matcher/not.rb +29 -0
- data/lib/mongoid/matcher/or.rb +21 -0
- data/lib/mongoid/matcher/regex.rb +41 -0
- data/lib/mongoid/matcher/size.rb +26 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +130 -0
- data/lib/mongoid/persistable/creatable.rb +20 -29
- data/lib/mongoid/persistable/deletable.rb +4 -22
- data/lib/mongoid/persistable/destroyable.rb +9 -10
- data/lib/mongoid/persistable/incrementable.rb +0 -5
- data/lib/mongoid/persistable/logical.rb +0 -5
- data/lib/mongoid/persistable/poppable.rb +0 -5
- data/lib/mongoid/persistable/pullable.rb +0 -7
- data/lib/mongoid/persistable/pushable.rb +4 -8
- data/lib/mongoid/persistable/renamable.rb +0 -5
- data/lib/mongoid/persistable/savable.rb +13 -8
- data/lib/mongoid/persistable/settable.rb +0 -5
- data/lib/mongoid/persistable/unsettable.rb +2 -7
- data/lib/mongoid/persistable/updatable.rb +96 -29
- data/lib/mongoid/persistable/upsertable.rb +20 -8
- data/lib/mongoid/persistable.rb +6 -26
- data/lib/mongoid/persistence_context.rb +71 -43
- data/lib/mongoid/positional.rb +0 -5
- data/lib/mongoid/query_cache.rb +16 -236
- data/lib/mongoid/railtie.rb +0 -15
- data/lib/mongoid/railties/controller_runtime.rb +1 -2
- data/lib/mongoid/railties/database.rake +7 -2
- data/lib/mongoid/reloadable.rb +17 -20
- data/lib/mongoid/scopable.rb +32 -56
- data/lib/mongoid/selectable.rb +5 -17
- data/lib/mongoid/serializable.rb +11 -22
- data/lib/mongoid/shardable.rb +49 -16
- data/lib/mongoid/stateful.rb +57 -19
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +12 -0
- data/lib/mongoid/tasks/database.rb +59 -11
- data/lib/mongoid/threaded/lifecycle.rb +5 -26
- data/lib/mongoid/threaded.rb +42 -67
- data/lib/mongoid/timestamps/created/short.rb +0 -1
- data/lib/mongoid/timestamps/created.rb +1 -2
- data/lib/mongoid/timestamps/short.rb +0 -1
- data/lib/mongoid/timestamps/timeless.rb +0 -7
- data/lib/mongoid/timestamps/updated/short.rb +0 -1
- data/lib/mongoid/timestamps/updated.rb +2 -5
- data/lib/mongoid/timestamps.rb +0 -1
- data/lib/mongoid/touchable.rb +34 -13
- data/lib/mongoid/traversable.rb +181 -59
- data/lib/mongoid/utils.rb +22 -0
- data/lib/mongoid/validatable/associated.rb +1 -4
- data/lib/mongoid/validatable/format.rb +0 -1
- data/lib/mongoid/validatable/length.rb +0 -1
- data/lib/mongoid/validatable/localizable.rb +1 -4
- data/lib/mongoid/validatable/macros.rb +5 -14
- data/lib/mongoid/validatable/presence.rb +6 -13
- data/lib/mongoid/validatable/queryable.rb +0 -3
- data/lib/mongoid/validatable/uniqueness.rb +26 -40
- data/lib/mongoid/validatable.rb +9 -27
- data/lib/mongoid/version.rb +1 -2
- data/lib/mongoid/warnings.rb +44 -0
- data/lib/mongoid.rb +42 -18
- data/lib/rails/generators/mongoid/config/config_generator.rb +8 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +12 -6
- data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/mongoid_generator.rb +0 -1
- data/lib/rails/mongoid.rb +0 -3
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +16 -0
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +345 -0
- data/spec/integration/associations/belongs_to_spec.rb +18 -1
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +163 -1
- data/spec/integration/associations/embeds_many_spec.rb +219 -0
- data/spec/integration/associations/embeds_one_spec.rb +41 -0
- data/spec/integration/associations/foreign_key_spec.rb +9 -1
- data/spec/integration/associations/foreign_key_spec_models.rb +0 -1
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +272 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
- data/spec/integration/associations/reverse_population_spec.rb +0 -1
- data/spec/integration/associations/reverse_population_spec_models.rb +0 -1
- data/spec/integration/associations/scope_option_spec.rb +101 -0
- data/spec/integration/atomic/modifiers_spec.rb +116 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/callbacks_models.rb +192 -0
- data/spec/integration/callbacks_spec.rb +584 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +40 -0
- data/spec/integration/criteria/default_scope_spec.rb +51 -0
- data/spec/integration/criteria/logical_spec.rb +43 -0
- data/spec/integration/criteria/range_spec.rb +359 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +125 -15
- data/spec/integration/discriminator_key_spec.rb +391 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +30 -1
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +3 -19
- data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +130 -45
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +20 -5
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +25 -9
- data/spec/mongoid/association/accessors_spec.rb +282 -78
- data/spec/mongoid/association/auto_save_spec.rb +72 -34
- data/spec/mongoid/association/builders_spec.rb +1 -2
- data/spec/mongoid/association/constrainable_spec.rb +0 -1
- data/spec/mongoid/association/counter_cache_spec.rb +33 -34
- data/spec/mongoid/association/depending_spec.rb +429 -339
- data/spec/mongoid/association/eager_spec.rb +6 -6
- data/spec/mongoid/association/embedded/cyclic_spec.rb +2 -3
- data/spec/mongoid/association/embedded/dirty_spec.rb +2 -3
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -2
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +54 -1
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +150 -14
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +112 -1
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +704 -198
- data/spec/mongoid/association/embedded/embeds_many_models.rb +194 -1
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +12 -1
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +78 -1
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +25 -1
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +36 -24
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_models.rb +20 -1
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +0 -1
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +28 -3
- data/spec/mongoid/association/macros_spec.rb +9 -10
- data/spec/mongoid/association/nested/many_spec.rb +0 -1
- data/spec/mongoid/association/nested/one_spec.rb +16 -13
- data/spec/mongoid/association/options_spec.rb +0 -1
- data/spec/mongoid/association/polymorphic_spec.rb +0 -1
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -2
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +109 -17
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +50 -15
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +112 -59
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +20 -1
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +26 -22
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +26 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +31 -3
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +523 -372
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +43 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +56 -3
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +1 -2
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +130 -1
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +23 -7
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +413 -130
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +857 -503
- data/spec/mongoid/association/referenced/has_many_models.rb +59 -2
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_many_spec.rb +46 -1
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +53 -10
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +17 -2
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +133 -28
- data/spec/mongoid/association/referenced/has_one_models.rb +63 -1
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +0 -1
- data/spec/mongoid/association/referenced/has_one_spec.rb +22 -2
- data/spec/mongoid/association/reflections_spec.rb +0 -1
- data/spec/mongoid/association/syncable_spec.rb +46 -33
- data/spec/mongoid/association_spec.rb +0 -1
- data/spec/mongoid/atomic/modifiers_spec.rb +47 -1
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +0 -1
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +0 -1
- data/spec/mongoid/atomic/paths/root_spec.rb +0 -1
- data/spec/mongoid/atomic/paths_spec.rb +91 -13
- data/spec/mongoid/atomic_spec.rb +51 -7
- data/spec/mongoid/attributes/dynamic_spec.rb +0 -1
- data/spec/mongoid/attributes/nested_spec.rb +147 -79
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +40 -0
- data/spec/mongoid/attributes/readonly_spec.rb +22 -23
- data/spec/mongoid/attributes_spec.rb +888 -62
- data/spec/mongoid/cacheable_spec.rb +4 -5
- data/spec/mongoid/changeable_spec.rb +464 -73
- data/spec/mongoid/clients/factory_spec.rb +91 -9
- data/spec/mongoid/clients/options_spec.rb +27 -19
- data/spec/mongoid/clients/sessions_spec.rb +27 -67
- data/spec/mongoid/clients/transactions_spec.rb +69 -35
- data/spec/mongoid/clients_spec.rb +187 -24
- data/spec/mongoid/collection_configurable_spec.rb +158 -0
- data/spec/mongoid/composable_spec.rb +0 -1
- data/spec/mongoid/config/defaults_spec.rb +160 -0
- data/spec/mongoid/config/environment_spec.rb +124 -9
- data/spec/mongoid/config/options_spec.rb +0 -1
- data/spec/mongoid/config_spec.rb +465 -1
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +431 -154
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +120 -21
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +148 -86
- data/spec/mongoid/contextual/geo_near_spec.rb +28 -20
- data/spec/mongoid/contextual/map_reduce_spec.rb +20 -20
- data/spec/mongoid/contextual/memory_spec.rb +1826 -304
- data/spec/mongoid/contextual/mongo/documents_loader_spec.rb +187 -0
- data/spec/mongoid/contextual/mongo_spec.rb +3501 -1272
- data/spec/mongoid/contextual/none_spec.rb +78 -68
- data/spec/mongoid/copyable_spec.rb +657 -37
- data/spec/mongoid/copyable_spec_models.rb +28 -1
- data/spec/mongoid/criteria/findable_spec.rb +109 -234
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +0 -1
- data/spec/mongoid/criteria/marshalable_spec.rb +18 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +37 -38
- data/spec/mongoid/criteria/options_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +0 -74
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +7 -20
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +134 -27
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +11 -1
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +11 -1
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +0 -16
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +73 -8
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +237 -179
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +7 -8
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +5 -71
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +0 -60
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +30 -8
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +39 -2
- data/spec/mongoid/criteria/queryable/key_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +143 -13
- data/spec/mongoid/criteria/queryable/optional_spec.rb +16 -486
- data/spec/mongoid/criteria/queryable/options_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +1 -2
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1186 -195
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +307 -705
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +15 -4
- data/spec/mongoid/criteria/queryable/smash_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/storable_spec.rb +37 -1
- data/spec/mongoid/criteria/scopable_spec.rb +127 -1
- data/spec/mongoid/criteria/translator_spec.rb +132 -0
- data/spec/mongoid/criteria_projection_spec.rb +406 -0
- data/spec/mongoid/criteria_spec.rb +1267 -1739
- data/spec/mongoid/document_fields_spec.rb +179 -5
- data/spec/mongoid/document_persistence_context_spec.rb +32 -0
- data/spec/mongoid/document_query_spec.rb +51 -1
- data/spec/mongoid/document_spec.rb +151 -88
- data/spec/mongoid/equality_spec.rb +142 -42
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +0 -1
- data/spec/mongoid/errors/callback_spec.rb +0 -1
- data/spec/mongoid/errors/delete_restriction_spec.rb +2 -3
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +0 -1
- data/spec/mongoid/errors/document_not_found_spec.rb +76 -1
- data/spec/mongoid/errors/invalid_collection_spec.rb +0 -1
- data/spec/mongoid/errors/{eager_load_spec.rb → invalid_config_file_spec.rb} +5 -6
- data/spec/mongoid/errors/invalid_config_option_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_field_option_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_field_spec.rb +1 -2
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_includes_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_index_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_options_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_path_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_relation_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_scope_spec.rb +1 -2
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +0 -1
- data/spec/mongoid/errors/invalid_time_spec.rb +0 -1
- data/spec/mongoid/errors/inverse_not_found_spec.rb +0 -1
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +0 -1
- data/spec/mongoid/errors/mixed_relations_spec.rb +0 -1
- data/spec/mongoid/errors/mongoid_error_spec.rb +22 -9
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +0 -1
- data/spec/mongoid/errors/no_client_config_spec.rb +2 -3
- data/spec/mongoid/errors/no_client_database_spec.rb +3 -4
- data/spec/mongoid/errors/no_client_hosts_spec.rb +3 -4
- data/spec/mongoid/errors/no_clients_config_spec.rb +0 -1
- data/spec/mongoid/errors/no_environment_spec.rb +3 -4
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +0 -1
- data/spec/mongoid/errors/no_metadata_spec.rb +0 -1
- data/spec/mongoid/errors/no_parent_spec.rb +0 -1
- data/spec/mongoid/errors/readonly_attribute_spec.rb +0 -1
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -3
- data/spec/mongoid/errors/scope_overwrite_spec.rb +0 -1
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +1 -2
- data/spec/mongoid/errors/unknown_attribute_spec.rb +2 -3
- data/spec/mongoid/errors/unsaved_document_spec.rb +0 -1
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +0 -1
- data/spec/mongoid/errors/validations_spec.rb +0 -1
- data/spec/mongoid/extensions/array_spec.rb +16 -3
- data/spec/mongoid/extensions/big_decimal_spec.rb +712 -213
- data/spec/mongoid/extensions/binary_spec.rb +44 -10
- data/spec/mongoid/extensions/boolean_spec.rb +68 -83
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +7 -4
- data/spec/mongoid/extensions/date_spec.rb +71 -2
- data/spec/mongoid/extensions/date_time_spec.rb +15 -10
- data/spec/mongoid/extensions/decimal128_spec.rb +0 -1
- data/spec/mongoid/extensions/false_class_spec.rb +1 -2
- data/spec/mongoid/extensions/float_spec.rb +53 -75
- data/spec/mongoid/extensions/hash_spec.rb +30 -1
- data/spec/mongoid/extensions/integer_spec.rb +50 -65
- data/spec/mongoid/extensions/module_spec.rb +0 -1
- data/spec/mongoid/extensions/nil_class_spec.rb +0 -1
- data/spec/mongoid/extensions/object_id_spec.rb +0 -1
- data/spec/mongoid/extensions/object_spec.rb +0 -1
- data/spec/mongoid/extensions/range_spec.rb +255 -55
- data/spec/mongoid/extensions/regexp_spec.rb +58 -34
- data/spec/mongoid/extensions/set_spec.rb +106 -1
- data/spec/mongoid/extensions/string_spec.rb +58 -31
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +18 -26
- data/spec/mongoid/extensions/time_spec.rb +639 -107
- data/spec/mongoid/extensions/time_with_zone_spec.rb +24 -84
- data/spec/mongoid/extensions/true_class_spec.rb +1 -2
- data/spec/mongoid/extensions_spec.rb +14 -3
- data/spec/mongoid/factory_spec.rb +323 -30
- data/spec/mongoid/fields/foreign_key_spec.rb +0 -1
- data/spec/mongoid/fields/localized_spec.rb +84 -42
- data/spec/mongoid/fields/standard_spec.rb +0 -1
- data/spec/mongoid/fields_spec.rb +855 -118
- data/spec/mongoid/findable_spec.rb +518 -65
- data/spec/mongoid/indexable/specification_spec.rb +2 -3
- data/spec/mongoid/indexable_spec.rb +85 -33
- data/spec/mongoid/inspectable_spec.rb +37 -3
- data/spec/mongoid/interceptable_spec.rb +702 -104
- data/spec/mongoid/interceptable_spec_models.rb +235 -4
- data/spec/mongoid/loggable_spec.rb +0 -1
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +36 -0
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +112 -30
- data/spec/mongoid/persistable/deletable_spec.rb +298 -19
- data/spec/mongoid/persistable/destroyable_spec.rb +226 -19
- data/spec/mongoid/persistable/incrementable_spec.rb +45 -9
- data/spec/mongoid/persistable/logical_spec.rb +41 -5
- data/spec/mongoid/persistable/poppable_spec.rb +40 -5
- data/spec/mongoid/persistable/pullable_spec.rb +80 -9
- data/spec/mongoid/persistable/pushable_spec.rb +80 -9
- data/spec/mongoid/persistable/renamable_spec.rb +39 -4
- data/spec/mongoid/persistable/savable_spec.rb +282 -26
- data/spec/mongoid/persistable/settable_spec.rb +76 -10
- data/spec/mongoid/persistable/unsettable_spec.rb +40 -5
- data/spec/mongoid/persistable/updatable_spec.rb +61 -50
- data/spec/mongoid/persistable/upsertable_spec.rb +91 -4
- data/spec/mongoid/persistable_spec.rb +3 -4
- data/spec/mongoid/persistence_context_spec.rb +57 -59
- data/spec/mongoid/positional_spec.rb +0 -1
- data/spec/mongoid/query_cache_middleware_spec.rb +7 -5
- data/spec/mongoid/query_cache_spec.rb +424 -68
- data/spec/mongoid/relations/proxy_spec.rb +7 -8
- data/spec/mongoid/reloadable_spec.rb +355 -27
- data/spec/mongoid/scopable_spec.rb +191 -39
- data/spec/mongoid/selectable_spec.rb +6 -7
- data/spec/mongoid/serializable_spec.rb +35 -39
- data/spec/mongoid/shardable_models.rb +15 -1
- data/spec/mongoid/shardable_spec.rb +181 -32
- data/spec/mongoid/stateful_spec.rb +151 -10
- data/spec/mongoid/tasks/database_rake_spec.rb +87 -14
- data/spec/mongoid/tasks/database_spec.rb +128 -2
- data/spec/mongoid/threaded_spec.rb +2 -3
- data/spec/mongoid/timestamps/created/short_spec.rb +1 -2
- data/spec/mongoid/timestamps/created_spec.rb +1 -2
- data/spec/mongoid/timestamps/timeless_spec.rb +2 -3
- data/spec/mongoid/timestamps/updated/short_spec.rb +3 -4
- data/spec/mongoid/timestamps/updated_spec.rb +3 -4
- data/spec/mongoid/timestamps_spec.rb +398 -11
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +525 -36
- data/spec/mongoid/touchable_spec_models.rb +59 -0
- data/spec/mongoid/traversable_spec.rb +1143 -2
- data/spec/mongoid/validatable/associated_spec.rb +0 -1
- data/spec/mongoid/validatable/format_spec.rb +0 -1
- data/spec/mongoid/validatable/length_spec.rb +0 -1
- data/spec/mongoid/validatable/numericality_spec.rb +0 -1
- data/spec/mongoid/validatable/presence_spec.rb +26 -23
- data/spec/mongoid/validatable/uniqueness_spec.rb +125 -99
- data/spec/mongoid/validatable_spec.rb +3 -4
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +35 -10
- data/spec/rails/controller_extension/controller_runtime_spec.rb +2 -3
- data/spec/rails/mongoid_spec.rb +4 -17
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/share/Dockerfile.erb +321 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +416 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +24 -54
- data/spec/support/authorization.rb +0 -1
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +34 -197
- data/spec/support/expectations.rb +0 -1
- data/spec/support/helpers.rb +1 -1
- data/spec/support/immutable_ids.rb +118 -0
- data/spec/support/macros.rb +109 -1
- data/spec/{app → support}/models/account.rb +1 -2
- data/spec/{app → support}/models/acolyte.rb +0 -1
- data/spec/{app → support}/models/actor.rb +1 -2
- data/spec/{app → support}/models/actress.rb +0 -1
- data/spec/{app → support}/models/address.rb +4 -1
- data/spec/{app → support}/models/address_component.rb +0 -1
- data/spec/{app → support}/models/address_number.rb +0 -1
- data/spec/{app → support}/models/agency.rb +0 -1
- data/spec/{app → support}/models/agent.rb +0 -1
- data/spec/{app → support}/models/album.rb +0 -1
- data/spec/{app → support}/models/alert.rb +0 -1
- data/spec/{app → support}/models/animal.rb +0 -1
- data/spec/{app → support}/models/answer.rb +0 -1
- data/spec/{app → support}/models/appointment.rb +0 -1
- data/spec/support/models/armrest.rb +9 -0
- data/spec/{app → support}/models/array_field.rb +0 -1
- data/spec/{app → support}/models/article.rb +0 -1
- data/spec/{app → support}/models/artist.rb +2 -2
- data/spec/{app → support}/models/artwork.rb +0 -1
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/{app → support}/models/audio.rb +0 -1
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/{app → support}/models/author.rb +0 -1
- data/spec/{app → support}/models/baby.rb +0 -1
- data/spec/{app → support}/models/band.rb +8 -1
- data/spec/{app → support}/models/bar.rb +0 -1
- data/spec/{app → support}/models/basic.rb +0 -1
- data/spec/{app → support}/models/bed.rb +0 -1
- data/spec/{app → support}/models/big_palette.rb +0 -1
- data/spec/{app → support}/models/birthday.rb +0 -1
- data/spec/support/models/bolt.rb +7 -0
- data/spec/{app → support}/models/bomb.rb +0 -1
- data/spec/{app → support}/models/book.rb +1 -1
- data/spec/{app → support}/models/breed.rb +0 -1
- data/spec/{app → support}/models/browser.rb +1 -2
- data/spec/{app → support}/models/building.rb +2 -1
- data/spec/{app → support}/models/building_address.rb +0 -1
- data/spec/{app → support}/models/bus.rb +0 -1
- data/spec/{app → support}/models/business.rb +0 -1
- data/spec/{app → support}/models/callback_test.rb +0 -1
- data/spec/{app → support}/models/canvas.rb +1 -2
- data/spec/{app → support}/models/car.rb +0 -1
- data/spec/{app → support}/models/cat.rb +0 -1
- data/spec/support/models/catalog.rb +24 -0
- data/spec/{app → support}/models/category.rb +0 -1
- data/spec/{app → support}/models/child.rb +0 -1
- data/spec/{app → support}/models/child_doc.rb +3 -4
- data/spec/{app → support}/models/church.rb +0 -1
- data/spec/{app → support}/models/circle.rb +0 -1
- data/spec/{app → support}/models/circuit.rb +0 -1
- data/spec/{app → support}/models/circus.rb +3 -1
- data/spec/{app → support}/models/code.rb +2 -1
- data/spec/{app → support}/models/coding/pull_request.rb +0 -1
- data/spec/support/models/coding.rb +3 -0
- data/spec/{app → support}/models/comment.rb +0 -1
- data/spec/{app → support}/models/company.rb +0 -1
- data/spec/{app → support}/models/consumption_period.rb +0 -1
- data/spec/{app → support}/models/contextable_item.rb +0 -1
- data/spec/{app → support}/models/contractor.rb +0 -1
- data/spec/{app → support}/models/cookie.rb +0 -1
- data/spec/{app → support}/models/country_code.rb +2 -1
- data/spec/{app → support}/models/courier_job.rb +0 -1
- data/spec/support/models/cover.rb +10 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +7 -0
- data/spec/{app → support}/models/definition.rb +0 -1
- data/spec/{app → support}/models/delegating_patient.rb +0 -1
- data/spec/{app → support}/models/description.rb +0 -1
- data/spec/{app → support}/models/dictionary.rb +6 -1
- data/spec/{app → support}/models/division.rb +0 -1
- data/spec/{app → support}/models/doctor.rb +0 -1
- data/spec/{app → support}/models/dog.rb +0 -1
- data/spec/{app → support}/models/dokument.rb +0 -1
- data/spec/{app → support}/models/draft.rb +0 -1
- data/spec/{app → support}/models/dragon.rb +0 -1
- data/spec/{app → support}/models/driver.rb +1 -2
- data/spec/{app → support}/models/drug.rb +0 -1
- data/spec/{app → support}/models/dungeon.rb +0 -1
- data/spec/{app → support}/models/edit.rb +0 -1
- data/spec/{app → support}/models/email.rb +0 -1
- data/spec/{app → support}/models/employer.rb +0 -1
- data/spec/{app → support}/models/entry.rb +0 -1
- data/spec/{app → support}/models/eraser.rb +0 -1
- data/spec/{app → support}/models/even.rb +0 -1
- data/spec/{app → support}/models/event.rb +0 -1
- data/spec/{app → support}/models/exhibition.rb +0 -1
- data/spec/{app → support}/models/exhibitor.rb +0 -1
- data/spec/{app → support}/models/explosion.rb +0 -1
- data/spec/{app → support}/models/eye.rb +0 -1
- data/spec/{app → support}/models/eye_bowl.rb +0 -1
- data/spec/{app → support}/models/face.rb +0 -1
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/{app → support}/models/favorite.rb +0 -1
- data/spec/{app → support}/models/filesystem.rb +0 -1
- data/spec/{app → support}/models/fire_hydrant.rb +0 -1
- data/spec/{app → support}/models/firefox.rb +0 -1
- data/spec/{app → support}/models/fish.rb +0 -1
- data/spec/{app → support}/models/folder.rb +0 -1
- data/spec/{app → support}/models/folder_item.rb +0 -1
- data/spec/{app → support}/models/fruits.rb +0 -1
- data/spec/{app → support}/models/game.rb +0 -1
- data/spec/{app → support}/models/ghost.rb +0 -1
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/{app → support}/models/home.rb +0 -1
- data/spec/{app → support}/models/house.rb +0 -1
- data/spec/{app → support}/models/html_writer.rb +0 -1
- data/spec/{app → support}/models/id_key.rb +0 -1
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/{app → support}/models/image.rb +0 -1
- data/spec/{app → support}/models/implant.rb +9 -1
- data/spec/support/models/instrument.rb +8 -0
- data/spec/{app → support}/models/item.rb +1 -2
- data/spec/{app → support}/models/jar.rb +0 -1
- data/spec/{app → support}/models/kaleidoscope.rb +0 -1
- data/spec/{app → support}/models/kangaroo.rb +0 -1
- data/spec/{app → support}/models/label.rb +4 -2
- data/spec/{app → support}/models/language.rb +0 -1
- data/spec/{app → support}/models/lat_lng.rb +0 -1
- data/spec/{app → support}/models/league.rb +0 -1
- data/spec/{app → support}/models/learner.rb +0 -1
- data/spec/{app → support}/models/line_item.rb +0 -1
- data/spec/{app → support}/models/location.rb +0 -1
- data/spec/{app → support}/models/login.rb +0 -1
- data/spec/{app → support}/models/manufacturer.rb +0 -1
- data/spec/{app → support}/models/meat.rb +0 -1
- data/spec/{app → support}/models/membership.rb +1 -1
- data/spec/{app → support}/models/message.rb +0 -1
- data/spec/{app → support}/models/minim.rb +0 -1
- data/spec/{app → support}/models/mixed_drink.rb +0 -1
- data/spec/support/models/mop.rb +24 -0
- data/spec/{app → support}/models/movie.rb +0 -1
- data/spec/{app → support}/models/my_hash.rb +0 -1
- data/spec/{app → support}/models/name.rb +0 -1
- data/spec/{app → support}/models/name_only.rb +0 -1
- data/spec/{app → support}/models/node.rb +0 -1
- data/spec/{app → support}/models/note.rb +0 -1
- data/spec/support/models/nut.rb +7 -0
- data/spec/{app → support}/models/odd.rb +0 -1
- data/spec/support/models/order.rb +12 -0
- data/spec/{app → support}/models/ordered_post.rb +1 -2
- data/spec/{app → support}/models/ordered_preference.rb +0 -1
- data/spec/{app → support}/models/oscar.rb +0 -1
- data/spec/{app → support}/models/other_owner_object.rb +0 -1
- data/spec/{app → support}/models/override.rb +0 -1
- data/spec/{app → support}/models/ownable.rb +0 -1
- data/spec/{app → support}/models/owner.rb +2 -1
- data/spec/{app → support}/models/pack.rb +0 -1
- data/spec/{app → support}/models/page.rb +0 -1
- data/spec/{app → support}/models/page_question.rb +0 -1
- data/spec/{app → support}/models/palette.rb +1 -2
- data/spec/{app → support}/models/parent.rb +0 -1
- data/spec/{app → support}/models/parent_doc.rb +0 -1
- data/spec/support/models/passport.rb +22 -0
- data/spec/{app → support}/models/patient.rb +0 -1
- data/spec/{app → support}/models/pdf_writer.rb +0 -1
- data/spec/{app → support}/models/pencil.rb +0 -1
- data/spec/{app → support}/models/person.rb +20 -2
- data/spec/{app → support}/models/pet.rb +0 -1
- data/spec/{app → support}/models/pet_owner.rb +0 -1
- data/spec/{app → support}/models/phone.rb +3 -2
- data/spec/support/models/piano.rb +4 -0
- data/spec/{app → support}/models/pizza.rb +0 -1
- data/spec/{app → support}/models/player.rb +2 -1
- data/spec/{app → support}/models/post.rb +0 -1
- data/spec/{app → support}/models/post_genre.rb +0 -1
- data/spec/support/models/powerup.rb +25 -0
- data/spec/{app → support}/models/preference.rb +0 -1
- data/spec/{app → support}/models/princess.rb +0 -1
- data/spec/{app → support}/models/product.rb +1 -1
- data/spec/support/models/profile.rb +17 -0
- data/spec/{app → support}/models/pronunciation.rb +0 -1
- data/spec/{app → support}/models/pub.rb +0 -1
- data/spec/{app → support}/models/publication/encyclopedia.rb +0 -1
- data/spec/{app → support}/models/publication/review.rb +0 -1
- data/spec/support/models/publication.rb +4 -0
- data/spec/{app → support}/models/purchase.rb +0 -1
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/{app → support}/models/question.rb +0 -1
- data/spec/{app → support}/models/quiz.rb +0 -1
- data/spec/{app → support}/models/rating.rb +0 -1
- data/spec/{app → support}/models/record.rb +0 -1
- data/spec/{app → support}/models/registry.rb +1 -1
- data/spec/{app → support}/models/role.rb +0 -1
- data/spec/{app → support}/models/root_category.rb +0 -1
- data/spec/{app → support}/models/sandwich.rb +0 -1
- data/spec/{app → support}/models/scheduler.rb +0 -1
- data/spec/support/models/school.rb +14 -0
- data/spec/{app/models/profile.rb → support/models/scribe.rb} +2 -3
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/{app → support}/models/seo.rb +0 -1
- data/spec/{app → support}/models/series.rb +1 -1
- data/spec/{app → support}/models/server.rb +0 -1
- data/spec/{app → support}/models/service.rb +0 -1
- data/spec/{app → support}/models/shape.rb +2 -3
- data/spec/{app → support}/models/shelf.rb +0 -1
- data/spec/support/models/shield.rb +18 -0
- data/spec/{app → support}/models/shipment_address.rb +0 -1
- data/spec/{app → support}/models/shipping_container.rb +0 -1
- data/spec/{app → support}/models/shipping_pack.rb +0 -1
- data/spec/support/models/shirt.rb +11 -0
- data/spec/{app → support}/models/shop.rb +0 -1
- data/spec/{app → support}/models/short_agent.rb +0 -1
- data/spec/{app → support}/models/short_quiz.rb +0 -1
- data/spec/{app → support}/models/simple.rb +0 -1
- data/spec/{app → support}/models/slave.rb +0 -1
- data/spec/{app → support}/models/song.rb +0 -1
- data/spec/{app → support}/models/sound.rb +0 -1
- data/spec/support/models/spacer.rb +7 -0
- data/spec/{app → support}/models/square.rb +0 -1
- data/spec/{app → support}/models/staff.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test1.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test2.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test3.rb +0 -1
- data/spec/{app → support}/models/store_as_dup_test4.rb +0 -1
- data/spec/{app → support}/models/strategy.rb +0 -1
- data/spec/support/models/student.rb +14 -0
- data/spec/{app → support}/models/sub_item.rb +0 -1
- data/spec/{app → support}/models/subscription.rb +0 -1
- data/spec/{app → support}/models/survey.rb +0 -1
- data/spec/{app → support}/models/symptom.rb +0 -1
- data/spec/support/models/system_role.rb +7 -0
- data/spec/{app → support}/models/tag.rb +0 -1
- data/spec/{app → support}/models/target.rb +0 -1
- data/spec/{app → support}/models/template.rb +0 -1
- data/spec/{app → support}/models/thing.rb +0 -1
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/{app → support}/models/title.rb +0 -1
- data/spec/{app → support}/models/tool.rb +2 -3
- data/spec/{app → support}/models/topping.rb +0 -1
- data/spec/support/models/toy.rb +9 -0
- data/spec/{app → support}/models/track.rb +0 -1
- data/spec/{app → support}/models/translation.rb +0 -1
- data/spec/{app → support}/models/tree.rb +0 -1
- data/spec/{app → support}/models/truck.rb +2 -1
- data/spec/{app → support}/models/updatable.rb +0 -1
- data/spec/{app → support}/models/user.rb +0 -1
- data/spec/{app → support}/models/user_account.rb +0 -1
- data/spec/{app → support}/models/validation_callback.rb +0 -1
- data/spec/{app → support}/models/vehicle.rb +7 -3
- data/spec/{app → support}/models/version.rb +0 -1
- data/spec/{app → support}/models/vertex.rb +0 -1
- data/spec/{app → support}/models/vet_visit.rb +0 -1
- data/spec/{app → support}/models/video.rb +0 -1
- data/spec/{app → support}/models/video_game.rb +0 -1
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/{app → support}/models/wiki_page.rb +1 -1
- data/spec/{app → support}/models/word.rb +0 -1
- data/spec/{app → support}/models/word_origin.rb +0 -1
- data/spec/{app → support}/models/writer.rb +2 -3
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +0 -1
- data/spec/support/spec_config.rb +28 -6
- data.tar.gz.sig +0 -0
- metadata +1216 -799
- metadata.gz.sig +0 -0
- data/lib/mongoid/errors/eager_load.rb +0 -26
- data/lib/mongoid/errors/invalid_value.rb +0 -18
- data/lib/mongoid/matchable/all.rb +0 -30
- data/lib/mongoid/matchable/and.rb +0 -32
- data/lib/mongoid/matchable/default.rb +0 -121
- data/lib/mongoid/matchable/elem_match.rb +0 -36
- data/lib/mongoid/matchable/eq.rb +0 -23
- data/lib/mongoid/matchable/exists.rb +0 -25
- data/lib/mongoid/matchable/gt.rb +0 -25
- data/lib/mongoid/matchable/gte.rb +0 -25
- data/lib/mongoid/matchable/in.rb +0 -26
- data/lib/mongoid/matchable/lt.rb +0 -25
- data/lib/mongoid/matchable/lte.rb +0 -25
- data/lib/mongoid/matchable/ne.rb +0 -23
- data/lib/mongoid/matchable/nin.rb +0 -24
- data/lib/mongoid/matchable/nor.rb +0 -38
- data/lib/mongoid/matchable/or.rb +0 -35
- data/lib/mongoid/matchable/regexp.rb +0 -30
- data/lib/mongoid/matchable/size.rb +0 -23
- data/lib/support/ruby_version.rb +0 -29
- data/spec/app/models/augmentation.rb +0 -14
- data/spec/app/models/coding.rb +0 -4
- data/spec/app/models/passport.rb +0 -8
- data/spec/app/models/powerup.rb +0 -14
- data/spec/app/models/publication.rb +0 -5
- data/spec/app/models/weapon.rb +0 -14
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +0 -61
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +0 -61
- data/spec/mongoid/matchable/all_spec.rb +0 -34
- data/spec/mongoid/matchable/and_spec.rb +0 -190
- data/spec/mongoid/matchable/default_spec.rb +0 -140
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -109
- data/spec/mongoid/matchable/eq_spec.rb +0 -49
- data/spec/mongoid/matchable/exists_spec.rb +0 -60
- data/spec/mongoid/matchable/gt_spec.rb +0 -89
- data/spec/mongoid/matchable/gte_spec.rb +0 -87
- data/spec/mongoid/matchable/in_spec.rb +0 -52
- data/spec/mongoid/matchable/lt_spec.rb +0 -88
- data/spec/mongoid/matchable/lte_spec.rb +0 -88
- data/spec/mongoid/matchable/ne_spec.rb +0 -49
- data/spec/mongoid/matchable/nin_spec.rb +0 -51
- data/spec/mongoid/matchable/nor_spec.rb +0 -210
- data/spec/mongoid/matchable/or_spec.rb +0 -134
- data/spec/mongoid/matchable/regexp_spec.rb +0 -62
- data/spec/mongoid/matchable/size_spec.rb +0 -28
- data/spec/mongoid/matchable_spec.rb +0 -856
- data/spec/support/cluster_config.rb +0 -158
- data/spec/support/lite_constraints.rb +0 -22
@@ -1,17 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# encoding: utf-8
|
3
2
|
|
4
3
|
require "spec_helper"
|
4
|
+
require_relative "../has_and_belongs_to_many_models"
|
5
5
|
|
6
6
|
describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
7
|
+
config_override :raise_not_found_error, true
|
7
8
|
|
8
9
|
around(:each) do |example|
|
9
|
-
original_raise_not_found_error = Mongoid.raise_not_found_error
|
10
10
|
original_preferences_association = Person.relations["preferences"]
|
11
|
-
Mongoid.raise_not_found_error = true
|
12
11
|
Person.has_and_belongs_to_many :preferences, autosave: true
|
13
12
|
example.run
|
14
|
-
Mongoid.raise_not_found_error = original_raise_not_found_error
|
15
13
|
Person.relations["preferences"] = original_preferences_association
|
16
14
|
end
|
17
15
|
|
@@ -27,7 +25,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
27
25
|
context "when the inverse_of is nil" do
|
28
26
|
|
29
27
|
let!(:article) do
|
30
|
-
Article.create
|
28
|
+
Article.create!
|
31
29
|
end
|
32
30
|
|
33
31
|
context "when the child document is new" do
|
@@ -48,7 +46,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
48
46
|
context "when the child document is not new" do
|
49
47
|
|
50
48
|
let(:preference) do
|
51
|
-
Preference.create
|
49
|
+
Preference.create!
|
52
50
|
end
|
53
51
|
|
54
52
|
it "does not persist the child document" do
|
@@ -80,7 +78,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
80
78
|
context "when the parent is not a new record" do
|
81
79
|
|
82
80
|
let(:person) do
|
83
|
-
Person.create
|
81
|
+
Person.create!
|
84
82
|
end
|
85
83
|
|
86
84
|
let!(:preference) do
|
@@ -124,11 +122,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
124
122
|
context "when appending in a parent create block" do
|
125
123
|
|
126
124
|
let!(:preference) do
|
127
|
-
Preference.create(name: "testing")
|
125
|
+
Preference.create!(name: "testing")
|
128
126
|
end
|
129
127
|
|
130
128
|
let!(:person) do
|
131
|
-
Person.create do |doc|
|
129
|
+
Person.create! do |doc|
|
132
130
|
doc.preferences << preference
|
133
131
|
end
|
134
132
|
end
|
@@ -213,7 +211,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
213
211
|
context "when the child is already persisted" do
|
214
212
|
|
215
213
|
let!(:persisted) do
|
216
|
-
Preference.create(name: "testy")
|
214
|
+
Preference.create!(name: "testy")
|
217
215
|
end
|
218
216
|
|
219
217
|
let(:preference) do
|
@@ -222,7 +220,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
222
220
|
|
223
221
|
before do
|
224
222
|
person.preferences.send(method, preference)
|
225
|
-
person.save
|
223
|
+
person.save!
|
226
224
|
end
|
227
225
|
|
228
226
|
it "adds the documents to the relation" do
|
@@ -253,7 +251,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
253
251
|
context "when setting via the associated ids" do
|
254
252
|
|
255
253
|
let!(:persisted) do
|
256
|
-
Preference.create(name: "testy")
|
254
|
+
Preference.create!(name: "testy")
|
257
255
|
end
|
258
256
|
|
259
257
|
let(:preference) do
|
@@ -265,7 +263,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
265
263
|
end
|
266
264
|
|
267
265
|
before do
|
268
|
-
person.save
|
266
|
+
person.save!
|
269
267
|
end
|
270
268
|
|
271
269
|
it "adds the documents to the relation" do
|
@@ -293,7 +291,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
293
291
|
context "when the parent is not a new record" do
|
294
292
|
|
295
293
|
let(:person) do
|
296
|
-
Person.create
|
294
|
+
Person.create!
|
297
295
|
end
|
298
296
|
|
299
297
|
let(:preference) do
|
@@ -375,11 +373,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
375
373
|
context "when both sides have been persisted" do
|
376
374
|
|
377
375
|
let(:person) do
|
378
|
-
Person.create
|
376
|
+
Person.create!
|
379
377
|
end
|
380
378
|
|
381
379
|
let(:event) do
|
382
|
-
Event.create
|
380
|
+
Event.create!
|
383
381
|
end
|
384
382
|
|
385
383
|
before do
|
@@ -428,15 +426,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
428
426
|
context "when the relation also includes a has_many relation" do
|
429
427
|
|
430
428
|
let(:artwork) do
|
431
|
-
Artwork.create
|
429
|
+
Artwork.create!
|
432
430
|
end
|
433
431
|
|
434
432
|
let(:exhibition) do
|
435
|
-
Exhibition.create
|
433
|
+
Exhibition.create!
|
436
434
|
end
|
437
435
|
|
438
436
|
let(:exhibitor) do
|
439
|
-
Exhibitor.create(exhibition: exhibition)
|
437
|
+
Exhibitor.create!(exhibition: exhibition)
|
440
438
|
end
|
441
439
|
|
442
440
|
before do
|
@@ -451,11 +449,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
451
449
|
context "when the relation is self referencing" do
|
452
450
|
|
453
451
|
let(:tag_one) do
|
454
|
-
Tag.create(text: "one")
|
452
|
+
Tag.create!(text: "one")
|
455
453
|
end
|
456
454
|
|
457
455
|
let(:tag_two) do
|
458
|
-
Tag.create(text: "two")
|
456
|
+
Tag.create!(text: "two")
|
459
457
|
end
|
460
458
|
|
461
459
|
before do
|
@@ -564,7 +562,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
564
562
|
end
|
565
563
|
|
566
564
|
let(:preference) do
|
567
|
-
Preference.create(name: "one")
|
565
|
+
Preference.create!(name: "one")
|
568
566
|
end
|
569
567
|
|
570
568
|
before do
|
@@ -585,7 +583,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
585
583
|
context "when the document is persisted" do
|
586
584
|
|
587
585
|
before do
|
588
|
-
person.save
|
586
|
+
person.save!
|
589
587
|
end
|
590
588
|
|
591
589
|
it "does not add the duplicates" do
|
@@ -656,7 +654,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
656
654
|
end
|
657
655
|
|
658
656
|
let!(:preference) do
|
659
|
-
Preference.create
|
657
|
+
Preference.create!
|
660
658
|
end
|
661
659
|
|
662
660
|
before do
|
@@ -703,7 +701,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
703
701
|
context "when the parent is not a new record" do
|
704
702
|
|
705
703
|
let(:person) do
|
706
|
-
Person.create
|
704
|
+
Person.create!
|
707
705
|
end
|
708
706
|
|
709
707
|
let(:preference) do
|
@@ -787,7 +785,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
787
785
|
expect(person.preferences).to eq([ another_preference ])
|
788
786
|
end
|
789
787
|
|
790
|
-
it "persists the relation between
|
788
|
+
it "persists the relation between another_preference and person" do
|
791
789
|
expect(another_preference.people).to eq([ person ])
|
792
790
|
end
|
793
791
|
|
@@ -799,7 +797,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
799
797
|
context "and person is saved" do
|
800
798
|
|
801
799
|
before do
|
802
|
-
person.save
|
800
|
+
person.save!
|
803
801
|
person.reload
|
804
802
|
another_preference.reload
|
805
803
|
end
|
@@ -808,7 +806,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
808
806
|
expect(person.preferences).to eq([ another_preference ])
|
809
807
|
end
|
810
808
|
|
811
|
-
it "persists the relation between
|
809
|
+
it "persists the relation between another_preference and person" do
|
812
810
|
expect(another_preference.people).to eq([ person ])
|
813
811
|
end
|
814
812
|
|
@@ -823,11 +821,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
823
821
|
|
824
822
|
describe "when self-referencing" do
|
825
823
|
let!(:parent) do
|
826
|
-
Vertex.create
|
824
|
+
Vertex.create!
|
827
825
|
end
|
828
826
|
|
829
827
|
let!(:child) do
|
830
|
-
Vertex.create(parents: [parent])
|
828
|
+
Vertex.create!(parents: [parent])
|
831
829
|
end
|
832
830
|
|
833
831
|
before do
|
@@ -964,7 +962,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
964
962
|
context "when the relation has been loaded" do
|
965
963
|
|
966
964
|
let(:person) do
|
967
|
-
Person.create
|
965
|
+
Person.create!
|
968
966
|
end
|
969
967
|
|
970
968
|
let(:preference) do
|
@@ -1004,7 +1002,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1004
1002
|
end
|
1005
1003
|
|
1006
1004
|
let(:person) do
|
1007
|
-
Person.create
|
1005
|
+
Person.create!.tap do |p|
|
1008
1006
|
p.preferences = [ preference ]
|
1009
1007
|
end
|
1010
1008
|
end
|
@@ -1074,7 +1072,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1074
1072
|
context "when the parent is not a new record" do
|
1075
1073
|
|
1076
1074
|
let(:person) do
|
1077
|
-
Person.create
|
1075
|
+
Person.create!
|
1078
1076
|
end
|
1079
1077
|
|
1080
1078
|
let!(:preference) do
|
@@ -1112,7 +1110,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1112
1110
|
context "when saving the target" do
|
1113
1111
|
|
1114
1112
|
before do
|
1115
|
-
preference.save
|
1113
|
+
preference.save!
|
1116
1114
|
end
|
1117
1115
|
|
1118
1116
|
it "persists the parent keys" do
|
@@ -1131,13 +1129,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1131
1129
|
context "when the parent has been persisted" do
|
1132
1130
|
|
1133
1131
|
let!(:person) do
|
1134
|
-
Person.create
|
1132
|
+
Person.create!
|
1135
1133
|
end
|
1136
1134
|
|
1137
1135
|
context "when the children are persisted" do
|
1138
1136
|
|
1139
1137
|
let!(:preference) do
|
1140
|
-
person.preferences.create(name: "settings")
|
1138
|
+
person.preferences.create!(name: "settings")
|
1141
1139
|
end
|
1142
1140
|
|
1143
1141
|
let!(:relation) do
|
@@ -1309,7 +1307,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1309
1307
|
context "when the parent is not a new record" do
|
1310
1308
|
|
1311
1309
|
let(:person) do
|
1312
|
-
Person.create
|
1310
|
+
Person.create!
|
1313
1311
|
end
|
1314
1312
|
|
1315
1313
|
let!(:preference) do
|
@@ -1353,11 +1351,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1353
1351
|
context "when appending in a parent create block" do
|
1354
1352
|
|
1355
1353
|
let!(:preference) do
|
1356
|
-
Preference.create(name: "testing")
|
1354
|
+
Preference.create!(name: "testing")
|
1357
1355
|
end
|
1358
1356
|
|
1359
1357
|
let!(:person) do
|
1360
|
-
Person.create do |doc|
|
1358
|
+
Person.create! do |doc|
|
1361
1359
|
doc.preferences.concat([ preference ])
|
1362
1360
|
end
|
1363
1361
|
end
|
@@ -1442,7 +1440,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1442
1440
|
context "when the child is already persisted" do
|
1443
1441
|
|
1444
1442
|
let!(:persisted) do
|
1445
|
-
Preference.create(name: "testy")
|
1443
|
+
Preference.create!(name: "testy")
|
1446
1444
|
end
|
1447
1445
|
|
1448
1446
|
let(:preference) do
|
@@ -1451,7 +1449,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1451
1449
|
|
1452
1450
|
before do
|
1453
1451
|
person.preferences.concat([ preference ])
|
1454
|
-
person.save
|
1452
|
+
person.save!
|
1455
1453
|
end
|
1456
1454
|
|
1457
1455
|
it "adds the documents to the relation" do
|
@@ -1482,7 +1480,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1482
1480
|
context "when setting via the associated ids" do
|
1483
1481
|
|
1484
1482
|
let!(:persisted) do
|
1485
|
-
Preference.create(name: "testy")
|
1483
|
+
Preference.create!(name: "testy")
|
1486
1484
|
end
|
1487
1485
|
|
1488
1486
|
let(:preference) do
|
@@ -1494,7 +1492,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1494
1492
|
end
|
1495
1493
|
|
1496
1494
|
before do
|
1497
|
-
person.save
|
1495
|
+
person.save!
|
1498
1496
|
end
|
1499
1497
|
|
1500
1498
|
it "adds the documents to the relation" do
|
@@ -1522,7 +1520,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1522
1520
|
context "when the parent is not a new record" do
|
1523
1521
|
|
1524
1522
|
let(:person) do
|
1525
|
-
Person.create
|
1523
|
+
Person.create!
|
1526
1524
|
end
|
1527
1525
|
|
1528
1526
|
let(:preference) do
|
@@ -1604,11 +1602,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1604
1602
|
context "when both sides have been persisted" do
|
1605
1603
|
|
1606
1604
|
let(:person) do
|
1607
|
-
Person.create
|
1605
|
+
Person.create!
|
1608
1606
|
end
|
1609
1607
|
|
1610
1608
|
let(:event) do
|
1611
|
-
Event.create
|
1609
|
+
Event.create!
|
1612
1610
|
end
|
1613
1611
|
|
1614
1612
|
before do
|
@@ -1657,15 +1655,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1657
1655
|
context "when the relation also includes a has_many relation" do
|
1658
1656
|
|
1659
1657
|
let(:artwork) do
|
1660
|
-
Artwork.create
|
1658
|
+
Artwork.create!
|
1661
1659
|
end
|
1662
1660
|
|
1663
1661
|
let(:exhibition) do
|
1664
|
-
Exhibition.create
|
1662
|
+
Exhibition.create!
|
1665
1663
|
end
|
1666
1664
|
|
1667
1665
|
let(:exhibitor) do
|
1668
|
-
Exhibitor.create(exhibition: exhibition)
|
1666
|
+
Exhibitor.create!(exhibition: exhibition)
|
1669
1667
|
end
|
1670
1668
|
|
1671
1669
|
before do
|
@@ -1680,11 +1678,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1680
1678
|
context "when the relation is self referencing" do
|
1681
1679
|
|
1682
1680
|
let(:tag_one) do
|
1683
|
-
Tag.create(text: "one")
|
1681
|
+
Tag.create!(text: "one")
|
1684
1682
|
end
|
1685
1683
|
|
1686
1684
|
let(:tag_two) do
|
1687
|
-
Tag.create(text: "two")
|
1685
|
+
Tag.create!(text: "two")
|
1688
1686
|
end
|
1689
1687
|
|
1690
1688
|
before do
|
@@ -1735,7 +1733,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1735
1733
|
describe "#count" do
|
1736
1734
|
|
1737
1735
|
let(:person) do
|
1738
|
-
Person.create
|
1736
|
+
Person.create!
|
1739
1737
|
end
|
1740
1738
|
|
1741
1739
|
context "when nothing exists on the relation" do
|
@@ -1757,10 +1755,47 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1757
1755
|
end
|
1758
1756
|
end
|
1759
1757
|
|
1758
|
+
describe "#any?" do
|
1759
|
+
|
1760
|
+
let(:person) do
|
1761
|
+
Person.create!
|
1762
|
+
end
|
1763
|
+
|
1764
|
+
context "when nothing exists on the relation" do
|
1765
|
+
|
1766
|
+
context "when no document is added" do
|
1767
|
+
|
1768
|
+
let!(:sandwich) do
|
1769
|
+
Sandwich.create!
|
1770
|
+
end
|
1771
|
+
|
1772
|
+
it "returns false" do
|
1773
|
+
expect(sandwich.meats.any?).to be false
|
1774
|
+
end
|
1775
|
+
end
|
1776
|
+
|
1777
|
+
context "when the document is destroyed" do
|
1778
|
+
|
1779
|
+
before do
|
1780
|
+
Meat.create!
|
1781
|
+
end
|
1782
|
+
|
1783
|
+
let!(:sandwich) do
|
1784
|
+
Sandwich.create!
|
1785
|
+
end
|
1786
|
+
|
1787
|
+
it "returns false" do
|
1788
|
+
sandwich.destroy
|
1789
|
+
expect(sandwich.meats.any?).to be false
|
1790
|
+
end
|
1791
|
+
end
|
1792
|
+
end
|
1793
|
+
end
|
1794
|
+
|
1760
1795
|
context "when documents have been persisted" do
|
1761
1796
|
|
1762
1797
|
let!(:preference) do
|
1763
|
-
person.preferences.create(name: "setting")
|
1798
|
+
person.preferences.create!(name: "setting")
|
1764
1799
|
end
|
1765
1800
|
|
1766
1801
|
it "returns the number of persisted documents" do
|
@@ -1771,12 +1806,12 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1771
1806
|
context "when appending to a loaded relation" do
|
1772
1807
|
|
1773
1808
|
let!(:preference) do
|
1774
|
-
person.preferences.create(name: "setting")
|
1809
|
+
person.preferences.create!(name: "setting")
|
1775
1810
|
end
|
1776
1811
|
|
1777
1812
|
before do
|
1778
1813
|
person.preferences.count
|
1779
|
-
person.preferences << Preference.create(name: "two")
|
1814
|
+
person.preferences << Preference.create!(name: "two")
|
1780
1815
|
end
|
1781
1816
|
|
1782
1817
|
it "returns the number of persisted documents" do
|
@@ -1800,7 +1835,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1800
1835
|
context "when the documents are part of the relation" do
|
1801
1836
|
|
1802
1837
|
before do
|
1803
|
-
Preference.create(person_ids: [ person.id ])
|
1838
|
+
Preference.create!(person_ids: [ person.id ])
|
1804
1839
|
end
|
1805
1840
|
|
1806
1841
|
it "returns the count from the db" do
|
@@ -1811,7 +1846,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1811
1846
|
context "when the documents are not part of the relation" do
|
1812
1847
|
|
1813
1848
|
before do
|
1814
|
-
Preference.create
|
1849
|
+
Preference.create!
|
1815
1850
|
end
|
1816
1851
|
|
1817
1852
|
it "returns the count from the db" do
|
@@ -1825,7 +1860,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1825
1860
|
context "when documents have been persisted" do
|
1826
1861
|
|
1827
1862
|
let!(:house) do
|
1828
|
-
person.houses.create(name: "Wayne Manor")
|
1863
|
+
person.houses.create!(name: "Wayne Manor")
|
1829
1864
|
end
|
1830
1865
|
|
1831
1866
|
it "returns the number of persisted documents" do
|
@@ -1846,6 +1881,107 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1846
1881
|
end
|
1847
1882
|
end
|
1848
1883
|
|
1884
|
+
describe "#any?" do
|
1885
|
+
|
1886
|
+
let(:sandwich) do
|
1887
|
+
Sandwich.create!
|
1888
|
+
end
|
1889
|
+
|
1890
|
+
context "when nothing exists on the relation" do
|
1891
|
+
|
1892
|
+
context "when no document is added" do
|
1893
|
+
|
1894
|
+
let!(:sandwich) do
|
1895
|
+
Sandwich.create!
|
1896
|
+
end
|
1897
|
+
|
1898
|
+
it "returns false" do
|
1899
|
+
expect(sandwich.meats.any?).to be false
|
1900
|
+
end
|
1901
|
+
end
|
1902
|
+
|
1903
|
+
context "when the document is destroyed" do
|
1904
|
+
|
1905
|
+
before do
|
1906
|
+
Meat.create!
|
1907
|
+
end
|
1908
|
+
|
1909
|
+
let!(:sandwich) do
|
1910
|
+
Sandwich.create!
|
1911
|
+
end
|
1912
|
+
|
1913
|
+
it "returns false" do
|
1914
|
+
sandwich.destroy
|
1915
|
+
expect(sandwich.meats.any?).to be false
|
1916
|
+
end
|
1917
|
+
end
|
1918
|
+
end
|
1919
|
+
|
1920
|
+
context "when appending to a relation and _loaded/_unloaded are empty" do
|
1921
|
+
|
1922
|
+
let!(:sandwich) do
|
1923
|
+
Sandwich.create!
|
1924
|
+
end
|
1925
|
+
|
1926
|
+
before do
|
1927
|
+
sandwich.meats << Meat.new
|
1928
|
+
end
|
1929
|
+
|
1930
|
+
it "returns true" do
|
1931
|
+
expect(sandwich.meats.any?).to be true
|
1932
|
+
end
|
1933
|
+
end
|
1934
|
+
|
1935
|
+
context "when appending to a relation in a transaction" do
|
1936
|
+
require_transaction_support
|
1937
|
+
|
1938
|
+
let!(:sandwich) do
|
1939
|
+
Sandwich.create!
|
1940
|
+
end
|
1941
|
+
|
1942
|
+
it "returns true" do
|
1943
|
+
sandwich.with_session do |session|
|
1944
|
+
session.with_transaction do
|
1945
|
+
expect{ sandwich.meats << Meat.new }.to_not raise_error
|
1946
|
+
expect(sandwich.meats.any?).to be true
|
1947
|
+
end
|
1948
|
+
end
|
1949
|
+
end
|
1950
|
+
end
|
1951
|
+
|
1952
|
+
context "when documents have been persisted" do
|
1953
|
+
|
1954
|
+
let!(:meat) do
|
1955
|
+
sandwich.meats.create!
|
1956
|
+
end
|
1957
|
+
|
1958
|
+
it "returns true" do
|
1959
|
+
expect(sandwich.meats.any?).to be true
|
1960
|
+
end
|
1961
|
+
end
|
1962
|
+
|
1963
|
+
context "when documents have not been persisted" do
|
1964
|
+
|
1965
|
+
let!(:meat) do
|
1966
|
+
sandwich.meats.build
|
1967
|
+
end
|
1968
|
+
|
1969
|
+
it "returns false" do
|
1970
|
+
expect(sandwich.meats.any?).to be true
|
1971
|
+
end
|
1972
|
+
end
|
1973
|
+
|
1974
|
+
context "when new documents exist in the database" do
|
1975
|
+
before do
|
1976
|
+
Meat.create!(sandwiches: [sandwich])
|
1977
|
+
end
|
1978
|
+
|
1979
|
+
it "returns true" do
|
1980
|
+
expect(sandwich.meats.any?).to be true
|
1981
|
+
end
|
1982
|
+
end
|
1983
|
+
end
|
1984
|
+
|
1849
1985
|
[ :create, :create! ].each do |method|
|
1850
1986
|
|
1851
1987
|
describe "##{method}" do
|
@@ -1855,15 +1991,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1855
1991
|
context "when using string keys" do
|
1856
1992
|
|
1857
1993
|
let(:agent) do
|
1858
|
-
Agent.create(number: "007")
|
1994
|
+
Agent.create!(number: "007")
|
1859
1995
|
end
|
1860
1996
|
|
1861
1997
|
before do
|
1862
|
-
agent.accounts.
|
1998
|
+
agent.accounts.send(method, name: "test again")
|
1863
1999
|
end
|
1864
2000
|
|
1865
2001
|
it "does not convert the string key to an object id" do
|
1866
|
-
expect(agent.account_ids).to eq([ "
|
2002
|
+
expect(agent.account_ids).to eq([ "test-again" ])
|
1867
2003
|
end
|
1868
2004
|
end
|
1869
2005
|
|
@@ -1935,7 +2071,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1935
2071
|
context "when validation fails" do
|
1936
2072
|
|
1937
2073
|
let(:person) do
|
1938
|
-
Person.create
|
2074
|
+
Person.create!
|
1939
2075
|
end
|
1940
2076
|
|
1941
2077
|
context "when the relation is not polymorphic" do
|
@@ -1949,290 +2085,236 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
1949
2085
|
end
|
1950
2086
|
end
|
1951
2087
|
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
let(:preference_one) do
|
1959
|
-
Preference.create(name: "Testing")
|
1960
|
-
end
|
1961
|
-
|
1962
|
-
let(:preference_two) do
|
1963
|
-
Preference.create(name: "Test")
|
1964
|
-
end
|
1965
|
-
|
1966
|
-
before do
|
1967
|
-
person.preferences << [ preference_one, preference_two ]
|
1968
|
-
end
|
1969
|
-
|
1970
|
-
context "when the document exists" do
|
1971
|
-
|
1972
|
-
let!(:deleted) do
|
1973
|
-
person.preferences.delete(preference_one)
|
1974
|
-
end
|
1975
|
-
|
1976
|
-
it "removes the document from the relation" do
|
1977
|
-
expect(person.preferences).to eq([ preference_two ])
|
1978
|
-
end
|
1979
|
-
|
1980
|
-
it "returns the document" do
|
1981
|
-
expect(deleted).to eq(preference_one)
|
1982
|
-
end
|
2088
|
+
%i[ delete delete_one ].each do |method|
|
2089
|
+
describe "\##{method}" do
|
2090
|
+
let(:person) { Person.create! }
|
2091
|
+
let(:preference_one) { Preference.create!(name: "Testing") }
|
2092
|
+
let(:preference_two) { Preference.create!(name: "Test") }
|
1983
2093
|
|
1984
|
-
|
1985
|
-
|
1986
|
-
end
|
1987
|
-
|
1988
|
-
it "removes the inverse reference" do
|
1989
|
-
expect(deleted.reload.people).to be_empty
|
1990
|
-
end
|
1991
|
-
|
1992
|
-
it "removes the base id from the inverse keys" do
|
1993
|
-
expect(deleted.reload.person_ids).to be_empty
|
2094
|
+
before do
|
2095
|
+
person.preferences << [ preference_one, preference_two ]
|
1994
2096
|
end
|
1995
2097
|
|
1996
|
-
context
|
1997
|
-
|
1998
|
-
|
1999
|
-
person.reload
|
2000
|
-
preference_one.reload
|
2001
|
-
preference_two.reload
|
2098
|
+
context 'when the document exists' do
|
2099
|
+
let!(:deleted) do
|
2100
|
+
person.preferences.send(method, preference_one)
|
2002
2101
|
end
|
2003
2102
|
|
2004
|
-
it
|
2103
|
+
it 'removes the document from the relation' do
|
2005
2104
|
expect(person.preferences).to eq([ preference_two ])
|
2006
2105
|
end
|
2007
2106
|
|
2008
|
-
it
|
2009
|
-
expect(
|
2107
|
+
it 'returns the document' do
|
2108
|
+
expect(deleted).to eq(preference_one)
|
2010
2109
|
end
|
2011
|
-
end
|
2012
|
-
end
|
2013
|
-
|
2014
|
-
context "when the document does not exist" do
|
2015
|
-
|
2016
|
-
let!(:deleted) do
|
2017
|
-
person.preferences.delete(Preference.new)
|
2018
|
-
end
|
2019
|
-
|
2020
|
-
it "returns nil" do
|
2021
|
-
expect(deleted).to be_nil
|
2022
|
-
end
|
2023
|
-
|
2024
|
-
it "does not modify the relation" do
|
2025
|
-
expect(person.preferences).to eq([ preference_one, preference_two ])
|
2026
|
-
end
|
2027
|
-
|
2028
|
-
it "does not modify the keys" do
|
2029
|
-
expect(person.preference_ids).to eq([ preference_one.id, preference_two.id ])
|
2030
|
-
end
|
2031
|
-
end
|
2032
|
-
|
2033
|
-
context "when :dependent => :nullify is set" do
|
2034
|
-
|
2035
|
-
context "when :inverse_of is set" do
|
2036
2110
|
|
2037
|
-
|
2038
|
-
|
2111
|
+
it 'removes the document key from the foreign key' do
|
2112
|
+
expect(person.preference_ids).to eq([ preference_two.id ])
|
2039
2113
|
end
|
2040
2114
|
|
2041
|
-
|
2042
|
-
|
2115
|
+
it 'removes the inverse reference' do
|
2116
|
+
expect(deleted.reload.people).to be_empty
|
2043
2117
|
end
|
2044
2118
|
|
2045
|
-
it
|
2046
|
-
expect(
|
2119
|
+
it 'removes the base id from the inverse keys' do
|
2120
|
+
expect(deleted.reload.person_ids).to be_empty
|
2047
2121
|
end
|
2048
|
-
end
|
2049
|
-
end
|
2050
2122
|
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2123
|
+
context 'and person and preferences are reloaded' do
|
2124
|
+
before do
|
2125
|
+
person.reload
|
2126
|
+
preference_one.reload
|
2127
|
+
preference_two.reload
|
2128
|
+
end
|
2056
2129
|
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2130
|
+
it 'nullifies the deleted preference' do
|
2131
|
+
expect(person.preferences).to eq([ preference_two ])
|
2132
|
+
end
|
2060
2133
|
|
2061
|
-
|
2062
|
-
|
2134
|
+
it 'retains the ids for one preference' do
|
2135
|
+
expect(person.preference_ids).to eq([ preference_two.id ])
|
2136
|
+
end
|
2137
|
+
end
|
2063
2138
|
end
|
2064
2139
|
|
2065
|
-
context
|
2066
|
-
|
2140
|
+
context 'when the document does not exist' do
|
2067
2141
|
let!(:deleted) do
|
2068
|
-
|
2069
|
-
end
|
2070
|
-
|
2071
|
-
it "deletes the document from the relation" do
|
2072
|
-
expect(tag_one.related).to be_empty
|
2142
|
+
person.preferences.send(method, Preference.new)
|
2073
2143
|
end
|
2074
2144
|
|
2075
|
-
it
|
2076
|
-
expect(
|
2145
|
+
it 'returns nil' do
|
2146
|
+
expect(deleted).to be_nil
|
2077
2147
|
end
|
2078
2148
|
|
2079
|
-
it
|
2080
|
-
expect(
|
2149
|
+
it 'does not modify the relation' do
|
2150
|
+
expect(person.preferences).to eq([ preference_one, preference_two ])
|
2081
2151
|
end
|
2082
2152
|
|
2083
|
-
it
|
2084
|
-
expect(
|
2153
|
+
it 'does not modify the keys' do
|
2154
|
+
expect(person.preference_ids).to eq([ preference_one.id, preference_two.id ])
|
2085
2155
|
end
|
2086
2156
|
end
|
2087
2157
|
|
2088
|
-
context
|
2089
|
-
|
2090
|
-
|
2158
|
+
context 'when :dependent => :nullify is set' do
|
2159
|
+
context 'when :inverse_of is set' do
|
2160
|
+
let(:event) { Event.create! }
|
2091
2161
|
|
2092
|
-
|
2093
|
-
|
2094
|
-
end
|
2095
|
-
|
2096
|
-
let!(:deleted) do
|
2097
|
-
reloaded.related.delete(tag_two)
|
2098
|
-
end
|
2099
|
-
|
2100
|
-
it "deletes the document from the relation" do
|
2101
|
-
expect(reloaded.related).to be_empty
|
2162
|
+
before do
|
2163
|
+
person.administrated_events << [ event ]
|
2102
2164
|
end
|
2103
2165
|
|
2104
|
-
it
|
2105
|
-
expect(
|
2166
|
+
it 'deletes the document' do
|
2167
|
+
expect(event.delete).to be true
|
2106
2168
|
end
|
2169
|
+
end
|
2170
|
+
end
|
2107
2171
|
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2172
|
+
context 'when the relationships are self referencing' do
|
2173
|
+
let(:tag_one) { Tag.create!(text: "one") }
|
2174
|
+
let(:tag_two) { Tag.create!(text: "two") }
|
2111
2175
|
|
2112
|
-
|
2113
|
-
|
2114
|
-
end
|
2176
|
+
before do
|
2177
|
+
tag_one.related << tag_two
|
2115
2178
|
end
|
2116
2179
|
|
2117
|
-
context
|
2118
|
-
|
2119
|
-
let(:reloaded) do
|
2120
|
-
tag_two.reload
|
2121
|
-
end
|
2180
|
+
context 'when deleting without reloading' do
|
2181
|
+
let!(:deleted) { tag_one.related.send(method, tag_two) }
|
2122
2182
|
|
2123
|
-
|
2124
|
-
|
2183
|
+
it 'deletes the document from the relation' do
|
2184
|
+
expect(tag_one.related).to be_empty
|
2125
2185
|
end
|
2126
2186
|
|
2127
|
-
it
|
2128
|
-
expect(
|
2187
|
+
it 'deletes the foreign key from the relation' do
|
2188
|
+
expect(tag_one.related_ids).to be_empty
|
2129
2189
|
end
|
2130
2190
|
|
2131
|
-
it
|
2132
|
-
expect(
|
2191
|
+
it 'removes the reference from the inverse' do
|
2192
|
+
expect(deleted.related).to be_empty
|
2133
2193
|
end
|
2134
2194
|
|
2135
|
-
it
|
2195
|
+
it 'removes the foreign keys from the inverse' do
|
2136
2196
|
expect(deleted.related_ids).to be_empty
|
2137
2197
|
end
|
2138
2198
|
end
|
2139
|
-
end
|
2140
|
-
end
|
2141
2199
|
|
2142
|
-
|
2200
|
+
context 'when deleting with reloading' do
|
2201
|
+
context "when deleting from the front side" do
|
2202
|
+
let(:reloaded) { tag_one.reload }
|
2203
|
+
let!(:deleted) { reloaded.related.send(method, tag_two) }
|
2143
2204
|
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2205
|
+
it 'deletes the document from the relation' do
|
2206
|
+
expect(reloaded.related).to be_empty
|
2207
|
+
end
|
2147
2208
|
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2209
|
+
it 'deletes the foreign key from the relation' do
|
2210
|
+
expect(reloaded.related_ids).to be_empty
|
2211
|
+
end
|
2151
2212
|
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2213
|
+
it 'removes the reference from the inverse' do
|
2214
|
+
expect(deleted.related).to be_empty
|
2215
|
+
end
|
2155
2216
|
|
2156
|
-
|
2217
|
+
it 'removes the foreign keys from the inverse' do
|
2218
|
+
expect(deleted.related_ids).to be_empty
|
2219
|
+
end
|
2220
|
+
end
|
2157
2221
|
|
2158
|
-
|
2222
|
+
context 'when deleting from the inverse side' do
|
2223
|
+
let(:reloaded) { tag_two.reload }
|
2224
|
+
let!(:deleted) { reloaded.related.send(method, tag_one) }
|
2159
2225
|
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2226
|
+
it 'deletes the document from the relation' do
|
2227
|
+
expect(reloaded.related).to be_empty
|
2228
|
+
end
|
2163
2229
|
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2230
|
+
it 'deletes the foreign key from the relation' do
|
2231
|
+
expect(reloaded.related_ids).to be_empty
|
2232
|
+
end
|
2167
2233
|
|
2168
|
-
|
2169
|
-
|
2234
|
+
it 'removes the foreign keys from the inverse' do
|
2235
|
+
expect(deleted.related_ids).to be_empty
|
2236
|
+
end
|
2170
2237
|
end
|
2171
2238
|
end
|
2239
|
+
end
|
2172
2240
|
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
expect(post).to receive(:before_remove_tag).and_raise
|
2177
|
-
begin; post.tags.delete(tag); rescue; end
|
2178
|
-
end
|
2241
|
+
context 'when the association has callbacks' do
|
2242
|
+
let(:post) { Post.new }
|
2243
|
+
let(:tag) { Tag.new }
|
2179
2244
|
|
2180
|
-
|
2181
|
-
|
2182
|
-
end
|
2245
|
+
before do
|
2246
|
+
post.tags << tag
|
2183
2247
|
end
|
2184
|
-
end
|
2185
2248
|
|
2186
|
-
|
2249
|
+
context 'when the callback is a before_remove' do
|
2250
|
+
context 'when there are no errors' do
|
2251
|
+
before do
|
2252
|
+
post.tags.send(method, tag)
|
2253
|
+
end
|
2187
2254
|
|
2188
|
-
|
2255
|
+
it 'executes the callback' do
|
2256
|
+
expect(post.before_remove_called).to be true
|
2257
|
+
end
|
2189
2258
|
|
2190
|
-
|
2191
|
-
|
2259
|
+
it 'removes the document from the relation' do
|
2260
|
+
expect(post.tags).to be_empty
|
2261
|
+
end
|
2192
2262
|
end
|
2193
2263
|
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2264
|
+
context "when errors are raised" do
|
2265
|
+
before do
|
2266
|
+
expect(post).to receive(:before_remove_tag).and_raise
|
2267
|
+
begin; post.tags.send(method, tag); rescue; end
|
2268
|
+
end
|
2197
2269
|
|
2198
|
-
|
2199
|
-
|
2270
|
+
it 'does not remove the document from the relation' do
|
2271
|
+
expect(post.tags).to eq([ tag ])
|
2272
|
+
end
|
2200
2273
|
end
|
2201
2274
|
end
|
2202
2275
|
|
2203
|
-
context
|
2276
|
+
context 'when the callback is an after_remove' do
|
2277
|
+
context 'when no errors are raised' do
|
2278
|
+
before do
|
2279
|
+
post.tags.send(method, tag)
|
2280
|
+
end
|
2204
2281
|
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2282
|
+
it 'executes the callback' do
|
2283
|
+
expect(post.after_remove_called).to be true
|
2284
|
+
end
|
2285
|
+
|
2286
|
+
it 'removes the document from the relation' do
|
2287
|
+
expect(post.tags).to be_empty
|
2288
|
+
end
|
2208
2289
|
end
|
2209
2290
|
|
2210
|
-
|
2211
|
-
|
2291
|
+
context 'when errors are raised' do
|
2292
|
+
before do
|
2293
|
+
expect(post).to receive(:after_remove_tag).and_raise
|
2294
|
+
begin; post.tags.send(method, tag); rescue; end
|
2295
|
+
end
|
2296
|
+
|
2297
|
+
it 'removes the document from the relation' do
|
2298
|
+
expect(post.tags).to be_empty
|
2299
|
+
end
|
2212
2300
|
end
|
2213
2301
|
end
|
2214
2302
|
end
|
2215
2303
|
end
|
2216
2304
|
end
|
2217
2305
|
|
2218
|
-
[
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
context "when conditions are provided" do
|
2225
|
-
|
2226
|
-
let(:person) do
|
2227
|
-
Person.create
|
2228
|
-
end
|
2306
|
+
%i[ delete_all destroy_all ].each do |method|
|
2307
|
+
describe "\##{method}" do
|
2308
|
+
context 'when the relation is not polymorphic' do
|
2309
|
+
context 'when conditions are provided' do
|
2310
|
+
let(:person) { Person.create! }
|
2229
2311
|
|
2230
2312
|
let!(:preference_one) do
|
2231
|
-
person.preferences.create(name: "Testing")
|
2313
|
+
person.preferences.create!(name: "Testing")
|
2232
2314
|
end
|
2233
2315
|
|
2234
2316
|
let!(:preference_two) do
|
2235
|
-
person.preferences.create(name: "Test")
|
2317
|
+
person.preferences.create!(name: "Test")
|
2236
2318
|
end
|
2237
2319
|
|
2238
2320
|
let!(:deleted) do
|
@@ -2257,14 +2339,18 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2257
2339
|
it "removes the ids from the foreign key" do
|
2258
2340
|
expect(person.preference_ids).to eq([ preference_two.id ])
|
2259
2341
|
end
|
2342
|
+
|
2343
|
+
it "sets the association locally" do
|
2344
|
+
expect(person.preferences).to eq([preference_two])
|
2345
|
+
end
|
2260
2346
|
end
|
2261
2347
|
|
2262
2348
|
context "when conditions are not provided" do
|
2263
2349
|
|
2264
2350
|
let(:person) do
|
2265
|
-
Person.create
|
2266
|
-
person.preferences.create(name: "Testing")
|
2267
|
-
person.preferences.create(name: "Test")
|
2351
|
+
Person.create!.tap do |person|
|
2352
|
+
person.preferences.create!(name: "Testing")
|
2353
|
+
person.preferences.create!(name: "Test")
|
2268
2354
|
end
|
2269
2355
|
end
|
2270
2356
|
|
@@ -2283,6 +2369,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2283
2369
|
it "returns the number of documents deleted" do
|
2284
2370
|
expect(deleted).to eq(2)
|
2285
2371
|
end
|
2372
|
+
|
2373
|
+
it "sets the association locally" do
|
2374
|
+
expect(person.preferences).to eq([])
|
2375
|
+
end
|
2286
2376
|
end
|
2287
2377
|
end
|
2288
2378
|
end
|
@@ -2298,13 +2388,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2298
2388
|
describe "#exists?" do
|
2299
2389
|
|
2300
2390
|
let!(:person) do
|
2301
|
-
Person.create
|
2391
|
+
Person.create!
|
2302
2392
|
end
|
2303
2393
|
|
2304
2394
|
context "when documents exist in the database" do
|
2305
2395
|
|
2306
2396
|
before do
|
2307
|
-
person.preferences.create
|
2397
|
+
person.preferences.create!
|
2308
2398
|
end
|
2309
2399
|
|
2310
2400
|
it "returns true" do
|
@@ -2329,23 +2419,23 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2329
2419
|
context "when the relation is not polymorphic" do
|
2330
2420
|
|
2331
2421
|
let(:person) do
|
2332
|
-
Person.create
|
2422
|
+
Person.create!
|
2333
2423
|
end
|
2334
2424
|
|
2335
2425
|
let!(:preference_one) do
|
2336
|
-
person.preferences.create(name: "Test")
|
2426
|
+
person.preferences.create!(name: "Test")
|
2337
2427
|
end
|
2338
2428
|
|
2339
2429
|
let!(:preference_two) do
|
2340
|
-
person.preferences.create(name: "OMG I has relations")
|
2430
|
+
person.preferences.create!(name: "OMG I has relations")
|
2341
2431
|
end
|
2342
2432
|
|
2343
2433
|
let!(:unrelated_pref) do
|
2344
|
-
Preference.create(name: "orphan annie")
|
2434
|
+
Preference.create!(name: "orphan annie")
|
2345
2435
|
end
|
2346
2436
|
|
2347
2437
|
let!(:unrelated_pref_two) do
|
2348
|
-
Preference.create(name: "orphan two")
|
2438
|
+
Preference.create!(name: "orphan two")
|
2349
2439
|
end
|
2350
2440
|
|
2351
2441
|
context "when providing an id" do
|
@@ -2370,39 +2460,29 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2370
2460
|
it "raises an error" do
|
2371
2461
|
expect {
|
2372
2462
|
preference
|
2373
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2463
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2374
2464
|
end
|
2375
2465
|
end
|
2376
2466
|
|
2377
2467
|
context "when the id does not match" do
|
2378
2468
|
|
2379
2469
|
context "when config set to raise error" do
|
2380
|
-
|
2381
|
-
before do
|
2382
|
-
Mongoid.raise_not_found_error = true
|
2383
|
-
end
|
2470
|
+
config_override :raise_not_found_error, true
|
2384
2471
|
|
2385
2472
|
it "raises an error" do
|
2386
2473
|
expect {
|
2387
2474
|
person.preferences.find(BSON::ObjectId.new)
|
2388
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2475
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2389
2476
|
end
|
2390
2477
|
end
|
2391
2478
|
|
2392
2479
|
context "when config set not to raise error" do
|
2480
|
+
config_override :raise_not_found_error, false
|
2393
2481
|
|
2394
2482
|
let(:preference) do
|
2395
2483
|
person.preferences.find(BSON::ObjectId.new)
|
2396
2484
|
end
|
2397
2485
|
|
2398
|
-
before do
|
2399
|
-
Mongoid.raise_not_found_error = false
|
2400
|
-
end
|
2401
|
-
|
2402
|
-
after do
|
2403
|
-
Mongoid.raise_not_found_error = true
|
2404
|
-
end
|
2405
|
-
|
2406
2486
|
it "returns nil" do
|
2407
2487
|
expect(preference).to be_nil
|
2408
2488
|
end
|
@@ -2423,7 +2503,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2423
2503
|
end
|
2424
2504
|
end
|
2425
2505
|
|
2426
|
-
context "when the ids
|
2506
|
+
context "when the ids match unreferenced documents" do
|
2427
2507
|
|
2428
2508
|
let(:preferences) do
|
2429
2509
|
person.preferences.find(
|
@@ -2434,39 +2514,29 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2434
2514
|
it "raises an error" do
|
2435
2515
|
expect {
|
2436
2516
|
preferences
|
2437
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2517
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2438
2518
|
end
|
2439
2519
|
end
|
2440
2520
|
|
2441
2521
|
context "when the ids do not match" do
|
2442
2522
|
|
2443
2523
|
context "when config set to raise error" do
|
2444
|
-
|
2445
|
-
before do
|
2446
|
-
Mongoid.raise_not_found_error = true
|
2447
|
-
end
|
2524
|
+
config_override :raise_not_found_error, true
|
2448
2525
|
|
2449
2526
|
it "raises an error" do
|
2450
2527
|
expect {
|
2451
2528
|
person.preferences.find([ BSON::ObjectId.new ])
|
2452
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2529
|
+
}.to raise_error(Mongoid::Errors::DocumentNotFound, /Document\(s\) not found for class Preference with id\(s\)/)
|
2453
2530
|
end
|
2454
2531
|
end
|
2455
2532
|
|
2456
2533
|
context "when config set not to raise error" do
|
2534
|
+
config_override :raise_not_found_error, false
|
2457
2535
|
|
2458
2536
|
let(:preferences) do
|
2459
2537
|
person.preferences.find([ BSON::ObjectId.new ])
|
2460
2538
|
end
|
2461
2539
|
|
2462
|
-
before do
|
2463
|
-
Mongoid.raise_not_found_error = false
|
2464
|
-
end
|
2465
|
-
|
2466
|
-
after do
|
2467
|
-
Mongoid.raise_not_found_error = true
|
2468
|
-
end
|
2469
|
-
|
2470
2540
|
it "returns an empty array" do
|
2471
2541
|
expect(preferences).to be_empty
|
2472
2542
|
end
|
@@ -2481,11 +2551,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2481
2551
|
context "when the relation is not polymorphic" do
|
2482
2552
|
|
2483
2553
|
let(:person) do
|
2484
|
-
Person.create
|
2554
|
+
Person.create!
|
2485
2555
|
end
|
2486
2556
|
|
2487
2557
|
let!(:preference) do
|
2488
|
-
person.preferences.create(name: "Testing")
|
2558
|
+
person.preferences.create!(name: "Testing")
|
2489
2559
|
end
|
2490
2560
|
|
2491
2561
|
context "when the document exists" do
|
@@ -2521,11 +2591,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2521
2591
|
context "when the relation is not polymorphic" do
|
2522
2592
|
|
2523
2593
|
let(:person) do
|
2524
|
-
Person.create
|
2594
|
+
Person.create!
|
2525
2595
|
end
|
2526
2596
|
|
2527
2597
|
let!(:preference) do
|
2528
|
-
person.preferences.create(name: "Testing")
|
2598
|
+
person.preferences.create!(name: "Testing")
|
2529
2599
|
end
|
2530
2600
|
|
2531
2601
|
context "when the document exists" do
|
@@ -2570,11 +2640,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2570
2640
|
context "when the relation is not polymorphic" do
|
2571
2641
|
|
2572
2642
|
let(:person) do
|
2573
|
-
Person.create
|
2643
|
+
Person.create!
|
2574
2644
|
end
|
2575
2645
|
|
2576
2646
|
let!(:preference) do
|
2577
|
-
person.preferences.create(name: "Testing")
|
2647
|
+
person.preferences.create!(name: "Testing")
|
2578
2648
|
end
|
2579
2649
|
|
2580
2650
|
context "when the document exists" do
|
@@ -2608,15 +2678,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2608
2678
|
describe "#max" do
|
2609
2679
|
|
2610
2680
|
let(:person) do
|
2611
|
-
Person.create
|
2681
|
+
Person.create!
|
2612
2682
|
end
|
2613
2683
|
|
2614
2684
|
let(:preference_one) do
|
2615
|
-
Preference.create(ranking: 5)
|
2685
|
+
Preference.create!(ranking: 5)
|
2616
2686
|
end
|
2617
2687
|
|
2618
2688
|
let(:preference_two) do
|
2619
|
-
Preference.create(ranking: 10)
|
2689
|
+
Preference.create!(ranking: 10)
|
2620
2690
|
end
|
2621
2691
|
|
2622
2692
|
before do
|
@@ -2637,15 +2707,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2637
2707
|
describe "#max_by" do
|
2638
2708
|
|
2639
2709
|
let(:person) do
|
2640
|
-
Person.create
|
2710
|
+
Person.create!
|
2641
2711
|
end
|
2642
2712
|
|
2643
2713
|
let(:preference_one) do
|
2644
|
-
Preference.create(ranking: 5)
|
2714
|
+
Preference.create!(ranking: 5)
|
2645
2715
|
end
|
2646
2716
|
|
2647
2717
|
let(:preference_two) do
|
2648
|
-
Preference.create(ranking: 10)
|
2718
|
+
Preference.create!(ranking: 10)
|
2649
2719
|
end
|
2650
2720
|
|
2651
2721
|
before do
|
@@ -2664,19 +2734,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2664
2734
|
describe "#method_missing" do
|
2665
2735
|
|
2666
2736
|
let!(:person) do
|
2667
|
-
Person.create
|
2737
|
+
Person.create!
|
2668
2738
|
end
|
2669
2739
|
|
2670
2740
|
let!(:preference_one) do
|
2671
|
-
person.preferences.create(name: "First", value: "Posting")
|
2741
|
+
person.preferences.create!(name: "First", value: "Posting")
|
2672
2742
|
end
|
2673
2743
|
|
2674
2744
|
let!(:preference_two) do
|
2675
|
-
person.preferences.create(name: "Second", value: "Testing")
|
2745
|
+
person.preferences.create!(name: "Second", value: "Testing")
|
2676
2746
|
end
|
2677
2747
|
|
2678
2748
|
let!(:unrelated) do
|
2679
|
-
Preference.create(name: "Third")
|
2749
|
+
Preference.create!(name: "Third")
|
2680
2750
|
end
|
2681
2751
|
|
2682
2752
|
context "when providing a single criteria" do
|
@@ -2689,7 +2759,8 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2689
2759
|
expect(preferences).to eq([ preference_one ])
|
2690
2760
|
end
|
2691
2761
|
|
2692
|
-
context 'when providing a collation'
|
2762
|
+
context 'when providing a collation' do
|
2763
|
+
min_server_version '3.4'
|
2693
2764
|
|
2694
2765
|
let(:preferences) do
|
2695
2766
|
person.preferences.where(name: "FIRST").collation(locale: 'en_US', strength: 2).to_a
|
@@ -2750,7 +2821,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2750
2821
|
context "when the inverse relation is not defined" do
|
2751
2822
|
|
2752
2823
|
let!(:house) do
|
2753
|
-
person.houses.create(name: "Wayne Manor")
|
2824
|
+
person.houses.create!(name: "Wayne Manor")
|
2754
2825
|
end
|
2755
2826
|
|
2756
2827
|
it "returns the distinct values for the fields" do
|
@@ -2764,15 +2835,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2764
2835
|
describe "#min" do
|
2765
2836
|
|
2766
2837
|
let(:person) do
|
2767
|
-
Person.create
|
2838
|
+
Person.create!
|
2768
2839
|
end
|
2769
2840
|
|
2770
2841
|
let(:preference_one) do
|
2771
|
-
Preference.create(ranking: 5)
|
2842
|
+
Preference.create!(ranking: 5)
|
2772
2843
|
end
|
2773
2844
|
|
2774
2845
|
let(:preference_two) do
|
2775
|
-
Preference.create(ranking: 10)
|
2846
|
+
Preference.create!(ranking: 10)
|
2776
2847
|
end
|
2777
2848
|
|
2778
2849
|
before do
|
@@ -2793,15 +2864,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2793
2864
|
describe "#min_by" do
|
2794
2865
|
|
2795
2866
|
let(:person) do
|
2796
|
-
Person.create
|
2867
|
+
Person.create!
|
2797
2868
|
end
|
2798
2869
|
|
2799
2870
|
let(:preference_one) do
|
2800
|
-
Preference.create(ranking: 5)
|
2871
|
+
Preference.create!(ranking: 5)
|
2801
2872
|
end
|
2802
2873
|
|
2803
2874
|
let(:preference_two) do
|
2804
|
-
Preference.create(ranking: 10)
|
2875
|
+
Preference.create!(ranking: 10)
|
2805
2876
|
end
|
2806
2877
|
|
2807
2878
|
before do
|
@@ -2827,15 +2898,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2827
2898
|
describe "#nullify_all" do
|
2828
2899
|
|
2829
2900
|
let(:person) do
|
2830
|
-
Person.create
|
2901
|
+
Person.create!
|
2831
2902
|
end
|
2832
2903
|
|
2833
2904
|
let!(:preference_one) do
|
2834
|
-
person.preferences.create(name: "One")
|
2905
|
+
person.preferences.create!(name: "One")
|
2835
2906
|
end
|
2836
2907
|
|
2837
2908
|
let!(:preference_two) do
|
2838
|
-
person.preferences.create(name: "Two")
|
2909
|
+
person.preferences.create!(name: "Two")
|
2839
2910
|
end
|
2840
2911
|
|
2841
2912
|
before do
|
@@ -2956,13 +3027,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2956
3027
|
describe "##{method}" do
|
2957
3028
|
|
2958
3029
|
let(:person) do
|
2959
|
-
Person.create
|
3030
|
+
Person.create!
|
2960
3031
|
end
|
2961
3032
|
|
2962
3033
|
context "when documents have been persisted" do
|
2963
3034
|
|
2964
3035
|
let!(:preference) do
|
2965
|
-
person.preferences.create(name: "Testing")
|
3036
|
+
person.preferences.create!(name: "Testing")
|
2966
3037
|
end
|
2967
3038
|
|
2968
3039
|
it "returns the number of documents" do
|
@@ -2974,7 +3045,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2974
3045
|
|
2975
3046
|
before do
|
2976
3047
|
person.preferences.build(name: "Test")
|
2977
|
-
person.preferences.create(name: "Test 2")
|
3048
|
+
person.preferences.create!(name: "Test 2")
|
2978
3049
|
end
|
2979
3050
|
|
2980
3051
|
it "returns the total number of documents" do
|
@@ -2989,15 +3060,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
2989
3060
|
context "when the relation has no default scope" do
|
2990
3061
|
|
2991
3062
|
let!(:person) do
|
2992
|
-
Person.create
|
3063
|
+
Person.create!
|
2993
3064
|
end
|
2994
3065
|
|
2995
3066
|
let!(:preference_one) do
|
2996
|
-
person.preferences.create(name: "first")
|
3067
|
+
person.preferences.create!(name: "first")
|
2997
3068
|
end
|
2998
3069
|
|
2999
3070
|
let!(:preference_two) do
|
3000
|
-
Preference.create(name: "second")
|
3071
|
+
Preference.create!(name: "second")
|
3001
3072
|
end
|
3002
3073
|
|
3003
3074
|
let(:unscoped) do
|
@@ -3012,15 +3083,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3012
3083
|
context "when the relation has a default scope" do
|
3013
3084
|
|
3014
3085
|
let!(:person) do
|
3015
|
-
Person.create
|
3086
|
+
Person.create!
|
3016
3087
|
end
|
3017
3088
|
|
3018
3089
|
let!(:house_one) do
|
3019
|
-
person.houses.create(name: "first")
|
3090
|
+
person.houses.create!(name: "first")
|
3020
3091
|
end
|
3021
3092
|
|
3022
3093
|
let!(:house_two) do
|
3023
|
-
House.create(name: "second")
|
3094
|
+
House.create!(name: "second")
|
3024
3095
|
end
|
3025
3096
|
|
3026
3097
|
let(:unscoped) do
|
@@ -3056,10 +3127,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3056
3127
|
end
|
3057
3128
|
|
3058
3129
|
before do
|
3059
|
-
person.update_attributes(
|
3130
|
+
person.update_attributes!(
|
3060
3131
|
houses: [ wife_house, exwife_house, girlfriend_house ]
|
3061
3132
|
)
|
3062
|
-
person.update_attributes(house_ids: [ girlfriend_house.id ])
|
3133
|
+
person.update_attributes!(house_ids: [ girlfriend_house.id ])
|
3063
3134
|
end
|
3064
3135
|
|
3065
3136
|
context "when reloading" do
|
@@ -3106,7 +3177,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3106
3177
|
end
|
3107
3178
|
|
3108
3179
|
let!(:business) do
|
3109
|
-
Business.create(name: "serious", owners: [ user ])
|
3180
|
+
Business.create!(name: "serious", owners: [ user ])
|
3110
3181
|
end
|
3111
3182
|
|
3112
3183
|
before do
|
@@ -3149,11 +3220,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3149
3220
|
context "when the documents are persisted" do
|
3150
3221
|
|
3151
3222
|
let(:user) do
|
3152
|
-
User.create(name: "tst")
|
3223
|
+
User.create!(name: "tst")
|
3153
3224
|
end
|
3154
3225
|
|
3155
3226
|
let(:business) do
|
3156
|
-
Business.create(name: "srs", owners: [ user ])
|
3227
|
+
Business.create!(name: "srs", owners: [ user ])
|
3157
3228
|
end
|
3158
3229
|
|
3159
3230
|
before do
|
@@ -3197,11 +3268,11 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3197
3268
|
context "when binding the relation multiple times" do
|
3198
3269
|
|
3199
3270
|
let(:person) do
|
3200
|
-
Person.create
|
3271
|
+
Person.create!
|
3201
3272
|
end
|
3202
3273
|
|
3203
3274
|
let(:preference) do
|
3204
|
-
person.preferences.create(name: "testing")
|
3275
|
+
person.preferences.create!(name: "testing")
|
3205
3276
|
end
|
3206
3277
|
|
3207
3278
|
before do
|
@@ -3220,19 +3291,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3220
3291
|
context "when the association has order criteria" do
|
3221
3292
|
|
3222
3293
|
let(:person) do
|
3223
|
-
Person.create
|
3294
|
+
Person.create!
|
3224
3295
|
end
|
3225
3296
|
|
3226
3297
|
let(:preference_one) do
|
3227
|
-
OrderedPreference.create(name: 'preference-1', value: 10)
|
3298
|
+
OrderedPreference.create!(name: 'preference-1', value: 10)
|
3228
3299
|
end
|
3229
3300
|
|
3230
3301
|
let(:preference_two) do
|
3231
|
-
OrderedPreference.create(name: 'preference-2', value: 20)
|
3302
|
+
OrderedPreference.create!(name: 'preference-2', value: 20)
|
3232
3303
|
end
|
3233
3304
|
|
3234
3305
|
let(:preference_three) do
|
3235
|
-
OrderedPreference.create(name: 'preference-3', value: 20)
|
3306
|
+
OrderedPreference.create!(name: 'preference-3', value: 20)
|
3236
3307
|
end
|
3237
3308
|
|
3238
3309
|
before do
|
@@ -3256,7 +3327,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3256
3327
|
context "when the parent is not a new record and freshly loaded" do
|
3257
3328
|
|
3258
3329
|
let(:person) do
|
3259
|
-
Person.create
|
3330
|
+
Person.create!
|
3260
3331
|
end
|
3261
3332
|
|
3262
3333
|
let(:preference) do
|
@@ -3265,7 +3336,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3265
3336
|
|
3266
3337
|
before do
|
3267
3338
|
person.preferences = [ preference ]
|
3268
|
-
person.save
|
3339
|
+
person.save!
|
3269
3340
|
person.reload
|
3270
3341
|
person.preferences = nil
|
3271
3342
|
end
|
@@ -3288,15 +3359,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3288
3359
|
context "when reloading the relation" do
|
3289
3360
|
|
3290
3361
|
let!(:person) do
|
3291
|
-
Person.create
|
3362
|
+
Person.create!
|
3292
3363
|
end
|
3293
3364
|
|
3294
3365
|
let!(:preference_one) do
|
3295
|
-
Preference.create(name: "one")
|
3366
|
+
Preference.create!(name: "one")
|
3296
3367
|
end
|
3297
3368
|
|
3298
3369
|
let!(:preference_two) do
|
3299
|
-
Preference.create(name: "two")
|
3370
|
+
Preference.create!(name: "two")
|
3300
3371
|
end
|
3301
3372
|
|
3302
3373
|
before do
|
@@ -3340,7 +3411,7 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3340
3411
|
context "when the document is new" do
|
3341
3412
|
|
3342
3413
|
let!(:person) do
|
3343
|
-
Person.create(preference_names: "one, two")
|
3414
|
+
Person.create!(preference_names: "one, two")
|
3344
3415
|
end
|
3345
3416
|
|
3346
3417
|
let(:preference_one) do
|
@@ -3376,23 +3447,23 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3376
3447
|
end
|
3377
3448
|
|
3378
3449
|
let(:preference_one) do
|
3379
|
-
Preference.create(name: "one")
|
3450
|
+
Preference.create!(name: "one")
|
3380
3451
|
end
|
3381
3452
|
|
3382
3453
|
let(:preference_two) do
|
3383
|
-
Preference.create(name: "two")
|
3454
|
+
Preference.create!(name: "two")
|
3384
3455
|
end
|
3385
3456
|
|
3386
3457
|
before do
|
3387
3458
|
person.preference_ids = [ preference_one.id, preference_two.id ]
|
3388
|
-
person.save
|
3459
|
+
person.save!
|
3389
3460
|
end
|
3390
3461
|
|
3391
3462
|
context "and the order is changed" do
|
3392
3463
|
|
3393
3464
|
before do
|
3394
3465
|
person.preference_ids = [ preference_two.id, preference_one.id ]
|
3395
|
-
person.save
|
3466
|
+
person.save!
|
3396
3467
|
end
|
3397
3468
|
|
3398
3469
|
let(:reloaded) do
|
@@ -3409,13 +3480,13 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3409
3480
|
context "and the order is changed and an element is added" do
|
3410
3481
|
|
3411
3482
|
let(:preference_three) do
|
3412
|
-
Preference.create(name: "three")
|
3483
|
+
Preference.create!(name: "three")
|
3413
3484
|
end
|
3414
3485
|
|
3415
3486
|
before do
|
3416
3487
|
person.preference_ids =
|
3417
3488
|
[ preference_two.id, preference_one.id, preference_three.id ]
|
3418
|
-
person.save
|
3489
|
+
person.save!
|
3419
3490
|
end
|
3420
3491
|
|
3421
3492
|
let(:reloaded) do
|
@@ -3432,16 +3503,16 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3432
3503
|
context "and the order is changed and an element is removed" do
|
3433
3504
|
|
3434
3505
|
let(:preference_three) do
|
3435
|
-
Preference.create(name: "three")
|
3506
|
+
Preference.create!(name: "three")
|
3436
3507
|
end
|
3437
3508
|
|
3438
3509
|
before do
|
3439
3510
|
person.preference_ids =
|
3440
3511
|
[ preference_one.id, preference_two.id, preference_three.id ]
|
3441
|
-
person.save
|
3512
|
+
person.save!
|
3442
3513
|
person.preference_ids =
|
3443
3514
|
[ preference_three.id, preference_two.id ]
|
3444
|
-
person.save
|
3515
|
+
person.save!
|
3445
3516
|
end
|
3446
3517
|
|
3447
3518
|
let(:reloaded) do
|
@@ -3491,15 +3562,15 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3491
3562
|
context "when the relation exists" do
|
3492
3563
|
|
3493
3564
|
let!(:person) do
|
3494
|
-
Person.create
|
3565
|
+
Person.create!
|
3495
3566
|
end
|
3496
3567
|
|
3497
3568
|
let!(:pref_one) do
|
3498
|
-
person.preferences.create
|
3569
|
+
person.preferences.create!
|
3499
3570
|
end
|
3500
3571
|
|
3501
3572
|
let!(:pref_two) do
|
3502
|
-
Preference.create
|
3573
|
+
Preference.create!
|
3503
3574
|
end
|
3504
3575
|
|
3505
3576
|
before do
|
@@ -3515,15 +3586,19 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3515
3586
|
context "when using a different primary key" do
|
3516
3587
|
|
3517
3588
|
let(:dog) do
|
3518
|
-
Dog.create(name: 'Doggie')
|
3589
|
+
Dog.create!(name: 'Doggie')
|
3519
3590
|
end
|
3520
3591
|
|
3521
3592
|
let(:cat) do
|
3522
|
-
Cat.create(name: 'Kitty')
|
3593
|
+
Cat.create!(name: 'Kitty')
|
3594
|
+
end
|
3595
|
+
|
3596
|
+
let(:another_cat) do
|
3597
|
+
Cat.create!(name: 'Kitten')
|
3523
3598
|
end
|
3524
3599
|
|
3525
3600
|
let(:fire_hydrant) do
|
3526
|
-
FireHydrant.create(location: '221B Baker Street')
|
3601
|
+
FireHydrant.create!(location: '221B Baker Street')
|
3527
3602
|
end
|
3528
3603
|
|
3529
3604
|
context "when adding to a one-way many to many" do
|
@@ -3537,6 +3612,28 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3537
3612
|
end
|
3538
3613
|
end
|
3539
3614
|
|
3615
|
+
context "when adding multiple documents to a one-way many to many" do
|
3616
|
+
|
3617
|
+
before do
|
3618
|
+
fire_hydrant.cats.push([cat, another_cat])
|
3619
|
+
end
|
3620
|
+
|
3621
|
+
it "adds the pk values to the fk set" do
|
3622
|
+
expect(fire_hydrant.cat_ids).to eq([cat.name, another_cat.name])
|
3623
|
+
end
|
3624
|
+
end
|
3625
|
+
|
3626
|
+
context "when adding a new document to a one-way many to many" do
|
3627
|
+
|
3628
|
+
before do
|
3629
|
+
fire_hydrant.cats.build name: 'Kitten'
|
3630
|
+
end
|
3631
|
+
|
3632
|
+
it "adds the pk values to the fk set" do
|
3633
|
+
expect(fire_hydrant.cat_ids).to eq(['Kitten'])
|
3634
|
+
end
|
3635
|
+
end
|
3636
|
+
|
3540
3637
|
context "when adding to a two-way many to many" do
|
3541
3638
|
|
3542
3639
|
before do
|
@@ -3593,10 +3690,10 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3593
3690
|
end
|
3594
3691
|
|
3595
3692
|
it "should assign relation from both sides" do
|
3596
|
-
p1 = Project.create name: 'Foo'
|
3597
|
-
p2 = Project.create name: 'Bar'
|
3598
|
-
d1 = Distributor.create name: 'Rock'
|
3599
|
-
d2 = Distributor.create name: 'Soul'
|
3693
|
+
p1 = Project.create! name: 'Foo'
|
3694
|
+
p2 = Project.create! name: 'Bar'
|
3695
|
+
d1 = Distributor.create! name: 'Rock'
|
3696
|
+
d2 = Distributor.create! name: 'Soul'
|
3600
3697
|
|
3601
3698
|
p1.distributors << d1
|
3602
3699
|
expect(p1.d_ids).to match_array([d1.id])
|
@@ -3606,4 +3703,58 @@ describe Mongoid::Association::Referenced::HasAndBelongsToMany::Proxy do
|
|
3606
3703
|
expect(p2.d_ids).to match_array([d2.id])
|
3607
3704
|
end
|
3608
3705
|
end
|
3706
|
+
|
3707
|
+
context "when accesing own _id from parent's foreign key in default" do
|
3708
|
+
let!(:contract) { HabtmmContract.create! }
|
3709
|
+
let!(:signature) { contract.signatures.create! }
|
3710
|
+
|
3711
|
+
it "is nil" do
|
3712
|
+
expect(signature.favorite_signature).to be nil
|
3713
|
+
end
|
3714
|
+
end
|
3715
|
+
|
3716
|
+
context "when setting an association on a model that uses the class_name option" do
|
3717
|
+
let!(:contract) { HabtmmContract.create! }
|
3718
|
+
let!(:signature) { HabtmmSignature.create!(contracts: [contract]) }
|
3719
|
+
|
3720
|
+
it "populates the inverse foreign key" do
|
3721
|
+
expect(signature.contracts.first.signature_ids).to eq([signature.id])
|
3722
|
+
end
|
3723
|
+
end
|
3724
|
+
|
3725
|
+
context "when there is a foreign key in the aliased associations" do
|
3726
|
+
it "has the correct aliases" do
|
3727
|
+
expect(Dog.aliased_associations["breed_ids"]).to eq("breeds")
|
3728
|
+
expect(Breed.aliased_associations["dog_ids"]).to eq("dogs")
|
3729
|
+
end
|
3730
|
+
end
|
3731
|
+
|
3732
|
+
# This test is for MONGOID-5344 which tests that the initial call to
|
3733
|
+
# signature_ids refers to the same array as subsequent calls to signature_ids.
|
3734
|
+
# Prior to the change in that ticket, this test broke because the array
|
3735
|
+
# returned from write_attribute (which is triggered the first time the
|
3736
|
+
# foreign key array is referenced, to set the default), refers to a different
|
3737
|
+
# array to the one stored in the attributes hash. This happened because,
|
3738
|
+
# when retrieving a document from the database, the attributes hash is actually
|
3739
|
+
# a BSON::Document, which applies a transformation to the array before
|
3740
|
+
# storing it.
|
3741
|
+
context "when executing concat on foreign key array from the db" do
|
3742
|
+
config_override :legacy_attributes, false
|
3743
|
+
|
3744
|
+
before do
|
3745
|
+
HabtmmContract.create!
|
3746
|
+
HabtmmSignature.create!
|
3747
|
+
end
|
3748
|
+
|
3749
|
+
let!(:contract) { HabtmmContract.first }
|
3750
|
+
let!(:signature) { HabtmmSignature.first }
|
3751
|
+
|
3752
|
+
before do
|
3753
|
+
contract.signature_ids.concat([signature.id])
|
3754
|
+
end
|
3755
|
+
|
3756
|
+
it "works on the first attempt" do
|
3757
|
+
expect(contract.signature_ids).to eq([signature.id])
|
3758
|
+
end
|
3759
|
+
end
|
3609
3760
|
end
|