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