mongoid 7.0.12 → 7.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +13 -13
- data/README.md +32 -19
- data/Rakefile +49 -0
- data/lib/config/locales/en.yml +113 -55
- data/lib/mongoid/association/accessors.rb +143 -53
- data/lib/mongoid/association/bindable.rb +7 -5
- data/lib/mongoid/association/builders.rb +4 -3
- data/lib/mongoid/association/constrainable.rb +5 -3
- data/lib/mongoid/association/depending.rb +10 -12
- data/lib/mongoid/association/eager_loadable.rb +2 -0
- data/lib/mongoid/association/embedded/batchable.rb +5 -3
- data/lib/mongoid/association/embedded/cyclic.rb +8 -6
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +4 -1
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +8 -2
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +15 -12
- data/lib/mongoid/association/embedded/embedded_in.rb +7 -4
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +5 -2
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +9 -3
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +60 -50
- data/lib/mongoid/association/embedded/embeds_many.rb +7 -4
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +5 -2
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +10 -4
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +17 -14
- data/lib/mongoid/association/embedded/embeds_one.rb +7 -4
- data/lib/mongoid/association/embedded.rb +3 -0
- data/lib/mongoid/association/macros.rb +38 -36
- data/lib/mongoid/association/many.rb +16 -13
- data/lib/mongoid/association/marshalable.rb +3 -1
- data/lib/mongoid/association/nested/many.rb +18 -16
- data/lib/mongoid/association/nested/nested_buildable.rb +6 -3
- data/lib/mongoid/association/nested/one.rb +15 -11
- data/lib/mongoid/association/nested.rb +4 -1
- data/lib/mongoid/association/one.rb +3 -1
- data/lib/mongoid/association/options.rb +9 -6
- data/lib/mongoid/association/proxy.rb +37 -15
- data/lib/mongoid/association/referenced/auto_save.rb +6 -3
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +4 -2
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +7 -4
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +40 -2
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +16 -14
- data/lib/mongoid/association/referenced/belongs_to.rb +6 -3
- data/lib/mongoid/association/referenced/counter_cache.rb +2 -0
- data/lib/mongoid/association/referenced/eager.rb +37 -15
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +12 -6
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +5 -2
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +2 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +26 -19
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +13 -6
- data/lib/mongoid/association/referenced/has_many/binding.rb +3 -1
- data/lib/mongoid/association/referenced/has_many/buildable.rb +5 -2
- data/lib/mongoid/association/referenced/has_many/eager.rb +2 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +493 -457
- data/lib/mongoid/association/referenced/has_many/proxy.rb +57 -47
- data/lib/mongoid/association/referenced/has_many.rb +7 -4
- data/lib/mongoid/association/referenced/has_one/binding.rb +4 -2
- data/lib/mongoid/association/referenced/has_one/buildable.rb +17 -2
- data/lib/mongoid/association/referenced/has_one/eager.rb +2 -0
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +13 -11
- data/lib/mongoid/association/referenced/has_one/proxy.rb +23 -16
- data/lib/mongoid/association/referenced/has_one.rb +5 -2
- data/lib/mongoid/association/referenced/syncable.rb +7 -5
- data/lib/mongoid/association/referenced.rb +3 -0
- data/lib/mongoid/association/reflections.rb +7 -5
- data/lib/mongoid/association/relatable.rb +19 -14
- data/lib/mongoid/association.rb +9 -6
- data/lib/mongoid/atomic/modifiers.rb +25 -2
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -2
- data/lib/mongoid/atomic/paths/embedded/one.rb +4 -2
- data/lib/mongoid/atomic/paths/embedded.rb +2 -0
- data/lib/mongoid/atomic/paths/root.rb +4 -2
- data/lib/mongoid/atomic/paths.rb +2 -0
- data/lib/mongoid/atomic.rb +28 -2
- data/lib/mongoid/attributes/dynamic.rb +3 -1
- data/lib/mongoid/attributes/nested.rb +7 -5
- data/lib/mongoid/attributes/processing.rb +8 -6
- data/lib/mongoid/attributes/projector.rb +120 -0
- data/lib/mongoid/attributes/readonly.rb +3 -1
- data/lib/mongoid/attributes.rb +46 -27
- data/lib/mongoid/cacheable.rb +5 -3
- data/lib/mongoid/changeable.rb +3 -1
- data/lib/mongoid/clients/factory.rb +42 -10
- data/lib/mongoid/clients/options.rb +10 -8
- data/lib/mongoid/clients/sessions.rb +3 -0
- data/lib/mongoid/clients/storage_options.rb +7 -5
- data/lib/mongoid/clients/validators/storage.rb +2 -0
- data/lib/mongoid/clients/validators.rb +2 -0
- data/lib/mongoid/clients.rb +3 -1
- data/lib/mongoid/composable.rb +5 -2
- data/lib/mongoid/config/environment.rb +11 -1
- data/lib/mongoid/config/options.rb +20 -12
- data/lib/mongoid/config/validators/client.rb +2 -0
- data/lib/mongoid/config/validators/option.rb +2 -0
- data/lib/mongoid/config/validators.rb +2 -0
- data/lib/mongoid/config.rb +75 -12
- data/lib/mongoid/contextual/aggregable/memory.rb +3 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +13 -9
- data/lib/mongoid/contextual/atomic.rb +31 -8
- data/lib/mongoid/contextual/command.rb +2 -0
- data/lib/mongoid/contextual/geo_near.rb +5 -3
- data/lib/mongoid/contextual/map_reduce.rb +5 -2
- data/lib/mongoid/contextual/memory.rb +4 -2
- data/lib/mongoid/contextual/mongo.rb +29 -5
- data/lib/mongoid/contextual/none.rb +5 -0
- data/lib/mongoid/contextual/queryable.rb +2 -0
- data/lib/mongoid/contextual.rb +7 -4
- data/lib/mongoid/copyable.rb +11 -5
- data/lib/mongoid/criteria/findable.rb +12 -2
- data/lib/mongoid/criteria/includable.rb +8 -6
- data/lib/mongoid/criteria/inspectable.rb +2 -0
- data/lib/mongoid/criteria/marshalable.rb +2 -0
- data/lib/mongoid/criteria/modifiable.rb +2 -0
- data/lib/mongoid/criteria/options.rb +2 -0
- data/lib/mongoid/criteria/permission.rb +2 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -0
- data/lib/mongoid/criteria/queryable/expandable.rb +69 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/date.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +5 -6
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/object.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/range.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +6 -4
- data/lib/mongoid/criteria/queryable/extensions/set.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/time.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +3 -1
- data/lib/mongoid/criteria/queryable/extensions.rb +1 -3
- data/lib/mongoid/criteria/queryable/key.rb +35 -7
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -1
- data/lib/mongoid/criteria/queryable/mergeable.rb +179 -11
- data/lib/mongoid/criteria/queryable/optional.rb +5 -3
- data/lib/mongoid/criteria/queryable/options.rb +2 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +5 -2
- data/lib/mongoid/criteria/queryable/selectable.rb +397 -98
- data/lib/mongoid/criteria/queryable/selector.rb +37 -8
- data/lib/mongoid/criteria/queryable/smash.rb +2 -0
- data/lib/mongoid/criteria/queryable/storable.rb +233 -0
- data/lib/mongoid/criteria/queryable.rb +7 -2
- data/lib/mongoid/criteria/scopable.rb +2 -0
- data/lib/mongoid/criteria.rb +79 -15
- data/lib/mongoid/document.rb +21 -20
- data/lib/mongoid/equality.rb +3 -2
- data/lib/mongoid/errors/ambiguous_relationship.rb +4 -2
- data/lib/mongoid/errors/callback.rb +2 -0
- data/lib/mongoid/errors/criteria_argument_required.rb +19 -0
- data/lib/mongoid/errors/delete_restriction.rb +10 -10
- data/lib/mongoid/errors/document_not_destroyed.rb +2 -0
- data/lib/mongoid/errors/document_not_found.rb +2 -0
- data/lib/mongoid/errors/eager_load.rb +6 -2
- data/lib/mongoid/errors/empty_config_file.rb +26 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +2 -0
- data/lib/mongoid/errors/invalid_collection.rb +2 -0
- data/lib/mongoid/errors/invalid_config_file.rb +26 -0
- data/lib/mongoid/errors/invalid_config_option.rb +2 -0
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +2 -0
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +25 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +33 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +26 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +28 -0
- data/lib/mongoid/errors/invalid_field.rb +2 -0
- data/lib/mongoid/errors/invalid_field_operator.rb +33 -0
- data/lib/mongoid/errors/invalid_field_option.rb +2 -0
- data/lib/mongoid/errors/invalid_find.rb +2 -0
- data/lib/mongoid/errors/invalid_includes.rb +2 -0
- data/lib/mongoid/errors/invalid_index.rb +2 -0
- data/lib/mongoid/errors/invalid_options.rb +4 -2
- data/lib/mongoid/errors/invalid_path.rb +2 -0
- data/lib/mongoid/errors/invalid_persistence_option.rb +2 -0
- data/lib/mongoid/errors/invalid_query.rb +41 -0
- data/lib/mongoid/errors/invalid_relation.rb +4 -2
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -2
- data/lib/mongoid/errors/invalid_scope.rb +2 -0
- data/lib/mongoid/errors/invalid_session_use.rb +2 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -4
- data/lib/mongoid/errors/invalid_storage_options.rb +2 -0
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -0
- data/lib/mongoid/errors/invalid_time.rb +2 -0
- data/lib/mongoid/errors/invalid_value.rb +2 -0
- data/lib/mongoid/errors/inverse_not_found.rb +3 -1
- data/lib/mongoid/errors/mixed_client_configuration.rb +2 -0
- data/lib/mongoid/errors/mixed_relations.rb +2 -0
- data/lib/mongoid/errors/mongoid_error.rb +3 -1
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -1
- data/lib/mongoid/errors/no_client_config.rb +4 -2
- data/lib/mongoid/errors/no_client_database.rb +2 -0
- data/lib/mongoid/errors/no_client_hosts.rb +2 -0
- data/lib/mongoid/errors/no_clients_config.rb +2 -0
- data/lib/mongoid/errors/no_default_client.rb +3 -1
- data/lib/mongoid/errors/no_environment.rb +2 -0
- data/lib/mongoid/errors/no_map_reduce_output.rb +2 -0
- data/lib/mongoid/errors/no_metadata.rb +2 -0
- data/lib/mongoid/errors/no_parent.rb +2 -0
- data/lib/mongoid/errors/readonly_attribute.rb +2 -0
- data/lib/mongoid/errors/readonly_document.rb +2 -0
- data/lib/mongoid/errors/scope_overwrite.rb +2 -0
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +3 -0
- data/lib/mongoid/errors/unknown_attribute.rb +2 -0
- data/lib/mongoid/errors/unknown_model.rb +2 -0
- data/lib/mongoid/errors/unsaved_document.rb +2 -0
- data/lib/mongoid/errors/unsupported_javascript.rb +2 -0
- data/lib/mongoid/errors/validations.rb +2 -0
- data/lib/mongoid/errors.rb +12 -0
- data/lib/mongoid/evolvable.rb +4 -2
- data/lib/mongoid/extensions/array.rb +23 -6
- data/lib/mongoid/extensions/big_decimal.rb +2 -0
- data/lib/mongoid/extensions/boolean.rb +3 -2
- data/lib/mongoid/extensions/date.rb +13 -3
- data/lib/mongoid/extensions/date_time.rb +4 -3
- data/lib/mongoid/extensions/decimal128.rb +2 -0
- data/lib/mongoid/extensions/false_class.rb +3 -1
- data/lib/mongoid/extensions/float.rb +5 -3
- data/lib/mongoid/extensions/hash.rb +49 -9
- data/lib/mongoid/extensions/integer.rb +5 -3
- data/lib/mongoid/extensions/module.rb +2 -0
- data/lib/mongoid/extensions/nil_class.rb +2 -0
- data/lib/mongoid/extensions/object.rb +16 -4
- data/lib/mongoid/extensions/object_id.rb +2 -0
- data/lib/mongoid/extensions/range.rb +2 -0
- data/lib/mongoid/extensions/regexp.rb +2 -0
- data/lib/mongoid/extensions/set.rb +2 -0
- data/lib/mongoid/extensions/string.rb +18 -9
- data/lib/mongoid/extensions/symbol.rb +2 -0
- data/lib/mongoid/extensions/time.rb +14 -0
- data/lib/mongoid/extensions/time_with_zone.rb +14 -0
- data/lib/mongoid/extensions/true_class.rb +3 -1
- data/lib/mongoid/extensions.rb +3 -0
- data/lib/mongoid/factory.rb +52 -12
- data/lib/mongoid/fields/foreign_key.rb +3 -1
- data/lib/mongoid/fields/localized.rb +2 -0
- data/lib/mongoid/fields/standard.rb +6 -3
- data/lib/mongoid/fields/validators/macro.rb +38 -11
- data/lib/mongoid/fields/validators.rb +2 -0
- data/lib/mongoid/fields.rb +49 -6
- data/lib/mongoid/findable.rb +59 -18
- data/lib/mongoid/indexable/specification.rb +3 -1
- data/lib/mongoid/indexable/validators/options.rb +2 -0
- data/lib/mongoid/indexable.rb +5 -3
- data/lib/mongoid/inspectable.rb +4 -2
- data/lib/mongoid/interceptable.rb +10 -4
- data/lib/mongoid/loggable.rb +13 -7
- data/lib/mongoid/matchable.rb +2 -148
- 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 +32 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +21 -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 +110 -0
- data/lib/mongoid/persistable/creatable.rb +3 -1
- data/lib/mongoid/persistable/deletable.rb +5 -4
- data/lib/mongoid/persistable/destroyable.rb +11 -3
- data/lib/mongoid/persistable/incrementable.rb +6 -2
- data/lib/mongoid/persistable/logical.rb +4 -1
- data/lib/mongoid/persistable/poppable.rb +3 -1
- data/lib/mongoid/persistable/pullable.rb +3 -1
- data/lib/mongoid/persistable/pushable.rb +3 -1
- data/lib/mongoid/persistable/renamable.rb +10 -3
- data/lib/mongoid/persistable/savable.rb +3 -1
- data/lib/mongoid/persistable/settable.rb +3 -1
- data/lib/mongoid/persistable/unsettable.rb +8 -3
- data/lib/mongoid/persistable/updatable.rb +30 -3
- data/lib/mongoid/persistable/upsertable.rb +3 -1
- data/lib/mongoid/persistable.rb +133 -15
- data/lib/mongoid/persistence_context.rb +24 -10
- data/lib/mongoid/positional.rb +2 -0
- data/lib/mongoid/query_cache.rb +118 -100
- data/lib/mongoid/railtie.rb +3 -1
- data/lib/mongoid/railties/controller_runtime.rb +4 -1
- data/lib/mongoid/railties/database.rake +9 -0
- data/lib/mongoid/reloadable.rb +11 -4
- data/lib/mongoid/scopable.rb +2 -1
- data/lib/mongoid/selectable.rb +8 -8
- data/lib/mongoid/serializable.rb +24 -14
- data/lib/mongoid/shardable.rb +80 -10
- data/lib/mongoid/stateful.rb +3 -1
- data/lib/mongoid/stringified_symbol.rb +53 -0
- data/lib/mongoid/tasks/database.rake +12 -5
- data/lib/mongoid/tasks/database.rb +85 -0
- data/lib/mongoid/threaded/lifecycle.rb +2 -0
- data/lib/mongoid/threaded.rb +2 -0
- data/lib/mongoid/timestamps/created/short.rb +2 -0
- data/lib/mongoid/timestamps/created.rb +3 -1
- data/lib/mongoid/timestamps/short.rb +2 -0
- data/lib/mongoid/timestamps/timeless.rb +6 -2
- data/lib/mongoid/timestamps/updated/short.rb +2 -0
- data/lib/mongoid/timestamps/updated.rb +3 -1
- data/lib/mongoid/timestamps.rb +3 -1
- data/lib/mongoid/touchable.rb +53 -16
- data/lib/mongoid/traversable.rb +115 -6
- data/lib/mongoid/validatable/associated.rb +5 -3
- data/lib/mongoid/validatable/format.rb +2 -0
- data/lib/mongoid/validatable/length.rb +2 -0
- data/lib/mongoid/validatable/localizable.rb +2 -0
- data/lib/mongoid/validatable/macros.rb +2 -0
- data/lib/mongoid/validatable/presence.rb +7 -5
- data/lib/mongoid/validatable/queryable.rb +2 -0
- data/lib/mongoid/validatable/uniqueness.rb +5 -3
- data/lib/mongoid/validatable.rb +7 -5
- data/lib/mongoid/version.rb +2 -1
- data/lib/mongoid.rb +34 -2
- data/lib/rails/generators/mongoid/config/config_generator.rb +10 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +45 -30
- data/lib/rails/generators/mongoid/model/model_generator.rb +3 -1
- data/lib/rails/generators/mongoid_generator.rb +2 -0
- data/lib/rails/mongoid.rb +4 -2
- data/lib/support/ruby_version.rb +3 -0
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +1 -0
- data/spec/integration/app_spec.rb +246 -94
- data/spec/integration/associations/belongs_to_spec.rb +3 -0
- data/spec/integration/associations/embedded_spec.rb +207 -0
- data/spec/integration/associations/embeds_many_spec.rb +68 -0
- data/spec/integration/associations/embeds_one_spec.rb +24 -0
- data/spec/integration/associations/foreign_key_spec.rb +99 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +65 -0
- data/spec/integration/associations/has_many_spec.rb +129 -0
- data/spec/integration/associations/has_one_spec.rb +177 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +116 -0
- data/spec/integration/associations/reverse_population_spec.rb +35 -0
- data/spec/integration/associations/reverse_population_spec_models.rb +37 -0
- data/spec/integration/atomic/modifiers_spec.rb +117 -0
- data/spec/integration/bson_regexp_raw_spec.rb +20 -0
- data/spec/integration/contextual/empty_spec.rb +142 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -1
- data/spec/integration/criteria/default_scope_spec.rb +21 -0
- data/spec/integration/criteria/logical_spec.rb +94 -0
- data/spec/integration/discriminator_key_spec.rb +354 -0
- data/spec/integration/discriminator_value_spec.rb +207 -0
- data/spec/integration/document_spec.rb +30 -0
- data/spec/integration/i18n_fallbacks_spec.rb +90 -0
- data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +120 -41
- 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 +40 -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 +100 -0
- data/spec/integration/matcher_spec.rb +189 -0
- data/spec/integration/server_query_spec.rb +142 -0
- data/spec/integration/shardable_spec.rb +149 -0
- data/spec/integration/stringified_symbol_field_spec.rb +190 -0
- data/spec/lite_spec_helper.rb +15 -5
- data/spec/mongoid/association/accessors_spec.rb +241 -63
- data/spec/mongoid/association/auto_save_spec.rb +3 -0
- data/spec/mongoid/association/builders_spec.rb +3 -0
- data/spec/mongoid/association/constrainable_spec.rb +3 -0
- data/spec/mongoid/association/counter_cache_spec.rb +3 -0
- data/spec/mongoid/association/depending_spec.rb +427 -333
- data/spec/mongoid/association/eager_spec.rb +3 -0
- data/spec/mongoid/association/embedded/cyclic_spec.rb +3 -0
- data/spec/mongoid/association/embedded/dirty_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +4 -1
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +53 -4
- data/spec/mongoid/association/embedded/embeds_many_models.rb +1 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +52 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +4 -1
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +4 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +29 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +4 -1
- data/spec/mongoid/association/macros_spec.rb +3 -0
- data/spec/mongoid/association/nested/many_spec.rb +3 -0
- data/spec/mongoid/association/nested/one_spec.rb +19 -12
- data/spec/mongoid/association/options_spec.rb +3 -0
- data/spec/mongoid/association/polymorphic_spec.rb +3 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +3 -0
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +3 -0
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +205 -10
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +45 -8
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +58 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +4 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +16 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +26 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +37 -14
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +26 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +40 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +26 -2
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +4 -1
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +18 -3
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +248 -93
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +1 -0
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +463 -186
- data/spec/mongoid/association/referenced/has_many_models.rb +41 -0
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +38 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +18 -3
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +3 -0
- data/spec/mongoid/association/referenced/has_one_models.rb +32 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +38 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +4 -1
- data/spec/mongoid/association/reflections_spec.rb +3 -0
- data/spec/mongoid/association/syncable_spec.rb +3 -0
- data/spec/mongoid/association_spec.rb +3 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +50 -0
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +3 -0
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +3 -0
- data/spec/mongoid/atomic/paths/root_spec.rb +3 -0
- data/spec/mongoid/atomic/paths_spec.rb +67 -12
- data/spec/mongoid/atomic_spec.rb +26 -0
- data/spec/mongoid/attributes/nested_spec.rb +4 -1
- 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 +41 -0
- data/spec/mongoid/attributes/readonly_spec.rb +3 -0
- data/spec/mongoid/attributes_spec.rb +336 -0
- data/spec/mongoid/cacheable_spec.rb +3 -0
- data/spec/mongoid/changeable_spec.rb +26 -0
- data/spec/mongoid/clients/factory_spec.rb +137 -28
- data/spec/mongoid/clients/options_spec.rb +42 -23
- data/spec/mongoid/clients/sessions_spec.rb +4 -6
- data/spec/mongoid/clients/transactions_spec.rb +6 -3
- data/spec/mongoid/clients_spec.rb +3 -0
- data/spec/mongoid/composable_spec.rb +3 -0
- data/spec/mongoid/config/environment_spec.rb +89 -8
- data/spec/mongoid/config/options_spec.rb +23 -3
- data/spec/mongoid/config_spec.rb +172 -0
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +3 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +3 -0
- data/spec/mongoid/contextual/atomic_spec.rb +181 -29
- data/spec/mongoid/contextual/geo_near_spec.rb +4 -1
- data/spec/mongoid/contextual/map_reduce_spec.rb +3 -0
- data/spec/mongoid/contextual/memory_spec.rb +3 -0
- data/spec/mongoid/contextual/mongo_spec.rb +77 -18
- data/spec/mongoid/contextual/none_spec.rb +3 -0
- data/spec/mongoid/copyable_spec.rb +200 -18
- data/spec/mongoid/copyable_spec_models.rb +31 -0
- data/spec/mongoid/criteria/findable_spec.rb +58 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +3 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +3 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +8 -4
- data/spec/mongoid/criteria/options_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +62 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +4 -1
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +36 -17
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +4 -1
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +24 -16
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +146 -12
- data/spec/mongoid/criteria/queryable/optional_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1593 -285
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +39 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1048 -2773
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +590 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +3 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +190 -0
- data/spec/mongoid/criteria/scopable_spec.rb +3 -0
- data/spec/mongoid/criteria_projection_spec.rb +411 -0
- data/spec/mongoid/criteria_spec.rb +241 -278
- data/spec/mongoid/document_fields_spec.rb +26 -0
- data/spec/mongoid/document_query_spec.rb +90 -0
- data/spec/mongoid/document_spec.rb +113 -16
- data/spec/mongoid/equality_spec.rb +3 -1
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +6 -3
- data/spec/mongoid/errors/callback_spec.rb +3 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +5 -2
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +3 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +3 -0
- data/spec/mongoid/errors/eager_load_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_collection_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_config_file_spec.rb +32 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_field_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_includes_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_index_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_options_spec.rb +5 -2
- data/spec/mongoid/errors/invalid_path_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_relation_spec.rb +5 -2
- data/spec/mongoid/errors/invalid_scope_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -0
- data/spec/mongoid/errors/invalid_time_spec.rb +3 -0
- data/spec/mongoid/errors/inverse_not_found_spec.rb +4 -1
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +3 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +3 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +23 -8
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +6 -3
- data/spec/mongoid/errors/no_client_config_spec.rb +5 -2
- data/spec/mongoid/errors/no_client_database_spec.rb +6 -3
- data/spec/mongoid/errors/no_client_hosts_spec.rb +6 -3
- data/spec/mongoid/errors/no_clients_config_spec.rb +3 -0
- data/spec/mongoid/errors/no_environment_spec.rb +3 -0
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -0
- data/spec/mongoid/errors/no_metadata_spec.rb +5 -2
- data/spec/mongoid/errors/no_parent_spec.rb +4 -1
- data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -0
- data/spec/mongoid/errors/readonly_document_spec.rb +3 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -0
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -0
- data/spec/mongoid/errors/unknown_attribute_spec.rb +3 -0
- data/spec/mongoid/errors/unsaved_document_spec.rb +4 -1
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -0
- data/spec/mongoid/errors/validations_spec.rb +3 -0
- data/spec/mongoid/extensions/array_spec.rb +26 -43
- data/spec/mongoid/extensions/big_decimal_spec.rb +3 -0
- data/spec/mongoid/extensions/binary_spec.rb +3 -0
- data/spec/mongoid/extensions/boolean_spec.rb +3 -0
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +336 -0
- data/spec/mongoid/extensions/date_spec.rb +9 -160
- data/spec/mongoid/extensions/date_time_spec.rb +18 -60
- data/spec/mongoid/extensions/decimal128_spec.rb +3 -0
- data/spec/mongoid/extensions/false_class_spec.rb +4 -1
- data/spec/mongoid/extensions/float_spec.rb +18 -3
- data/spec/mongoid/extensions/hash_spec.rb +106 -0
- data/spec/mongoid/extensions/integer_spec.rb +15 -2
- data/spec/mongoid/extensions/module_spec.rb +3 -0
- data/spec/mongoid/extensions/nil_class_spec.rb +3 -0
- data/spec/mongoid/extensions/object_id_spec.rb +3 -0
- data/spec/mongoid/extensions/object_spec.rb +14 -24
- data/spec/mongoid/extensions/range_spec.rb +3 -0
- data/spec/mongoid/extensions/regexp_spec.rb +3 -0
- data/spec/mongoid/extensions/set_spec.rb +3 -0
- data/spec/mongoid/extensions/string_spec.rb +59 -25
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +85 -0
- data/spec/mongoid/extensions/symbol_spec.rb +3 -0
- data/spec/mongoid/extensions/time_spec.rb +30 -0
- data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -0
- data/spec/mongoid/extensions/true_class_spec.rb +4 -1
- data/spec/mongoid/extensions_spec.rb +3 -0
- data/spec/mongoid/factory_spec.rb +287 -27
- data/spec/mongoid/fields/foreign_key_spec.rb +3 -0
- data/spec/mongoid/fields/localized_spec.rb +7 -4
- data/spec/mongoid/fields/standard_spec.rb +3 -0
- data/spec/mongoid/fields_spec.rb +93 -6
- data/spec/mongoid/findable_spec.rb +35 -0
- data/spec/mongoid/indexable/specification_spec.rb +3 -0
- data/spec/mongoid/indexable_spec.rb +31 -2
- data/spec/mongoid/inspectable_spec.rb +40 -2
- data/spec/mongoid/interceptable_spec.rb +67 -2
- data/spec/mongoid/interceptable_spec_models.rb +76 -0
- data/spec/mongoid/loggable_spec.rb +3 -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 +37 -0
- data/spec/mongoid/persistable/creatable_spec.rb +111 -25
- data/spec/mongoid/persistable/deletable_spec.rb +264 -1
- data/spec/mongoid/persistable/destroyable_spec.rb +194 -3
- data/spec/mongoid/persistable/incrementable_spec.rb +17 -0
- data/spec/mongoid/persistable/logical_spec.rb +17 -0
- data/spec/mongoid/persistable/poppable_spec.rb +17 -0
- data/spec/mongoid/persistable/pullable_spec.rb +31 -0
- data/spec/mongoid/persistable/pushable_spec.rb +31 -0
- data/spec/mongoid/persistable/renamable_spec.rb +17 -0
- data/spec/mongoid/persistable/savable_spec.rb +175 -16
- data/spec/mongoid/persistable/settable_spec.rb +47 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +17 -0
- data/spec/mongoid/persistable/updatable_spec.rb +5 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +4 -1
- data/spec/mongoid/persistable_spec.rb +85 -8
- data/spec/mongoid/persistence_context_spec.rb +3 -0
- data/spec/mongoid/positional_spec.rb +3 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +69 -0
- data/spec/mongoid/query_cache_spec.rb +466 -82
- data/spec/mongoid/relations/proxy_spec.rb +3 -0
- data/spec/mongoid/reloadable_spec.rb +93 -1
- data/spec/mongoid/scopable_spec.rb +3 -0
- data/spec/mongoid/selectable_spec.rb +3 -0
- data/spec/mongoid/serializable_spec.rb +152 -20
- data/spec/mongoid/shardable_models.rb +61 -0
- data/spec/mongoid/shardable_spec.rb +116 -16
- data/spec/mongoid/stateful_spec.rb +3 -0
- data/spec/mongoid/tasks/database_rake_spec.rb +3 -0
- data/spec/mongoid/tasks/database_spec.rb +3 -0
- data/spec/mongoid/threaded_spec.rb +3 -0
- data/spec/mongoid/timestamps/created/short_spec.rb +3 -0
- data/spec/mongoid/timestamps/created_spec.rb +3 -0
- data/spec/mongoid/timestamps/timeless_spec.rb +3 -0
- data/spec/mongoid/timestamps/updated/short_spec.rb +3 -0
- data/spec/mongoid/timestamps/updated_spec.rb +3 -0
- data/spec/mongoid/timestamps_spec.rb +3 -0
- data/spec/mongoid/touchable_spec.rb +171 -19
- data/spec/mongoid/touchable_spec_models.rb +54 -0
- data/spec/mongoid/traversable_spec.rb +1103 -0
- data/spec/mongoid/validatable/associated_spec.rb +3 -0
- data/spec/mongoid/validatable/format_spec.rb +3 -0
- data/spec/mongoid/validatable/length_spec.rb +3 -0
- data/spec/mongoid/validatable/numericality_spec.rb +3 -0
- data/spec/mongoid/validatable/presence_spec.rb +3 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +3 -0
- data/spec/mongoid/validatable_spec.rb +4 -1
- data/spec/mongoid_spec.rb +3 -0
- data/spec/rails/controller_extension/controller_runtime_spec.rb +4 -1
- data/spec/rails/mongoid_spec.rb +5 -2
- 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/cluster_config.rb +19 -4
- data/spec/shared/lib/mrss/constraints.rb +67 -12
- data/spec/shared/lib/mrss/docker_runner.rb +10 -1
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +16 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +84 -33
- data/spec/shared/lib/mrss/spec_organizer.rb +32 -2
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +126 -32
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/server.sh +123 -26
- data/spec/shared/shlib/set_env.sh +4 -1
- data/spec/spec_helper.rb +31 -17
- data/spec/support/authorization.rb +3 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +15 -233
- data/spec/support/expectations.rb +6 -1
- data/spec/support/helpers.rb +11 -0
- data/spec/support/macros.rb +1 -0
- data/spec/{app → support}/models/account.rb +3 -0
- data/spec/{app → support}/models/acolyte.rb +3 -0
- data/spec/{app → support}/models/actor.rb +4 -1
- data/spec/support/models/actress.rb +5 -0
- data/spec/{app → support}/models/address.rb +7 -0
- data/spec/{app → support}/models/address_component.rb +3 -0
- data/spec/{app → support}/models/address_number.rb +3 -0
- data/spec/{app → support}/models/agency.rb +3 -0
- data/spec/{app → support}/models/agent.rb +3 -0
- data/spec/{app → support}/models/album.rb +3 -0
- data/spec/{app → support}/models/alert.rb +3 -0
- data/spec/{app → support}/models/animal.rb +3 -0
- data/spec/{app → support}/models/answer.rb +3 -0
- data/spec/{app → support}/models/appointment.rb +3 -0
- data/spec/support/models/armrest.rb +10 -0
- data/spec/{app → support}/models/array_field.rb +1 -0
- data/spec/{app → support}/models/article.rb +3 -0
- data/spec/{app → support}/models/artist.rb +3 -0
- data/spec/{app → support}/models/artwork.rb +3 -0
- data/spec/{app → support}/models/audio.rb +3 -0
- data/spec/{app → support}/models/augmentation.rb +3 -0
- data/spec/{app → support}/models/author.rb +3 -0
- data/spec/{app → support}/models/baby.rb +3 -0
- data/spec/{app → support}/models/band.rb +3 -0
- data/spec/{app → support}/models/bar.rb +3 -0
- data/spec/{app → support}/models/basic.rb +3 -0
- data/spec/support/models/bed.rb +4 -0
- data/spec/support/models/big_palette.rb +5 -0
- data/spec/{app → support}/models/birthday.rb +3 -0
- data/spec/support/models/bolt.rb +8 -0
- data/spec/{app → support}/models/bomb.rb +3 -0
- data/spec/{app → support}/models/book.rb +3 -0
- data/spec/{app → support}/models/breed.rb +3 -0
- data/spec/support/models/browser.rb +9 -0
- data/spec/{app → support}/models/building.rb +3 -0
- data/spec/{app → support}/models/building_address.rb +3 -0
- data/spec/{app → support}/models/bus.rb +3 -0
- data/spec/{app → support}/models/business.rb +3 -0
- data/spec/{app → support}/models/callback_test.rb +3 -0
- data/spec/{app → support}/models/canvas.rb +4 -1
- data/spec/support/models/car.rb +4 -0
- data/spec/{app → support}/models/cat.rb +3 -0
- data/spec/{app → support}/models/category.rb +3 -0
- data/spec/{app → support}/models/child.rb +3 -0
- data/spec/{app → support}/models/child_doc.rb +3 -0
- data/spec/{app → support}/models/church.rb +3 -0
- data/spec/{app → support}/models/circle.rb +3 -0
- data/spec/{app → support}/models/circuit.rb +3 -0
- data/spec/{app → support}/models/circus.rb +3 -0
- data/spec/{app → support}/models/code.rb +3 -0
- data/spec/support/models/coding/pull_request.rb +12 -0
- data/spec/support/models/coding.rb +4 -0
- data/spec/{app → support}/models/comment.rb +3 -0
- data/spec/{app → support}/models/company.rb +3 -0
- data/spec/{app → support}/models/consumption_period.rb +3 -0
- data/spec/{app → support}/models/contextable_item.rb +3 -0
- data/spec/{app → support}/models/contractor.rb +3 -0
- data/spec/{app → support}/models/cookie.rb +3 -0
- data/spec/{app → support}/models/country_code.rb +3 -0
- data/spec/{app → support}/models/courier_job.rb +3 -0
- data/spec/support/models/crate.rb +13 -0
- data/spec/{app → support}/models/customer.rb +0 -0
- data/spec/{app → support}/models/customer_address.rb +0 -0
- data/spec/support/models/deed.rb +8 -0
- data/spec/{app → support}/models/definition.rb +3 -0
- data/spec/{app → support}/models/delegating_patient.rb +0 -0
- data/spec/{app → support}/models/description.rb +3 -0
- data/spec/{app → support}/models/dictionary.rb +9 -0
- data/spec/{app → support}/models/division.rb +3 -0
- data/spec/{app → support}/models/doctor.rb +3 -0
- data/spec/{app → support}/models/dog.rb +3 -0
- data/spec/{app → support}/models/dokument.rb +3 -0
- data/spec/{app → support}/models/draft.rb +3 -0
- data/spec/{app → support}/models/dragon.rb +3 -0
- data/spec/{app → support}/models/driver.rb +4 -1
- data/spec/{app → support}/models/drug.rb +3 -0
- data/spec/{app → support}/models/dungeon.rb +3 -0
- data/spec/{app → support}/models/edit.rb +3 -0
- data/spec/{app → support}/models/email.rb +3 -0
- data/spec/support/models/employer.rb +8 -0
- data/spec/{app → support}/models/entry.rb +3 -0
- data/spec/support/models/eraser.rb +4 -0
- data/spec/{app → support}/models/even.rb +3 -0
- data/spec/{app → support}/models/event.rb +3 -0
- data/spec/{app → support}/models/exhibition.rb +3 -0
- data/spec/{app → support}/models/exhibitor.rb +3 -0
- data/spec/{app → support}/models/explosion.rb +3 -0
- data/spec/{app → support}/models/eye.rb +3 -0
- data/spec/{app → support}/models/eye_bowl.rb +3 -0
- data/spec/{app → support}/models/face.rb +3 -0
- data/spec/{app → support}/models/favorite.rb +3 -0
- data/spec/{app → support}/models/filesystem.rb +3 -0
- data/spec/{app → support}/models/fire_hydrant.rb +3 -0
- data/spec/{app → support}/models/firefox.rb +3 -0
- data/spec/{app → support}/models/fish.rb +3 -0
- data/spec/{app → support}/models/folder.rb +3 -0
- data/spec/{app → support}/models/folder_item.rb +3 -0
- data/spec/{app → support}/models/fruits.rb +3 -0
- data/spec/{app → support}/models/game.rb +3 -0
- data/spec/{app → support}/models/ghost.rb +3 -0
- data/spec/support/models/guitar.rb +5 -0
- data/spec/support/models/hole.rb +13 -0
- data/spec/{app → support}/models/home.rb +3 -0
- data/spec/{app → support}/models/house.rb +3 -0
- data/spec/support/models/html_writer.rb +6 -0
- data/spec/{app → support}/models/id_key.rb +3 -0
- data/spec/support/models/idnodef.rb +8 -0
- data/spec/{app → support}/models/image.rb +3 -0
- data/spec/{app → support}/models/implant.rb +3 -0
- data/spec/support/models/instrument.rb +9 -0
- data/spec/{app → support}/models/item.rb +4 -1
- data/spec/{app → support}/models/jar.rb +3 -0
- data/spec/{app → support}/models/kaleidoscope.rb +3 -0
- data/spec/{app → support}/models/kangaroo.rb +4 -1
- data/spec/{app → support}/models/label.rb +3 -0
- data/spec/{app → support}/models/language.rb +3 -0
- data/spec/{app → support}/models/lat_lng.rb +3 -0
- data/spec/{app → support}/models/league.rb +3 -0
- data/spec/support/models/learner.rb +5 -0
- data/spec/{app → support}/models/line_item.rb +3 -0
- data/spec/{app → support}/models/location.rb +3 -0
- data/spec/{app → support}/models/login.rb +3 -0
- data/spec/{app → support}/models/manufacturer.rb +3 -0
- data/spec/{app → support}/models/meat.rb +3 -0
- data/spec/{app → support}/models/membership.rb +3 -0
- data/spec/{app → support}/models/message.rb +3 -0
- data/spec/{app → support}/models/minim.rb +1 -1
- data/spec/{app → support}/models/mixed_drink.rb +3 -0
- data/spec/support/models/mop.rb +25 -0
- data/spec/{app → support}/models/movie.rb +3 -0
- data/spec/support/models/my_hash.rb +5 -0
- data/spec/{app → support}/models/name.rb +3 -0
- data/spec/support/models/name_only.rb +9 -0
- data/spec/{app → support}/models/node.rb +3 -0
- data/spec/{app → support}/models/note.rb +3 -0
- data/spec/support/models/nut.rb +8 -0
- data/spec/{app → support}/models/odd.rb +3 -0
- data/spec/support/models/order.rb +11 -0
- data/spec/{app → support}/models/ordered_post.rb +3 -0
- data/spec/{app → support}/models/ordered_preference.rb +3 -0
- data/spec/{app → support}/models/oscar.rb +3 -0
- data/spec/support/models/other_owner_object.rb +5 -0
- data/spec/{app → support}/models/override.rb +3 -0
- data/spec/{app → support}/models/ownable.rb +3 -0
- data/spec/{app → support}/models/owner.rb +5 -0
- data/spec/support/models/pack.rb +6 -0
- data/spec/{app → support}/models/page.rb +3 -0
- data/spec/{app → support}/models/page_question.rb +3 -0
- data/spec/{app → support}/models/palette.rb +4 -1
- data/spec/{app → support}/models/parent.rb +3 -0
- data/spec/{app → support}/models/parent_doc.rb +3 -0
- data/spec/{app → support}/models/passport.rb +4 -0
- data/spec/{app → support}/models/patient.rb +3 -0
- data/spec/support/models/pdf_writer.rb +6 -0
- data/spec/support/models/pencil.rb +4 -0
- data/spec/{app → support}/models/person.rb +21 -1
- data/spec/{app → support}/models/pet.rb +3 -0
- data/spec/{app → support}/models/pet_owner.rb +3 -0
- data/spec/{app → support}/models/phone.rb +4 -0
- data/spec/support/models/piano.rb +5 -0
- data/spec/{app → support}/models/pizza.rb +3 -0
- data/spec/{app → support}/models/player.rb +3 -0
- data/spec/{app → support}/models/post.rb +3 -0
- data/spec/{app → support}/models/post_genre.rb +3 -0
- data/spec/{app → support}/models/powerup.rb +3 -0
- data/spec/{app → support}/models/preference.rb +3 -0
- data/spec/{app → support}/models/princess.rb +3 -0
- data/spec/{app → support}/models/product.rb +3 -0
- data/spec/support/models/profile.rb +18 -0
- data/spec/{app → support}/models/pronunciation.rb +3 -0
- data/spec/{app → support}/models/pub.rb +3 -0
- data/spec/support/models/publication/encyclopedia.rb +12 -0
- data/spec/support/models/publication/review.rb +14 -0
- data/spec/support/models/publication.rb +5 -0
- data/spec/{app → support}/models/purchase.rb +3 -0
- data/spec/{app → support}/models/question.rb +3 -0
- data/spec/{app → support}/models/quiz.rb +3 -0
- data/spec/{app → support}/models/rating.rb +3 -0
- data/spec/{app → support}/models/record.rb +3 -0
- data/spec/{app → support}/models/registry.rb +3 -0
- data/spec/{app → support}/models/role.rb +3 -0
- data/spec/{app → support}/models/root_category.rb +3 -0
- data/spec/{app → support}/models/sandwich.rb +3 -0
- data/spec/{app → support}/models/scheduler.rb +3 -0
- data/spec/support/models/scribe.rb +8 -0
- data/spec/support/models/sealer.rb +8 -0
- data/spec/support/models/seat.rb +25 -0
- data/spec/{app → support}/models/seo.rb +3 -0
- data/spec/support/models/series.rb +8 -0
- data/spec/{app → support}/models/server.rb +3 -0
- data/spec/{app → support}/models/service.rb +3 -0
- data/spec/{app → support}/models/shape.rb +5 -2
- data/spec/{app → support}/models/shelf.rb +3 -0
- data/spec/{app → support}/models/shipment_address.rb +3 -0
- data/spec/{app → support}/models/shipping_container.rb +3 -0
- data/spec/{app → support}/models/shipping_pack.rb +3 -0
- data/spec/support/models/shirt.rb +12 -0
- data/spec/{app → support}/models/shop.rb +3 -0
- data/spec/{app → support}/models/short_agent.rb +3 -0
- data/spec/{app → support}/models/short_quiz.rb +3 -0
- data/spec/{app → support}/models/simple.rb +3 -0
- data/spec/{app → support}/models/slave.rb +3 -0
- data/spec/{app → support}/models/song.rb +3 -0
- data/spec/{app → support}/models/sound.rb +3 -0
- data/spec/support/models/spacer.rb +8 -0
- data/spec/{app → support}/models/square.rb +3 -0
- data/spec/{app → support}/models/staff.rb +3 -0
- data/spec/{app → support}/models/store_as_dup_test1.rb +3 -0
- data/spec/{app → support}/models/store_as_dup_test2.rb +3 -0
- data/spec/{app → support}/models/store_as_dup_test3.rb +1 -0
- data/spec/{app → support}/models/store_as_dup_test4.rb +1 -0
- data/spec/support/models/strategy.rb +6 -0
- data/spec/support/models/sub_item.rb +6 -0
- data/spec/{app → support}/models/subscription.rb +3 -0
- data/spec/{app → support}/models/survey.rb +3 -0
- data/spec/{app → support}/models/symptom.rb +3 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/{app → support}/models/tag.rb +3 -0
- data/spec/{app → support}/models/target.rb +3 -0
- data/spec/{app → support}/models/template.rb +3 -0
- data/spec/{app → support}/models/thing.rb +3 -0
- data/spec/support/models/threadlocker.rb +8 -0
- data/spec/support/models/title.rb +6 -0
- data/spec/support/models/tool.rb +11 -0
- data/spec/{app → support}/models/topping.rb +3 -0
- data/spec/support/models/toy.rb +10 -0
- data/spec/{app → support}/models/track.rb +3 -0
- data/spec/{app → support}/models/translation.rb +3 -0
- data/spec/{app → support}/models/tree.rb +3 -0
- data/spec/support/models/truck.rb +8 -0
- data/spec/{app → support}/models/updatable.rb +1 -0
- data/spec/{app → support}/models/user.rb +3 -0
- data/spec/{app → support}/models/user_account.rb +3 -0
- data/spec/{app → support}/models/validation_callback.rb +3 -0
- data/spec/support/models/vehicle.rb +19 -0
- data/spec/{app → support}/models/version.rb +3 -0
- data/spec/{app → support}/models/vertex.rb +4 -1
- data/spec/{app → support}/models/vet_visit.rb +3 -0
- data/spec/{app → support}/models/video.rb +3 -0
- data/spec/support/models/video_game.rb +4 -0
- data/spec/support/models/washer.rb +8 -0
- data/spec/{app → support}/models/weapon.rb +3 -0
- data/spec/{app → support}/models/wiki_page.rb +4 -0
- data/spec/{app → support}/models/word.rb +3 -0
- data/spec/{app → support}/models/word_origin.rb +3 -0
- data/spec/{app → support}/models/writer.rb +5 -2
- data/spec/support/shared/time.rb +54 -0
- data/spec/support/spec_config.rb +14 -3
- data.tar.gz.sig +0 -0
- metadata +1035 -732
- metadata.gz.sig +2 -2
- data/lib/mongoid/criteria/queryable/forwardable.rb +0 -65
- data/lib/mongoid/matchable/all.rb +0 -28
- data/lib/mongoid/matchable/and.rb +0 -30
- data/lib/mongoid/matchable/default.rb +0 -119
- data/lib/mongoid/matchable/elem_match.rb +0 -34
- data/lib/mongoid/matchable/eq.rb +0 -22
- data/lib/mongoid/matchable/exists.rb +0 -23
- data/lib/mongoid/matchable/gt.rb +0 -23
- data/lib/mongoid/matchable/gte.rb +0 -23
- data/lib/mongoid/matchable/in.rb +0 -24
- data/lib/mongoid/matchable/lt.rb +0 -23
- data/lib/mongoid/matchable/lte.rb +0 -23
- data/lib/mongoid/matchable/ne.rb +0 -21
- data/lib/mongoid/matchable/nin.rb +0 -22
- data/lib/mongoid/matchable/nor.rb +0 -37
- data/lib/mongoid/matchable/or.rb +0 -33
- data/lib/mongoid/matchable/regexp.rb +0 -27
- data/lib/mongoid/matchable/size.rb +0 -21
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/big_palette.rb +0 -2
- data/spec/app/models/browser.rb +0 -6
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/employer.rb +0 -5
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/html_writer.rb +0 -3
- 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/pack.rb +0 -3
- data/spec/app/models/pdf_writer.rb +0 -3
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/strategy.rb +0 -3
- data/spec/app/models/sub_item.rb +0 -3
- data/spec/app/models/title.rb +0 -3
- data/spec/app/models/tool.rb +0 -8
- 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/mongoid/criteria/queryable/forwardable_spec.rb +0 -87
- data/spec/mongoid/matchable/all_spec.rb +0 -31
- data/spec/mongoid/matchable/and_spec.rb +0 -187
- data/spec/mongoid/matchable/default_spec.rb +0 -137
- data/spec/mongoid/matchable/elem_match_spec.rb +0 -106
- data/spec/mongoid/matchable/eq_spec.rb +0 -48
- data/spec/mongoid/matchable/exists_spec.rb +0 -57
- data/spec/mongoid/matchable/gt_spec.rb +0 -86
- data/spec/mongoid/matchable/gte_spec.rb +0 -84
- data/spec/mongoid/matchable/in_spec.rb +0 -49
- data/spec/mongoid/matchable/lt_spec.rb +0 -85
- data/spec/mongoid/matchable/lte_spec.rb +0 -85
- data/spec/mongoid/matchable/ne_spec.rb +0 -46
- data/spec/mongoid/matchable/nin_spec.rb +0 -48
- data/spec/mongoid/matchable/nor_spec.rb +0 -209
- data/spec/mongoid/matchable/or_spec.rb +0 -131
- data/spec/mongoid/matchable/regexp_spec.rb +0 -59
- data/spec/mongoid/matchable/size_spec.rb +0 -25
- data/spec/mongoid/matchable_spec.rb +0 -853
- data/spec/support/child_process_helper.rb +0 -76
- data/spec/support/cluster_config.rb +0 -158
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
1
4
|
require "spec_helper"
|
|
2
5
|
|
|
3
6
|
describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
@@ -28,16 +31,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
28
31
|
person.posts.send(method, Post.new(person: person))
|
|
29
32
|
end
|
|
30
33
|
|
|
31
|
-
it "only adds the
|
|
34
|
+
it "only adds the association once" do
|
|
32
35
|
expect(person.posts.size).to eq(1)
|
|
33
36
|
end
|
|
34
37
|
|
|
35
|
-
it "only persists the
|
|
38
|
+
it "only persists the association once" do
|
|
36
39
|
expect(person.reload.posts.size).to eq(1)
|
|
37
40
|
end
|
|
38
41
|
end
|
|
39
42
|
|
|
40
|
-
context "when the
|
|
43
|
+
context "when the associations are not polymorphic" do
|
|
41
44
|
|
|
42
45
|
context "when the parent is a new record" do
|
|
43
46
|
|
|
@@ -55,15 +58,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
55
58
|
person.posts.send(method, post)
|
|
56
59
|
end
|
|
57
60
|
|
|
58
|
-
it "sets the foreign key on the
|
|
61
|
+
it "sets the foreign key on the association" do
|
|
59
62
|
expect(post.person_id).to eq(person.id)
|
|
60
63
|
end
|
|
61
64
|
|
|
62
|
-
it "sets the base on the inverse
|
|
65
|
+
it "sets the base on the inverse association" do
|
|
63
66
|
expect(post.person).to eq(person)
|
|
64
67
|
end
|
|
65
68
|
|
|
66
|
-
it "sets the same instance on the inverse
|
|
69
|
+
it "sets the same instance on the inverse association" do
|
|
67
70
|
expect(post.person).to eql(person)
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -75,7 +78,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
75
78
|
expect(person.posts.size).to eq(1)
|
|
76
79
|
end
|
|
77
80
|
|
|
78
|
-
it "returns the
|
|
81
|
+
it "returns the association" do
|
|
79
82
|
expect(added).to eq(person.posts)
|
|
80
83
|
end
|
|
81
84
|
end
|
|
@@ -90,15 +93,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
90
93
|
person.posts.send(method, post)
|
|
91
94
|
end
|
|
92
95
|
|
|
93
|
-
it "sets the foreign key on the
|
|
96
|
+
it "sets the foreign key on the association" do
|
|
94
97
|
expect(post.person_id).to eq(person.id)
|
|
95
98
|
end
|
|
96
99
|
|
|
97
|
-
it "sets the base on the inverse
|
|
100
|
+
it "sets the base on the inverse association" do
|
|
98
101
|
expect(post.person).to eq(person)
|
|
99
102
|
end
|
|
100
103
|
|
|
101
|
-
it "sets the same instance on the inverse
|
|
104
|
+
it "sets the same instance on the inverse association" do
|
|
102
105
|
expect(post.person).to eql(person)
|
|
103
106
|
end
|
|
104
107
|
|
|
@@ -117,7 +120,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
117
120
|
post.save
|
|
118
121
|
end
|
|
119
122
|
|
|
120
|
-
it "returns the correct count of the
|
|
123
|
+
it "returns the correct count of the association" do
|
|
121
124
|
expect(person.posts.count).to eq(1)
|
|
122
125
|
end
|
|
123
126
|
end
|
|
@@ -136,11 +139,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
136
139
|
end
|
|
137
140
|
end
|
|
138
141
|
|
|
139
|
-
it "adds the documents to the
|
|
142
|
+
it "adds the documents to the association" do
|
|
140
143
|
expect(person.posts).to eq([ post ])
|
|
141
144
|
end
|
|
142
145
|
|
|
143
|
-
it "sets the foreign key on the inverse
|
|
146
|
+
it "sets the foreign key on the inverse association" do
|
|
144
147
|
expect(post.person_id).to eq(person.id)
|
|
145
148
|
end
|
|
146
149
|
|
|
@@ -171,15 +174,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
171
174
|
person.posts.send(method, post)
|
|
172
175
|
end
|
|
173
176
|
|
|
174
|
-
it "sets the foreign key on the
|
|
177
|
+
it "sets the foreign key on the association" do
|
|
175
178
|
expect(post.person_id).to eq(person.id)
|
|
176
179
|
end
|
|
177
180
|
|
|
178
|
-
it "sets the base on the inverse
|
|
181
|
+
it "sets the base on the inverse association" do
|
|
179
182
|
expect(post.person).to eq(person)
|
|
180
183
|
end
|
|
181
184
|
|
|
182
|
-
it "sets the same instance on the inverse
|
|
185
|
+
it "sets the same instance on the inverse association" do
|
|
183
186
|
expect(post.person).to eql(person)
|
|
184
187
|
end
|
|
185
188
|
|
|
@@ -200,7 +203,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
200
203
|
expect(person.changed).to eq([])
|
|
201
204
|
end
|
|
202
205
|
|
|
203
|
-
context "when the related item has embedded
|
|
206
|
+
context "when the related item has embedded associations" do
|
|
204
207
|
|
|
205
208
|
let!(:user) do
|
|
206
209
|
User.create
|
|
@@ -229,7 +232,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
229
232
|
end
|
|
230
233
|
end
|
|
231
234
|
|
|
232
|
-
context "when documents already exist on the
|
|
235
|
+
context "when documents already exist on the association" do
|
|
233
236
|
|
|
234
237
|
let(:post_two) do
|
|
235
238
|
Post.new(title: "Test")
|
|
@@ -239,15 +242,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
239
242
|
person.posts.send(method, post_two)
|
|
240
243
|
end
|
|
241
244
|
|
|
242
|
-
it "sets the foreign key on the
|
|
245
|
+
it "sets the foreign key on the association" do
|
|
243
246
|
expect(post_two.person_id).to eq(person.id)
|
|
244
247
|
end
|
|
245
248
|
|
|
246
|
-
it "sets the base on the inverse
|
|
249
|
+
it "sets the base on the inverse association" do
|
|
247
250
|
expect(post_two.person).to eq(person)
|
|
248
251
|
end
|
|
249
252
|
|
|
250
|
-
it "sets the same instance on the inverse
|
|
253
|
+
it "sets the same instance on the inverse association" do
|
|
251
254
|
expect(post_two.person).to eql(person)
|
|
252
255
|
end
|
|
253
256
|
|
|
@@ -274,7 +277,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
274
277
|
end
|
|
275
278
|
end
|
|
276
279
|
|
|
277
|
-
context "when.adding to the
|
|
280
|
+
context "when.adding to the association" do
|
|
278
281
|
|
|
279
282
|
let(:person) do
|
|
280
283
|
Person.create
|
|
@@ -290,7 +293,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
290
293
|
person.posts.send(method, post)
|
|
291
294
|
end
|
|
292
295
|
|
|
293
|
-
it "adds the document to the
|
|
296
|
+
it "adds the document to the association" do
|
|
294
297
|
expect(person.posts).to eq([ post ])
|
|
295
298
|
end
|
|
296
299
|
end
|
|
@@ -315,7 +318,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
315
318
|
end
|
|
316
319
|
end
|
|
317
320
|
|
|
318
|
-
context "when the
|
|
321
|
+
context "when the associations are polymorphic" do
|
|
319
322
|
|
|
320
323
|
context "when the parent is a new record" do
|
|
321
324
|
|
|
@@ -331,11 +334,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
331
334
|
movie.ratings.send(method, rating)
|
|
332
335
|
end
|
|
333
336
|
|
|
334
|
-
it "sets the foreign key on the
|
|
337
|
+
it "sets the foreign key on the association" do
|
|
335
338
|
expect(rating.ratable_id).to eq(movie.id)
|
|
336
339
|
end
|
|
337
340
|
|
|
338
|
-
it "sets the base on the inverse
|
|
341
|
+
it "sets the base on the inverse association" do
|
|
339
342
|
expect(rating.ratable).to eq(movie)
|
|
340
343
|
end
|
|
341
344
|
|
|
@@ -362,11 +365,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
362
365
|
movie.ratings.send(method, rating)
|
|
363
366
|
end
|
|
364
367
|
|
|
365
|
-
it "sets the foreign key on the
|
|
368
|
+
it "sets the foreign key on the association" do
|
|
366
369
|
expect(rating.ratable_id).to eq(movie.id)
|
|
367
370
|
end
|
|
368
371
|
|
|
369
|
-
it "sets the base on the inverse
|
|
372
|
+
it "sets the base on the inverse association" do
|
|
370
373
|
expect(rating.ratable).to eq(movie)
|
|
371
374
|
end
|
|
372
375
|
|
|
@@ -384,7 +387,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
384
387
|
|
|
385
388
|
describe "#=" do
|
|
386
389
|
|
|
387
|
-
context "when the
|
|
390
|
+
context "when the association is not polymorphic" do
|
|
388
391
|
|
|
389
392
|
context "when the parent is a new record" do
|
|
390
393
|
|
|
@@ -400,15 +403,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
400
403
|
person.posts = [ post ]
|
|
401
404
|
end
|
|
402
405
|
|
|
403
|
-
it "sets the target of the
|
|
406
|
+
it "sets the target of the association" do
|
|
404
407
|
expect(person.posts._target).to eq([ post ])
|
|
405
408
|
end
|
|
406
409
|
|
|
407
|
-
it "sets the foreign key on the
|
|
410
|
+
it "sets the foreign key on the association" do
|
|
408
411
|
expect(post.person_id).to eq(person.id)
|
|
409
412
|
end
|
|
410
413
|
|
|
411
|
-
it "sets the base on the inverse
|
|
414
|
+
it "sets the base on the inverse association" do
|
|
412
415
|
expect(post.person).to eq(person)
|
|
413
416
|
end
|
|
414
417
|
|
|
@@ -431,15 +434,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
431
434
|
person.posts = [ post ]
|
|
432
435
|
end
|
|
433
436
|
|
|
434
|
-
it "sets the target of the
|
|
437
|
+
it "sets the target of the association" do
|
|
435
438
|
expect(person.posts._target).to eq([ post ])
|
|
436
439
|
end
|
|
437
440
|
|
|
438
|
-
it "sets the foreign key of the
|
|
441
|
+
it "sets the foreign key of the association" do
|
|
439
442
|
expect(post.person_id).to eq(person.id)
|
|
440
443
|
end
|
|
441
444
|
|
|
442
|
-
it "sets the base on the inverse
|
|
445
|
+
it "sets the base on the inverse association" do
|
|
443
446
|
expect(post.person).to eq(person)
|
|
444
447
|
end
|
|
445
448
|
|
|
@@ -447,7 +450,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
447
450
|
expect(post).to be_persisted
|
|
448
451
|
end
|
|
449
452
|
|
|
450
|
-
context "when replacing the
|
|
453
|
+
context "when replacing the association with the same documents" do
|
|
451
454
|
|
|
452
455
|
context "when using the same in memory instance" do
|
|
453
456
|
|
|
@@ -455,11 +458,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
455
458
|
person.posts = [ post ]
|
|
456
459
|
end
|
|
457
460
|
|
|
458
|
-
it "keeps the
|
|
461
|
+
it "keeps the association intact" do
|
|
459
462
|
expect(person.posts).to eq([ post ])
|
|
460
463
|
end
|
|
461
464
|
|
|
462
|
-
it "does not delete the
|
|
465
|
+
it "does not delete the association" do
|
|
463
466
|
expect(person.reload.posts).to eq([ post ])
|
|
464
467
|
end
|
|
465
468
|
end
|
|
@@ -474,11 +477,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
474
477
|
from_db.posts = [ post ]
|
|
475
478
|
end
|
|
476
479
|
|
|
477
|
-
it "keeps the
|
|
480
|
+
it "keeps the association intact" do
|
|
478
481
|
expect(from_db.posts).to eq([ post ])
|
|
479
482
|
end
|
|
480
483
|
|
|
481
|
-
it "does not delete the
|
|
484
|
+
it "does not delete the association" do
|
|
482
485
|
expect(from_db.reload.posts).to eq([ post ])
|
|
483
486
|
end
|
|
484
487
|
end
|
|
@@ -496,7 +499,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
496
499
|
person.posts = [ post, new_post ]
|
|
497
500
|
end
|
|
498
501
|
|
|
499
|
-
it "keeps the
|
|
502
|
+
it "keeps the association intact" do
|
|
500
503
|
expect(person.posts.size).to eq(2)
|
|
501
504
|
end
|
|
502
505
|
|
|
@@ -508,7 +511,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
508
511
|
expect(person.posts).to include(new_post)
|
|
509
512
|
end
|
|
510
513
|
|
|
511
|
-
it "does not delete the
|
|
514
|
+
it "does not delete the association" do
|
|
512
515
|
expect(person.reload.posts).to eq([ post, new_post ])
|
|
513
516
|
end
|
|
514
517
|
end
|
|
@@ -523,11 +526,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
523
526
|
from_db.posts = [ post, new_post ]
|
|
524
527
|
end
|
|
525
528
|
|
|
526
|
-
it "keeps the
|
|
529
|
+
it "keeps the association intact" do
|
|
527
530
|
expect(from_db.posts).to eq([ post, new_post ])
|
|
528
531
|
end
|
|
529
532
|
|
|
530
|
-
it "does not delete the
|
|
533
|
+
it "does not delete the association" do
|
|
531
534
|
expect(from_db.reload.posts).to eq([ post, new_post ])
|
|
532
535
|
end
|
|
533
536
|
end
|
|
@@ -545,11 +548,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
545
548
|
person.posts = [ new_post ]
|
|
546
549
|
end
|
|
547
550
|
|
|
548
|
-
it "keeps the
|
|
551
|
+
it "keeps the association intact" do
|
|
549
552
|
expect(person.posts).to eq([ new_post ])
|
|
550
553
|
end
|
|
551
554
|
|
|
552
|
-
it "does not delete the
|
|
555
|
+
it "does not delete the association" do
|
|
553
556
|
expect(person.reload.posts).to eq([ new_post ])
|
|
554
557
|
end
|
|
555
558
|
end
|
|
@@ -564,11 +567,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
564
567
|
from_db.posts = [ new_post ]
|
|
565
568
|
end
|
|
566
569
|
|
|
567
|
-
it "keeps the
|
|
570
|
+
it "keeps the association intact" do
|
|
568
571
|
expect(from_db.posts).to eq([ new_post ])
|
|
569
572
|
end
|
|
570
573
|
|
|
571
|
-
it "does not delete the
|
|
574
|
+
it "does not delete the association" do
|
|
572
575
|
expect(from_db.reload.posts).to eq([ new_post ])
|
|
573
576
|
end
|
|
574
577
|
end
|
|
@@ -576,7 +579,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
576
579
|
end
|
|
577
580
|
end
|
|
578
581
|
|
|
579
|
-
context "when the
|
|
582
|
+
context "when the association is polymorphic" do
|
|
580
583
|
|
|
581
584
|
context "when the parent is a new record" do
|
|
582
585
|
|
|
@@ -592,15 +595,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
592
595
|
movie.ratings = [ rating ]
|
|
593
596
|
end
|
|
594
597
|
|
|
595
|
-
it "sets the target of the
|
|
598
|
+
it "sets the target of the association" do
|
|
596
599
|
expect(movie.ratings._target).to eq([ rating ])
|
|
597
600
|
end
|
|
598
601
|
|
|
599
|
-
it "sets the foreign key on the
|
|
602
|
+
it "sets the foreign key on the association" do
|
|
600
603
|
expect(rating.ratable_id).to eq(movie.id)
|
|
601
604
|
end
|
|
602
605
|
|
|
603
|
-
it "sets the base on the inverse
|
|
606
|
+
it "sets the base on the inverse association" do
|
|
604
607
|
expect(rating.ratable).to eq(movie)
|
|
605
608
|
end
|
|
606
609
|
|
|
@@ -623,15 +626,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
623
626
|
movie.ratings = [ rating ]
|
|
624
627
|
end
|
|
625
628
|
|
|
626
|
-
it "sets the target of the
|
|
629
|
+
it "sets the target of the association" do
|
|
627
630
|
expect(movie.ratings._target).to eq([ rating ])
|
|
628
631
|
end
|
|
629
632
|
|
|
630
|
-
it "sets the foreign key of the
|
|
633
|
+
it "sets the foreign key of the association" do
|
|
631
634
|
expect(rating.ratable_id).to eq(movie.id)
|
|
632
635
|
end
|
|
633
636
|
|
|
634
|
-
it "sets the base on the inverse
|
|
637
|
+
it "sets the base on the inverse association" do
|
|
635
638
|
expect(rating.ratable).to eq(movie)
|
|
636
639
|
end
|
|
637
640
|
|
|
@@ -673,7 +676,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
673
676
|
|
|
674
677
|
describe "#= nil" do
|
|
675
678
|
|
|
676
|
-
context "when the
|
|
679
|
+
context "when the association is not polymorphic" do
|
|
677
680
|
|
|
678
681
|
context "when the parent is a new record" do
|
|
679
682
|
|
|
@@ -690,11 +693,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
690
693
|
person.posts = nil
|
|
691
694
|
end
|
|
692
695
|
|
|
693
|
-
it "sets the
|
|
696
|
+
it "sets the association to an empty array" do
|
|
694
697
|
expect(person.posts).to be_empty
|
|
695
698
|
end
|
|
696
699
|
|
|
697
|
-
it "removed the inverse
|
|
700
|
+
it "removed the inverse association" do
|
|
698
701
|
expect(post.person).to be_nil
|
|
699
702
|
end
|
|
700
703
|
|
|
@@ -720,11 +723,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
720
723
|
person.posts = nil
|
|
721
724
|
end
|
|
722
725
|
|
|
723
|
-
it "sets the
|
|
726
|
+
it "sets the association to empty" do
|
|
724
727
|
expect(person.posts).to be_empty
|
|
725
728
|
end
|
|
726
729
|
|
|
727
|
-
it "removed the inverse
|
|
730
|
+
it "removed the inverse association" do
|
|
728
731
|
expect(post.person).to be_nil
|
|
729
732
|
end
|
|
730
733
|
|
|
@@ -748,11 +751,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
748
751
|
person.drugs = nil
|
|
749
752
|
end
|
|
750
753
|
|
|
751
|
-
it "sets the
|
|
754
|
+
it "sets the association to empty" do
|
|
752
755
|
expect(person.drugs).to be_empty
|
|
753
756
|
end
|
|
754
757
|
|
|
755
|
-
it "removed the inverse
|
|
758
|
+
it "removed the inverse association" do
|
|
756
759
|
expect(drug.person).to be_nil
|
|
757
760
|
end
|
|
758
761
|
|
|
@@ -760,14 +763,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
760
763
|
expect(drug.person_id).to be_nil
|
|
761
764
|
end
|
|
762
765
|
|
|
763
|
-
it "nullifies the
|
|
766
|
+
it "nullifies the association" do
|
|
764
767
|
expect(drug).to_not be_destroyed
|
|
765
768
|
end
|
|
766
769
|
end
|
|
767
770
|
end
|
|
768
771
|
end
|
|
769
772
|
|
|
770
|
-
context "when the
|
|
773
|
+
context "when the association is polymorphic" do
|
|
771
774
|
|
|
772
775
|
context "when the parent is a new record" do
|
|
773
776
|
|
|
@@ -784,11 +787,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
784
787
|
movie.ratings = nil
|
|
785
788
|
end
|
|
786
789
|
|
|
787
|
-
it "sets the
|
|
790
|
+
it "sets the association to an empty array" do
|
|
788
791
|
expect(movie.ratings).to be_empty
|
|
789
792
|
end
|
|
790
793
|
|
|
791
|
-
it "removed the inverse
|
|
794
|
+
it "removed the inverse association" do
|
|
792
795
|
expect(rating.ratable).to be_nil
|
|
793
796
|
end
|
|
794
797
|
|
|
@@ -812,11 +815,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
812
815
|
movie.ratings = nil
|
|
813
816
|
end
|
|
814
817
|
|
|
815
|
-
it "sets the
|
|
818
|
+
it "sets the association to empty" do
|
|
816
819
|
expect(movie.ratings).to be_empty
|
|
817
820
|
end
|
|
818
821
|
|
|
819
|
-
it "removed the inverse
|
|
822
|
+
it "removed the inverse association" do
|
|
820
823
|
expect(rating.ratable).to be_nil
|
|
821
824
|
end
|
|
822
825
|
|
|
@@ -867,7 +870,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
867
870
|
Person.create(posts: posts)
|
|
868
871
|
end
|
|
869
872
|
|
|
870
|
-
it "returns ids of documents that are in the
|
|
873
|
+
it "returns ids of documents that are in the association" do
|
|
871
874
|
expect(person.post_ids).to eq(posts.map(&:id))
|
|
872
875
|
end
|
|
873
876
|
end
|
|
@@ -876,7 +879,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
876
879
|
|
|
877
880
|
describe "##{method}" do
|
|
878
881
|
|
|
879
|
-
context "when the
|
|
882
|
+
context "when the association is not polymorphic" do
|
|
880
883
|
|
|
881
884
|
context "when the parent is a new record" do
|
|
882
885
|
|
|
@@ -888,11 +891,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
888
891
|
person.posts.send(method, title: "$$$")
|
|
889
892
|
end
|
|
890
893
|
|
|
891
|
-
it "sets the foreign key on the
|
|
894
|
+
it "sets the foreign key on the association" do
|
|
892
895
|
expect(post.person_id).to eq(person.id)
|
|
893
896
|
end
|
|
894
897
|
|
|
895
|
-
it "sets the base on the inverse
|
|
898
|
+
it "sets the base on the inverse association" do
|
|
896
899
|
expect(post.person).to eq(person)
|
|
897
900
|
end
|
|
898
901
|
|
|
@@ -927,11 +930,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
927
930
|
person.posts.send(method, text: "Testing")
|
|
928
931
|
end
|
|
929
932
|
|
|
930
|
-
it "sets the foreign key on the
|
|
933
|
+
it "sets the foreign key on the association" do
|
|
931
934
|
expect(post.person_id).to eq(person.id)
|
|
932
935
|
end
|
|
933
936
|
|
|
934
|
-
it "sets the base on the inverse
|
|
937
|
+
it "sets the base on the inverse association" do
|
|
935
938
|
expect(post.person).to eq(person)
|
|
936
939
|
end
|
|
937
940
|
|
|
@@ -949,7 +952,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
949
952
|
end
|
|
950
953
|
end
|
|
951
954
|
|
|
952
|
-
context "when the
|
|
955
|
+
context "when the association is polymorphic" do
|
|
953
956
|
|
|
954
957
|
context "when the parent is a subclass" do
|
|
955
958
|
|
|
@@ -980,11 +983,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
980
983
|
movie.ratings.send(method, value: 3)
|
|
981
984
|
end
|
|
982
985
|
|
|
983
|
-
it "sets the foreign key on the
|
|
986
|
+
it "sets the foreign key on the association" do
|
|
984
987
|
expect(rating.ratable_id).to eq(movie.id)
|
|
985
988
|
end
|
|
986
989
|
|
|
987
|
-
it "sets the base on the inverse
|
|
990
|
+
it "sets the base on the inverse association" do
|
|
988
991
|
expect(rating.ratable).to eq(movie)
|
|
989
992
|
end
|
|
990
993
|
|
|
@@ -1015,11 +1018,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1015
1018
|
movie.ratings.send(method, value: 4)
|
|
1016
1019
|
end
|
|
1017
1020
|
|
|
1018
|
-
it "sets the foreign key on the
|
|
1021
|
+
it "sets the foreign key on the association" do
|
|
1019
1022
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1020
1023
|
end
|
|
1021
1024
|
|
|
1022
|
-
it "sets the base on the inverse
|
|
1025
|
+
it "sets the base on the inverse association" do
|
|
1023
1026
|
expect(rating.ratable).to eq(movie)
|
|
1024
1027
|
end
|
|
1025
1028
|
|
|
@@ -1041,7 +1044,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1041
1044
|
|
|
1042
1045
|
describe "#clear" do
|
|
1043
1046
|
|
|
1044
|
-
context "when the
|
|
1047
|
+
context "when the association is not polymorphic" do
|
|
1045
1048
|
|
|
1046
1049
|
context "when the parent has been persisted" do
|
|
1047
1050
|
|
|
@@ -1055,11 +1058,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1055
1058
|
person.posts.create(title: "Testing")
|
|
1056
1059
|
end
|
|
1057
1060
|
|
|
1058
|
-
let!(:
|
|
1061
|
+
let!(:association) do
|
|
1059
1062
|
person.posts.clear
|
|
1060
1063
|
end
|
|
1061
1064
|
|
|
1062
|
-
it "clears out the
|
|
1065
|
+
it "clears out the association" do
|
|
1063
1066
|
expect(person.posts).to be_empty
|
|
1064
1067
|
end
|
|
1065
1068
|
|
|
@@ -1071,8 +1074,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1071
1074
|
expect(person.reload.posts).to be_empty
|
|
1072
1075
|
end
|
|
1073
1076
|
|
|
1074
|
-
it "returns the
|
|
1075
|
-
expect(
|
|
1077
|
+
it "returns the association" do
|
|
1078
|
+
expect(association).to be_empty
|
|
1076
1079
|
end
|
|
1077
1080
|
end
|
|
1078
1081
|
|
|
@@ -1082,11 +1085,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1082
1085
|
person.posts.build(title: "Testing")
|
|
1083
1086
|
end
|
|
1084
1087
|
|
|
1085
|
-
let!(:
|
|
1088
|
+
let!(:association) do
|
|
1086
1089
|
person.posts.clear
|
|
1087
1090
|
end
|
|
1088
1091
|
|
|
1089
|
-
it "clears out the
|
|
1092
|
+
it "clears out the association" do
|
|
1090
1093
|
expect(person.posts).to be_empty
|
|
1091
1094
|
end
|
|
1092
1095
|
end
|
|
@@ -1102,17 +1105,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1102
1105
|
person.posts.build(title: "Testing")
|
|
1103
1106
|
end
|
|
1104
1107
|
|
|
1105
|
-
let!(:
|
|
1108
|
+
let!(:association) do
|
|
1106
1109
|
person.posts.clear
|
|
1107
1110
|
end
|
|
1108
1111
|
|
|
1109
|
-
it "clears out the
|
|
1112
|
+
it "clears out the association" do
|
|
1110
1113
|
expect(person.posts).to be_empty
|
|
1111
1114
|
end
|
|
1112
1115
|
end
|
|
1113
1116
|
end
|
|
1114
1117
|
|
|
1115
|
-
context "when the
|
|
1118
|
+
context "when the association is polymorphic" do
|
|
1116
1119
|
|
|
1117
1120
|
context "when the parent has been persisted" do
|
|
1118
1121
|
|
|
@@ -1126,11 +1129,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1126
1129
|
movie.ratings.create(value: 1)
|
|
1127
1130
|
end
|
|
1128
1131
|
|
|
1129
|
-
let!(:
|
|
1132
|
+
let!(:association) do
|
|
1130
1133
|
movie.ratings.clear
|
|
1131
1134
|
end
|
|
1132
1135
|
|
|
1133
|
-
it "clears out the
|
|
1136
|
+
it "clears out the association" do
|
|
1134
1137
|
expect(movie.ratings).to be_empty
|
|
1135
1138
|
end
|
|
1136
1139
|
|
|
@@ -1142,8 +1145,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1142
1145
|
expect(movie.reload.ratings).to be_empty
|
|
1143
1146
|
end
|
|
1144
1147
|
|
|
1145
|
-
it "returns the
|
|
1146
|
-
expect(
|
|
1148
|
+
it "returns the association" do
|
|
1149
|
+
expect(association).to be_empty
|
|
1147
1150
|
end
|
|
1148
1151
|
end
|
|
1149
1152
|
|
|
@@ -1153,11 +1156,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1153
1156
|
movie.ratings.build(value: 3)
|
|
1154
1157
|
end
|
|
1155
1158
|
|
|
1156
|
-
let!(:
|
|
1159
|
+
let!(:association) do
|
|
1157
1160
|
movie.ratings.clear
|
|
1158
1161
|
end
|
|
1159
1162
|
|
|
1160
|
-
it "clears out the
|
|
1163
|
+
it "clears out the association" do
|
|
1161
1164
|
expect(movie.ratings).to be_empty
|
|
1162
1165
|
end
|
|
1163
1166
|
end
|
|
@@ -1173,11 +1176,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1173
1176
|
movie.ratings.build(value: 2)
|
|
1174
1177
|
end
|
|
1175
1178
|
|
|
1176
|
-
let!(:
|
|
1179
|
+
let!(:association) do
|
|
1177
1180
|
movie.ratings.clear
|
|
1178
1181
|
end
|
|
1179
1182
|
|
|
1180
|
-
it "clears out the
|
|
1183
|
+
it "clears out the association" do
|
|
1181
1184
|
expect(movie.ratings).to be_empty
|
|
1182
1185
|
end
|
|
1183
1186
|
end
|
|
@@ -1186,7 +1189,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1186
1189
|
|
|
1187
1190
|
describe "#concat" do
|
|
1188
1191
|
|
|
1189
|
-
context "when the
|
|
1192
|
+
context "when the associations are not polymorphic" do
|
|
1190
1193
|
|
|
1191
1194
|
context "when the parent is a new record" do
|
|
1192
1195
|
|
|
@@ -1202,15 +1205,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1202
1205
|
person.posts.concat([ post ])
|
|
1203
1206
|
end
|
|
1204
1207
|
|
|
1205
|
-
it "sets the foreign key on the
|
|
1208
|
+
it "sets the foreign key on the association" do
|
|
1206
1209
|
expect(post.person_id).to eq(person.id)
|
|
1207
1210
|
end
|
|
1208
1211
|
|
|
1209
|
-
it "sets the base on the inverse
|
|
1212
|
+
it "sets the base on the inverse association" do
|
|
1210
1213
|
expect(post.person).to eq(person)
|
|
1211
1214
|
end
|
|
1212
1215
|
|
|
1213
|
-
it "sets the same instance on the inverse
|
|
1216
|
+
it "sets the same instance on the inverse association" do
|
|
1214
1217
|
expect(post.person).to eql(person)
|
|
1215
1218
|
end
|
|
1216
1219
|
|
|
@@ -1235,11 +1238,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1235
1238
|
end
|
|
1236
1239
|
end
|
|
1237
1240
|
|
|
1238
|
-
it "adds the documents to the
|
|
1241
|
+
it "adds the documents to the association" do
|
|
1239
1242
|
expect(person.posts).to eq([ post ])
|
|
1240
1243
|
end
|
|
1241
1244
|
|
|
1242
|
-
it "sets the foreign key on the inverse
|
|
1245
|
+
it "sets the foreign key on the inverse association" do
|
|
1243
1246
|
expect(post.person_id).to eq(person.id)
|
|
1244
1247
|
end
|
|
1245
1248
|
|
|
@@ -1274,15 +1277,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1274
1277
|
person.posts.concat([ post, post_three ])
|
|
1275
1278
|
end
|
|
1276
1279
|
|
|
1277
|
-
it "sets the foreign key on the
|
|
1280
|
+
it "sets the foreign key on the association" do
|
|
1278
1281
|
expect(post.person_id).to eq(person.id)
|
|
1279
1282
|
end
|
|
1280
1283
|
|
|
1281
|
-
it "sets the base on the inverse
|
|
1284
|
+
it "sets the base on the inverse association" do
|
|
1282
1285
|
expect(post.person).to eq(person)
|
|
1283
1286
|
end
|
|
1284
1287
|
|
|
1285
|
-
it "sets the same instance on the inverse
|
|
1288
|
+
it "sets the same instance on the inverse association" do
|
|
1286
1289
|
expect(post.person).to eql(person)
|
|
1287
1290
|
end
|
|
1288
1291
|
|
|
@@ -1294,7 +1297,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1294
1297
|
expect(person.posts.count).to eq(2)
|
|
1295
1298
|
end
|
|
1296
1299
|
|
|
1297
|
-
context "when documents already exist on the
|
|
1300
|
+
context "when documents already exist on the association" do
|
|
1298
1301
|
|
|
1299
1302
|
let(:post_two) do
|
|
1300
1303
|
Post.new(title: "Test")
|
|
@@ -1304,15 +1307,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1304
1307
|
person.posts.concat([ post_two ])
|
|
1305
1308
|
end
|
|
1306
1309
|
|
|
1307
|
-
it "sets the foreign key on the
|
|
1310
|
+
it "sets the foreign key on the association" do
|
|
1308
1311
|
expect(post_two.person_id).to eq(person.id)
|
|
1309
1312
|
end
|
|
1310
1313
|
|
|
1311
|
-
it "sets the base on the inverse
|
|
1314
|
+
it "sets the base on the inverse association" do
|
|
1312
1315
|
expect(post_two.person).to eq(person)
|
|
1313
1316
|
end
|
|
1314
1317
|
|
|
1315
|
-
it "sets the same instance on the inverse
|
|
1318
|
+
it "sets the same instance on the inverse association" do
|
|
1316
1319
|
expect(post_two.person).to eql(person)
|
|
1317
1320
|
end
|
|
1318
1321
|
|
|
@@ -1336,7 +1339,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1336
1339
|
end
|
|
1337
1340
|
end
|
|
1338
1341
|
|
|
1339
|
-
context "when the
|
|
1342
|
+
context "when the associations are polymorphic" do
|
|
1340
1343
|
|
|
1341
1344
|
context "when the parent is a new record" do
|
|
1342
1345
|
|
|
@@ -1352,11 +1355,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1352
1355
|
movie.ratings.concat([ rating ])
|
|
1353
1356
|
end
|
|
1354
1357
|
|
|
1355
|
-
it "sets the foreign key on the
|
|
1358
|
+
it "sets the foreign key on the association" do
|
|
1356
1359
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1357
1360
|
end
|
|
1358
1361
|
|
|
1359
|
-
it "sets the base on the inverse
|
|
1362
|
+
it "sets the base on the inverse association" do
|
|
1360
1363
|
expect(rating.ratable).to eq(movie)
|
|
1361
1364
|
end
|
|
1362
1365
|
|
|
@@ -1383,11 +1386,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1383
1386
|
movie.ratings.concat([ rating ])
|
|
1384
1387
|
end
|
|
1385
1388
|
|
|
1386
|
-
it "sets the foreign key on the
|
|
1389
|
+
it "sets the foreign key on the association" do
|
|
1387
1390
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1388
1391
|
end
|
|
1389
1392
|
|
|
1390
|
-
it "sets the base on the inverse
|
|
1393
|
+
it "sets the base on the inverse association" do
|
|
1391
1394
|
expect(rating.ratable).to eq(movie)
|
|
1392
1395
|
end
|
|
1393
1396
|
|
|
@@ -1429,9 +1432,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1429
1432
|
end
|
|
1430
1433
|
end
|
|
1431
1434
|
|
|
1435
|
+
context "when no document is added" do
|
|
1436
|
+
|
|
1437
|
+
it "returns false" do
|
|
1438
|
+
expect(movie.ratings.any?).to be false
|
|
1439
|
+
end
|
|
1440
|
+
end
|
|
1441
|
+
|
|
1432
1442
|
context "when new documents exist in the database" do
|
|
1433
1443
|
|
|
1434
|
-
context "when the documents are part of the
|
|
1444
|
+
context "when the documents are part of the association" do
|
|
1435
1445
|
|
|
1436
1446
|
before do
|
|
1437
1447
|
Rating.create(ratable: movie)
|
|
@@ -1442,7 +1452,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1442
1452
|
end
|
|
1443
1453
|
end
|
|
1444
1454
|
|
|
1445
|
-
context "when the documents are not part of the
|
|
1455
|
+
context "when the documents are not part of the association" do
|
|
1446
1456
|
|
|
1447
1457
|
before do
|
|
1448
1458
|
Rating.create
|
|
@@ -1455,6 +1465,188 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1455
1465
|
end
|
|
1456
1466
|
end
|
|
1457
1467
|
|
|
1468
|
+
describe "#any?" do
|
|
1469
|
+
|
|
1470
|
+
shared_examples 'does not query database when association is loaded' do
|
|
1471
|
+
|
|
1472
|
+
let(:fresh_movie) { Movie.find(movie.id) }
|
|
1473
|
+
|
|
1474
|
+
context 'when association is not loaded' do
|
|
1475
|
+
it 'queries database on each call' do
|
|
1476
|
+
fresh_movie
|
|
1477
|
+
|
|
1478
|
+
expect_query(1) do
|
|
1479
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1480
|
+
end
|
|
1481
|
+
|
|
1482
|
+
expect_query(1) do
|
|
1483
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1484
|
+
end
|
|
1485
|
+
end
|
|
1486
|
+
|
|
1487
|
+
context 'when using a block' do
|
|
1488
|
+
it 'queries database on first call only' do
|
|
1489
|
+
fresh_movie
|
|
1490
|
+
|
|
1491
|
+
expect_query(1) do
|
|
1492
|
+
fresh_movie.ratings.any? { false }.should be false
|
|
1493
|
+
end
|
|
1494
|
+
|
|
1495
|
+
expect_no_queries do
|
|
1496
|
+
fresh_movie.ratings.any? { false }.should be false
|
|
1497
|
+
end
|
|
1498
|
+
end
|
|
1499
|
+
end
|
|
1500
|
+
end
|
|
1501
|
+
|
|
1502
|
+
context 'when association is loaded' do
|
|
1503
|
+
it 'does not query database' do
|
|
1504
|
+
fresh_movie
|
|
1505
|
+
|
|
1506
|
+
expect_query(1) do
|
|
1507
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1508
|
+
end
|
|
1509
|
+
|
|
1510
|
+
fresh_movie.ratings.to_a
|
|
1511
|
+
|
|
1512
|
+
expect_no_queries do
|
|
1513
|
+
fresh_movie.ratings.any?.should be expected_result
|
|
1514
|
+
end
|
|
1515
|
+
end
|
|
1516
|
+
end
|
|
1517
|
+
end
|
|
1518
|
+
|
|
1519
|
+
let(:movie) do
|
|
1520
|
+
Movie.create
|
|
1521
|
+
end
|
|
1522
|
+
|
|
1523
|
+
context "when nothing exists on the association" do
|
|
1524
|
+
|
|
1525
|
+
context "when no document is added" do
|
|
1526
|
+
|
|
1527
|
+
let!(:movie) do
|
|
1528
|
+
Movie.create!
|
|
1529
|
+
end
|
|
1530
|
+
|
|
1531
|
+
it "returns false" do
|
|
1532
|
+
expect(movie.ratings.any?).to be false
|
|
1533
|
+
end
|
|
1534
|
+
|
|
1535
|
+
let(:expected_result) { false }
|
|
1536
|
+
include_examples 'does not query database when association is loaded'
|
|
1537
|
+
end
|
|
1538
|
+
|
|
1539
|
+
context "when the document is destroyed" do
|
|
1540
|
+
|
|
1541
|
+
before do
|
|
1542
|
+
Rating.create!
|
|
1543
|
+
end
|
|
1544
|
+
|
|
1545
|
+
let!(:movie) do
|
|
1546
|
+
Movie.create!
|
|
1547
|
+
end
|
|
1548
|
+
|
|
1549
|
+
it "returns false" do
|
|
1550
|
+
movie.destroy
|
|
1551
|
+
expect(movie.ratings.any?).to be false
|
|
1552
|
+
end
|
|
1553
|
+
end
|
|
1554
|
+
end
|
|
1555
|
+
|
|
1556
|
+
context "when appending to a association and _loaded/_unloaded are empty" do
|
|
1557
|
+
|
|
1558
|
+
let!(:movie) do
|
|
1559
|
+
Movie.create!
|
|
1560
|
+
end
|
|
1561
|
+
|
|
1562
|
+
before do
|
|
1563
|
+
movie.ratings << Rating.new
|
|
1564
|
+
end
|
|
1565
|
+
|
|
1566
|
+
it "returns true" do
|
|
1567
|
+
expect(movie.ratings.any?).to be true
|
|
1568
|
+
end
|
|
1569
|
+
|
|
1570
|
+
context 'when association is not loaded' do
|
|
1571
|
+
before do
|
|
1572
|
+
movie.ratings._loaded?.should be false
|
|
1573
|
+
end
|
|
1574
|
+
|
|
1575
|
+
it 'does not query the database because it knows about the added models' do
|
|
1576
|
+
expect_no_queries do
|
|
1577
|
+
movie.ratings.any?.should be true
|
|
1578
|
+
end
|
|
1579
|
+
end
|
|
1580
|
+
end
|
|
1581
|
+
|
|
1582
|
+
context 'when association is loaded' do
|
|
1583
|
+
it 'does not query database' do
|
|
1584
|
+
expect_no_queries do
|
|
1585
|
+
movie.ratings.any?.should be true
|
|
1586
|
+
end
|
|
1587
|
+
|
|
1588
|
+
movie.ratings.to_a
|
|
1589
|
+
|
|
1590
|
+
expect_no_queries do
|
|
1591
|
+
movie.ratings.any?.should be true
|
|
1592
|
+
end
|
|
1593
|
+
end
|
|
1594
|
+
end
|
|
1595
|
+
end
|
|
1596
|
+
|
|
1597
|
+
context "when appending to a association in a transaction" do
|
|
1598
|
+
require_transaction_support
|
|
1599
|
+
|
|
1600
|
+
let!(:movie) do
|
|
1601
|
+
Movie.create!
|
|
1602
|
+
end
|
|
1603
|
+
|
|
1604
|
+
it "returns true" do
|
|
1605
|
+
movie.with_session do |session|
|
|
1606
|
+
session.with_transaction do
|
|
1607
|
+
expect{ movie.ratings << Rating.new }.to_not raise_error
|
|
1608
|
+
expect(movie.ratings.any?).to be true
|
|
1609
|
+
end
|
|
1610
|
+
end
|
|
1611
|
+
end
|
|
1612
|
+
end
|
|
1613
|
+
|
|
1614
|
+
context "when documents have been persisted" do
|
|
1615
|
+
|
|
1616
|
+
let!(:rating) do
|
|
1617
|
+
movie.ratings.create(value: 1)
|
|
1618
|
+
end
|
|
1619
|
+
|
|
1620
|
+
it "returns true" do
|
|
1621
|
+
expect(movie.ratings.any?).to be true
|
|
1622
|
+
end
|
|
1623
|
+
|
|
1624
|
+
let(:expected_result) { true }
|
|
1625
|
+
include_examples 'does not query database when association is loaded'
|
|
1626
|
+
end
|
|
1627
|
+
|
|
1628
|
+
context "when documents have not been persisted" do
|
|
1629
|
+
|
|
1630
|
+
let!(:rating) do
|
|
1631
|
+
movie.ratings.build(value: 1)
|
|
1632
|
+
end
|
|
1633
|
+
|
|
1634
|
+
it "returns false" do
|
|
1635
|
+
expect(movie.ratings.any?).to be true
|
|
1636
|
+
end
|
|
1637
|
+
end
|
|
1638
|
+
|
|
1639
|
+
context "when new documents exist in the database" do
|
|
1640
|
+
before do
|
|
1641
|
+
Rating.create(ratable: movie)
|
|
1642
|
+
end
|
|
1643
|
+
|
|
1644
|
+
it "returns true" do
|
|
1645
|
+
expect(movie.ratings.any?).to be true
|
|
1646
|
+
end
|
|
1647
|
+
end
|
|
1648
|
+
end
|
|
1649
|
+
|
|
1458
1650
|
describe "#create" do
|
|
1459
1651
|
|
|
1460
1652
|
context "when providing multiple attributes" do
|
|
@@ -1484,7 +1676,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1484
1676
|
end
|
|
1485
1677
|
end
|
|
1486
1678
|
|
|
1487
|
-
context "when the
|
|
1679
|
+
context "when the association is not polymorphic" do
|
|
1488
1680
|
|
|
1489
1681
|
context "when the parent is a new record" do
|
|
1490
1682
|
|
|
@@ -1550,11 +1742,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1550
1742
|
end
|
|
1551
1743
|
end
|
|
1552
1744
|
|
|
1553
|
-
it "sets the foreign key on the
|
|
1745
|
+
it "sets the foreign key on the association" do
|
|
1554
1746
|
expect(post.person_id).to eq(person.id)
|
|
1555
1747
|
end
|
|
1556
1748
|
|
|
1557
|
-
it "sets the base on the inverse
|
|
1749
|
+
it "sets the base on the inverse association" do
|
|
1558
1750
|
expect(post.person).to eq(person)
|
|
1559
1751
|
end
|
|
1560
1752
|
|
|
@@ -1603,7 +1795,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1603
1795
|
end
|
|
1604
1796
|
end
|
|
1605
1797
|
|
|
1606
|
-
context "when the
|
|
1798
|
+
context "when the association is polymorphic" do
|
|
1607
1799
|
|
|
1608
1800
|
context "when the parent is a new record" do
|
|
1609
1801
|
|
|
@@ -1630,11 +1822,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1630
1822
|
movie.ratings.create(value: 3)
|
|
1631
1823
|
end
|
|
1632
1824
|
|
|
1633
|
-
it "sets the foreign key on the
|
|
1825
|
+
it "sets the foreign key on the association" do
|
|
1634
1826
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1635
1827
|
end
|
|
1636
1828
|
|
|
1637
|
-
it "sets the base on the inverse
|
|
1829
|
+
it "sets the base on the inverse association" do
|
|
1638
1830
|
expect(rating.ratable).to eq(movie)
|
|
1639
1831
|
end
|
|
1640
1832
|
|
|
@@ -1697,7 +1889,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1697
1889
|
end
|
|
1698
1890
|
end
|
|
1699
1891
|
|
|
1700
|
-
context "when the
|
|
1892
|
+
context "when the association is not polymorphic" do
|
|
1701
1893
|
|
|
1702
1894
|
context "when the parent is a new record" do
|
|
1703
1895
|
|
|
@@ -1724,11 +1916,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1724
1916
|
person.posts.create!(title: "Testing")
|
|
1725
1917
|
end
|
|
1726
1918
|
|
|
1727
|
-
it "sets the foreign key on the
|
|
1919
|
+
it "sets the foreign key on the association" do
|
|
1728
1920
|
expect(post.person_id).to eq(person.id)
|
|
1729
1921
|
end
|
|
1730
1922
|
|
|
1731
|
-
it "sets the base on the inverse
|
|
1923
|
+
it "sets the base on the inverse association" do
|
|
1732
1924
|
expect(post.person).to eq(person)
|
|
1733
1925
|
end
|
|
1734
1926
|
|
|
@@ -1755,7 +1947,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1755
1947
|
end
|
|
1756
1948
|
end
|
|
1757
1949
|
|
|
1758
|
-
context "when the
|
|
1950
|
+
context "when the association is polymorphic" do
|
|
1759
1951
|
|
|
1760
1952
|
context "when the parent is a new record" do
|
|
1761
1953
|
|
|
@@ -1782,11 +1974,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1782
1974
|
movie.ratings.create!(value: 4)
|
|
1783
1975
|
end
|
|
1784
1976
|
|
|
1785
|
-
it "sets the foreign key on the
|
|
1977
|
+
it "sets the foreign key on the association" do
|
|
1786
1978
|
expect(rating.ratable_id).to eq(movie.id)
|
|
1787
1979
|
end
|
|
1788
1980
|
|
|
1789
|
-
it "sets the base on the inverse
|
|
1981
|
+
it "sets the base on the inverse association" do
|
|
1790
1982
|
expect(rating.ratable).to eq(movie)
|
|
1791
1983
|
end
|
|
1792
1984
|
|
|
@@ -1820,7 +2012,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1820
2012
|
Movie.new
|
|
1821
2013
|
end
|
|
1822
2014
|
|
|
1823
|
-
context "when the
|
|
2015
|
+
context "when the association is polymorphic" do
|
|
1824
2016
|
|
|
1825
2017
|
let(:association) do
|
|
1826
2018
|
Movie.relations["ratings"]
|
|
@@ -1840,7 +2032,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1840
2032
|
end
|
|
1841
2033
|
end
|
|
1842
2034
|
|
|
1843
|
-
context "when the
|
|
2035
|
+
context "when the association is not polymorphic" do
|
|
1844
2036
|
|
|
1845
2037
|
let(:association) do
|
|
1846
2038
|
Person.relations["posts"]
|
|
@@ -1911,7 +2103,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1911
2103
|
expect(drug.person_id).to be_nil
|
|
1912
2104
|
end
|
|
1913
2105
|
|
|
1914
|
-
it "removes the document from the
|
|
2106
|
+
it "removes the document from the association" do
|
|
1915
2107
|
expect(person.drugs).to_not include(drug)
|
|
1916
2108
|
end
|
|
1917
2109
|
end
|
|
@@ -1934,7 +2126,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1934
2126
|
expect(drug.person_id).to be_nil
|
|
1935
2127
|
end
|
|
1936
2128
|
|
|
1937
|
-
it "removes the document from the
|
|
2129
|
+
it "removes the document from the association" do
|
|
1938
2130
|
expect(person.drugs).to_not include(drug)
|
|
1939
2131
|
end
|
|
1940
2132
|
end
|
|
@@ -1960,7 +2152,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1960
2152
|
expect(post).to be_destroyed
|
|
1961
2153
|
end
|
|
1962
2154
|
|
|
1963
|
-
it "removes the document from the
|
|
2155
|
+
it "removes the document from the association" do
|
|
1964
2156
|
expect(person.posts).to_not include(post)
|
|
1965
2157
|
end
|
|
1966
2158
|
end
|
|
@@ -1983,7 +2175,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
1983
2175
|
expect(post).to be_destroyed
|
|
1984
2176
|
end
|
|
1985
2177
|
|
|
1986
|
-
it "removes the document from the
|
|
2178
|
+
it "removes the document from the association" do
|
|
1987
2179
|
expect(person.posts).to_not include(post)
|
|
1988
2180
|
end
|
|
1989
2181
|
end
|
|
@@ -2014,7 +2206,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2014
2206
|
|
|
2015
2207
|
describe "##{method}" do
|
|
2016
2208
|
|
|
2017
|
-
context "when the
|
|
2209
|
+
context "when the association is not polymorphic" do
|
|
2018
2210
|
|
|
2019
2211
|
context "when conditions are provided" do
|
|
2020
2212
|
|
|
@@ -2070,7 +2262,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2070
2262
|
end
|
|
2071
2263
|
end
|
|
2072
2264
|
|
|
2073
|
-
context "when the
|
|
2265
|
+
context "when the association is polymorphic" do
|
|
2074
2266
|
|
|
2075
2267
|
context "when conditions are provided" do
|
|
2076
2268
|
|
|
@@ -2149,9 +2341,35 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2149
2341
|
it "returns true" do
|
|
2150
2342
|
expect(person.posts.exists?).to be true
|
|
2151
2343
|
end
|
|
2344
|
+
|
|
2345
|
+
context 'when association is not loaded' do
|
|
2346
|
+
it 'queries database on each call' do
|
|
2347
|
+
expect_query(1) do
|
|
2348
|
+
person.posts.exists?.should be true
|
|
2349
|
+
end
|
|
2350
|
+
|
|
2351
|
+
expect_query(1) do
|
|
2352
|
+
person.posts.exists?.should be true
|
|
2353
|
+
end
|
|
2354
|
+
end
|
|
2355
|
+
end
|
|
2356
|
+
|
|
2357
|
+
context 'when association is loaded' do
|
|
2358
|
+
it 'queries database on each call' do
|
|
2359
|
+
expect_query(1) do
|
|
2360
|
+
person.posts.exists?.should be true
|
|
2361
|
+
end
|
|
2362
|
+
|
|
2363
|
+
person.posts.to_a
|
|
2364
|
+
|
|
2365
|
+
expect_query(1) do
|
|
2366
|
+
person.posts.exists?.should be true
|
|
2367
|
+
end
|
|
2368
|
+
end
|
|
2369
|
+
end
|
|
2152
2370
|
end
|
|
2153
2371
|
|
|
2154
|
-
context "when
|
|
2372
|
+
context "when documents exist in application but not in database" do
|
|
2155
2373
|
|
|
2156
2374
|
before do
|
|
2157
2375
|
person.posts.build
|
|
@@ -2160,6 +2378,65 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2160
2378
|
it "returns false" do
|
|
2161
2379
|
expect(person.posts.exists?).to be false
|
|
2162
2380
|
end
|
|
2381
|
+
|
|
2382
|
+
context 'when association is not loaded' do
|
|
2383
|
+
it 'queries database on each call' do
|
|
2384
|
+
expect_query(1) do
|
|
2385
|
+
person.posts.exists?.should be false
|
|
2386
|
+
end
|
|
2387
|
+
|
|
2388
|
+
expect_query(1) do
|
|
2389
|
+
person.posts.exists?.should be false
|
|
2390
|
+
end
|
|
2391
|
+
end
|
|
2392
|
+
end
|
|
2393
|
+
|
|
2394
|
+
context 'when association is loaded' do
|
|
2395
|
+
it 'queries database on each call' do
|
|
2396
|
+
expect_query(1) do
|
|
2397
|
+
person.posts.exists?.should be false
|
|
2398
|
+
end
|
|
2399
|
+
|
|
2400
|
+
person.posts.to_a
|
|
2401
|
+
|
|
2402
|
+
expect_query(1) do
|
|
2403
|
+
person.posts.exists?.should be false
|
|
2404
|
+
end
|
|
2405
|
+
end
|
|
2406
|
+
end
|
|
2407
|
+
end
|
|
2408
|
+
|
|
2409
|
+
context "when no documents exist" do
|
|
2410
|
+
|
|
2411
|
+
it "returns false" do
|
|
2412
|
+
expect(person.posts.exists?).to be false
|
|
2413
|
+
end
|
|
2414
|
+
|
|
2415
|
+
context 'when association is not loaded' do
|
|
2416
|
+
it 'queries database on each call' do
|
|
2417
|
+
expect_query(1) do
|
|
2418
|
+
person.posts.exists?.should be false
|
|
2419
|
+
end
|
|
2420
|
+
|
|
2421
|
+
expect_query(1) do
|
|
2422
|
+
person.posts.exists?.should be false
|
|
2423
|
+
end
|
|
2424
|
+
end
|
|
2425
|
+
end
|
|
2426
|
+
|
|
2427
|
+
context 'when association is loaded' do
|
|
2428
|
+
it 'queries database on each call' do
|
|
2429
|
+
expect_query(1) do
|
|
2430
|
+
person.posts.exists?.should be false
|
|
2431
|
+
end
|
|
2432
|
+
|
|
2433
|
+
person.posts.to_a
|
|
2434
|
+
|
|
2435
|
+
expect_query(1) do
|
|
2436
|
+
person.posts.exists?.should be false
|
|
2437
|
+
end
|
|
2438
|
+
end
|
|
2439
|
+
end
|
|
2163
2440
|
end
|
|
2164
2441
|
end
|
|
2165
2442
|
|
|
@@ -2186,7 +2463,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2186
2463
|
end
|
|
2187
2464
|
end
|
|
2188
2465
|
|
|
2189
|
-
context "when the
|
|
2466
|
+
context "when the association is not polymorphic" do
|
|
2190
2467
|
|
|
2191
2468
|
let(:person) do
|
|
2192
2469
|
Person.create
|
|
@@ -2197,7 +2474,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2197
2474
|
end
|
|
2198
2475
|
|
|
2199
2476
|
let!(:post_two) do
|
|
2200
|
-
person.posts.create(title: "OMG I has
|
|
2477
|
+
person.posts.create(title: "OMG I has associations")
|
|
2201
2478
|
end
|
|
2202
2479
|
|
|
2203
2480
|
context "when providing an id" do
|
|
@@ -2213,7 +2490,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2213
2490
|
end
|
|
2214
2491
|
end
|
|
2215
2492
|
|
|
2216
|
-
context "when the id matches but is not scoped to the
|
|
2493
|
+
context "when the id matches but is not scoped to the association" do
|
|
2217
2494
|
|
|
2218
2495
|
let(:post) do
|
|
2219
2496
|
Post.create(title: "Unscoped")
|
|
@@ -2312,7 +2589,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2312
2589
|
end
|
|
2313
2590
|
end
|
|
2314
2591
|
|
|
2315
|
-
context "when the
|
|
2592
|
+
context "when the association is polymorphic" do
|
|
2316
2593
|
|
|
2317
2594
|
let(:movie) do
|
|
2318
2595
|
Movie.create
|
|
@@ -2436,7 +2713,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2436
2713
|
|
|
2437
2714
|
describe "#find_or_create_by" do
|
|
2438
2715
|
|
|
2439
|
-
context "when the
|
|
2716
|
+
context "when the association is not polymorphic" do
|
|
2440
2717
|
|
|
2441
2718
|
let(:person) do
|
|
2442
2719
|
Person.create
|
|
@@ -2456,7 +2733,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2456
2733
|
expect(found).to eq(post)
|
|
2457
2734
|
end
|
|
2458
2735
|
|
|
2459
|
-
it "keeps the document in the
|
|
2736
|
+
it "keeps the document in the association" do
|
|
2460
2737
|
expect(found.person).to eq(person)
|
|
2461
2738
|
end
|
|
2462
2739
|
end
|
|
@@ -2483,7 +2760,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2483
2760
|
expect(found.content).to eq("The Content")
|
|
2484
2761
|
end
|
|
2485
2762
|
|
|
2486
|
-
it "keeps the document in the
|
|
2763
|
+
it "keeps the document in the association" do
|
|
2487
2764
|
expect(found.person).to eq(person)
|
|
2488
2765
|
end
|
|
2489
2766
|
end
|
|
@@ -2502,14 +2779,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2502
2779
|
expect(found).to be_persisted
|
|
2503
2780
|
end
|
|
2504
2781
|
|
|
2505
|
-
it "keeps the document in the
|
|
2782
|
+
it "keeps the document in the association" do
|
|
2506
2783
|
expect(found.person).to eq(person)
|
|
2507
2784
|
end
|
|
2508
2785
|
end
|
|
2509
2786
|
end
|
|
2510
2787
|
end
|
|
2511
2788
|
|
|
2512
|
-
context "when the
|
|
2789
|
+
context "when the association is polymorphic" do
|
|
2513
2790
|
|
|
2514
2791
|
let(:movie) do
|
|
2515
2792
|
Movie.create
|
|
@@ -2529,7 +2806,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2529
2806
|
expect(found).to eq(rating)
|
|
2530
2807
|
end
|
|
2531
2808
|
|
|
2532
|
-
it "keeps the document in the
|
|
2809
|
+
it "keeps the document in the association" do
|
|
2533
2810
|
expect(found.ratable).to eq(movie)
|
|
2534
2811
|
end
|
|
2535
2812
|
end
|
|
@@ -2548,7 +2825,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2548
2825
|
expect(found).to be_persisted
|
|
2549
2826
|
end
|
|
2550
2827
|
|
|
2551
|
-
it "keeps the document in the
|
|
2828
|
+
it "keeps the document in the association" do
|
|
2552
2829
|
expect(found.ratable).to eq(movie)
|
|
2553
2830
|
end
|
|
2554
2831
|
end
|
|
@@ -2557,7 +2834,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2557
2834
|
|
|
2558
2835
|
describe "#find_or_create_by!" do
|
|
2559
2836
|
|
|
2560
|
-
context "when the
|
|
2837
|
+
context "when the association is not polymorphic" do
|
|
2561
2838
|
|
|
2562
2839
|
let(:person) do
|
|
2563
2840
|
Person.create
|
|
@@ -2577,7 +2854,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2577
2854
|
expect(found).to eq(post)
|
|
2578
2855
|
end
|
|
2579
2856
|
|
|
2580
|
-
it "keeps the document in the
|
|
2857
|
+
it "keeps the document in the association" do
|
|
2581
2858
|
expect(found.person).to eq(person)
|
|
2582
2859
|
end
|
|
2583
2860
|
end
|
|
@@ -2604,7 +2881,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2604
2881
|
expect(found.content).to eq("The Content")
|
|
2605
2882
|
end
|
|
2606
2883
|
|
|
2607
|
-
it "keeps the document in the
|
|
2884
|
+
it "keeps the document in the association" do
|
|
2608
2885
|
expect(found.person).to eq(person)
|
|
2609
2886
|
end
|
|
2610
2887
|
end
|
|
@@ -2623,14 +2900,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2623
2900
|
expect(found).to be_persisted
|
|
2624
2901
|
end
|
|
2625
2902
|
|
|
2626
|
-
it "keeps the document in the
|
|
2903
|
+
it "keeps the document in the association" do
|
|
2627
2904
|
expect(found.person).to eq(person)
|
|
2628
2905
|
end
|
|
2629
2906
|
end
|
|
2630
2907
|
end
|
|
2631
2908
|
end
|
|
2632
2909
|
|
|
2633
|
-
context "when the
|
|
2910
|
+
context "when the association is polymorphic" do
|
|
2634
2911
|
|
|
2635
2912
|
let(:movie) do
|
|
2636
2913
|
Movie.create
|
|
@@ -2650,7 +2927,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2650
2927
|
expect(found).to eq(rating)
|
|
2651
2928
|
end
|
|
2652
2929
|
|
|
2653
|
-
it "keeps the document in the
|
|
2930
|
+
it "keeps the document in the association" do
|
|
2654
2931
|
expect(found.ratable).to eq(movie)
|
|
2655
2932
|
end
|
|
2656
2933
|
end
|
|
@@ -2669,7 +2946,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2669
2946
|
expect(found).to be_persisted
|
|
2670
2947
|
end
|
|
2671
2948
|
|
|
2672
|
-
it "keeps the document in the
|
|
2949
|
+
it "keeps the document in the association" do
|
|
2673
2950
|
expect(found.ratable).to eq(movie)
|
|
2674
2951
|
end
|
|
2675
2952
|
|
|
@@ -2687,7 +2964,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2687
2964
|
|
|
2688
2965
|
describe "#find_or_initialize_by" do
|
|
2689
2966
|
|
|
2690
|
-
context "when the
|
|
2967
|
+
context "when the association is not polymorphic" do
|
|
2691
2968
|
|
|
2692
2969
|
let(:person) do
|
|
2693
2970
|
Person.create
|
|
@@ -2730,7 +3007,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2730
3007
|
end
|
|
2731
3008
|
end
|
|
2732
3009
|
|
|
2733
|
-
context "when the
|
|
3010
|
+
context "when the association is polymorphic" do
|
|
2734
3011
|
|
|
2735
3012
|
let(:movie) do
|
|
2736
3013
|
Movie.create
|
|
@@ -2770,7 +3047,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2770
3047
|
|
|
2771
3048
|
describe "#initialize" do
|
|
2772
3049
|
|
|
2773
|
-
context "when an illegal mixed
|
|
3050
|
+
context "when an illegal mixed association exists" do
|
|
2774
3051
|
|
|
2775
3052
|
let(:post) do
|
|
2776
3053
|
Post.new
|
|
@@ -2783,7 +3060,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
2783
3060
|
end
|
|
2784
3061
|
end
|
|
2785
3062
|
|
|
2786
|
-
context "when a cyclic
|
|
3063
|
+
context "when a cyclic association exists" do
|
|
2787
3064
|
|
|
2788
3065
|
let(:post) do
|
|
2789
3066
|
Post.new
|
|
@@ -3050,7 +3327,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3050
3327
|
end
|
|
3051
3328
|
end
|
|
3052
3329
|
|
|
3053
|
-
context "when the
|
|
3330
|
+
context "when the association is not polymorphic" do
|
|
3054
3331
|
|
|
3055
3332
|
let(:person) do
|
|
3056
3333
|
Person.create
|
|
@@ -3084,19 +3361,19 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3084
3361
|
expect(post_one.reload.person).to be_nil
|
|
3085
3362
|
end
|
|
3086
3363
|
|
|
3087
|
-
context "when adding a nullified document back to the
|
|
3364
|
+
context "when adding a nullified document back to the association" do
|
|
3088
3365
|
|
|
3089
3366
|
before do
|
|
3090
3367
|
person.posts.push(post_one)
|
|
3091
3368
|
end
|
|
3092
3369
|
|
|
3093
|
-
it "persists the
|
|
3370
|
+
it "persists the association" do
|
|
3094
3371
|
expect(person.posts(true)).to eq([ post_one ])
|
|
3095
3372
|
end
|
|
3096
3373
|
end
|
|
3097
3374
|
end
|
|
3098
3375
|
|
|
3099
|
-
context "when the
|
|
3376
|
+
context "when the association is polymorphic" do
|
|
3100
3377
|
|
|
3101
3378
|
let(:movie) do
|
|
3102
3379
|
Movie.create(title: "Oldboy")
|
|
@@ -3179,7 +3456,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3179
3456
|
person.posts.scoped
|
|
3180
3457
|
end
|
|
3181
3458
|
|
|
3182
|
-
it "returns the
|
|
3459
|
+
it "returns the association criteria" do
|
|
3183
3460
|
expect(scoped).to be_a(Mongoid::Criteria)
|
|
3184
3461
|
end
|
|
3185
3462
|
|
|
@@ -3223,7 +3500,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3223
3500
|
|
|
3224
3501
|
describe "#unscoped" do
|
|
3225
3502
|
|
|
3226
|
-
context "when the
|
|
3503
|
+
context "when the association has no default scope" do
|
|
3227
3504
|
|
|
3228
3505
|
let!(:person) do
|
|
3229
3506
|
Person.create
|
|
@@ -3246,7 +3523,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3246
3523
|
end
|
|
3247
3524
|
end
|
|
3248
3525
|
|
|
3249
|
-
context "when the
|
|
3526
|
+
context "when the association has a default scope" do
|
|
3250
3527
|
|
|
3251
3528
|
let!(:church) do
|
|
3252
3529
|
Church.create
|
|
@@ -3310,7 +3587,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3310
3587
|
end
|
|
3311
3588
|
end
|
|
3312
3589
|
|
|
3313
|
-
context "when reloading the
|
|
3590
|
+
context "when reloading the association" do
|
|
3314
3591
|
|
|
3315
3592
|
let!(:person) do
|
|
3316
3593
|
Person.create
|
|
@@ -3328,7 +3605,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3328
3605
|
person.posts << post_one
|
|
3329
3606
|
end
|
|
3330
3607
|
|
|
3331
|
-
context "when the
|
|
3608
|
+
context "when the association references the same documents" do
|
|
3332
3609
|
|
|
3333
3610
|
before do
|
|
3334
3611
|
Post.collection.find({ _id: post_one.id }).
|
|
@@ -3344,7 +3621,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3344
3621
|
end
|
|
3345
3622
|
end
|
|
3346
3623
|
|
|
3347
|
-
context "when the
|
|
3624
|
+
context "when the association references different documents" do
|
|
3348
3625
|
|
|
3349
3626
|
before do
|
|
3350
3627
|
person.posts << post_two
|
|
@@ -3431,7 +3708,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3431
3708
|
expect(album.before_add_called).to be true
|
|
3432
3709
|
end
|
|
3433
3710
|
|
|
3434
|
-
it "adds the document to the
|
|
3711
|
+
it "adds the document to the association" do
|
|
3435
3712
|
expect(artist.albums).to eq([ album ])
|
|
3436
3713
|
end
|
|
3437
3714
|
end
|
|
@@ -3443,7 +3720,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3443
3720
|
begin; artist.albums << album; rescue; end
|
|
3444
3721
|
end
|
|
3445
3722
|
|
|
3446
|
-
it "does not add the document to the
|
|
3723
|
+
it "does not add the document to the association" do
|
|
3447
3724
|
expect(artist.albums).to be_empty
|
|
3448
3725
|
end
|
|
3449
3726
|
end
|
|
@@ -3471,12 +3748,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3471
3748
|
begin; artist.albums << album; rescue; end
|
|
3472
3749
|
end
|
|
3473
3750
|
|
|
3474
|
-
it "adds the document to the
|
|
3751
|
+
it "adds the document to the association" do
|
|
3475
3752
|
expect(artist.albums).to eq([ album ])
|
|
3476
3753
|
end
|
|
3477
3754
|
end
|
|
3478
3755
|
|
|
3479
|
-
context 'when the
|
|
3756
|
+
context 'when the association already exists' do
|
|
3480
3757
|
|
|
3481
3758
|
before do
|
|
3482
3759
|
artist.albums << album
|
|
@@ -3489,7 +3766,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3489
3766
|
Album.where(artist_id: artist.id).first
|
|
3490
3767
|
end
|
|
3491
3768
|
|
|
3492
|
-
it 'does not execute the callback when the
|
|
3769
|
+
it 'does not execute the callback when the association is accessed' do
|
|
3493
3770
|
expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
|
|
3494
3771
|
end
|
|
3495
3772
|
end
|
|
@@ -3521,7 +3798,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3521
3798
|
expect(artist.before_remove_referenced_called).to be true
|
|
3522
3799
|
end
|
|
3523
3800
|
|
|
3524
|
-
it "removes the document from the
|
|
3801
|
+
it "removes the document from the association" do
|
|
3525
3802
|
expect(artist.albums).to be_empty
|
|
3526
3803
|
end
|
|
3527
3804
|
end
|
|
@@ -3536,7 +3813,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3536
3813
|
expect(artist.before_remove_referenced_called).to be true
|
|
3537
3814
|
end
|
|
3538
3815
|
|
|
3539
|
-
it "clears the
|
|
3816
|
+
it "clears the association" do
|
|
3540
3817
|
expect(artist.albums).to be_empty
|
|
3541
3818
|
end
|
|
3542
3819
|
end
|
|
@@ -3553,7 +3830,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3553
3830
|
begin; artist.albums.delete(album); rescue; end
|
|
3554
3831
|
end
|
|
3555
3832
|
|
|
3556
|
-
it "does not remove the document from the
|
|
3833
|
+
it "does not remove the document from the association" do
|
|
3557
3834
|
expect(artist.albums).to eq([ album ])
|
|
3558
3835
|
end
|
|
3559
3836
|
end
|
|
@@ -3564,7 +3841,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3564
3841
|
begin; artist.albums.clear; rescue; end
|
|
3565
3842
|
end
|
|
3566
3843
|
|
|
3567
|
-
it "does not clear the
|
|
3844
|
+
it "does not clear the association" do
|
|
3568
3845
|
expect(artist.albums).to eq([ album ])
|
|
3569
3846
|
end
|
|
3570
3847
|
end
|
|
@@ -3624,7 +3901,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3624
3901
|
begin; artist.albums.delete(album); rescue; end
|
|
3625
3902
|
end
|
|
3626
3903
|
|
|
3627
|
-
it "removes the documents from the
|
|
3904
|
+
it "removes the documents from the association" do
|
|
3628
3905
|
expect(artist.albums).to be_empty
|
|
3629
3906
|
end
|
|
3630
3907
|
end
|
|
@@ -3635,14 +3912,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3635
3912
|
begin; artist.albums.clear; rescue; end
|
|
3636
3913
|
end
|
|
3637
3914
|
|
|
3638
|
-
it "removes the documents from the
|
|
3915
|
+
it "removes the documents from the association" do
|
|
3639
3916
|
expect(artist.albums).to be_empty
|
|
3640
3917
|
end
|
|
3641
3918
|
end
|
|
3642
3919
|
end
|
|
3643
3920
|
end
|
|
3644
3921
|
|
|
3645
|
-
context "when executing a criteria call on an ordered
|
|
3922
|
+
context "when executing a criteria call on an ordered association" do
|
|
3646
3923
|
|
|
3647
3924
|
let(:person) do
|
|
3648
3925
|
Person.create
|
|
@@ -3680,7 +3957,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3680
3957
|
end
|
|
3681
3958
|
end
|
|
3682
3959
|
|
|
3683
|
-
context "when accessing a
|
|
3960
|
+
context "when accessing a association named parent" do
|
|
3684
3961
|
|
|
3685
3962
|
let!(:parent) do
|
|
3686
3963
|
Odd.create(name: "odd parent")
|
|
@@ -3691,7 +3968,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3691
3968
|
end
|
|
3692
3969
|
|
|
3693
3970
|
it "updates the child after accessing the parent" do
|
|
3694
|
-
# Access parent
|
|
3971
|
+
# Access parent association on the child to make sure it is loaded
|
|
3695
3972
|
child.parent
|
|
3696
3973
|
|
|
3697
3974
|
new_child_name = "updated even child"
|
|
@@ -3704,7 +3981,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3704
3981
|
end
|
|
3705
3982
|
end
|
|
3706
3983
|
|
|
3707
|
-
context 'when a document has referenced and embedded
|
|
3984
|
+
context 'when a document has referenced and embedded associations' do
|
|
3708
3985
|
|
|
3709
3986
|
let(:agent) do
|
|
3710
3987
|
Agent.new
|
|
@@ -3728,7 +4005,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
|
3728
4005
|
end
|
|
3729
4006
|
end
|
|
3730
4007
|
|
|
3731
|
-
context 'when the two models use the same name to refer to the
|
|
4008
|
+
context 'when the two models use the same name to refer to the association' do
|
|
3732
4009
|
|
|
3733
4010
|
let(:agent) do
|
|
3734
4011
|
Agent.new
|