mongoid 7.0.10 → 7.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +30 -30
- data/README.md +32 -19
- data/Rakefile +51 -7
- data/lib/config/locales/en.yml +129 -70
- data/lib/mongoid/association/accessors.rb +143 -80
- data/lib/mongoid/association/bindable.rb +7 -26
- data/lib/mongoid/association/builders.rb +4 -12
- data/lib/mongoid/association/constrainable.rb +5 -6
- data/lib/mongoid/association/depending.rb +9 -18
- data/lib/mongoid/association/eager_loadable.rb +2 -3
- data/lib/mongoid/association/embedded/batchable.rb +16 -42
- data/lib/mongoid/association/embedded/cyclic.rb +10 -17
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +3 -7
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +7 -4
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +14 -24
- data/lib/mongoid/association/embedded/embedded_in.rb +6 -26
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +4 -8
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +8 -5
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +90 -93
- data/lib/mongoid/association/embedded/embeds_many.rb +6 -34
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +4 -8
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +9 -6
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +42 -27
- data/lib/mongoid/association/embedded/embeds_one.rb +6 -30
- data/lib/mongoid/association/embedded.rb +2 -0
- data/lib/mongoid/association/macros.rb +44 -41
- data/lib/mongoid/association/many.rb +16 -30
- data/lib/mongoid/association/marshalable.rb +3 -6
- data/lib/mongoid/association/nested/many.rb +18 -27
- data/lib/mongoid/association/nested/nested_buildable.rb +5 -11
- data/lib/mongoid/association/nested/one.rb +16 -27
- data/lib/mongoid/association/nested.rb +3 -3
- data/lib/mongoid/association/one.rb +4 -11
- data/lib/mongoid/association/options.rb +8 -38
- data/lib/mongoid/association/proxy.rb +37 -36
- data/lib/mongoid/association/referenced/auto_save.rb +5 -11
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +4 -9
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +11 -9
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +40 -3
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +16 -27
- data/lib/mongoid/association/referenced/belongs_to.rb +14 -36
- data/lib/mongoid/association/referenced/counter_cache.rb +4 -15
- data/lib/mongoid/association/referenced/eager.rb +39 -38
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +12 -11
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +5 -5
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +37 -57
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +23 -43
- data/lib/mongoid/association/referenced/has_many/binding.rb +3 -6
- data/lib/mongoid/association/referenced/has_many/buildable.rb +5 -5
- data/lib/mongoid/association/referenced/has_many/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +444 -456
- data/lib/mongoid/association/referenced/has_many/proxy.rb +74 -107
- data/lib/mongoid/association/referenced/has_many.rb +18 -42
- data/lib/mongoid/association/referenced/has_one/binding.rb +4 -9
- data/lib/mongoid/association/referenced/has_one/buildable.rb +20 -6
- data/lib/mongoid/association/referenced/has_one/eager.rb +2 -1
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +13 -26
- data/lib/mongoid/association/referenced/has_one/proxy.rb +23 -25
- data/lib/mongoid/association/referenced/has_one.rb +13 -33
- data/lib/mongoid/association/referenced/syncable.rb +7 -22
- data/lib/mongoid/association/referenced.rb +2 -0
- data/lib/mongoid/association/reflections.rb +7 -6
- data/lib/mongoid/association/relatable.rb +18 -74
- data/lib/mongoid/association.rb +8 -22
- data/lib/mongoid/atomic/modifiers.rb +27 -51
- data/lib/mongoid/atomic/paths/embedded/many.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded/one.rb +4 -7
- data/lib/mongoid/atomic/paths/embedded.rb +2 -3
- data/lib/mongoid/atomic/paths/root.rb +4 -7
- data/lib/mongoid/atomic/paths.rb +2 -1
- data/lib/mongoid/atomic.rb +29 -44
- data/lib/mongoid/attributes/dynamic.rb +3 -18
- data/lib/mongoid/attributes/nested.rb +7 -10
- data/lib/mongoid/attributes/processing.rb +9 -24
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +3 -6
- data/lib/mongoid/attributes.rb +46 -60
- data/lib/mongoid/cacheable.rb +6 -9
- data/lib/mongoid/changeable.rb +6 -60
- data/lib/mongoid/clients/factory.rb +42 -17
- data/lib/mongoid/clients/options.rb +10 -13
- data/lib/mongoid/clients/sessions.rb +2 -6
- data/lib/mongoid/clients/storage_options.rb +7 -12
- data/lib/mongoid/clients/validators/storage.rb +2 -9
- data/lib/mongoid/clients/validators.rb +2 -1
- data/lib/mongoid/clients.rb +3 -10
- data/lib/mongoid/composable.rb +5 -9
- data/lib/mongoid/config/environment.rb +15 -6
- data/lib/mongoid/config/options.rb +20 -23
- data/lib/mongoid/config/validators/client.rb +2 -17
- data/lib/mongoid/config/validators/option.rb +2 -3
- data/lib/mongoid/config/validators.rb +2 -1
- data/lib/mongoid/config.rb +112 -41
- data/lib/mongoid/contextual/aggregable/memory.rb +17 -12
- data/lib/mongoid/contextual/aggregable/mongo.rb +25 -26
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +29 -31
- data/lib/mongoid/contextual/command.rb +2 -5
- data/lib/mongoid/contextual/geo_near.rb +6 -37
- data/lib/mongoid/contextual/map_reduce.rb +5 -33
- data/lib/mongoid/contextual/memory.rb +8 -61
- data/lib/mongoid/contextual/mongo.rb +160 -82
- data/lib/mongoid/contextual/none.rb +44 -28
- data/lib/mongoid/contextual/queryable.rb +2 -3
- data/lib/mongoid/contextual.rb +7 -9
- data/lib/mongoid/copyable.rb +11 -10
- data/lib/mongoid/criteria/findable.rb +12 -15
- data/lib/mongoid/criteria/includable.rb +8 -15
- data/lib/mongoid/criteria/inspectable.rb +2 -3
- data/lib/mongoid/criteria/marshalable.rb +2 -5
- data/lib/mongoid/criteria/modifiable.rb +2 -19
- data/lib/mongoid/criteria/options.rb +2 -3
- data/lib/mongoid/criteria/permission.rb +2 -1
- data/lib/mongoid/criteria/queryable/aggregable.rb +2 -13
- data/lib/mongoid/criteria/queryable/expandable.rb +68 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +4 -27
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +3 -4
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +3 -4
- data/lib/mongoid/criteria/queryable/extensions/date.rb +3 -8
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +5 -11
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +3 -26
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +3 -14
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +3 -12
- data/lib/mongoid/criteria/queryable/extensions/object.rb +4 -29
- data/lib/mongoid/criteria/queryable/extensions/range.rb +41 -17
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +6 -13
- data/lib/mongoid/criteria/queryable/extensions/set.rb +3 -4
- data/lib/mongoid/criteria/queryable/extensions/string.rb +3 -18
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +3 -10
- data/lib/mongoid/criteria/queryable/extensions/time.rb +3 -8
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +3 -8
- data/lib/mongoid/criteria/queryable/extensions.rb +1 -4
- data/lib/mongoid/criteria/queryable/key.rb +36 -21
- data/lib/mongoid/criteria/queryable/macroable.rb +3 -4
- data/lib/mongoid/criteria/queryable/mergeable.rb +179 -40
- data/lib/mongoid/criteria/queryable/optional.rb +5 -48
- data/lib/mongoid/criteria/queryable/options.rb +2 -19
- data/lib/mongoid/criteria/queryable/pipeline.rb +5 -15
- data/lib/mongoid/criteria/queryable/selectable.rb +414 -162
- data/lib/mongoid/criteria/queryable/selector.rb +36 -24
- data/lib/mongoid/criteria/queryable/smash.rb +2 -11
- data/lib/mongoid/criteria/queryable/storable.rb +237 -0
- data/lib/mongoid/criteria/queryable.rb +7 -9
- data/lib/mongoid/criteria/scopable.rb +27 -19
- data/lib/mongoid/criteria.rb +79 -72
- data/lib/mongoid/document.rb +24 -73
- data/lib/mongoid/equality.rb +29 -12
- data/lib/mongoid/errors/ambiguous_relationship.rb +4 -5
- data/lib/mongoid/errors/callback.rb +2 -3
- data/lib/mongoid/errors/criteria_argument_required.rb +18 -0
- data/lib/mongoid/errors/delete_restriction.rb +10 -13
- data/lib/mongoid/errors/document_not_destroyed.rb +4 -7
- data/lib/mongoid/errors/document_not_found.rb +2 -9
- data/lib/mongoid/errors/eager_load.rb +6 -5
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +2 -3
- data/lib/mongoid/errors/invalid_collection.rb +2 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +2 -3
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +2 -3
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +2 -5
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +2 -3
- data/lib/mongoid/errors/invalid_find.rb +2 -3
- data/lib/mongoid/errors/invalid_includes.rb +2 -3
- data/lib/mongoid/errors/invalid_index.rb +2 -3
- data/lib/mongoid/errors/invalid_options.rb +4 -5
- data/lib/mongoid/errors/invalid_path.rb +2 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +2 -5
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +4 -9
- data/lib/mongoid/errors/invalid_relation_option.rb +4 -5
- data/lib/mongoid/errors/invalid_scope.rb +2 -3
- data/lib/mongoid/errors/invalid_session_use.rb +3 -6
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -5
- data/lib/mongoid/errors/invalid_storage_options.rb +2 -3
- data/lib/mongoid/errors/invalid_storage_parent.rb +2 -3
- data/lib/mongoid/errors/invalid_time.rb +2 -3
- data/lib/mongoid/errors/invalid_value.rb +2 -1
- data/lib/mongoid/errors/inverse_not_found.rb +3 -4
- data/lib/mongoid/errors/mixed_client_configuration.rb +2 -3
- data/lib/mongoid/errors/mixed_relations.rb +2 -3
- data/lib/mongoid/errors/mongoid_error.rb +3 -10
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -4
- data/lib/mongoid/errors/no_client_config.rb +4 -5
- data/lib/mongoid/errors/no_client_database.rb +2 -3
- data/lib/mongoid/errors/no_client_hosts.rb +2 -3
- data/lib/mongoid/errors/no_clients_config.rb +2 -3
- data/lib/mongoid/errors/no_default_client.rb +3 -4
- data/lib/mongoid/errors/no_environment.rb +2 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +2 -3
- data/lib/mongoid/errors/no_metadata.rb +2 -3
- data/lib/mongoid/errors/no_parent.rb +2 -3
- data/lib/mongoid/errors/readonly_attribute.rb +2 -3
- data/lib/mongoid/errors/readonly_document.rb +3 -6
- data/lib/mongoid/errors/scope_overwrite.rb +2 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +2 -0
- data/lib/mongoid/errors/unknown_attribute.rb +2 -3
- data/lib/mongoid/errors/unknown_model.rb +2 -3
- data/lib/mongoid/errors/unsaved_document.rb +3 -2
- data/lib/mongoid/errors/unsupported_javascript.rb +2 -3
- data/lib/mongoid/errors/validations.rb +2 -1
- data/lib/mongoid/errors.rb +12 -1
- data/lib/mongoid/evolvable.rb +4 -5
- data/lib/mongoid/extensions/array.rb +28 -37
- data/lib/mongoid/extensions/big_decimal.rb +2 -11
- data/lib/mongoid/extensions/boolean.rb +3 -5
- data/lib/mongoid/extensions/date.rb +13 -12
- data/lib/mongoid/extensions/date_time.rb +4 -12
- data/lib/mongoid/extensions/decimal128.rb +2 -5
- data/lib/mongoid/extensions/false_class.rb +4 -7
- data/lib/mongoid/extensions/float.rb +5 -10
- data/lib/mongoid/extensions/hash.rb +47 -34
- data/lib/mongoid/extensions/integer.rb +5 -12
- data/lib/mongoid/extensions/module.rb +2 -3
- data/lib/mongoid/extensions/nil_class.rb +2 -5
- data/lib/mongoid/extensions/object.rb +17 -44
- data/lib/mongoid/extensions/object_id.rb +2 -7
- data/lib/mongoid/extensions/range.rb +2 -11
- data/lib/mongoid/extensions/regexp.rb +2 -3
- data/lib/mongoid/extensions/set.rb +2 -7
- data/lib/mongoid/extensions/string.rb +19 -39
- data/lib/mongoid/extensions/symbol.rb +2 -7
- data/lib/mongoid/extensions/time.rb +12 -9
- data/lib/mongoid/extensions/time_with_zone.rb +25 -7
- data/lib/mongoid/extensions/true_class.rb +4 -7
- data/lib/mongoid/extensions.rb +18 -3
- data/lib/mongoid/factory.rb +52 -13
- data/lib/mongoid/fields/foreign_key.rb +3 -22
- data/lib/mongoid/fields/localized.rb +2 -11
- data/lib/mongoid/fields/standard.rb +6 -36
- data/lib/mongoid/fields/validators/macro.rb +36 -18
- data/lib/mongoid/fields/validators.rb +2 -1
- data/lib/mongoid/fields.rb +113 -63
- data/lib/mongoid/findable.rb +59 -23
- data/lib/mongoid/indexable/specification.rb +3 -16
- data/lib/mongoid/indexable/validators/options.rb +2 -7
- data/lib/mongoid/indexable.rb +6 -21
- data/lib/mongoid/inspectable.rb +4 -11
- data/lib/mongoid/interceptable.rb +13 -30
- data/lib/mongoid/loggable.rb +13 -16
- data/lib/mongoid/matchable.rb +2 -153
- data/lib/mongoid/matcher/all.rb +22 -0
- data/lib/mongoid/matcher/and.rb +21 -0
- data/lib/mongoid/matcher/bits.rb +41 -0
- data/lib/mongoid/matcher/bits_all_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_all_set.rb +20 -0
- data/lib/mongoid/matcher/bits_any_clear.rb +20 -0
- data/lib/mongoid/matcher/bits_any_set.rb +20 -0
- data/lib/mongoid/matcher/elem_match.rb +36 -0
- data/lib/mongoid/matcher/elem_match_expression.rb +20 -0
- data/lib/mongoid/matcher/eq.rb +11 -0
- data/lib/mongoid/matcher/eq_impl.rb +67 -0
- data/lib/mongoid/matcher/eq_impl_with_regexp.rb +26 -0
- data/lib/mongoid/matcher/exists.rb +15 -0
- data/lib/mongoid/matcher/expression.rb +35 -0
- data/lib/mongoid/matcher/expression_operator.rb +19 -0
- data/lib/mongoid/matcher/field_expression.rb +62 -0
- data/lib/mongoid/matcher/field_operator.rb +54 -0
- data/lib/mongoid/matcher/gt.rb +17 -0
- data/lib/mongoid/matcher/gte.rb +17 -0
- data/lib/mongoid/matcher/in.rb +25 -0
- data/lib/mongoid/matcher/lt.rb +17 -0
- data/lib/mongoid/matcher/lte.rb +17 -0
- data/lib/mongoid/matcher/mod.rb +17 -0
- data/lib/mongoid/matcher/ne.rb +16 -0
- data/lib/mongoid/matcher/nin.rb +11 -0
- data/lib/mongoid/matcher/nor.rb +25 -0
- data/lib/mongoid/matcher/not.rb +29 -0
- data/lib/mongoid/matcher/or.rb +21 -0
- data/lib/mongoid/matcher/regex.rb +41 -0
- data/lib/mongoid/matcher/size.rb +26 -0
- data/lib/mongoid/matcher/type.rb +99 -0
- data/lib/mongoid/matcher.rb +110 -0
- data/lib/mongoid/persistable/creatable.rb +4 -21
- data/lib/mongoid/persistable/deletable.rb +5 -21
- data/lib/mongoid/persistable/destroyable.rb +11 -10
- data/lib/mongoid/persistable/incrementable.rb +6 -7
- data/lib/mongoid/persistable/logical.rb +4 -6
- data/lib/mongoid/persistable/poppable.rb +3 -6
- data/lib/mongoid/persistable/pullable.rb +3 -8
- data/lib/mongoid/persistable/pushable.rb +3 -8
- data/lib/mongoid/persistable/renamable.rb +10 -8
- data/lib/mongoid/persistable/savable.rb +3 -8
- data/lib/mongoid/persistable/settable.rb +3 -6
- data/lib/mongoid/persistable/unsettable.rb +8 -8
- data/lib/mongoid/persistable/updatable.rb +32 -20
- data/lib/mongoid/persistable/upsertable.rb +3 -8
- data/lib/mongoid/persistable.rb +133 -38
- data/lib/mongoid/persistence_context.rb +23 -36
- data/lib/mongoid/positional.rb +2 -5
- data/lib/mongoid/query_cache.rb +118 -103
- data/lib/mongoid/railtie.rb +3 -16
- data/lib/mongoid/railties/controller_runtime.rb +3 -1
- data/lib/mongoid/railties/database.rake +9 -0
- data/lib/mongoid/reloadable.rb +14 -19
- data/lib/mongoid/scopable.rb +8 -35
- data/lib/mongoid/selectable.rb +8 -17
- data/lib/mongoid/serializable.rb +24 -29
- data/lib/mongoid/shardable.rb +80 -17
- data/lib/mongoid/stateful.rb +3 -10
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +12 -5
- data/lib/mongoid/tasks/database.rb +85 -5
- data/lib/mongoid/threaded/lifecycle.rb +2 -21
- data/lib/mongoid/threaded.rb +2 -55
- data/lib/mongoid/timestamps/created/short.rb +2 -1
- data/lib/mongoid/timestamps/created.rb +3 -2
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +6 -9
- data/lib/mongoid/timestamps/updated/short.rb +2 -1
- data/lib/mongoid/timestamps/updated.rb +3 -4
- data/lib/mongoid/timestamps.rb +3 -2
- data/lib/mongoid/touchable.rb +53 -23
- data/lib/mongoid/traversable.rb +177 -57
- data/lib/mongoid/validatable/associated.rb +5 -6
- data/lib/mongoid/validatable/format.rb +2 -1
- data/lib/mongoid/validatable/length.rb +2 -1
- data/lib/mongoid/validatable/localizable.rb +2 -3
- data/lib/mongoid/validatable/macros.rb +2 -7
- data/lib/mongoid/validatable/presence.rb +8 -13
- data/lib/mongoid/validatable/queryable.rb +2 -3
- data/lib/mongoid/validatable/uniqueness.rb +20 -33
- data/lib/mongoid/validatable.rb +8 -27
- data/lib/mongoid/version.rb +2 -2
- data/lib/mongoid.rb +32 -15
- data/lib/rails/generators/mongoid/config/config_generator.rb +10 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +45 -30
- data/lib/rails/generators/mongoid/model/model_generator.rb +3 -2
- data/lib/rails/generators/mongoid_generator.rb +2 -1
- data/lib/rails/mongoid.rb +4 -5
- data/spec/README.md +19 -4
- data/spec/config/mongoid.yml +1 -0
- data/spec/integration/app_spec.rb +246 -95
- data/spec/integration/associations/belongs_to_spec.rb +2 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +29 -0
- data/spec/integration/associations/embedded_spec.rb +207 -1
- data/spec/integration/associations/embeds_many_spec.rb +206 -0
- data/spec/integration/associations/embeds_one_spec.rb +23 -0
- data/spec/integration/associations/foreign_key_spec.rb +98 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +176 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
- data/spec/integration/associations/reverse_population_spec.rb +34 -0
- data/spec/integration/associations/reverse_population_spec_models.rb +36 -0
- data/spec/integration/associations/scope_option_spec.rb +101 -0
- data/spec/integration/atomic/modifiers_spec.rb +116 -0
- data/spec/integration/bson_regexp_raw_spec.rb +19 -0
- data/spec/integration/callbacks_models.rb +61 -0
- data/spec/integration/callbacks_spec.rb +228 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +1 -2
- data/spec/integration/criteria/default_scope_spec.rb +72 -0
- data/spec/integration/criteria/logical_spec.rb +124 -0
- data/spec/integration/criteria/range_spec.rb +265 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +125 -15
- data/spec/integration/discriminator_key_spec.rb +353 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +30 -1
- data/spec/integration/i18n_fallbacks_spec.rb +89 -0
- data/spec/integration/{matchable_spec.rb → matcher_examples_spec.rb} +120 -42
- 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 +124 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +22 -5
- data/spec/mongoid/association/accessors_spec.rb +284 -77
- data/spec/mongoid/association/auto_save_spec.rb +74 -33
- data/spec/mongoid/association/builders_spec.rb +3 -1
- data/spec/mongoid/association/constrainable_spec.rb +2 -0
- data/spec/mongoid/association/counter_cache_spec.rb +34 -32
- data/spec/mongoid/association/depending_spec.rb +426 -333
- data/spec/mongoid/association/eager_spec.rb +6 -4
- data/spec/mongoid/association/embedded/cyclic_spec.rb +4 -2
- data/spec/mongoid/association/embedded/dirty_spec.rb +4 -2
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +65 -13
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +3 -1
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +431 -133
- data/spec/mongoid/association/embedded/embeds_many_models.rb +17 -1
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +51 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +3 -1
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +23 -21
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +2 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +3 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +3 -1
- data/spec/mongoid/association/macros_spec.rb +11 -9
- data/spec/mongoid/association/nested/many_spec.rb +2 -0
- data/spec/mongoid/association/nested/one_spec.rb +18 -12
- data/spec/mongoid/association/options_spec.rb +2 -0
- data/spec/mongoid/association/polymorphic_spec.rb +2 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +2 -0
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +57 -16
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +242 -12
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +99 -58
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +24 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +3 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +28 -1
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +46 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +25 -5
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +215 -167
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +43 -2
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_query_spec.rb +39 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_spec.rb +46 -2
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +3 -1
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +23 -0
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +40 -9
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +306 -125
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +679 -339
- data/spec/mongoid/association/referenced/has_many_models.rb +58 -0
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +23 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +2 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +53 -7
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +34 -4
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +28 -26
- data/spec/mongoid/association/referenced/has_one_models.rb +49 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +24 -1
- data/spec/mongoid/association/reflections_spec.rb +2 -0
- data/spec/mongoid/association/syncable_spec.rb +33 -31
- data/spec/mongoid/association_spec.rb +2 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +49 -0
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +2 -0
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +2 -0
- data/spec/mongoid/atomic/paths/root_spec.rb +2 -0
- data/spec/mongoid/atomic/paths_spec.rb +107 -12
- data/spec/mongoid/atomic_spec.rb +31 -6
- data/spec/mongoid/attributes/dynamic_spec.rb +0 -1
- data/spec/mongoid/attributes/nested_spec.rb +69 -67
- 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 +44 -0
- data/spec/mongoid/attributes/readonly_spec.rb +24 -22
- data/spec/mongoid/attributes_spec.rb +363 -28
- data/spec/mongoid/cacheable_spec.rb +3 -1
- data/spec/mongoid/changeable_spec.rb +60 -35
- data/spec/mongoid/clients/factory_spec.rb +136 -28
- data/spec/mongoid/clients/options_spec.rb +44 -26
- data/spec/mongoid/clients/sessions_spec.rb +25 -28
- data/spec/mongoid/clients/transactions_spec.rb +54 -29
- data/spec/mongoid/clients_spec.rb +8 -6
- data/spec/mongoid/composable_spec.rb +2 -0
- data/spec/mongoid/config/environment_spec.rb +88 -8
- data/spec/mongoid/config/options_spec.rb +22 -3
- data/spec/mongoid/config_spec.rb +277 -1
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +53 -11
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +122 -20
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +222 -71
- data/spec/mongoid/contextual/geo_near_spec.rb +20 -18
- data/spec/mongoid/contextual/map_reduce_spec.rb +4 -2
- data/spec/mongoid/contextual/memory_spec.rb +25 -23
- data/spec/mongoid/contextual/mongo_spec.rb +413 -92
- data/spec/mongoid/contextual/none_spec.rb +9 -81
- data/spec/mongoid/copyable_spec.rb +207 -26
- data/spec/mongoid/copyable_spec_models.rb +30 -0
- data/spec/mongoid/criteria/findable_spec.rb +77 -20
- data/spec/mongoid/criteria/inspectable_spec.rb +2 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +2 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +43 -40
- data/spec/mongoid/criteria/options_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +61 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +35 -17
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +0 -1
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +239 -178
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +23 -16
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +145 -12
- data/spec/mongoid/criteria/queryable/optional_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/options_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +3 -1
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +1593 -286
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +1010 -2736
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +2 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +226 -0
- data/spec/mongoid/criteria/scopable_spec.rb +129 -0
- data/spec/mongoid/criteria_projection_spec.rb +410 -0
- data/spec/mongoid/criteria_spec.rb +782 -459
- data/spec/mongoid/document_fields_spec.rb +26 -1
- data/spec/mongoid/document_persistence_context_spec.rb +0 -1
- data/spec/mongoid/document_query_spec.rb +89 -0
- data/spec/mongoid/document_spec.rb +123 -48
- data/spec/mongoid/equality_spec.rb +144 -41
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +5 -3
- data/spec/mongoid/errors/callback_spec.rb +2 -0
- data/spec/mongoid/errors/delete_restriction_spec.rb +4 -2
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +2 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +2 -0
- data/spec/mongoid/errors/eager_load_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_collection_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_config_file_spec.rb +31 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_field_option_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_field_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_includes_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_index_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_options_spec.rb +4 -2
- data/spec/mongoid/errors/invalid_path_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_relation_spec.rb +4 -2
- data/spec/mongoid/errors/invalid_scope_spec.rb +3 -1
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +2 -0
- data/spec/mongoid/errors/invalid_time_spec.rb +2 -0
- data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -1
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +2 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +2 -0
- data/spec/mongoid/errors/mongoid_error_spec.rb +22 -8
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +5 -3
- data/spec/mongoid/errors/no_client_config_spec.rb +4 -2
- data/spec/mongoid/errors/no_client_database_spec.rb +5 -3
- data/spec/mongoid/errors/no_client_hosts_spec.rb +5 -3
- data/spec/mongoid/errors/no_clients_config_spec.rb +2 -0
- data/spec/mongoid/errors/no_environment_spec.rb +2 -0
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +2 -0
- data/spec/mongoid/errors/no_metadata_spec.rb +4 -2
- data/spec/mongoid/errors/no_parent_spec.rb +3 -1
- data/spec/mongoid/errors/readonly_attribute_spec.rb +2 -0
- data/spec/mongoid/errors/readonly_document_spec.rb +2 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +2 -0
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +2 -0
- data/spec/mongoid/errors/unknown_attribute_spec.rb +4 -2
- data/spec/mongoid/errors/unsaved_document_spec.rb +3 -1
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +2 -0
- data/spec/mongoid/errors/validations_spec.rb +2 -0
- data/spec/mongoid/extensions/array_spec.rb +25 -43
- data/spec/mongoid/extensions/big_decimal_spec.rb +2 -0
- data/spec/mongoid/extensions/binary_spec.rb +2 -0
- data/spec/mongoid/extensions/boolean_spec.rb +2 -0
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +335 -0
- data/spec/mongoid/extensions/date_spec.rb +8 -160
- data/spec/mongoid/extensions/date_time_spec.rb +17 -60
- data/spec/mongoid/extensions/decimal128_spec.rb +2 -0
- data/spec/mongoid/extensions/false_class_spec.rb +3 -1
- data/spec/mongoid/extensions/float_spec.rb +17 -3
- data/spec/mongoid/extensions/hash_spec.rb +105 -0
- data/spec/mongoid/extensions/integer_spec.rb +14 -2
- data/spec/mongoid/extensions/module_spec.rb +2 -0
- data/spec/mongoid/extensions/nil_class_spec.rb +2 -0
- data/spec/mongoid/extensions/object_id_spec.rb +2 -0
- data/spec/mongoid/extensions/object_spec.rb +13 -24
- data/spec/mongoid/extensions/range_spec.rb +2 -0
- data/spec/mongoid/extensions/regexp_spec.rb +2 -0
- data/spec/mongoid/extensions/set_spec.rb +2 -0
- data/spec/mongoid/extensions/string_spec.rb +60 -27
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +2 -0
- data/spec/mongoid/extensions/time_spec.rb +29 -0
- data/spec/mongoid/extensions/time_with_zone_spec.rb +33 -0
- data/spec/mongoid/extensions/true_class_spec.rb +3 -1
- data/spec/mongoid/extensions_spec.rb +16 -2
- data/spec/mongoid/factory_spec.rb +287 -27
- data/spec/mongoid/fields/foreign_key_spec.rb +2 -0
- data/spec/mongoid/fields/localized_spec.rb +6 -4
- data/spec/mongoid/fields/standard_spec.rb +2 -0
- data/spec/mongoid/fields_spec.rb +418 -36
- data/spec/mongoid/findable_spec.rb +53 -19
- data/spec/mongoid/indexable/specification_spec.rb +2 -0
- data/spec/mongoid/indexable_spec.rb +30 -2
- data/spec/mongoid/inspectable_spec.rb +39 -2
- data/spec/mongoid/interceptable_spec.rb +168 -96
- data/spec/mongoid/interceptable_spec_models.rb +76 -0
- data/spec/mongoid/loggable_spec.rb +2 -0
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +40 -0
- data/spec/mongoid/persistable/creatable_spec.rb +112 -27
- data/spec/mongoid/persistable/deletable_spec.rb +273 -11
- data/spec/mongoid/persistable/destroyable_spec.rb +201 -11
- data/spec/mongoid/persistable/incrementable_spec.rb +23 -7
- data/spec/mongoid/persistable/logical_spec.rb +19 -3
- data/spec/mongoid/persistable/poppable_spec.rb +19 -3
- data/spec/mongoid/persistable/pullable_spec.rb +36 -6
- data/spec/mongoid/persistable/pushable_spec.rb +36 -6
- data/spec/mongoid/persistable/renamable_spec.rb +18 -2
- data/spec/mongoid/persistable/savable_spec.rb +188 -25
- data/spec/mongoid/persistable/settable_spec.rb +54 -8
- data/spec/mongoid/persistable/unsettable_spec.rb +19 -3
- data/spec/mongoid/persistable/updatable_spec.rb +45 -23
- data/spec/mongoid/persistable/upsertable_spec.rb +4 -2
- data/spec/mongoid/persistable_spec.rb +85 -9
- data/spec/mongoid/persistence_context_spec.rb +2 -0
- data/spec/mongoid/positional_spec.rb +2 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +68 -0
- data/spec/mongoid/query_cache_spec.rb +501 -81
- data/spec/mongoid/relations/proxy_spec.rb +8 -6
- data/spec/mongoid/reloadable_spec.rb +298 -20
- data/spec/mongoid/scopable_spec.rb +67 -21
- data/spec/mongoid/selectable_spec.rb +8 -6
- data/spec/mongoid/serializable_spec.rb +160 -29
- data/spec/mongoid/shardable_models.rb +61 -0
- data/spec/mongoid/shardable_spec.rb +116 -17
- data/spec/mongoid/stateful_spec.rb +3 -1
- data/spec/mongoid/tasks/database_rake_spec.rb +2 -0
- data/spec/mongoid/tasks/database_spec.rb +2 -0
- data/spec/mongoid/threaded_spec.rb +4 -2
- data/spec/mongoid/timestamps/created/short_spec.rb +3 -1
- data/spec/mongoid/timestamps/created_spec.rb +3 -1
- data/spec/mongoid/timestamps/timeless_spec.rb +4 -2
- data/spec/mongoid/timestamps/updated/short_spec.rb +5 -3
- data/spec/mongoid/timestamps/updated_spec.rb +5 -3
- data/spec/mongoid/timestamps_spec.rb +8 -6
- data/spec/mongoid/touchable_spec.rb +180 -33
- data/spec/mongoid/touchable_spec_models.rb +53 -0
- data/spec/mongoid/traversable_spec.rb +1167 -1
- data/spec/mongoid/validatable/associated_spec.rb +2 -0
- data/spec/mongoid/validatable/format_spec.rb +2 -0
- data/spec/mongoid/validatable/length_spec.rb +2 -0
- data/spec/mongoid/validatable/numericality_spec.rb +2 -0
- data/spec/mongoid/validatable/presence_spec.rb +28 -22
- data/spec/mongoid/validatable/uniqueness_spec.rb +69 -67
- data/spec/mongoid/validatable_spec.rb +5 -3
- data/spec/mongoid_spec.rb +2 -0
- data/spec/rails/controller_extension/controller_runtime_spec.rb +3 -1
- data/spec/rails/mongoid_spec.rb +4 -2
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +386 -0
- data/spec/shared/lib/mrss/docker_runner.rb +271 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +199 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +120 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +15 -0
- data/spec/shared/share/Dockerfile.erb +339 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +379 -0
- data/spec/shared/shlib/set_env.sh +132 -0
- data/spec/spec_helper.rb +39 -35
- data/spec/support/authorization.rb +2 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +15 -234
- data/spec/support/expectations.rb +5 -1
- data/spec/support/helpers.rb +11 -0
- data/spec/support/macros.rb +22 -0
- data/spec/{app → support}/models/account.rb +3 -1
- data/spec/{app → support}/models/acolyte.rb +2 -0
- data/spec/{app → support}/models/actor.rb +3 -1
- data/spec/support/models/actress.rb +4 -0
- data/spec/{app → support}/models/address.rb +6 -0
- data/spec/{app → support}/models/address_component.rb +2 -0
- data/spec/{app → support}/models/address_number.rb +2 -0
- data/spec/{app → support}/models/agency.rb +2 -0
- data/spec/{app → support}/models/agent.rb +2 -0
- data/spec/{app → support}/models/album.rb +2 -0
- data/spec/{app → support}/models/alert.rb +2 -0
- data/spec/{app → support}/models/animal.rb +2 -0
- data/spec/{app → support}/models/answer.rb +2 -0
- data/spec/{app → support}/models/appointment.rb +2 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/{app → support}/models/article.rb +2 -0
- data/spec/{app → support}/models/artist.rb +4 -0
- data/spec/{app → support}/models/artwork.rb +2 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/{app → support}/models/audio.rb +2 -0
- data/spec/{app → support}/models/augmentation.rb +2 -0
- data/spec/{app → support}/models/author.rb +2 -0
- data/spec/{app → support}/models/baby.rb +2 -0
- data/spec/{app → support}/models/band.rb +6 -0
- data/spec/{app → support}/models/bar.rb +2 -0
- data/spec/{app → support}/models/basic.rb +2 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/{app → support}/models/big_palette.rb +2 -0
- data/spec/{app → support}/models/birthday.rb +2 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/{app → support}/models/bomb.rb +2 -0
- data/spec/{app → support}/models/book.rb +2 -0
- data/spec/{app → support}/models/breed.rb +2 -0
- data/spec/{app → support}/models/browser.rb +3 -1
- data/spec/{app → support}/models/building.rb +2 -0
- data/spec/{app → support}/models/building_address.rb +2 -0
- data/spec/{app → support}/models/bus.rb +2 -0
- data/spec/{app → support}/models/business.rb +2 -0
- data/spec/{app → support}/models/callback_test.rb +2 -0
- data/spec/{app → support}/models/canvas.rb +3 -1
- data/spec/support/models/car.rb +3 -0
- data/spec/{app → support}/models/cat.rb +2 -0
- data/spec/{app → support}/models/category.rb +2 -0
- data/spec/{app → support}/models/child.rb +2 -0
- data/spec/{app → support}/models/child_doc.rb +5 -3
- data/spec/{app → support}/models/church.rb +2 -0
- data/spec/{app → support}/models/circle.rb +2 -0
- data/spec/{app → support}/models/circuit.rb +2 -0
- data/spec/{app → support}/models/circus.rb +2 -0
- data/spec/{app → support}/models/code.rb +2 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/{app → support}/models/comment.rb +2 -0
- data/spec/{app → support}/models/company.rb +2 -0
- data/spec/{app → support}/models/consumption_period.rb +2 -0
- data/spec/{app → support}/models/contextable_item.rb +2 -0
- data/spec/{app → support}/models/contractor.rb +2 -0
- data/spec/{app → support}/models/cookie.rb +2 -0
- data/spec/{app → support}/models/country_code.rb +4 -0
- data/spec/{app → support}/models/courier_job.rb +2 -0
- data/spec/support/models/crate.rb +12 -0
- data/spec/support/models/customer.rb +10 -0
- data/spec/support/models/customer_address.rb +11 -0
- data/spec/support/models/deed.rb +7 -0
- data/spec/{app → support}/models/definition.rb +2 -0
- data/spec/{app → support}/models/delegating_patient.rb +0 -1
- data/spec/{app → support}/models/description.rb +2 -0
- data/spec/{app → support}/models/dictionary.rb +8 -0
- data/spec/{app → support}/models/division.rb +2 -0
- data/spec/{app → support}/models/doctor.rb +2 -0
- data/spec/{app → support}/models/dog.rb +2 -0
- data/spec/{app → support}/models/dokument.rb +2 -0
- data/spec/{app → support}/models/draft.rb +2 -0
- data/spec/{app → support}/models/dragon.rb +2 -0
- data/spec/{app → support}/models/driver.rb +3 -1
- data/spec/{app → support}/models/drug.rb +2 -0
- data/spec/{app → support}/models/dungeon.rb +2 -0
- data/spec/{app → support}/models/edit.rb +2 -0
- data/spec/{app → support}/models/email.rb +2 -0
- data/spec/{app → support}/models/employer.rb +2 -0
- data/spec/{app → support}/models/entry.rb +2 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/{app → support}/models/even.rb +2 -0
- data/spec/{app → support}/models/event.rb +2 -0
- data/spec/{app → support}/models/exhibition.rb +2 -0
- data/spec/{app → support}/models/exhibitor.rb +2 -0
- data/spec/{app → support}/models/explosion.rb +2 -0
- data/spec/{app → support}/models/eye.rb +2 -0
- data/spec/{app → support}/models/eye_bowl.rb +2 -0
- data/spec/{app → support}/models/face.rb +2 -0
- data/spec/{app → support}/models/favorite.rb +2 -0
- data/spec/{app → support}/models/filesystem.rb +2 -0
- data/spec/{app → support}/models/fire_hydrant.rb +2 -0
- data/spec/{app → support}/models/firefox.rb +2 -0
- data/spec/{app → support}/models/fish.rb +2 -0
- data/spec/{app → support}/models/folder.rb +2 -0
- data/spec/{app → support}/models/folder_item.rb +2 -0
- data/spec/{app → support}/models/fruits.rb +2 -0
- data/spec/{app → support}/models/game.rb +2 -0
- data/spec/{app → support}/models/ghost.rb +2 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/{app → support}/models/home.rb +2 -0
- data/spec/{app → support}/models/house.rb +2 -0
- data/spec/{app → support}/models/html_writer.rb +2 -0
- data/spec/{app → support}/models/id_key.rb +2 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/{app → support}/models/image.rb +2 -0
- data/spec/{app → support}/models/implant.rb +2 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/{app → support}/models/item.rb +3 -1
- data/spec/{app → support}/models/jar.rb +2 -0
- data/spec/{app → support}/models/kaleidoscope.rb +2 -0
- data/spec/{app → support}/models/kangaroo.rb +3 -1
- data/spec/{app → support}/models/label.rb +4 -1
- data/spec/{app → support}/models/language.rb +2 -0
- data/spec/{app → support}/models/lat_lng.rb +2 -0
- data/spec/{app → support}/models/league.rb +2 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/{app → support}/models/line_item.rb +2 -0
- data/spec/{app → support}/models/location.rb +2 -0
- data/spec/{app → support}/models/login.rb +2 -0
- data/spec/{app → support}/models/manufacturer.rb +2 -0
- data/spec/{app → support}/models/meat.rb +2 -0
- data/spec/{app → support}/models/membership.rb +2 -0
- data/spec/{app → support}/models/message.rb +2 -0
- data/spec/{app → support}/models/minim.rb +0 -1
- data/spec/{app → support}/models/mixed_drink.rb +2 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/{app → support}/models/movie.rb +2 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/{app → support}/models/name.rb +2 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/{app → support}/models/node.rb +2 -0
- data/spec/{app → support}/models/note.rb +2 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/{app → support}/models/odd.rb +2 -0
- data/spec/support/models/order.rb +12 -0
- data/spec/{app → support}/models/ordered_post.rb +3 -1
- data/spec/{app → support}/models/ordered_preference.rb +2 -0
- data/spec/{app → support}/models/oscar.rb +2 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/{app → support}/models/override.rb +2 -0
- data/spec/{app → support}/models/ownable.rb +2 -0
- data/spec/{app → support}/models/owner.rb +4 -0
- data/spec/{app → support}/models/pack.rb +2 -0
- data/spec/{app → support}/models/page.rb +2 -0
- data/spec/{app → support}/models/page_question.rb +2 -0
- data/spec/{app → support}/models/palette.rb +3 -1
- data/spec/{app → support}/models/parent.rb +2 -0
- data/spec/{app → support}/models/parent_doc.rb +2 -0
- data/spec/support/models/passport.rb +13 -0
- data/spec/{app → support}/models/patient.rb +2 -0
- data/spec/{app → support}/models/pdf_writer.rb +2 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/{app → support}/models/person.rb +21 -1
- data/spec/{app → support}/models/pet.rb +2 -0
- data/spec/{app → support}/models/pet_owner.rb +2 -0
- data/spec/{app → support}/models/phone.rb +5 -1
- data/spec/support/models/piano.rb +4 -0
- data/spec/{app → support}/models/pizza.rb +2 -0
- data/spec/{app → support}/models/player.rb +2 -0
- data/spec/{app → support}/models/post.rb +2 -0
- data/spec/{app → support}/models/post_genre.rb +2 -0
- data/spec/{app → support}/models/powerup.rb +2 -0
- data/spec/{app → support}/models/preference.rb +2 -0
- data/spec/{app → support}/models/princess.rb +2 -0
- data/spec/{app → support}/models/product.rb +2 -0
- data/spec/support/models/profile.rb +17 -0
- data/spec/{app → support}/models/pronunciation.rb +2 -0
- data/spec/{app → support}/models/pub.rb +2 -0
- data/spec/support/models/publication/encyclopedia.rb +11 -0
- data/spec/support/models/publication/review.rb +13 -0
- data/spec/support/models/publication.rb +4 -0
- data/spec/{app → support}/models/purchase.rb +2 -0
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/{app → support}/models/question.rb +2 -0
- data/spec/{app → support}/models/quiz.rb +2 -0
- data/spec/{app → support}/models/rating.rb +2 -0
- data/spec/{app → support}/models/record.rb +2 -0
- data/spec/{app → support}/models/registry.rb +2 -0
- data/spec/{app → support}/models/role.rb +2 -0
- data/spec/{app → support}/models/root_category.rb +2 -0
- data/spec/{app → support}/models/sandwich.rb +2 -0
- data/spec/{app → support}/models/scheduler.rb +2 -0
- data/spec/support/models/scribe.rb +7 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/{app → support}/models/seo.rb +2 -0
- data/spec/support/models/series.rb +7 -0
- data/spec/{app → support}/models/server.rb +2 -0
- data/spec/{app → support}/models/service.rb +2 -0
- data/spec/{app → support}/models/shape.rb +4 -2
- data/spec/{app → support}/models/shelf.rb +2 -0
- data/spec/{app → support}/models/shipment_address.rb +2 -0
- data/spec/{app → support}/models/shipping_container.rb +2 -0
- data/spec/{app → support}/models/shipping_pack.rb +2 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/{app → support}/models/shop.rb +2 -0
- data/spec/{app → support}/models/short_agent.rb +2 -0
- data/spec/{app → support}/models/short_quiz.rb +2 -0
- data/spec/{app → support}/models/simple.rb +2 -0
- data/spec/{app → support}/models/slave.rb +2 -0
- data/spec/{app → support}/models/song.rb +2 -0
- data/spec/{app → support}/models/sound.rb +2 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/{app → support}/models/square.rb +2 -0
- data/spec/{app → support}/models/staff.rb +2 -0
- data/spec/{app → support}/models/store_as_dup_test1.rb +2 -0
- data/spec/{app → support}/models/store_as_dup_test2.rb +2 -0
- data/spec/{app → support}/models/strategy.rb +2 -0
- data/spec/{app → support}/models/sub_item.rb +2 -0
- data/spec/{app → support}/models/subscription.rb +2 -0
- data/spec/{app → support}/models/survey.rb +2 -0
- data/spec/{app → support}/models/symptom.rb +2 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/{app → support}/models/tag.rb +2 -0
- data/spec/{app → support}/models/target.rb +2 -0
- data/spec/{app → support}/models/template.rb +2 -0
- data/spec/{app → support}/models/thing.rb +2 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/{app → support}/models/title.rb +2 -0
- data/spec/{app → support}/models/tool.rb +4 -2
- data/spec/{app → support}/models/topping.rb +2 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/{app → support}/models/track.rb +2 -0
- data/spec/{app → support}/models/translation.rb +2 -0
- data/spec/{app → support}/models/tree.rb +2 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/{app → support}/models/user.rb +2 -0
- data/spec/{app → support}/models/user_account.rb +2 -0
- data/spec/{app → support}/models/validation_callback.rb +2 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/{app → support}/models/version.rb +2 -0
- data/spec/{app → support}/models/vertex.rb +3 -1
- data/spec/{app → support}/models/vet_visit.rb +2 -0
- data/spec/{app → support}/models/video.rb +2 -0
- data/spec/support/models/video_game.rb +3 -0
- data/spec/support/models/washer.rb +7 -0
- data/spec/{app → support}/models/weapon.rb +2 -0
- data/spec/{app → support}/models/wiki_page.rb +3 -0
- data/spec/{app → support}/models/word.rb +2 -0
- data/spec/{app → support}/models/word_origin.rb +2 -0
- data/spec/{app → support}/models/writer.rb +4 -2
- data/spec/support/shared/time.rb +53 -0
- data/spec/support/spec_config.rb +16 -3
- data.tar.gz.sig +0 -0
- metadata +1100 -738
- metadata.gz.sig +0 -0
- 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/lib/support/ruby_version.rb +0 -26
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/other_owner_object.rb +0 -2
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/video_game.rb +0 -1
- data/spec/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
- /data/spec/{app → support}/models/array_field.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test3.rb +0 -0
- /data/spec/{app → support}/models/store_as_dup_test4.rb +0 -0
- /data/spec/{app → support}/models/updatable.rb +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "spec_helper"
|
2
4
|
|
3
5
|
describe Mongoid::Association::Referenced::HasMany::Proxy do
|
@@ -18,26 +20,26 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
18
20
|
|
19
21
|
describe "##{method}" do
|
20
22
|
|
21
|
-
context "when providing the base class in child
|
23
|
+
context "when providing the base class in child constructor" do
|
22
24
|
|
23
25
|
let(:person) do
|
24
|
-
Person.create
|
26
|
+
Person.create!
|
25
27
|
end
|
26
28
|
|
27
29
|
let!(:post) do
|
28
30
|
person.posts.send(method, Post.new(person: person))
|
29
31
|
end
|
30
32
|
|
31
|
-
it "only adds the
|
33
|
+
it "only adds the association once" do
|
32
34
|
expect(person.posts.size).to eq(1)
|
33
35
|
end
|
34
36
|
|
35
|
-
it "only persists the
|
37
|
+
it "only persists the association once" do
|
36
38
|
expect(person.reload.posts.size).to eq(1)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
context "when the
|
42
|
+
context "when the associations are not polymorphic" do
|
41
43
|
|
42
44
|
context "when the parent is a new record" do
|
43
45
|
|
@@ -55,15 +57,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
55
57
|
person.posts.send(method, post)
|
56
58
|
end
|
57
59
|
|
58
|
-
it "sets the foreign key on the
|
60
|
+
it "sets the foreign key on the association" do
|
59
61
|
expect(post.person_id).to eq(person.id)
|
60
62
|
end
|
61
63
|
|
62
|
-
it "sets the base on the inverse
|
64
|
+
it "sets the base on the inverse association" do
|
63
65
|
expect(post.person).to eq(person)
|
64
66
|
end
|
65
67
|
|
66
|
-
it "sets the same instance on the inverse
|
68
|
+
it "sets the same instance on the inverse association" do
|
67
69
|
expect(post.person).to eql(person)
|
68
70
|
end
|
69
71
|
|
@@ -75,7 +77,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
75
77
|
expect(person.posts.size).to eq(1)
|
76
78
|
end
|
77
79
|
|
78
|
-
it "returns the
|
80
|
+
it "returns the association" do
|
79
81
|
expect(added).to eq(person.posts)
|
80
82
|
end
|
81
83
|
end
|
@@ -83,22 +85,22 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
83
85
|
context "when the child is persisted" do
|
84
86
|
|
85
87
|
let(:post) do
|
86
|
-
Post.create
|
88
|
+
Post.create!
|
87
89
|
end
|
88
90
|
|
89
91
|
before do
|
90
92
|
person.posts.send(method, post)
|
91
93
|
end
|
92
94
|
|
93
|
-
it "sets the foreign key on the
|
95
|
+
it "sets the foreign key on the association" do
|
94
96
|
expect(post.person_id).to eq(person.id)
|
95
97
|
end
|
96
98
|
|
97
|
-
it "sets the base on the inverse
|
99
|
+
it "sets the base on the inverse association" do
|
98
100
|
expect(post.person).to eq(person)
|
99
101
|
end
|
100
102
|
|
101
|
-
it "sets the same instance on the inverse
|
103
|
+
it "sets the same instance on the inverse association" do
|
102
104
|
expect(post.person).to eql(person)
|
103
105
|
end
|
104
106
|
|
@@ -113,11 +115,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
113
115
|
context "when subsequently saving the parent" do
|
114
116
|
|
115
117
|
before do
|
116
|
-
person.save
|
117
|
-
post.save
|
118
|
+
person.save!
|
119
|
+
post.save!
|
118
120
|
end
|
119
121
|
|
120
|
-
it "returns the correct count of the
|
122
|
+
it "returns the correct count of the association" do
|
121
123
|
expect(person.posts.count).to eq(1)
|
122
124
|
end
|
123
125
|
end
|
@@ -127,20 +129,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
127
129
|
context "when appending in a parent create block" do
|
128
130
|
|
129
131
|
let!(:post) do
|
130
|
-
Post.create(title: "testing")
|
132
|
+
Post.create!(title: "testing")
|
131
133
|
end
|
132
134
|
|
133
135
|
let!(:person) do
|
134
|
-
Person.create do |doc|
|
136
|
+
Person.create! do |doc|
|
135
137
|
doc.posts << post
|
136
138
|
end
|
137
139
|
end
|
138
140
|
|
139
|
-
it "adds the documents to the
|
141
|
+
it "adds the documents to the association" do
|
140
142
|
expect(person.posts).to eq([ post ])
|
141
143
|
end
|
142
144
|
|
143
|
-
it "sets the foreign key on the inverse
|
145
|
+
it "sets the foreign key on the inverse association" do
|
144
146
|
expect(post.person_id).to eq(person.id)
|
145
147
|
end
|
146
148
|
|
@@ -160,7 +162,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
160
162
|
context "when the parent is not a new record" do
|
161
163
|
|
162
164
|
let(:person) do
|
163
|
-
Person.create
|
165
|
+
Person.create!
|
164
166
|
end
|
165
167
|
|
166
168
|
let(:post) do
|
@@ -171,15 +173,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
171
173
|
person.posts.send(method, post)
|
172
174
|
end
|
173
175
|
|
174
|
-
it "sets the foreign key on the
|
176
|
+
it "sets the foreign key on the association" do
|
175
177
|
expect(post.person_id).to eq(person.id)
|
176
178
|
end
|
177
179
|
|
178
|
-
it "sets the base on the inverse
|
180
|
+
it "sets the base on the inverse association" do
|
179
181
|
expect(post.person).to eq(person)
|
180
182
|
end
|
181
183
|
|
182
|
-
it "sets the same instance on the inverse
|
184
|
+
it "sets the same instance on the inverse association" do
|
183
185
|
expect(post.person).to eql(person)
|
184
186
|
end
|
185
187
|
|
@@ -200,16 +202,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
200
202
|
expect(person.changed).to eq([])
|
201
203
|
end
|
202
204
|
|
203
|
-
context "when the related item has embedded
|
205
|
+
context "when the related item has embedded associations" do
|
204
206
|
|
205
207
|
let!(:user) do
|
206
|
-
User.create
|
208
|
+
User.create!
|
207
209
|
end
|
208
210
|
|
209
211
|
before do
|
210
|
-
p = Post.create(roles: [ Role.create ])
|
212
|
+
p = Post.create!(roles: [ Role.create! ])
|
211
213
|
user.posts = [ p ]
|
212
|
-
user.save
|
214
|
+
user.save!
|
213
215
|
end
|
214
216
|
|
215
217
|
it "add the document to the target" do
|
@@ -229,7 +231,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
229
231
|
end
|
230
232
|
end
|
231
233
|
|
232
|
-
context "when documents already exist on the
|
234
|
+
context "when documents already exist on the association" do
|
233
235
|
|
234
236
|
let(:post_two) do
|
235
237
|
Post.new(title: "Test")
|
@@ -239,15 +241,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
239
241
|
person.posts.send(method, post_two)
|
240
242
|
end
|
241
243
|
|
242
|
-
it "sets the foreign key on the
|
244
|
+
it "sets the foreign key on the association" do
|
243
245
|
expect(post_two.person_id).to eq(person.id)
|
244
246
|
end
|
245
247
|
|
246
|
-
it "sets the base on the inverse
|
248
|
+
it "sets the base on the inverse association" do
|
247
249
|
expect(post_two.person).to eq(person)
|
248
250
|
end
|
249
251
|
|
250
|
-
it "sets the same instance on the inverse
|
252
|
+
it "sets the same instance on the inverse association" do
|
251
253
|
expect(post_two.person).to eql(person)
|
252
254
|
end
|
253
255
|
|
@@ -274,10 +276,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
274
276
|
end
|
275
277
|
end
|
276
278
|
|
277
|
-
context "when.adding to the
|
279
|
+
context "when.adding to the association" do
|
278
280
|
|
279
281
|
let(:person) do
|
280
|
-
Person.create
|
282
|
+
Person.create!
|
281
283
|
end
|
282
284
|
|
283
285
|
context "when the operation succeeds" do
|
@@ -290,7 +292,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
290
292
|
person.posts.send(method, post)
|
291
293
|
end
|
292
294
|
|
293
|
-
it "adds the document to the
|
295
|
+
it "adds the document to the association" do
|
294
296
|
expect(person.posts).to eq([ post ])
|
295
297
|
end
|
296
298
|
end
|
@@ -298,7 +300,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
298
300
|
context "when the operation fails" do
|
299
301
|
|
300
302
|
let!(:existing) do
|
301
|
-
Post.create
|
303
|
+
Post.create!
|
302
304
|
end
|
303
305
|
|
304
306
|
let(:post) do
|
@@ -315,7 +317,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
315
317
|
end
|
316
318
|
end
|
317
319
|
|
318
|
-
context "when the
|
320
|
+
context "when the associations are polymorphic" do
|
319
321
|
|
320
322
|
context "when the parent is a new record" do
|
321
323
|
|
@@ -331,11 +333,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
331
333
|
movie.ratings.send(method, rating)
|
332
334
|
end
|
333
335
|
|
334
|
-
it "sets the foreign key on the
|
336
|
+
it "sets the foreign key on the association" do
|
335
337
|
expect(rating.ratable_id).to eq(movie.id)
|
336
338
|
end
|
337
339
|
|
338
|
-
it "sets the base on the inverse
|
340
|
+
it "sets the base on the inverse association" do
|
339
341
|
expect(rating.ratable).to eq(movie)
|
340
342
|
end
|
341
343
|
|
@@ -351,7 +353,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
351
353
|
context "when the parent is not a new record" do
|
352
354
|
|
353
355
|
let(:movie) do
|
354
|
-
Movie.create
|
356
|
+
Movie.create!
|
355
357
|
end
|
356
358
|
|
357
359
|
let(:rating) do
|
@@ -362,11 +364,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
362
364
|
movie.ratings.send(method, rating)
|
363
365
|
end
|
364
366
|
|
365
|
-
it "sets the foreign key on the
|
367
|
+
it "sets the foreign key on the association" do
|
366
368
|
expect(rating.ratable_id).to eq(movie.id)
|
367
369
|
end
|
368
370
|
|
369
|
-
it "sets the base on the inverse
|
371
|
+
it "sets the base on the inverse association" do
|
370
372
|
expect(rating.ratable).to eq(movie)
|
371
373
|
end
|
372
374
|
|
@@ -384,7 +386,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
384
386
|
|
385
387
|
describe "#=" do
|
386
388
|
|
387
|
-
context "when the
|
389
|
+
context "when the association is not polymorphic" do
|
388
390
|
|
389
391
|
context "when the parent is a new record" do
|
390
392
|
|
@@ -400,15 +402,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
400
402
|
person.posts = [ post ]
|
401
403
|
end
|
402
404
|
|
403
|
-
it "sets the target of the
|
405
|
+
it "sets the target of the association" do
|
404
406
|
expect(person.posts._target).to eq([ post ])
|
405
407
|
end
|
406
408
|
|
407
|
-
it "sets the foreign key on the
|
409
|
+
it "sets the foreign key on the association" do
|
408
410
|
expect(post.person_id).to eq(person.id)
|
409
411
|
end
|
410
412
|
|
411
|
-
it "sets the base on the inverse
|
413
|
+
it "sets the base on the inverse association" do
|
412
414
|
expect(post.person).to eq(person)
|
413
415
|
end
|
414
416
|
|
@@ -420,7 +422,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
420
422
|
context "when the parent is not a new record" do
|
421
423
|
|
422
424
|
let(:person) do
|
423
|
-
Person.create
|
425
|
+
Person.create!
|
424
426
|
end
|
425
427
|
|
426
428
|
let(:post) do
|
@@ -431,15 +433,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
431
433
|
person.posts = [ post ]
|
432
434
|
end
|
433
435
|
|
434
|
-
it "sets the target of the
|
436
|
+
it "sets the target of the association" do
|
435
437
|
expect(person.posts._target).to eq([ post ])
|
436
438
|
end
|
437
439
|
|
438
|
-
it "sets the foreign key of the
|
440
|
+
it "sets the foreign key of the association" do
|
439
441
|
expect(post.person_id).to eq(person.id)
|
440
442
|
end
|
441
443
|
|
442
|
-
it "sets the base on the inverse
|
444
|
+
it "sets the base on the inverse association" do
|
443
445
|
expect(post.person).to eq(person)
|
444
446
|
end
|
445
447
|
|
@@ -447,7 +449,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
447
449
|
expect(post).to be_persisted
|
448
450
|
end
|
449
451
|
|
450
|
-
context "when replacing the
|
452
|
+
context "when replacing the association with the same documents" do
|
451
453
|
|
452
454
|
context "when using the same in memory instance" do
|
453
455
|
|
@@ -455,11 +457,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
455
457
|
person.posts = [ post ]
|
456
458
|
end
|
457
459
|
|
458
|
-
it "keeps the
|
460
|
+
it "keeps the association intact" do
|
459
461
|
expect(person.posts).to eq([ post ])
|
460
462
|
end
|
461
463
|
|
462
|
-
it "does not delete the
|
464
|
+
it "does not delete the association" do
|
463
465
|
expect(person.reload.posts).to eq([ post ])
|
464
466
|
end
|
465
467
|
end
|
@@ -474,11 +476,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
474
476
|
from_db.posts = [ post ]
|
475
477
|
end
|
476
478
|
|
477
|
-
it "keeps the
|
479
|
+
it "keeps the association intact" do
|
478
480
|
expect(from_db.posts).to eq([ post ])
|
479
481
|
end
|
480
482
|
|
481
|
-
it "does not delete the
|
483
|
+
it "does not delete the association" do
|
482
484
|
expect(from_db.reload.posts).to eq([ post ])
|
483
485
|
end
|
484
486
|
end
|
@@ -487,7 +489,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
487
489
|
context "when replacing the with a combination of old and new docs" do
|
488
490
|
|
489
491
|
let(:new_post) do
|
490
|
-
Post.create(title: "new post")
|
492
|
+
Post.create!(title: "new post")
|
491
493
|
end
|
492
494
|
|
493
495
|
context "when using the same in memory instance" do
|
@@ -496,7 +498,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
496
498
|
person.posts = [ post, new_post ]
|
497
499
|
end
|
498
500
|
|
499
|
-
it "keeps the
|
501
|
+
it "keeps the association intact" do
|
500
502
|
expect(person.posts.size).to eq(2)
|
501
503
|
end
|
502
504
|
|
@@ -508,7 +510,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
508
510
|
expect(person.posts).to include(new_post)
|
509
511
|
end
|
510
512
|
|
511
|
-
it "does not delete the
|
513
|
+
it "does not delete the association" do
|
512
514
|
expect(person.reload.posts).to eq([ post, new_post ])
|
513
515
|
end
|
514
516
|
end
|
@@ -523,11 +525,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
523
525
|
from_db.posts = [ post, new_post ]
|
524
526
|
end
|
525
527
|
|
526
|
-
it "keeps the
|
528
|
+
it "keeps the association intact" do
|
527
529
|
expect(from_db.posts).to eq([ post, new_post ])
|
528
530
|
end
|
529
531
|
|
530
|
-
it "does not delete the
|
532
|
+
it "does not delete the association" do
|
531
533
|
expect(from_db.reload.posts).to eq([ post, new_post ])
|
532
534
|
end
|
533
535
|
end
|
@@ -536,7 +538,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
536
538
|
context "when replacing the with a combination of only new docs" do
|
537
539
|
|
538
540
|
let(:new_post) do
|
539
|
-
Post.create(title: "new post")
|
541
|
+
Post.create!(title: "new post")
|
540
542
|
end
|
541
543
|
|
542
544
|
context "when using the same in memory instance" do
|
@@ -545,11 +547,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
545
547
|
person.posts = [ new_post ]
|
546
548
|
end
|
547
549
|
|
548
|
-
it "keeps the
|
550
|
+
it "keeps the association intact" do
|
549
551
|
expect(person.posts).to eq([ new_post ])
|
550
552
|
end
|
551
553
|
|
552
|
-
it "does not delete the
|
554
|
+
it "does not delete the association" do
|
553
555
|
expect(person.reload.posts).to eq([ new_post ])
|
554
556
|
end
|
555
557
|
end
|
@@ -564,11 +566,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
564
566
|
from_db.posts = [ new_post ]
|
565
567
|
end
|
566
568
|
|
567
|
-
it "keeps the
|
569
|
+
it "keeps the association intact" do
|
568
570
|
expect(from_db.posts).to eq([ new_post ])
|
569
571
|
end
|
570
572
|
|
571
|
-
it "does not delete the
|
573
|
+
it "does not delete the association" do
|
572
574
|
expect(from_db.reload.posts).to eq([ new_post ])
|
573
575
|
end
|
574
576
|
end
|
@@ -576,7 +578,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
576
578
|
end
|
577
579
|
end
|
578
580
|
|
579
|
-
context "when the
|
581
|
+
context "when the association is polymorphic" do
|
580
582
|
|
581
583
|
context "when the parent is a new record" do
|
582
584
|
|
@@ -592,15 +594,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
592
594
|
movie.ratings = [ rating ]
|
593
595
|
end
|
594
596
|
|
595
|
-
it "sets the target of the
|
597
|
+
it "sets the target of the association" do
|
596
598
|
expect(movie.ratings._target).to eq([ rating ])
|
597
599
|
end
|
598
600
|
|
599
|
-
it "sets the foreign key on the
|
601
|
+
it "sets the foreign key on the association" do
|
600
602
|
expect(rating.ratable_id).to eq(movie.id)
|
601
603
|
end
|
602
604
|
|
603
|
-
it "sets the base on the inverse
|
605
|
+
it "sets the base on the inverse association" do
|
604
606
|
expect(rating.ratable).to eq(movie)
|
605
607
|
end
|
606
608
|
|
@@ -612,7 +614,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
612
614
|
context "when the parent is not a new record" do
|
613
615
|
|
614
616
|
let(:movie) do
|
615
|
-
Movie.create
|
617
|
+
Movie.create!
|
616
618
|
end
|
617
619
|
|
618
620
|
let(:rating) do
|
@@ -623,15 +625,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
623
625
|
movie.ratings = [ rating ]
|
624
626
|
end
|
625
627
|
|
626
|
-
it "sets the target of the
|
628
|
+
it "sets the target of the association" do
|
627
629
|
expect(movie.ratings._target).to eq([ rating ])
|
628
630
|
end
|
629
631
|
|
630
|
-
it "sets the foreign key of the
|
632
|
+
it "sets the foreign key of the association" do
|
631
633
|
expect(rating.ratable_id).to eq(movie.id)
|
632
634
|
end
|
633
635
|
|
634
|
-
it "sets the base on the inverse
|
636
|
+
it "sets the base on the inverse association" do
|
635
637
|
expect(rating.ratable).to eq(movie)
|
636
638
|
end
|
637
639
|
|
@@ -647,11 +649,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
647
649
|
context "when the parent is persisted" do
|
648
650
|
|
649
651
|
let(:posts) do
|
650
|
-
[ Post.create(title: "1"), Post.create(title: "2") ]
|
652
|
+
[ Post.create!(title: "1"), Post.create!(title: "2") ]
|
651
653
|
end
|
652
654
|
|
653
655
|
let(:person) do
|
654
|
-
Person.create(posts: posts)
|
656
|
+
Person.create!(posts: posts)
|
655
657
|
end
|
656
658
|
|
657
659
|
context "when the parent has multiple children" do
|
@@ -673,7 +675,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
673
675
|
|
674
676
|
describe "#= nil" do
|
675
677
|
|
676
|
-
context "when the
|
678
|
+
context "when the association is not polymorphic" do
|
677
679
|
|
678
680
|
context "when the parent is a new record" do
|
679
681
|
|
@@ -690,11 +692,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
690
692
|
person.posts = nil
|
691
693
|
end
|
692
694
|
|
693
|
-
it "sets the
|
695
|
+
it "sets the association to an empty array" do
|
694
696
|
expect(person.posts).to be_empty
|
695
697
|
end
|
696
698
|
|
697
|
-
it "removed the inverse
|
699
|
+
it "removed the inverse association" do
|
698
700
|
expect(post.person).to be_nil
|
699
701
|
end
|
700
702
|
|
@@ -706,7 +708,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
706
708
|
context "when the parent is not a new record" do
|
707
709
|
|
708
710
|
let(:person) do
|
709
|
-
Person.create
|
711
|
+
Person.create!
|
710
712
|
end
|
711
713
|
|
712
714
|
context "when dependent is destructive" do
|
@@ -720,11 +722,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
720
722
|
person.posts = nil
|
721
723
|
end
|
722
724
|
|
723
|
-
it "sets the
|
725
|
+
it "sets the association to empty" do
|
724
726
|
expect(person.posts).to be_empty
|
725
727
|
end
|
726
728
|
|
727
|
-
it "removed the inverse
|
729
|
+
it "removed the inverse association" do
|
728
730
|
expect(post.person).to be_nil
|
729
731
|
end
|
730
732
|
|
@@ -748,11 +750,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
748
750
|
person.drugs = nil
|
749
751
|
end
|
750
752
|
|
751
|
-
it "sets the
|
753
|
+
it "sets the association to empty" do
|
752
754
|
expect(person.drugs).to be_empty
|
753
755
|
end
|
754
756
|
|
755
|
-
it "removed the inverse
|
757
|
+
it "removed the inverse association" do
|
756
758
|
expect(drug.person).to be_nil
|
757
759
|
end
|
758
760
|
|
@@ -760,14 +762,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
760
762
|
expect(drug.person_id).to be_nil
|
761
763
|
end
|
762
764
|
|
763
|
-
it "nullifies the
|
765
|
+
it "nullifies the association" do
|
764
766
|
expect(drug).to_not be_destroyed
|
765
767
|
end
|
766
768
|
end
|
767
769
|
end
|
768
770
|
end
|
769
771
|
|
770
|
-
context "when the
|
772
|
+
context "when the association is polymorphic" do
|
771
773
|
|
772
774
|
context "when the parent is a new record" do
|
773
775
|
|
@@ -784,11 +786,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
784
786
|
movie.ratings = nil
|
785
787
|
end
|
786
788
|
|
787
|
-
it "sets the
|
789
|
+
it "sets the association to an empty array" do
|
788
790
|
expect(movie.ratings).to be_empty
|
789
791
|
end
|
790
792
|
|
791
|
-
it "removed the inverse
|
793
|
+
it "removed the inverse association" do
|
792
794
|
expect(rating.ratable).to be_nil
|
793
795
|
end
|
794
796
|
|
@@ -800,7 +802,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
800
802
|
context "when the parent is not a new record" do
|
801
803
|
|
802
804
|
let(:movie) do
|
803
|
-
Movie.create
|
805
|
+
Movie.create!
|
804
806
|
end
|
805
807
|
|
806
808
|
let(:rating) do
|
@@ -812,11 +814,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
812
814
|
movie.ratings = nil
|
813
815
|
end
|
814
816
|
|
815
|
-
it "sets the
|
817
|
+
it "sets the association to empty" do
|
816
818
|
expect(movie.ratings).to be_empty
|
817
819
|
end
|
818
820
|
|
819
|
-
it "removed the inverse
|
821
|
+
it "removed the inverse association" do
|
820
822
|
expect(rating.ratable).to be_nil
|
821
823
|
end
|
822
824
|
|
@@ -841,11 +843,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
841
843
|
end
|
842
844
|
|
843
845
|
let(:post_one) do
|
844
|
-
Post.create
|
846
|
+
Post.create!
|
845
847
|
end
|
846
848
|
|
847
849
|
let(:post_two) do
|
848
|
-
Post.create
|
850
|
+
Post.create!
|
849
851
|
end
|
850
852
|
|
851
853
|
before do
|
@@ -860,14 +862,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
860
862
|
describe "#\{name}_ids" do
|
861
863
|
|
862
864
|
let(:posts) do
|
863
|
-
[ Post.create
|
865
|
+
[ Post.create!, Post.create! ]
|
864
866
|
end
|
865
867
|
|
866
868
|
let(:person) do
|
867
|
-
Person.create(posts: posts)
|
869
|
+
Person.create!(posts: posts)
|
868
870
|
end
|
869
871
|
|
870
|
-
it "returns ids of documents that are in the
|
872
|
+
it "returns ids of documents that are in the association" do
|
871
873
|
expect(person.post_ids).to eq(posts.map(&:id))
|
872
874
|
end
|
873
875
|
end
|
@@ -876,7 +878,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
876
878
|
|
877
879
|
describe "##{method}" do
|
878
880
|
|
879
|
-
context "when the
|
881
|
+
context "when the association is not polymorphic" do
|
880
882
|
|
881
883
|
context "when the parent is a new record" do
|
882
884
|
|
@@ -888,11 +890,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
888
890
|
person.posts.send(method, title: "$$$")
|
889
891
|
end
|
890
892
|
|
891
|
-
it "sets the foreign key on the
|
893
|
+
it "sets the foreign key on the association" do
|
892
894
|
expect(post.person_id).to eq(person.id)
|
893
895
|
end
|
894
896
|
|
895
|
-
it "sets the base on the inverse
|
897
|
+
it "sets the base on the inverse association" do
|
896
898
|
expect(post.person).to eq(person)
|
897
899
|
end
|
898
900
|
|
@@ -920,18 +922,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
920
922
|
context "when the parent is not a new record" do
|
921
923
|
|
922
924
|
let(:person) do
|
923
|
-
Person.create
|
925
|
+
Person.create!
|
924
926
|
end
|
925
927
|
|
926
928
|
let!(:post) do
|
927
929
|
person.posts.send(method, text: "Testing")
|
928
930
|
end
|
929
931
|
|
930
|
-
it "sets the foreign key on the
|
932
|
+
it "sets the foreign key on the association" do
|
931
933
|
expect(post.person_id).to eq(person.id)
|
932
934
|
end
|
933
935
|
|
934
|
-
it "sets the base on the inverse
|
936
|
+
it "sets the base on the inverse association" do
|
935
937
|
expect(post.person).to eq(person)
|
936
938
|
end
|
937
939
|
|
@@ -949,12 +951,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
949
951
|
end
|
950
952
|
end
|
951
953
|
|
952
|
-
context "when the
|
954
|
+
context "when the association is polymorphic" do
|
953
955
|
|
954
956
|
context "when the parent is a subclass" do
|
955
957
|
|
956
958
|
let(:video_game) do
|
957
|
-
VideoGame.create
|
959
|
+
VideoGame.create!
|
958
960
|
end
|
959
961
|
|
960
962
|
let(:rating) do
|
@@ -980,11 +982,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
980
982
|
movie.ratings.send(method, value: 3)
|
981
983
|
end
|
982
984
|
|
983
|
-
it "sets the foreign key on the
|
985
|
+
it "sets the foreign key on the association" do
|
984
986
|
expect(rating.ratable_id).to eq(movie.id)
|
985
987
|
end
|
986
988
|
|
987
|
-
it "sets the base on the inverse
|
989
|
+
it "sets the base on the inverse association" do
|
988
990
|
expect(rating.ratable).to eq(movie)
|
989
991
|
end
|
990
992
|
|
@@ -1008,18 +1010,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1008
1010
|
context "when the parent is not a new record" do
|
1009
1011
|
|
1010
1012
|
let(:movie) do
|
1011
|
-
Movie.create
|
1013
|
+
Movie.create!
|
1012
1014
|
end
|
1013
1015
|
|
1014
1016
|
let!(:rating) do
|
1015
1017
|
movie.ratings.send(method, value: 4)
|
1016
1018
|
end
|
1017
1019
|
|
1018
|
-
it "sets the foreign key on the
|
1020
|
+
it "sets the foreign key on the association" do
|
1019
1021
|
expect(rating.ratable_id).to eq(movie.id)
|
1020
1022
|
end
|
1021
1023
|
|
1022
|
-
it "sets the base on the inverse
|
1024
|
+
it "sets the base on the inverse association" do
|
1023
1025
|
expect(rating.ratable).to eq(movie)
|
1024
1026
|
end
|
1025
1027
|
|
@@ -1041,25 +1043,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1041
1043
|
|
1042
1044
|
describe "#clear" do
|
1043
1045
|
|
1044
|
-
context "when the
|
1046
|
+
context "when the association is not polymorphic" do
|
1045
1047
|
|
1046
1048
|
context "when the parent has been persisted" do
|
1047
1049
|
|
1048
1050
|
let!(:person) do
|
1049
|
-
Person.create
|
1051
|
+
Person.create!
|
1050
1052
|
end
|
1051
1053
|
|
1052
1054
|
context "when the children are persisted" do
|
1053
1055
|
|
1054
1056
|
let!(:post) do
|
1055
|
-
person.posts.create(title: "Testing")
|
1057
|
+
person.posts.create!(title: "Testing")
|
1056
1058
|
end
|
1057
1059
|
|
1058
|
-
let!(:
|
1060
|
+
let!(:association) do
|
1059
1061
|
person.posts.clear
|
1060
1062
|
end
|
1061
1063
|
|
1062
|
-
it "clears out the
|
1064
|
+
it "clears out the association" do
|
1063
1065
|
expect(person.posts).to be_empty
|
1064
1066
|
end
|
1065
1067
|
|
@@ -1071,8 +1073,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1071
1073
|
expect(person.reload.posts).to be_empty
|
1072
1074
|
end
|
1073
1075
|
|
1074
|
-
it "returns the
|
1075
|
-
expect(
|
1076
|
+
it "returns the association" do
|
1077
|
+
expect(association).to be_empty
|
1076
1078
|
end
|
1077
1079
|
end
|
1078
1080
|
|
@@ -1082,11 +1084,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1082
1084
|
person.posts.build(title: "Testing")
|
1083
1085
|
end
|
1084
1086
|
|
1085
|
-
let!(:
|
1087
|
+
let!(:association) do
|
1086
1088
|
person.posts.clear
|
1087
1089
|
end
|
1088
1090
|
|
1089
|
-
it "clears out the
|
1091
|
+
it "clears out the association" do
|
1090
1092
|
expect(person.posts).to be_empty
|
1091
1093
|
end
|
1092
1094
|
end
|
@@ -1102,35 +1104,35 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1102
1104
|
person.posts.build(title: "Testing")
|
1103
1105
|
end
|
1104
1106
|
|
1105
|
-
let!(:
|
1107
|
+
let!(:association) do
|
1106
1108
|
person.posts.clear
|
1107
1109
|
end
|
1108
1110
|
|
1109
|
-
it "clears out the
|
1111
|
+
it "clears out the association" do
|
1110
1112
|
expect(person.posts).to be_empty
|
1111
1113
|
end
|
1112
1114
|
end
|
1113
1115
|
end
|
1114
1116
|
|
1115
|
-
context "when the
|
1117
|
+
context "when the association is polymorphic" do
|
1116
1118
|
|
1117
1119
|
context "when the parent has been persisted" do
|
1118
1120
|
|
1119
1121
|
let!(:movie) do
|
1120
|
-
Movie.create
|
1122
|
+
Movie.create!
|
1121
1123
|
end
|
1122
1124
|
|
1123
1125
|
context "when the children are persisted" do
|
1124
1126
|
|
1125
1127
|
let!(:rating) do
|
1126
|
-
movie.ratings.create(value: 1)
|
1128
|
+
movie.ratings.create!(value: 1)
|
1127
1129
|
end
|
1128
1130
|
|
1129
|
-
let!(:
|
1131
|
+
let!(:association) do
|
1130
1132
|
movie.ratings.clear
|
1131
1133
|
end
|
1132
1134
|
|
1133
|
-
it "clears out the
|
1135
|
+
it "clears out the association" do
|
1134
1136
|
expect(movie.ratings).to be_empty
|
1135
1137
|
end
|
1136
1138
|
|
@@ -1142,8 +1144,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1142
1144
|
expect(movie.reload.ratings).to be_empty
|
1143
1145
|
end
|
1144
1146
|
|
1145
|
-
it "returns the
|
1146
|
-
expect(
|
1147
|
+
it "returns the association" do
|
1148
|
+
expect(association).to be_empty
|
1147
1149
|
end
|
1148
1150
|
end
|
1149
1151
|
|
@@ -1153,11 +1155,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1153
1155
|
movie.ratings.build(value: 3)
|
1154
1156
|
end
|
1155
1157
|
|
1156
|
-
let!(:
|
1158
|
+
let!(:association) do
|
1157
1159
|
movie.ratings.clear
|
1158
1160
|
end
|
1159
1161
|
|
1160
|
-
it "clears out the
|
1162
|
+
it "clears out the association" do
|
1161
1163
|
expect(movie.ratings).to be_empty
|
1162
1164
|
end
|
1163
1165
|
end
|
@@ -1173,11 +1175,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1173
1175
|
movie.ratings.build(value: 2)
|
1174
1176
|
end
|
1175
1177
|
|
1176
|
-
let!(:
|
1178
|
+
let!(:association) do
|
1177
1179
|
movie.ratings.clear
|
1178
1180
|
end
|
1179
1181
|
|
1180
|
-
it "clears out the
|
1182
|
+
it "clears out the association" do
|
1181
1183
|
expect(movie.ratings).to be_empty
|
1182
1184
|
end
|
1183
1185
|
end
|
@@ -1186,7 +1188,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1186
1188
|
|
1187
1189
|
describe "#concat" do
|
1188
1190
|
|
1189
|
-
context "when the
|
1191
|
+
context "when the associations are not polymorphic" do
|
1190
1192
|
|
1191
1193
|
context "when the parent is a new record" do
|
1192
1194
|
|
@@ -1202,15 +1204,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1202
1204
|
person.posts.concat([ post ])
|
1203
1205
|
end
|
1204
1206
|
|
1205
|
-
it "sets the foreign key on the
|
1207
|
+
it "sets the foreign key on the association" do
|
1206
1208
|
expect(post.person_id).to eq(person.id)
|
1207
1209
|
end
|
1208
1210
|
|
1209
|
-
it "sets the base on the inverse
|
1211
|
+
it "sets the base on the inverse association" do
|
1210
1212
|
expect(post.person).to eq(person)
|
1211
1213
|
end
|
1212
1214
|
|
1213
|
-
it "sets the same instance on the inverse
|
1215
|
+
it "sets the same instance on the inverse association" do
|
1214
1216
|
expect(post.person).to eql(person)
|
1215
1217
|
end
|
1216
1218
|
|
@@ -1226,20 +1228,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1226
1228
|
context "when appending in a parent create block" do
|
1227
1229
|
|
1228
1230
|
let!(:post) do
|
1229
|
-
Post.create(title: "testing")
|
1231
|
+
Post.create!(title: "testing")
|
1230
1232
|
end
|
1231
1233
|
|
1232
1234
|
let!(:person) do
|
1233
|
-
Person.create do |doc|
|
1235
|
+
Person.create! do |doc|
|
1234
1236
|
doc.posts.concat([ post ])
|
1235
1237
|
end
|
1236
1238
|
end
|
1237
1239
|
|
1238
|
-
it "adds the documents to the
|
1240
|
+
it "adds the documents to the association" do
|
1239
1241
|
expect(person.posts).to eq([ post ])
|
1240
1242
|
end
|
1241
1243
|
|
1242
|
-
it "sets the foreign key on the inverse
|
1244
|
+
it "sets the foreign key on the inverse association" do
|
1243
1245
|
expect(post.person_id).to eq(person.id)
|
1244
1246
|
end
|
1245
1247
|
|
@@ -1259,7 +1261,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1259
1261
|
context "when the parent is not a new record" do
|
1260
1262
|
|
1261
1263
|
let(:person) do
|
1262
|
-
Person.create
|
1264
|
+
Person.create!
|
1263
1265
|
end
|
1264
1266
|
|
1265
1267
|
let(:post) do
|
@@ -1274,15 +1276,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1274
1276
|
person.posts.concat([ post, post_three ])
|
1275
1277
|
end
|
1276
1278
|
|
1277
|
-
it "sets the foreign key on the
|
1279
|
+
it "sets the foreign key on the association" do
|
1278
1280
|
expect(post.person_id).to eq(person.id)
|
1279
1281
|
end
|
1280
1282
|
|
1281
|
-
it "sets the base on the inverse
|
1283
|
+
it "sets the base on the inverse association" do
|
1282
1284
|
expect(post.person).to eq(person)
|
1283
1285
|
end
|
1284
1286
|
|
1285
|
-
it "sets the same instance on the inverse
|
1287
|
+
it "sets the same instance on the inverse association" do
|
1286
1288
|
expect(post.person).to eql(person)
|
1287
1289
|
end
|
1288
1290
|
|
@@ -1294,7 +1296,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1294
1296
|
expect(person.posts.count).to eq(2)
|
1295
1297
|
end
|
1296
1298
|
|
1297
|
-
context "when documents already exist on the
|
1299
|
+
context "when documents already exist on the association" do
|
1298
1300
|
|
1299
1301
|
let(:post_two) do
|
1300
1302
|
Post.new(title: "Test")
|
@@ -1304,15 +1306,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1304
1306
|
person.posts.concat([ post_two ])
|
1305
1307
|
end
|
1306
1308
|
|
1307
|
-
it "sets the foreign key on the
|
1309
|
+
it "sets the foreign key on the association" do
|
1308
1310
|
expect(post_two.person_id).to eq(person.id)
|
1309
1311
|
end
|
1310
1312
|
|
1311
|
-
it "sets the base on the inverse
|
1313
|
+
it "sets the base on the inverse association" do
|
1312
1314
|
expect(post_two.person).to eq(person)
|
1313
1315
|
end
|
1314
1316
|
|
1315
|
-
it "sets the same instance on the inverse
|
1317
|
+
it "sets the same instance on the inverse association" do
|
1316
1318
|
expect(post_two.person).to eql(person)
|
1317
1319
|
end
|
1318
1320
|
|
@@ -1336,7 +1338,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1336
1338
|
end
|
1337
1339
|
end
|
1338
1340
|
|
1339
|
-
context "when the
|
1341
|
+
context "when the associations are polymorphic" do
|
1340
1342
|
|
1341
1343
|
context "when the parent is a new record" do
|
1342
1344
|
|
@@ -1352,11 +1354,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1352
1354
|
movie.ratings.concat([ rating ])
|
1353
1355
|
end
|
1354
1356
|
|
1355
|
-
it "sets the foreign key on the
|
1357
|
+
it "sets the foreign key on the association" do
|
1356
1358
|
expect(rating.ratable_id).to eq(movie.id)
|
1357
1359
|
end
|
1358
1360
|
|
1359
|
-
it "sets the base on the inverse
|
1361
|
+
it "sets the base on the inverse association" do
|
1360
1362
|
expect(rating.ratable).to eq(movie)
|
1361
1363
|
end
|
1362
1364
|
|
@@ -1372,7 +1374,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1372
1374
|
context "when the parent is not a new record" do
|
1373
1375
|
|
1374
1376
|
let(:movie) do
|
1375
|
-
Movie.create
|
1377
|
+
Movie.create!
|
1376
1378
|
end
|
1377
1379
|
|
1378
1380
|
let(:rating) do
|
@@ -1383,11 +1385,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1383
1385
|
movie.ratings.concat([ rating ])
|
1384
1386
|
end
|
1385
1387
|
|
1386
|
-
it "sets the foreign key on the
|
1388
|
+
it "sets the foreign key on the association" do
|
1387
1389
|
expect(rating.ratable_id).to eq(movie.id)
|
1388
1390
|
end
|
1389
1391
|
|
1390
|
-
it "sets the base on the inverse
|
1392
|
+
it "sets the base on the inverse association" do
|
1391
1393
|
expect(rating.ratable).to eq(movie)
|
1392
1394
|
end
|
1393
1395
|
|
@@ -1404,18 +1406,23 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1404
1406
|
describe "#count" do
|
1405
1407
|
|
1406
1408
|
let(:movie) do
|
1407
|
-
Movie.create
|
1409
|
+
Movie.create!
|
1408
1410
|
end
|
1409
1411
|
|
1410
1412
|
context "when documents have been persisted" do
|
1411
1413
|
|
1412
1414
|
let!(:rating) do
|
1413
|
-
movie.ratings.create(value: 1)
|
1415
|
+
movie.ratings.create!(value: 1)
|
1414
1416
|
end
|
1415
1417
|
|
1416
1418
|
it "returns the number of persisted documents" do
|
1417
1419
|
expect(movie.ratings.count).to eq(1)
|
1418
1420
|
end
|
1421
|
+
|
1422
|
+
it "block form includes persisted results" do
|
1423
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
1424
|
+
expect(movie.ratings.count {|r| r.value >= 2 }).to eq(0)
|
1425
|
+
end
|
1419
1426
|
end
|
1420
1427
|
|
1421
1428
|
context "when documents have not been persisted" do
|
@@ -1427,14 +1434,42 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1427
1434
|
it "returns 0" do
|
1428
1435
|
expect(movie.ratings.count).to eq(0)
|
1429
1436
|
end
|
1437
|
+
|
1438
|
+
it "block form does not include unpersisted results" do
|
1439
|
+
expect(movie.ratings.count {|r| r.value == 1 }).to eq(0)
|
1440
|
+
end
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
context "when mixed persisted and unpersisted documents" do
|
1444
|
+
|
1445
|
+
before do
|
1446
|
+
movie.ratings.create(value: 1)
|
1447
|
+
movie.ratings.build(value: 2)
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
it "returns 1" do
|
1451
|
+
expect(movie.ratings.count).to eq(1)
|
1452
|
+
end
|
1453
|
+
|
1454
|
+
it "block form includes only persisted results" do
|
1455
|
+
expect(movie.ratings.count {|r| r.value >= 1 }).to eq(1)
|
1456
|
+
expect(movie.ratings.count {|r| r.value == 2 }).to eq(0)
|
1457
|
+
end
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
context "when no document is added" do
|
1461
|
+
|
1462
|
+
it "returns false" do
|
1463
|
+
expect(movie.ratings.any?).to be false
|
1464
|
+
end
|
1430
1465
|
end
|
1431
1466
|
|
1432
1467
|
context "when new documents exist in the database" do
|
1433
1468
|
|
1434
|
-
context "when the documents are part of the
|
1469
|
+
context "when the documents are part of the association" do
|
1435
1470
|
|
1436
1471
|
before do
|
1437
|
-
Rating.create(ratable: movie)
|
1472
|
+
Rating.create!(ratable: movie)
|
1438
1473
|
end
|
1439
1474
|
|
1440
1475
|
it "returns the count from the db" do
|
@@ -1442,10 +1477,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1442
1477
|
end
|
1443
1478
|
end
|
1444
1479
|
|
1445
|
-
context "when the documents are not part of the
|
1480
|
+
context "when the documents are not part of the association" do
|
1446
1481
|
|
1447
1482
|
before do
|
1448
|
-
Rating.create
|
1483
|
+
Rating.create!
|
1449
1484
|
end
|
1450
1485
|
|
1451
1486
|
it "returns the count from the db" do
|
@@ -1455,16 +1490,198 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1455
1490
|
end
|
1456
1491
|
end
|
1457
1492
|
|
1493
|
+
describe "#any?" do
|
1494
|
+
|
1495
|
+
shared_examples 'does not query database when association is loaded' do
|
1496
|
+
|
1497
|
+
let(:fresh_movie) { Movie.find(movie.id) }
|
1498
|
+
|
1499
|
+
context 'when association is not loaded' do
|
1500
|
+
it 'queries database on each call' do
|
1501
|
+
fresh_movie
|
1502
|
+
|
1503
|
+
expect_query(1) do
|
1504
|
+
fresh_movie.ratings.any?.should be expected_result
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
expect_query(1) do
|
1508
|
+
fresh_movie.ratings.any?.should be expected_result
|
1509
|
+
end
|
1510
|
+
end
|
1511
|
+
|
1512
|
+
context 'when using a block' do
|
1513
|
+
it 'queries database on first call only' do
|
1514
|
+
fresh_movie
|
1515
|
+
|
1516
|
+
expect_query(1) do
|
1517
|
+
fresh_movie.ratings.any? { false }.should be false
|
1518
|
+
end
|
1519
|
+
|
1520
|
+
expect_no_queries do
|
1521
|
+
fresh_movie.ratings.any? { false }.should be false
|
1522
|
+
end
|
1523
|
+
end
|
1524
|
+
end
|
1525
|
+
end
|
1526
|
+
|
1527
|
+
context 'when association is loaded' do
|
1528
|
+
it 'does not query database' do
|
1529
|
+
fresh_movie
|
1530
|
+
|
1531
|
+
expect_query(1) do
|
1532
|
+
fresh_movie.ratings.any?.should be expected_result
|
1533
|
+
end
|
1534
|
+
|
1535
|
+
fresh_movie.ratings.to_a
|
1536
|
+
|
1537
|
+
expect_no_queries do
|
1538
|
+
fresh_movie.ratings.any?.should be expected_result
|
1539
|
+
end
|
1540
|
+
end
|
1541
|
+
end
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
let(:movie) do
|
1545
|
+
Movie.create!
|
1546
|
+
end
|
1547
|
+
|
1548
|
+
context "when nothing exists on the association" do
|
1549
|
+
|
1550
|
+
context "when no document is added" do
|
1551
|
+
|
1552
|
+
let!(:movie) do
|
1553
|
+
Movie.create!
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
it "returns false" do
|
1557
|
+
expect(movie.ratings.any?).to be false
|
1558
|
+
end
|
1559
|
+
|
1560
|
+
let(:expected_result) { false }
|
1561
|
+
include_examples 'does not query database when association is loaded'
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
context "when the document is destroyed" do
|
1565
|
+
|
1566
|
+
before do
|
1567
|
+
Rating.create!
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
let!(:movie) do
|
1571
|
+
Movie.create!
|
1572
|
+
end
|
1573
|
+
|
1574
|
+
it "returns false" do
|
1575
|
+
movie.destroy
|
1576
|
+
expect(movie.ratings.any?).to be false
|
1577
|
+
end
|
1578
|
+
end
|
1579
|
+
end
|
1580
|
+
|
1581
|
+
context "when appending to a association and _loaded/_unloaded are empty" do
|
1582
|
+
|
1583
|
+
let!(:movie) do
|
1584
|
+
Movie.create!
|
1585
|
+
end
|
1586
|
+
|
1587
|
+
before do
|
1588
|
+
movie.ratings << Rating.new
|
1589
|
+
end
|
1590
|
+
|
1591
|
+
it "returns true" do
|
1592
|
+
expect(movie.ratings.any?).to be true
|
1593
|
+
end
|
1594
|
+
|
1595
|
+
context 'when association is not loaded' do
|
1596
|
+
before do
|
1597
|
+
movie.ratings._loaded?.should be false
|
1598
|
+
end
|
1599
|
+
|
1600
|
+
it 'does not query the database because it knows about the added models' do
|
1601
|
+
expect_no_queries do
|
1602
|
+
movie.ratings.any?.should be true
|
1603
|
+
end
|
1604
|
+
end
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
context 'when association is loaded' do
|
1608
|
+
it 'does not query database' do
|
1609
|
+
expect_no_queries do
|
1610
|
+
movie.ratings.any?.should be true
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
movie.ratings.to_a
|
1614
|
+
|
1615
|
+
expect_no_queries do
|
1616
|
+
movie.ratings.any?.should be true
|
1617
|
+
end
|
1618
|
+
end
|
1619
|
+
end
|
1620
|
+
end
|
1621
|
+
|
1622
|
+
context "when appending to a association in a transaction" do
|
1623
|
+
require_transaction_support
|
1624
|
+
|
1625
|
+
let!(:movie) do
|
1626
|
+
Movie.create!
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
it "returns true" do
|
1630
|
+
movie.with_session do |session|
|
1631
|
+
session.with_transaction do
|
1632
|
+
expect{ movie.ratings << Rating.new }.to_not raise_error
|
1633
|
+
expect(movie.ratings.any?).to be true
|
1634
|
+
end
|
1635
|
+
end
|
1636
|
+
end
|
1637
|
+
end
|
1638
|
+
|
1639
|
+
context "when documents have been persisted" do
|
1640
|
+
|
1641
|
+
let!(:rating) do
|
1642
|
+
movie.ratings.create!(value: 1)
|
1643
|
+
end
|
1644
|
+
|
1645
|
+
it "returns true" do
|
1646
|
+
expect(movie.ratings.any?).to be true
|
1647
|
+
end
|
1648
|
+
|
1649
|
+
let(:expected_result) { true }
|
1650
|
+
include_examples 'does not query database when association is loaded'
|
1651
|
+
end
|
1652
|
+
|
1653
|
+
context "when documents have not been persisted" do
|
1654
|
+
|
1655
|
+
let!(:rating) do
|
1656
|
+
movie.ratings.build(value: 1)
|
1657
|
+
end
|
1658
|
+
|
1659
|
+
it "returns false" do
|
1660
|
+
expect(movie.ratings.any?).to be true
|
1661
|
+
end
|
1662
|
+
end
|
1663
|
+
|
1664
|
+
context "when new documents exist in the database" do
|
1665
|
+
before do
|
1666
|
+
Rating.create!(ratable: movie)
|
1667
|
+
end
|
1668
|
+
|
1669
|
+
it "returns true" do
|
1670
|
+
expect(movie.ratings.any?).to be true
|
1671
|
+
end
|
1672
|
+
end
|
1673
|
+
end
|
1674
|
+
|
1458
1675
|
describe "#create" do
|
1459
1676
|
|
1460
1677
|
context "when providing multiple attributes" do
|
1461
1678
|
|
1462
1679
|
let(:person) do
|
1463
|
-
Person.create
|
1680
|
+
Person.create!
|
1464
1681
|
end
|
1465
1682
|
|
1466
1683
|
let!(:posts) do
|
1467
|
-
person.posts.create([{ text: "Test1" }, { text: "Test2" }])
|
1684
|
+
person.posts.create!([{ text: "Test1" }, { text: "Test2" }])
|
1468
1685
|
end
|
1469
1686
|
|
1470
1687
|
it "creates multiple documents" do
|
@@ -1484,7 +1701,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1484
1701
|
end
|
1485
1702
|
end
|
1486
1703
|
|
1487
|
-
context "when the
|
1704
|
+
context "when the association is not polymorphic" do
|
1488
1705
|
|
1489
1706
|
context "when the parent is a new record" do
|
1490
1707
|
|
@@ -1493,7 +1710,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1493
1710
|
end
|
1494
1711
|
|
1495
1712
|
let(:post) do
|
1496
|
-
person.posts.create(text: "Testing")
|
1713
|
+
person.posts.create!(text: "Testing")
|
1497
1714
|
end
|
1498
1715
|
|
1499
1716
|
it "raises an unsaved document error" do
|
@@ -1506,11 +1723,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1506
1723
|
context "when the operation is successful" do
|
1507
1724
|
|
1508
1725
|
let(:person) do
|
1509
|
-
Person.create
|
1726
|
+
Person.create!
|
1510
1727
|
end
|
1511
1728
|
|
1512
1729
|
let!(:post) do
|
1513
|
-
person.posts.create(text: "Testing")
|
1730
|
+
person.posts.create!(text: "Testing")
|
1514
1731
|
end
|
1515
1732
|
|
1516
1733
|
it "creates the document" do
|
@@ -1521,16 +1738,16 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1521
1738
|
context "when the operation fails" do
|
1522
1739
|
|
1523
1740
|
let(:person) do
|
1524
|
-
Person.create
|
1741
|
+
Person.create!
|
1525
1742
|
end
|
1526
1743
|
|
1527
1744
|
let!(:existing) do
|
1528
|
-
Post.create
|
1745
|
+
Post.create!
|
1529
1746
|
end
|
1530
1747
|
|
1531
1748
|
it "raises an error" do
|
1532
1749
|
expect {
|
1533
|
-
person.posts.create do |doc|
|
1750
|
+
person.posts.create! do |doc|
|
1534
1751
|
doc._id = existing.id
|
1535
1752
|
end
|
1536
1753
|
}.to raise_error(Mongo::Error::OperationFailure)
|
@@ -1541,20 +1758,20 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1541
1758
|
context "when the parent is not a new record" do
|
1542
1759
|
|
1543
1760
|
let(:person) do
|
1544
|
-
Person.create
|
1761
|
+
Person.create!
|
1545
1762
|
end
|
1546
1763
|
|
1547
1764
|
let!(:post) do
|
1548
|
-
person.posts.create(text: "Testing") do |post|
|
1765
|
+
person.posts.create!(text: "Testing") do |post|
|
1549
1766
|
post.content = "The Content"
|
1550
1767
|
end
|
1551
1768
|
end
|
1552
1769
|
|
1553
|
-
it "sets the foreign key on the
|
1770
|
+
it "sets the foreign key on the association" do
|
1554
1771
|
expect(post.person_id).to eq(person.id)
|
1555
1772
|
end
|
1556
1773
|
|
1557
|
-
it "sets the base on the inverse
|
1774
|
+
it "sets the base on the inverse association" do
|
1558
1775
|
expect(post.person).to eq(person)
|
1559
1776
|
end
|
1560
1777
|
|
@@ -1578,11 +1795,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1578
1795
|
context "when passing a new object" do
|
1579
1796
|
|
1580
1797
|
let!(:odd) do
|
1581
|
-
Odd.create(name: 'one')
|
1798
|
+
Odd.create!(name: 'one')
|
1582
1799
|
end
|
1583
1800
|
|
1584
1801
|
let!(:even) do
|
1585
|
-
odd.evens.create(name: 'two', odds: [Odd.new(name: 'three')])
|
1802
|
+
odd.evens.create!(name: 'two', odds: [Odd.new(name: 'three')])
|
1586
1803
|
end
|
1587
1804
|
|
1588
1805
|
it "only push one even to the list" do
|
@@ -1603,7 +1820,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1603
1820
|
end
|
1604
1821
|
end
|
1605
1822
|
|
1606
|
-
context "when the
|
1823
|
+
context "when the association is polymorphic" do
|
1607
1824
|
|
1608
1825
|
context "when the parent is a new record" do
|
1609
1826
|
|
@@ -1612,7 +1829,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1612
1829
|
end
|
1613
1830
|
|
1614
1831
|
let(:rating) do
|
1615
|
-
movie.ratings.create(value: 1)
|
1832
|
+
movie.ratings.create!(value: 1)
|
1616
1833
|
end
|
1617
1834
|
|
1618
1835
|
it "raises an unsaved document error" do
|
@@ -1623,18 +1840,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1623
1840
|
context "when the parent is not a new record" do
|
1624
1841
|
|
1625
1842
|
let(:movie) do
|
1626
|
-
Movie.create
|
1843
|
+
Movie.create!
|
1627
1844
|
end
|
1628
1845
|
|
1629
1846
|
let!(:rating) do
|
1630
|
-
movie.ratings.create(value: 3)
|
1847
|
+
movie.ratings.create!(value: 3)
|
1631
1848
|
end
|
1632
1849
|
|
1633
|
-
it "sets the foreign key on the
|
1850
|
+
it "sets the foreign key on the association" do
|
1634
1851
|
expect(rating.ratable_id).to eq(movie.id)
|
1635
1852
|
end
|
1636
1853
|
|
1637
|
-
it "sets the base on the inverse
|
1854
|
+
it "sets the base on the inverse association" do
|
1638
1855
|
expect(rating.ratable).to eq(movie)
|
1639
1856
|
end
|
1640
1857
|
|
@@ -1652,7 +1869,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1652
1869
|
end
|
1653
1870
|
end
|
1654
1871
|
|
1655
|
-
context "when using a
|
1872
|
+
context "when using a different primary_key" do
|
1656
1873
|
|
1657
1874
|
let(:person) do
|
1658
1875
|
Person.create!(username: 'arthurnn')
|
@@ -1673,7 +1890,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1673
1890
|
context "when providing multiple attributes" do
|
1674
1891
|
|
1675
1892
|
let(:person) do
|
1676
|
-
Person.create
|
1893
|
+
Person.create!
|
1677
1894
|
end
|
1678
1895
|
|
1679
1896
|
let!(:posts) do
|
@@ -1697,7 +1914,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1697
1914
|
end
|
1698
1915
|
end
|
1699
1916
|
|
1700
|
-
context "when the
|
1917
|
+
context "when the association is not polymorphic" do
|
1701
1918
|
|
1702
1919
|
context "when the parent is a new record" do
|
1703
1920
|
|
@@ -1717,18 +1934,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1717
1934
|
context "when the parent is not a new record" do
|
1718
1935
|
|
1719
1936
|
let(:person) do
|
1720
|
-
Person.create
|
1937
|
+
Person.create!
|
1721
1938
|
end
|
1722
1939
|
|
1723
1940
|
let!(:post) do
|
1724
1941
|
person.posts.create!(title: "Testing")
|
1725
1942
|
end
|
1726
1943
|
|
1727
|
-
it "sets the foreign key on the
|
1944
|
+
it "sets the foreign key on the association" do
|
1728
1945
|
expect(post.person_id).to eq(person.id)
|
1729
1946
|
end
|
1730
1947
|
|
1731
|
-
it "sets the base on the inverse
|
1948
|
+
it "sets the base on the inverse association" do
|
1732
1949
|
expect(post.person).to eq(person)
|
1733
1950
|
end
|
1734
1951
|
|
@@ -1755,7 +1972,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1755
1972
|
end
|
1756
1973
|
end
|
1757
1974
|
|
1758
|
-
context "when the
|
1975
|
+
context "when the association is polymorphic" do
|
1759
1976
|
|
1760
1977
|
context "when the parent is a new record" do
|
1761
1978
|
|
@@ -1775,18 +1992,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1775
1992
|
context "when the parent is not a new record" do
|
1776
1993
|
|
1777
1994
|
let(:movie) do
|
1778
|
-
Movie.create
|
1995
|
+
Movie.create!
|
1779
1996
|
end
|
1780
1997
|
|
1781
1998
|
let!(:rating) do
|
1782
1999
|
movie.ratings.create!(value: 4)
|
1783
2000
|
end
|
1784
2001
|
|
1785
|
-
it "sets the foreign key on the
|
2002
|
+
it "sets the foreign key on the association" do
|
1786
2003
|
expect(rating.ratable_id).to eq(movie.id)
|
1787
2004
|
end
|
1788
2005
|
|
1789
|
-
it "sets the base on the inverse
|
2006
|
+
it "sets the base on the inverse association" do
|
1790
2007
|
expect(rating.ratable).to eq(movie)
|
1791
2008
|
end
|
1792
2009
|
|
@@ -1820,7 +2037,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1820
2037
|
Movie.new
|
1821
2038
|
end
|
1822
2039
|
|
1823
|
-
context "when the
|
2040
|
+
context "when the association is polymorphic" do
|
1824
2041
|
|
1825
2042
|
let(:association) do
|
1826
2043
|
Movie.relations["ratings"]
|
@@ -1840,7 +2057,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1840
2057
|
end
|
1841
2058
|
end
|
1842
2059
|
|
1843
|
-
context "when the
|
2060
|
+
context "when the association is not polymorphic" do
|
1844
2061
|
|
1845
2062
|
let(:association) do
|
1846
2063
|
Person.relations["posts"]
|
@@ -1863,7 +2080,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1863
2080
|
describe "#delete" do
|
1864
2081
|
|
1865
2082
|
let!(:person) do
|
1866
|
-
Person.create(username: 'arthurnn')
|
2083
|
+
Person.create!(username: 'arthurnn')
|
1867
2084
|
end
|
1868
2085
|
|
1869
2086
|
context "when the document is found" do
|
@@ -1873,7 +2090,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1873
2090
|
context "when we are assigning attributes" do
|
1874
2091
|
|
1875
2092
|
let!(:drug) do
|
1876
|
-
person.drugs.create
|
2093
|
+
person.drugs.create!
|
1877
2094
|
end
|
1878
2095
|
|
1879
2096
|
before do
|
@@ -1896,7 +2113,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1896
2113
|
context "when the document is loaded" do
|
1897
2114
|
|
1898
2115
|
let!(:drug) do
|
1899
|
-
person.drugs.create
|
2116
|
+
person.drugs.create!
|
1900
2117
|
end
|
1901
2118
|
|
1902
2119
|
let!(:deleted) do
|
@@ -1911,7 +2128,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1911
2128
|
expect(drug.person_id).to be_nil
|
1912
2129
|
end
|
1913
2130
|
|
1914
|
-
it "removes the document from the
|
2131
|
+
it "removes the document from the association" do
|
1915
2132
|
expect(person.drugs).to_not include(drug)
|
1916
2133
|
end
|
1917
2134
|
end
|
@@ -1919,7 +2136,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1919
2136
|
context "when the document is not loaded" do
|
1920
2137
|
|
1921
2138
|
let!(:drug) do
|
1922
|
-
Drug.create(person_id: person.username)
|
2139
|
+
Drug.create!(person_id: person.username)
|
1923
2140
|
end
|
1924
2141
|
|
1925
2142
|
let!(:deleted) do
|
@@ -1934,7 +2151,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1934
2151
|
expect(drug.person_id).to be_nil
|
1935
2152
|
end
|
1936
2153
|
|
1937
|
-
it "removes the document from the
|
2154
|
+
it "removes the document from the association" do
|
1938
2155
|
expect(person.drugs).to_not include(drug)
|
1939
2156
|
end
|
1940
2157
|
end
|
@@ -1945,7 +2162,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1945
2162
|
context "when the document is loaded" do
|
1946
2163
|
|
1947
2164
|
let!(:post) do
|
1948
|
-
person.posts.create(title: "test")
|
2165
|
+
person.posts.create!(title: "test")
|
1949
2166
|
end
|
1950
2167
|
|
1951
2168
|
let!(:deleted) do
|
@@ -1960,7 +2177,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1960
2177
|
expect(post).to be_destroyed
|
1961
2178
|
end
|
1962
2179
|
|
1963
|
-
it "removes the document from the
|
2180
|
+
it "removes the document from the association" do
|
1964
2181
|
expect(person.posts).to_not include(post)
|
1965
2182
|
end
|
1966
2183
|
end
|
@@ -1968,7 +2185,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1968
2185
|
context "when the document is not loaded" do
|
1969
2186
|
|
1970
2187
|
let!(:post) do
|
1971
|
-
Post.create(title: "foo", person_id: person.id)
|
2188
|
+
Post.create!(title: "foo", person_id: person.id)
|
1972
2189
|
end
|
1973
2190
|
|
1974
2191
|
let!(:deleted) do
|
@@ -1983,7 +2200,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1983
2200
|
expect(post).to be_destroyed
|
1984
2201
|
end
|
1985
2202
|
|
1986
|
-
it "removes the document from the
|
2203
|
+
it "removes the document from the association" do
|
1987
2204
|
expect(person.posts).to_not include(post)
|
1988
2205
|
end
|
1989
2206
|
end
|
@@ -1993,7 +2210,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
1993
2210
|
context "when the document is not found" do
|
1994
2211
|
|
1995
2212
|
let!(:post) do
|
1996
|
-
Post.create(title: "foo")
|
2213
|
+
Post.create!(title: "foo")
|
1997
2214
|
end
|
1998
2215
|
|
1999
2216
|
let!(:deleted) do
|
@@ -2014,17 +2231,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2014
2231
|
|
2015
2232
|
describe "##{method}" do
|
2016
2233
|
|
2017
|
-
context "when the
|
2234
|
+
context "when the association is not polymorphic" do
|
2018
2235
|
|
2019
2236
|
context "when conditions are provided" do
|
2020
2237
|
|
2021
2238
|
let(:person) do
|
2022
|
-
Person.create(username: 'durran')
|
2239
|
+
Person.create!(username: 'durran')
|
2023
2240
|
end
|
2024
2241
|
|
2025
2242
|
before do
|
2026
|
-
person.posts.create(title: "Testing")
|
2027
|
-
person.posts.create(title: "Test")
|
2243
|
+
person.posts.create!(title: "Testing")
|
2244
|
+
person.posts.create!(title: "Test")
|
2028
2245
|
end
|
2029
2246
|
|
2030
2247
|
it "removes the correct posts" do
|
@@ -2046,12 +2263,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2046
2263
|
context "when conditions are not provided" do
|
2047
2264
|
|
2048
2265
|
let(:person) do
|
2049
|
-
Person.create
|
2266
|
+
Person.create!
|
2050
2267
|
end
|
2051
2268
|
|
2052
2269
|
before do
|
2053
|
-
person.posts.create(title: "Testing")
|
2054
|
-
person.posts.create(title: "Test")
|
2270
|
+
person.posts.create!(title: "Testing")
|
2271
|
+
person.posts.create!(title: "Test")
|
2055
2272
|
end
|
2056
2273
|
|
2057
2274
|
it "removes the correct posts" do
|
@@ -2070,17 +2287,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2070
2287
|
end
|
2071
2288
|
end
|
2072
2289
|
|
2073
|
-
context "when the
|
2290
|
+
context "when the association is polymorphic" do
|
2074
2291
|
|
2075
2292
|
context "when conditions are provided" do
|
2076
2293
|
|
2077
2294
|
let(:movie) do
|
2078
|
-
Movie.create(title: "Bladerunner")
|
2295
|
+
Movie.create!(title: "Bladerunner")
|
2079
2296
|
end
|
2080
2297
|
|
2081
2298
|
before do
|
2082
|
-
movie.ratings.create(value: 1)
|
2083
|
-
movie.ratings.create(value: 2)
|
2299
|
+
movie.ratings.create!(value: 1)
|
2300
|
+
movie.ratings.create!(value: 2)
|
2084
2301
|
end
|
2085
2302
|
|
2086
2303
|
it "removes the correct ratings" do
|
@@ -2101,12 +2318,12 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2101
2318
|
context "when conditions are not provided" do
|
2102
2319
|
|
2103
2320
|
let(:movie) do
|
2104
|
-
Movie.create(title: "Bladerunner")
|
2321
|
+
Movie.create!(title: "Bladerunner")
|
2105
2322
|
end
|
2106
2323
|
|
2107
2324
|
before do
|
2108
|
-
movie.ratings.create(value: 1)
|
2109
|
-
movie.ratings.create(value: 2)
|
2325
|
+
movie.ratings.create!(value: 1)
|
2326
|
+
movie.ratings.create!(value: 2)
|
2110
2327
|
end
|
2111
2328
|
|
2112
2329
|
it "removes the correct ratings" do
|
@@ -2137,21 +2354,47 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2137
2354
|
describe "#exists?" do
|
2138
2355
|
|
2139
2356
|
let!(:person) do
|
2140
|
-
Person.create
|
2357
|
+
Person.create!
|
2141
2358
|
end
|
2142
2359
|
|
2143
2360
|
context "when documents exist in the database" do
|
2144
2361
|
|
2145
2362
|
before do
|
2146
|
-
person.posts.create
|
2363
|
+
person.posts.create!
|
2147
2364
|
end
|
2148
2365
|
|
2149
2366
|
it "returns true" do
|
2150
2367
|
expect(person.posts.exists?).to be true
|
2151
2368
|
end
|
2369
|
+
|
2370
|
+
context 'when association is not loaded' do
|
2371
|
+
it 'queries database on each call' do
|
2372
|
+
expect_query(1) do
|
2373
|
+
person.posts.exists?.should be true
|
2374
|
+
end
|
2375
|
+
|
2376
|
+
expect_query(1) do
|
2377
|
+
person.posts.exists?.should be true
|
2378
|
+
end
|
2379
|
+
end
|
2380
|
+
end
|
2381
|
+
|
2382
|
+
context 'when association is loaded' do
|
2383
|
+
it 'queries database on each call' do
|
2384
|
+
expect_query(1) do
|
2385
|
+
person.posts.exists?.should be true
|
2386
|
+
end
|
2387
|
+
|
2388
|
+
person.posts.to_a
|
2389
|
+
|
2390
|
+
expect_query(1) do
|
2391
|
+
person.posts.exists?.should be true
|
2392
|
+
end
|
2393
|
+
end
|
2394
|
+
end
|
2152
2395
|
end
|
2153
2396
|
|
2154
|
-
context "when
|
2397
|
+
context "when documents exist in application but not in database" do
|
2155
2398
|
|
2156
2399
|
before do
|
2157
2400
|
person.posts.build
|
@@ -2160,6 +2403,65 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2160
2403
|
it "returns false" do
|
2161
2404
|
expect(person.posts.exists?).to be false
|
2162
2405
|
end
|
2406
|
+
|
2407
|
+
context 'when association is not loaded' do
|
2408
|
+
it 'queries database on each call' do
|
2409
|
+
expect_query(1) do
|
2410
|
+
person.posts.exists?.should be false
|
2411
|
+
end
|
2412
|
+
|
2413
|
+
expect_query(1) do
|
2414
|
+
person.posts.exists?.should be false
|
2415
|
+
end
|
2416
|
+
end
|
2417
|
+
end
|
2418
|
+
|
2419
|
+
context 'when association is loaded' do
|
2420
|
+
it 'queries database on each call' do
|
2421
|
+
expect_query(1) do
|
2422
|
+
person.posts.exists?.should be false
|
2423
|
+
end
|
2424
|
+
|
2425
|
+
person.posts.to_a
|
2426
|
+
|
2427
|
+
expect_query(1) do
|
2428
|
+
person.posts.exists?.should be false
|
2429
|
+
end
|
2430
|
+
end
|
2431
|
+
end
|
2432
|
+
end
|
2433
|
+
|
2434
|
+
context "when no documents exist" do
|
2435
|
+
|
2436
|
+
it "returns false" do
|
2437
|
+
expect(person.posts.exists?).to be false
|
2438
|
+
end
|
2439
|
+
|
2440
|
+
context 'when association is not loaded' do
|
2441
|
+
it 'queries database on each call' do
|
2442
|
+
expect_query(1) do
|
2443
|
+
person.posts.exists?.should be false
|
2444
|
+
end
|
2445
|
+
|
2446
|
+
expect_query(1) do
|
2447
|
+
person.posts.exists?.should be false
|
2448
|
+
end
|
2449
|
+
end
|
2450
|
+
end
|
2451
|
+
|
2452
|
+
context 'when association is loaded' do
|
2453
|
+
it 'queries database on each call' do
|
2454
|
+
expect_query(1) do
|
2455
|
+
person.posts.exists?.should be false
|
2456
|
+
end
|
2457
|
+
|
2458
|
+
person.posts.to_a
|
2459
|
+
|
2460
|
+
expect_query(1) do
|
2461
|
+
person.posts.exists?.should be false
|
2462
|
+
end
|
2463
|
+
end
|
2464
|
+
end
|
2163
2465
|
end
|
2164
2466
|
end
|
2165
2467
|
|
@@ -2186,18 +2488,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2186
2488
|
end
|
2187
2489
|
end
|
2188
2490
|
|
2189
|
-
context "when the
|
2491
|
+
context "when the association is not polymorphic" do
|
2190
2492
|
|
2191
2493
|
let(:person) do
|
2192
|
-
Person.create
|
2494
|
+
Person.create!
|
2193
2495
|
end
|
2194
2496
|
|
2195
2497
|
let!(:post_one) do
|
2196
|
-
person.posts.create(title: "Test")
|
2498
|
+
person.posts.create!(title: "Test")
|
2197
2499
|
end
|
2198
2500
|
|
2199
2501
|
let!(:post_two) do
|
2200
|
-
person.posts.create(title: "OMG I has
|
2502
|
+
person.posts.create!(title: "OMG I has associations")
|
2201
2503
|
end
|
2202
2504
|
|
2203
2505
|
context "when providing an id" do
|
@@ -2213,10 +2515,10 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2213
2515
|
end
|
2214
2516
|
end
|
2215
2517
|
|
2216
|
-
context "when the id matches but is not scoped to the
|
2518
|
+
context "when the id matches but is not scoped to the association" do
|
2217
2519
|
|
2218
2520
|
let(:post) do
|
2219
|
-
Post.create(title: "Unscoped")
|
2521
|
+
Post.create!(title: "Unscoped")
|
2220
2522
|
end
|
2221
2523
|
|
2222
2524
|
it "raises an error" do
|
@@ -2312,18 +2614,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2312
2614
|
end
|
2313
2615
|
end
|
2314
2616
|
|
2315
|
-
context "when the
|
2617
|
+
context "when the association is polymorphic" do
|
2316
2618
|
|
2317
2619
|
let(:movie) do
|
2318
|
-
Movie.create
|
2620
|
+
Movie.create!
|
2319
2621
|
end
|
2320
2622
|
|
2321
2623
|
let!(:rating_one) do
|
2322
|
-
movie.ratings.create(value: 1)
|
2624
|
+
movie.ratings.create!(value: 1)
|
2323
2625
|
end
|
2324
2626
|
|
2325
2627
|
let!(:rating_two) do
|
2326
|
-
movie.ratings.create(value: 5)
|
2628
|
+
movie.ratings.create!(value: 5)
|
2327
2629
|
end
|
2328
2630
|
|
2329
2631
|
context "when providing an id" do
|
@@ -2432,18 +2734,56 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2432
2734
|
end
|
2433
2735
|
end
|
2434
2736
|
end
|
2737
|
+
|
2738
|
+
context "with block" do
|
2739
|
+
let!(:author) do
|
2740
|
+
Person.create!(title: 'Person')
|
2741
|
+
end
|
2742
|
+
|
2743
|
+
let!(:post_one) do
|
2744
|
+
author.posts.create!(title: 'post one')
|
2745
|
+
end
|
2746
|
+
|
2747
|
+
let!(:post_two) do
|
2748
|
+
author.posts.create!(title: 'post two')
|
2749
|
+
end
|
2750
|
+
|
2751
|
+
it "finds one" do
|
2752
|
+
expect(
|
2753
|
+
author.posts.find do |post|
|
2754
|
+
post.title == 'post one'
|
2755
|
+
end
|
2756
|
+
).to be_a(Post)
|
2757
|
+
end
|
2758
|
+
|
2759
|
+
it "returns first match of multiple" do
|
2760
|
+
expect(
|
2761
|
+
author.posts.find do |post|
|
2762
|
+
['post one', 'post two'].include?(post.title)
|
2763
|
+
end
|
2764
|
+
).to eq(post_one)
|
2765
|
+
end
|
2766
|
+
|
2767
|
+
it "returns nil when not found" do
|
2768
|
+
expect(
|
2769
|
+
author.posts.find do |post|
|
2770
|
+
post.title == 'non exiting one'
|
2771
|
+
end
|
2772
|
+
).to be_nil
|
2773
|
+
end
|
2774
|
+
end
|
2435
2775
|
end
|
2436
2776
|
|
2437
2777
|
describe "#find_or_create_by" do
|
2438
2778
|
|
2439
|
-
context "when the
|
2779
|
+
context "when the association is not polymorphic" do
|
2440
2780
|
|
2441
2781
|
let(:person) do
|
2442
|
-
Person.create
|
2782
|
+
Person.create!
|
2443
2783
|
end
|
2444
2784
|
|
2445
2785
|
let!(:post) do
|
2446
|
-
person.posts.create(title: "Testing")
|
2786
|
+
person.posts.create!(title: "Testing")
|
2447
2787
|
end
|
2448
2788
|
|
2449
2789
|
context "when the document exists" do
|
@@ -2456,7 +2796,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2456
2796
|
expect(found).to eq(post)
|
2457
2797
|
end
|
2458
2798
|
|
2459
|
-
it "keeps the document in the
|
2799
|
+
it "keeps the document in the association" do
|
2460
2800
|
expect(found.person).to eq(person)
|
2461
2801
|
end
|
2462
2802
|
end
|
@@ -2483,7 +2823,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2483
2823
|
expect(found.content).to eq("The Content")
|
2484
2824
|
end
|
2485
2825
|
|
2486
|
-
it "keeps the document in the
|
2826
|
+
it "keeps the document in the association" do
|
2487
2827
|
expect(found.person).to eq(person)
|
2488
2828
|
end
|
2489
2829
|
end
|
@@ -2502,21 +2842,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2502
2842
|
expect(found).to be_persisted
|
2503
2843
|
end
|
2504
2844
|
|
2505
|
-
it "keeps the document in the
|
2845
|
+
it "keeps the document in the association" do
|
2506
2846
|
expect(found.person).to eq(person)
|
2507
2847
|
end
|
2508
2848
|
end
|
2509
2849
|
end
|
2510
2850
|
end
|
2511
2851
|
|
2512
|
-
context "when the
|
2852
|
+
context "when the association is polymorphic" do
|
2513
2853
|
|
2514
2854
|
let(:movie) do
|
2515
|
-
Movie.create
|
2855
|
+
Movie.create!
|
2516
2856
|
end
|
2517
2857
|
|
2518
2858
|
let!(:rating) do
|
2519
|
-
movie.ratings.create(value: 1)
|
2859
|
+
movie.ratings.create!(value: 1)
|
2520
2860
|
end
|
2521
2861
|
|
2522
2862
|
context "when the document exists" do
|
@@ -2529,7 +2869,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2529
2869
|
expect(found).to eq(rating)
|
2530
2870
|
end
|
2531
2871
|
|
2532
|
-
it "keeps the document in the
|
2872
|
+
it "keeps the document in the association" do
|
2533
2873
|
expect(found.ratable).to eq(movie)
|
2534
2874
|
end
|
2535
2875
|
end
|
@@ -2548,7 +2888,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2548
2888
|
expect(found).to be_persisted
|
2549
2889
|
end
|
2550
2890
|
|
2551
|
-
it "keeps the document in the
|
2891
|
+
it "keeps the document in the association" do
|
2552
2892
|
expect(found.ratable).to eq(movie)
|
2553
2893
|
end
|
2554
2894
|
end
|
@@ -2557,14 +2897,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2557
2897
|
|
2558
2898
|
describe "#find_or_create_by!" do
|
2559
2899
|
|
2560
|
-
context "when the
|
2900
|
+
context "when the association is not polymorphic" do
|
2561
2901
|
|
2562
2902
|
let(:person) do
|
2563
|
-
Person.create
|
2903
|
+
Person.create!
|
2564
2904
|
end
|
2565
2905
|
|
2566
2906
|
let!(:post) do
|
2567
|
-
person.posts.create(title: "Testing")
|
2907
|
+
person.posts.create!(title: "Testing")
|
2568
2908
|
end
|
2569
2909
|
|
2570
2910
|
context "when the document exists" do
|
@@ -2577,7 +2917,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2577
2917
|
expect(found).to eq(post)
|
2578
2918
|
end
|
2579
2919
|
|
2580
|
-
it "keeps the document in the
|
2920
|
+
it "keeps the document in the association" do
|
2581
2921
|
expect(found.person).to eq(person)
|
2582
2922
|
end
|
2583
2923
|
end
|
@@ -2604,7 +2944,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2604
2944
|
expect(found.content).to eq("The Content")
|
2605
2945
|
end
|
2606
2946
|
|
2607
|
-
it "keeps the document in the
|
2947
|
+
it "keeps the document in the association" do
|
2608
2948
|
expect(found.person).to eq(person)
|
2609
2949
|
end
|
2610
2950
|
end
|
@@ -2623,21 +2963,21 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2623
2963
|
expect(found).to be_persisted
|
2624
2964
|
end
|
2625
2965
|
|
2626
|
-
it "keeps the document in the
|
2966
|
+
it "keeps the document in the association" do
|
2627
2967
|
expect(found.person).to eq(person)
|
2628
2968
|
end
|
2629
2969
|
end
|
2630
2970
|
end
|
2631
2971
|
end
|
2632
2972
|
|
2633
|
-
context "when the
|
2973
|
+
context "when the association is polymorphic" do
|
2634
2974
|
|
2635
2975
|
let(:movie) do
|
2636
|
-
Movie.create
|
2976
|
+
Movie.create!
|
2637
2977
|
end
|
2638
2978
|
|
2639
2979
|
let!(:rating) do
|
2640
|
-
movie.ratings.create(value: 1)
|
2980
|
+
movie.ratings.create!(value: 1)
|
2641
2981
|
end
|
2642
2982
|
|
2643
2983
|
context "when the document exists" do
|
@@ -2650,7 +2990,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2650
2990
|
expect(found).to eq(rating)
|
2651
2991
|
end
|
2652
2992
|
|
2653
|
-
it "keeps the document in the
|
2993
|
+
it "keeps the document in the association" do
|
2654
2994
|
expect(found.ratable).to eq(movie)
|
2655
2995
|
end
|
2656
2996
|
end
|
@@ -2669,7 +3009,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2669
3009
|
expect(found).to be_persisted
|
2670
3010
|
end
|
2671
3011
|
|
2672
|
-
it "keeps the document in the
|
3012
|
+
it "keeps the document in the association" do
|
2673
3013
|
expect(found.ratable).to eq(movie)
|
2674
3014
|
end
|
2675
3015
|
|
@@ -2687,14 +3027,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2687
3027
|
|
2688
3028
|
describe "#find_or_initialize_by" do
|
2689
3029
|
|
2690
|
-
context "when the
|
3030
|
+
context "when the association is not polymorphic" do
|
2691
3031
|
|
2692
3032
|
let(:person) do
|
2693
|
-
Person.create
|
3033
|
+
Person.create!
|
2694
3034
|
end
|
2695
3035
|
|
2696
3036
|
let!(:post) do
|
2697
|
-
person.posts.create(title: "Testing")
|
3037
|
+
person.posts.create!(title: "Testing")
|
2698
3038
|
end
|
2699
3039
|
|
2700
3040
|
context "when the document exists" do
|
@@ -2730,14 +3070,14 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2730
3070
|
end
|
2731
3071
|
end
|
2732
3072
|
|
2733
|
-
context "when the
|
3073
|
+
context "when the association is polymorphic" do
|
2734
3074
|
|
2735
3075
|
let(:movie) do
|
2736
|
-
Movie.create
|
3076
|
+
Movie.create!
|
2737
3077
|
end
|
2738
3078
|
|
2739
3079
|
let!(:rating) do
|
2740
|
-
movie.ratings.create(value: 1)
|
3080
|
+
movie.ratings.create!(value: 1)
|
2741
3081
|
end
|
2742
3082
|
|
2743
3083
|
context "when the document exists" do
|
@@ -2770,7 +3110,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2770
3110
|
|
2771
3111
|
describe "#initialize" do
|
2772
3112
|
|
2773
|
-
context "when an illegal mixed
|
3113
|
+
context "when an illegal mixed association exists" do
|
2774
3114
|
|
2775
3115
|
let(:post) do
|
2776
3116
|
Post.new
|
@@ -2783,7 +3123,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2783
3123
|
end
|
2784
3124
|
end
|
2785
3125
|
|
2786
|
-
context "when a cyclic
|
3126
|
+
context "when a cyclic association exists" do
|
2787
3127
|
|
2788
3128
|
let(:post) do
|
2789
3129
|
Post.new
|
@@ -2827,15 +3167,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2827
3167
|
describe "#max" do
|
2828
3168
|
|
2829
3169
|
let(:person) do
|
2830
|
-
Person.create
|
3170
|
+
Person.create!
|
2831
3171
|
end
|
2832
3172
|
|
2833
3173
|
let(:post_one) do
|
2834
|
-
Post.create(rating: 5)
|
3174
|
+
Post.create!(rating: 5)
|
2835
3175
|
end
|
2836
3176
|
|
2837
3177
|
let(:post_two) do
|
2838
|
-
Post.create(rating: 10)
|
3178
|
+
Post.create!(rating: 10)
|
2839
3179
|
end
|
2840
3180
|
|
2841
3181
|
before do
|
@@ -2856,15 +3196,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2856
3196
|
describe "#max_by" do
|
2857
3197
|
|
2858
3198
|
let(:person) do
|
2859
|
-
Person.create
|
3199
|
+
Person.create!
|
2860
3200
|
end
|
2861
3201
|
|
2862
3202
|
let(:post_one) do
|
2863
|
-
Post.create(rating: 5)
|
3203
|
+
Post.create!(rating: 5)
|
2864
3204
|
end
|
2865
3205
|
|
2866
3206
|
let(:post_two) do
|
2867
|
-
Post.create(rating: 10)
|
3207
|
+
Post.create!(rating: 10)
|
2868
3208
|
end
|
2869
3209
|
|
2870
3210
|
before do
|
@@ -2883,15 +3223,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2883
3223
|
describe "#method_missing" do
|
2884
3224
|
|
2885
3225
|
let!(:person) do
|
2886
|
-
Person.create
|
3226
|
+
Person.create!
|
2887
3227
|
end
|
2888
3228
|
|
2889
3229
|
let!(:post_one) do
|
2890
|
-
person.posts.create(title: "First", content: "Posting")
|
3230
|
+
person.posts.create!(title: "First", content: "Posting")
|
2891
3231
|
end
|
2892
3232
|
|
2893
3233
|
let!(:post_two) do
|
2894
|
-
person.posts.create(title: "Second", content: "Testing")
|
3234
|
+
person.posts.create!(title: "Second", content: "Testing")
|
2895
3235
|
end
|
2896
3236
|
|
2897
3237
|
context "when providing a single criteria" do
|
@@ -2958,15 +3298,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2958
3298
|
describe "#min" do
|
2959
3299
|
|
2960
3300
|
let(:person) do
|
2961
|
-
Person.create
|
3301
|
+
Person.create!
|
2962
3302
|
end
|
2963
3303
|
|
2964
3304
|
let(:post_one) do
|
2965
|
-
Post.create(rating: 5)
|
3305
|
+
Post.create!(rating: 5)
|
2966
3306
|
end
|
2967
3307
|
|
2968
3308
|
let(:post_two) do
|
2969
|
-
Post.create(rating: 10)
|
3309
|
+
Post.create!(rating: 10)
|
2970
3310
|
end
|
2971
3311
|
|
2972
3312
|
before do
|
@@ -2987,15 +3327,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
2987
3327
|
describe "#min_by" do
|
2988
3328
|
|
2989
3329
|
let(:person) do
|
2990
|
-
Person.create
|
3330
|
+
Person.create!
|
2991
3331
|
end
|
2992
3332
|
|
2993
3333
|
let(:post_one) do
|
2994
|
-
Post.create(rating: 5)
|
3334
|
+
Post.create!(rating: 5)
|
2995
3335
|
end
|
2996
3336
|
|
2997
3337
|
let(:post_two) do
|
2998
|
-
Post.create(rating: 10)
|
3338
|
+
Post.create!(rating: 10)
|
2999
3339
|
end
|
3000
3340
|
|
3001
3341
|
before do
|
@@ -3016,15 +3356,15 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3016
3356
|
context "when the inverse has not been loaded" do
|
3017
3357
|
|
3018
3358
|
let(:person) do
|
3019
|
-
Person.create
|
3359
|
+
Person.create!
|
3020
3360
|
end
|
3021
3361
|
|
3022
3362
|
let!(:post_one) do
|
3023
|
-
person.posts.create(title: "One")
|
3363
|
+
person.posts.create!(title: "One")
|
3024
3364
|
end
|
3025
3365
|
|
3026
3366
|
let!(:post_two) do
|
3027
|
-
person.posts.create(title: "Two")
|
3367
|
+
person.posts.create!(title: "Two")
|
3028
3368
|
end
|
3029
3369
|
|
3030
3370
|
let(:from_db) do
|
@@ -3050,18 +3390,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3050
3390
|
end
|
3051
3391
|
end
|
3052
3392
|
|
3053
|
-
context "when the
|
3393
|
+
context "when the association is not polymorphic" do
|
3054
3394
|
|
3055
3395
|
let(:person) do
|
3056
|
-
Person.create
|
3396
|
+
Person.create!
|
3057
3397
|
end
|
3058
3398
|
|
3059
3399
|
let!(:post_one) do
|
3060
|
-
person.posts.create(title: "One")
|
3400
|
+
person.posts.create!(title: "One")
|
3061
3401
|
end
|
3062
3402
|
|
3063
3403
|
let!(:post_two) do
|
3064
|
-
person.posts.create(title: "Two")
|
3404
|
+
person.posts.create!(title: "Two")
|
3065
3405
|
end
|
3066
3406
|
|
3067
3407
|
before do
|
@@ -3084,30 +3424,30 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3084
3424
|
expect(post_one.reload.person).to be_nil
|
3085
3425
|
end
|
3086
3426
|
|
3087
|
-
context "when adding a nullified document back to the
|
3427
|
+
context "when adding a nullified document back to the association" do
|
3088
3428
|
|
3089
3429
|
before do
|
3090
3430
|
person.posts.push(post_one)
|
3091
3431
|
end
|
3092
3432
|
|
3093
|
-
it "persists the
|
3433
|
+
it "persists the association" do
|
3094
3434
|
expect(person.posts(true)).to eq([ post_one ])
|
3095
3435
|
end
|
3096
3436
|
end
|
3097
3437
|
end
|
3098
3438
|
|
3099
|
-
context "when the
|
3439
|
+
context "when the association is polymorphic" do
|
3100
3440
|
|
3101
3441
|
let(:movie) do
|
3102
|
-
Movie.create(title: "Oldboy")
|
3442
|
+
Movie.create!(title: "Oldboy")
|
3103
3443
|
end
|
3104
3444
|
|
3105
3445
|
let!(:rating_one) do
|
3106
|
-
movie.ratings.create(value: 10)
|
3446
|
+
movie.ratings.create!(value: 10)
|
3107
3447
|
end
|
3108
3448
|
|
3109
3449
|
let!(:rating_two) do
|
3110
|
-
movie.ratings.create(value: 9)
|
3450
|
+
movie.ratings.create!(value: 9)
|
3111
3451
|
end
|
3112
3452
|
|
3113
3453
|
before do
|
@@ -3179,7 +3519,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3179
3519
|
person.posts.scoped
|
3180
3520
|
end
|
3181
3521
|
|
3182
|
-
it "returns the
|
3522
|
+
it "returns the association criteria" do
|
3183
3523
|
expect(scoped).to be_a(Mongoid::Criteria)
|
3184
3524
|
end
|
3185
3525
|
|
@@ -3193,13 +3533,13 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3193
3533
|
describe "##{method}" do
|
3194
3534
|
|
3195
3535
|
let(:movie) do
|
3196
|
-
Movie.create
|
3536
|
+
Movie.create!
|
3197
3537
|
end
|
3198
3538
|
|
3199
3539
|
context "when documents have been persisted" do
|
3200
3540
|
|
3201
3541
|
let!(:rating) do
|
3202
|
-
movie.ratings.create(value: 1)
|
3542
|
+
movie.ratings.create!(value: 1)
|
3203
3543
|
end
|
3204
3544
|
|
3205
3545
|
it "returns 1" do
|
@@ -3211,7 +3551,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3211
3551
|
|
3212
3552
|
before do
|
3213
3553
|
movie.ratings.build(value: 1)
|
3214
|
-
movie.ratings.create(value: 2)
|
3554
|
+
movie.ratings.create!(value: 2)
|
3215
3555
|
end
|
3216
3556
|
|
3217
3557
|
it "returns the total number of documents" do
|
@@ -3223,18 +3563,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3223
3563
|
|
3224
3564
|
describe "#unscoped" do
|
3225
3565
|
|
3226
|
-
context "when the
|
3566
|
+
context "when the association has no default scope" do
|
3227
3567
|
|
3228
3568
|
let!(:person) do
|
3229
|
-
Person.create
|
3569
|
+
Person.create!
|
3230
3570
|
end
|
3231
3571
|
|
3232
3572
|
let!(:post_one) do
|
3233
|
-
person.posts.create(title: "first")
|
3573
|
+
person.posts.create!(title: "first")
|
3234
3574
|
end
|
3235
3575
|
|
3236
3576
|
let!(:post_two) do
|
3237
|
-
Post.create(title: "second")
|
3577
|
+
Post.create!(title: "second")
|
3238
3578
|
end
|
3239
3579
|
|
3240
3580
|
let(:unscoped) do
|
@@ -3246,18 +3586,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3246
3586
|
end
|
3247
3587
|
end
|
3248
3588
|
|
3249
|
-
context "when the
|
3589
|
+
context "when the association has a default scope" do
|
3250
3590
|
|
3251
3591
|
let!(:church) do
|
3252
|
-
Church.create
|
3592
|
+
Church.create!
|
3253
3593
|
end
|
3254
3594
|
|
3255
3595
|
let!(:acolyte_one) do
|
3256
|
-
church.acolytes.create(name: "first")
|
3596
|
+
church.acolytes.create!(name: "first")
|
3257
3597
|
end
|
3258
3598
|
|
3259
3599
|
let!(:acolyte_two) do
|
3260
|
-
Acolyte.create(name: "second")
|
3600
|
+
Acolyte.create!(name: "second")
|
3261
3601
|
end
|
3262
3602
|
|
3263
3603
|
let(:unscoped) do
|
@@ -3277,19 +3617,19 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3277
3617
|
context "when the association has an order defined" do
|
3278
3618
|
|
3279
3619
|
let(:person) do
|
3280
|
-
Person.create
|
3620
|
+
Person.create!
|
3281
3621
|
end
|
3282
3622
|
|
3283
3623
|
let(:post_one) do
|
3284
|
-
OrderedPost.create(rating: 10, title: '1')
|
3624
|
+
OrderedPost.create!(rating: 10, title: '1')
|
3285
3625
|
end
|
3286
3626
|
|
3287
3627
|
let(:post_two) do
|
3288
|
-
OrderedPost.create(rating: 20, title: '2')
|
3628
|
+
OrderedPost.create!(rating: 20, title: '2')
|
3289
3629
|
end
|
3290
3630
|
|
3291
3631
|
let(:post_three) do
|
3292
|
-
OrderedPost.create(rating: 20, title: '3')
|
3632
|
+
OrderedPost.create!(rating: 20, title: '3')
|
3293
3633
|
end
|
3294
3634
|
|
3295
3635
|
before do
|
@@ -3303,32 +3643,32 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3303
3643
|
)
|
3304
3644
|
end
|
3305
3645
|
|
3306
|
-
it "chaining order
|
3646
|
+
it "chaining order criteria" do
|
3307
3647
|
expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
|
3308
3648
|
[post_three, post_two, post_one]
|
3309
3649
|
)
|
3310
3650
|
end
|
3311
3651
|
end
|
3312
3652
|
|
3313
|
-
context "when reloading the
|
3653
|
+
context "when reloading the association" do
|
3314
3654
|
|
3315
3655
|
let!(:person) do
|
3316
|
-
Person.create
|
3656
|
+
Person.create!
|
3317
3657
|
end
|
3318
3658
|
|
3319
3659
|
let!(:post_one) do
|
3320
|
-
Post.create(title: "one")
|
3660
|
+
Post.create!(title: "one")
|
3321
3661
|
end
|
3322
3662
|
|
3323
3663
|
let!(:post_two) do
|
3324
|
-
Post.create(title: "two")
|
3664
|
+
Post.create!(title: "two")
|
3325
3665
|
end
|
3326
3666
|
|
3327
3667
|
before do
|
3328
3668
|
person.posts << post_one
|
3329
3669
|
end
|
3330
3670
|
|
3331
|
-
context "when the
|
3671
|
+
context "when the association references the same documents" do
|
3332
3672
|
|
3333
3673
|
before do
|
3334
3674
|
Post.collection.find({ _id: post_one.id }).
|
@@ -3344,7 +3684,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3344
3684
|
end
|
3345
3685
|
end
|
3346
3686
|
|
3347
|
-
context "when the
|
3687
|
+
context "when the association references different documents" do
|
3348
3688
|
|
3349
3689
|
before do
|
3350
3690
|
person.posts << post_two
|
@@ -3367,7 +3707,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3367
3707
|
context "when the parent is using integer ids" do
|
3368
3708
|
|
3369
3709
|
let(:jar) do
|
3370
|
-
Jar.create do |doc|
|
3710
|
+
Jar.create! do |doc|
|
3371
3711
|
doc._id = 1
|
3372
3712
|
end
|
3373
3713
|
end
|
@@ -3431,7 +3771,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3431
3771
|
expect(album.before_add_called).to be true
|
3432
3772
|
end
|
3433
3773
|
|
3434
|
-
it "adds the document to the
|
3774
|
+
it "adds the document to the association" do
|
3435
3775
|
expect(artist.albums).to eq([ album ])
|
3436
3776
|
end
|
3437
3777
|
end
|
@@ -3443,7 +3783,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3443
3783
|
begin; artist.albums << album; rescue; end
|
3444
3784
|
end
|
3445
3785
|
|
3446
|
-
it "does not add the document to the
|
3786
|
+
it "does not add the document to the association" do
|
3447
3787
|
expect(artist.albums).to be_empty
|
3448
3788
|
end
|
3449
3789
|
end
|
@@ -3471,17 +3811,17 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3471
3811
|
begin; artist.albums << album; rescue; end
|
3472
3812
|
end
|
3473
3813
|
|
3474
|
-
it "adds the document to the
|
3814
|
+
it "adds the document to the association" do
|
3475
3815
|
expect(artist.albums).to eq([ album ])
|
3476
3816
|
end
|
3477
3817
|
end
|
3478
3818
|
|
3479
|
-
context 'when the
|
3819
|
+
context 'when the association already exists' do
|
3480
3820
|
|
3481
3821
|
before do
|
3482
3822
|
artist.albums << album
|
3483
|
-
album.save
|
3484
|
-
artist.save
|
3823
|
+
album.save!
|
3824
|
+
artist.save!
|
3485
3825
|
expect(artist).not_to receive(:after_add_album)
|
3486
3826
|
end
|
3487
3827
|
|
@@ -3489,7 +3829,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3489
3829
|
Album.where(artist_id: artist.id).first
|
3490
3830
|
end
|
3491
3831
|
|
3492
|
-
it 'does not execute the callback when the
|
3832
|
+
it 'does not execute the callback when the association is accessed' do
|
3493
3833
|
expect(reloaded_album.artist.after_add_referenced_called).to be(nil)
|
3494
3834
|
end
|
3495
3835
|
end
|
@@ -3521,7 +3861,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3521
3861
|
expect(artist.before_remove_referenced_called).to be true
|
3522
3862
|
end
|
3523
3863
|
|
3524
|
-
it "removes the document from the
|
3864
|
+
it "removes the document from the association" do
|
3525
3865
|
expect(artist.albums).to be_empty
|
3526
3866
|
end
|
3527
3867
|
end
|
@@ -3536,7 +3876,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3536
3876
|
expect(artist.before_remove_referenced_called).to be true
|
3537
3877
|
end
|
3538
3878
|
|
3539
|
-
it "clears the
|
3879
|
+
it "clears the association" do
|
3540
3880
|
expect(artist.albums).to be_empty
|
3541
3881
|
end
|
3542
3882
|
end
|
@@ -3553,7 +3893,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3553
3893
|
begin; artist.albums.delete(album); rescue; end
|
3554
3894
|
end
|
3555
3895
|
|
3556
|
-
it "does not remove the document from the
|
3896
|
+
it "does not remove the document from the association" do
|
3557
3897
|
expect(artist.albums).to eq([ album ])
|
3558
3898
|
end
|
3559
3899
|
end
|
@@ -3564,7 +3904,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3564
3904
|
begin; artist.albums.clear; rescue; end
|
3565
3905
|
end
|
3566
3906
|
|
3567
|
-
it "does not clear the
|
3907
|
+
it "does not clear the association" do
|
3568
3908
|
expect(artist.albums).to eq([ album ])
|
3569
3909
|
end
|
3570
3910
|
end
|
@@ -3624,7 +3964,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3624
3964
|
begin; artist.albums.delete(album); rescue; end
|
3625
3965
|
end
|
3626
3966
|
|
3627
|
-
it "removes the documents from the
|
3967
|
+
it "removes the documents from the association" do
|
3628
3968
|
expect(artist.albums).to be_empty
|
3629
3969
|
end
|
3630
3970
|
end
|
@@ -3635,25 +3975,25 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3635
3975
|
begin; artist.albums.clear; rescue; end
|
3636
3976
|
end
|
3637
3977
|
|
3638
|
-
it "removes the documents from the
|
3978
|
+
it "removes the documents from the association" do
|
3639
3979
|
expect(artist.albums).to be_empty
|
3640
3980
|
end
|
3641
3981
|
end
|
3642
3982
|
end
|
3643
3983
|
end
|
3644
3984
|
|
3645
|
-
context "when executing a criteria call on an ordered
|
3985
|
+
context "when executing a criteria call on an ordered association" do
|
3646
3986
|
|
3647
3987
|
let(:person) do
|
3648
|
-
Person.create
|
3988
|
+
Person.create!
|
3649
3989
|
end
|
3650
3990
|
|
3651
3991
|
let!(:post_one) do
|
3652
|
-
person.ordered_posts.create(rating: 1)
|
3992
|
+
person.ordered_posts.create!(rating: 1)
|
3653
3993
|
end
|
3654
3994
|
|
3655
3995
|
let!(:post_two) do
|
3656
|
-
person.ordered_posts.create(rating: 5)
|
3996
|
+
person.ordered_posts.create!(rating: 5)
|
3657
3997
|
end
|
3658
3998
|
|
3659
3999
|
let(:criteria) do
|
@@ -3668,11 +4008,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3668
4008
|
context "when accessing a scope named open" do
|
3669
4009
|
|
3670
4010
|
let(:person) do
|
3671
|
-
Person.create
|
4011
|
+
Person.create!
|
3672
4012
|
end
|
3673
4013
|
|
3674
4014
|
let!(:post) do
|
3675
|
-
person.posts.create(title: "open")
|
4015
|
+
person.posts.create!(title: "open")
|
3676
4016
|
end
|
3677
4017
|
|
3678
4018
|
it "returns the appropriate documents" do
|
@@ -3680,18 +4020,18 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3680
4020
|
end
|
3681
4021
|
end
|
3682
4022
|
|
3683
|
-
context "when accessing a
|
4023
|
+
context "when accessing a association named parent" do
|
3684
4024
|
|
3685
4025
|
let!(:parent) do
|
3686
|
-
Odd.create(name: "odd parent")
|
4026
|
+
Odd.create!(name: "odd parent")
|
3687
4027
|
end
|
3688
4028
|
|
3689
4029
|
let(:child) do
|
3690
|
-
Even.create(parent_id: parent.id, name: "original even child")
|
4030
|
+
Even.create!(parent_id: parent.id, name: "original even child")
|
3691
4031
|
end
|
3692
4032
|
|
3693
4033
|
it "updates the child after accessing the parent" do
|
3694
|
-
# Access parent
|
4034
|
+
# Access parent association on the child to make sure it is loaded
|
3695
4035
|
child.parent
|
3696
4036
|
|
3697
4037
|
new_child_name = "updated even child"
|
@@ -3704,7 +4044,7 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3704
4044
|
end
|
3705
4045
|
end
|
3706
4046
|
|
3707
|
-
context 'when a document has referenced and embedded
|
4047
|
+
context 'when a document has referenced and embedded associations' do
|
3708
4048
|
|
3709
4049
|
let(:agent) do
|
3710
4050
|
Agent.new
|
@@ -3724,11 +4064,11 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3724
4064
|
end
|
3725
4065
|
|
3726
4066
|
it 'saves the document correctly' do
|
3727
|
-
expect(agent.save).to be(true)
|
4067
|
+
expect(agent.save!).to be(true)
|
3728
4068
|
end
|
3729
4069
|
end
|
3730
4070
|
|
3731
|
-
context 'when the two models use the same name to refer to the
|
4071
|
+
context 'when the two models use the same name to refer to the association' do
|
3732
4072
|
|
3733
4073
|
let(:agent) do
|
3734
4074
|
Agent.new
|
@@ -3740,8 +4080,8 @@ describe Mongoid::Association::Referenced::HasMany::Proxy do
|
|
3740
4080
|
|
3741
4081
|
before do
|
3742
4082
|
agent.same_name = band
|
3743
|
-
agent.save
|
3744
|
-
band.save
|
4083
|
+
agent.save!
|
4084
|
+
band.save!
|
3745
4085
|
band.reload
|
3746
4086
|
end
|
3747
4087
|
|