mongoid 3.1.5 → 8.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +636 -33
- data/LICENSE +2 -1
- data/README.md +32 -24
- data/Rakefile +75 -5
- data/lib/config/locales/en.yml +301 -132
- data/lib/mongoid/association/accessors.rb +431 -0
- data/lib/mongoid/association/bindable.rb +227 -0
- data/lib/mongoid/association/builders.rb +86 -0
- data/lib/mongoid/association/constrainable.rb +42 -0
- data/lib/mongoid/association/depending.rb +128 -0
- data/lib/mongoid/association/eager_loadable.rb +57 -0
- data/lib/mongoid/association/embedded/batchable.rb +398 -0
- data/lib/mongoid/association/embedded/cyclic.rb +102 -0
- data/lib/mongoid/association/embedded/embedded_in/binding.rb +74 -0
- data/lib/mongoid/association/embedded/embedded_in/buildable.rb +38 -0
- data/lib/mongoid/association/embedded/embedded_in/proxy.rb +111 -0
- data/lib/mongoid/association/embedded/embedded_in.rb +135 -0
- data/lib/mongoid/association/embedded/embeds_many/binding.rb +42 -0
- data/lib/mongoid/association/embedded/embeds_many/buildable.rb +45 -0
- data/lib/mongoid/association/embedded/embeds_many/proxy.rb +571 -0
- data/lib/mongoid/association/embedded/embeds_many.rb +183 -0
- data/lib/mongoid/association/embedded/embeds_one/binding.rb +43 -0
- data/lib/mongoid/association/embedded/embeds_one/buildable.rb +53 -0
- data/lib/mongoid/association/embedded/embeds_one/proxy.rb +164 -0
- data/lib/mongoid/association/embedded/embeds_one.rb +150 -0
- data/lib/mongoid/association/embedded.rb +6 -0
- data/lib/mongoid/association/macros.rb +228 -0
- data/lib/mongoid/association/many.rb +202 -0
- data/lib/mongoid/association/marshalable.rb +31 -0
- data/lib/mongoid/association/nested/many.rb +192 -0
- data/lib/mongoid/association/nested/nested_buildable.rb +66 -0
- data/lib/mongoid/association/nested/one.rb +116 -0
- data/lib/mongoid/association/nested.rb +15 -0
- data/lib/mongoid/association/one.rb +53 -0
- data/lib/mongoid/association/options.rb +122 -0
- data/lib/mongoid/association/proxy.rb +200 -0
- data/lib/mongoid/association/referenced/auto_save.rb +74 -0
- data/lib/mongoid/association/referenced/belongs_to/binding.rb +83 -0
- data/lib/mongoid/association/referenced/belongs_to/buildable.rb +48 -0
- data/lib/mongoid/association/referenced/belongs_to/eager.rb +73 -0
- data/lib/mongoid/association/referenced/belongs_to/proxy.rb +124 -0
- data/lib/mongoid/association/referenced/belongs_to.rb +226 -0
- data/lib/mongoid/association/referenced/counter_cache.rb +152 -0
- data/lib/mongoid/association/referenced/eager.rb +163 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/binding.rb +72 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/buildable.rb +40 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/eager.rb +53 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many/proxy.rb +345 -0
- data/lib/mongoid/association/referenced/has_and_belongs_to_many.rb +273 -0
- data/lib/mongoid/association/referenced/has_many/binding.rb +36 -0
- data/lib/mongoid/association/referenced/has_many/buildable.rb +38 -0
- data/lib/mongoid/association/referenced/has_many/eager.rb +44 -0
- data/lib/mongoid/association/referenced/has_many/enumerable.rb +494 -0
- data/lib/mongoid/association/referenced/has_many/proxy.rb +551 -0
- data/lib/mongoid/association/referenced/has_many.rb +251 -0
- data/lib/mongoid/association/referenced/has_one/binding.rb +42 -0
- data/lib/mongoid/association/referenced/has_one/buildable.rb +74 -0
- data/lib/mongoid/association/referenced/has_one/eager.rb +36 -0
- data/lib/mongoid/association/referenced/has_one/nested_builder.rb +113 -0
- data/lib/mongoid/association/referenced/has_one/proxy.rb +108 -0
- data/lib/mongoid/association/referenced/has_one.rb +184 -0
- data/lib/mongoid/association/referenced/syncable.rb +155 -0
- data/lib/mongoid/association/referenced.rb +9 -0
- data/lib/mongoid/association/reflections.rb +69 -0
- data/lib/mongoid/association/relatable.rb +489 -0
- data/lib/mongoid/association.rb +135 -0
- data/lib/mongoid/atomic/modifiers.rb +41 -61
- data/lib/mongoid/atomic/paths/embedded/many.rb +24 -8
- data/lib/mongoid/atomic/paths/embedded/one.rb +5 -8
- data/lib/mongoid/atomic/paths/embedded.rb +3 -34
- data/lib/mongoid/atomic/paths/root.rb +4 -20
- data/lib/mongoid/atomic/paths.rb +2 -1
- data/lib/mongoid/atomic.rb +52 -69
- data/lib/mongoid/attributes/dynamic.rb +141 -0
- data/lib/mongoid/attributes/nested.rb +93 -0
- data/lib/mongoid/attributes/processing.rb +35 -97
- data/lib/mongoid/attributes/projector.rb +119 -0
- data/lib/mongoid/attributes/readonly.rb +27 -10
- data/lib/mongoid/attributes.rb +159 -181
- data/lib/mongoid/cacheable.rb +33 -0
- data/lib/mongoid/changeable.rb +420 -0
- data/lib/mongoid/clients/factory.rb +105 -0
- data/lib/mongoid/clients/options.rb +111 -0
- data/lib/mongoid/clients/sessions.rb +113 -0
- data/lib/mongoid/clients/storage_options.rb +79 -0
- data/lib/mongoid/clients/validators/storage.rb +58 -0
- data/lib/mongoid/clients/validators.rb +3 -0
- data/lib/mongoid/clients.rb +79 -0
- data/lib/mongoid/composable.rb +128 -0
- data/lib/mongoid/config/environment.rb +51 -13
- data/lib/mongoid/config/options.rb +30 -18
- data/lib/mongoid/config/validators/client.rb +128 -0
- data/lib/mongoid/config/validators/option.rb +3 -4
- data/lib/mongoid/config/validators.rb +3 -2
- data/lib/mongoid/config.rb +170 -89
- data/lib/mongoid/contextual/aggregable/memory.rb +40 -27
- data/lib/mongoid/contextual/aggregable/mongo.rb +33 -36
- data/lib/mongoid/contextual/aggregable/none.rb +65 -0
- data/lib/mongoid/contextual/aggregable.rb +17 -0
- data/lib/mongoid/contextual/atomic.rb +80 -79
- data/lib/mongoid/contextual/command.rb +8 -11
- data/lib/mongoid/contextual/geo_near.rb +42 -44
- data/lib/mongoid/contextual/map_reduce.rb +33 -127
- data/lib/mongoid/contextual/memory.rb +226 -88
- data/lib/mongoid/contextual/mongo.rb +466 -293
- data/lib/mongoid/contextual/none.rb +193 -0
- data/lib/mongoid/contextual/queryable.rb +3 -4
- data/lib/mongoid/contextual.rb +11 -11
- data/lib/mongoid/copyable.rb +68 -20
- data/lib/mongoid/criteria/findable.rb +143 -0
- data/lib/mongoid/criteria/includable.rb +92 -0
- data/lib/mongoid/criteria/inspectable.rb +24 -0
- data/lib/mongoid/criteria/marshalable.rb +55 -0
- data/lib/mongoid/criteria/modifiable.rb +235 -0
- data/lib/mongoid/criteria/options.rb +24 -0
- data/lib/mongoid/criteria/permission.rb +71 -0
- data/lib/mongoid/criteria/queryable/aggregable.rb +109 -0
- data/lib/mongoid/criteria/queryable/expandable.rb +68 -0
- data/lib/mongoid/criteria/queryable/extensions/array.rb +151 -0
- data/lib/mongoid/criteria/queryable/extensions/big_decimal.rb +57 -0
- data/lib/mongoid/criteria/queryable/extensions/boolean.rb +33 -0
- data/lib/mongoid/criteria/queryable/extensions/date.rb +63 -0
- data/lib/mongoid/criteria/queryable/extensions/date_time.rb +52 -0
- data/lib/mongoid/criteria/queryable/extensions/hash.rb +163 -0
- data/lib/mongoid/criteria/queryable/extensions/nil_class.rb +75 -0
- data/lib/mongoid/criteria/queryable/extensions/numeric.rb +81 -0
- data/lib/mongoid/criteria/queryable/extensions/object.rb +182 -0
- data/lib/mongoid/criteria/queryable/extensions/range.rb +102 -0
- data/lib/mongoid/criteria/queryable/extensions/regexp.rb +72 -0
- data/lib/mongoid/criteria/queryable/extensions/set.rb +33 -0
- data/lib/mongoid/criteria/queryable/extensions/string.rb +122 -0
- data/lib/mongoid/criteria/queryable/extensions/symbol.rb +74 -0
- data/lib/mongoid/criteria/queryable/extensions/time.rb +60 -0
- data/lib/mongoid/criteria/queryable/extensions/time_with_zone.rb +66 -0
- data/lib/mongoid/criteria/queryable/extensions.rb +25 -0
- data/lib/mongoid/criteria/queryable/key.rb +177 -0
- data/lib/mongoid/criteria/queryable/macroable.rb +26 -0
- data/lib/mongoid/criteria/queryable/mergeable.rb +434 -0
- data/lib/mongoid/criteria/queryable/optional.rb +380 -0
- data/lib/mongoid/criteria/queryable/options.rb +136 -0
- data/lib/mongoid/criteria/queryable/pipeline.rb +106 -0
- data/lib/mongoid/criteria/queryable/selectable.rb +937 -0
- data/lib/mongoid/criteria/queryable/selector.rb +287 -0
- data/lib/mongoid/criteria/queryable/smash.rb +128 -0
- data/lib/mongoid/criteria/queryable/storable.rb +237 -0
- data/lib/mongoid/criteria/queryable.rb +90 -0
- data/lib/mongoid/criteria/scopable.rb +166 -0
- data/lib/mongoid/criteria.rb +177 -189
- data/lib/mongoid/deprecable.rb +36 -0
- data/lib/mongoid/deprecation.rb +25 -0
- data/lib/mongoid/document.rb +193 -139
- data/lib/mongoid/equality.rb +35 -18
- data/lib/mongoid/errors/ambiguous_relationship.rb +5 -6
- 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 +22 -0
- data/lib/mongoid/errors/document_not_found.rb +36 -21
- data/lib/mongoid/errors/empty_config_file.rb +25 -0
- data/lib/mongoid/errors/in_memory_collation_not_supported.rb +19 -0
- data/lib/mongoid/errors/invalid_collection.rb +2 -1
- data/lib/mongoid/errors/invalid_config_file.rb +25 -0
- data/lib/mongoid/errors/invalid_config_option.rb +3 -4
- data/lib/mongoid/errors/invalid_dependent_strategy.rb +31 -0
- data/lib/mongoid/errors/invalid_discriminator_key_target.rb +24 -0
- data/lib/mongoid/errors/invalid_dot_dollar_assignment.rb +23 -0
- data/lib/mongoid/errors/invalid_elem_match_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_estimated_count_criteria.rb +25 -0
- data/lib/mongoid/errors/invalid_expression_operator.rb +27 -0
- data/lib/mongoid/errors/invalid_field.rb +10 -9
- data/lib/mongoid/errors/invalid_field_operator.rb +32 -0
- data/lib/mongoid/errors/invalid_field_option.rb +2 -3
- data/lib/mongoid/errors/invalid_field_type.rb +26 -0
- data/lib/mongoid/errors/invalid_find.rb +2 -3
- data/lib/mongoid/errors/invalid_includes.rb +2 -3
- data/lib/mongoid/errors/invalid_index.rb +2 -3
- data/lib/mongoid/errors/invalid_options.rb +4 -5
- data/lib/mongoid/errors/invalid_path.rb +2 -3
- data/lib/mongoid/errors/invalid_persistence_option.rb +26 -0
- data/lib/mongoid/errors/invalid_query.rb +40 -0
- data/lib/mongoid/errors/invalid_relation.rb +61 -0
- data/lib/mongoid/errors/invalid_relation_option.rb +28 -0
- data/lib/mongoid/errors/invalid_scope.rb +2 -3
- data/lib/mongoid/errors/invalid_session_use.rb +21 -0
- data/lib/mongoid/errors/invalid_set_polymorphic_relation.rb +6 -5
- data/lib/mongoid/errors/invalid_storage_options.rb +4 -5
- data/lib/mongoid/errors/invalid_storage_parent.rb +25 -0
- data/lib/mongoid/errors/invalid_time.rb +2 -3
- data/lib/mongoid/errors/inverse_not_found.rb +4 -5
- data/lib/mongoid/errors/mixed_client_configuration.rb +27 -0
- data/lib/mongoid/errors/mixed_relations.rb +2 -3
- data/lib/mongoid/errors/mongoid_error.rb +22 -23
- data/lib/mongoid/errors/nested_attributes_metadata_not_found.rb +3 -4
- data/lib/mongoid/errors/no_client_config.rb +21 -0
- data/lib/mongoid/errors/no_client_database.rb +26 -0
- data/lib/mongoid/errors/no_client_hosts.rb +26 -0
- data/lib/mongoid/errors/no_clients_config.rb +19 -0
- data/lib/mongoid/errors/no_default_client.rb +22 -0
- data/lib/mongoid/errors/no_environment.rb +2 -3
- data/lib/mongoid/errors/no_map_reduce_output.rb +2 -3
- data/lib/mongoid/errors/no_metadata.rb +2 -3
- data/lib/mongoid/errors/no_parent.rb +2 -3
- data/lib/mongoid/errors/readonly_attribute.rb +3 -4
- data/lib/mongoid/errors/readonly_document.rb +21 -0
- data/lib/mongoid/errors/scope_overwrite.rb +2 -1
- data/lib/mongoid/errors/too_many_nested_attribute_records.rb +3 -1
- data/lib/mongoid/errors/unknown_attribute.rb +3 -4
- data/lib/mongoid/errors/unknown_model.rb +24 -0
- 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 +30 -9
- data/lib/mongoid/evolvable.rb +4 -5
- data/lib/mongoid/extensions/array.rb +45 -52
- data/lib/mongoid/extensions/big_decimal.rb +41 -22
- data/lib/mongoid/extensions/binary.rb +42 -0
- data/lib/mongoid/extensions/boolean.rb +19 -17
- data/lib/mongoid/extensions/date.rb +33 -23
- data/lib/mongoid/extensions/date_time.rb +5 -13
- data/lib/mongoid/extensions/decimal128.rb +36 -0
- data/lib/mongoid/extensions/false_class.rb +5 -8
- data/lib/mongoid/extensions/float.rb +11 -16
- data/lib/mongoid/extensions/hash.rb +88 -49
- data/lib/mongoid/extensions/integer.rb +10 -18
- data/lib/mongoid/extensions/module.rb +3 -4
- data/lib/mongoid/extensions/nil_class.rb +2 -5
- data/lib/mongoid/extensions/object.rb +38 -62
- data/lib/mongoid/extensions/object_id.rb +7 -12
- data/lib/mongoid/extensions/range.rb +46 -17
- data/lib/mongoid/extensions/regexp.rb +15 -8
- data/lib/mongoid/extensions/set.rb +17 -15
- data/lib/mongoid/extensions/string.rb +40 -80
- data/lib/mongoid/extensions/symbol.rb +7 -23
- data/lib/mongoid/extensions/time.rb +42 -25
- data/lib/mongoid/extensions/time_with_zone.rb +27 -10
- data/lib/mongoid/extensions/true_class.rb +5 -8
- data/lib/mongoid/extensions.rb +31 -13
- data/lib/mongoid/factory.rb +99 -11
- data/lib/mongoid/fields/foreign_key.rb +26 -34
- data/lib/mongoid/fields/localized.rb +24 -13
- data/lib/mongoid/fields/standard.rb +19 -73
- data/lib/mongoid/fields/validators/macro.rb +56 -15
- data/lib/mongoid/fields/validators.rb +2 -1
- data/lib/mongoid/fields.rb +342 -87
- data/lib/mongoid/findable.rb +219 -0
- data/lib/mongoid/indexable/specification.rb +103 -0
- data/lib/mongoid/indexable/validators/options.rb +110 -0
- data/lib/mongoid/indexable.rb +148 -0
- data/lib/mongoid/inspectable.rb +52 -0
- data/lib/mongoid/interceptable.rb +312 -0
- data/lib/mongoid/loggable.rb +15 -18
- data/lib/mongoid/matchable.rb +23 -0
- 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 +115 -0
- data/lib/mongoid/persistable/creatable.rb +181 -0
- data/lib/mongoid/persistable/deletable.rb +132 -0
- data/lib/mongoid/persistable/destroyable.rb +57 -0
- data/lib/mongoid/persistable/incrementable.rb +35 -0
- data/lib/mongoid/persistable/logical.rb +36 -0
- data/lib/mongoid/persistable/poppable.rb +36 -0
- data/lib/mongoid/persistable/pullable.rb +50 -0
- data/lib/mongoid/persistable/pushable.rb +66 -0
- data/lib/mongoid/persistable/renamable.rb +37 -0
- data/lib/mongoid/persistable/savable.rb +47 -0
- data/lib/mongoid/persistable/settable.rb +93 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +165 -0
- data/lib/mongoid/persistable/upsertable.rb +51 -0
- data/lib/mongoid/persistable.rb +305 -0
- data/lib/mongoid/persistence_context.rb +239 -0
- data/lib/mongoid/positional.rb +72 -0
- data/lib/mongoid/query_cache.rb +64 -0
- data/lib/mongoid/railtie.rb +35 -78
- data/lib/mongoid/railties/controller_runtime.rb +88 -0
- data/lib/mongoid/railties/database.rake +18 -25
- data/lib/mongoid/reloadable.rb +94 -0
- data/lib/mongoid/scopable.rb +324 -0
- data/lib/mongoid/selectable.rb +49 -0
- data/lib/mongoid/serializable.rb +170 -0
- data/lib/mongoid/shardable.rb +130 -0
- data/lib/mongoid/stateful.rb +134 -0
- data/lib/mongoid/stringified_symbol.rb +52 -0
- data/lib/mongoid/tasks/database.rake +38 -0
- data/lib/mongoid/tasks/database.rb +194 -0
- data/lib/mongoid/threaded/lifecycle.rb +28 -70
- data/lib/mongoid/threaded.rb +142 -219
- data/lib/mongoid/timestamps/created/short.rb +2 -1
- data/lib/mongoid/timestamps/created.rb +9 -5
- data/lib/mongoid/timestamps/short.rb +2 -1
- data/lib/mongoid/timestamps/timeless.rb +52 -16
- data/lib/mongoid/timestamps/updated/short.rb +4 -3
- data/lib/mongoid/timestamps/updated.rb +14 -9
- data/lib/mongoid/timestamps.rb +4 -3
- data/lib/mongoid/touchable.rb +131 -0
- data/lib/mongoid/traversable.rb +337 -0
- data/lib/mongoid/validatable/associated.rb +47 -0
- data/lib/mongoid/validatable/format.rb +21 -0
- data/lib/mongoid/validatable/length.rb +21 -0
- data/lib/mongoid/validatable/localizable.rb +29 -0
- data/lib/mongoid/validatable/macros.rb +89 -0
- data/lib/mongoid/validatable/presence.rb +81 -0
- data/lib/mongoid/validatable/queryable.rb +29 -0
- data/lib/mongoid/validatable/uniqueness.rb +304 -0
- data/lib/mongoid/validatable.rb +160 -0
- data/lib/mongoid/version.rb +3 -2
- data/lib/mongoid/warnings.rb +28 -0
- data/lib/mongoid.rb +68 -109
- data/lib/rails/generators/mongoid/config/config_generator.rb +10 -2
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +150 -45
- data/lib/rails/generators/mongoid/model/model_generator.rb +3 -3
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +1 -4
- data/lib/rails/generators/mongoid_generator.rb +5 -41
- data/lib/rails/mongoid.rb +6 -129
- data/spec/README.md +33 -0
- data/spec/config/mongoid.yml +56 -25
- data/spec/config/mongoid_with_schema_map_uuid.yml +27 -0
- data/spec/integration/app_spec.rb +345 -0
- data/spec/integration/associations/belongs_to_spec.rb +33 -0
- data/spec/integration/associations/embedded_dirty_spec.rb +57 -0
- data/spec/integration/associations/embedded_spec.rb +283 -0
- data/spec/integration/associations/embeds_many_spec.rb +219 -0
- data/spec/integration/associations/embeds_one_spec.rb +41 -0
- data/spec/integration/associations/foreign_key_spec.rb +107 -0
- data/spec/integration/associations/foreign_key_spec_models.rb +64 -0
- data/spec/integration/associations/has_and_belongs_to_many_spec.rb +21 -0
- data/spec/integration/associations/has_many_spec.rb +128 -0
- data/spec/integration/associations/has_one_spec.rb +272 -0
- data/spec/integration/associations/nested_attributes_assignment_spec.rb +115 -0
- data/spec/integration/associations/reverse_population_spec.rb +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 +155 -0
- data/spec/integration/callbacks_spec.rb +450 -0
- data/spec/integration/contextual/empty_spec.rb +141 -0
- data/spec/integration/criteria/alias_query_spec.rb +161 -0
- data/spec/integration/criteria/date_field_spec.rb +40 -0
- data/spec/integration/criteria/default_scope_spec.rb +72 -0
- data/spec/integration/criteria/logical_spec.rb +124 -0
- data/spec/integration/criteria/range_spec.rb +359 -0
- data/spec/integration/criteria/time_with_zone_spec.rb +142 -0
- data/spec/integration/discriminator_key_spec.rb +392 -0
- data/spec/integration/discriminator_value_spec.rb +206 -0
- data/spec/integration/document_spec.rb +51 -0
- data/spec/integration/dots_and_dollars_spec.rb +277 -0
- data/spec/integration/i18n_fallbacks_spec.rb +89 -0
- data/spec/integration/matcher_examples_spec.rb +765 -0
- data/spec/integration/matcher_operator_data/all.yml +140 -0
- data/spec/integration/matcher_operator_data/and.yml +93 -0
- data/spec/integration/matcher_operator_data/bits_all_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_all_set.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_clear.yml +159 -0
- data/spec/integration/matcher_operator_data/bits_any_set.yml +159 -0
- data/spec/integration/matcher_operator_data/comment.yml +22 -0
- data/spec/integration/matcher_operator_data/elem_match.yml +409 -0
- data/spec/integration/matcher_operator_data/elem_match_expr.yml +213 -0
- data/spec/integration/matcher_operator_data/eq.yml +191 -0
- data/spec/integration/matcher_operator_data/exists.yml +213 -0
- data/spec/integration/matcher_operator_data/generic_op.yml +17 -0
- data/spec/integration/matcher_operator_data/gt.yml +132 -0
- data/spec/integration/matcher_operator_data/gt_types.yml +63 -0
- data/spec/integration/matcher_operator_data/gte.yml +132 -0
- data/spec/integration/matcher_operator_data/gte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/implicit.yml +331 -0
- data/spec/integration/matcher_operator_data/implicit_traversal.yml +112 -0
- data/spec/integration/matcher_operator_data/in.yml +210 -0
- data/spec/integration/matcher_operator_data/invalid_op.yml +59 -0
- data/spec/integration/matcher_operator_data/invalid_syntax.yml +39 -0
- data/spec/integration/matcher_operator_data/lt.yml +132 -0
- data/spec/integration/matcher_operator_data/lt_types.yml +15 -0
- data/spec/integration/matcher_operator_data/lte.yml +132 -0
- data/spec/integration/matcher_operator_data/lte_types.yml +15 -0
- data/spec/integration/matcher_operator_data/mod.yml +55 -0
- data/spec/integration/matcher_operator_data/multiple.yml +29 -0
- data/spec/integration/matcher_operator_data/ne.yml +150 -0
- data/spec/integration/matcher_operator_data/ne_types.yml +15 -0
- data/spec/integration/matcher_operator_data/nin.yml +114 -0
- data/spec/integration/matcher_operator_data/nor.yml +126 -0
- data/spec/integration/matcher_operator_data/not.yml +196 -0
- data/spec/integration/matcher_operator_data/or.yml +137 -0
- data/spec/integration/matcher_operator_data/regex.yml +174 -0
- data/spec/integration/matcher_operator_data/regex_options.yml +72 -0
- data/spec/integration/matcher_operator_data/size.yml +174 -0
- data/spec/integration/matcher_operator_data/type.yml +70 -0
- data/spec/integration/matcher_operator_data/type_array.yml +16 -0
- data/spec/integration/matcher_operator_data/type_binary.yml +18 -0
- data/spec/integration/matcher_operator_data/type_boolean.yml +39 -0
- data/spec/integration/matcher_operator_data/type_code.yml +26 -0
- data/spec/integration/matcher_operator_data/type_code_with_scope.yml +26 -0
- data/spec/integration/matcher_operator_data/type_date.yml +39 -0
- data/spec/integration/matcher_operator_data/type_db_pointer.yml +19 -0
- data/spec/integration/matcher_operator_data/type_decimal.yml +41 -0
- data/spec/integration/matcher_operator_data/type_double.yml +15 -0
- data/spec/integration/matcher_operator_data/type_int32.yml +33 -0
- data/spec/integration/matcher_operator_data/type_int64.yml +33 -0
- data/spec/integration/matcher_operator_data/type_max_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_min_key.yml +17 -0
- data/spec/integration/matcher_operator_data/type_null.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object.yml +23 -0
- data/spec/integration/matcher_operator_data/type_object_id.yml +25 -0
- data/spec/integration/matcher_operator_data/type_regex.yml +44 -0
- data/spec/integration/matcher_operator_data/type_string.yml +15 -0
- data/spec/integration/matcher_operator_data/type_symbol.yml +32 -0
- data/spec/integration/matcher_operator_data/type_timestamp.yml +25 -0
- data/spec/integration/matcher_operator_data/type_undefined.yml +17 -0
- data/spec/integration/matcher_operator_spec.rb +122 -0
- data/spec/integration/matcher_spec.rb +283 -0
- data/spec/integration/persistence/range_field_spec.rb +350 -0
- data/spec/integration/server_query_spec.rb +141 -0
- data/spec/integration/shardable_spec.rb +148 -0
- data/spec/integration/stringified_symbol_field_spec.rb +203 -0
- data/spec/lite_spec_helper.rb +83 -0
- data/spec/mongoid/association/accessors_spec.rb +1067 -0
- data/spec/mongoid/association/auto_save_spec.rb +403 -0
- data/spec/mongoid/association/builders_spec.rb +255 -0
- data/spec/mongoid/association/constrainable_spec.rb +117 -0
- data/spec/mongoid/association/counter_cache_spec.rb +452 -0
- data/spec/mongoid/association/depending_spec.rb +959 -0
- data/spec/mongoid/association/eager_spec.rb +282 -0
- data/spec/mongoid/association/embedded/cyclic_spec.rb +180 -0
- data/spec/mongoid/association/embedded/dirty_spec.rb +67 -0
- data/spec/mongoid/association/embedded/embedded_in/binding_spec.rb +174 -0
- data/spec/mongoid/association/embedded/embedded_in/buildable_spec.rb +90 -0
- data/spec/mongoid/association/embedded/embedded_in/proxy_spec.rb +619 -0
- data/spec/mongoid/association/embedded/embedded_in_spec.rb +903 -0
- data/spec/mongoid/association/embedded/embeds_many/binding_spec.rb +56 -0
- data/spec/mongoid/association/embedded/embeds_many/buildable_spec.rb +218 -0
- data/spec/mongoid/association/embedded/embeds_many/proxy_spec.rb +4863 -0
- data/spec/mongoid/association/embedded/embeds_many_models.rb +226 -0
- data/spec/mongoid/association/embedded/embeds_many_query_spec.rb +63 -0
- data/spec/mongoid/association/embedded/embeds_many_spec.rb +932 -0
- data/spec/mongoid/association/embedded/embeds_one/binding_spec.rb +79 -0
- data/spec/mongoid/association/embedded/embeds_one/buildable_spec.rb +106 -0
- data/spec/mongoid/association/embedded/embeds_one/proxy_spec.rb +1025 -0
- data/spec/mongoid/association/embedded/embeds_one_dnl_models.rb +8 -0
- data/spec/mongoid/association/embedded/embeds_one_models.rb +73 -0
- data/spec/mongoid/association/embedded/embeds_one_query_spec.rb +28 -0
- data/spec/mongoid/association/embedded/embeds_one_spec.rb +984 -0
- data/spec/mongoid/association/macros_spec.rb +1116 -0
- data/spec/mongoid/association/nested/many_spec.rb +232 -0
- data/spec/mongoid/association/nested/one_spec.rb +253 -0
- data/spec/mongoid/association/options_spec.rb +1323 -0
- data/spec/mongoid/association/polymorphic_spec.rb +162 -0
- data/spec/mongoid/association/referenced/belongs_to/binding_spec.rb +244 -0
- data/spec/mongoid/association/referenced/belongs_to/buildable_spec.rb +292 -0
- data/spec/mongoid/association/referenced/belongs_to/eager_spec.rb +412 -0
- data/spec/mongoid/association/referenced/belongs_to/proxy_spec.rb +1388 -0
- data/spec/mongoid/association/referenced/belongs_to_models.rb +11 -0
- data/spec/mongoid/association/referenced/belongs_to_query_spec.rb +57 -0
- data/spec/mongoid/association/referenced/belongs_to_spec.rb +2046 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/binding_spec.rb +180 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/buildable_spec.rb +148 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/eager_spec.rb +196 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_persistence_spec.rb +76 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many/proxy_spec.rb +3836 -0
- data/spec/mongoid/association/referenced/has_and_belongs_to_many_models.rb +92 -0
- 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 +1104 -0
- data/spec/mongoid/association/referenced/has_many/binding_spec.rb +155 -0
- data/spec/mongoid/association/referenced/has_many/buildable_spec.rb +251 -0
- data/spec/mongoid/association/referenced/has_many/eager_spec.rb +290 -0
- data/spec/mongoid/association/referenced/has_many/enumerable_spec.rb +2232 -0
- data/spec/mongoid/association/referenced/has_many/proxy_query_spec.rb +23 -0
- data/spec/mongoid/association/referenced/has_many/proxy_spec.rb +4161 -0
- data/spec/mongoid/association/referenced/has_many_models.rb +97 -0
- data/spec/mongoid/association/referenced/has_many_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_many_spec.rb +1273 -0
- data/spec/mongoid/association/referenced/has_one/binding_spec.rb +133 -0
- data/spec/mongoid/association/referenced/has_one/buildable_spec.rb +159 -0
- data/spec/mongoid/association/referenced/has_one/eager_spec.rb +193 -0
- data/spec/mongoid/association/referenced/has_one/proxy_spec.rb +1248 -0
- data/spec/mongoid/association/referenced/has_one_models.rb +113 -0
- data/spec/mongoid/association/referenced/has_one_query_spec.rb +37 -0
- data/spec/mongoid/association/referenced/has_one_spec.rb +1383 -0
- data/spec/mongoid/association/reflections_spec.rb +92 -0
- data/spec/mongoid/association/syncable_spec.rb +513 -0
- data/spec/mongoid/association_spec.rb +191 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +88 -39
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +10 -49
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +9 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +5 -61
- data/spec/mongoid/atomic/paths_spec.rb +115 -35
- data/spec/mongoid/atomic_spec.rb +89 -42
- data/spec/mongoid/attributes/dynamic_spec.rb +152 -0
- data/spec/mongoid/attributes/nested_spec.rb +5000 -0
- data/spec/mongoid/attributes/nested_spec_models.rb +48 -0
- data/spec/mongoid/attributes/projector_data/embedded.yml +105 -0
- data/spec/mongoid/attributes/projector_data/fields.yml +93 -0
- data/spec/mongoid/attributes/projector_spec.rb +40 -0
- data/spec/mongoid/attributes/readonly_spec.rb +166 -64
- data/spec/mongoid/attributes_spec.rb +1418 -409
- data/spec/mongoid/cacheable_spec.rb +114 -0
- data/spec/mongoid/changeable_spec.rb +1914 -0
- data/spec/mongoid/clients/factory_spec.rb +426 -0
- data/spec/mongoid/clients/options_spec.rb +521 -0
- data/spec/mongoid/clients/sessions_spec.rb +297 -0
- data/spec/mongoid/clients/transactions_spec.rb +415 -0
- data/spec/mongoid/clients_spec.rb +1084 -0
- data/spec/mongoid/composable_spec.rb +33 -0
- data/spec/mongoid/config/environment_spec.rb +138 -17
- data/spec/mongoid/config/options_spec.rb +26 -7
- data/spec/mongoid/config_spec.rb +607 -93
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +433 -153
- data/spec/mongoid/contextual/aggregable/memory_table.yml +88 -0
- data/spec/mongoid/contextual/aggregable/memory_table_spec.rb +62 -0
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +221 -56
- data/spec/mongoid/contextual/aggregable/none_spec.rb +60 -0
- data/spec/mongoid/contextual/atomic_spec.rb +577 -162
- data/spec/mongoid/contextual/geo_near_spec.rb +104 -38
- data/spec/mongoid/contextual/map_reduce_spec.rb +137 -142
- data/spec/mongoid/contextual/memory_spec.rb +1880 -269
- data/spec/mongoid/contextual/mongo_spec.rb +2523 -601
- data/spec/mongoid/contextual/none_spec.rb +123 -0
- data/spec/mongoid/copyable_spec.rb +833 -76
- data/spec/mongoid/copyable_spec_models.rb +47 -0
- data/spec/mongoid/criteria/findable_spec.rb +1132 -0
- data/spec/mongoid/criteria/includable_spec.rb +1492 -0
- data/spec/mongoid/criteria/includable_spec_models.rb +54 -0
- data/spec/mongoid/criteria/inspectable_spec.rb +29 -0
- data/spec/mongoid/criteria/marshalable_spec.rb +47 -0
- data/spec/mongoid/criteria/modifiable_spec.rb +1812 -0
- data/spec/mongoid/criteria/options_spec.rb +31 -0
- data/spec/mongoid/criteria/queryable/aggregable_spec.rb +372 -0
- data/spec/mongoid/criteria/queryable/expandable_spec.rb +61 -0
- data/spec/mongoid/criteria/queryable/extensions/array_spec.rb +513 -0
- data/spec/mongoid/criteria/queryable/extensions/big_decimal_spec.rb +169 -0
- data/spec/mongoid/criteria/queryable/extensions/bignum_spec.rb +60 -0
- data/spec/mongoid/criteria/queryable/extensions/boolean_spec.rb +215 -0
- data/spec/mongoid/criteria/queryable/extensions/date_spec.rb +343 -0
- data/spec/mongoid/criteria/queryable/extensions/date_time_spec.rb +434 -0
- data/spec/mongoid/criteria/queryable/extensions/fixnum_spec.rb +60 -0
- data/spec/mongoid/criteria/queryable/extensions/float_spec.rb +67 -0
- data/spec/mongoid/criteria/queryable/extensions/hash_spec.rb +314 -0
- data/spec/mongoid/criteria/queryable/extensions/integer_spec.rb +67 -0
- data/spec/mongoid/criteria/queryable/extensions/nil_class_spec.rb +79 -0
- data/spec/mongoid/criteria/queryable/extensions/numeric_spec.rb +119 -0
- data/spec/mongoid/criteria/queryable/extensions/object_spec.rb +110 -0
- data/spec/mongoid/criteria/queryable/extensions/range_spec.rb +370 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_raw_spec.rb +91 -0
- data/spec/mongoid/criteria/queryable/extensions/regexp_spec.rb +92 -0
- data/spec/mongoid/criteria/queryable/extensions/set_spec.rb +41 -0
- data/spec/mongoid/criteria/queryable/extensions/string_spec.rb +347 -0
- data/spec/mongoid/criteria/queryable/extensions/symbol_spec.rb +169 -0
- data/spec/mongoid/criteria/queryable/extensions/time_spec.rb +406 -0
- data/spec/mongoid/criteria/queryable/extensions/time_with_zone_spec.rb +387 -0
- data/spec/mongoid/criteria/queryable/key_spec.rb +96 -0
- data/spec/mongoid/criteria/queryable/mergeable_spec.rb +182 -0
- data/spec/mongoid/criteria/queryable/optional_spec.rb +1317 -0
- data/spec/mongoid/criteria/queryable/options_spec.rb +362 -0
- data/spec/mongoid/criteria/queryable/pipeline_spec.rb +214 -0
- data/spec/mongoid/criteria/queryable/queryable_spec.rb +139 -0
- data/spec/mongoid/criteria/queryable/selectable_logical_spec.rb +2119 -0
- data/spec/mongoid/criteria/queryable/selectable_shared_examples.rb +38 -0
- data/spec/mongoid/criteria/queryable/selectable_spec.rb +2462 -0
- data/spec/mongoid/criteria/queryable/selectable_where_spec.rb +589 -0
- data/spec/mongoid/criteria/queryable/selector_spec.rb +895 -0
- data/spec/mongoid/criteria/queryable/smash_spec.rb +32 -0
- data/spec/mongoid/criteria/queryable/storable_spec.rb +226 -0
- data/spec/mongoid/criteria/scopable_spec.rb +601 -0
- data/spec/mongoid/criteria_projection_spec.rb +410 -0
- data/spec/mongoid/criteria_spec.rb +1828 -3572
- data/spec/mongoid/document_fields_spec.rb +262 -0
- data/spec/mongoid/document_persistence_context_spec.rb +32 -0
- data/spec/mongoid/document_query_spec.rb +89 -0
- data/spec/mongoid/document_spec.rb +452 -221
- data/spec/mongoid/equality_spec.rb +155 -52
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +8 -6
- data/spec/mongoid/errors/callback_spec.rb +5 -3
- data/spec/mongoid/errors/delete_restriction_spec.rb +7 -5
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +35 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +89 -11
- data/spec/mongoid/errors/invalid_collection_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_config_file_spec.rb +31 -0
- data/spec/mongoid/errors/invalid_config_option_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_field_option_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_field_spec.rb +6 -4
- data/spec/mongoid/errors/invalid_field_type_spec.rb +55 -0
- data/spec/mongoid/errors/invalid_find_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_includes_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_index_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_options_spec.rb +7 -5
- data/spec/mongoid/errors/invalid_path_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_relation_spec.rb +39 -0
- data/spec/mongoid/errors/invalid_scope_spec.rb +7 -5
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +5 -3
- data/spec/mongoid/errors/invalid_time_spec.rb +5 -3
- data/spec/mongoid/errors/inverse_not_found_spec.rb +6 -4
- data/spec/mongoid/errors/mixed_client_configuration_spec.rb +31 -0
- data/spec/mongoid/errors/mixed_relations_spec.rb +5 -3
- data/spec/mongoid/errors/mongoid_error_spec.rb +45 -10
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +8 -6
- data/spec/mongoid/errors/no_client_config_spec.rb +31 -0
- data/spec/mongoid/errors/no_client_database_spec.rb +31 -0
- data/spec/mongoid/errors/no_client_hosts_spec.rb +31 -0
- data/spec/mongoid/errors/no_clients_config_spec.rb +31 -0
- data/spec/mongoid/errors/no_environment_spec.rb +8 -6
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +5 -3
- data/spec/mongoid/errors/no_metadata_spec.rb +5 -3
- data/spec/mongoid/errors/no_parent_spec.rb +6 -4
- data/spec/mongoid/errors/readonly_attribute_spec.rb +5 -3
- data/spec/mongoid/errors/readonly_document_spec.rb +31 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +5 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +6 -4
- data/spec/mongoid/errors/unknown_attribute_spec.rb +7 -5
- data/spec/mongoid/errors/unsaved_document_spec.rb +6 -4
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +5 -3
- data/spec/mongoid/errors/validations_spec.rb +9 -7
- data/spec/mongoid/extensions/array_spec.rb +108 -116
- data/spec/mongoid/extensions/big_decimal_spec.rb +838 -49
- data/spec/mongoid/extensions/binary_spec.rb +55 -18
- data/spec/mongoid/extensions/boolean_spec.rb +76 -74
- data/spec/mongoid/extensions/date_class_mongoize_spec.rb +339 -0
- data/spec/mongoid/extensions/date_spec.rb +59 -145
- data/spec/mongoid/extensions/date_time_spec.rb +35 -76
- data/spec/mongoid/extensions/decimal128_spec.rb +46 -0
- data/spec/mongoid/extensions/false_class_spec.rb +7 -5
- data/spec/mongoid/extensions/float_spec.rb +69 -62
- data/spec/mongoid/extensions/hash_spec.rb +197 -30
- data/spec/mongoid/extensions/integer_spec.rb +63 -65
- data/spec/mongoid/extensions/module_spec.rb +4 -2
- data/spec/mongoid/extensions/nil_class_spec.rb +3 -1
- data/spec/mongoid/extensions/object_id_spec.rb +136 -134
- data/spec/mongoid/extensions/object_spec.rb +53 -57
- data/spec/mongoid/extensions/range_spec.rb +287 -28
- data/spec/mongoid/extensions/regexp_spec.rb +71 -21
- data/spec/mongoid/extensions/set_spec.rb +112 -4
- data/spec/mongoid/extensions/string_spec.rb +188 -89
- data/spec/mongoid/extensions/stringified_symbol_spec.rb +84 -0
- data/spec/mongoid/extensions/symbol_spec.rb +25 -30
- data/spec/mongoid/extensions/time_spec.rb +703 -110
- data/spec/mongoid/extensions/time_with_zone_spec.rb +82 -67
- data/spec/mongoid/extensions/true_class_spec.rb +7 -5
- data/spec/mongoid/extensions_spec.rb +43 -0
- data/spec/mongoid/factory_spec.rb +374 -25
- data/spec/mongoid/fields/foreign_key_spec.rb +116 -92
- data/spec/mongoid/fields/localized_spec.rb +177 -35
- data/spec/mongoid/fields/standard_spec.rb +15 -13
- data/spec/mongoid/fields_spec.rb +952 -238
- data/spec/mongoid/findable_spec.rb +632 -0
- data/spec/mongoid/indexable/specification_spec.rb +129 -0
- data/spec/mongoid/indexable_spec.rb +643 -0
- data/spec/mongoid/inspectable_spec.rb +86 -0
- data/spec/mongoid/interceptable_spec.rb +2373 -0
- data/spec/mongoid/interceptable_spec_models.rb +307 -0
- data/spec/mongoid/loggable_spec.rb +3 -1
- data/spec/mongoid/matcher/extract_attribute_data/numeric_keys.yml +104 -0
- data/spec/mongoid/matcher/extract_attribute_data/traversal.yml +239 -0
- data/spec/mongoid/matcher/extract_attribute_spec.rb +36 -0
- data/spec/mongoid/mongoizable_spec.rb +285 -0
- data/spec/mongoid/persistable/creatable_spec.rb +662 -0
- data/spec/mongoid/persistable/deletable_spec.rb +514 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +455 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +241 -0
- data/spec/mongoid/persistable/logical_spec.rb +159 -0
- data/spec/mongoid/persistable/poppable_spec.rb +131 -0
- data/spec/mongoid/persistable/pullable_spec.rb +258 -0
- data/spec/mongoid/persistable/pushable_spec.rb +353 -0
- data/spec/mongoid/persistable/renamable_spec.rb +151 -0
- data/spec/mongoid/persistable/savable_spec.rb +684 -0
- data/spec/mongoid/persistable/settable_spec.rb +544 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +171 -0
- data/spec/mongoid/persistable/updatable_spec.rb +760 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +122 -0
- data/spec/mongoid/persistable_spec.rb +321 -0
- data/spec/mongoid/persistence_context_spec.rb +745 -0
- data/spec/mongoid/positional_spec.rb +223 -0
- data/spec/mongoid/query_cache_middleware_spec.rb +50 -0
- data/spec/mongoid/query_cache_spec.rb +870 -0
- data/spec/mongoid/relations/proxy_spec.rb +125 -47
- data/spec/mongoid/reloadable_spec.rb +665 -0
- data/spec/mongoid/scopable_spec.rb +1234 -0
- data/spec/mongoid/selectable_spec.rb +136 -0
- data/spec/mongoid/serializable_spec.rb +963 -0
- data/spec/mongoid/shardable_models.rb +61 -0
- data/spec/mongoid/shardable_spec.rb +204 -0
- data/spec/mongoid/stateful_spec.rb +157 -0
- data/spec/mongoid/tasks/database_rake_spec.rb +287 -0
- data/spec/mongoid/tasks/database_spec.rb +181 -0
- data/spec/mongoid/threaded_spec.rb +88 -78
- data/spec/mongoid/timestamps/created/short_spec.rb +9 -7
- data/spec/mongoid/timestamps/created_spec.rb +8 -6
- data/spec/mongoid/timestamps/timeless_spec.rb +29 -10
- data/spec/mongoid/timestamps/updated/short_spec.rb +16 -14
- data/spec/mongoid/timestamps/updated_spec.rb +14 -16
- data/spec/mongoid/timestamps_spec.rb +406 -18
- data/spec/mongoid/timestamps_spec_models.rb +67 -0
- data/spec/mongoid/touchable_spec.rb +704 -0
- data/spec/mongoid/touchable_spec_models.rb +57 -0
- data/spec/mongoid/traversable_spec.rb +1410 -0
- data/spec/mongoid/validatable/associated_spec.rb +208 -0
- data/spec/mongoid/validatable/format_spec.rb +85 -0
- data/spec/mongoid/validatable/length_spec.rb +225 -0
- data/spec/mongoid/validatable/numericality_spec.rb +32 -0
- data/spec/mongoid/validatable/presence_spec.rb +592 -0
- data/spec/mongoid/validatable/uniqueness_spec.rb +2504 -0
- data/spec/mongoid/validatable_spec.rb +327 -0
- data/spec/mongoid/warnings_spec.rb +35 -0
- data/spec/mongoid_spec.rb +20 -20
- data/spec/rails/controller_extension/controller_runtime_spec.rb +112 -0
- data/spec/rails/mongoid_spec.rb +37 -354
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +291 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +200 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +230 -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 +325 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +74 -0
- data/spec/shared/shlib/server.sh +392 -0
- data/spec/shared/shlib/set_env.sh +169 -0
- data/spec/spec_helper.rb +163 -42
- data/spec/support/authorization.rb +15 -0
- data/spec/support/client_registry.rb +9 -0
- data/spec/support/constraints.rb +77 -0
- data/spec/support/expectations.rb +32 -0
- data/spec/support/helpers.rb +11 -0
- data/spec/support/macros.rb +81 -0
- data/spec/support/models/account.rb +38 -0
- data/spec/support/models/acolyte.rb +19 -0
- data/spec/support/models/actor.rb +20 -0
- data/spec/support/models/actress.rb +4 -0
- data/spec/support/models/address.rb +85 -0
- data/spec/support/models/address_component.rb +7 -0
- data/spec/support/models/address_number.rb +8 -0
- data/spec/support/models/agency.rb +7 -0
- data/spec/support/models/agent.rb +18 -0
- data/spec/support/models/album.rb +20 -0
- data/spec/support/models/alert.rb +9 -0
- data/spec/support/models/animal.rb +28 -0
- data/spec/support/models/answer.rb +8 -0
- data/spec/support/models/appointment.rb +9 -0
- data/spec/support/models/armrest.rb +9 -0
- data/spec/support/models/array_field.rb +7 -0
- data/spec/support/models/article.rb +14 -0
- data/spec/support/models/artist.rb +91 -0
- data/spec/support/models/artwork.rb +6 -0
- data/spec/support/models/audible_sound.rb +3 -0
- data/spec/support/models/audio.rb +7 -0
- data/spec/support/models/augmentation.rb +25 -0
- data/spec/support/models/author.rb +8 -0
- data/spec/support/models/baby.rb +6 -0
- data/spec/support/models/band.rb +40 -0
- data/spec/support/models/bar.rb +12 -0
- data/spec/support/models/basic.rb +8 -0
- data/spec/support/models/bed.rb +3 -0
- data/spec/support/models/big_palette.rb +4 -0
- data/spec/support/models/birthday.rb +15 -0
- data/spec/support/models/bolt.rb +7 -0
- data/spec/support/models/bomb.rb +6 -0
- data/spec/support/models/book.rb +18 -0
- data/spec/support/models/breed.rb +6 -0
- data/spec/support/models/browser.rb +8 -0
- data/spec/support/models/building.rb +8 -0
- data/spec/support/models/building_address.rb +9 -0
- data/spec/support/models/bus.rb +9 -0
- data/spec/support/models/business.rb +7 -0
- data/spec/support/models/callback_test.rb +11 -0
- data/spec/support/models/canvas.rb +27 -0
- data/spec/support/models/car.rb +3 -0
- data/spec/support/models/cat.rb +10 -0
- data/spec/support/models/catalog.rb +24 -0
- data/spec/support/models/category.rb +10 -0
- data/spec/support/models/child.rb +6 -0
- data/spec/support/models/child_doc.rb +24 -0
- data/spec/support/models/church.rb +8 -0
- data/spec/support/models/circle.rb +5 -0
- data/spec/support/models/circuit.rb +6 -0
- data/spec/support/models/circus.rb +12 -0
- data/spec/support/models/code.rb +15 -0
- data/spec/support/models/coding/pull_request.rb +11 -0
- data/spec/support/models/coding.rb +3 -0
- data/spec/support/models/comment.rb +18 -0
- data/spec/support/models/company.rb +7 -0
- data/spec/support/models/consumption_period.rb +9 -0
- data/spec/support/models/contextable_item.rb +7 -0
- data/spec/support/models/contractor.rb +7 -0
- data/spec/support/models/cookie.rb +8 -0
- data/spec/support/models/country_code.rb +12 -0
- data/spec/support/models/courier_job.rb +6 -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/support/models/definition.rb +11 -0
- data/spec/support/models/delegating_patient.rb +15 -0
- data/spec/support/models/description.rb +13 -0
- data/spec/support/models/dictionary.rb +18 -0
- data/spec/support/models/division.rb +12 -0
- data/spec/support/models/doctor.rb +14 -0
- data/spec/support/models/dog.rb +9 -0
- data/spec/support/models/dokument.rb +8 -0
- data/spec/support/models/draft.rb +11 -0
- data/spec/support/models/dragon.rb +6 -0
- data/spec/support/models/driver.rb +9 -0
- data/spec/support/models/drug.rb +8 -0
- data/spec/support/models/dungeon.rb +6 -0
- data/spec/support/models/edit.rb +7 -0
- data/spec/support/models/email.rb +8 -0
- data/spec/support/models/employer.rb +7 -0
- data/spec/support/models/entry.rb +8 -0
- data/spec/support/models/eraser.rb +3 -0
- data/spec/support/models/even.rb +9 -0
- data/spec/support/models/event.rb +24 -0
- data/spec/support/models/exhibition.rb +6 -0
- data/spec/support/models/exhibitor.rb +8 -0
- data/spec/support/models/explosion.rb +6 -0
- data/spec/support/models/eye.rb +11 -0
- data/spec/support/models/eye_bowl.rb +11 -0
- data/spec/support/models/face.rb +10 -0
- data/spec/support/models/fanatic.rb +8 -0
- data/spec/support/models/favorite.rb +8 -0
- data/spec/support/models/filesystem.rb +7 -0
- data/spec/support/models/fire_hydrant.rb +8 -0
- data/spec/support/models/firefox.rb +6 -0
- data/spec/support/models/fish.rb +9 -0
- data/spec/support/models/folder.rb +9 -0
- data/spec/support/models/folder_item.rb +11 -0
- data/spec/support/models/fruits.rb +36 -0
- data/spec/support/models/game.rb +21 -0
- data/spec/support/models/ghost.rb +9 -0
- data/spec/support/models/guitar.rb +4 -0
- data/spec/support/models/hole.rb +12 -0
- data/spec/support/models/home.rb +6 -0
- data/spec/support/models/house.rb +8 -0
- data/spec/support/models/html_writer.rb +5 -0
- data/spec/support/models/id_key.rb +8 -0
- data/spec/support/models/idnodef.rb +7 -0
- data/spec/support/models/image.rb +24 -0
- data/spec/support/models/implant.rb +27 -0
- data/spec/support/models/instrument.rb +8 -0
- data/spec/support/models/item.rb +10 -0
- data/spec/support/models/jar.rb +9 -0
- data/spec/support/models/kaleidoscope.rb +8 -0
- data/spec/support/models/kangaroo.rb +6 -0
- data/spec/support/models/label.rb +52 -0
- data/spec/support/models/language.rb +7 -0
- data/spec/support/models/lat_lng.rb +17 -0
- data/spec/support/models/league.rb +13 -0
- data/spec/support/models/learner.rb +4 -0
- data/spec/support/models/line_item.rb +8 -0
- data/spec/support/models/location.rb +10 -0
- data/spec/support/models/login.rb +10 -0
- data/spec/support/models/manufacturer.rb +9 -0
- data/spec/support/models/meat.rb +6 -0
- data/spec/support/models/membership.rb +7 -0
- data/spec/support/models/message.rb +13 -0
- data/spec/support/models/minim.rb +6 -0
- data/spec/support/models/mixed_drink.rb +6 -0
- data/spec/support/models/mop.rb +24 -0
- data/spec/support/models/movie.rb +15 -0
- data/spec/support/models/my_hash.rb +4 -0
- data/spec/support/models/name.rb +26 -0
- data/spec/support/models/name_only.rb +8 -0
- data/spec/support/models/node.rb +7 -0
- data/spec/support/models/note.rb +19 -0
- data/spec/support/models/nut.rb +7 -0
- data/spec/support/models/odd.rb +9 -0
- data/spec/support/models/order.rb +12 -0
- data/spec/support/models/ordered_post.rb +13 -0
- data/spec/support/models/ordered_preference.rb +8 -0
- data/spec/support/models/oscar.rb +16 -0
- data/spec/support/models/other_owner_object.rb +4 -0
- data/spec/support/models/override.rb +18 -0
- data/spec/support/models/ownable.rb +8 -0
- data/spec/support/models/owner.rb +10 -0
- data/spec/support/models/pack.rb +5 -0
- data/spec/support/models/page.rb +18 -0
- data/spec/support/models/page_question.rb +6 -0
- data/spec/support/models/palette.rb +9 -0
- data/spec/support/models/parent.rb +7 -0
- data/spec/support/models/parent_doc.rb +8 -0
- data/spec/support/models/passport.rb +22 -0
- data/spec/support/models/patient.rb +11 -0
- data/spec/support/models/pdf_writer.rb +5 -0
- data/spec/support/models/pencil.rb +3 -0
- data/spec/support/models/person.rb +231 -0
- data/spec/support/models/pet.rb +25 -0
- data/spec/support/models/pet_owner.rb +8 -0
- data/spec/support/models/phone.rb +13 -0
- data/spec/support/models/piano.rb +4 -0
- data/spec/support/models/pizza.rb +9 -0
- data/spec/support/models/player.rb +39 -0
- data/spec/support/models/post.rb +52 -0
- data/spec/support/models/post_genre.rb +8 -0
- data/spec/support/models/powerup.rb +25 -0
- data/spec/support/models/preference.rb +11 -0
- data/spec/support/models/princess.rb +12 -0
- data/spec/support/models/product.rb +19 -0
- data/spec/support/models/profile.rb +17 -0
- data/spec/support/models/pronunciation.rb +7 -0
- data/spec/support/models/pub.rb +8 -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/support/models/purchase.rb +6 -0
- data/spec/support/models/purchased_item.rb +10 -0
- data/spec/support/models/question.rb +10 -0
- data/spec/support/models/quiz.rb +9 -0
- data/spec/support/models/rating.rb +10 -0
- data/spec/support/models/record.rb +54 -0
- data/spec/support/models/registry.rb +7 -0
- data/spec/support/models/role.rb +9 -0
- data/spec/support/models/root_category.rb +6 -0
- data/spec/support/models/sandwich.rb +11 -0
- data/spec/support/models/scheduler.rb +9 -0
- data/spec/support/models/school.rb +14 -0
- data/spec/support/models/scribe.rb +7 -0
- data/spec/support/models/sealer.rb +7 -0
- data/spec/support/models/seat.rb +24 -0
- data/spec/support/models/seo.rb +9 -0
- data/spec/support/models/series.rb +7 -0
- data/spec/support/models/server.rb +15 -0
- data/spec/support/models/service.rb +24 -0
- data/spec/support/models/shape.rb +14 -0
- data/spec/support/models/shelf.rb +7 -0
- data/spec/support/models/shield.rb +18 -0
- data/spec/support/models/shipment_address.rb +5 -0
- data/spec/support/models/shipping_container.rb +7 -0
- data/spec/support/models/shipping_pack.rb +5 -0
- data/spec/support/models/shirt.rb +11 -0
- data/spec/support/models/shop.rb +8 -0
- data/spec/support/models/short_agent.rb +6 -0
- data/spec/support/models/short_quiz.rb +7 -0
- data/spec/support/models/simple.rb +7 -0
- data/spec/support/models/slave.rb +8 -0
- data/spec/support/models/song.rb +10 -0
- data/spec/support/models/sound.rb +7 -0
- data/spec/support/models/spacer.rb +7 -0
- data/spec/support/models/square.rb +6 -0
- data/spec/support/models/staff.rb +9 -0
- data/spec/support/models/store_as_dup_test1.rb +7 -0
- data/spec/support/models/store_as_dup_test2.rb +7 -0
- data/spec/support/models/store_as_dup_test3.rb +7 -0
- data/spec/support/models/store_as_dup_test4.rb +7 -0
- data/spec/support/models/strategy.rb +5 -0
- data/spec/support/models/student.rb +14 -0
- data/spec/support/models/sub_item.rb +5 -0
- data/spec/support/models/subscription.rb +7 -0
- data/spec/support/models/survey.rb +7 -0
- data/spec/support/models/symptom.rb +8 -0
- data/spec/support/models/system_role.rb +7 -0
- data/spec/support/models/tag.rb +10 -0
- data/spec/support/models/target.rb +7 -0
- data/spec/support/models/template.rb +7 -0
- data/spec/support/models/thing.rb +11 -0
- data/spec/support/models/threadlocker.rb +7 -0
- data/spec/support/models/title.rb +5 -0
- data/spec/support/models/tool.rb +10 -0
- data/spec/support/models/topping.rb +7 -0
- data/spec/support/models/toy.rb +9 -0
- data/spec/support/models/track.rb +40 -0
- data/spec/support/models/translation.rb +7 -0
- data/spec/support/models/tree.rb +11 -0
- data/spec/support/models/truck.rb +7 -0
- data/spec/support/models/updatable.rb +7 -0
- data/spec/support/models/user.rb +23 -0
- data/spec/support/models/user_account.rb +12 -0
- data/spec/support/models/validation_callback.rb +12 -0
- data/spec/support/models/vehicle.rb +18 -0
- data/spec/support/models/version.rb +7 -0
- data/spec/support/models/vertex.rb +8 -0
- data/spec/support/models/vet_visit.rb +7 -0
- data/spec/support/models/video.rb +15 -0
- data/spec/support/models/video_game.rb +3 -0
- data/spec/support/models/washer.rb +7 -0
- data/spec/support/models/weapon.rb +25 -0
- data/spec/support/models/wiki_page.rb +17 -0
- data/spec/support/models/word.rb +17 -0
- data/spec/support/models/word_origin.rb +13 -0
- data/spec/support/models/writer.rb +13 -0
- data/spec/support/schema_maps/schema_map_aws.json +17 -0
- data/spec/support/schema_maps/schema_map_aws_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_azure.json +17 -0
- data/spec/support/schema_maps/schema_map_azure_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_gcp.json +17 -0
- data/spec/support/schema_maps/schema_map_gcp_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_kmip.json +17 -0
- data/spec/support/schema_maps/schema_map_kmip_key_alt_names.json +12 -0
- data/spec/support/schema_maps/schema_map_local.json +18 -0
- data/spec/support/schema_maps/schema_map_local_key_alt_names.json +12 -0
- data/spec/support/shared/time.rb +53 -0
- data/spec/support/spec_config.rb +64 -0
- data.tar.gz.sig +0 -0
- metadata +1582 -912
- metadata.gz.sig +0 -0
- data/lib/mongoid/atomic/positionable.rb +0 -73
- data/lib/mongoid/callbacks.rb +0 -314
- data/lib/mongoid/components.rb +0 -93
- data/lib/mongoid/config/inflections.rb +0 -6
- data/lib/mongoid/config/validators/session.rb +0 -140
- data/lib/mongoid/contextual/eager.rb +0 -158
- data/lib/mongoid/contextual/find_and_modify.rb +0 -69
- data/lib/mongoid/criterion/findable.rb +0 -179
- data/lib/mongoid/criterion/inspection.rb +0 -25
- data/lib/mongoid/criterion/marshalable.rb +0 -48
- data/lib/mongoid/criterion/modifiable.rb +0 -189
- data/lib/mongoid/criterion/scoping.rb +0 -158
- data/lib/mongoid/dirty.rb +0 -376
- data/lib/mongoid/errors/eager_load.rb +0 -22
- data/lib/mongoid/errors/mixed_session_configuration.rb +0 -28
- data/lib/mongoid/errors/no_default_session.rb +0 -23
- data/lib/mongoid/errors/no_session_config.rb +0 -22
- data/lib/mongoid/errors/no_session_database.rb +0 -27
- data/lib/mongoid/errors/no_session_hosts.rb +0 -27
- data/lib/mongoid/errors/no_sessions_config.rb +0 -20
- data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
- data/lib/mongoid/finders.rb +0 -130
- data/lib/mongoid/hierarchy.rb +0 -188
- data/lib/mongoid/identity_map.rb +0 -163
- data/lib/mongoid/indexes/validators/options.rb +0 -102
- data/lib/mongoid/indexes.rb +0 -154
- data/lib/mongoid/inspection.rb +0 -55
- data/lib/mongoid/json.rb +0 -16
- data/lib/mongoid/matchers/all.rb +0 -27
- data/lib/mongoid/matchers/and.rb +0 -30
- data/lib/mongoid/matchers/default.rb +0 -72
- data/lib/mongoid/matchers/exists.rb +0 -23
- data/lib/mongoid/matchers/gt.rb +0 -21
- data/lib/mongoid/matchers/gte.rb +0 -21
- data/lib/mongoid/matchers/in.rb +0 -24
- data/lib/mongoid/matchers/lt.rb +0 -21
- data/lib/mongoid/matchers/lte.rb +0 -21
- data/lib/mongoid/matchers/ne.rb +0 -21
- data/lib/mongoid/matchers/nin.rb +0 -21
- data/lib/mongoid/matchers/or.rb +0 -33
- data/lib/mongoid/matchers/size.rb +0 -21
- data/lib/mongoid/matchers/strategies.rb +0 -97
- data/lib/mongoid/matchers.rb +0 -32
- data/lib/mongoid/multi_parameter_attributes.rb +0 -105
- data/lib/mongoid/nested_attributes.rb +0 -78
- data/lib/mongoid/observer.rb +0 -192
- data/lib/mongoid/paranoia.rb +0 -137
- data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
- data/lib/mongoid/persistence/atomic/bit.rb +0 -35
- data/lib/mongoid/persistence/atomic/inc.rb +0 -45
- data/lib/mongoid/persistence/atomic/operation.rb +0 -154
- data/lib/mongoid/persistence/atomic/pop.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
- data/lib/mongoid/persistence/atomic/push.rb +0 -25
- data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
- data/lib/mongoid/persistence/atomic/rename.rb +0 -30
- data/lib/mongoid/persistence/atomic/sets.rb +0 -28
- data/lib/mongoid/persistence/atomic/unset.rb +0 -27
- data/lib/mongoid/persistence/atomic.rb +0 -231
- data/lib/mongoid/persistence/deletion.rb +0 -32
- data/lib/mongoid/persistence/insertion.rb +0 -38
- data/lib/mongoid/persistence/modification.rb +0 -35
- data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
- data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
- data/lib/mongoid/persistence/operations/insert.rb +0 -34
- data/lib/mongoid/persistence/operations/remove.rb +0 -33
- data/lib/mongoid/persistence/operations/update.rb +0 -59
- data/lib/mongoid/persistence/operations/upsert.rb +0 -28
- data/lib/mongoid/persistence/operations.rb +0 -214
- data/lib/mongoid/persistence/upsertion.rb +0 -31
- data/lib/mongoid/persistence.rb +0 -352
- data/lib/mongoid/railties/document.rb +0 -12
- data/lib/mongoid/relations/accessors.rb +0 -299
- data/lib/mongoid/relations/auto_save.rb +0 -107
- data/lib/mongoid/relations/binding.rb +0 -241
- data/lib/mongoid/relations/bindings/embedded/in.rb +0 -63
- data/lib/mongoid/relations/bindings/embedded/many.rb +0 -52
- data/lib/mongoid/relations/bindings/embedded/one.rb +0 -55
- data/lib/mongoid/relations/bindings/referenced/in.rb +0 -70
- data/lib/mongoid/relations/bindings/referenced/many.rb +0 -42
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +0 -67
- data/lib/mongoid/relations/bindings/referenced/one.rb +0 -44
- data/lib/mongoid/relations/bindings.rb +0 -9
- data/lib/mongoid/relations/builder.rb +0 -57
- data/lib/mongoid/relations/builders/embedded/in.rb +0 -29
- data/lib/mongoid/relations/builders/embedded/many.rb +0 -36
- data/lib/mongoid/relations/builders/embedded/one.rb +0 -30
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +0 -177
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +0 -127
- data/lib/mongoid/relations/builders/referenced/in.rb +0 -26
- data/lib/mongoid/relations/builders/referenced/many.rb +0 -27
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +0 -40
- data/lib/mongoid/relations/builders/referenced/one.rb +0 -26
- data/lib/mongoid/relations/builders.rb +0 -104
- data/lib/mongoid/relations/cascading/delete.rb +0 -44
- data/lib/mongoid/relations/cascading/destroy.rb +0 -43
- data/lib/mongoid/relations/cascading/nullify.rb +0 -35
- data/lib/mongoid/relations/cascading/restrict.rb +0 -39
- data/lib/mongoid/relations/cascading.rb +0 -58
- data/lib/mongoid/relations/constraint.rb +0 -49
- data/lib/mongoid/relations/conversions.rb +0 -34
- data/lib/mongoid/relations/counter_cache.rb +0 -107
- data/lib/mongoid/relations/cyclic.rb +0 -107
- data/lib/mongoid/relations/embedded/batchable.rb +0 -356
- data/lib/mongoid/relations/embedded/in.rb +0 -231
- data/lib/mongoid/relations/embedded/many.rb +0 -659
- data/lib/mongoid/relations/embedded/one.rb +0 -223
- data/lib/mongoid/relations/macros.rb +0 -359
- data/lib/mongoid/relations/many.rb +0 -217
- data/lib/mongoid/relations/marshalable.rb +0 -32
- data/lib/mongoid/relations/metadata.rb +0 -1227
- data/lib/mongoid/relations/nested_builder.rb +0 -74
- data/lib/mongoid/relations/one.rb +0 -60
- data/lib/mongoid/relations/options.rb +0 -48
- data/lib/mongoid/relations/polymorphic.rb +0 -40
- data/lib/mongoid/relations/proxy.rb +0 -264
- data/lib/mongoid/relations/referenced/in.rb +0 -314
- data/lib/mongoid/relations/referenced/many.rb +0 -789
- data/lib/mongoid/relations/referenced/many_to_many.rb +0 -495
- data/lib/mongoid/relations/referenced/one.rb +0 -297
- data/lib/mongoid/relations/reflections.rb +0 -62
- data/lib/mongoid/relations/synchronization.rb +0 -169
- data/lib/mongoid/relations/targets/enumerable.rb +0 -473
- data/lib/mongoid/relations/targets.rb +0 -2
- data/lib/mongoid/relations/touchable.rb +0 -61
- data/lib/mongoid/relations.rb +0 -162
- data/lib/mongoid/reloading.rb +0 -92
- data/lib/mongoid/scoping.rb +0 -356
- data/lib/mongoid/serialization.rb +0 -161
- data/lib/mongoid/sessions/factory.rb +0 -129
- data/lib/mongoid/sessions/mongo_uri.rb +0 -93
- data/lib/mongoid/sessions/validators/storage.rb +0 -49
- data/lib/mongoid/sessions/validators.rb +0 -2
- data/lib/mongoid/sessions.rb +0 -433
- data/lib/mongoid/sharding.rb +0 -61
- data/lib/mongoid/state.rb +0 -97
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/validations/associated.rb +0 -46
- data/lib/mongoid/validations/format.rb +0 -20
- data/lib/mongoid/validations/length.rb +0 -20
- data/lib/mongoid/validations/localizable.rb +0 -30
- data/lib/mongoid/validations/macros.rb +0 -93
- data/lib/mongoid/validations/presence.rb +0 -86
- data/lib/mongoid/validations/queryable.rb +0 -31
- data/lib/mongoid/validations/uniqueness.rb +0 -330
- data/lib/mongoid/validations.rb +0 -166
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rack/mongoid.rb +0 -2
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
- data/lib/support/ruby_version.rb +0 -26
- data/spec/app/models/account.rb +0 -32
- data/spec/app/models/acolyte.rb +0 -16
- data/spec/app/models/actor.rb +0 -19
- data/spec/app/models/actor_observer.rb +0 -15
- data/spec/app/models/actress.rb +0 -2
- data/spec/app/models/address.rb +0 -72
- data/spec/app/models/address_component.rb +0 -5
- data/spec/app/models/address_number.rb +0 -6
- data/spec/app/models/agency.rb +0 -5
- data/spec/app/models/agent.rb +0 -12
- data/spec/app/models/album.rb +0 -14
- data/spec/app/models/alert.rb +0 -5
- data/spec/app/models/animal.rb +0 -25
- data/spec/app/models/answer.rb +0 -4
- data/spec/app/models/appointment.rb +0 -7
- data/spec/app/models/article.rb +0 -13
- data/spec/app/models/artist.rb +0 -66
- data/spec/app/models/artwork.rb +0 -4
- data/spec/app/models/augmentation.rb +0 -11
- data/spec/app/models/author.rb +0 -6
- data/spec/app/models/band.rb +0 -25
- data/spec/app/models/bar.rb +0 -9
- data/spec/app/models/basic.rb +0 -6
- data/spec/app/models/bed.rb +0 -1
- data/spec/app/models/big_palette.rb +0 -2
- data/spec/app/models/birthday.rb +0 -13
- data/spec/app/models/book.rb +0 -12
- data/spec/app/models/breed.rb +0 -4
- data/spec/app/models/browser.rb +0 -6
- data/spec/app/models/building.rb +0 -7
- data/spec/app/models/building_address.rb +0 -7
- data/spec/app/models/bus.rb +0 -7
- data/spec/app/models/business.rb +0 -5
- data/spec/app/models/callback_recorder.rb +0 -25
- data/spec/app/models/callback_test.rb +0 -9
- data/spec/app/models/canvas.rb +0 -25
- data/spec/app/models/car.rb +0 -1
- data/spec/app/models/cat.rb +0 -8
- data/spec/app/models/category.rb +0 -8
- data/spec/app/models/child.rb +0 -4
- data/spec/app/models/child_doc.rb +0 -22
- data/spec/app/models/church.rb +0 -4
- data/spec/app/models/circle.rb +0 -3
- data/spec/app/models/circuit.rb +0 -4
- data/spec/app/models/circus.rb +0 -7
- data/spec/app/models/code.rb +0 -5
- data/spec/app/models/comment.rb +0 -16
- data/spec/app/models/contractor.rb +0 -7
- data/spec/app/models/cookie.rb +0 -6
- data/spec/app/models/country_code.rb +0 -8
- data/spec/app/models/definition.rb +0 -8
- data/spec/app/models/description.rb +0 -11
- data/spec/app/models/dictionary.rb +0 -10
- data/spec/app/models/division.rb +0 -10
- data/spec/app/models/doctor.rb +0 -12
- data/spec/app/models/dog.rb +0 -7
- data/spec/app/models/dokument.rb +0 -5
- data/spec/app/models/driver.rb +0 -7
- data/spec/app/models/drug.rb +0 -8
- data/spec/app/models/email.rb +0 -6
- data/spec/app/models/employer.rb +0 -5
- data/spec/app/models/entry.rb +0 -6
- data/spec/app/models/eraser.rb +0 -1
- data/spec/app/models/event.rb +0 -22
- data/spec/app/models/exhibition.rb +0 -4
- data/spec/app/models/exhibitor.rb +0 -5
- data/spec/app/models/eye.rb +0 -9
- data/spec/app/models/eye_bowl.rb +0 -9
- data/spec/app/models/face.rb +0 -8
- data/spec/app/models/favorite.rb +0 -6
- data/spec/app/models/filesystem.rb +0 -4
- data/spec/app/models/fire_hydrant.rb +0 -6
- data/spec/app/models/firefox.rb +0 -4
- data/spec/app/models/fish.rb +0 -8
- data/spec/app/models/folder.rb +0 -7
- data/spec/app/models/folder_item.rb +0 -9
- data/spec/app/models/fruits.rb +0 -28
- data/spec/app/models/game.rb +0 -21
- data/spec/app/models/ghost.rb +0 -7
- data/spec/app/models/home.rb +0 -4
- data/spec/app/models/house.rb +0 -8
- data/spec/app/models/html_writer.rb +0 -3
- data/spec/app/models/image.rb +0 -22
- data/spec/app/models/implant.rb +0 -16
- data/spec/app/models/item.rb +0 -12
- data/spec/app/models/jar.rb +0 -7
- data/spec/app/models/label.rb +0 -40
- data/spec/app/models/language.rb +0 -5
- data/spec/app/models/lat_lng.rb +0 -15
- data/spec/app/models/league.rb +0 -11
- data/spec/app/models/learner.rb +0 -2
- data/spec/app/models/line_item.rb +0 -6
- data/spec/app/models/location.rb +0 -8
- data/spec/app/models/login.rb +0 -8
- data/spec/app/models/manufacturer.rb +0 -7
- data/spec/app/models/meat.rb +0 -4
- data/spec/app/models/membership.rb +0 -4
- data/spec/app/models/mixed_drink.rb +0 -4
- data/spec/app/models/movie.rb +0 -12
- data/spec/app/models/my_hash.rb +0 -2
- data/spec/app/models/name.rb +0 -23
- data/spec/app/models/node.rb +0 -5
- data/spec/app/models/note.rb +0 -12
- data/spec/app/models/ordered_post.rb +0 -6
- data/spec/app/models/ordered_preference.rb +0 -6
- data/spec/app/models/oscar.rb +0 -15
- data/spec/app/models/override.rb +0 -16
- data/spec/app/models/ownable.rb +0 -6
- data/spec/app/models/owner.rb +0 -6
- data/spec/app/models/pack.rb +0 -3
- data/spec/app/models/page.rb +0 -5
- data/spec/app/models/page_question.rb +0 -4
- data/spec/app/models/palette.rb +0 -7
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -36
- data/spec/app/models/parent.rb +0 -5
- data/spec/app/models/parent_doc.rb +0 -6
- data/spec/app/models/passport.rb +0 -5
- data/spec/app/models/patient.rb +0 -9
- data/spec/app/models/pdf_writer.rb +0 -3
- data/spec/app/models/pencil.rb +0 -1
- data/spec/app/models/person.rb +0 -201
- data/spec/app/models/pet.rb +0 -23
- data/spec/app/models/pet_owner.rb +0 -6
- data/spec/app/models/phone.rb +0 -11
- data/spec/app/models/phone_observer.rb +0 -6
- data/spec/app/models/pizza.rb +0 -7
- data/spec/app/models/player.rb +0 -35
- data/spec/app/models/post.rb +0 -43
- data/spec/app/models/powerup.rb +0 -11
- data/spec/app/models/preference.rb +0 -9
- data/spec/app/models/princess.rb +0 -8
- data/spec/app/models/product.rb +0 -17
- data/spec/app/models/profile.rb +0 -5
- data/spec/app/models/pronunciation.rb +0 -5
- data/spec/app/models/purchase.rb +0 -4
- data/spec/app/models/question.rb +0 -8
- data/spec/app/models/quiz.rb +0 -10
- data/spec/app/models/rating.rb +0 -8
- data/spec/app/models/record.rb +0 -46
- data/spec/app/models/registry.rb +0 -4
- data/spec/app/models/role.rb +0 -7
- data/spec/app/models/root_category.rb +0 -4
- data/spec/app/models/sandwich.rb +0 -4
- data/spec/app/models/scheduler.rb +0 -7
- data/spec/app/models/seo.rb +0 -7
- data/spec/app/models/series.rb +0 -4
- data/spec/app/models/server.rb +0 -13
- data/spec/app/models/service.rb +0 -22
- data/spec/app/models/shape.rb +0 -12
- data/spec/app/models/shelf.rb +0 -5
- data/spec/app/models/shipping_container.rb +0 -5
- data/spec/app/models/shipping_pack.rb +0 -3
- data/spec/app/models/shop.rb +0 -6
- data/spec/app/models/short_agent.rb +0 -4
- data/spec/app/models/short_quiz.rb +0 -5
- data/spec/app/models/slave.rb +0 -6
- data/spec/app/models/song.rb +0 -8
- data/spec/app/models/square.rb +0 -4
- data/spec/app/models/strategy.rb +0 -3
- data/spec/app/models/sub_item.rb +0 -3
- data/spec/app/models/subscription.rb +0 -4
- data/spec/app/models/survey.rb +0 -5
- data/spec/app/models/symptom.rb +0 -6
- data/spec/app/models/tag.rb +0 -8
- data/spec/app/models/target.rb +0 -5
- data/spec/app/models/template.rb +0 -5
- data/spec/app/models/thing.rb +0 -9
- data/spec/app/models/title.rb +0 -4
- data/spec/app/models/tool.rb +0 -8
- data/spec/app/models/topping.rb +0 -5
- data/spec/app/models/track.rb +0 -38
- data/spec/app/models/translation.rb +0 -5
- data/spec/app/models/tree.rb +0 -9
- data/spec/app/models/truck.rb +0 -3
- data/spec/app/models/user.rb +0 -21
- data/spec/app/models/user_account.rb +0 -10
- data/spec/app/models/validation_callback.rb +0 -10
- data/spec/app/models/vehicle.rb +0 -11
- data/spec/app/models/version.rb +0 -5
- data/spec/app/models/vet_visit.rb +0 -5
- data/spec/app/models/video.rb +0 -17
- data/spec/app/models/video_game.rb +0 -1
- data/spec/app/models/weapon.rb +0 -11
- data/spec/app/models/wiki_page.rb +0 -17
- data/spec/app/models/word.rb +0 -12
- data/spec/app/models/word_origin.rb +0 -11
- data/spec/app/models/writer.rb +0 -11
- data/spec/mongoid/atomic/positionable_spec.rb +0 -227
- data/spec/mongoid/attributes/processing_spec.rb +0 -149
- data/spec/mongoid/callbacks_spec.rb +0 -1564
- data/spec/mongoid/components_spec.rb +0 -24
- data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
- data/spec/mongoid/criterion/destructive_spec.rb +0 -101
- data/spec/mongoid/criterion/inspection_spec.rb +0 -27
- data/spec/mongoid/criterion/marshalable_spec.rb +0 -28
- data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
- data/spec/mongoid/criterion/modification_spec.rb +0 -402
- data/spec/mongoid/criterion/scoping_spec.rb +0 -391
- data/spec/mongoid/dirty_spec.rb +0 -1508
- data/spec/mongoid/errors/eager_load_spec.rb +0 -29
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_config_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_database_spec.rb +0 -29
- data/spec/mongoid/errors/no_session_hosts_spec.rb +0 -29
- data/spec/mongoid/errors/no_sessions_config_spec.rb +0 -29
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +0 -184
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +0 -201
- data/spec/mongoid/finders_spec.rb +0 -321
- data/spec/mongoid/hierarchy_spec.rb +0 -244
- data/spec/mongoid/identity_map_spec.rb +0 -564
- data/spec/mongoid/indexes_spec.rb +0 -404
- data/spec/mongoid/inspection_spec.rb +0 -57
- data/spec/mongoid/json_spec.rb +0 -33
- data/spec/mongoid/matchers/all_spec.rb +0 -31
- data/spec/mongoid/matchers/and_spec.rb +0 -162
- data/spec/mongoid/matchers/default_spec.rb +0 -130
- data/spec/mongoid/matchers/exists_spec.rb +0 -57
- data/spec/mongoid/matchers/gt_spec.rb +0 -74
- data/spec/mongoid/matchers/gte_spec.rb +0 -74
- data/spec/mongoid/matchers/in_spec.rb +0 -25
- data/spec/mongoid/matchers/lt_spec.rb +0 -74
- data/spec/mongoid/matchers/lte_spec.rb +0 -74
- data/spec/mongoid/matchers/ne_spec.rb +0 -25
- data/spec/mongoid/matchers/nin_spec.rb +0 -25
- data/spec/mongoid/matchers/or_spec.rb +0 -106
- data/spec/mongoid/matchers/size_spec.rb +0 -25
- data/spec/mongoid/matchers_spec.rb +0 -532
- data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
- data/spec/mongoid/nested_attributes_spec.rb +0 -4945
- data/spec/mongoid/observer_spec.rb +0 -290
- data/spec/mongoid/paranoia_spec.rb +0 -759
- data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
- data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
- data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
- data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
- data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
- data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
- data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
- data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
- data/spec/mongoid/persistence/atomic_spec.rb +0 -216
- data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
- data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
- data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
- data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
- data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
- data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
- data/spec/mongoid/persistence/operations_spec.rb +0 -313
- data/spec/mongoid/persistence_spec.rb +0 -2279
- data/spec/mongoid/railties/document_spec.rb +0 -24
- data/spec/mongoid/relations/accessors_spec.rb +0 -844
- data/spec/mongoid/relations/auto_save_spec.rb +0 -261
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +0 -171
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +0 -54
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +0 -77
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +0 -241
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +0 -153
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +0 -131
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +0 -34
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +0 -132
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +0 -99
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +0 -234
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +0 -250
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +0 -241
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +0 -137
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +0 -178
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +0 -124
- data/spec/mongoid/relations/builders_spec.rb +0 -226
- data/spec/mongoid/relations/cascading/delete_spec.rb +0 -101
- data/spec/mongoid/relations/cascading/destroy_spec.rb +0 -47
- data/spec/mongoid/relations/cascading/nullify_spec.rb +0 -32
- data/spec/mongoid/relations/cascading/restrict_spec.rb +0 -68
- data/spec/mongoid/relations/cascading_spec.rb +0 -355
- data/spec/mongoid/relations/constraint_spec.rb +0 -74
- data/spec/mongoid/relations/conversions_spec.rb +0 -126
- data/spec/mongoid/relations/counter_cache_spec.rb +0 -205
- data/spec/mongoid/relations/cyclic_spec.rb +0 -156
- data/spec/mongoid/relations/embedded/dirty_spec.rb +0 -65
- data/spec/mongoid/relations/embedded/in_spec.rb +0 -580
- data/spec/mongoid/relations/embedded/many_spec.rb +0 -3841
- data/spec/mongoid/relations/embedded/one_spec.rb +0 -1055
- data/spec/mongoid/relations/macros_spec.rb +0 -625
- data/spec/mongoid/relations/metadata_spec.rb +0 -2030
- data/spec/mongoid/relations/options_spec.rb +0 -35
- data/spec/mongoid/relations/polymorphic_spec.rb +0 -132
- data/spec/mongoid/relations/referenced/in_spec.rb +0 -1501
- data/spec/mongoid/relations/referenced/many_spec.rb +0 -3632
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +0 -3561
- data/spec/mongoid/relations/referenced/one_spec.rb +0 -1331
- data/spec/mongoid/relations/reflections_spec.rb +0 -101
- data/spec/mongoid/relations/synchronization_spec.rb +0 -453
- data/spec/mongoid/relations/targets/enumerable_spec.rb +0 -1710
- data/spec/mongoid/relations_spec.rb +0 -188
- data/spec/mongoid/reloading_spec.rb +0 -305
- data/spec/mongoid/scoping_spec.rb +0 -978
- data/spec/mongoid/serialization_spec.rb +0 -833
- data/spec/mongoid/sessions/factory_spec.rb +0 -312
- data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
- data/spec/mongoid/sessions_spec.rb +0 -1111
- data/spec/mongoid/sharding_spec.rb +0 -61
- data/spec/mongoid/state_spec.rb +0 -102
- data/spec/mongoid/unit_of_work_spec.rb +0 -196
- data/spec/mongoid/validations/associated_spec.rb +0 -183
- data/spec/mongoid/validations/format_spec.rb +0 -83
- data/spec/mongoid/validations/length_spec.rb +0 -223
- data/spec/mongoid/validations/numericality_spec.rb +0 -30
- data/spec/mongoid/validations/presence_spec.rb +0 -592
- data/spec/mongoid/validations/uniqueness_spec.rb +0 -2399
- data/spec/mongoid/validations_spec.rb +0 -309
- data/spec/mongoid/versioning_spec.rb +0 -540
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -1,4945 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Mongoid::NestedAttributes do
|
4
|
-
|
5
|
-
describe ".accepts_nested_attributes_for" do
|
6
|
-
|
7
|
-
context "when the autosave option is not defined" do
|
8
|
-
|
9
|
-
let(:person) do
|
10
|
-
Person.new
|
11
|
-
end
|
12
|
-
|
13
|
-
before do
|
14
|
-
Person.accepts_nested_attributes_for :favorites
|
15
|
-
end
|
16
|
-
|
17
|
-
after do
|
18
|
-
Person.send(:undef_method, :favorites_attributes=)
|
19
|
-
Person.nested_attributes.clear
|
20
|
-
end
|
21
|
-
|
22
|
-
it "adds a method for handling the attributes" do
|
23
|
-
expect(person).to respond_to(:favorites_attributes=)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "adds the method name to the nested attributes list" do
|
27
|
-
expect(Person.nested_attributes).to eq({
|
28
|
-
"favorites_attributes" => "favorites_attributes="
|
29
|
-
})
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when autosave is explicitly false" do
|
34
|
-
|
35
|
-
before do
|
36
|
-
Account.accepts_nested_attributes_for :alerts
|
37
|
-
end
|
38
|
-
|
39
|
-
after do
|
40
|
-
Account.send(:undef_method, :alerts_attributes=)
|
41
|
-
Account.nested_attributes.clear
|
42
|
-
end
|
43
|
-
|
44
|
-
let(:metadata) do
|
45
|
-
Account.reflect_on_association(:alerts)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "keeps autosave set to false" do
|
49
|
-
expect(metadata).to_not be_autosave
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#initialize" do
|
55
|
-
|
56
|
-
context "when the relation is an embeds one" do
|
57
|
-
|
58
|
-
before(:all) do
|
59
|
-
Person.send(:undef_method, :name_attributes=)
|
60
|
-
Person.accepts_nested_attributes_for :name
|
61
|
-
end
|
62
|
-
|
63
|
-
let(:person) do
|
64
|
-
Person.new(name_attributes: { first_name: "Johnny" })
|
65
|
-
end
|
66
|
-
|
67
|
-
it "sets the nested attributes" do
|
68
|
-
person.name.first_name.should eq("Johnny")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when the relation is an embeds many" do
|
73
|
-
|
74
|
-
before(:all) do
|
75
|
-
Person.send(:undef_method, :addresses_attributes=)
|
76
|
-
Person.accepts_nested_attributes_for :addresses
|
77
|
-
end
|
78
|
-
|
79
|
-
let(:person) do
|
80
|
-
Person.new(addresses_attributes: { "1" => { street: "Alexanderstr" }})
|
81
|
-
end
|
82
|
-
|
83
|
-
it "sets the nested attributes" do
|
84
|
-
person.addresses.first.street.should eq("Alexanderstr")
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when there are 10 or more child records" do
|
88
|
-
|
89
|
-
let(:person) do
|
90
|
-
Person.new(addresses: addresses)
|
91
|
-
end
|
92
|
-
|
93
|
-
let(:addresses) do
|
94
|
-
('0'..'10').inject({}) do |addresses,i|
|
95
|
-
addresses.merge(i => {number: i})
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
it "preserves the order of the children" do
|
100
|
-
person.addresses.map(&:number).should eq((0..10).to_a)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when the relation is an embedded in" do
|
106
|
-
|
107
|
-
before(:all) do
|
108
|
-
Video.accepts_nested_attributes_for :person
|
109
|
-
end
|
110
|
-
|
111
|
-
let(:video) do
|
112
|
-
Video.new(person_attributes: { title: "Sir" })
|
113
|
-
end
|
114
|
-
|
115
|
-
it "sets the nested attributes" do
|
116
|
-
video.person.title.should eq("Sir")
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "when the relation is a references one" do
|
121
|
-
|
122
|
-
before(:all) do
|
123
|
-
Person.send(:undef_method, :game_attributes=)
|
124
|
-
Person.accepts_nested_attributes_for :game
|
125
|
-
end
|
126
|
-
|
127
|
-
let(:person) do
|
128
|
-
Person.new(game_attributes: { name: "Tron" })
|
129
|
-
end
|
130
|
-
|
131
|
-
it "sets the nested attributes" do
|
132
|
-
person.game.name.should eq("Tron")
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when the relation is a references many" do
|
137
|
-
|
138
|
-
before(:all) do
|
139
|
-
Person.send(:undef_method, :posts_attributes=)
|
140
|
-
Person.accepts_nested_attributes_for :posts
|
141
|
-
end
|
142
|
-
|
143
|
-
let(:person) do
|
144
|
-
Person.new(posts_attributes: { "1" => { title: "First" }})
|
145
|
-
end
|
146
|
-
|
147
|
-
it "sets the nested attributes" do
|
148
|
-
person.posts.first.title.should eq("First")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
context "when the relation is a references and referenced in many" do
|
153
|
-
|
154
|
-
before(:all) do
|
155
|
-
Person.send(:undef_method, :preferences_attributes=)
|
156
|
-
Person.accepts_nested_attributes_for :preferences
|
157
|
-
end
|
158
|
-
|
159
|
-
let(:person) do
|
160
|
-
Person.new(preferences_attributes: { "1" => { name: "First" }})
|
161
|
-
end
|
162
|
-
|
163
|
-
it "sets the nested attributes" do
|
164
|
-
person.preferences.first.name.should eq("First")
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "when the relation is a referenced in" do
|
169
|
-
|
170
|
-
before(:all) do
|
171
|
-
Post.accepts_nested_attributes_for :person
|
172
|
-
end
|
173
|
-
|
174
|
-
let(:post) do
|
175
|
-
Post.new(person_attributes: { title: "Sir" })
|
176
|
-
end
|
177
|
-
|
178
|
-
it "sets the nested attributes" do
|
179
|
-
post.person.title.should eq("Sir")
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
describe "##{name}_attributes=" do
|
185
|
-
|
186
|
-
context "when the parent document is new" do
|
187
|
-
|
188
|
-
context "when the relation is an embeds one" do
|
189
|
-
|
190
|
-
context "when the parent document is persisted" do
|
191
|
-
|
192
|
-
let(:person) do
|
193
|
-
Person.create
|
194
|
-
end
|
195
|
-
|
196
|
-
before do
|
197
|
-
Person.send(:undef_method, :name_attributes=)
|
198
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
199
|
-
end
|
200
|
-
|
201
|
-
after do
|
202
|
-
Person.send(:undef_method, :name_attributes=)
|
203
|
-
Person.accepts_nested_attributes_for :name
|
204
|
-
end
|
205
|
-
|
206
|
-
context "when setting the child attributes" do
|
207
|
-
|
208
|
-
before do
|
209
|
-
person.name_attributes = { last_name: "Fischer" }
|
210
|
-
end
|
211
|
-
|
212
|
-
it "sets the child document" do
|
213
|
-
person.name.last_name.should eq("Fischer")
|
214
|
-
end
|
215
|
-
|
216
|
-
it "does not persist the child document" do
|
217
|
-
person.name.should_not be_persisted
|
218
|
-
end
|
219
|
-
|
220
|
-
context "when saving the parent" do
|
221
|
-
|
222
|
-
before do
|
223
|
-
person.save
|
224
|
-
person.reload
|
225
|
-
end
|
226
|
-
|
227
|
-
it "persists the child document" do
|
228
|
-
person.name.should be_persisted
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
let(:person) do
|
235
|
-
Person.new
|
236
|
-
end
|
237
|
-
|
238
|
-
context "when a reject proc is specified" do
|
239
|
-
|
240
|
-
before(:all) do
|
241
|
-
Person.send(:undef_method, :name_attributes=)
|
242
|
-
Person.accepts_nested_attributes_for \
|
243
|
-
:name, reject_if: ->(attrs){ attrs[:first_name].blank? }
|
244
|
-
end
|
245
|
-
|
246
|
-
after(:all) do
|
247
|
-
Person.send(:undef_method, :name_attributes=)
|
248
|
-
Person.accepts_nested_attributes_for :name
|
249
|
-
end
|
250
|
-
|
251
|
-
context "when the attributes match" do
|
252
|
-
|
253
|
-
before do
|
254
|
-
person.name_attributes = { last_name: "Lang" }
|
255
|
-
end
|
256
|
-
|
257
|
-
it "does not add the document" do
|
258
|
-
person.name.should be_nil
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context "when the attributes do not match" do
|
263
|
-
|
264
|
-
before do
|
265
|
-
person.name_attributes = { first_name: "Lang" }
|
266
|
-
end
|
267
|
-
|
268
|
-
it "adds the document" do
|
269
|
-
person.name.first_name.should eq("Lang")
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context "when :reject_if => :all_blank is specified" do
|
275
|
-
|
276
|
-
context "when the relation is not autobuilding" do
|
277
|
-
|
278
|
-
before(:all) do
|
279
|
-
Person.send(:undef_method, :name_attributes=)
|
280
|
-
Person.accepts_nested_attributes_for \
|
281
|
-
:name, reject_if: :all_blank
|
282
|
-
end
|
283
|
-
|
284
|
-
after(:all) do
|
285
|
-
Person.send(:undef_method, :name_attributes=)
|
286
|
-
Person.accepts_nested_attributes_for :name
|
287
|
-
end
|
288
|
-
|
289
|
-
context "when all attributes are empty" do
|
290
|
-
|
291
|
-
before do
|
292
|
-
person.name_attributes = { last_name: "" }
|
293
|
-
end
|
294
|
-
|
295
|
-
it "does not add the document" do
|
296
|
-
person.name.should be_nil
|
297
|
-
end
|
298
|
-
end
|
299
|
-
|
300
|
-
context "when an attribute is non-empty" do
|
301
|
-
|
302
|
-
before do
|
303
|
-
person.name_attributes = { first_name: "Lang" }
|
304
|
-
end
|
305
|
-
|
306
|
-
it "adds the document" do
|
307
|
-
person.name.first_name.should eq("Lang")
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context "when the relation is autobuilding" do
|
313
|
-
|
314
|
-
before(:all) do
|
315
|
-
Product.accepts_nested_attributes_for :seo, reject_if: :all_blank
|
316
|
-
end
|
317
|
-
|
318
|
-
after(:all) do
|
319
|
-
Product.send(:undef_method, :seo_attributes=)
|
320
|
-
end
|
321
|
-
|
322
|
-
context "when all attributes are empty" do
|
323
|
-
|
324
|
-
let(:product) do
|
325
|
-
Product.create(name: "testing")
|
326
|
-
end
|
327
|
-
|
328
|
-
it "does not add the document" do
|
329
|
-
product.seo.should_not be_persisted
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context "when no id has been passed" do
|
336
|
-
|
337
|
-
context "with no destroy attribute" do
|
338
|
-
|
339
|
-
before do
|
340
|
-
person.name_attributes = { first_name: "Leo" }
|
341
|
-
end
|
342
|
-
|
343
|
-
it "builds a new document" do
|
344
|
-
person.name.first_name.should eq("Leo")
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
context "with a destroy attribute" do
|
349
|
-
|
350
|
-
context "when allow_destroy is true" do
|
351
|
-
|
352
|
-
before(:all) do
|
353
|
-
Person.send(:undef_method, :name_attributes=)
|
354
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
355
|
-
end
|
356
|
-
|
357
|
-
after(:all) do
|
358
|
-
Person.send(:undef_method, :name_attributes=)
|
359
|
-
Person.accepts_nested_attributes_for :name
|
360
|
-
end
|
361
|
-
|
362
|
-
context "when destroy is a symbol" do
|
363
|
-
|
364
|
-
before do
|
365
|
-
person.name_attributes = { first_name: "Leo", _destroy: "1" }
|
366
|
-
end
|
367
|
-
|
368
|
-
it "does not build the document" do
|
369
|
-
person.name.should be_nil
|
370
|
-
end
|
371
|
-
end
|
372
|
-
|
373
|
-
context "when destroy is a string" do
|
374
|
-
|
375
|
-
before do
|
376
|
-
person.name_attributes = { first_name: "Leo", "_destroy" => "1" }
|
377
|
-
end
|
378
|
-
|
379
|
-
it "does not build the document" do
|
380
|
-
person.name.should be_nil
|
381
|
-
end
|
382
|
-
end
|
383
|
-
end
|
384
|
-
|
385
|
-
context "when allow_destroy is false" do
|
386
|
-
|
387
|
-
before(:all) do
|
388
|
-
Person.send(:undef_method, :name_attributes=)
|
389
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
390
|
-
end
|
391
|
-
|
392
|
-
after(:all) do
|
393
|
-
Person.send(:undef_method, :name_attributes=)
|
394
|
-
Person.accepts_nested_attributes_for :name
|
395
|
-
end
|
396
|
-
|
397
|
-
before do
|
398
|
-
person.name_attributes = { first_name: "Leo", _destroy: "1" }
|
399
|
-
end
|
400
|
-
|
401
|
-
it "builds the document" do
|
402
|
-
person.name.first_name.should eq("Leo")
|
403
|
-
end
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
context "with empty attributes" do
|
408
|
-
|
409
|
-
before do
|
410
|
-
person.name_attributes = {}
|
411
|
-
end
|
412
|
-
|
413
|
-
it "does not build the document" do
|
414
|
-
person.name.should be_nil
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
context "when there is an existing document" do
|
419
|
-
|
420
|
-
context "with no destroy attribute" do
|
421
|
-
|
422
|
-
before do
|
423
|
-
person.name = Name.new(first_name: "Michael")
|
424
|
-
person.name_attributes = { first_name: "Jack" }
|
425
|
-
end
|
426
|
-
|
427
|
-
it "replaces the document" do
|
428
|
-
person.name.first_name.should eq("Jack")
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
context "with a destroy attribute" do
|
433
|
-
|
434
|
-
context "when allow_destroy is true" do
|
435
|
-
|
436
|
-
before(:all) do
|
437
|
-
Person.send(:undef_method, :name_attributes=)
|
438
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
439
|
-
end
|
440
|
-
|
441
|
-
after(:all) do
|
442
|
-
Person.send(:undef_method, :name_attributes=)
|
443
|
-
Person.accepts_nested_attributes_for :name
|
444
|
-
end
|
445
|
-
|
446
|
-
before do
|
447
|
-
person.name = Name.new(first_name: "Michael")
|
448
|
-
person.name_attributes = { first_name: "Jack", _destroy: "1" }
|
449
|
-
end
|
450
|
-
|
451
|
-
it "does not replace the document" do
|
452
|
-
person.name.first_name.should eq("Michael")
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
context "when allow_destroy is false" do
|
457
|
-
|
458
|
-
before(:all) do
|
459
|
-
Person.send(:undef_method, :name_attributes=)
|
460
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
461
|
-
end
|
462
|
-
|
463
|
-
after(:all) do
|
464
|
-
Person.send(:undef_method, :name_attributes=)
|
465
|
-
Person.accepts_nested_attributes_for :name
|
466
|
-
end
|
467
|
-
|
468
|
-
before do
|
469
|
-
person.name = Name.new(first_name: "Michael")
|
470
|
-
person.name_attributes = { first_name: "Jack", _destroy: "1" }
|
471
|
-
end
|
472
|
-
|
473
|
-
it "replaces the document" do
|
474
|
-
person.name.first_name.should eq("Jack")
|
475
|
-
end
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
context "when an id is passed" do
|
482
|
-
|
483
|
-
context "when there is an existing record" do
|
484
|
-
|
485
|
-
let(:name) do
|
486
|
-
Name.new(first_name: "Joe")
|
487
|
-
end
|
488
|
-
|
489
|
-
before do
|
490
|
-
person.name = name
|
491
|
-
end
|
492
|
-
|
493
|
-
context "when the id matches" do
|
494
|
-
|
495
|
-
context "when passed keys as symbols" do
|
496
|
-
|
497
|
-
before do
|
498
|
-
person.name_attributes =
|
499
|
-
{ id: name.id.to_s, first_name: "Bob" }
|
500
|
-
end
|
501
|
-
|
502
|
-
it "updates the existing document" do
|
503
|
-
person.name.first_name.should eq("Bob")
|
504
|
-
end
|
505
|
-
end
|
506
|
-
|
507
|
-
context "when passed keys as strings" do
|
508
|
-
|
509
|
-
before do
|
510
|
-
person.name_attributes =
|
511
|
-
{ "id" => name.id.to_s, "first_name" => "Bob" }
|
512
|
-
end
|
513
|
-
|
514
|
-
it "updates the existing document" do
|
515
|
-
person.name.first_name.should eq("Bob")
|
516
|
-
end
|
517
|
-
end
|
518
|
-
|
519
|
-
context "when allow_destroy is true" do
|
520
|
-
|
521
|
-
before(:all) do
|
522
|
-
Person.send(:undef_method, :name_attributes=)
|
523
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
524
|
-
end
|
525
|
-
|
526
|
-
after(:all) do
|
527
|
-
Person.send(:undef_method, :name_attributes=)
|
528
|
-
Person.accepts_nested_attributes_for :name
|
529
|
-
end
|
530
|
-
|
531
|
-
[ 1, "1", true, "true" ].each do |truth|
|
532
|
-
|
533
|
-
context "when passed #{truth} with destroy" do
|
534
|
-
|
535
|
-
context "when the document has no callbacks" do
|
536
|
-
|
537
|
-
before do
|
538
|
-
person.name_attributes =
|
539
|
-
{ id: name.id, _destroy: truth }
|
540
|
-
end
|
541
|
-
|
542
|
-
it "destroys the existing document" do
|
543
|
-
person.name.should be_nil
|
544
|
-
end
|
545
|
-
end
|
546
|
-
|
547
|
-
context "when the document has destroy callbacks" do
|
548
|
-
|
549
|
-
before(:all) do
|
550
|
-
PetOwner.accepts_nested_attributes_for :pet, allow_destroy: true
|
551
|
-
end
|
552
|
-
|
553
|
-
after(:all) do
|
554
|
-
PetOwner.send(:undef_method, :pet_attributes=)
|
555
|
-
end
|
556
|
-
|
557
|
-
let(:owner) do
|
558
|
-
PetOwner.create
|
559
|
-
end
|
560
|
-
|
561
|
-
let!(:pet) do
|
562
|
-
owner.create_pet
|
563
|
-
end
|
564
|
-
|
565
|
-
before do
|
566
|
-
owner.pet_attributes = { id: pet.id, _destroy: truth }
|
567
|
-
owner.save
|
568
|
-
end
|
569
|
-
|
570
|
-
it "destroys the existing document" do
|
571
|
-
owner.pet.should be_nil
|
572
|
-
end
|
573
|
-
|
574
|
-
it "runs the destroy callbacks" do
|
575
|
-
pet.destroy_flag.should be_true
|
576
|
-
end
|
577
|
-
end
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
[ nil, 0, "0", false, "false" ].each do |falsehood|
|
582
|
-
|
583
|
-
context "when passed #{falsehood} with destroy" do
|
584
|
-
|
585
|
-
before do
|
586
|
-
person.name_attributes =
|
587
|
-
{ id: name.id, _destroy: falsehood }
|
588
|
-
end
|
589
|
-
|
590
|
-
it "does not destroy the existing document" do
|
591
|
-
person.name.should eq(name)
|
592
|
-
end
|
593
|
-
end
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
context "when allow destroy is false" do
|
598
|
-
|
599
|
-
before(:all) do
|
600
|
-
Person.send(:undef_method, :name_attributes=)
|
601
|
-
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
602
|
-
end
|
603
|
-
|
604
|
-
after(:all) do
|
605
|
-
Person.send(:undef_method, :name_attributes=)
|
606
|
-
Person.accepts_nested_attributes_for :name
|
607
|
-
end
|
608
|
-
|
609
|
-
context "when a destroy attribute is passed" do
|
610
|
-
|
611
|
-
before do
|
612
|
-
person.name_attributes =
|
613
|
-
{ id: name.id, _destroy: true }
|
614
|
-
end
|
615
|
-
|
616
|
-
it "does not destroy the document" do
|
617
|
-
person.name.should eq(name)
|
618
|
-
end
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
context "when update only is true" do
|
623
|
-
|
624
|
-
before(:all) do
|
625
|
-
Person.send(:undef_method, :name_attributes=)
|
626
|
-
Person.accepts_nested_attributes_for \
|
627
|
-
:name,
|
628
|
-
update_only: true,
|
629
|
-
allow_destroy: true
|
630
|
-
end
|
631
|
-
|
632
|
-
after(:all) do
|
633
|
-
Person.send(:undef_method, :name_attributes=)
|
634
|
-
Person.accepts_nested_attributes_for :name
|
635
|
-
end
|
636
|
-
|
637
|
-
context "when the id matches" do
|
638
|
-
|
639
|
-
before do
|
640
|
-
person.name_attributes =
|
641
|
-
{ id: name.id, first_name: "Ro" }
|
642
|
-
end
|
643
|
-
|
644
|
-
it "updates the existing document" do
|
645
|
-
person.name.first_name.should eq("Ro")
|
646
|
-
end
|
647
|
-
end
|
648
|
-
|
649
|
-
context "when the id does not match" do
|
650
|
-
|
651
|
-
before do
|
652
|
-
person.name_attributes =
|
653
|
-
{ id: Moped::BSON::ObjectId.new.to_s, first_name: "Durran" }
|
654
|
-
end
|
655
|
-
|
656
|
-
it "updates the existing document" do
|
657
|
-
person.name.first_name.should eq("Durran")
|
658
|
-
end
|
659
|
-
end
|
660
|
-
|
661
|
-
context "when passed a destroy truth" do
|
662
|
-
|
663
|
-
before do
|
664
|
-
person.name_attributes =
|
665
|
-
{ id: name.id, _destroy: true }
|
666
|
-
end
|
667
|
-
|
668
|
-
it "destroys the existing document" do
|
669
|
-
person.name.should be_nil
|
670
|
-
end
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
context "when ids are ObjectId strings" do
|
675
|
-
|
676
|
-
let(:quiz) do
|
677
|
-
person.quiz = Quiz.new(topic: "Math")
|
678
|
-
end
|
679
|
-
|
680
|
-
before do
|
681
|
-
person.quiz_attributes = {
|
682
|
-
"id" => quiz.id.to_s, topic: "English"
|
683
|
-
}
|
684
|
-
end
|
685
|
-
|
686
|
-
it "updates the existing document" do
|
687
|
-
person.quiz.topic.should eq("English")
|
688
|
-
end
|
689
|
-
end
|
690
|
-
end
|
691
|
-
end
|
692
|
-
end
|
693
|
-
|
694
|
-
context "when the nested document is invalid" do
|
695
|
-
|
696
|
-
before(:all) do
|
697
|
-
Person.validates_associated(:pet)
|
698
|
-
end
|
699
|
-
|
700
|
-
after(:all) do
|
701
|
-
Person.reset_callbacks(:validate)
|
702
|
-
end
|
703
|
-
|
704
|
-
before do
|
705
|
-
person.pet_attributes = { name: "$$$" }
|
706
|
-
end
|
707
|
-
|
708
|
-
it "propagates invalidity to parent" do
|
709
|
-
person.pet.should_not be_valid
|
710
|
-
person.should_not be_valid
|
711
|
-
end
|
712
|
-
end
|
713
|
-
|
714
|
-
context "when a type is passed" do
|
715
|
-
|
716
|
-
let(:canvas) do
|
717
|
-
Canvas.new
|
718
|
-
end
|
719
|
-
|
720
|
-
before do
|
721
|
-
Canvas.send(:undef_method, :writer_attributes=)
|
722
|
-
Canvas.accepts_nested_attributes_for :writer
|
723
|
-
canvas.writer_attributes = { _type: "HtmlWriter" }
|
724
|
-
end
|
725
|
-
|
726
|
-
it "instantiates an object of the given type" do
|
727
|
-
canvas.writer.class.should eq(HtmlWriter)
|
728
|
-
end
|
729
|
-
end
|
730
|
-
end
|
731
|
-
|
732
|
-
context "when the relation is embedded in" do
|
733
|
-
|
734
|
-
context "when the child is new" do
|
735
|
-
|
736
|
-
let(:animal) do
|
737
|
-
Animal.new
|
738
|
-
end
|
739
|
-
|
740
|
-
context "when no id has been passed" do
|
741
|
-
|
742
|
-
context "when no destroy attribute passed" do
|
743
|
-
|
744
|
-
before do
|
745
|
-
animal.person_attributes = { title: "Sir" }
|
746
|
-
end
|
747
|
-
|
748
|
-
it "builds a new document" do
|
749
|
-
animal.person.title.should eq("Sir")
|
750
|
-
end
|
751
|
-
|
752
|
-
end
|
753
|
-
|
754
|
-
context "when a destroy attribute is passed" do
|
755
|
-
|
756
|
-
context "when allow_destroy is true" do
|
757
|
-
|
758
|
-
before(:all) do
|
759
|
-
Animal.send(:undef_method, :person_attributes=)
|
760
|
-
Animal.accepts_nested_attributes_for :person, allow_destroy: true
|
761
|
-
end
|
762
|
-
|
763
|
-
after(:all) do
|
764
|
-
Animal.send(:undef_method, :person_attributes=)
|
765
|
-
Animal.accepts_nested_attributes_for :person
|
766
|
-
end
|
767
|
-
|
768
|
-
before do
|
769
|
-
animal.person_attributes = { title: "Sir", _destroy: 1 }
|
770
|
-
end
|
771
|
-
|
772
|
-
it "does not build a new document" do
|
773
|
-
animal.person.should be_nil
|
774
|
-
end
|
775
|
-
end
|
776
|
-
|
777
|
-
context "when allow_destroy is false" do
|
778
|
-
|
779
|
-
before(:all) do
|
780
|
-
Animal.send(:undef_method, :person_attributes=)
|
781
|
-
Animal.accepts_nested_attributes_for :person, allow_destroy: false
|
782
|
-
end
|
783
|
-
|
784
|
-
after(:all) do
|
785
|
-
Animal.send(:undef_method, :person_attributes=)
|
786
|
-
Animal.accepts_nested_attributes_for :person
|
787
|
-
end
|
788
|
-
|
789
|
-
before do
|
790
|
-
animal.person_attributes = { title: "Sir", _destroy: 1 }
|
791
|
-
end
|
792
|
-
|
793
|
-
it "builds a new document" do
|
794
|
-
animal.person.title.should eq("Sir")
|
795
|
-
end
|
796
|
-
end
|
797
|
-
end
|
798
|
-
end
|
799
|
-
|
800
|
-
context "when an id has been passed" do
|
801
|
-
|
802
|
-
let(:person) do
|
803
|
-
Person.new
|
804
|
-
end
|
805
|
-
|
806
|
-
context "when no destroy attribute passed" do
|
807
|
-
|
808
|
-
context "when the id matches" do
|
809
|
-
|
810
|
-
before do
|
811
|
-
animal.person_attributes = { id: person.id, title: "Sir" }
|
812
|
-
end
|
813
|
-
|
814
|
-
it "updates the existing document" do
|
815
|
-
animal.person.title.should eq("Sir")
|
816
|
-
end
|
817
|
-
end
|
818
|
-
end
|
819
|
-
|
820
|
-
context "when there is an existing document" do
|
821
|
-
|
822
|
-
before do
|
823
|
-
animal.person = person
|
824
|
-
end
|
825
|
-
|
826
|
-
context "when allow destroy is true" do
|
827
|
-
|
828
|
-
before(:all) do
|
829
|
-
Animal.send(:undef_method, :person_attributes=)
|
830
|
-
Animal.accepts_nested_attributes_for :person, allow_destroy: true
|
831
|
-
end
|
832
|
-
|
833
|
-
after(:all) do
|
834
|
-
Animal.send(:undef_method, :person_attributes=)
|
835
|
-
Animal.accepts_nested_attributes_for :person
|
836
|
-
end
|
837
|
-
|
838
|
-
[ 1, "1", true, "true" ].each do |truth|
|
839
|
-
|
840
|
-
context "when passed #{truth} with destroy" do
|
841
|
-
|
842
|
-
before do
|
843
|
-
animal.person_attributes =
|
844
|
-
{ id: person.id, _destroy: truth }
|
845
|
-
end
|
846
|
-
|
847
|
-
it "destroys the existing document" do
|
848
|
-
animal.person.should be_nil
|
849
|
-
end
|
850
|
-
end
|
851
|
-
end
|
852
|
-
|
853
|
-
[ nil, 0, "0", false, "false" ].each do |falsehood|
|
854
|
-
|
855
|
-
context "when passed #{falsehood} with destroy" do
|
856
|
-
|
857
|
-
before do
|
858
|
-
animal.person_attributes =
|
859
|
-
{ id: person.id, _destroy: falsehood }
|
860
|
-
end
|
861
|
-
|
862
|
-
it "does not destroy the existing document" do
|
863
|
-
animal.person.should eq(person)
|
864
|
-
end
|
865
|
-
end
|
866
|
-
end
|
867
|
-
end
|
868
|
-
|
869
|
-
context "when allow destroy is false" do
|
870
|
-
|
871
|
-
before(:all) do
|
872
|
-
Animal.send(:undef_method, :person_attributes=)
|
873
|
-
Animal.accepts_nested_attributes_for :person, allow_destroy: false
|
874
|
-
end
|
875
|
-
|
876
|
-
after(:all) do
|
877
|
-
Animal.send(:undef_method, :person_attributes=)
|
878
|
-
Animal.accepts_nested_attributes_for :person
|
879
|
-
end
|
880
|
-
|
881
|
-
context "when a destroy attribute is passed" do
|
882
|
-
|
883
|
-
before do
|
884
|
-
animal.person_attributes =
|
885
|
-
{ id: person.id, _destroy: true }
|
886
|
-
end
|
887
|
-
|
888
|
-
it "does not delete the document" do
|
889
|
-
animal.person.should eq(person)
|
890
|
-
end
|
891
|
-
end
|
892
|
-
end
|
893
|
-
|
894
|
-
context "when update only is true" do
|
895
|
-
|
896
|
-
before do
|
897
|
-
Animal.send(:undef_method, :person_attributes=)
|
898
|
-
Animal.accepts_nested_attributes_for \
|
899
|
-
:person,
|
900
|
-
update_only: true,
|
901
|
-
allow_destroy: true
|
902
|
-
end
|
903
|
-
|
904
|
-
context "when the id matches" do
|
905
|
-
|
906
|
-
before do
|
907
|
-
animal.person_attributes =
|
908
|
-
{ id: person.id, title: "Madam" }
|
909
|
-
end
|
910
|
-
|
911
|
-
it "updates the existing document" do
|
912
|
-
animal.person.title.should eq("Madam")
|
913
|
-
end
|
914
|
-
end
|
915
|
-
|
916
|
-
context "when the id does not match" do
|
917
|
-
|
918
|
-
before do
|
919
|
-
animal.person_attributes =
|
920
|
-
{ id: Moped::BSON::ObjectId.new.to_s, title: "Madam" }
|
921
|
-
end
|
922
|
-
|
923
|
-
it "updates the existing document" do
|
924
|
-
animal.person.title.should eq("Madam")
|
925
|
-
end
|
926
|
-
end
|
927
|
-
|
928
|
-
context "when passed a destroy truth" do
|
929
|
-
|
930
|
-
before do
|
931
|
-
animal.person_attributes =
|
932
|
-
{ id: person.id, title: "Madam", _destroy: "true" }
|
933
|
-
end
|
934
|
-
|
935
|
-
it "deletes the existing document" do
|
936
|
-
animal.person.should be_nil
|
937
|
-
end
|
938
|
-
end
|
939
|
-
end
|
940
|
-
end
|
941
|
-
end
|
942
|
-
|
943
|
-
context "when the nested document is invalid" do
|
944
|
-
|
945
|
-
before(:all) do
|
946
|
-
Person.validates_format_of :ssn, without: /\$\$\$/
|
947
|
-
end
|
948
|
-
|
949
|
-
after(:all) do
|
950
|
-
Person.reset_callbacks(:validate)
|
951
|
-
end
|
952
|
-
|
953
|
-
before do
|
954
|
-
animal.person_attributes = { ssn: '$$$' }
|
955
|
-
end
|
956
|
-
|
957
|
-
it "does not propagate invalidity to parent" do
|
958
|
-
animal.person.should_not be_valid
|
959
|
-
animal.should be_valid
|
960
|
-
end
|
961
|
-
end
|
962
|
-
end
|
963
|
-
|
964
|
-
context "when a type is passed" do
|
965
|
-
|
966
|
-
let(:tool) do
|
967
|
-
Tool.new
|
968
|
-
end
|
969
|
-
|
970
|
-
before do
|
971
|
-
tool.palette_attributes ={ _type: "BigPalette" }
|
972
|
-
end
|
973
|
-
|
974
|
-
it "instantiates an object of the given type" do
|
975
|
-
tool.palette.class.should eq(BigPalette)
|
976
|
-
end
|
977
|
-
end
|
978
|
-
end
|
979
|
-
|
980
|
-
context "when the relation is an embeds many" do
|
981
|
-
|
982
|
-
context "when the parent document is persisted" do
|
983
|
-
|
984
|
-
let(:person) do
|
985
|
-
Person.create
|
986
|
-
end
|
987
|
-
|
988
|
-
before do
|
989
|
-
Person.send(:undef_method, :addresses_attributes=)
|
990
|
-
Person.accepts_nested_attributes_for :addresses
|
991
|
-
end
|
992
|
-
|
993
|
-
after do
|
994
|
-
Person.send(:undef_method, :addresses_attributes=)
|
995
|
-
Person.accepts_nested_attributes_for :addresses
|
996
|
-
end
|
997
|
-
|
998
|
-
context "when setting the child attributes" do
|
999
|
-
|
1000
|
-
let(:attributes) do
|
1001
|
-
{ "foo" => { "street" => "Maybachufer" } }
|
1002
|
-
end
|
1003
|
-
|
1004
|
-
before do
|
1005
|
-
person.addresses_attributes = attributes
|
1006
|
-
end
|
1007
|
-
|
1008
|
-
it "sets the child documents" do
|
1009
|
-
person.addresses.first.street.should eq("Maybachufer")
|
1010
|
-
end
|
1011
|
-
|
1012
|
-
it "does not persist the child documents" do
|
1013
|
-
person.addresses.first.should_not be_persisted
|
1014
|
-
end
|
1015
|
-
|
1016
|
-
context "when saving the parent" do
|
1017
|
-
|
1018
|
-
before do
|
1019
|
-
person.save
|
1020
|
-
person.reload
|
1021
|
-
end
|
1022
|
-
|
1023
|
-
it "saves the child documents" do
|
1024
|
-
person.addresses.first.should be_persisted
|
1025
|
-
end
|
1026
|
-
end
|
1027
|
-
end
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
let(:person) do
|
1031
|
-
Person.new
|
1032
|
-
end
|
1033
|
-
|
1034
|
-
let(:address_one) do
|
1035
|
-
Address.new(street: "Unter den Linden")
|
1036
|
-
end
|
1037
|
-
|
1038
|
-
let(:address_two) do
|
1039
|
-
Address.new(street: "Kurfeurstendamm")
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
let(:phone_one) do
|
1043
|
-
ParanoidPhone.new(number: "1")
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
let(:phone_two) do
|
1047
|
-
ParanoidPhone.new(number: "2")
|
1048
|
-
end
|
1049
|
-
|
1050
|
-
context "when a limit is specified" do
|
1051
|
-
|
1052
|
-
before(:all) do
|
1053
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1054
|
-
Person.accepts_nested_attributes_for :addresses, limit: 2
|
1055
|
-
end
|
1056
|
-
|
1057
|
-
after(:all) do
|
1058
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1059
|
-
Person.accepts_nested_attributes_for :addresses
|
1060
|
-
end
|
1061
|
-
|
1062
|
-
context "when more are provided than the limit" do
|
1063
|
-
|
1064
|
-
let(:attributes) do
|
1065
|
-
{
|
1066
|
-
"foo" => { "street" => "Maybachufer" },
|
1067
|
-
"bar" => { "street" => "Alexander Platz" },
|
1068
|
-
"baz" => { "street" => "Unter den Linden" }
|
1069
|
-
}
|
1070
|
-
end
|
1071
|
-
|
1072
|
-
it "raises an error" do
|
1073
|
-
expect {
|
1074
|
-
person.addresses_attributes = attributes
|
1075
|
-
}.to raise_error(Mongoid::Errors::TooManyNestedAttributeRecords)
|
1076
|
-
end
|
1077
|
-
end
|
1078
|
-
|
1079
|
-
context "when less are provided than the limit" do
|
1080
|
-
|
1081
|
-
let(:attributes) do
|
1082
|
-
{
|
1083
|
-
"foo" => { "street" => "Maybachufer" },
|
1084
|
-
"bar" => { "street" => "Alexander Platz" }
|
1085
|
-
}
|
1086
|
-
end
|
1087
|
-
|
1088
|
-
before do
|
1089
|
-
person.addresses_attributes = attributes
|
1090
|
-
end
|
1091
|
-
|
1092
|
-
it "sets the documents on the relation" do
|
1093
|
-
person.addresses.size.should eq(2)
|
1094
|
-
end
|
1095
|
-
end
|
1096
|
-
|
1097
|
-
context "when an array of attributes are passed" do
|
1098
|
-
|
1099
|
-
let(:attributes) do
|
1100
|
-
[
|
1101
|
-
{ "street" => "Maybachufer" },
|
1102
|
-
{ "street" => "Alexander Platz" }
|
1103
|
-
]
|
1104
|
-
end
|
1105
|
-
|
1106
|
-
before do
|
1107
|
-
person.addresses_attributes = attributes
|
1108
|
-
end
|
1109
|
-
|
1110
|
-
it "sets the documents on the relation" do
|
1111
|
-
person.addresses.size.should eq(2)
|
1112
|
-
end
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
context "when cascading callbacks" do
|
1116
|
-
|
1117
|
-
before(:all) do
|
1118
|
-
Band.accepts_nested_attributes_for :records
|
1119
|
-
end
|
1120
|
-
|
1121
|
-
after(:all) do
|
1122
|
-
Band.send(:undef_method, :records_attributes=)
|
1123
|
-
end
|
1124
|
-
|
1125
|
-
let(:band) do
|
1126
|
-
Band.new
|
1127
|
-
end
|
1128
|
-
|
1129
|
-
let(:attributes) do
|
1130
|
-
[
|
1131
|
-
{ "name" => "101" },
|
1132
|
-
{ "name" => "Ultra" }
|
1133
|
-
]
|
1134
|
-
end
|
1135
|
-
|
1136
|
-
before do
|
1137
|
-
band.records_attributes = attributes
|
1138
|
-
end
|
1139
|
-
|
1140
|
-
context "when the parent is saved" do
|
1141
|
-
|
1142
|
-
before do
|
1143
|
-
band.save
|
1144
|
-
end
|
1145
|
-
|
1146
|
-
it "runs the first child create callbacks" do
|
1147
|
-
band.records.first.before_create_called.should be_true
|
1148
|
-
end
|
1149
|
-
|
1150
|
-
it "runs the last child create callbacks" do
|
1151
|
-
band.records.last.before_create_called.should be_true
|
1152
|
-
end
|
1153
|
-
end
|
1154
|
-
end
|
1155
|
-
end
|
1156
|
-
|
1157
|
-
context "when ids are passed" do
|
1158
|
-
|
1159
|
-
before do
|
1160
|
-
person.addresses << [ address_one, address_two ]
|
1161
|
-
end
|
1162
|
-
|
1163
|
-
context "when no destroy attributes are passed" do
|
1164
|
-
|
1165
|
-
context "when the ids match" do
|
1166
|
-
|
1167
|
-
before do
|
1168
|
-
person.addresses_attributes =
|
1169
|
-
{
|
1170
|
-
"foo" => { "id" => address_one.id, "street" => "Maybachufer" },
|
1171
|
-
"bar" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1172
|
-
}
|
1173
|
-
end
|
1174
|
-
|
1175
|
-
it "updates the first existing document" do
|
1176
|
-
person.addresses.first.street.should eq("Maybachufer")
|
1177
|
-
end
|
1178
|
-
|
1179
|
-
it "updates the second existing document" do
|
1180
|
-
person.addresses.second.street.should eq("Alexander Platz")
|
1181
|
-
end
|
1182
|
-
|
1183
|
-
it "does not add new documents" do
|
1184
|
-
person.addresses.size.should eq(2)
|
1185
|
-
end
|
1186
|
-
end
|
1187
|
-
|
1188
|
-
context "when the ids match in an array of attributes" do
|
1189
|
-
|
1190
|
-
context "when passing in id" do
|
1191
|
-
|
1192
|
-
before do
|
1193
|
-
person.addresses_attributes =
|
1194
|
-
[
|
1195
|
-
{ "id" => address_one.id, "street" => "Maybachufer" },
|
1196
|
-
{ "id" => address_two.id, "street" => "Alexander Platz" }
|
1197
|
-
]
|
1198
|
-
end
|
1199
|
-
|
1200
|
-
it "updates the first existing document" do
|
1201
|
-
person.addresses.collect { |a| a['street'] }.should include('Maybachufer')
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
it "updates the second existing document" do
|
1205
|
-
person.addresses.collect { |a| a['street'] }.should include('Alexander Platz')
|
1206
|
-
end
|
1207
|
-
|
1208
|
-
it "does not add new documents" do
|
1209
|
-
person.addresses.size.should eq(2)
|
1210
|
-
end
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
context "when passing in _id" do
|
1214
|
-
|
1215
|
-
before do
|
1216
|
-
person.addresses_attributes =
|
1217
|
-
[
|
1218
|
-
{ "_id" => address_one.id, "street" => "Maybachufer" },
|
1219
|
-
{ "_id" => address_two.id, "street" => "Alexander Platz" }
|
1220
|
-
]
|
1221
|
-
end
|
1222
|
-
|
1223
|
-
it "updates the first existing document" do
|
1224
|
-
person.addresses.collect { |a| a['street'] }.should include('Maybachufer')
|
1225
|
-
end
|
1226
|
-
|
1227
|
-
it "updates the second existing document" do
|
1228
|
-
person.addresses.collect { |a| a['street'] }.should include('Alexander Platz')
|
1229
|
-
end
|
1230
|
-
|
1231
|
-
it "does not add new documents" do
|
1232
|
-
person.addresses.size.should eq(2)
|
1233
|
-
end
|
1234
|
-
end
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
context "when the ids match in an array of attributes and start with '_'" do
|
1238
|
-
|
1239
|
-
before do
|
1240
|
-
person.addresses_attributes =
|
1241
|
-
[
|
1242
|
-
{ "_id" => address_one.id, "street" => "Maybachufer" },
|
1243
|
-
{ "_id" => address_two.id, "street" => "Alexander Platz" }
|
1244
|
-
]
|
1245
|
-
end
|
1246
|
-
|
1247
|
-
it "updates the first existing document" do
|
1248
|
-
person.addresses.collect { |a| a['street'] }.should include('Maybachufer')
|
1249
|
-
end
|
1250
|
-
|
1251
|
-
it "updates the second existing document" do
|
1252
|
-
person.addresses.collect { |a| a['street'] }.should include('Alexander Platz')
|
1253
|
-
end
|
1254
|
-
|
1255
|
-
it "does not add new documents" do
|
1256
|
-
person.addresses.size.should eq(2)
|
1257
|
-
end
|
1258
|
-
end
|
1259
|
-
|
1260
|
-
context "when the ids are _id symbols" do
|
1261
|
-
|
1262
|
-
before do
|
1263
|
-
person.addresses_attributes =
|
1264
|
-
[
|
1265
|
-
{ _id: address_one.id, "street" => "Maybachufer" },
|
1266
|
-
{ _id: address_two.id, "street" => "Alexander Platz" }
|
1267
|
-
]
|
1268
|
-
end
|
1269
|
-
|
1270
|
-
it "updates the first existing document" do
|
1271
|
-
person.addresses.collect { |a| a['street'] }.should include('Maybachufer')
|
1272
|
-
end
|
1273
|
-
|
1274
|
-
it "updates the second existing document" do
|
1275
|
-
person.addresses.collect { |a| a['street'] }.should include('Alexander Platz')
|
1276
|
-
end
|
1277
|
-
|
1278
|
-
it "does not add new documents" do
|
1279
|
-
person.addresses.size.should eq(2)
|
1280
|
-
end
|
1281
|
-
end
|
1282
|
-
|
1283
|
-
context "when the ids are id symbols" do
|
1284
|
-
|
1285
|
-
before do
|
1286
|
-
person.addresses_attributes =
|
1287
|
-
[
|
1288
|
-
{ id: address_one.id, "street" => "Maybachufer" },
|
1289
|
-
{ id: address_two.id, "street" => "Alexander Platz" }
|
1290
|
-
]
|
1291
|
-
end
|
1292
|
-
|
1293
|
-
it "updates the first existing document" do
|
1294
|
-
person.addresses.collect { |a| a['street'] }.should include('Maybachufer')
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
it "updates the second existing document" do
|
1298
|
-
person.addresses.collect { |a| a['street'] }.should include('Alexander Platz')
|
1299
|
-
end
|
1300
|
-
|
1301
|
-
it "does not add new documents" do
|
1302
|
-
person.addresses.size.should eq(2)
|
1303
|
-
end
|
1304
|
-
end
|
1305
|
-
|
1306
|
-
context "when the ids do not match" do
|
1307
|
-
|
1308
|
-
it "raises an error" do
|
1309
|
-
expect {
|
1310
|
-
person.addresses_attributes =
|
1311
|
-
{ "foo" => { "id" => "test", "street" => "Test" } }
|
1312
|
-
}.to raise_error
|
1313
|
-
end
|
1314
|
-
end
|
1315
|
-
end
|
1316
|
-
|
1317
|
-
context "when destroy attributes are passed" do
|
1318
|
-
|
1319
|
-
context "when the ids match" do
|
1320
|
-
|
1321
|
-
context "when allow_destroy is true" do
|
1322
|
-
|
1323
|
-
context "when the parent validation failed" do
|
1324
|
-
|
1325
|
-
before(:all) do
|
1326
|
-
Band.validates_presence_of :name
|
1327
|
-
Band.accepts_nested_attributes_for :records, :allow_destroy => true
|
1328
|
-
end
|
1329
|
-
|
1330
|
-
after(:all) do
|
1331
|
-
Band.send(:undef_method, :records_attributes=)
|
1332
|
-
Band.reset_callbacks(:validate)
|
1333
|
-
end
|
1334
|
-
|
1335
|
-
let!(:band) do
|
1336
|
-
Band.create(name: "Depeche Mode")
|
1337
|
-
end
|
1338
|
-
|
1339
|
-
let!(:record) do
|
1340
|
-
band.records.create
|
1341
|
-
end
|
1342
|
-
|
1343
|
-
let(:attributes) do
|
1344
|
-
{
|
1345
|
-
name: nil,
|
1346
|
-
records_attributes: { "foo" => { "id" => record.id, "_destroy" => true }}
|
1347
|
-
}
|
1348
|
-
end
|
1349
|
-
|
1350
|
-
before do
|
1351
|
-
band.update_attributes(attributes)
|
1352
|
-
end
|
1353
|
-
|
1354
|
-
it "does not remove the child document" do
|
1355
|
-
band.records.should_not be_empty
|
1356
|
-
end
|
1357
|
-
|
1358
|
-
it "keeps the child flagged for destruction" do
|
1359
|
-
record.should be_flagged_for_destroy
|
1360
|
-
end
|
1361
|
-
|
1362
|
-
it "does not persist any change" do
|
1363
|
-
band.reload.records.should eq([ record ])
|
1364
|
-
end
|
1365
|
-
end
|
1366
|
-
|
1367
|
-
context "when the child accesses the parent after destroy" do
|
1368
|
-
|
1369
|
-
before(:all) do
|
1370
|
-
Band.accepts_nested_attributes_for :records, :allow_destroy => true
|
1371
|
-
end
|
1372
|
-
|
1373
|
-
after(:all) do
|
1374
|
-
Band.send(:undef_method, :records_attributes=)
|
1375
|
-
end
|
1376
|
-
|
1377
|
-
let!(:band) do
|
1378
|
-
Band.create
|
1379
|
-
end
|
1380
|
-
|
1381
|
-
let!(:record) do
|
1382
|
-
band.records.create
|
1383
|
-
end
|
1384
|
-
|
1385
|
-
before do
|
1386
|
-
band.records_attributes =
|
1387
|
-
{ "foo" => { "id" => record.id, "_destroy" => true }}
|
1388
|
-
band.save
|
1389
|
-
end
|
1390
|
-
|
1391
|
-
it "deletes the child document" do
|
1392
|
-
band.records.should be_empty
|
1393
|
-
end
|
1394
|
-
|
1395
|
-
it "persists the changes" do
|
1396
|
-
band.reload.records.should be_empty
|
1397
|
-
end
|
1398
|
-
end
|
1399
|
-
|
1400
|
-
context "when the child has defaults" do
|
1401
|
-
|
1402
|
-
before(:all) do
|
1403
|
-
Person.accepts_nested_attributes_for :appointments, allow_destroy: true
|
1404
|
-
end
|
1405
|
-
|
1406
|
-
after(:all) do
|
1407
|
-
Person.send(:undef_method, :appointments_attributes=)
|
1408
|
-
end
|
1409
|
-
|
1410
|
-
context "when the parent is persisted" do
|
1411
|
-
|
1412
|
-
let!(:persisted) do
|
1413
|
-
Person.create(age: 42)
|
1414
|
-
end
|
1415
|
-
|
1416
|
-
context "when the child returns false in a before callback" do
|
1417
|
-
|
1418
|
-
context "when the child is paranoid" do
|
1419
|
-
|
1420
|
-
before(:all) do
|
1421
|
-
Person.accepts_nested_attributes_for :paranoid_phones, allow_destroy: true
|
1422
|
-
end
|
1423
|
-
|
1424
|
-
after(:all) do
|
1425
|
-
Person.send(:undef_method, :paranoid_phones=)
|
1426
|
-
Person.accepts_nested_attributes_for :paranoid_phones
|
1427
|
-
end
|
1428
|
-
|
1429
|
-
let!(:phone) do
|
1430
|
-
persisted.paranoid_phones.create
|
1431
|
-
end
|
1432
|
-
|
1433
|
-
before do
|
1434
|
-
persisted.paranoid_phones_attributes =
|
1435
|
-
{ "foo" => { "id" => phone.id, "number" => 42, "_destroy" => true }}
|
1436
|
-
end
|
1437
|
-
|
1438
|
-
it "does not destroy the child" do
|
1439
|
-
persisted.reload.paranoid_phones.should_not be_empty
|
1440
|
-
end
|
1441
|
-
end
|
1442
|
-
|
1443
|
-
context "when the child is not paranoid" do
|
1444
|
-
|
1445
|
-
let(:actor) do
|
1446
|
-
Actor.create
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
let!(:thing) do
|
1450
|
-
actor.things.create
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
before do
|
1454
|
-
actor.things_attributes =
|
1455
|
-
{ "foo" => { "id" => thing.id, "_destroy" => true }}
|
1456
|
-
actor.save
|
1457
|
-
end
|
1458
|
-
|
1459
|
-
it "does not destroy the child" do
|
1460
|
-
actor.reload.things.should_not be_empty
|
1461
|
-
end
|
1462
|
-
end
|
1463
|
-
end
|
1464
|
-
|
1465
|
-
context "when only 1 child has the default persisted" do
|
1466
|
-
|
1467
|
-
let!(:app_one) do
|
1468
|
-
persisted.appointments.create
|
1469
|
-
end
|
1470
|
-
|
1471
|
-
let!(:app_two) do
|
1472
|
-
persisted.appointments.create.tap do |app|
|
1473
|
-
app.unset(:timed)
|
1474
|
-
end
|
1475
|
-
end
|
1476
|
-
|
1477
|
-
context "when destroying both children" do
|
1478
|
-
|
1479
|
-
let(:from_db) do
|
1480
|
-
Person.find(persisted.id)
|
1481
|
-
end
|
1482
|
-
|
1483
|
-
before do
|
1484
|
-
from_db.appointments_attributes =
|
1485
|
-
{
|
1486
|
-
"bar" => { "id" => app_one.id, "_destroy" => true },
|
1487
|
-
"foo" => { "id" => app_two.id, "_destroy" => true }
|
1488
|
-
}
|
1489
|
-
from_db.save
|
1490
|
-
end
|
1491
|
-
|
1492
|
-
it "destroys both children" do
|
1493
|
-
from_db.appointments.should be_empty
|
1494
|
-
end
|
1495
|
-
|
1496
|
-
it "persists the deletes" do
|
1497
|
-
from_db.reload.appointments.should be_empty
|
1498
|
-
end
|
1499
|
-
end
|
1500
|
-
end
|
1501
|
-
end
|
1502
|
-
end
|
1503
|
-
|
1504
|
-
context "when the child is not paranoid" do
|
1505
|
-
|
1506
|
-
before(:all) do
|
1507
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1508
|
-
Person.accepts_nested_attributes_for :addresses, allow_destroy: true
|
1509
|
-
end
|
1510
|
-
|
1511
|
-
after(:all) do
|
1512
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1513
|
-
Person.accepts_nested_attributes_for :addresses
|
1514
|
-
end
|
1515
|
-
|
1516
|
-
[ 1, "1", true, "true" ].each do |truth|
|
1517
|
-
|
1518
|
-
context "when passed a #{truth} with destroy" do
|
1519
|
-
|
1520
|
-
context "when the parent is new" do
|
1521
|
-
|
1522
|
-
context "when provided a hash of attributes" do
|
1523
|
-
|
1524
|
-
before do
|
1525
|
-
person.addresses_attributes =
|
1526
|
-
{
|
1527
|
-
"bar" => { "id" => address_one.id.to_s, "_destroy" => truth },
|
1528
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1529
|
-
}
|
1530
|
-
end
|
1531
|
-
|
1532
|
-
it "deletes the marked document" do
|
1533
|
-
person.addresses.size.should eq(1)
|
1534
|
-
end
|
1535
|
-
|
1536
|
-
it "does not delete the unmarked document" do
|
1537
|
-
person.addresses.first.street.should eq("Alexander Platz")
|
1538
|
-
end
|
1539
|
-
end
|
1540
|
-
|
1541
|
-
context "when provided an array of attributes" do
|
1542
|
-
|
1543
|
-
before do
|
1544
|
-
person.addresses_attributes =
|
1545
|
-
[
|
1546
|
-
{ "id" => address_one.id.to_s, "_destroy" => truth },
|
1547
|
-
{ "id" => address_two.id, "street" => "Alexander Platz" }
|
1548
|
-
]
|
1549
|
-
end
|
1550
|
-
|
1551
|
-
it "deletes the marked document" do
|
1552
|
-
person.addresses.size.should eq(1)
|
1553
|
-
end
|
1554
|
-
|
1555
|
-
it "does not delete the unmarked document" do
|
1556
|
-
person.addresses.first.street.should eq("Alexander Platz")
|
1557
|
-
end
|
1558
|
-
end
|
1559
|
-
end
|
1560
|
-
|
1561
|
-
context "when the parent is persisted" do
|
1562
|
-
|
1563
|
-
let!(:persisted) do
|
1564
|
-
Person.create do |p|
|
1565
|
-
p.addresses << [ address_one, address_two ]
|
1566
|
-
end
|
1567
|
-
end
|
1568
|
-
|
1569
|
-
context "when setting, pulling, and pushing in one op" do
|
1570
|
-
|
1571
|
-
before do
|
1572
|
-
persisted.addresses_attributes =
|
1573
|
-
{
|
1574
|
-
"bar" => { "id" => address_one.id, "_destroy" => truth },
|
1575
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" },
|
1576
|
-
"baz" => { "street" => "Potsdammer Platz" }
|
1577
|
-
}
|
1578
|
-
end
|
1579
|
-
|
1580
|
-
it "does not remove the first document from the relation" do
|
1581
|
-
persisted.addresses.size.should eq(3)
|
1582
|
-
end
|
1583
|
-
|
1584
|
-
it "flags the destroyed document for removal" do
|
1585
|
-
address_one.should be_marked_for_destruction
|
1586
|
-
end
|
1587
|
-
|
1588
|
-
it "does not delete the unmarked document" do
|
1589
|
-
persisted.addresses.second.street.should eq(
|
1590
|
-
"Alexander Platz"
|
1591
|
-
)
|
1592
|
-
end
|
1593
|
-
|
1594
|
-
it "adds the new document to the relation" do
|
1595
|
-
persisted.addresses.last.street.should eq(
|
1596
|
-
"Potsdammer Platz"
|
1597
|
-
)
|
1598
|
-
end
|
1599
|
-
|
1600
|
-
it "has the proper persisted count" do
|
1601
|
-
persisted.addresses.count.should eq(2)
|
1602
|
-
end
|
1603
|
-
|
1604
|
-
it "does not delete the removed document" do
|
1605
|
-
address_one.should_not be_destroyed
|
1606
|
-
end
|
1607
|
-
|
1608
|
-
context "when saving the parent" do
|
1609
|
-
|
1610
|
-
before do
|
1611
|
-
persisted.with(safe: true).save
|
1612
|
-
end
|
1613
|
-
|
1614
|
-
it "deletes the marked document from the relation" do
|
1615
|
-
persisted.reload.addresses.count.should eq(2)
|
1616
|
-
end
|
1617
|
-
|
1618
|
-
it "does not delete the unmarked document" do
|
1619
|
-
persisted.reload.addresses.first.street.should eq(
|
1620
|
-
"Alexander Platz"
|
1621
|
-
)
|
1622
|
-
end
|
1623
|
-
|
1624
|
-
it "persists the new document to the relation" do
|
1625
|
-
persisted.reload.addresses.last.street.should eq(
|
1626
|
-
"Potsdammer Platz"
|
1627
|
-
)
|
1628
|
-
end
|
1629
|
-
end
|
1630
|
-
end
|
1631
|
-
|
1632
|
-
context "when pulling and pushing in one op" do
|
1633
|
-
|
1634
|
-
before do
|
1635
|
-
persisted.addresses_attributes =
|
1636
|
-
{
|
1637
|
-
"bar" => { "id" => address_one.id, "_destroy" => truth },
|
1638
|
-
"baz" => { "street" => "Potsdammer Platz" }
|
1639
|
-
}
|
1640
|
-
end
|
1641
|
-
|
1642
|
-
it "does not remove the first document from the relation" do
|
1643
|
-
persisted.addresses.size.should eq(3)
|
1644
|
-
end
|
1645
|
-
|
1646
|
-
it "marks the first document for destruction" do
|
1647
|
-
address_one.should be_marked_for_destruction
|
1648
|
-
end
|
1649
|
-
|
1650
|
-
it "adds the new document to the relation" do
|
1651
|
-
persisted.addresses.last.street.should eq(
|
1652
|
-
"Potsdammer Platz"
|
1653
|
-
)
|
1654
|
-
end
|
1655
|
-
|
1656
|
-
it "has the proper persisted count" do
|
1657
|
-
persisted.addresses.count.should eq(2)
|
1658
|
-
end
|
1659
|
-
|
1660
|
-
it "does not delete the removed document" do
|
1661
|
-
address_one.should_not be_destroyed
|
1662
|
-
end
|
1663
|
-
|
1664
|
-
context "when saving the parent" do
|
1665
|
-
|
1666
|
-
before do
|
1667
|
-
persisted.with(safe: true).save
|
1668
|
-
end
|
1669
|
-
|
1670
|
-
it "deletes the marked document from the relation" do
|
1671
|
-
persisted.reload.addresses.count.should eq(2)
|
1672
|
-
end
|
1673
|
-
|
1674
|
-
it "persists the new document to the relation" do
|
1675
|
-
persisted.reload.addresses.last.street.should eq(
|
1676
|
-
"Potsdammer Platz"
|
1677
|
-
)
|
1678
|
-
end
|
1679
|
-
end
|
1680
|
-
end
|
1681
|
-
end
|
1682
|
-
end
|
1683
|
-
end
|
1684
|
-
|
1685
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
1686
|
-
|
1687
|
-
context "when passed a #{falsehood} with destroy" do
|
1688
|
-
|
1689
|
-
before do
|
1690
|
-
person.addresses_attributes =
|
1691
|
-
{
|
1692
|
-
"bar" => { "id" => address_one.id, "_destroy" => falsehood },
|
1693
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1694
|
-
}
|
1695
|
-
end
|
1696
|
-
|
1697
|
-
it "does not delete the marked document" do
|
1698
|
-
person.addresses.size.should eq(2)
|
1699
|
-
end
|
1700
|
-
|
1701
|
-
it "does not delete the unmarked document" do
|
1702
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
1703
|
-
end
|
1704
|
-
end
|
1705
|
-
end
|
1706
|
-
end
|
1707
|
-
|
1708
|
-
context "when the child is paranoid" do
|
1709
|
-
|
1710
|
-
before(:all) do
|
1711
|
-
Person.send(:undef_method, :paranoid_phones_attributes=)
|
1712
|
-
Person.accepts_nested_attributes_for :paranoid_phones,
|
1713
|
-
allow_destroy: true
|
1714
|
-
end
|
1715
|
-
|
1716
|
-
after(:all) do
|
1717
|
-
Person.send(:undef_method, :paranoid_phones_attributes=)
|
1718
|
-
Person.accepts_nested_attributes_for :paranoid_phones
|
1719
|
-
end
|
1720
|
-
|
1721
|
-
[ 1, "1", true, "true" ].each do |truth|
|
1722
|
-
|
1723
|
-
context "when passed a #{truth} with destroy" do
|
1724
|
-
|
1725
|
-
context "when the parent is persisted" do
|
1726
|
-
|
1727
|
-
let!(:persisted) do
|
1728
|
-
Person.create do |p|
|
1729
|
-
p.paranoid_phones << [ phone_one, phone_two ]
|
1730
|
-
end
|
1731
|
-
end
|
1732
|
-
|
1733
|
-
context "when setting, pulling, and pushing in one op" do
|
1734
|
-
|
1735
|
-
before do
|
1736
|
-
persisted.paranoid_phones_attributes =
|
1737
|
-
{
|
1738
|
-
"bar" => { "id" => phone_one.id, "_destroy" => truth },
|
1739
|
-
"foo" => { "id" => phone_two.id, "number" => "3" },
|
1740
|
-
"baz" => { "number" => "4" }
|
1741
|
-
}
|
1742
|
-
end
|
1743
|
-
|
1744
|
-
it "removes the first document from the relation" do
|
1745
|
-
persisted.paranoid_phones.size.should eq(2)
|
1746
|
-
end
|
1747
|
-
|
1748
|
-
it "does not delete the unmarked document" do
|
1749
|
-
persisted.paranoid_phones.first.number.should eq("3")
|
1750
|
-
end
|
1751
|
-
|
1752
|
-
it "adds the new document to the relation" do
|
1753
|
-
persisted.paranoid_phones.last.number.should eq("4")
|
1754
|
-
end
|
1755
|
-
|
1756
|
-
it "has the proper persisted count" do
|
1757
|
-
persisted.paranoid_phones.count.should eq(1)
|
1758
|
-
end
|
1759
|
-
|
1760
|
-
it "soft deletes the removed document" do
|
1761
|
-
phone_one.should be_destroyed
|
1762
|
-
end
|
1763
|
-
|
1764
|
-
context "when saving the parent" do
|
1765
|
-
|
1766
|
-
before do
|
1767
|
-
persisted.with(safe: true).save
|
1768
|
-
end
|
1769
|
-
|
1770
|
-
it "deletes the marked document from the relation" do
|
1771
|
-
persisted.reload.paranoid_phones.count.should eq(2)
|
1772
|
-
end
|
1773
|
-
|
1774
|
-
it "does not delete the unmarked document" do
|
1775
|
-
persisted.reload.paranoid_phones.first.number.should eq("3")
|
1776
|
-
end
|
1777
|
-
|
1778
|
-
it "persists the new document to the relation" do
|
1779
|
-
persisted.reload.paranoid_phones.last.number.should eq("4")
|
1780
|
-
end
|
1781
|
-
end
|
1782
|
-
end
|
1783
|
-
end
|
1784
|
-
end
|
1785
|
-
end
|
1786
|
-
end
|
1787
|
-
end
|
1788
|
-
|
1789
|
-
context "when allow_destroy is false" do
|
1790
|
-
|
1791
|
-
before(:all) do
|
1792
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1793
|
-
Person.accepts_nested_attributes_for :addresses, allow_destroy: false
|
1794
|
-
end
|
1795
|
-
|
1796
|
-
after(:all) do
|
1797
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1798
|
-
Person.accepts_nested_attributes_for :addresses
|
1799
|
-
end
|
1800
|
-
|
1801
|
-
[ 1, "1", true, "true" ].each do |truth|
|
1802
|
-
|
1803
|
-
context "when passed a #{truth} with destroy" do
|
1804
|
-
|
1805
|
-
before do
|
1806
|
-
person.addresses_attributes =
|
1807
|
-
{
|
1808
|
-
"bar" => {
|
1809
|
-
"id" => address_one.id, "street" => "Maybachufer", "_destroy" => truth },
|
1810
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1811
|
-
}
|
1812
|
-
end
|
1813
|
-
|
1814
|
-
it "does not ignore the marked document" do
|
1815
|
-
person.addresses.first.street.should eq("Maybachufer")
|
1816
|
-
end
|
1817
|
-
|
1818
|
-
it "does not delete the unmarked document" do
|
1819
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
1820
|
-
end
|
1821
|
-
|
1822
|
-
it "does not add additional documents" do
|
1823
|
-
person.addresses.size.should eq(2)
|
1824
|
-
end
|
1825
|
-
end
|
1826
|
-
end
|
1827
|
-
|
1828
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
1829
|
-
|
1830
|
-
context "when passed a #{falsehood} with destroy" do
|
1831
|
-
|
1832
|
-
before do
|
1833
|
-
person.addresses_attributes =
|
1834
|
-
{
|
1835
|
-
"bar" => { "id" => address_one.id, "_destroy" => falsehood },
|
1836
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1837
|
-
}
|
1838
|
-
end
|
1839
|
-
|
1840
|
-
it "does not delete the marked document" do
|
1841
|
-
person.addresses.size.should eq(2)
|
1842
|
-
end
|
1843
|
-
|
1844
|
-
it "does not delete the unmarked document" do
|
1845
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
1846
|
-
end
|
1847
|
-
end
|
1848
|
-
end
|
1849
|
-
end
|
1850
|
-
|
1851
|
-
context "when allow_destroy is undefined" do
|
1852
|
-
|
1853
|
-
before(:all) do
|
1854
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1855
|
-
Person.accepts_nested_attributes_for :addresses
|
1856
|
-
end
|
1857
|
-
|
1858
|
-
[ 1, "1", true, "true" ].each do |truth|
|
1859
|
-
|
1860
|
-
context "when passed a #{truth} with destroy" do
|
1861
|
-
|
1862
|
-
before do
|
1863
|
-
person.addresses_attributes =
|
1864
|
-
{
|
1865
|
-
"bar" => {
|
1866
|
-
"id" => address_one.id, "street" => "Maybachufer", "_destroy" => truth },
|
1867
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1868
|
-
}
|
1869
|
-
end
|
1870
|
-
|
1871
|
-
it "does not ignore the marked document" do
|
1872
|
-
person.addresses.first.street.should eq("Maybachufer")
|
1873
|
-
end
|
1874
|
-
|
1875
|
-
it "does not delete the unmarked document" do
|
1876
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
1877
|
-
end
|
1878
|
-
|
1879
|
-
it "does not add additional documents" do
|
1880
|
-
person.addresses.size.should eq(2)
|
1881
|
-
end
|
1882
|
-
end
|
1883
|
-
end
|
1884
|
-
|
1885
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
1886
|
-
|
1887
|
-
context "when passed a #{falsehood} with destroy" do
|
1888
|
-
|
1889
|
-
before do
|
1890
|
-
person.addresses_attributes =
|
1891
|
-
{
|
1892
|
-
"bar" => { "id" => address_one.id, "_destroy" => falsehood },
|
1893
|
-
"foo" => { "id" => address_two.id, "street" => "Alexander Platz" }
|
1894
|
-
}
|
1895
|
-
end
|
1896
|
-
|
1897
|
-
it "does not delete the marked document" do
|
1898
|
-
person.addresses.size.should eq(2)
|
1899
|
-
end
|
1900
|
-
|
1901
|
-
it "does not delete the unmarked document" do
|
1902
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
1903
|
-
end
|
1904
|
-
end
|
1905
|
-
end
|
1906
|
-
end
|
1907
|
-
end
|
1908
|
-
end
|
1909
|
-
end
|
1910
|
-
|
1911
|
-
context "when no ids are passed" do
|
1912
|
-
|
1913
|
-
context "when no destroy attributes are passed" do
|
1914
|
-
|
1915
|
-
before do
|
1916
|
-
person.addresses_attributes =
|
1917
|
-
{
|
1918
|
-
"4" => { "street" => "Maybachufer" },
|
1919
|
-
"1" => { "street" => "Frederichstrasse" },
|
1920
|
-
"2" => { "street" => "Alexander Platz" }
|
1921
|
-
}
|
1922
|
-
end
|
1923
|
-
|
1924
|
-
it "builds a new first document" do
|
1925
|
-
person.addresses.first.street.should eq("Frederichstrasse")
|
1926
|
-
end
|
1927
|
-
|
1928
|
-
it "builds a new second document" do
|
1929
|
-
person.addresses.second.street.should eq("Alexander Platz")
|
1930
|
-
end
|
1931
|
-
|
1932
|
-
it "builds a new third document" do
|
1933
|
-
person.addresses.third.street.should eq("Maybachufer")
|
1934
|
-
end
|
1935
|
-
|
1936
|
-
it "does not add extra documents" do
|
1937
|
-
person.addresses.size.should eq(3)
|
1938
|
-
end
|
1939
|
-
|
1940
|
-
it "adds the documents in the sorted hash key order" do
|
1941
|
-
person.addresses.map(&:street).should eq(
|
1942
|
-
[ "Frederichstrasse", "Alexander Platz", "Maybachufer" ]
|
1943
|
-
)
|
1944
|
-
end
|
1945
|
-
end
|
1946
|
-
|
1947
|
-
context "when a reject block is supplied" do
|
1948
|
-
|
1949
|
-
before(:all) do
|
1950
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1951
|
-
Person.accepts_nested_attributes_for \
|
1952
|
-
:addresses, reject_if: ->(attrs){ attrs["street"].blank? }
|
1953
|
-
end
|
1954
|
-
|
1955
|
-
after(:all) do
|
1956
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1957
|
-
Person.accepts_nested_attributes_for :addresses
|
1958
|
-
end
|
1959
|
-
|
1960
|
-
context "when the attributes match" do
|
1961
|
-
|
1962
|
-
before do
|
1963
|
-
person.addresses_attributes =
|
1964
|
-
{ "3" => { "city" => "Berlin" } }
|
1965
|
-
end
|
1966
|
-
|
1967
|
-
it "does not add the new document" do
|
1968
|
-
person.addresses.should be_empty
|
1969
|
-
end
|
1970
|
-
end
|
1971
|
-
|
1972
|
-
context "when the attributes do not match" do
|
1973
|
-
|
1974
|
-
before do
|
1975
|
-
person.addresses_attributes =
|
1976
|
-
{ "3" => { "street" => "Maybachufer" } }
|
1977
|
-
end
|
1978
|
-
|
1979
|
-
it "adds the new document" do
|
1980
|
-
person.addresses.size.should eq(1)
|
1981
|
-
end
|
1982
|
-
|
1983
|
-
it "sets the correct attributes" do
|
1984
|
-
person.addresses.first.street.should eq("Maybachufer")
|
1985
|
-
end
|
1986
|
-
end
|
1987
|
-
end
|
1988
|
-
|
1989
|
-
context "when :reject_if => :all_blank is supplied" do
|
1990
|
-
|
1991
|
-
before(:all) do
|
1992
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1993
|
-
Person.accepts_nested_attributes_for \
|
1994
|
-
:addresses, reject_if: :all_blank
|
1995
|
-
end
|
1996
|
-
|
1997
|
-
after(:all) do
|
1998
|
-
Person.send(:undef_method, :addresses_attributes=)
|
1999
|
-
Person.accepts_nested_attributes_for :addresses
|
2000
|
-
end
|
2001
|
-
|
2002
|
-
context "when all attributes are empty" do
|
2003
|
-
|
2004
|
-
before do
|
2005
|
-
person.addresses_attributes =
|
2006
|
-
{ "3" => { "city" => "" } }
|
2007
|
-
end
|
2008
|
-
|
2009
|
-
it "does not add the new document" do
|
2010
|
-
person.addresses.should be_empty
|
2011
|
-
end
|
2012
|
-
end
|
2013
|
-
|
2014
|
-
context "when an attribute is not-empty" do
|
2015
|
-
|
2016
|
-
before do
|
2017
|
-
person.addresses_attributes =
|
2018
|
-
{ "3" => { "street" => "Maybachufer" } }
|
2019
|
-
end
|
2020
|
-
|
2021
|
-
it "adds the new document" do
|
2022
|
-
person.addresses.size.should eq(1)
|
2023
|
-
end
|
2024
|
-
|
2025
|
-
it "sets the correct attributes" do
|
2026
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2027
|
-
end
|
2028
|
-
end
|
2029
|
-
end
|
2030
|
-
|
2031
|
-
context "when destroy attributes are passed" do
|
2032
|
-
|
2033
|
-
context "when allow_destroy is true" do
|
2034
|
-
|
2035
|
-
before(:all) do
|
2036
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2037
|
-
Person.accepts_nested_attributes_for :addresses, allow_destroy: true
|
2038
|
-
end
|
2039
|
-
|
2040
|
-
after(:all) do
|
2041
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2042
|
-
Person.accepts_nested_attributes_for :addresses
|
2043
|
-
end
|
2044
|
-
|
2045
|
-
[ 1, "1", true, "true" ].each do |truth|
|
2046
|
-
|
2047
|
-
context "when passed a #{truth} with destroy" do
|
2048
|
-
|
2049
|
-
before do
|
2050
|
-
person.addresses_attributes =
|
2051
|
-
{
|
2052
|
-
"bar" => { "street" => "Maybachufer", "_destroy" => truth },
|
2053
|
-
"foo" => { "street" => "Alexander Platz" }
|
2054
|
-
}
|
2055
|
-
end
|
2056
|
-
|
2057
|
-
it "ignores the the marked document" do
|
2058
|
-
person.addresses.size.should eq(1)
|
2059
|
-
end
|
2060
|
-
|
2061
|
-
it "adds the new unmarked document" do
|
2062
|
-
person.addresses.first.street.should eq("Alexander Platz")
|
2063
|
-
end
|
2064
|
-
end
|
2065
|
-
end
|
2066
|
-
|
2067
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
2068
|
-
|
2069
|
-
context "when passed a #{falsehood} with destroy" do
|
2070
|
-
|
2071
|
-
before do
|
2072
|
-
person.addresses_attributes =
|
2073
|
-
{
|
2074
|
-
"0" => { "street" => "Maybachufer", "_destroy" => falsehood },
|
2075
|
-
"1" => { "street" => "Alexander Platz" }
|
2076
|
-
}
|
2077
|
-
end
|
2078
|
-
|
2079
|
-
it "adds the new marked document" do
|
2080
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2081
|
-
end
|
2082
|
-
|
2083
|
-
it "adds the new unmarked document" do
|
2084
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
2085
|
-
end
|
2086
|
-
|
2087
|
-
it "does not add extra documents" do
|
2088
|
-
person.addresses.size.should eq(2)
|
2089
|
-
end
|
2090
|
-
end
|
2091
|
-
end
|
2092
|
-
end
|
2093
|
-
|
2094
|
-
context "when allow destroy is false" do
|
2095
|
-
|
2096
|
-
before(:all) do
|
2097
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2098
|
-
Person.accepts_nested_attributes_for :addresses, allow_destroy: false
|
2099
|
-
end
|
2100
|
-
|
2101
|
-
after(:all) do
|
2102
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2103
|
-
Person.accepts_nested_attributes_for :addresses
|
2104
|
-
end
|
2105
|
-
|
2106
|
-
[ 1, "1", true, "true" ].each do |truth|
|
2107
|
-
|
2108
|
-
context "when passed a #{truth} with destroy" do
|
2109
|
-
|
2110
|
-
before do
|
2111
|
-
person.addresses_attributes =
|
2112
|
-
{
|
2113
|
-
"0" => { "street" => "Maybachufer", "_destroy" => truth },
|
2114
|
-
"1" => { "street" => "Alexander Platz" }
|
2115
|
-
}
|
2116
|
-
end
|
2117
|
-
|
2118
|
-
it "adds the the marked document" do
|
2119
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2120
|
-
end
|
2121
|
-
|
2122
|
-
it "adds the new unmarked document" do
|
2123
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
2124
|
-
end
|
2125
|
-
|
2126
|
-
it "adds the correct number of documents" do
|
2127
|
-
person.addresses.size.should eq(2)
|
2128
|
-
end
|
2129
|
-
end
|
2130
|
-
end
|
2131
|
-
|
2132
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
2133
|
-
|
2134
|
-
context "when passed a #{falsehood} with destroy" do
|
2135
|
-
|
2136
|
-
before do
|
2137
|
-
person.addresses_attributes =
|
2138
|
-
{
|
2139
|
-
"0" => { "street" => "Maybachufer", "_destroy" => falsehood },
|
2140
|
-
"1" => { "street" => "Alexander Platz" }
|
2141
|
-
}
|
2142
|
-
end
|
2143
|
-
|
2144
|
-
it "adds the new marked document" do
|
2145
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2146
|
-
end
|
2147
|
-
|
2148
|
-
it "adds the new unmarked document" do
|
2149
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
2150
|
-
end
|
2151
|
-
|
2152
|
-
it "does not add extra documents" do
|
2153
|
-
person.addresses.size.should eq(2)
|
2154
|
-
end
|
2155
|
-
end
|
2156
|
-
end
|
2157
|
-
end
|
2158
|
-
|
2159
|
-
context "when allow destroy is not defined" do
|
2160
|
-
|
2161
|
-
before(:all) do
|
2162
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2163
|
-
Person.accepts_nested_attributes_for :addresses
|
2164
|
-
end
|
2165
|
-
|
2166
|
-
[ 1, "1", true, "true" ].each do |truth|
|
2167
|
-
|
2168
|
-
context "when passed a #{truth} with destroy" do
|
2169
|
-
|
2170
|
-
before do
|
2171
|
-
person.addresses_attributes =
|
2172
|
-
{
|
2173
|
-
"0" => { "street" => "Maybachufer", "_destroy" => truth },
|
2174
|
-
"1" => { "street" => "Alexander Platz" }
|
2175
|
-
}
|
2176
|
-
end
|
2177
|
-
|
2178
|
-
it "adds the the marked document" do
|
2179
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2180
|
-
end
|
2181
|
-
|
2182
|
-
it "adds the new unmarked document" do
|
2183
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
2184
|
-
end
|
2185
|
-
|
2186
|
-
it "adds the correct number of documents" do
|
2187
|
-
person.addresses.size.should eq(2)
|
2188
|
-
end
|
2189
|
-
end
|
2190
|
-
end
|
2191
|
-
|
2192
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
2193
|
-
|
2194
|
-
context "when passed a #{falsehood} with destroy" do
|
2195
|
-
|
2196
|
-
before do
|
2197
|
-
person.addresses_attributes =
|
2198
|
-
{
|
2199
|
-
"0" => { "street" => "Maybachufer", "_destroy" => falsehood },
|
2200
|
-
"1" => { "street" => "Alexander Platz" }
|
2201
|
-
}
|
2202
|
-
end
|
2203
|
-
|
2204
|
-
it "adds the new marked document" do
|
2205
|
-
person.addresses.first.street.should eq("Maybachufer")
|
2206
|
-
end
|
2207
|
-
|
2208
|
-
it "adds the new unmarked document" do
|
2209
|
-
person.addresses.last.street.should eq("Alexander Platz")
|
2210
|
-
end
|
2211
|
-
|
2212
|
-
it "does not add extra documents" do
|
2213
|
-
person.addresses.size.should eq(2)
|
2214
|
-
end
|
2215
|
-
end
|
2216
|
-
end
|
2217
|
-
end
|
2218
|
-
end
|
2219
|
-
|
2220
|
-
context "when 'reject_if: :all_blank' and 'allow_destroy: true' are specified" do
|
2221
|
-
|
2222
|
-
before(:all) do
|
2223
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2224
|
-
Person.accepts_nested_attributes_for \
|
2225
|
-
:addresses, reject_if: :all_blank, allow_destroy: true
|
2226
|
-
end
|
2227
|
-
|
2228
|
-
after(:all) do
|
2229
|
-
Person.send(:undef_method, :addresses_attributes=)
|
2230
|
-
Person.accepts_nested_attributes_for :addresses
|
2231
|
-
end
|
2232
|
-
|
2233
|
-
context "when all attributes are blank and _destroy has a truthy, non-blank value" do
|
2234
|
-
|
2235
|
-
before do
|
2236
|
-
person.addresses_attributes =
|
2237
|
-
{ "3" => { last_name: "", _destroy: "0" } }
|
2238
|
-
end
|
2239
|
-
|
2240
|
-
it "does not add the document" do
|
2241
|
-
person.addresses.should be_empty
|
2242
|
-
end
|
2243
|
-
end
|
2244
|
-
end
|
2245
|
-
end
|
2246
|
-
|
2247
|
-
context "when the nested document is invalid" do
|
2248
|
-
|
2249
|
-
before(:all) do
|
2250
|
-
Person.validates_associated(:addresses)
|
2251
|
-
end
|
2252
|
-
|
2253
|
-
after(:all) do
|
2254
|
-
Person.reset_callbacks(:validate)
|
2255
|
-
end
|
2256
|
-
|
2257
|
-
before do
|
2258
|
-
person.addresses_attributes = {
|
2259
|
-
"0" => { street: '123' }
|
2260
|
-
}
|
2261
|
-
end
|
2262
|
-
|
2263
|
-
it "propagates invalidity to parent" do
|
2264
|
-
person.addresses.first.should_not be_valid
|
2265
|
-
person.should_not be_valid
|
2266
|
-
end
|
2267
|
-
end
|
2268
|
-
|
2269
|
-
context "when a type is passed" do
|
2270
|
-
|
2271
|
-
let(:canvas) do
|
2272
|
-
Canvas.new
|
2273
|
-
end
|
2274
|
-
|
2275
|
-
before do
|
2276
|
-
Canvas.send(:undef_method, :shapes_attributes=)
|
2277
|
-
Canvas.accepts_nested_attributes_for :shapes
|
2278
|
-
canvas.shapes_attributes =
|
2279
|
-
{
|
2280
|
-
"foo" => { "_type" => "Square" },
|
2281
|
-
"bar" => { "_type" => "Circle" }
|
2282
|
-
}
|
2283
|
-
end
|
2284
|
-
|
2285
|
-
it "instantiates an object of the given type" do
|
2286
|
-
canvas.shapes.map(&:class).should eq([Square, Circle])
|
2287
|
-
end
|
2288
|
-
end
|
2289
|
-
end
|
2290
|
-
|
2291
|
-
context "when the relation is a references one" do
|
2292
|
-
|
2293
|
-
let(:person) do
|
2294
|
-
Person.new
|
2295
|
-
end
|
2296
|
-
|
2297
|
-
context "when a reject proc is specified" do
|
2298
|
-
|
2299
|
-
before(:all) do
|
2300
|
-
Person.send(:undef_method, :game_attributes=)
|
2301
|
-
Person.accepts_nested_attributes_for \
|
2302
|
-
:game, reject_if: ->(attrs){ attrs[:name].blank? }
|
2303
|
-
end
|
2304
|
-
|
2305
|
-
after(:all) do
|
2306
|
-
Person.send(:undef_method, :game_attributes=)
|
2307
|
-
Person.accepts_nested_attributes_for :game
|
2308
|
-
end
|
2309
|
-
|
2310
|
-
context "when the attributes match" do
|
2311
|
-
|
2312
|
-
before do
|
2313
|
-
person.game_attributes = { score: 10 }
|
2314
|
-
end
|
2315
|
-
|
2316
|
-
it "does not add the document" do
|
2317
|
-
person.game.should be_nil
|
2318
|
-
end
|
2319
|
-
end
|
2320
|
-
|
2321
|
-
context "when the attributes do not match" do
|
2322
|
-
|
2323
|
-
before do
|
2324
|
-
person.game_attributes = { name: "Tron" }
|
2325
|
-
end
|
2326
|
-
|
2327
|
-
it "adds the document" do
|
2328
|
-
person.game.name.should eq("Tron")
|
2329
|
-
end
|
2330
|
-
end
|
2331
|
-
end
|
2332
|
-
|
2333
|
-
context "when reject_if => :all_blank is specified" do
|
2334
|
-
|
2335
|
-
before(:all) do
|
2336
|
-
Person.send(:undef_method, :game_attributes=)
|
2337
|
-
Person.accepts_nested_attributes_for \
|
2338
|
-
:game, reject_if: :all_blank
|
2339
|
-
end
|
2340
|
-
|
2341
|
-
after(:all) do
|
2342
|
-
Person.send(:undef_method, :game_attributes=)
|
2343
|
-
Person.accepts_nested_attributes_for :game
|
2344
|
-
end
|
2345
|
-
|
2346
|
-
context "when all attributes are empty" do
|
2347
|
-
|
2348
|
-
before do
|
2349
|
-
person.game_attributes = { score: nil }
|
2350
|
-
end
|
2351
|
-
|
2352
|
-
it "does not add the document" do
|
2353
|
-
person.game.should be_nil
|
2354
|
-
end
|
2355
|
-
end
|
2356
|
-
|
2357
|
-
context "when an attribute is non-empty" do
|
2358
|
-
|
2359
|
-
before do
|
2360
|
-
person.game_attributes = { name: "Tron" }
|
2361
|
-
end
|
2362
|
-
|
2363
|
-
it "adds the document" do
|
2364
|
-
person.game.name.should eq("Tron")
|
2365
|
-
end
|
2366
|
-
end
|
2367
|
-
end
|
2368
|
-
|
2369
|
-
context "when no id has been passed" do
|
2370
|
-
|
2371
|
-
context "with no destroy attribute" do
|
2372
|
-
|
2373
|
-
before do
|
2374
|
-
person.game_attributes = { name: "Tron" }
|
2375
|
-
end
|
2376
|
-
|
2377
|
-
it "builds a new document" do
|
2378
|
-
person.game.name.should eq("Tron")
|
2379
|
-
end
|
2380
|
-
end
|
2381
|
-
|
2382
|
-
context "with a destroy attribute" do
|
2383
|
-
|
2384
|
-
context "when allow_destroy is true" do
|
2385
|
-
|
2386
|
-
before(:all) do
|
2387
|
-
Person.send(:undef_method, :game_attributes=)
|
2388
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2389
|
-
end
|
2390
|
-
|
2391
|
-
after(:all) do
|
2392
|
-
Person.send(:undef_method, :game_attributes=)
|
2393
|
-
Person.accepts_nested_attributes_for :game
|
2394
|
-
end
|
2395
|
-
|
2396
|
-
before do
|
2397
|
-
person.game_attributes = { name: "Tron", _destroy: "1" }
|
2398
|
-
end
|
2399
|
-
|
2400
|
-
it "does not build the document" do
|
2401
|
-
person.game.should be_nil
|
2402
|
-
end
|
2403
|
-
end
|
2404
|
-
|
2405
|
-
context "when allow_destroy is false" do
|
2406
|
-
|
2407
|
-
before(:all) do
|
2408
|
-
Person.send(:undef_method, :game_attributes=)
|
2409
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2410
|
-
end
|
2411
|
-
|
2412
|
-
after(:all) do
|
2413
|
-
Person.send(:undef_method, :game_attributes=)
|
2414
|
-
Person.accepts_nested_attributes_for :game
|
2415
|
-
end
|
2416
|
-
|
2417
|
-
before do
|
2418
|
-
person.game_attributes = { name: "Tron", _destroy: "1" }
|
2419
|
-
end
|
2420
|
-
|
2421
|
-
it "builds the document" do
|
2422
|
-
person.game.name.should eq("Tron")
|
2423
|
-
end
|
2424
|
-
end
|
2425
|
-
end
|
2426
|
-
|
2427
|
-
context "with empty attributes" do
|
2428
|
-
|
2429
|
-
before do
|
2430
|
-
person.game_attributes = {}
|
2431
|
-
end
|
2432
|
-
|
2433
|
-
it "does not build the document" do
|
2434
|
-
person.game.should be_nil
|
2435
|
-
end
|
2436
|
-
end
|
2437
|
-
|
2438
|
-
context "when there is an existing document" do
|
2439
|
-
|
2440
|
-
context "with no destroy attribute" do
|
2441
|
-
|
2442
|
-
before do
|
2443
|
-
person.game = Game.new(name: "Tron")
|
2444
|
-
person.game_attributes = { name: "Pong" }
|
2445
|
-
end
|
2446
|
-
|
2447
|
-
it "replaces the document" do
|
2448
|
-
person.game.name.should eq("Pong")
|
2449
|
-
end
|
2450
|
-
end
|
2451
|
-
|
2452
|
-
context "when updating attributes" do
|
2453
|
-
|
2454
|
-
let!(:pizza) do
|
2455
|
-
Pizza.create(name: "large")
|
2456
|
-
end
|
2457
|
-
|
2458
|
-
before do
|
2459
|
-
pizza.topping = Topping.create(name: "cheese")
|
2460
|
-
pizza.update_attributes(topping_attributes: { name: "onions" })
|
2461
|
-
end
|
2462
|
-
|
2463
|
-
it "persists the attribute changes" do
|
2464
|
-
pizza.reload.topping.name.should eq("onions")
|
2465
|
-
end
|
2466
|
-
end
|
2467
|
-
|
2468
|
-
context "with a destroy attribute" do
|
2469
|
-
|
2470
|
-
context "when allow_destroy is true" do
|
2471
|
-
|
2472
|
-
before(:all) do
|
2473
|
-
Person.send(:undef_method, :game_attributes=)
|
2474
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2475
|
-
end
|
2476
|
-
|
2477
|
-
after(:all) do
|
2478
|
-
Person.send(:undef_method, :game_attributes=)
|
2479
|
-
Person.accepts_nested_attributes_for :game
|
2480
|
-
end
|
2481
|
-
|
2482
|
-
before do
|
2483
|
-
person.game = Game.new(name: "Tron")
|
2484
|
-
person.game_attributes = { name: "Pong", _destroy: "1" }
|
2485
|
-
end
|
2486
|
-
|
2487
|
-
it "does not replace the document" do
|
2488
|
-
person.game.name.should eq("Tron")
|
2489
|
-
end
|
2490
|
-
end
|
2491
|
-
|
2492
|
-
context "when allow_destroy is false" do
|
2493
|
-
|
2494
|
-
before(:all) do
|
2495
|
-
Person.send(:undef_method, :game_attributes=)
|
2496
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2497
|
-
end
|
2498
|
-
|
2499
|
-
after(:all) do
|
2500
|
-
Person.send(:undef_method, :game_attributes=)
|
2501
|
-
Person.accepts_nested_attributes_for :game
|
2502
|
-
end
|
2503
|
-
|
2504
|
-
before do
|
2505
|
-
person.game = Game.new(name: "Tron")
|
2506
|
-
person.game_attributes = { name: "Pong", _destroy: "1" }
|
2507
|
-
end
|
2508
|
-
|
2509
|
-
it "replaces the document" do
|
2510
|
-
person.game.name.should eq("Pong")
|
2511
|
-
end
|
2512
|
-
end
|
2513
|
-
end
|
2514
|
-
end
|
2515
|
-
end
|
2516
|
-
|
2517
|
-
context "when an id is passed" do
|
2518
|
-
|
2519
|
-
context "when there is an existing record" do
|
2520
|
-
|
2521
|
-
let(:game) do
|
2522
|
-
Game.new(name: "Tron")
|
2523
|
-
end
|
2524
|
-
|
2525
|
-
before do
|
2526
|
-
person.game = game
|
2527
|
-
end
|
2528
|
-
|
2529
|
-
context "when the id matches" do
|
2530
|
-
|
2531
|
-
context "when passed keys as symbols" do
|
2532
|
-
|
2533
|
-
before do
|
2534
|
-
person.game_attributes =
|
2535
|
-
{ id: game.id, name: "Pong" }
|
2536
|
-
end
|
2537
|
-
|
2538
|
-
it "updates the existing document" do
|
2539
|
-
person.game.name.should eq("Pong")
|
2540
|
-
end
|
2541
|
-
end
|
2542
|
-
|
2543
|
-
context "when passed keys as strings" do
|
2544
|
-
|
2545
|
-
before do
|
2546
|
-
person.game_attributes =
|
2547
|
-
{ "id" => game.id, "name" => "Pong" }
|
2548
|
-
end
|
2549
|
-
|
2550
|
-
it "updates the existing document" do
|
2551
|
-
person.game.name.should eq("Pong")
|
2552
|
-
end
|
2553
|
-
end
|
2554
|
-
|
2555
|
-
context "when allow_destroy is true" do
|
2556
|
-
|
2557
|
-
before(:all) do
|
2558
|
-
Person.send(:undef_method, :game_attributes=)
|
2559
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2560
|
-
end
|
2561
|
-
|
2562
|
-
after(:all) do
|
2563
|
-
Person.send(:undef_method, :game_attributes=)
|
2564
|
-
Person.accepts_nested_attributes_for :game
|
2565
|
-
end
|
2566
|
-
|
2567
|
-
[ 1, "1", true, "true" ].each do |truth|
|
2568
|
-
|
2569
|
-
context "when passed #{truth} with destroy" do
|
2570
|
-
|
2571
|
-
before do
|
2572
|
-
person.game_attributes =
|
2573
|
-
{ id: game.id, _destroy: truth }
|
2574
|
-
end
|
2575
|
-
|
2576
|
-
it "destroys the existing document" do
|
2577
|
-
person.game.should be_nil
|
2578
|
-
end
|
2579
|
-
end
|
2580
|
-
end
|
2581
|
-
|
2582
|
-
[ nil, 0, "0", false, "false" ].each do |falsehood|
|
2583
|
-
|
2584
|
-
context "when passed #{falsehood} with destroy" do
|
2585
|
-
|
2586
|
-
before do
|
2587
|
-
person.game_attributes =
|
2588
|
-
{ id: game.id, _destroy: falsehood }
|
2589
|
-
end
|
2590
|
-
|
2591
|
-
it "does not destroy the existing document" do
|
2592
|
-
person.game.should eq(game)
|
2593
|
-
end
|
2594
|
-
end
|
2595
|
-
end
|
2596
|
-
end
|
2597
|
-
|
2598
|
-
context "when allow destroy is false" do
|
2599
|
-
|
2600
|
-
before(:all) do
|
2601
|
-
Person.send(:undef_method, :game_attributes=)
|
2602
|
-
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2603
|
-
end
|
2604
|
-
|
2605
|
-
after(:all) do
|
2606
|
-
Person.send(:undef_method, :game_attributes=)
|
2607
|
-
Person.accepts_nested_attributes_for :game
|
2608
|
-
end
|
2609
|
-
|
2610
|
-
context "when a destroy attribute is passed" do
|
2611
|
-
|
2612
|
-
before do
|
2613
|
-
person.game_attributes =
|
2614
|
-
{ id: game.id, _destroy: true }
|
2615
|
-
end
|
2616
|
-
|
2617
|
-
it "does not destroy the document" do
|
2618
|
-
person.game.should eq(game)
|
2619
|
-
end
|
2620
|
-
end
|
2621
|
-
end
|
2622
|
-
|
2623
|
-
context "when update only is true" do
|
2624
|
-
|
2625
|
-
before(:all) do
|
2626
|
-
Person.send(:undef_method, :game_attributes=)
|
2627
|
-
Person.accepts_nested_attributes_for \
|
2628
|
-
:game,
|
2629
|
-
update_only: true,
|
2630
|
-
allow_destroy: true
|
2631
|
-
end
|
2632
|
-
|
2633
|
-
after(:all) do
|
2634
|
-
Person.send(:undef_method, :game_attributes=)
|
2635
|
-
Person.accepts_nested_attributes_for :game
|
2636
|
-
end
|
2637
|
-
|
2638
|
-
context "when the id matches" do
|
2639
|
-
|
2640
|
-
before do
|
2641
|
-
person.game_attributes =
|
2642
|
-
{ id: game.id, name: "Donkey Kong" }
|
2643
|
-
end
|
2644
|
-
|
2645
|
-
it "updates the existing document" do
|
2646
|
-
person.game.name.should eq("Donkey Kong")
|
2647
|
-
end
|
2648
|
-
end
|
2649
|
-
|
2650
|
-
context "when the id does not match" do
|
2651
|
-
|
2652
|
-
before do
|
2653
|
-
person.game_attributes =
|
2654
|
-
{ id: Moped::BSON::ObjectId.new.to_s, name: "Pong" }
|
2655
|
-
end
|
2656
|
-
|
2657
|
-
it "updates the existing document" do
|
2658
|
-
person.game.name.should eq("Pong")
|
2659
|
-
end
|
2660
|
-
end
|
2661
|
-
|
2662
|
-
context "when passed a destroy truth" do
|
2663
|
-
|
2664
|
-
before do
|
2665
|
-
person.game_attributes =
|
2666
|
-
{ id: game.id, _destroy: true }
|
2667
|
-
end
|
2668
|
-
|
2669
|
-
it "destroys the existing document" do
|
2670
|
-
person.game.should be_nil
|
2671
|
-
end
|
2672
|
-
end
|
2673
|
-
end
|
2674
|
-
end
|
2675
|
-
end
|
2676
|
-
end
|
2677
|
-
|
2678
|
-
context "when the nested document is invalid" do
|
2679
|
-
|
2680
|
-
before(:all) do
|
2681
|
-
Person.validates_associated(:game)
|
2682
|
-
end
|
2683
|
-
|
2684
|
-
after(:all) do
|
2685
|
-
Person.reset_callbacks(:validate)
|
2686
|
-
end
|
2687
|
-
|
2688
|
-
before do
|
2689
|
-
person.game_attributes = { name: '$$$' }
|
2690
|
-
end
|
2691
|
-
|
2692
|
-
it "propagates invalidity to parent" do
|
2693
|
-
person.game.should_not be_valid
|
2694
|
-
person.should_not be_valid
|
2695
|
-
end
|
2696
|
-
end
|
2697
|
-
|
2698
|
-
context "when a type is passed" do
|
2699
|
-
|
2700
|
-
let(:driver) do
|
2701
|
-
Driver.new
|
2702
|
-
end
|
2703
|
-
|
2704
|
-
before do
|
2705
|
-
Driver.send(:undef_method, :vehicle_attributes=)
|
2706
|
-
Driver.accepts_nested_attributes_for :vehicle
|
2707
|
-
driver.vehicle_attributes = { "_type" => "Truck" }
|
2708
|
-
end
|
2709
|
-
|
2710
|
-
it "instantiates an object of the given type" do
|
2711
|
-
driver.vehicle.class.should eq(Truck)
|
2712
|
-
end
|
2713
|
-
end
|
2714
|
-
end
|
2715
|
-
|
2716
|
-
context "when the relation is referenced in" do
|
2717
|
-
|
2718
|
-
context "when the child is new" do
|
2719
|
-
|
2720
|
-
let(:game) do
|
2721
|
-
Game.new
|
2722
|
-
end
|
2723
|
-
|
2724
|
-
context "when no id has been passed" do
|
2725
|
-
|
2726
|
-
context "when no destroy attribute passed" do
|
2727
|
-
|
2728
|
-
before do
|
2729
|
-
game.person_attributes = { title: "Sir" }
|
2730
|
-
end
|
2731
|
-
|
2732
|
-
it "builds a new document" do
|
2733
|
-
game.person.title.should eq("Sir")
|
2734
|
-
end
|
2735
|
-
|
2736
|
-
end
|
2737
|
-
|
2738
|
-
context "when a destroy attribute is passed" do
|
2739
|
-
|
2740
|
-
context "when allow_destroy is true" do
|
2741
|
-
|
2742
|
-
before(:all) do
|
2743
|
-
Game.send(:undef_method, :person_attributes=)
|
2744
|
-
Game.accepts_nested_attributes_for :person, allow_destroy: true
|
2745
|
-
end
|
2746
|
-
|
2747
|
-
after(:all) do
|
2748
|
-
Game.send(:undef_method, :person_attributes=)
|
2749
|
-
Game.accepts_nested_attributes_for :person
|
2750
|
-
end
|
2751
|
-
|
2752
|
-
before do
|
2753
|
-
game.person_attributes = { title: "Sir", _destroy: 1 }
|
2754
|
-
end
|
2755
|
-
|
2756
|
-
it "does not build a new document" do
|
2757
|
-
game.person.should be_nil
|
2758
|
-
end
|
2759
|
-
end
|
2760
|
-
|
2761
|
-
context "when allow_destroy is false" do
|
2762
|
-
|
2763
|
-
before(:all) do
|
2764
|
-
Game.send(:undef_method, :person_attributes=)
|
2765
|
-
Game.accepts_nested_attributes_for :person, allow_destroy: false
|
2766
|
-
end
|
2767
|
-
|
2768
|
-
after(:all) do
|
2769
|
-
Game.send(:undef_method, :person_attributes=)
|
2770
|
-
Game.accepts_nested_attributes_for :person
|
2771
|
-
end
|
2772
|
-
|
2773
|
-
before do
|
2774
|
-
game.person_attributes = { title: "Sir", _destroy: 1 }
|
2775
|
-
end
|
2776
|
-
|
2777
|
-
it "builds a new document" do
|
2778
|
-
game.person.title.should eq("Sir")
|
2779
|
-
end
|
2780
|
-
end
|
2781
|
-
end
|
2782
|
-
end
|
2783
|
-
|
2784
|
-
context "when an id has been passed" do
|
2785
|
-
|
2786
|
-
let(:person) do
|
2787
|
-
Person.new
|
2788
|
-
end
|
2789
|
-
|
2790
|
-
context "when no destroy attribute passed" do
|
2791
|
-
|
2792
|
-
context "when the id matches" do
|
2793
|
-
|
2794
|
-
before do
|
2795
|
-
game.person_attributes = { id: person.id, title: "Sir" }
|
2796
|
-
end
|
2797
|
-
|
2798
|
-
it "updates the existing document" do
|
2799
|
-
game.person.title.should eq("Sir")
|
2800
|
-
end
|
2801
|
-
end
|
2802
|
-
end
|
2803
|
-
|
2804
|
-
context "when there is an existing document" do
|
2805
|
-
|
2806
|
-
before do
|
2807
|
-
game.person = person
|
2808
|
-
end
|
2809
|
-
|
2810
|
-
context "when allow destroy is true" do
|
2811
|
-
|
2812
|
-
before(:all) do
|
2813
|
-
Game.send(:undef_method, :person_attributes=)
|
2814
|
-
Game.accepts_nested_attributes_for :person, allow_destroy: true
|
2815
|
-
end
|
2816
|
-
|
2817
|
-
after(:all) do
|
2818
|
-
Game.send(:undef_method, :person_attributes=)
|
2819
|
-
Game.accepts_nested_attributes_for :person
|
2820
|
-
end
|
2821
|
-
|
2822
|
-
[ 1, "1", true, "true" ].each do |truth|
|
2823
|
-
|
2824
|
-
context "when passed #{truth} with destroy" do
|
2825
|
-
|
2826
|
-
before do
|
2827
|
-
game.person_attributes =
|
2828
|
-
{ id: person.id, _destroy: truth }
|
2829
|
-
end
|
2830
|
-
|
2831
|
-
it "destroys the existing document" do
|
2832
|
-
game.person.should be_nil
|
2833
|
-
end
|
2834
|
-
end
|
2835
|
-
end
|
2836
|
-
|
2837
|
-
[ nil, 0, "0", false, "false" ].each do |falsehood|
|
2838
|
-
|
2839
|
-
context "when passed #{falsehood} with destroy" do
|
2840
|
-
|
2841
|
-
before do
|
2842
|
-
game.person_attributes =
|
2843
|
-
{ id: person.id, _destroy: falsehood }
|
2844
|
-
end
|
2845
|
-
|
2846
|
-
it "does not destroy the existing document" do
|
2847
|
-
game.person.should eq(person)
|
2848
|
-
end
|
2849
|
-
end
|
2850
|
-
end
|
2851
|
-
end
|
2852
|
-
|
2853
|
-
context "when allow destroy is false" do
|
2854
|
-
|
2855
|
-
before(:all) do
|
2856
|
-
Game.send(:undef_method, :person_attributes=)
|
2857
|
-
Game.accepts_nested_attributes_for :person, allow_destroy: false
|
2858
|
-
end
|
2859
|
-
|
2860
|
-
after(:all) do
|
2861
|
-
Game.send(:undef_method, :person_attributes=)
|
2862
|
-
Game.accepts_nested_attributes_for :person
|
2863
|
-
end
|
2864
|
-
|
2865
|
-
context "when a destroy attribute is passed" do
|
2866
|
-
|
2867
|
-
before do
|
2868
|
-
game.person_attributes =
|
2869
|
-
{ id: person.id, _destroy: true }
|
2870
|
-
end
|
2871
|
-
|
2872
|
-
it "does not delete the document" do
|
2873
|
-
game.person.should eq(person)
|
2874
|
-
end
|
2875
|
-
end
|
2876
|
-
end
|
2877
|
-
|
2878
|
-
context "when update only is true" do
|
2879
|
-
|
2880
|
-
before do
|
2881
|
-
Game.send(:undef_method, :person_attributes=)
|
2882
|
-
Game.accepts_nested_attributes_for \
|
2883
|
-
:person,
|
2884
|
-
update_only: true,
|
2885
|
-
allow_destroy: true
|
2886
|
-
end
|
2887
|
-
|
2888
|
-
context "when the id matches" do
|
2889
|
-
|
2890
|
-
before do
|
2891
|
-
game.person_attributes =
|
2892
|
-
{ id: person.id, title: "Madam" }
|
2893
|
-
end
|
2894
|
-
|
2895
|
-
it "updates the existing document" do
|
2896
|
-
game.person.title.should eq("Madam")
|
2897
|
-
end
|
2898
|
-
end
|
2899
|
-
|
2900
|
-
context "when the id does not match" do
|
2901
|
-
|
2902
|
-
before do
|
2903
|
-
game.person_attributes =
|
2904
|
-
{ id: Moped::BSON::ObjectId.new.to_s, title: "Madam" }
|
2905
|
-
end
|
2906
|
-
|
2907
|
-
it "updates the existing document" do
|
2908
|
-
game.person.title.should eq("Madam")
|
2909
|
-
end
|
2910
|
-
end
|
2911
|
-
|
2912
|
-
context "when passed a destroy truth" do
|
2913
|
-
|
2914
|
-
before do
|
2915
|
-
game.person_attributes =
|
2916
|
-
{ id: person.id, title: "Madam", _destroy: "true" }
|
2917
|
-
end
|
2918
|
-
|
2919
|
-
it "deletes the existing document" do
|
2920
|
-
game.person.should be_nil
|
2921
|
-
end
|
2922
|
-
end
|
2923
|
-
end
|
2924
|
-
end
|
2925
|
-
end
|
2926
|
-
|
2927
|
-
context "when the nested document is invalid" do
|
2928
|
-
|
2929
|
-
before(:all) do
|
2930
|
-
Person.validates_format_of :ssn, without: /\$\$\$/
|
2931
|
-
end
|
2932
|
-
|
2933
|
-
after(:all) do
|
2934
|
-
Person.reset_callbacks(:validate)
|
2935
|
-
end
|
2936
|
-
|
2937
|
-
before do
|
2938
|
-
game.person_attributes = { ssn: '$$$' }
|
2939
|
-
end
|
2940
|
-
|
2941
|
-
it "propagates invalidity to parent" do
|
2942
|
-
game.person.should_not be_valid
|
2943
|
-
game.should_not be_valid
|
2944
|
-
end
|
2945
|
-
end
|
2946
|
-
end
|
2947
|
-
|
2948
|
-
context "when a type is passed" do
|
2949
|
-
|
2950
|
-
let(:vehicle) do
|
2951
|
-
Vehicle.new
|
2952
|
-
end
|
2953
|
-
|
2954
|
-
before do
|
2955
|
-
Vehicle.send(:undef_method, :driver_attributes=)
|
2956
|
-
Vehicle.accepts_nested_attributes_for :driver
|
2957
|
-
vehicle.driver_attributes = { "_type" => "Learner" }
|
2958
|
-
end
|
2959
|
-
|
2960
|
-
it "instantiates an object of the given type" do
|
2961
|
-
vehicle.driver.class.should eq(Learner)
|
2962
|
-
end
|
2963
|
-
end
|
2964
|
-
end
|
2965
|
-
|
2966
|
-
context "when the relation is a references many" do
|
2967
|
-
|
2968
|
-
let(:person) do
|
2969
|
-
Person.new
|
2970
|
-
end
|
2971
|
-
|
2972
|
-
let(:post_one) do
|
2973
|
-
Post.new(title: "First post")
|
2974
|
-
end
|
2975
|
-
|
2976
|
-
let(:post_two) do
|
2977
|
-
Post.new(title: "First response")
|
2978
|
-
end
|
2979
|
-
|
2980
|
-
context "when a limit is specified" do
|
2981
|
-
|
2982
|
-
before(:all) do
|
2983
|
-
Person.send(:undef_method, :posts_attributes=)
|
2984
|
-
Person.accepts_nested_attributes_for :posts, limit: 2
|
2985
|
-
end
|
2986
|
-
|
2987
|
-
after(:all) do
|
2988
|
-
Person.send(:undef_method, :posts_attributes=)
|
2989
|
-
Person.accepts_nested_attributes_for :posts
|
2990
|
-
end
|
2991
|
-
|
2992
|
-
context "when more are provided than the limit" do
|
2993
|
-
|
2994
|
-
let(:attributes) do
|
2995
|
-
{
|
2996
|
-
"foo" => { "title" => "First" },
|
2997
|
-
"bar" => { "title" => "Second" },
|
2998
|
-
"baz" => { "title" => "Third" }
|
2999
|
-
}
|
3000
|
-
end
|
3001
|
-
|
3002
|
-
it "raises an error" do
|
3003
|
-
expect {
|
3004
|
-
person.posts_attributes = attributes
|
3005
|
-
}.to raise_error(Mongoid::Errors::TooManyNestedAttributeRecords)
|
3006
|
-
end
|
3007
|
-
end
|
3008
|
-
|
3009
|
-
context "when less are provided than the limit" do
|
3010
|
-
|
3011
|
-
let(:attributes) do
|
3012
|
-
{
|
3013
|
-
"foo" => { "title" => "First" },
|
3014
|
-
"bar" => { "title" => "Second" }
|
3015
|
-
}
|
3016
|
-
end
|
3017
|
-
|
3018
|
-
before do
|
3019
|
-
person.posts_attributes = attributes
|
3020
|
-
end
|
3021
|
-
|
3022
|
-
it "sets the documents on the relation" do
|
3023
|
-
person.posts.size.should eq(2)
|
3024
|
-
end
|
3025
|
-
|
3026
|
-
it "does not persist the new documents" do
|
3027
|
-
person.posts.count.should eq(0)
|
3028
|
-
end
|
3029
|
-
end
|
3030
|
-
end
|
3031
|
-
|
3032
|
-
context "when ids are passed" do
|
3033
|
-
|
3034
|
-
let(:person) do
|
3035
|
-
Person.create
|
3036
|
-
end
|
3037
|
-
|
3038
|
-
before do
|
3039
|
-
person.posts << [ post_one, post_two ]
|
3040
|
-
end
|
3041
|
-
|
3042
|
-
context "when no destroy attributes are passed" do
|
3043
|
-
|
3044
|
-
context "when the ids match" do
|
3045
|
-
|
3046
|
-
before do
|
3047
|
-
person.posts_attributes =
|
3048
|
-
{
|
3049
|
-
"0" => { "id" => post_one.id, "title" => "First" },
|
3050
|
-
"1" => { "id" => post_two.id, "title" => "Second" }
|
3051
|
-
}
|
3052
|
-
end
|
3053
|
-
|
3054
|
-
context "when reloading the document" do
|
3055
|
-
|
3056
|
-
it "updates the first existing document" do
|
3057
|
-
person.posts(true).first.title.should eq("First")
|
3058
|
-
end
|
3059
|
-
|
3060
|
-
it "updates the second existing document" do
|
3061
|
-
person.posts(true).last.title.should eq("Second")
|
3062
|
-
end
|
3063
|
-
|
3064
|
-
it "does not add new documents" do
|
3065
|
-
person.posts(true).size.should eq(2)
|
3066
|
-
end
|
3067
|
-
end
|
3068
|
-
|
3069
|
-
context "when there are no documents" do
|
3070
|
-
|
3071
|
-
before do
|
3072
|
-
person.posts.clear
|
3073
|
-
end
|
3074
|
-
|
3075
|
-
it "raises a document not found error" do
|
3076
|
-
expect {
|
3077
|
-
person.posts_attributes =
|
3078
|
-
{ "0" =>
|
3079
|
-
{ "id" => Moped::BSON::ObjectId.new.to_s, "title" => "Rogue" }
|
3080
|
-
}
|
3081
|
-
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
3082
|
-
end
|
3083
|
-
end
|
3084
|
-
end
|
3085
|
-
|
3086
|
-
context "when the parent is freshly loaded from the db" do
|
3087
|
-
|
3088
|
-
before do
|
3089
|
-
person.reload
|
3090
|
-
end
|
3091
|
-
|
3092
|
-
context "when updating valid documents with invalid values" do
|
3093
|
-
|
3094
|
-
before do
|
3095
|
-
person.posts_attributes =
|
3096
|
-
{
|
3097
|
-
"0" => { "id" => post_one.id, "title" => "testing again" },
|
3098
|
-
"1" => { "id" => post_two.id, "title" => "$$$" }
|
3099
|
-
}
|
3100
|
-
person.save
|
3101
|
-
end
|
3102
|
-
|
3103
|
-
it "does not perist the invalid value" do
|
3104
|
-
post_two.reload.title.should eq("First response")
|
3105
|
-
end
|
3106
|
-
end
|
3107
|
-
end
|
3108
|
-
|
3109
|
-
context "when the ids do not match" do
|
3110
|
-
|
3111
|
-
it "raises an error" do
|
3112
|
-
expect {
|
3113
|
-
person.posts_attributes =
|
3114
|
-
{ "foo" => { "id" => "test", "title" => "Test" } }
|
3115
|
-
}.to raise_error
|
3116
|
-
end
|
3117
|
-
end
|
3118
|
-
end
|
3119
|
-
|
3120
|
-
context "when destroy attributes are passed" do
|
3121
|
-
|
3122
|
-
context "when the ids match" do
|
3123
|
-
|
3124
|
-
context "when allow_destroy is true" do
|
3125
|
-
|
3126
|
-
before do
|
3127
|
-
Person.send(:undef_method, :posts_attributes=)
|
3128
|
-
Person.accepts_nested_attributes_for :posts, allow_destroy: true
|
3129
|
-
end
|
3130
|
-
|
3131
|
-
after do
|
3132
|
-
Person.send(:undef_method, :posts_attributes=)
|
3133
|
-
Person.accepts_nested_attributes_for :posts
|
3134
|
-
end
|
3135
|
-
|
3136
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3137
|
-
|
3138
|
-
context "when passed a #{truth} with destroy" do
|
3139
|
-
|
3140
|
-
before do
|
3141
|
-
person.posts_attributes =
|
3142
|
-
{
|
3143
|
-
"0" => { "id" => post_one.id, "_destroy" => truth },
|
3144
|
-
"1" => { "id" => post_two.id, "title" => "My Blog" }
|
3145
|
-
}
|
3146
|
-
end
|
3147
|
-
|
3148
|
-
context "when reloading the documents" do
|
3149
|
-
|
3150
|
-
it "deletes the marked document" do
|
3151
|
-
person.posts(true).size.should eq(1)
|
3152
|
-
end
|
3153
|
-
|
3154
|
-
it "does not delete the unmarked document" do
|
3155
|
-
person.posts(true).first.title.should eq("My Blog")
|
3156
|
-
end
|
3157
|
-
end
|
3158
|
-
end
|
3159
|
-
end
|
3160
|
-
|
3161
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3162
|
-
|
3163
|
-
context "when passed a #{falsehood} with destroy" do
|
3164
|
-
|
3165
|
-
before do
|
3166
|
-
person.posts_attributes =
|
3167
|
-
{
|
3168
|
-
"0" => { "id" => post_one.id, "_destroy" => falsehood },
|
3169
|
-
"1" => { "id" => post_two.id, "title" => "My Blog" }
|
3170
|
-
}
|
3171
|
-
end
|
3172
|
-
|
3173
|
-
context "when reloading the document" do
|
3174
|
-
|
3175
|
-
it "does not delete the marked document" do
|
3176
|
-
person.posts(true).size.should eq(2)
|
3177
|
-
end
|
3178
|
-
|
3179
|
-
it "does not delete the unmarked document" do
|
3180
|
-
person.posts(true).map(&:title).should include("My Blog")
|
3181
|
-
end
|
3182
|
-
end
|
3183
|
-
end
|
3184
|
-
end
|
3185
|
-
end
|
3186
|
-
|
3187
|
-
context "when allow_destroy is false" do
|
3188
|
-
|
3189
|
-
before do
|
3190
|
-
Person.send(:undef_method, :posts_attributes=)
|
3191
|
-
Person.accepts_nested_attributes_for :posts, allow_destroy: false
|
3192
|
-
end
|
3193
|
-
|
3194
|
-
after do
|
3195
|
-
Person.send(:undef_method, :posts_attributes=)
|
3196
|
-
Person.accepts_nested_attributes_for :posts
|
3197
|
-
end
|
3198
|
-
|
3199
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3200
|
-
|
3201
|
-
context "when passed a #{truth} with destroy" do
|
3202
|
-
|
3203
|
-
before do
|
3204
|
-
person.posts_attributes =
|
3205
|
-
{
|
3206
|
-
"0" => {
|
3207
|
-
"id" => post_one.id, "title" => "Another Title", "_destroy" => truth },
|
3208
|
-
"1" => { "id" => post_two.id, "title" => "New Title" }
|
3209
|
-
}
|
3210
|
-
end
|
3211
|
-
|
3212
|
-
context "when reloading the document" do
|
3213
|
-
|
3214
|
-
it "does not ignore the marked document" do
|
3215
|
-
person.posts(true).first.title.should eq("Another Title")
|
3216
|
-
end
|
3217
|
-
|
3218
|
-
it "does not delete the unmarked document" do
|
3219
|
-
person.posts(true).last.title.should eq("New Title")
|
3220
|
-
end
|
3221
|
-
|
3222
|
-
it "does not add additional documents" do
|
3223
|
-
person.posts(true).size.should eq(2)
|
3224
|
-
end
|
3225
|
-
end
|
3226
|
-
end
|
3227
|
-
end
|
3228
|
-
|
3229
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3230
|
-
|
3231
|
-
context "when passed a #{falsehood} with destroy" do
|
3232
|
-
|
3233
|
-
before do
|
3234
|
-
person.posts_attributes =
|
3235
|
-
{
|
3236
|
-
"0" => { "id" => post_one.id, "_destroy" => falsehood },
|
3237
|
-
"1" => { "id" => post_two.id, "title" => "New Title" }
|
3238
|
-
}
|
3239
|
-
end
|
3240
|
-
|
3241
|
-
context "when reloading the documents" do
|
3242
|
-
|
3243
|
-
it "does not delete the marked document" do
|
3244
|
-
person.posts(true).size.should eq(2)
|
3245
|
-
end
|
3246
|
-
|
3247
|
-
it "does not delete the unmarked document" do
|
3248
|
-
person.posts(true).last.title.should eq("New Title")
|
3249
|
-
end
|
3250
|
-
end
|
3251
|
-
end
|
3252
|
-
end
|
3253
|
-
end
|
3254
|
-
|
3255
|
-
context "when allow_destroy is undefined" do
|
3256
|
-
|
3257
|
-
before(:all) do
|
3258
|
-
Person.send(:undef_method, :posts_attributes=)
|
3259
|
-
Person.accepts_nested_attributes_for :posts
|
3260
|
-
end
|
3261
|
-
|
3262
|
-
after(:all) do
|
3263
|
-
Person.send(:undef_method, :posts_attributes=)
|
3264
|
-
Person.accepts_nested_attributes_for :posts
|
3265
|
-
end
|
3266
|
-
|
3267
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3268
|
-
|
3269
|
-
context "when passed a #{truth} with destroy" do
|
3270
|
-
|
3271
|
-
before do
|
3272
|
-
person.posts_attributes =
|
3273
|
-
{
|
3274
|
-
"0" => {
|
3275
|
-
"id" => post_one.id,
|
3276
|
-
"title" => "Another Title",
|
3277
|
-
"_destroy" => truth
|
3278
|
-
},
|
3279
|
-
"1" => { "id" => post_two.id, "title" => "New Title" }
|
3280
|
-
}
|
3281
|
-
end
|
3282
|
-
|
3283
|
-
context "when reloading" do
|
3284
|
-
|
3285
|
-
it "does not ignore the marked document" do
|
3286
|
-
person.posts(true).find(post_one.id).title.should eq("Another Title")
|
3287
|
-
end
|
3288
|
-
|
3289
|
-
it "does not delete the unmarked document" do
|
3290
|
-
person.posts(true).find(post_two.id).title.should eq("New Title")
|
3291
|
-
end
|
3292
|
-
|
3293
|
-
it "does not add additional documents" do
|
3294
|
-
person.posts(true).size.should eq(2)
|
3295
|
-
end
|
3296
|
-
end
|
3297
|
-
end
|
3298
|
-
end
|
3299
|
-
|
3300
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3301
|
-
|
3302
|
-
context "when passed a #{falsehood} with destroy" do
|
3303
|
-
|
3304
|
-
before do
|
3305
|
-
person.posts_attributes =
|
3306
|
-
{
|
3307
|
-
"0" => { "id" => post_one.id, "_destroy" => falsehood },
|
3308
|
-
"1" => { "id" => post_two.id, "title" => "New Title" }
|
3309
|
-
}
|
3310
|
-
end
|
3311
|
-
|
3312
|
-
context "when reloading" do
|
3313
|
-
|
3314
|
-
it "does not delete the marked document" do
|
3315
|
-
person.posts(true).size.should eq(2)
|
3316
|
-
end
|
3317
|
-
|
3318
|
-
it "does not delete the unmarked document" do
|
3319
|
-
person.posts(true).last.title.should eq("New Title")
|
3320
|
-
end
|
3321
|
-
end
|
3322
|
-
end
|
3323
|
-
end
|
3324
|
-
end
|
3325
|
-
end
|
3326
|
-
end
|
3327
|
-
end
|
3328
|
-
|
3329
|
-
context "when no ids are passed" do
|
3330
|
-
|
3331
|
-
context "when no destroy attributes are passed" do
|
3332
|
-
|
3333
|
-
context "when passing a hash of attributes" do
|
3334
|
-
|
3335
|
-
before do
|
3336
|
-
person.posts_attributes =
|
3337
|
-
{
|
3338
|
-
"4" => { "title" => "Third" },
|
3339
|
-
"1" => { "title" => "First" },
|
3340
|
-
"2" => { "title" => "Second" }
|
3341
|
-
}
|
3342
|
-
end
|
3343
|
-
|
3344
|
-
it "builds a new first document" do
|
3345
|
-
person.posts.first.title.should eq("First")
|
3346
|
-
end
|
3347
|
-
|
3348
|
-
it "builds a new second document" do
|
3349
|
-
person.posts.second.title.should eq("Second")
|
3350
|
-
end
|
3351
|
-
|
3352
|
-
it "builds a new third document" do
|
3353
|
-
person.posts.third.title.should eq("Third")
|
3354
|
-
end
|
3355
|
-
|
3356
|
-
it "does not add extra documents" do
|
3357
|
-
person.posts.size.should eq(3)
|
3358
|
-
end
|
3359
|
-
|
3360
|
-
it "does not persist the documents" do
|
3361
|
-
person.posts.count.should eq(0)
|
3362
|
-
end
|
3363
|
-
|
3364
|
-
it "adds the documents in the sorted hash key order" do
|
3365
|
-
person.posts.map(&:title).should eq(
|
3366
|
-
[ "First", "Second", "Third" ]
|
3367
|
-
)
|
3368
|
-
end
|
3369
|
-
end
|
3370
|
-
|
3371
|
-
context "when passing an array of attributes" do
|
3372
|
-
|
3373
|
-
context "when the parent is saved" do
|
3374
|
-
|
3375
|
-
before do
|
3376
|
-
person.save
|
3377
|
-
person.posts_attributes =
|
3378
|
-
[
|
3379
|
-
{ "title" => "Third" },
|
3380
|
-
{ "title" => "First" },
|
3381
|
-
{ "title" => "Second" }
|
3382
|
-
]
|
3383
|
-
end
|
3384
|
-
|
3385
|
-
it "builds a new first document" do
|
3386
|
-
person.posts.first.title.should eq("Third")
|
3387
|
-
end
|
3388
|
-
|
3389
|
-
it "builds a new second document" do
|
3390
|
-
person.posts.second.title.should eq("First")
|
3391
|
-
end
|
3392
|
-
|
3393
|
-
it "builds a new third document" do
|
3394
|
-
person.posts.third.title.should eq("Second")
|
3395
|
-
end
|
3396
|
-
|
3397
|
-
it "does not add extra documents" do
|
3398
|
-
person.posts.size.should eq(3)
|
3399
|
-
end
|
3400
|
-
|
3401
|
-
it "does not persist the documents" do
|
3402
|
-
person.posts.count.should eq(0)
|
3403
|
-
end
|
3404
|
-
end
|
3405
|
-
end
|
3406
|
-
end
|
3407
|
-
|
3408
|
-
context "when a reject block is supplied" do
|
3409
|
-
|
3410
|
-
before(:all) do
|
3411
|
-
Person.send(:undef_method, :posts_attributes=)
|
3412
|
-
Person.accepts_nested_attributes_for \
|
3413
|
-
:posts, reject_if: ->(attrs){ attrs["title"].blank? }
|
3414
|
-
end
|
3415
|
-
|
3416
|
-
after(:all) do
|
3417
|
-
Person.send(:undef_method, :posts_attributes=)
|
3418
|
-
Person.accepts_nested_attributes_for :posts
|
3419
|
-
end
|
3420
|
-
|
3421
|
-
context "when the attributes match" do
|
3422
|
-
|
3423
|
-
before do
|
3424
|
-
person.posts_attributes =
|
3425
|
-
{ "3" => { "content" => "My first blog" } }
|
3426
|
-
end
|
3427
|
-
|
3428
|
-
it "does not add the new document" do
|
3429
|
-
person.posts.should be_empty
|
3430
|
-
end
|
3431
|
-
end
|
3432
|
-
|
3433
|
-
context "when the attributes do not match" do
|
3434
|
-
|
3435
|
-
before do
|
3436
|
-
person.posts_attributes =
|
3437
|
-
{ "3" => { "title" => "Blogging" } }
|
3438
|
-
end
|
3439
|
-
|
3440
|
-
it "adds the new document" do
|
3441
|
-
person.posts.size.should eq(1)
|
3442
|
-
end
|
3443
|
-
|
3444
|
-
it "sets the correct attributes" do
|
3445
|
-
person.posts.first.title.should eq("Blogging")
|
3446
|
-
end
|
3447
|
-
end
|
3448
|
-
end
|
3449
|
-
|
3450
|
-
context "when :reject_if => :all_blank is supplied" do
|
3451
|
-
|
3452
|
-
before(:all) do
|
3453
|
-
Person.send(:undef_method, :posts_attributes=)
|
3454
|
-
Person.accepts_nested_attributes_for \
|
3455
|
-
:posts, reject_if: :all_blank
|
3456
|
-
end
|
3457
|
-
|
3458
|
-
after(:all) do
|
3459
|
-
Person.send(:undef_method, :posts_attributes=)
|
3460
|
-
Person.accepts_nested_attributes_for :posts
|
3461
|
-
end
|
3462
|
-
|
3463
|
-
context "when all attributes are blank" do
|
3464
|
-
|
3465
|
-
before do
|
3466
|
-
person.posts_attributes =
|
3467
|
-
{ "3" => { "content" => "" } }
|
3468
|
-
end
|
3469
|
-
|
3470
|
-
it "does not add the new document" do
|
3471
|
-
person.posts.should be_empty
|
3472
|
-
end
|
3473
|
-
end
|
3474
|
-
|
3475
|
-
context "when an attribute is non-empty" do
|
3476
|
-
|
3477
|
-
before do
|
3478
|
-
person.posts_attributes =
|
3479
|
-
{ "3" => { "title" => "Blogging" } }
|
3480
|
-
end
|
3481
|
-
|
3482
|
-
it "adds the new document" do
|
3483
|
-
person.posts.size.should eq(1)
|
3484
|
-
end
|
3485
|
-
|
3486
|
-
it "sets the correct attributes" do
|
3487
|
-
person.posts.first.title.should eq("Blogging")
|
3488
|
-
end
|
3489
|
-
end
|
3490
|
-
end
|
3491
|
-
|
3492
|
-
context "when destroy attributes are passed" do
|
3493
|
-
|
3494
|
-
context "when allow_destroy is true" do
|
3495
|
-
|
3496
|
-
before(:all) do
|
3497
|
-
Person.send(:undef_method, :posts_attributes=)
|
3498
|
-
Person.accepts_nested_attributes_for :posts, allow_destroy: true
|
3499
|
-
end
|
3500
|
-
|
3501
|
-
after(:all) do
|
3502
|
-
Person.send(:undef_method, :posts_attributes=)
|
3503
|
-
Person.accepts_nested_attributes_for :posts
|
3504
|
-
end
|
3505
|
-
|
3506
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3507
|
-
|
3508
|
-
context "when passed a #{truth} with destroy" do
|
3509
|
-
|
3510
|
-
before do
|
3511
|
-
person.posts_attributes =
|
3512
|
-
{
|
3513
|
-
"0" => { "title" => "New Blog", "_destroy" => truth },
|
3514
|
-
"1" => { "title" => "Blog Two" }
|
3515
|
-
}
|
3516
|
-
end
|
3517
|
-
|
3518
|
-
it "ignores the the marked document" do
|
3519
|
-
person.posts.size.should eq(1)
|
3520
|
-
end
|
3521
|
-
|
3522
|
-
it "adds the new unmarked document" do
|
3523
|
-
person.posts.first.title.should eq("Blog Two")
|
3524
|
-
end
|
3525
|
-
end
|
3526
|
-
end
|
3527
|
-
|
3528
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3529
|
-
|
3530
|
-
context "when passed a #{falsehood} with destroy" do
|
3531
|
-
|
3532
|
-
before do
|
3533
|
-
person.posts_attributes =
|
3534
|
-
{
|
3535
|
-
"0" => { "title" => "New Blog", "_destroy" => falsehood },
|
3536
|
-
"1" => { "title" => "Blog Two" }
|
3537
|
-
}
|
3538
|
-
end
|
3539
|
-
|
3540
|
-
it "adds the new marked document" do
|
3541
|
-
person.posts.first.title.should eq("New Blog")
|
3542
|
-
end
|
3543
|
-
|
3544
|
-
it "adds the new unmarked document" do
|
3545
|
-
person.posts.last.title.should eq("Blog Two")
|
3546
|
-
end
|
3547
|
-
|
3548
|
-
it "does not add extra documents" do
|
3549
|
-
person.posts.size.should eq(2)
|
3550
|
-
end
|
3551
|
-
end
|
3552
|
-
end
|
3553
|
-
end
|
3554
|
-
|
3555
|
-
context "when allow destroy is false" do
|
3556
|
-
|
3557
|
-
before(:all) do
|
3558
|
-
Person.send(:undef_method, :posts_attributes=)
|
3559
|
-
Person.accepts_nested_attributes_for :posts, allow_destroy: false
|
3560
|
-
end
|
3561
|
-
|
3562
|
-
after(:all) do
|
3563
|
-
Person.send(:undef_method, :posts_attributes=)
|
3564
|
-
Person.accepts_nested_attributes_for :posts
|
3565
|
-
end
|
3566
|
-
|
3567
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3568
|
-
|
3569
|
-
context "when passed a #{truth} with destroy" do
|
3570
|
-
|
3571
|
-
before do
|
3572
|
-
person.posts_attributes =
|
3573
|
-
{
|
3574
|
-
"0" => { "title" => "New Blog", "_destroy" => truth },
|
3575
|
-
"1" => { "title" => "Blog Two" }
|
3576
|
-
}
|
3577
|
-
end
|
3578
|
-
|
3579
|
-
it "adds the the marked document" do
|
3580
|
-
person.posts.first.title.should eq("New Blog")
|
3581
|
-
end
|
3582
|
-
|
3583
|
-
it "adds the new unmarked document" do
|
3584
|
-
person.posts.last.title.should eq("Blog Two")
|
3585
|
-
end
|
3586
|
-
|
3587
|
-
it "adds the correct number of documents" do
|
3588
|
-
person.posts.size.should eq(2)
|
3589
|
-
end
|
3590
|
-
end
|
3591
|
-
end
|
3592
|
-
|
3593
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3594
|
-
|
3595
|
-
context "when passed a #{falsehood} with destroy" do
|
3596
|
-
|
3597
|
-
before do
|
3598
|
-
person.posts_attributes =
|
3599
|
-
{
|
3600
|
-
"0" => { "title" => "New Blog", "_destroy" => falsehood },
|
3601
|
-
"1" => { "title" => "Blog Two" }
|
3602
|
-
}
|
3603
|
-
end
|
3604
|
-
|
3605
|
-
it "adds the new marked document" do
|
3606
|
-
person.posts.first.title.should eq("New Blog")
|
3607
|
-
end
|
3608
|
-
|
3609
|
-
it "adds the new unmarked document" do
|
3610
|
-
person.posts.last.title.should eq("Blog Two")
|
3611
|
-
end
|
3612
|
-
|
3613
|
-
it "does not add extra documents" do
|
3614
|
-
person.posts.size.should eq(2)
|
3615
|
-
end
|
3616
|
-
end
|
3617
|
-
end
|
3618
|
-
end
|
3619
|
-
|
3620
|
-
context "when allow destroy is not defined" do
|
3621
|
-
|
3622
|
-
before(:all) do
|
3623
|
-
Person.send(:undef_method, :posts_attributes=)
|
3624
|
-
Person.accepts_nested_attributes_for :posts
|
3625
|
-
end
|
3626
|
-
|
3627
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3628
|
-
|
3629
|
-
context "when passed a #{truth} with destroy" do
|
3630
|
-
|
3631
|
-
before do
|
3632
|
-
person.posts_attributes =
|
3633
|
-
{
|
3634
|
-
"0" => { "title" => "New Blog", "_destroy" => truth },
|
3635
|
-
"1" => { "title" => "Blog Two" }
|
3636
|
-
}
|
3637
|
-
end
|
3638
|
-
|
3639
|
-
it "adds the the marked document" do
|
3640
|
-
person.posts.first.title.should eq("New Blog")
|
3641
|
-
end
|
3642
|
-
|
3643
|
-
it "adds the new unmarked document" do
|
3644
|
-
person.posts.last.title.should eq("Blog Two")
|
3645
|
-
end
|
3646
|
-
|
3647
|
-
it "adds the correct number of documents" do
|
3648
|
-
person.posts.size.should eq(2)
|
3649
|
-
end
|
3650
|
-
end
|
3651
|
-
end
|
3652
|
-
|
3653
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3654
|
-
|
3655
|
-
context "when passed a #{falsehood} with destroy" do
|
3656
|
-
|
3657
|
-
before do
|
3658
|
-
person.posts_attributes =
|
3659
|
-
{
|
3660
|
-
"0" => { "title" => "New Blog", "_destroy" => falsehood },
|
3661
|
-
"1" => { "title" => "Blog Two" }
|
3662
|
-
}
|
3663
|
-
end
|
3664
|
-
|
3665
|
-
it "adds the new marked document" do
|
3666
|
-
person.posts.first.title.should eq("New Blog")
|
3667
|
-
end
|
3668
|
-
|
3669
|
-
it "adds the new unmarked document" do
|
3670
|
-
person.posts.last.title.should eq("Blog Two")
|
3671
|
-
end
|
3672
|
-
|
3673
|
-
it "does not add extra documents" do
|
3674
|
-
person.posts.size.should eq(2)
|
3675
|
-
end
|
3676
|
-
end
|
3677
|
-
end
|
3678
|
-
end
|
3679
|
-
end
|
3680
|
-
end
|
3681
|
-
|
3682
|
-
context "when the nested document is invalid" do
|
3683
|
-
|
3684
|
-
before(:all) do
|
3685
|
-
Person.validates_associated(:posts)
|
3686
|
-
end
|
3687
|
-
|
3688
|
-
after(:all) do
|
3689
|
-
Person.reset_callbacks(:validate)
|
3690
|
-
end
|
3691
|
-
|
3692
|
-
before do
|
3693
|
-
person.posts_attributes = {
|
3694
|
-
"0" => { title: "$$$" }
|
3695
|
-
}
|
3696
|
-
end
|
3697
|
-
|
3698
|
-
it "propagates invalidity to parent" do
|
3699
|
-
person.should_not be_valid
|
3700
|
-
person.posts.first.should_not be_valid
|
3701
|
-
end
|
3702
|
-
end
|
3703
|
-
|
3704
|
-
context "when a type is passed" do
|
3705
|
-
|
3706
|
-
let(:shipping_container) do
|
3707
|
-
ShippingContainer.new
|
3708
|
-
end
|
3709
|
-
|
3710
|
-
before do
|
3711
|
-
ShippingContainer.send(:undef_method, :vehicles_attributes=)
|
3712
|
-
ShippingContainer.accepts_nested_attributes_for :vehicles
|
3713
|
-
shipping_container.vehicles_attributes =
|
3714
|
-
{
|
3715
|
-
"foo" => { "_type" => "Car" },
|
3716
|
-
"bar" => { "_type" => "Truck" }
|
3717
|
-
}
|
3718
|
-
end
|
3719
|
-
|
3720
|
-
it "instantiates an object of the given type" do
|
3721
|
-
shipping_container.vehicles.map(&:class).should eq([Car, Truck])
|
3722
|
-
end
|
3723
|
-
end
|
3724
|
-
end
|
3725
|
-
|
3726
|
-
context "when the relation is a references many to many" do
|
3727
|
-
|
3728
|
-
let(:person) do
|
3729
|
-
Person.new
|
3730
|
-
end
|
3731
|
-
|
3732
|
-
let(:preference_one) do
|
3733
|
-
Preference.new(name: "First preference")
|
3734
|
-
end
|
3735
|
-
|
3736
|
-
let(:preference_two) do
|
3737
|
-
Preference.new(name: "First response")
|
3738
|
-
end
|
3739
|
-
|
3740
|
-
context "when a limit is specified" do
|
3741
|
-
|
3742
|
-
before(:all) do
|
3743
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3744
|
-
Person.accepts_nested_attributes_for :preferences, limit: 2
|
3745
|
-
end
|
3746
|
-
|
3747
|
-
after(:all) do
|
3748
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3749
|
-
Person.accepts_nested_attributes_for :preferences
|
3750
|
-
end
|
3751
|
-
|
3752
|
-
context "when more are provided than the limit" do
|
3753
|
-
|
3754
|
-
let(:attributes) do
|
3755
|
-
{
|
3756
|
-
"foo" => { "name" => "First" },
|
3757
|
-
"bar" => { "name" => "Second" },
|
3758
|
-
"baz" => { "name" => "Third" }
|
3759
|
-
}
|
3760
|
-
end
|
3761
|
-
|
3762
|
-
it "raises an error" do
|
3763
|
-
expect {
|
3764
|
-
person.preferences_attributes = attributes
|
3765
|
-
}.to raise_error(Mongoid::Errors::TooManyNestedAttributeRecords)
|
3766
|
-
end
|
3767
|
-
end
|
3768
|
-
|
3769
|
-
context "when less are provided than the limit" do
|
3770
|
-
|
3771
|
-
let(:attributes) do
|
3772
|
-
{
|
3773
|
-
"foo" => { "name" => "First" },
|
3774
|
-
"bar" => { "name" => "Second" }
|
3775
|
-
}
|
3776
|
-
end
|
3777
|
-
|
3778
|
-
before do
|
3779
|
-
person.preferences_attributes = attributes
|
3780
|
-
end
|
3781
|
-
|
3782
|
-
it "sets the documents on the relation" do
|
3783
|
-
person.preferences.size.should eq(2)
|
3784
|
-
end
|
3785
|
-
end
|
3786
|
-
end
|
3787
|
-
|
3788
|
-
context "when ids are passed" do
|
3789
|
-
|
3790
|
-
let(:person) do
|
3791
|
-
Person.create
|
3792
|
-
end
|
3793
|
-
|
3794
|
-
before do
|
3795
|
-
person.preferences << [ preference_one, preference_two ]
|
3796
|
-
end
|
3797
|
-
|
3798
|
-
context "when no destroy attributes are passed" do
|
3799
|
-
|
3800
|
-
context "when the ids match" do
|
3801
|
-
|
3802
|
-
before do
|
3803
|
-
person.preferences_attributes =
|
3804
|
-
{
|
3805
|
-
"0" => { "id" => preference_one.id, "name" => "First" },
|
3806
|
-
"1" => { "id" => preference_two.id, "name" => "Second" }
|
3807
|
-
}
|
3808
|
-
end
|
3809
|
-
|
3810
|
-
context "when reloading the document" do
|
3811
|
-
|
3812
|
-
it "updates the first existing document" do
|
3813
|
-
person.preferences(true).first.name.should eq("First")
|
3814
|
-
end
|
3815
|
-
|
3816
|
-
it "updates the second existing document" do
|
3817
|
-
person.preferences(true).second.name.should eq("Second")
|
3818
|
-
end
|
3819
|
-
|
3820
|
-
it "does not add new documents" do
|
3821
|
-
person.preferences(true).size.should eq(2)
|
3822
|
-
end
|
3823
|
-
end
|
3824
|
-
end
|
3825
|
-
|
3826
|
-
context "when the ids do not match" do
|
3827
|
-
|
3828
|
-
it "raises an error" do
|
3829
|
-
expect {
|
3830
|
-
person.preferences_attributes =
|
3831
|
-
{ "foo" => { "id" => "test", "name" => "Test" } }
|
3832
|
-
}.to raise_error
|
3833
|
-
end
|
3834
|
-
end
|
3835
|
-
end
|
3836
|
-
|
3837
|
-
context "when destroy attributes are passed" do
|
3838
|
-
|
3839
|
-
context "when the ids match" do
|
3840
|
-
|
3841
|
-
context "when allow_destroy is true" do
|
3842
|
-
|
3843
|
-
before(:all) do
|
3844
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3845
|
-
Person.accepts_nested_attributes_for :preferences, allow_destroy: true
|
3846
|
-
end
|
3847
|
-
|
3848
|
-
after(:all) do
|
3849
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3850
|
-
Person.accepts_nested_attributes_for :preferences
|
3851
|
-
end
|
3852
|
-
|
3853
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3854
|
-
|
3855
|
-
context "when passed a #{truth} with destroy" do
|
3856
|
-
|
3857
|
-
before do
|
3858
|
-
person.preferences_attributes =
|
3859
|
-
{
|
3860
|
-
"0" => { "id" => preference_one.id, "_destroy" => truth },
|
3861
|
-
"1" => { "id" => preference_two.id, "name" => "My Blog" }
|
3862
|
-
}
|
3863
|
-
end
|
3864
|
-
|
3865
|
-
context "when reloading the documents" do
|
3866
|
-
|
3867
|
-
it "deletes the marked document" do
|
3868
|
-
person.preferences(true).size.should eq(1)
|
3869
|
-
end
|
3870
|
-
|
3871
|
-
it "does not delete the unmarked document" do
|
3872
|
-
person.preferences(true).first.name.should eq("My Blog")
|
3873
|
-
end
|
3874
|
-
end
|
3875
|
-
end
|
3876
|
-
end
|
3877
|
-
|
3878
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3879
|
-
|
3880
|
-
context "when passed a #{falsehood} with destroy" do
|
3881
|
-
|
3882
|
-
before do
|
3883
|
-
person.preferences_attributes =
|
3884
|
-
{
|
3885
|
-
"0" => { "id" => preference_one.id, "_destroy" => falsehood },
|
3886
|
-
"1" => { "id" => preference_two.id, "name" => "My Blog" }
|
3887
|
-
}
|
3888
|
-
end
|
3889
|
-
|
3890
|
-
context "when reloading the document" do
|
3891
|
-
|
3892
|
-
it "does not delete the marked document" do
|
3893
|
-
person.preferences(true).size.should eq(2)
|
3894
|
-
end
|
3895
|
-
|
3896
|
-
it "does not delete the unmarked document" do
|
3897
|
-
person.preferences(true).last.name.should eq("My Blog")
|
3898
|
-
end
|
3899
|
-
end
|
3900
|
-
end
|
3901
|
-
end
|
3902
|
-
end
|
3903
|
-
|
3904
|
-
context "when allow_destroy is false" do
|
3905
|
-
|
3906
|
-
before(:all) do
|
3907
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3908
|
-
Person.accepts_nested_attributes_for :preferences, allow_destroy: false
|
3909
|
-
end
|
3910
|
-
|
3911
|
-
after(:all) do
|
3912
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3913
|
-
Person.accepts_nested_attributes_for :preferences
|
3914
|
-
end
|
3915
|
-
|
3916
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3917
|
-
|
3918
|
-
context "when passed a #{truth} with destroy" do
|
3919
|
-
|
3920
|
-
before do
|
3921
|
-
person.preferences_attributes =
|
3922
|
-
{
|
3923
|
-
"0" => {
|
3924
|
-
"id" => preference_one.id, "name" => "Another Title", "_destroy" => truth },
|
3925
|
-
"1" => { "id" => preference_two.id, "name" => "New Title" }
|
3926
|
-
}
|
3927
|
-
end
|
3928
|
-
|
3929
|
-
context "when reloading the document" do
|
3930
|
-
|
3931
|
-
it "does not ignore the marked document" do
|
3932
|
-
person.preferences(true).first.name.should eq("Another Title")
|
3933
|
-
end
|
3934
|
-
|
3935
|
-
it "does not delete the unmarked document" do
|
3936
|
-
person.preferences(true).last.name.should eq("New Title")
|
3937
|
-
end
|
3938
|
-
|
3939
|
-
it "does not add additional documents" do
|
3940
|
-
person.preferences(true).size.should eq(2)
|
3941
|
-
end
|
3942
|
-
end
|
3943
|
-
end
|
3944
|
-
end
|
3945
|
-
|
3946
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
3947
|
-
|
3948
|
-
context "when passed a #{falsehood} with destroy" do
|
3949
|
-
|
3950
|
-
before do
|
3951
|
-
person.preferences_attributes =
|
3952
|
-
{
|
3953
|
-
"0" => { "id" => preference_one.id, "_destroy" => falsehood },
|
3954
|
-
"1" => { "id" => preference_two.id, "name" => "New Title" }
|
3955
|
-
}
|
3956
|
-
end
|
3957
|
-
|
3958
|
-
context "when reloading the documents" do
|
3959
|
-
|
3960
|
-
it "does not delete the marked document" do
|
3961
|
-
person.preferences(true).size.should eq(2)
|
3962
|
-
end
|
3963
|
-
|
3964
|
-
it "does not delete the unmarked document" do
|
3965
|
-
person.preferences(true).last.name.should eq("New Title")
|
3966
|
-
end
|
3967
|
-
end
|
3968
|
-
end
|
3969
|
-
end
|
3970
|
-
end
|
3971
|
-
|
3972
|
-
context "when allow_destroy is undefined" do
|
3973
|
-
|
3974
|
-
before(:all) do
|
3975
|
-
Person.send(:undef_method, :preferences_attributes=)
|
3976
|
-
Person.accepts_nested_attributes_for :preferences
|
3977
|
-
end
|
3978
|
-
|
3979
|
-
[ 1, "1", true, "true" ].each do |truth|
|
3980
|
-
|
3981
|
-
context "when passed a #{truth} with destroy" do
|
3982
|
-
|
3983
|
-
before do
|
3984
|
-
person.preferences_attributes =
|
3985
|
-
{
|
3986
|
-
"0" => {
|
3987
|
-
"id" => preference_one.id, "name" => "Another Title", "_destroy" => truth },
|
3988
|
-
"1" => { "id" => preference_two.id, "name" => "New Title" }
|
3989
|
-
}
|
3990
|
-
end
|
3991
|
-
|
3992
|
-
context "when reloading" do
|
3993
|
-
|
3994
|
-
it "does not ignore the marked document" do
|
3995
|
-
person.preferences(true).first.name.should eq("Another Title")
|
3996
|
-
end
|
3997
|
-
|
3998
|
-
it "does not delete the unmarked document" do
|
3999
|
-
person.preferences(true).last.name.should eq("New Title")
|
4000
|
-
end
|
4001
|
-
|
4002
|
-
it "does not add additional documents" do
|
4003
|
-
person.preferences(true).size.should eq(2)
|
4004
|
-
end
|
4005
|
-
end
|
4006
|
-
end
|
4007
|
-
end
|
4008
|
-
|
4009
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
4010
|
-
|
4011
|
-
context "when passed a #{falsehood} with destroy" do
|
4012
|
-
|
4013
|
-
before do
|
4014
|
-
person.preferences_attributes =
|
4015
|
-
{
|
4016
|
-
"0" => { "id" => preference_one.id, "_destroy" => falsehood },
|
4017
|
-
"1" => { "id" => preference_two.id, "name" => "New Title" }
|
4018
|
-
}
|
4019
|
-
end
|
4020
|
-
|
4021
|
-
context "when reloading" do
|
4022
|
-
|
4023
|
-
it "does not delete the marked document" do
|
4024
|
-
person.preferences(true).size.should eq(2)
|
4025
|
-
end
|
4026
|
-
|
4027
|
-
it "does not delete the unmarked document" do
|
4028
|
-
person.preferences(true).last.name.should eq("New Title")
|
4029
|
-
end
|
4030
|
-
end
|
4031
|
-
end
|
4032
|
-
end
|
4033
|
-
end
|
4034
|
-
end
|
4035
|
-
end
|
4036
|
-
end
|
4037
|
-
|
4038
|
-
context "when no ids are passed" do
|
4039
|
-
|
4040
|
-
context "when no destroy attributes are passed" do
|
4041
|
-
|
4042
|
-
before do
|
4043
|
-
person.preferences_attributes =
|
4044
|
-
{
|
4045
|
-
"4" => { "name" => "Third" },
|
4046
|
-
"1" => { "name" => "First" },
|
4047
|
-
"2" => { "name" => "Second" }
|
4048
|
-
}
|
4049
|
-
end
|
4050
|
-
|
4051
|
-
it "builds a new first document" do
|
4052
|
-
person.preferences.first.name.should eq("First")
|
4053
|
-
end
|
4054
|
-
|
4055
|
-
it "builds a new second document" do
|
4056
|
-
person.preferences.second.name.should eq("Second")
|
4057
|
-
end
|
4058
|
-
|
4059
|
-
it "builds a new third document" do
|
4060
|
-
person.preferences.third.name.should eq("Third")
|
4061
|
-
end
|
4062
|
-
|
4063
|
-
it "does not add extra documents" do
|
4064
|
-
person.preferences.size.should eq(3)
|
4065
|
-
end
|
4066
|
-
|
4067
|
-
it "adds the documents in the sorted hash key order" do
|
4068
|
-
person.preferences.map(&:name).should eq(
|
4069
|
-
[ "First", "Second", "Third" ]
|
4070
|
-
)
|
4071
|
-
end
|
4072
|
-
end
|
4073
|
-
|
4074
|
-
context "when a reject block is supplied" do
|
4075
|
-
|
4076
|
-
before(:all) do
|
4077
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4078
|
-
Person.accepts_nested_attributes_for \
|
4079
|
-
:preferences, reject_if: ->(attrs){ attrs["name"].blank? }
|
4080
|
-
end
|
4081
|
-
|
4082
|
-
after(:all) do
|
4083
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4084
|
-
Person.accepts_nested_attributes_for :preferences
|
4085
|
-
end
|
4086
|
-
|
4087
|
-
context "when the attributes match" do
|
4088
|
-
|
4089
|
-
before do
|
4090
|
-
person.preferences_attributes =
|
4091
|
-
{ "3" => { "content" => "My first blog" } }
|
4092
|
-
end
|
4093
|
-
|
4094
|
-
it "does not add the new document" do
|
4095
|
-
person.preferences.should be_empty
|
4096
|
-
end
|
4097
|
-
end
|
4098
|
-
|
4099
|
-
context "when the attributes do not match" do
|
4100
|
-
|
4101
|
-
before do
|
4102
|
-
person.preferences_attributes =
|
4103
|
-
{ "3" => { "name" => "Blogging" } }
|
4104
|
-
end
|
4105
|
-
|
4106
|
-
it "adds the new document" do
|
4107
|
-
person.preferences.size.should eq(1)
|
4108
|
-
end
|
4109
|
-
|
4110
|
-
it "sets the correct attributes" do
|
4111
|
-
person.preferences.first.name.should eq("Blogging")
|
4112
|
-
end
|
4113
|
-
end
|
4114
|
-
end
|
4115
|
-
|
4116
|
-
context "when :reject_if => :all_blank is supplied" do
|
4117
|
-
|
4118
|
-
before(:all) do
|
4119
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4120
|
-
Person.accepts_nested_attributes_for \
|
4121
|
-
:preferences, reject_if: :all_blank
|
4122
|
-
end
|
4123
|
-
|
4124
|
-
after(:all) do
|
4125
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4126
|
-
Person.accepts_nested_attributes_for :preferences
|
4127
|
-
end
|
4128
|
-
|
4129
|
-
context "when all attributes are empty" do
|
4130
|
-
|
4131
|
-
before do
|
4132
|
-
person.preferences_attributes =
|
4133
|
-
{ "3" => { "content" => "" } }
|
4134
|
-
end
|
4135
|
-
|
4136
|
-
it "does not add the new document" do
|
4137
|
-
person.preferences.should be_empty
|
4138
|
-
end
|
4139
|
-
end
|
4140
|
-
|
4141
|
-
context "when an attribute is non-empty" do
|
4142
|
-
|
4143
|
-
before do
|
4144
|
-
person.preferences_attributes =
|
4145
|
-
{ "3" => { "name" => "Blogging" } }
|
4146
|
-
end
|
4147
|
-
|
4148
|
-
it "adds the new document" do
|
4149
|
-
person.preferences.size.should eq(1)
|
4150
|
-
end
|
4151
|
-
|
4152
|
-
it "sets the correct attributes" do
|
4153
|
-
person.preferences.first.name.should eq("Blogging")
|
4154
|
-
end
|
4155
|
-
end
|
4156
|
-
end
|
4157
|
-
|
4158
|
-
context "when destroy attributes are passed" do
|
4159
|
-
|
4160
|
-
context "when allow_destroy is true" do
|
4161
|
-
|
4162
|
-
before(:all) do
|
4163
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4164
|
-
Person.accepts_nested_attributes_for :preferences, allow_destroy: true
|
4165
|
-
end
|
4166
|
-
|
4167
|
-
after(:all) do
|
4168
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4169
|
-
Person.accepts_nested_attributes_for :preferences
|
4170
|
-
end
|
4171
|
-
|
4172
|
-
[ 1, "1", true, "true" ].each do |truth|
|
4173
|
-
|
4174
|
-
context "when passed a #{truth} with destroy" do
|
4175
|
-
|
4176
|
-
before do
|
4177
|
-
person.preferences_attributes =
|
4178
|
-
{
|
4179
|
-
"0" => { "name" => "New Blog", "_destroy" => truth },
|
4180
|
-
"1" => { "name" => "Blog Two" }
|
4181
|
-
}
|
4182
|
-
end
|
4183
|
-
|
4184
|
-
it "ignores the the marked document" do
|
4185
|
-
person.preferences.size.should eq(1)
|
4186
|
-
end
|
4187
|
-
|
4188
|
-
it "adds the new unmarked document" do
|
4189
|
-
person.preferences.first.name.should eq("Blog Two")
|
4190
|
-
end
|
4191
|
-
end
|
4192
|
-
end
|
4193
|
-
|
4194
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
4195
|
-
|
4196
|
-
context "when passed a #{falsehood} with destroy" do
|
4197
|
-
|
4198
|
-
before do
|
4199
|
-
person.preferences_attributes =
|
4200
|
-
{
|
4201
|
-
"0" => { "name" => "New Blog", "_destroy" => falsehood },
|
4202
|
-
"1" => { "name" => "Blog Two" }
|
4203
|
-
}
|
4204
|
-
end
|
4205
|
-
|
4206
|
-
it "adds the new marked document" do
|
4207
|
-
person.preferences.first.name.should eq("New Blog")
|
4208
|
-
end
|
4209
|
-
|
4210
|
-
it "adds the new unmarked document" do
|
4211
|
-
person.preferences.last.name.should eq("Blog Two")
|
4212
|
-
end
|
4213
|
-
|
4214
|
-
it "does not add extra documents" do
|
4215
|
-
person.preferences.size.should eq(2)
|
4216
|
-
end
|
4217
|
-
end
|
4218
|
-
end
|
4219
|
-
end
|
4220
|
-
|
4221
|
-
context "when allow destroy is false" do
|
4222
|
-
|
4223
|
-
before(:all) do
|
4224
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4225
|
-
Person.accepts_nested_attributes_for :preferences, allow_destroy: false
|
4226
|
-
end
|
4227
|
-
|
4228
|
-
after(:all) do
|
4229
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4230
|
-
Person.accepts_nested_attributes_for :preferences
|
4231
|
-
end
|
4232
|
-
|
4233
|
-
[ 1, "1", true, "true" ].each do |truth|
|
4234
|
-
|
4235
|
-
context "when passed a #{truth} with destroy" do
|
4236
|
-
|
4237
|
-
before do
|
4238
|
-
person.preferences_attributes =
|
4239
|
-
{
|
4240
|
-
"0" => { "name" => "New Blog", "_destroy" => truth },
|
4241
|
-
"1" => { "name" => "Blog Two" }
|
4242
|
-
}
|
4243
|
-
end
|
4244
|
-
|
4245
|
-
it "adds the the marked document" do
|
4246
|
-
person.preferences.first.name.should eq("New Blog")
|
4247
|
-
end
|
4248
|
-
|
4249
|
-
it "adds the new unmarked document" do
|
4250
|
-
person.preferences.last.name.should eq("Blog Two")
|
4251
|
-
end
|
4252
|
-
|
4253
|
-
it "adds the correct number of documents" do
|
4254
|
-
person.preferences.size.should eq(2)
|
4255
|
-
end
|
4256
|
-
end
|
4257
|
-
end
|
4258
|
-
|
4259
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
4260
|
-
|
4261
|
-
context "when passed a #{falsehood} with destroy" do
|
4262
|
-
|
4263
|
-
before do
|
4264
|
-
person.preferences_attributes =
|
4265
|
-
{
|
4266
|
-
"0" => { "name" => "New Blog", "_destroy" => falsehood },
|
4267
|
-
"1" => { "name" => "Blog Two" }
|
4268
|
-
}
|
4269
|
-
end
|
4270
|
-
|
4271
|
-
it "adds the new marked document" do
|
4272
|
-
person.preferences.first.name.should eq("New Blog")
|
4273
|
-
end
|
4274
|
-
|
4275
|
-
it "adds the new unmarked document" do
|
4276
|
-
person.preferences.last.name.should eq("Blog Two")
|
4277
|
-
end
|
4278
|
-
|
4279
|
-
it "does not add extra documents" do
|
4280
|
-
person.preferences.size.should eq(2)
|
4281
|
-
end
|
4282
|
-
end
|
4283
|
-
end
|
4284
|
-
end
|
4285
|
-
|
4286
|
-
context "when allow destroy is not defined" do
|
4287
|
-
|
4288
|
-
before(:all) do
|
4289
|
-
Person.send(:undef_method, :preferences_attributes=)
|
4290
|
-
Person.accepts_nested_attributes_for :preferences
|
4291
|
-
end
|
4292
|
-
|
4293
|
-
[ 1, "1", true, "true" ].each do |truth|
|
4294
|
-
|
4295
|
-
context "when passed a #{truth} with destroy" do
|
4296
|
-
|
4297
|
-
before do
|
4298
|
-
person.preferences_attributes =
|
4299
|
-
{
|
4300
|
-
"0" => { "name" => "New Blog", "_destroy" => truth },
|
4301
|
-
"1" => { "name" => "Blog Two" }
|
4302
|
-
}
|
4303
|
-
end
|
4304
|
-
|
4305
|
-
it "adds the the marked document" do
|
4306
|
-
person.preferences.first.name.should eq("New Blog")
|
4307
|
-
end
|
4308
|
-
|
4309
|
-
it "adds the new unmarked document" do
|
4310
|
-
person.preferences.last.name.should eq("Blog Two")
|
4311
|
-
end
|
4312
|
-
|
4313
|
-
it "adds the correct number of documents" do
|
4314
|
-
person.preferences.size.should eq(2)
|
4315
|
-
end
|
4316
|
-
end
|
4317
|
-
end
|
4318
|
-
|
4319
|
-
[ 0, "0", false, "false" ].each do |falsehood|
|
4320
|
-
|
4321
|
-
context "when passed a #{falsehood} with destroy" do
|
4322
|
-
|
4323
|
-
before do
|
4324
|
-
person.preferences_attributes =
|
4325
|
-
{
|
4326
|
-
"0" => { "name" => "New Blog", "_destroy" => falsehood },
|
4327
|
-
"1" => { "name" => "Blog Two" }
|
4328
|
-
}
|
4329
|
-
end
|
4330
|
-
|
4331
|
-
it "adds the new marked document" do
|
4332
|
-
person.preferences.first.name.should eq("New Blog")
|
4333
|
-
end
|
4334
|
-
|
4335
|
-
it "adds the new unmarked document" do
|
4336
|
-
person.preferences.last.name.should eq("Blog Two")
|
4337
|
-
end
|
4338
|
-
|
4339
|
-
it "does not add extra documents" do
|
4340
|
-
person.preferences.size.should eq(2)
|
4341
|
-
end
|
4342
|
-
end
|
4343
|
-
end
|
4344
|
-
end
|
4345
|
-
end
|
4346
|
-
end
|
4347
|
-
|
4348
|
-
context "when the nested document is invalid" do
|
4349
|
-
|
4350
|
-
before(:all) do
|
4351
|
-
Person.validates_associated(:preferences)
|
4352
|
-
end
|
4353
|
-
|
4354
|
-
after(:all) do
|
4355
|
-
Person.reset_callbacks(:validate)
|
4356
|
-
end
|
4357
|
-
|
4358
|
-
before do
|
4359
|
-
person.preferences_attributes = {
|
4360
|
-
"0" => { name: 'x' }
|
4361
|
-
}
|
4362
|
-
end
|
4363
|
-
|
4364
|
-
it "propagates invalidity to parent" do
|
4365
|
-
person.preferences.first.should_not be_valid
|
4366
|
-
person.should_not be_valid
|
4367
|
-
end
|
4368
|
-
end
|
4369
|
-
end
|
4370
|
-
end
|
4371
|
-
end
|
4372
|
-
|
4373
|
-
describe "#update_attributes" do
|
4374
|
-
|
4375
|
-
before(:all) do
|
4376
|
-
Person.send(:undef_method, :addresses_attributes=)
|
4377
|
-
Person.accepts_nested_attributes_for :addresses
|
4378
|
-
end
|
4379
|
-
|
4380
|
-
context "when embedding one level behind a has many" do
|
4381
|
-
|
4382
|
-
let(:node) do
|
4383
|
-
Node.create
|
4384
|
-
end
|
4385
|
-
|
4386
|
-
let!(:server) do
|
4387
|
-
node.servers.create(name: "prod")
|
4388
|
-
end
|
4389
|
-
|
4390
|
-
context "when adding a new embedded document" do
|
4391
|
-
|
4392
|
-
let(:attributes) do
|
4393
|
-
{ servers_attributes:
|
4394
|
-
{ "0" =>
|
4395
|
-
{
|
4396
|
-
_id: server.id,
|
4397
|
-
filesystems_attributes: {
|
4398
|
-
"0" => { name: "NFS" }
|
4399
|
-
}
|
4400
|
-
}
|
4401
|
-
}
|
4402
|
-
}
|
4403
|
-
end
|
4404
|
-
|
4405
|
-
before do
|
4406
|
-
node.update_attributes(attributes)
|
4407
|
-
end
|
4408
|
-
|
4409
|
-
it "adds the new embedded document" do
|
4410
|
-
server.reload.filesystems.first.name.should eq("NFS")
|
4411
|
-
end
|
4412
|
-
|
4413
|
-
it "does not add more than one document" do
|
4414
|
-
server.reload.filesystems.count.should eq(1)
|
4415
|
-
end
|
4416
|
-
end
|
4417
|
-
end
|
4418
|
-
|
4419
|
-
context "when deleting the child document" do
|
4420
|
-
|
4421
|
-
let(:person) do
|
4422
|
-
Person.create
|
4423
|
-
end
|
4424
|
-
|
4425
|
-
let!(:service) do
|
4426
|
-
person.services.create(sid: "123")
|
4427
|
-
end
|
4428
|
-
|
4429
|
-
let(:attributes) do
|
4430
|
-
{ services_attributes:
|
4431
|
-
{ "0" =>
|
4432
|
-
{ _id: service.id, sid: service.sid, _destroy: 1 }
|
4433
|
-
}
|
4434
|
-
}
|
4435
|
-
end
|
4436
|
-
|
4437
|
-
before do
|
4438
|
-
person.update_attributes(attributes)
|
4439
|
-
end
|
4440
|
-
|
4441
|
-
it "removes the document from the parent" do
|
4442
|
-
person.services.should be_empty
|
4443
|
-
end
|
4444
|
-
|
4445
|
-
it "deletes the document" do
|
4446
|
-
service.should be_destroyed
|
4447
|
-
end
|
4448
|
-
|
4449
|
-
it "runs the before destroy callbacks" do
|
4450
|
-
service.before_destroy_called.should be_true
|
4451
|
-
end
|
4452
|
-
|
4453
|
-
it "runs the after destroy callbacks" do
|
4454
|
-
service.after_destroy_called.should be_true
|
4455
|
-
end
|
4456
|
-
|
4457
|
-
it "clears the delayed atomic pulls from the parent" do
|
4458
|
-
person.delayed_atomic_pulls.should be_empty
|
4459
|
-
end
|
4460
|
-
end
|
4461
|
-
|
4462
|
-
context "when nesting multiple levels and parent is timestamped" do
|
4463
|
-
|
4464
|
-
before(:all) do
|
4465
|
-
class Address
|
4466
|
-
after_save do
|
4467
|
-
addressable.touch
|
4468
|
-
end
|
4469
|
-
end
|
4470
|
-
end
|
4471
|
-
|
4472
|
-
after(:all) do
|
4473
|
-
Address.reset_callbacks(:save)
|
4474
|
-
end
|
4475
|
-
|
4476
|
-
let(:dokument) do
|
4477
|
-
Dokument.create
|
4478
|
-
end
|
4479
|
-
|
4480
|
-
let!(:address) do
|
4481
|
-
dokument.addresses.create(street: "hobrecht")
|
4482
|
-
end
|
4483
|
-
|
4484
|
-
let!(:location) do
|
4485
|
-
address.locations.create(name: "work")
|
4486
|
-
end
|
4487
|
-
|
4488
|
-
let(:attributes) do
|
4489
|
-
{
|
4490
|
-
locations_attributes: {
|
4491
|
-
a: { name: "home" }
|
4492
|
-
}
|
4493
|
-
}
|
4494
|
-
end
|
4495
|
-
|
4496
|
-
before do
|
4497
|
-
address.with(safe: true).update_attributes(attributes)
|
4498
|
-
address.reload
|
4499
|
-
end
|
4500
|
-
|
4501
|
-
it "does not add any extra locations" do
|
4502
|
-
address.locations.size.should eq(2)
|
4503
|
-
end
|
4504
|
-
end
|
4505
|
-
|
4506
|
-
context "when nesting multiple levels" do
|
4507
|
-
|
4508
|
-
let!(:person) do
|
4509
|
-
Person.create
|
4510
|
-
end
|
4511
|
-
|
4512
|
-
context "when second level is a one to many" do
|
4513
|
-
|
4514
|
-
let(:person_one) do
|
4515
|
-
Person.create
|
4516
|
-
end
|
4517
|
-
|
4518
|
-
let!(:address_one) do
|
4519
|
-
person_one.addresses.create(street: "hobrecht")
|
4520
|
-
end
|
4521
|
-
|
4522
|
-
let!(:location_one) do
|
4523
|
-
address_one.locations.create(name: "home")
|
4524
|
-
end
|
4525
|
-
|
4526
|
-
context "when destroying a second level document" do
|
4527
|
-
|
4528
|
-
let(:attributes) do
|
4529
|
-
{ addresses_attributes:
|
4530
|
-
{ "0" =>
|
4531
|
-
{
|
4532
|
-
_id: address_one.id,
|
4533
|
-
locations_attributes: { "0" => { _id: location_one.id, _destroy: true }}
|
4534
|
-
}
|
4535
|
-
}
|
4536
|
-
}
|
4537
|
-
end
|
4538
|
-
|
4539
|
-
before do
|
4540
|
-
person_one.update_attributes(attributes)
|
4541
|
-
end
|
4542
|
-
|
4543
|
-
it "deletes the document from the relation" do
|
4544
|
-
address_one.locations.should be_empty
|
4545
|
-
end
|
4546
|
-
|
4547
|
-
it "persists the change" do
|
4548
|
-
address_one.reload.locations.should be_empty
|
4549
|
-
end
|
4550
|
-
end
|
4551
|
-
|
4552
|
-
context "when destroying a second level document with callbacks" do
|
4553
|
-
|
4554
|
-
let(:band) do
|
4555
|
-
Band.create(name: "Tool")
|
4556
|
-
end
|
4557
|
-
|
4558
|
-
let(:record) do
|
4559
|
-
band.records.create(name: "Undertow")
|
4560
|
-
end
|
4561
|
-
|
4562
|
-
let!(:track) do
|
4563
|
-
record.tracks.create(name: "Sober")
|
4564
|
-
end
|
4565
|
-
|
4566
|
-
context "when cascading callbacks" do
|
4567
|
-
|
4568
|
-
before(:all) do
|
4569
|
-
Band.accepts_nested_attributes_for :records
|
4570
|
-
Record.accepts_nested_attributes_for :tracks, allow_destroy: true
|
4571
|
-
end
|
4572
|
-
|
4573
|
-
after(:all) do
|
4574
|
-
Band.send(:undef_method, :records_attributes=)
|
4575
|
-
Record.send(:undef_method, :tracks_attributes=)
|
4576
|
-
end
|
4577
|
-
|
4578
|
-
let(:attributes) do
|
4579
|
-
{ records_attributes:
|
4580
|
-
{ "0" =>
|
4581
|
-
{
|
4582
|
-
_id: record.id,
|
4583
|
-
tracks_attributes: { "0" => { _id: track.id, _destroy: true }}
|
4584
|
-
}
|
4585
|
-
}
|
4586
|
-
}
|
4587
|
-
end
|
4588
|
-
|
4589
|
-
before do
|
4590
|
-
band.update_attributes(attributes)
|
4591
|
-
end
|
4592
|
-
|
4593
|
-
it "removes the child from the relation" do
|
4594
|
-
record.tracks.should be_empty
|
4595
|
-
end
|
4596
|
-
|
4597
|
-
it "deletes the child document" do
|
4598
|
-
track.should be_destroyed
|
4599
|
-
end
|
4600
|
-
|
4601
|
-
it "runs the child's callbacks" do
|
4602
|
-
track.before_destroy_called.should be_true
|
4603
|
-
end
|
4604
|
-
end
|
4605
|
-
end
|
4606
|
-
|
4607
|
-
context "when adding new documents in both levels" do
|
4608
|
-
|
4609
|
-
context "when no documents has previously existed" do
|
4610
|
-
|
4611
|
-
let(:attributes) do
|
4612
|
-
{ addresses_attributes:
|
4613
|
-
{ "0" =>
|
4614
|
-
{
|
4615
|
-
street: "Alexanderstr",
|
4616
|
-
locations_attributes: { "0" => { name: "Home" } }
|
4617
|
-
}
|
4618
|
-
}
|
4619
|
-
}
|
4620
|
-
end
|
4621
|
-
|
4622
|
-
before do
|
4623
|
-
person.with(safe: true).update_attributes(attributes)
|
4624
|
-
end
|
4625
|
-
|
4626
|
-
let(:address) do
|
4627
|
-
person.addresses.first
|
4628
|
-
end
|
4629
|
-
|
4630
|
-
let(:location) do
|
4631
|
-
address.locations.first
|
4632
|
-
end
|
4633
|
-
|
4634
|
-
it "adds the new first level embedded document" do
|
4635
|
-
address.street.should eq("Alexanderstr")
|
4636
|
-
end
|
4637
|
-
|
4638
|
-
it "adds the nested embedded document" do
|
4639
|
-
location.name.should eq("Home")
|
4640
|
-
end
|
4641
|
-
end
|
4642
|
-
|
4643
|
-
context "when adding to an existing document in the first level" do
|
4644
|
-
|
4645
|
-
let!(:address) do
|
4646
|
-
person.addresses.create(street: "hobrecht")
|
4647
|
-
end
|
4648
|
-
|
4649
|
-
let!(:location) do
|
4650
|
-
address.locations.create(name: "work")
|
4651
|
-
end
|
4652
|
-
|
4653
|
-
let(:attributes) do
|
4654
|
-
{
|
4655
|
-
addresses_attributes: {
|
4656
|
-
a: { id: address.id, locations_attributes: { b: { name: "home" }}},
|
4657
|
-
c: { street: "pfluger" }
|
4658
|
-
}
|
4659
|
-
}
|
4660
|
-
end
|
4661
|
-
|
4662
|
-
before do
|
4663
|
-
person.with(safe: true).update_attributes(attributes)
|
4664
|
-
person.reload
|
4665
|
-
end
|
4666
|
-
|
4667
|
-
it "adds the new location to the existing address" do
|
4668
|
-
person.addresses.first.locations.count.should eq(2)
|
4669
|
-
end
|
4670
|
-
|
4671
|
-
it "adds the new address" do
|
4672
|
-
person.addresses.count.should eq(2)
|
4673
|
-
end
|
4674
|
-
end
|
4675
|
-
end
|
4676
|
-
end
|
4677
|
-
|
4678
|
-
context "when the second level is a one to one" do
|
4679
|
-
|
4680
|
-
context "when the nested document is new" do
|
4681
|
-
|
4682
|
-
let(:attributes) do
|
4683
|
-
{ addresses_attributes:
|
4684
|
-
{ "0" =>
|
4685
|
-
{
|
4686
|
-
street: "Alexanderstr",
|
4687
|
-
code_attributes: { name: "Home" }
|
4688
|
-
}
|
4689
|
-
}
|
4690
|
-
}
|
4691
|
-
end
|
4692
|
-
|
4693
|
-
before do
|
4694
|
-
person.with(safe: true).update_attributes(attributes)
|
4695
|
-
end
|
4696
|
-
|
4697
|
-
let(:address) do
|
4698
|
-
person.addresses.first
|
4699
|
-
end
|
4700
|
-
|
4701
|
-
let(:code) do
|
4702
|
-
address.code
|
4703
|
-
end
|
4704
|
-
|
4705
|
-
it "adds the new first level embedded document" do
|
4706
|
-
address.street.should eq("Alexanderstr")
|
4707
|
-
end
|
4708
|
-
|
4709
|
-
it "adds the nested embedded document" do
|
4710
|
-
code.name.should eq("Home")
|
4711
|
-
end
|
4712
|
-
end
|
4713
|
-
end
|
4714
|
-
|
4715
|
-
context "when the nested document is getting updated" do
|
4716
|
-
|
4717
|
-
context "when the nested document is not polymorphic" do
|
4718
|
-
|
4719
|
-
let!(:address) do
|
4720
|
-
person.addresses.create(street: "Alexanderstr", number: 1)
|
4721
|
-
end
|
4722
|
-
|
4723
|
-
let!(:code) do
|
4724
|
-
address.create_code(name: "Home")
|
4725
|
-
end
|
4726
|
-
|
4727
|
-
let(:attributes) do
|
4728
|
-
{ addresses_attributes:
|
4729
|
-
{ "0" =>
|
4730
|
-
{
|
4731
|
-
_id: address.id,
|
4732
|
-
number: 45,
|
4733
|
-
code_attributes: {
|
4734
|
-
_id: code.id,
|
4735
|
-
name: "Work"
|
4736
|
-
}
|
4737
|
-
}
|
4738
|
-
}
|
4739
|
-
}
|
4740
|
-
end
|
4741
|
-
|
4742
|
-
before do
|
4743
|
-
person.with(safe: true).update_attributes(attributes)
|
4744
|
-
end
|
4745
|
-
|
4746
|
-
it "updates the first level embedded document" do
|
4747
|
-
address.number.should eq(45)
|
4748
|
-
end
|
4749
|
-
|
4750
|
-
it "updates the nested embedded document" do
|
4751
|
-
code.name.should eq("Work")
|
4752
|
-
end
|
4753
|
-
end
|
4754
|
-
|
4755
|
-
context "when the nested document is polymorphic" do
|
4756
|
-
|
4757
|
-
context "when the first level is an embeds many" do
|
4758
|
-
|
4759
|
-
let!(:address) do
|
4760
|
-
person.addresses.create(street: "Alexanderstr", number: 1)
|
4761
|
-
end
|
4762
|
-
|
4763
|
-
let!(:target) do
|
4764
|
-
address.create_target(name: "test")
|
4765
|
-
end
|
4766
|
-
|
4767
|
-
let(:attributes) do
|
4768
|
-
{ addresses_attributes:
|
4769
|
-
{ "0" =>
|
4770
|
-
{
|
4771
|
-
_id: address.id,
|
4772
|
-
number: 45,
|
4773
|
-
target_attributes: {
|
4774
|
-
_id: target.id,
|
4775
|
-
name: "updated"
|
4776
|
-
}
|
4777
|
-
}
|
4778
|
-
}
|
4779
|
-
}
|
4780
|
-
end
|
4781
|
-
|
4782
|
-
before do
|
4783
|
-
person.with(safe: true).update_attributes(attributes)
|
4784
|
-
end
|
4785
|
-
|
4786
|
-
it "updates the first level embedded document" do
|
4787
|
-
address.number.should eq(45)
|
4788
|
-
end
|
4789
|
-
|
4790
|
-
it "updates the nested embedded document" do
|
4791
|
-
target.name.should eq("updated")
|
4792
|
-
end
|
4793
|
-
end
|
4794
|
-
|
4795
|
-
context "when the first level is an embeds one" do
|
4796
|
-
|
4797
|
-
context "when the id is passed as a string" do
|
4798
|
-
|
4799
|
-
let!(:name) do
|
4800
|
-
person.create_name(first_name: "john", last_name: "doe")
|
4801
|
-
end
|
4802
|
-
|
4803
|
-
let!(:language) do
|
4804
|
-
name.create_language(name: "english")
|
4805
|
-
end
|
4806
|
-
|
4807
|
-
let(:attributes) do
|
4808
|
-
{ name_attributes:
|
4809
|
-
{
|
4810
|
-
language_attributes: {
|
4811
|
-
_id: language.id.to_s,
|
4812
|
-
name: "deutsch"
|
4813
|
-
}
|
4814
|
-
}
|
4815
|
-
}
|
4816
|
-
end
|
4817
|
-
|
4818
|
-
before do
|
4819
|
-
person.with(safe: true).update_attributes(attributes)
|
4820
|
-
end
|
4821
|
-
|
4822
|
-
it "updates the nested embedded document" do
|
4823
|
-
language.name.should eq("deutsch")
|
4824
|
-
end
|
4825
|
-
end
|
4826
|
-
end
|
4827
|
-
end
|
4828
|
-
end
|
4829
|
-
end
|
4830
|
-
|
4831
|
-
context "when the relation is a has many" do
|
4832
|
-
|
4833
|
-
context "when updating with valid attributes" do
|
4834
|
-
|
4835
|
-
let(:user) do
|
4836
|
-
User.create
|
4837
|
-
end
|
4838
|
-
|
4839
|
-
let(:params) do
|
4840
|
-
{ posts_attributes:
|
4841
|
-
{ "0" => { title: "Testing" }}
|
4842
|
-
}
|
4843
|
-
end
|
4844
|
-
|
4845
|
-
before do
|
4846
|
-
user.update_attributes(params)
|
4847
|
-
end
|
4848
|
-
|
4849
|
-
let(:post) do
|
4850
|
-
user.posts.first
|
4851
|
-
end
|
4852
|
-
|
4853
|
-
it "adds the new document to the relation" do
|
4854
|
-
post.title.should eq("Testing")
|
4855
|
-
end
|
4856
|
-
|
4857
|
-
it "autosaves the relation" do
|
4858
|
-
user.posts(true).first.title.should eq("Testing")
|
4859
|
-
end
|
4860
|
-
end
|
4861
|
-
|
4862
|
-
context "when the document is freshly loaded from the db" do
|
4863
|
-
|
4864
|
-
let!(:node) do
|
4865
|
-
Node.create
|
4866
|
-
end
|
4867
|
-
|
4868
|
-
let!(:server) do
|
4869
|
-
node.servers.create(name: "test")
|
4870
|
-
end
|
4871
|
-
|
4872
|
-
before do
|
4873
|
-
node.reload
|
4874
|
-
end
|
4875
|
-
|
4876
|
-
context "when updating invalid attributes" do
|
4877
|
-
|
4878
|
-
let!(:update) do
|
4879
|
-
node.update_attributes({
|
4880
|
-
servers_attributes: { "0" => { "_id" => server.id, "name" => "" }}
|
4881
|
-
})
|
4882
|
-
end
|
4883
|
-
|
4884
|
-
it "returns false" do
|
4885
|
-
update.should be_false
|
4886
|
-
end
|
4887
|
-
|
4888
|
-
it "does not update the child document" do
|
4889
|
-
server.reload.name.should eq("test")
|
4890
|
-
end
|
4891
|
-
|
4892
|
-
it "adds the errors to the document" do
|
4893
|
-
node.errors[:servers].should_not be_nil
|
4894
|
-
end
|
4895
|
-
end
|
4896
|
-
end
|
4897
|
-
end
|
4898
|
-
|
4899
|
-
context "when the relation is an embeds many" do
|
4900
|
-
|
4901
|
-
let(:league) do
|
4902
|
-
League.create
|
4903
|
-
end
|
4904
|
-
|
4905
|
-
let!(:division) do
|
4906
|
-
league.divisions.create(name: "Old Name")
|
4907
|
-
end
|
4908
|
-
|
4909
|
-
let(:params) do
|
4910
|
-
{ divisions_attributes:
|
4911
|
-
{ "0" => { id: division.id.to_s, name: "New Name" }}
|
4912
|
-
}
|
4913
|
-
end
|
4914
|
-
|
4915
|
-
before do
|
4916
|
-
league.update_attributes(params)
|
4917
|
-
end
|
4918
|
-
|
4919
|
-
it "sets the nested attributes" do
|
4920
|
-
league.reload.divisions.first.name.should eq("New Name")
|
4921
|
-
end
|
4922
|
-
|
4923
|
-
context "with corrupted data" do
|
4924
|
-
|
4925
|
-
before do
|
4926
|
-
league[:league] = params
|
4927
|
-
end
|
4928
|
-
|
4929
|
-
let(:new_params) do
|
4930
|
-
{ divisions_attributes:
|
4931
|
-
{ "0" => { id: division.id.to_s, name: "Name" }}
|
4932
|
-
}
|
4933
|
-
end
|
4934
|
-
|
4935
|
-
before do
|
4936
|
-
league.update_attributes(new_params)
|
4937
|
-
end
|
4938
|
-
|
4939
|
-
it "sets the nested attributes" do
|
4940
|
-
league.reload.divisions.first.name.should eq("Name")
|
4941
|
-
end
|
4942
|
-
end
|
4943
|
-
end
|
4944
|
-
end
|
4945
|
-
end
|