mongoid 3.1.6 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +479 -8
- data/README.md +10 -7
- data/lib/config/locales/en.yml +34 -20
- data/lib/mongoid.rb +10 -76
- data/lib/mongoid/atomic.rb +3 -14
- data/lib/mongoid/atomic/paths/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/attributes.rb +65 -101
- data/lib/mongoid/attributes/dynamic.rb +154 -0
- data/lib/mongoid/attributes/nested.rb +82 -0
- data/lib/mongoid/attributes/processing.rb +13 -66
- data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
- data/lib/mongoid/composable.rb +105 -0
- data/lib/mongoid/config.rb +3 -9
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -0
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
- data/lib/mongoid/contextual/atomic.rb +53 -53
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -2
- data/lib/mongoid/contextual/memory.rb +23 -11
- data/lib/mongoid/contextual/mongo.rb +75 -57
- data/lib/mongoid/contextual/none.rb +90 -0
- data/lib/mongoid/contextual/text_search.rb +178 -0
- data/lib/mongoid/copyable.rb +2 -3
- data/lib/mongoid/criteria.rb +39 -34
- data/lib/mongoid/criteria/#findable.rb# +141 -0
- data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
- data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
- data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
- data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
- data/lib/mongoid/criteria/permission.rb +70 -0
- data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
- data/lib/mongoid/document.rb +39 -24
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
- data/lib/mongoid/errors/document_not_found.rb +2 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
- data/lib/mongoid/errors/invalid_value.rb +16 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/errors/readonly_document.rb +24 -0
- data/lib/mongoid/extensions.rb +15 -7
- data/lib/mongoid/extensions/array.rb +3 -3
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +15 -17
- data/lib/mongoid/extensions/date.rb +1 -1
- data/lib/mongoid/extensions/date_time.rb +3 -3
- data/lib/mongoid/extensions/float.rb +2 -1
- data/lib/mongoid/extensions/hash.rb +3 -3
- data/lib/mongoid/extensions/integer.rb +1 -1
- data/lib/mongoid/extensions/object.rb +7 -7
- data/lib/mongoid/extensions/object_id.rb +5 -5
- data/lib/mongoid/extensions/range.rb +9 -3
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/set.rb +1 -1
- data/lib/mongoid/extensions/string.rb +6 -18
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/time.rb +3 -3
- data/lib/mongoid/extensions/time_with_zone.rb +1 -1
- data/lib/mongoid/factory.rb +8 -6
- data/lib/mongoid/fields.rb +41 -8
- data/lib/mongoid/fields/foreign_key.rb +3 -3
- data/lib/mongoid/fields/localized.rb +1 -1
- data/lib/mongoid/fields/standard.rb +5 -17
- data/lib/mongoid/fields/validators/macro.rb +15 -5
- data/lib/mongoid/{finders.rb → findable.rb} +35 -7
- data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
- data/lib/mongoid/indexable/specification.rb +104 -0
- data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
- data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
- data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
- data/lib/mongoid/log_subscriber.rb +55 -0
- data/lib/mongoid/matchable.rb +152 -0
- data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
- data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
- data/lib/mongoid/persistable.rb +216 -0
- data/lib/mongoid/persistable/creatable.rb +189 -0
- data/lib/mongoid/persistable/deletable.rb +149 -0
- data/lib/mongoid/persistable/destroyable.rb +60 -0
- data/lib/mongoid/persistable/incrementable.rb +36 -0
- data/lib/mongoid/persistable/logical.rb +38 -0
- data/lib/mongoid/persistable/poppable.rb +39 -0
- data/lib/mongoid/persistable/pullable.rb +55 -0
- data/lib/mongoid/persistable/pushable.rb +62 -0
- data/lib/mongoid/persistable/renamable.rb +35 -0
- data/lib/mongoid/persistable/savable.rb +52 -0
- data/lib/mongoid/persistable/settable.rb +33 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +153 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/query_cache.rb +255 -0
- data/lib/mongoid/railtie.rb +34 -60
- data/lib/mongoid/railties/database.rake +9 -25
- data/lib/mongoid/relations.rb +11 -25
- data/lib/mongoid/relations/accessors.rb +15 -51
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +2 -25
- data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
- data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
- data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
- data/lib/mongoid/relations/builder.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -6
- data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
- data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
- data/lib/mongoid/relations/cascading.rb +3 -5
- data/lib/mongoid/relations/constraint.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +39 -15
- data/lib/mongoid/relations/eager.rb +46 -0
- data/lib/mongoid/relations/eager/base.rb +149 -0
- data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
- data/lib/mongoid/relations/eager/has_many.rb +38 -0
- data/lib/mongoid/relations/eager/has_one.rb +30 -0
- data/lib/mongoid/relations/embedded/batchable.rb +4 -5
- data/lib/mongoid/relations/embedded/in.rb +4 -4
- data/lib/mongoid/relations/embedded/many.rb +14 -32
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/relations/macros.rb +3 -4
- data/lib/mongoid/relations/many.rb +51 -31
- data/lib/mongoid/relations/marshalable.rb +3 -3
- data/lib/mongoid/relations/metadata.rb +14 -79
- data/lib/mongoid/relations/nested_builder.rb +2 -2
- data/lib/mongoid/relations/one.rb +1 -1
- data/lib/mongoid/relations/options.rb +1 -0
- data/lib/mongoid/relations/polymorphic.rb +0 -1
- data/lib/mongoid/relations/proxy.rb +21 -41
- data/lib/mongoid/relations/referenced/in.rb +4 -20
- data/lib/mongoid/relations/referenced/many.rb +22 -35
- data/lib/mongoid/relations/referenced/many_to_many.rb +19 -42
- data/lib/mongoid/relations/referenced/one.rb +6 -25
- data/lib/mongoid/relations/synchronization.rb +4 -4
- data/lib/mongoid/relations/targets/enumerable.rb +10 -10
- data/lib/mongoid/relations/touchable.rb +34 -1
- data/lib/mongoid/{reloading.rb → reloadable.rb} +7 -5
- data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
- data/lib/mongoid/sessions.rb +37 -345
- data/lib/mongoid/sessions/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +185 -0
- data/lib/mongoid/sessions/storage_options.rb +140 -0
- data/lib/mongoid/sessions/thread_options.rb +19 -0
- data/lib/mongoid/sessions/validators/storage.rb +16 -3
- data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
- data/lib/mongoid/{state.rb → stateful.rb} +13 -1
- data/lib/mongoid/support/query_counter.rb +23 -0
- data/lib/mongoid/tasks/database.rake +31 -0
- data/lib/mongoid/tasks/database.rb +107 -0
- data/lib/mongoid/threaded.rb +26 -172
- data/lib/mongoid/threaded/lifecycle.rb +0 -28
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
- data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
- data/lib/mongoid/{validations → validatable}/format.rb +1 -1
- data/lib/mongoid/{validations → validatable}/length.rb +1 -1
- data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
- data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
- data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
- data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
- data/lib/mongoid/{validations → validatable}/uniqueness.rb +25 -21
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +46 -25
- data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
- data/lib/rails/generators/mongoid_generator.rb +3 -40
- data/lib/rails/mongoid.rb +0 -122
- data/lib/support/ruby_version.rb +1 -1
- data/spec/app/models/account.rb +2 -6
- data/spec/app/models/acolyte.rb +2 -1
- data/spec/app/models/actor.rb +0 -1
- data/spec/app/models/address.rb +8 -3
- data/spec/app/models/animal.rb +1 -1
- data/spec/app/models/appointment.rb +3 -3
- data/spec/app/models/article.rb +1 -4
- data/spec/app/models/audio.rb +5 -0
- data/spec/app/models/author.rb +0 -2
- data/spec/app/models/band.rb +3 -2
- data/spec/app/models/bar.rb +1 -0
- data/spec/app/models/book.rb +1 -0
- data/spec/app/models/building.rb +0 -2
- data/spec/app/models/building_address.rb +0 -2
- data/spec/app/models/bus.rb +1 -1
- data/spec/app/models/canvas.rb +1 -1
- data/spec/app/models/contextable_item.rb +5 -0
- data/spec/app/models/contractor.rb +0 -2
- data/spec/app/models/country_code.rb +1 -1
- data/spec/app/models/definition.rb +2 -2
- data/spec/app/models/dog.rb +1 -1
- data/spec/app/models/draft.rb +9 -0
- data/spec/app/models/dragon.rb +4 -0
- data/spec/app/models/drug.rb +1 -3
- data/spec/app/models/dungeon.rb +4 -0
- data/spec/app/models/edit.rb +5 -0
- data/spec/app/models/even.rb +7 -0
- data/spec/app/models/event.rb +1 -1
- data/spec/app/models/filesystem.rb +1 -0
- data/spec/app/models/fish.rb +0 -1
- data/spec/app/models/fruits.rb +6 -0
- data/spec/app/models/game.rb +0 -2
- data/spec/app/models/house.rb +1 -3
- data/spec/app/models/id_key.rb +6 -0
- data/spec/app/models/item.rb +1 -5
- data/spec/app/models/jar.rb +1 -1
- data/spec/app/models/label.rb +4 -4
- data/spec/app/models/line_item.rb +1 -1
- data/spec/app/models/login.rb +1 -1
- data/spec/app/models/message.rb +8 -0
- data/spec/app/models/movie.rb +1 -0
- data/spec/app/models/name.rb +3 -3
- data/spec/app/models/note.rb +3 -1
- data/spec/app/models/odd.rb +7 -0
- data/spec/app/models/oscar.rb +1 -1
- data/spec/app/models/parent_doc.rb +1 -1
- data/spec/app/models/person.rb +16 -10
- data/spec/app/models/phone.rb +1 -3
- data/spec/app/models/player.rb +3 -3
- data/spec/app/models/post.rb +5 -3
- data/spec/app/models/preference.rb +1 -1
- data/spec/app/models/quiz.rb +0 -3
- data/spec/app/models/record.rb +10 -5
- data/spec/app/models/registry.rb +1 -1
- data/spec/app/models/server.rb +1 -1
- data/spec/app/models/service.rb +3 -3
- data/spec/app/models/sound.rb +5 -0
- data/spec/app/models/symptom.rb +1 -1
- data/spec/app/models/template.rb +1 -1
- data/spec/app/models/title.rb +0 -1
- data/spec/app/models/track.rb +5 -5
- data/spec/app/models/tree.rb +3 -3
- data/spec/app/models/video.rb +1 -5
- data/spec/app/models/wiki_page.rb +2 -5
- data/spec/app/models/word.rb +3 -0
- data/spec/app/models/word_origin.rb +1 -1
- data/spec/config/mongoid.yml +7 -8
- data/spec/helpers.rb +18 -0
- data/spec/mongoid/#atomic_spec.rb# +365 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
- data/spec/mongoid/atomic/paths_spec.rb +19 -19
- data/spec/mongoid/atomic_spec.rb +19 -19
- data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +474 -592
- data/spec/mongoid/attributes/readonly_spec.rb +58 -18
- data/spec/mongoid/attributes_spec.rb +349 -434
- data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
- data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
- data/spec/mongoid/config/environment_spec.rb +3 -3
- data/spec/mongoid/config/options_spec.rb +6 -6
- data/spec/mongoid/config_spec.rb +24 -48
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
- data/spec/mongoid/contextual/atomic_spec.rb +60 -56
- data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
- data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
- data/spec/mongoid/contextual/memory_spec.rb +156 -94
- data/spec/mongoid/contextual/mongo_spec.rb +238 -150
- data/spec/mongoid/contextual/none_spec.rb +127 -0
- data/spec/mongoid/contextual/text_search_spec.rb +209 -0
- data/spec/mongoid/copyable_spec.rb +56 -68
- data/spec/mongoid/criteria/findable_spec.rb +991 -0
- data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
- data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1252 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
- data/spec/mongoid/criteria_spec.rb +715 -2421
- data/spec/mongoid/document_spec.rb +171 -121
- data/spec/mongoid/equality_spec.rb +22 -22
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
- data/spec/mongoid/errors/callback_spec.rb +3 -3
- data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
- data/spec/mongoid/errors/eager_load_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
- data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
- data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
- data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
- data/spec/mongoid/errors/no_parent_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
- data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
- data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
- data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
- data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
- data/spec/mongoid/errors/validations_spec.rb +7 -7
- data/spec/mongoid/extensions/array_spec.rb +61 -61
- data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
- data/spec/mongoid/extensions/binary_spec.rb +12 -12
- data/spec/mongoid/extensions/boolean_spec.rb +18 -18
- data/spec/mongoid/extensions/date_spec.rb +13 -13
- data/spec/mongoid/extensions/date_time_spec.rb +8 -8
- data/spec/mongoid/extensions/false_class_spec.rb +5 -5
- data/spec/mongoid/extensions/float_spec.rb +29 -15
- data/spec/mongoid/extensions/hash_spec.rb +29 -29
- data/spec/mongoid/extensions/integer_spec.rb +15 -15
- data/spec/mongoid/extensions/module_spec.rb +2 -2
- data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
- data/spec/mongoid/extensions/object_id_spec.rb +134 -134
- data/spec/mongoid/extensions/object_spec.rb +26 -26
- data/spec/mongoid/extensions/range_spec.rb +61 -12
- data/spec/mongoid/extensions/regexp_spec.rb +4 -4
- data/spec/mongoid/extensions/set_spec.rb +4 -4
- data/spec/mongoid/extensions/string_spec.rb +35 -46
- data/spec/mongoid/extensions/symbol_spec.rb +9 -9
- data/spec/mongoid/extensions/time_spec.rb +49 -49
- data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
- data/spec/mongoid/extensions/true_class_spec.rb +5 -5
- data/spec/mongoid/extensions_spec.rb +29 -0
- data/spec/mongoid/factory_spec.rb +15 -15
- data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
- data/spec/mongoid/fields/localized_spec.rb +38 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +263 -217
- data/spec/mongoid/findable_spec.rb +509 -0
- data/spec/mongoid/indexable/specification_spec.rb +102 -0
- data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
- data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
- data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
- data/spec/mongoid/log_subscriber_spec.rb +75 -0
- data/spec/mongoid/loggable_spec.rb +1 -1
- data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
- data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
- data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
- data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
- data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
- data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
- data/spec/mongoid/matchable/in_spec.rb +49 -0
- data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
- data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
- data/spec/mongoid/matchable/ne_spec.rb +46 -0
- data/spec/mongoid/matchable/nin_spec.rb +48 -0
- data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
- data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
- data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
- data/spec/mongoid/persistable/creatable_spec.rb +553 -0
- data/spec/mongoid/persistable/deletable_spec.rb +218 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
- data/spec/mongoid/persistable/logical_spec.rb +143 -0
- data/spec/mongoid/persistable/poppable_spec.rb +115 -0
- data/spec/mongoid/persistable/pullable_spec.rb +228 -0
- data/spec/mongoid/persistable/pushable_spec.rb +258 -0
- data/spec/mongoid/persistable/renamable_spec.rb +135 -0
- data/spec/mongoid/persistable/savable_spec.rb +498 -0
- data/spec/mongoid/persistable/settable_spec.rb +162 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
- data/spec/mongoid/persistable/updatable_spec.rb +558 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
- data/spec/mongoid/persistable_spec.rb +206 -0
- data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +14 -19
- data/spec/mongoid/query_cache_spec.rb +263 -0
- data/spec/mongoid/railties/document_spec.rb +2 -2
- data/spec/mongoid/relations/accessors_spec.rb +53 -145
- data/spec/mongoid/relations/auto_save_spec.rb +37 -17
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
- data/spec/mongoid/relations/builders_spec.rb +21 -21
- data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
- data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
- data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
- data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
- data/spec/mongoid/relations/cascading_spec.rb +16 -16
- data/spec/mongoid/relations/constraint_spec.rb +8 -7
- data/spec/mongoid/relations/conversions_spec.rb +16 -14
- data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
- data/spec/mongoid/relations/cyclic_spec.rb +18 -18
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
- data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
- data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
- data/spec/mongoid/relations/eager_spec.rb +228 -0
- data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
- data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
- data/spec/mongoid/relations/embedded/many_spec.rb +467 -372
- data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
- data/spec/mongoid/relations/macros_spec.rb +108 -102
- data/spec/mongoid/relations/metadata_spec.rb +180 -255
- data/spec/mongoid/relations/options_spec.rb +1 -1
- data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
- data/spec/mongoid/relations/proxy_spec.rb +2 -2
- data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
- data/spec/mongoid/relations/referenced/many_spec.rb +587 -527
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +401 -424
- data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
- data/spec/mongoid/relations/reflections_spec.rb +6 -6
- data/spec/mongoid/relations/synchronization_spec.rb +46 -50
- data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
- data/spec/mongoid/relations/touchable_spec.rb +333 -0
- data/spec/mongoid/relations_spec.rb +16 -15
- data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +38 -55
- data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
- data/spec/mongoid/sessions/factory_spec.rb +49 -28
- data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
- data/spec/mongoid/sessions/options_spec.rb +108 -0
- data/spec/mongoid/sessions_spec.rb +319 -178
- data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
- data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
- data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
- data/spec/mongoid/tasks/database_spec.rb +160 -0
- data/spec/mongoid/threaded_spec.rb +17 -70
- data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
- data/spec/mongoid/timestamps/created_spec.rb +5 -5
- data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
- data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
- data/spec/mongoid/timestamps/updated_spec.rb +9 -13
- data/spec/mongoid/timestamps_spec.rb +9 -13
- data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
- data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
- data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
- data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
- data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
- data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
- data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
- data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
- data/spec/mongoid_spec.rb +8 -8
- data/spec/rails/mongoid_spec.rb +19 -335
- data/spec/spec_helper.rb +31 -13
- metadata +303 -283
- data/lib/mongoid/atomic/positionable.rb +0 -73
- data/lib/mongoid/components.rb +0 -92
- data/lib/mongoid/config/inflections.rb +0 -6
- data/lib/mongoid/contextual/eager.rb +0 -158
- data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
- data/lib/mongoid/identity_map.rb +0 -163
- data/lib/mongoid/json.rb +0 -16
- data/lib/mongoid/matchers.rb +0 -32
- data/lib/mongoid/matchers/strategies.rb +0 -97
- 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 -136
- data/lib/mongoid/persistence.rb +0 -357
- data/lib/mongoid/persistence/atomic.rb +0 -231
- 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/deletion.rb +0 -31
- data/lib/mongoid/persistence/insertion.rb +0 -38
- data/lib/mongoid/persistence/modification.rb +0 -35
- data/lib/mongoid/persistence/operations.rb +0 -214
- 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/upsertion.rb +0 -31
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid.rb +0 -2
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
- data/spec/app/models/actor_observer.rb +0 -15
- data/spec/app/models/callback_recorder.rb +0 -25
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -36
- data/spec/app/models/phone_observer.rb +0 -6
- data/spec/mongoid/attributes/processing_spec.rb +0 -149
- data/spec/mongoid/criterion/destructive_spec.rb +0 -101
- data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
- data/spec/mongoid/criterion/modification_spec.rb +0 -402
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
- data/spec/mongoid/finders_spec.rb +0 -321
- data/spec/mongoid/identity_map_spec.rb +0 -564
- data/spec/mongoid/json_spec.rb +0 -33
- data/spec/mongoid/matchers/in_spec.rb +0 -25
- data/spec/mongoid/matchers/ne_spec.rb +0 -25
- data/spec/mongoid/matchers/nin_spec.rb +0 -25
- data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
- 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/unit_of_work_spec.rb +0 -196
- data/spec/mongoid/versioning_spec.rb +0 -540
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -28,14 +28,14 @@ describe Mongoid::Atomic::Paths do
|
|
28
28
|
context "when document is an embeds_one" do
|
29
29
|
|
30
30
|
it "returns $unset" do
|
31
|
-
name.atomic_delete_modifier.
|
31
|
+
expect(name.atomic_delete_modifier).to eq("$unset")
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context "when document is an embeds_many" do
|
36
36
|
|
37
37
|
it "returns $pull" do
|
38
|
-
address.atomic_delete_modifier.
|
38
|
+
expect(address.atomic_delete_modifier).to eq("$pull")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -50,14 +50,14 @@ describe Mongoid::Atomic::Paths do
|
|
50
50
|
context "when document is an embeds_one" do
|
51
51
|
|
52
52
|
it "returns $set" do
|
53
|
-
name.atomic_insert_modifier.
|
53
|
+
expect(name.atomic_insert_modifier).to eq("$set")
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
context "when document is an embeds_many" do
|
58
58
|
|
59
59
|
it "returns $push" do
|
60
|
-
address.atomic_insert_modifier.
|
60
|
+
expect(address.atomic_insert_modifier).to eq("$push")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -67,7 +67,7 @@ describe Mongoid::Atomic::Paths do
|
|
67
67
|
context "when the document is a parent" do
|
68
68
|
|
69
69
|
it "returns an empty string" do
|
70
|
-
person.atomic_path.
|
70
|
+
expect(person.atomic_path).to be_empty
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -78,7 +78,7 @@ describe Mongoid::Atomic::Paths do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "returns the inverse_of value of the association" do
|
81
|
-
address.atomic_path.
|
81
|
+
expect(address.atomic_path).to eq("addresses")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -90,7 +90,7 @@ describe Mongoid::Atomic::Paths do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "returns the JSON notation to the document" do
|
93
|
-
location.atomic_path.
|
93
|
+
expect(location.atomic_path).to eq("addresses.locations")
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|
@@ -100,7 +100,7 @@ describe Mongoid::Atomic::Paths do
|
|
100
100
|
context "when the document is a parent" do
|
101
101
|
|
102
102
|
it "returns an id.atomic_selector" do
|
103
|
-
person.atomic_selector.
|
103
|
+
expect(person.atomic_selector).to eq({ "_id" => person.id })
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -111,7 +111,7 @@ describe Mongoid::Atomic::Paths do
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it "returns the association with id.atomic_selector" do
|
114
|
-
address.atomic_selector.
|
114
|
+
expect(address.atomic_selector).to eq(
|
115
115
|
{ "_id" => person.id, "addresses._id" => address.id }
|
116
116
|
)
|
117
117
|
end
|
@@ -125,7 +125,7 @@ describe Mongoid::Atomic::Paths do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it "returns the JSON notation to the document with ids" do
|
128
|
-
location.atomic_selector.
|
128
|
+
expect(location.atomic_selector).to eq(
|
129
129
|
{
|
130
130
|
"_id" => person.id,
|
131
131
|
"addresses._id" => address.id,
|
@@ -141,7 +141,7 @@ describe Mongoid::Atomic::Paths do
|
|
141
141
|
context "when the document is a parent" do
|
142
142
|
|
143
143
|
it "returns an empty string" do
|
144
|
-
person.atomic_position.
|
144
|
+
expect(person.atomic_position).to be_empty
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -154,7 +154,7 @@ describe Mongoid::Atomic::Paths do
|
|
154
154
|
context "when the document is new" do
|
155
155
|
|
156
156
|
it "returns the.atomic_path without index" do
|
157
|
-
address.atomic_position.
|
157
|
+
expect(address.atomic_position).to eq("addresses")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -165,7 +165,7 @@ describe Mongoid::Atomic::Paths do
|
|
165
165
|
end
|
166
166
|
|
167
167
|
it "returns the.atomic_path plus index" do
|
168
|
-
address.atomic_position.
|
168
|
+
expect(address.atomic_position).to eq("addresses.0")
|
169
169
|
end
|
170
170
|
end
|
171
171
|
end
|
@@ -185,7 +185,7 @@ describe Mongoid::Atomic::Paths do
|
|
185
185
|
context "when the document is new" do
|
186
186
|
|
187
187
|
it "returns the.atomic_path with parent indexes" do
|
188
|
-
location.atomic_position.
|
188
|
+
expect(location.atomic_position).to eq("addresses.0.locations")
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -196,7 +196,7 @@ describe Mongoid::Atomic::Paths do
|
|
196
196
|
end
|
197
197
|
|
198
198
|
it "returns the.atomic_path plus index" do
|
199
|
-
location.atomic_position.
|
199
|
+
expect(location.atomic_position).to eq("addresses.0.locations.1")
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -207,7 +207,7 @@ describe Mongoid::Atomic::Paths do
|
|
207
207
|
context "when the document is a parent" do
|
208
208
|
|
209
209
|
it "returns an empty string" do
|
210
|
-
person.atomic_path.
|
210
|
+
expect(person.atomic_path).to be_empty
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -224,7 +224,7 @@ describe Mongoid::Atomic::Paths do
|
|
224
224
|
end
|
225
225
|
|
226
226
|
it "returns the.atomic_path without the index" do
|
227
|
-
address.atomic_path.
|
227
|
+
expect(address.atomic_path).to eq("addresses")
|
228
228
|
end
|
229
229
|
|
230
230
|
context "and there are 10 or more documents" do
|
@@ -236,7 +236,7 @@ describe Mongoid::Atomic::Paths do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
it "returns the.atomic_path without the index" do
|
239
|
-
address.atomic_path.
|
239
|
+
expect(address.atomic_path).to eq("addresses")
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
@@ -261,7 +261,7 @@ describe Mongoid::Atomic::Paths do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
it "returns the.atomic_path plus index" do
|
264
|
-
location.atomic_path.
|
264
|
+
expect(location.atomic_path).to eq("addresses.0.locations")
|
265
265
|
end
|
266
266
|
|
267
267
|
end
|
data/spec/mongoid/atomic_spec.rb
CHANGED
@@ -21,11 +21,11 @@ describe Mongoid::Atomic do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "adds the document to the delayed atomic pulls" do
|
24
|
-
person.delayed_atomic_pulls["addresses"].
|
24
|
+
expect(person.delayed_atomic_pulls["addresses"]).to eq([ address ])
|
25
25
|
end
|
26
26
|
|
27
27
|
it "flags the document for destruction" do
|
28
|
-
address.
|
28
|
+
expect(address).to be_flagged_for_destroy
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -44,11 +44,11 @@ describe Mongoid::Atomic do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "adds the document to the delayed atomic unsets" do
|
47
|
-
person.delayed_atomic_unsets["name"].
|
47
|
+
expect(person.delayed_atomic_unsets["name"]).to eq([ name ])
|
48
48
|
end
|
49
49
|
|
50
50
|
it "flags the document for destruction" do
|
51
|
-
name.
|
51
|
+
expect(name).to be_flagged_for_destroy
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -67,7 +67,7 @@ describe Mongoid::Atomic do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "returns the atomic updates" do
|
70
|
-
person.atomic_updates.
|
70
|
+
expect(person.atomic_updates).to eq({ "$set" => { "title" => "Sir" }})
|
71
71
|
end
|
72
72
|
|
73
73
|
context "when an embeds many child is added" do
|
@@ -77,7 +77,7 @@ describe Mongoid::Atomic do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it "returns a $set and $pushAll for modifications" do
|
80
|
-
person.atomic_updates.
|
80
|
+
expect(person.atomic_updates).to eq(
|
81
81
|
{
|
82
82
|
"$set" => { "title" => "Sir" },
|
83
83
|
"$pushAll" => { "addresses" => [
|
@@ -95,7 +95,7 @@ describe Mongoid::Atomic do
|
|
95
95
|
end
|
96
96
|
|
97
97
|
it "returns a $set for modifications" do
|
98
|
-
person.atomic_updates.
|
98
|
+
expect(person.atomic_updates).to eq(
|
99
99
|
{
|
100
100
|
"$set" => {
|
101
101
|
"title" => "Sir",
|
@@ -119,7 +119,7 @@ describe Mongoid::Atomic do
|
|
119
119
|
context "when asking for the updates from the root" do
|
120
120
|
|
121
121
|
it "returns the $set with correct position and modifications" do
|
122
|
-
person.atomic_updates.
|
122
|
+
expect(person.atomic_updates).to eq(
|
123
123
|
{ "$set" => { "title" => "Sir", "addresses.0.street" => "Bond St" }}
|
124
124
|
)
|
125
125
|
end
|
@@ -128,7 +128,7 @@ describe Mongoid::Atomic do
|
|
128
128
|
context "when asking for the updates from the child" do
|
129
129
|
|
130
130
|
it "returns the $set with correct position and modifications" do
|
131
|
-
address.atomic_updates.
|
131
|
+
expect(address.atomic_updates).to eq(
|
132
132
|
{ "$set" => { "addresses.0.street" => "Bond St" }}
|
133
133
|
)
|
134
134
|
end
|
@@ -147,7 +147,7 @@ describe Mongoid::Atomic do
|
|
147
147
|
context "when asking for the updates from the root" do
|
148
148
|
|
149
149
|
it "returns the $set with correct positions and modifications" do
|
150
|
-
person.atomic_updates.
|
150
|
+
expect(person.atomic_updates).to eq(
|
151
151
|
{ "$set" => {
|
152
152
|
"title" => "Sir",
|
153
153
|
"addresses.0.street" => "Bond St",
|
@@ -160,7 +160,7 @@ describe Mongoid::Atomic do
|
|
160
160
|
context "when asking for the updates from the 1st level child" do
|
161
161
|
|
162
162
|
it "returns the $set with correct positions and modifications" do
|
163
|
-
address.atomic_updates.
|
163
|
+
expect(address.atomic_updates).to eq(
|
164
164
|
{ "$set" => {
|
165
165
|
"addresses.0.street" => "Bond St",
|
166
166
|
"addresses.0.locations.0.name" => "Work" }
|
@@ -172,7 +172,7 @@ describe Mongoid::Atomic do
|
|
172
172
|
context "when asking for the updates from the 2nd level child" do
|
173
173
|
|
174
174
|
it "returns the $set with correct positions and modifications" do
|
175
|
-
location.atomic_updates.
|
175
|
+
expect(location.atomic_updates).to eq(
|
176
176
|
{ "$set" => {
|
177
177
|
"addresses.0.locations.0.name" => "Work" }
|
178
178
|
}
|
@@ -190,7 +190,7 @@ describe Mongoid::Atomic do
|
|
190
190
|
context "when asking for the updates from the root" do
|
191
191
|
|
192
192
|
it "returns the $set with correct positions and modifications" do
|
193
|
-
person.atomic_updates.
|
193
|
+
expect(person.atomic_updates).to eq(
|
194
194
|
{
|
195
195
|
"$set" => {
|
196
196
|
"title" => "Sir",
|
@@ -209,7 +209,7 @@ describe Mongoid::Atomic do
|
|
209
209
|
context "when asking for the updates from the 1st level child" do
|
210
210
|
|
211
211
|
it "returns the $set with correct positions and modifications" do
|
212
|
-
address.atomic_updates.
|
212
|
+
expect(address.atomic_updates).to eq(
|
213
213
|
{
|
214
214
|
"$set" => {
|
215
215
|
"addresses.0.street" => "Bond St"
|
@@ -236,7 +236,7 @@ describe Mongoid::Atomic do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
it "returns the $set for the first level and $unset for other." do
|
239
|
-
updates.
|
239
|
+
expect(updates).to eq({
|
240
240
|
"$unset" => { "addresses" => true },
|
241
241
|
"$set" => { "title" => "Sir" }
|
242
242
|
})
|
@@ -256,7 +256,7 @@ describe Mongoid::Atomic do
|
|
256
256
|
context "when asking for the updates from the root document" do
|
257
257
|
|
258
258
|
it "returns the $set for 1st level and other for the 2nd level" do
|
259
|
-
person.atomic_updates.
|
259
|
+
expect(person.atomic_updates).to eq(
|
260
260
|
{
|
261
261
|
"$set" => {
|
262
262
|
"title" => "Sir",
|
@@ -282,7 +282,7 @@ describe Mongoid::Atomic do
|
|
282
282
|
context "when asking for the updates from the 1st level document" do
|
283
283
|
|
284
284
|
it "returns the $set for 1st level and other for the 2nd level" do
|
285
|
-
address.atomic_updates.
|
285
|
+
expect(address.atomic_updates).to eq(
|
286
286
|
{ "$set" => { "addresses.0.street" => "Bond St" }}
|
287
287
|
)
|
288
288
|
end
|
@@ -305,7 +305,7 @@ describe Mongoid::Atomic do
|
|
305
305
|
end
|
306
306
|
|
307
307
|
it "returns the $set for 1st and 2nd level and other for the 3nd level" do
|
308
|
-
person.atomic_updates.
|
308
|
+
expect(person.atomic_updates).to eq(
|
309
309
|
{
|
310
310
|
"$set" => {
|
311
311
|
"title" => "Sir"
|
@@ -340,7 +340,7 @@ describe Mongoid::Atomic do
|
|
340
340
|
end
|
341
341
|
|
342
342
|
it "returns the proper $sets and $pushAlls for all levels" do
|
343
|
-
person.atomic_updates.
|
343
|
+
expect(person.atomic_updates).to eq(
|
344
344
|
{
|
345
345
|
"$set" => {
|
346
346
|
"title" => "Sir",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Mongoid::
|
3
|
+
describe Mongoid::Attributes::Nested do
|
4
4
|
|
5
5
|
describe ".accepts_nested_attributes_for" do
|
6
6
|
|
@@ -55,7 +55,7 @@ describe Mongoid::NestedAttributes do
|
|
55
55
|
|
56
56
|
context "when the relation is an embeds one" do
|
57
57
|
|
58
|
-
before
|
58
|
+
before do
|
59
59
|
Person.send(:undef_method, :name_attributes=)
|
60
60
|
Person.accepts_nested_attributes_for :name
|
61
61
|
end
|
@@ -65,13 +65,13 @@ describe Mongoid::NestedAttributes do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "sets the nested attributes" do
|
68
|
-
person.name.first_name.
|
68
|
+
expect(person.name.first_name).to eq("Johnny")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
context "when the relation is an embeds many" do
|
73
73
|
|
74
|
-
before
|
74
|
+
before do
|
75
75
|
Person.send(:undef_method, :addresses_attributes=)
|
76
76
|
Person.accepts_nested_attributes_for :addresses
|
77
77
|
end
|
@@ -81,7 +81,7 @@ describe Mongoid::NestedAttributes do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
it "sets the nested attributes" do
|
84
|
-
person.addresses.first.street.
|
84
|
+
expect(person.addresses.first.street).to eq("Alexanderstr")
|
85
85
|
end
|
86
86
|
|
87
87
|
context "when there are 10 or more child records" do
|
@@ -97,14 +97,14 @@ describe Mongoid::NestedAttributes do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
it "preserves the order of the children" do
|
100
|
-
person.addresses.map(&:number).
|
100
|
+
expect(person.addresses.map(&:number)).to eq((0..10).to_a)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
context "when the relation is an embedded in" do
|
106
106
|
|
107
|
-
before
|
107
|
+
before do
|
108
108
|
Video.accepts_nested_attributes_for :person
|
109
109
|
end
|
110
110
|
|
@@ -113,13 +113,13 @@ describe Mongoid::NestedAttributes do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it "sets the nested attributes" do
|
116
|
-
video.person.title.
|
116
|
+
expect(video.person.title).to eq("Sir")
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
context "when the relation is a references one" do
|
121
121
|
|
122
|
-
before
|
122
|
+
before do
|
123
123
|
Person.send(:undef_method, :game_attributes=)
|
124
124
|
Person.accepts_nested_attributes_for :game
|
125
125
|
end
|
@@ -129,13 +129,13 @@ describe Mongoid::NestedAttributes do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
it "sets the nested attributes" do
|
132
|
-
person.game.name.
|
132
|
+
expect(person.game.name).to eq("Tron")
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
136
|
context "when the relation is a references many" do
|
137
137
|
|
138
|
-
before
|
138
|
+
before do
|
139
139
|
Person.send(:undef_method, :posts_attributes=)
|
140
140
|
Person.accepts_nested_attributes_for :posts
|
141
141
|
end
|
@@ -145,13 +145,13 @@ describe Mongoid::NestedAttributes do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
it "sets the nested attributes" do
|
148
|
-
person.posts.first.title.
|
148
|
+
expect(person.posts.first.title).to eq("First")
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
152
|
context "when the relation is a references and referenced in many" do
|
153
153
|
|
154
|
-
before
|
154
|
+
before do
|
155
155
|
Person.send(:undef_method, :preferences_attributes=)
|
156
156
|
Person.accepts_nested_attributes_for :preferences
|
157
157
|
end
|
@@ -161,13 +161,13 @@ describe Mongoid::NestedAttributes do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "sets the nested attributes" do
|
164
|
-
person.preferences.first.name.
|
164
|
+
expect(person.preferences.first.name).to eq("First")
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
168
168
|
context "when the relation is a referenced in" do
|
169
169
|
|
170
|
-
before
|
170
|
+
before do
|
171
171
|
Post.accepts_nested_attributes_for :person
|
172
172
|
end
|
173
173
|
|
@@ -176,7 +176,7 @@ describe Mongoid::NestedAttributes do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "sets the nested attributes" do
|
179
|
-
post.person.title.
|
179
|
+
expect(post.person.title).to eq("Sir")
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
@@ -210,11 +210,11 @@ describe Mongoid::NestedAttributes do
|
|
210
210
|
end
|
211
211
|
|
212
212
|
it "sets the child document" do
|
213
|
-
person.name.last_name.
|
213
|
+
expect(person.name.last_name).to eq("Fischer")
|
214
214
|
end
|
215
215
|
|
216
216
|
it "does not persist the child document" do
|
217
|
-
person.name.
|
217
|
+
expect(person.name).to_not be_persisted
|
218
218
|
end
|
219
219
|
|
220
220
|
context "when saving the parent" do
|
@@ -225,7 +225,7 @@ describe Mongoid::NestedAttributes do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
it "persists the child document" do
|
228
|
-
person.name.
|
228
|
+
expect(person.name).to be_persisted
|
229
229
|
end
|
230
230
|
end
|
231
231
|
end
|
@@ -237,13 +237,13 @@ describe Mongoid::NestedAttributes do
|
|
237
237
|
|
238
238
|
context "when a reject proc is specified" do
|
239
239
|
|
240
|
-
before
|
240
|
+
before do
|
241
241
|
Person.send(:undef_method, :name_attributes=)
|
242
242
|
Person.accepts_nested_attributes_for \
|
243
243
|
:name, reject_if: ->(attrs){ attrs[:first_name].blank? }
|
244
244
|
end
|
245
245
|
|
246
|
-
after
|
246
|
+
after do
|
247
247
|
Person.send(:undef_method, :name_attributes=)
|
248
248
|
Person.accepts_nested_attributes_for :name
|
249
249
|
end
|
@@ -255,7 +255,7 @@ describe Mongoid::NestedAttributes do
|
|
255
255
|
end
|
256
256
|
|
257
257
|
it "does not add the document" do
|
258
|
-
person.name.
|
258
|
+
expect(person.name).to be_nil
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
@@ -266,7 +266,7 @@ describe Mongoid::NestedAttributes do
|
|
266
266
|
end
|
267
267
|
|
268
268
|
it "adds the document" do
|
269
|
-
person.name.first_name.
|
269
|
+
expect(person.name.first_name).to eq("Lang")
|
270
270
|
end
|
271
271
|
end
|
272
272
|
end
|
@@ -275,13 +275,13 @@ describe Mongoid::NestedAttributes do
|
|
275
275
|
|
276
276
|
context "when the relation is not autobuilding" do
|
277
277
|
|
278
|
-
before
|
278
|
+
before do
|
279
279
|
Person.send(:undef_method, :name_attributes=)
|
280
280
|
Person.accepts_nested_attributes_for \
|
281
281
|
:name, reject_if: :all_blank
|
282
282
|
end
|
283
283
|
|
284
|
-
after
|
284
|
+
after do
|
285
285
|
Person.send(:undef_method, :name_attributes=)
|
286
286
|
Person.accepts_nested_attributes_for :name
|
287
287
|
end
|
@@ -293,7 +293,7 @@ describe Mongoid::NestedAttributes do
|
|
293
293
|
end
|
294
294
|
|
295
295
|
it "does not add the document" do
|
296
|
-
person.name.
|
296
|
+
expect(person.name).to be_nil
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
@@ -304,18 +304,18 @@ describe Mongoid::NestedAttributes do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
it "adds the document" do
|
307
|
-
person.name.first_name.
|
307
|
+
expect(person.name.first_name).to eq("Lang")
|
308
308
|
end
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
312
312
|
context "when the relation is autobuilding" do
|
313
313
|
|
314
|
-
before
|
314
|
+
before do
|
315
315
|
Product.accepts_nested_attributes_for :seo, reject_if: :all_blank
|
316
316
|
end
|
317
317
|
|
318
|
-
after
|
318
|
+
after do
|
319
319
|
Product.send(:undef_method, :seo_attributes=)
|
320
320
|
end
|
321
321
|
|
@@ -326,7 +326,7 @@ describe Mongoid::NestedAttributes do
|
|
326
326
|
end
|
327
327
|
|
328
328
|
it "does not add the document" do
|
329
|
-
product.seo.
|
329
|
+
expect(product.seo).to_not be_persisted
|
330
330
|
end
|
331
331
|
end
|
332
332
|
end
|
@@ -341,7 +341,7 @@ describe Mongoid::NestedAttributes do
|
|
341
341
|
end
|
342
342
|
|
343
343
|
it "builds a new document" do
|
344
|
-
person.name.first_name.
|
344
|
+
expect(person.name.first_name).to eq("Leo")
|
345
345
|
end
|
346
346
|
end
|
347
347
|
|
@@ -349,12 +349,12 @@ describe Mongoid::NestedAttributes do
|
|
349
349
|
|
350
350
|
context "when allow_destroy is true" do
|
351
351
|
|
352
|
-
before
|
352
|
+
before do
|
353
353
|
Person.send(:undef_method, :name_attributes=)
|
354
354
|
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
355
355
|
end
|
356
356
|
|
357
|
-
after
|
357
|
+
after do
|
358
358
|
Person.send(:undef_method, :name_attributes=)
|
359
359
|
Person.accepts_nested_attributes_for :name
|
360
360
|
end
|
@@ -366,7 +366,7 @@ describe Mongoid::NestedAttributes do
|
|
366
366
|
end
|
367
367
|
|
368
368
|
it "does not build the document" do
|
369
|
-
person.name.
|
369
|
+
expect(person.name).to be_nil
|
370
370
|
end
|
371
371
|
end
|
372
372
|
|
@@ -377,19 +377,19 @@ describe Mongoid::NestedAttributes do
|
|
377
377
|
end
|
378
378
|
|
379
379
|
it "does not build the document" do
|
380
|
-
person.name.
|
380
|
+
expect(person.name).to be_nil
|
381
381
|
end
|
382
382
|
end
|
383
383
|
end
|
384
384
|
|
385
385
|
context "when allow_destroy is false" do
|
386
386
|
|
387
|
-
before
|
387
|
+
before do
|
388
388
|
Person.send(:undef_method, :name_attributes=)
|
389
389
|
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
390
390
|
end
|
391
391
|
|
392
|
-
after
|
392
|
+
after do
|
393
393
|
Person.send(:undef_method, :name_attributes=)
|
394
394
|
Person.accepts_nested_attributes_for :name
|
395
395
|
end
|
@@ -399,7 +399,7 @@ describe Mongoid::NestedAttributes do
|
|
399
399
|
end
|
400
400
|
|
401
401
|
it "builds the document" do
|
402
|
-
person.name.first_name.
|
402
|
+
expect(person.name.first_name).to eq("Leo")
|
403
403
|
end
|
404
404
|
end
|
405
405
|
end
|
@@ -411,7 +411,7 @@ describe Mongoid::NestedAttributes do
|
|
411
411
|
end
|
412
412
|
|
413
413
|
it "does not build the document" do
|
414
|
-
person.name.
|
414
|
+
expect(person.name).to be_nil
|
415
415
|
end
|
416
416
|
end
|
417
417
|
|
@@ -425,7 +425,7 @@ describe Mongoid::NestedAttributes do
|
|
425
425
|
end
|
426
426
|
|
427
427
|
it "replaces the document" do
|
428
|
-
person.name.first_name.
|
428
|
+
expect(person.name.first_name).to eq("Jack")
|
429
429
|
end
|
430
430
|
end
|
431
431
|
|
@@ -433,12 +433,12 @@ describe Mongoid::NestedAttributes do
|
|
433
433
|
|
434
434
|
context "when allow_destroy is true" do
|
435
435
|
|
436
|
-
before
|
436
|
+
before do
|
437
437
|
Person.send(:undef_method, :name_attributes=)
|
438
438
|
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
439
439
|
end
|
440
440
|
|
441
|
-
after
|
441
|
+
after do
|
442
442
|
Person.send(:undef_method, :name_attributes=)
|
443
443
|
Person.accepts_nested_attributes_for :name
|
444
444
|
end
|
@@ -449,18 +449,18 @@ describe Mongoid::NestedAttributes do
|
|
449
449
|
end
|
450
450
|
|
451
451
|
it "does not replace the document" do
|
452
|
-
person.name.first_name.
|
452
|
+
expect(person.name.first_name).to eq("Michael")
|
453
453
|
end
|
454
454
|
end
|
455
455
|
|
456
456
|
context "when allow_destroy is false" do
|
457
457
|
|
458
|
-
before
|
458
|
+
before do
|
459
459
|
Person.send(:undef_method, :name_attributes=)
|
460
460
|
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
461
461
|
end
|
462
462
|
|
463
|
-
after
|
463
|
+
after do
|
464
464
|
Person.send(:undef_method, :name_attributes=)
|
465
465
|
Person.accepts_nested_attributes_for :name
|
466
466
|
end
|
@@ -471,7 +471,7 @@ describe Mongoid::NestedAttributes do
|
|
471
471
|
end
|
472
472
|
|
473
473
|
it "replaces the document" do
|
474
|
-
person.name.first_name.
|
474
|
+
expect(person.name.first_name).to eq("Jack")
|
475
475
|
end
|
476
476
|
end
|
477
477
|
end
|
@@ -500,7 +500,7 @@ describe Mongoid::NestedAttributes do
|
|
500
500
|
end
|
501
501
|
|
502
502
|
it "updates the existing document" do
|
503
|
-
person.name.first_name.
|
503
|
+
expect(person.name.first_name).to eq("Bob")
|
504
504
|
end
|
505
505
|
end
|
506
506
|
|
@@ -512,18 +512,18 @@ describe Mongoid::NestedAttributes do
|
|
512
512
|
end
|
513
513
|
|
514
514
|
it "updates the existing document" do
|
515
|
-
person.name.first_name.
|
515
|
+
expect(person.name.first_name).to eq("Bob")
|
516
516
|
end
|
517
517
|
end
|
518
518
|
|
519
519
|
context "when allow_destroy is true" do
|
520
520
|
|
521
|
-
before
|
521
|
+
before do
|
522
522
|
Person.send(:undef_method, :name_attributes=)
|
523
523
|
Person.accepts_nested_attributes_for :name, allow_destroy: true
|
524
524
|
end
|
525
525
|
|
526
|
-
after
|
526
|
+
after do
|
527
527
|
Person.send(:undef_method, :name_attributes=)
|
528
528
|
Person.accepts_nested_attributes_for :name
|
529
529
|
end
|
@@ -540,17 +540,17 @@ describe Mongoid::NestedAttributes do
|
|
540
540
|
end
|
541
541
|
|
542
542
|
it "destroys the existing document" do
|
543
|
-
person.name.
|
543
|
+
expect(person.name).to be_nil
|
544
544
|
end
|
545
545
|
end
|
546
546
|
|
547
547
|
context "when the document has destroy callbacks" do
|
548
548
|
|
549
|
-
before
|
549
|
+
before do
|
550
550
|
PetOwner.accepts_nested_attributes_for :pet, allow_destroy: true
|
551
551
|
end
|
552
552
|
|
553
|
-
after
|
553
|
+
after do
|
554
554
|
PetOwner.send(:undef_method, :pet_attributes=)
|
555
555
|
end
|
556
556
|
|
@@ -568,11 +568,11 @@ describe Mongoid::NestedAttributes do
|
|
568
568
|
end
|
569
569
|
|
570
570
|
it "destroys the existing document" do
|
571
|
-
owner.pet.
|
571
|
+
expect(owner.pet).to be_nil
|
572
572
|
end
|
573
573
|
|
574
574
|
it "runs the destroy callbacks" do
|
575
|
-
pet.destroy_flag.
|
575
|
+
expect(pet.destroy_flag).to be true
|
576
576
|
end
|
577
577
|
end
|
578
578
|
end
|
@@ -588,7 +588,7 @@ describe Mongoid::NestedAttributes do
|
|
588
588
|
end
|
589
589
|
|
590
590
|
it "does not destroy the existing document" do
|
591
|
-
person.name.
|
591
|
+
expect(person.name).to eq(name)
|
592
592
|
end
|
593
593
|
end
|
594
594
|
end
|
@@ -596,12 +596,12 @@ describe Mongoid::NestedAttributes do
|
|
596
596
|
|
597
597
|
context "when allow destroy is false" do
|
598
598
|
|
599
|
-
before
|
599
|
+
before do
|
600
600
|
Person.send(:undef_method, :name_attributes=)
|
601
601
|
Person.accepts_nested_attributes_for :name, allow_destroy: false
|
602
602
|
end
|
603
603
|
|
604
|
-
after
|
604
|
+
after do
|
605
605
|
Person.send(:undef_method, :name_attributes=)
|
606
606
|
Person.accepts_nested_attributes_for :name
|
607
607
|
end
|
@@ -614,14 +614,14 @@ describe Mongoid::NestedAttributes do
|
|
614
614
|
end
|
615
615
|
|
616
616
|
it "does not destroy the document" do
|
617
|
-
person.name.
|
617
|
+
expect(person.name).to eq(name)
|
618
618
|
end
|
619
619
|
end
|
620
620
|
end
|
621
621
|
|
622
622
|
context "when update only is true" do
|
623
623
|
|
624
|
-
before
|
624
|
+
before do
|
625
625
|
Person.send(:undef_method, :name_attributes=)
|
626
626
|
Person.accepts_nested_attributes_for \
|
627
627
|
:name,
|
@@ -629,7 +629,7 @@ describe Mongoid::NestedAttributes do
|
|
629
629
|
allow_destroy: true
|
630
630
|
end
|
631
631
|
|
632
|
-
after
|
632
|
+
after do
|
633
633
|
Person.send(:undef_method, :name_attributes=)
|
634
634
|
Person.accepts_nested_attributes_for :name
|
635
635
|
end
|
@@ -642,7 +642,7 @@ describe Mongoid::NestedAttributes do
|
|
642
642
|
end
|
643
643
|
|
644
644
|
it "updates the existing document" do
|
645
|
-
person.name.first_name.
|
645
|
+
expect(person.name.first_name).to eq("Ro")
|
646
646
|
end
|
647
647
|
end
|
648
648
|
|
@@ -650,11 +650,11 @@ describe Mongoid::NestedAttributes do
|
|
650
650
|
|
651
651
|
before do
|
652
652
|
person.name_attributes =
|
653
|
-
{ id:
|
653
|
+
{ id: BSON::ObjectId.new.to_s, first_name: "Durran" }
|
654
654
|
end
|
655
655
|
|
656
656
|
it "updates the existing document" do
|
657
|
-
person.name.first_name.
|
657
|
+
expect(person.name.first_name).to eq("Durran")
|
658
658
|
end
|
659
659
|
end
|
660
660
|
|
@@ -666,7 +666,7 @@ describe Mongoid::NestedAttributes do
|
|
666
666
|
end
|
667
667
|
|
668
668
|
it "destroys the existing document" do
|
669
|
-
person.name.
|
669
|
+
expect(person.name).to be_nil
|
670
670
|
end
|
671
671
|
end
|
672
672
|
end
|
@@ -684,7 +684,7 @@ describe Mongoid::NestedAttributes do
|
|
684
684
|
end
|
685
685
|
|
686
686
|
it "updates the existing document" do
|
687
|
-
person.quiz.topic.
|
687
|
+
expect(person.quiz.topic).to eq("English")
|
688
688
|
end
|
689
689
|
end
|
690
690
|
end
|
@@ -693,11 +693,11 @@ describe Mongoid::NestedAttributes do
|
|
693
693
|
|
694
694
|
context "when the nested document is invalid" do
|
695
695
|
|
696
|
-
before
|
696
|
+
before do
|
697
697
|
Person.validates_associated(:pet)
|
698
698
|
end
|
699
699
|
|
700
|
-
after
|
700
|
+
after do
|
701
701
|
Person.reset_callbacks(:validate)
|
702
702
|
end
|
703
703
|
|
@@ -706,8 +706,8 @@ describe Mongoid::NestedAttributes do
|
|
706
706
|
end
|
707
707
|
|
708
708
|
it "propagates invalidity to parent" do
|
709
|
-
person.pet.
|
710
|
-
person.
|
709
|
+
expect(person.pet).to_not be_valid
|
710
|
+
expect(person).to_not be_valid
|
711
711
|
end
|
712
712
|
end
|
713
713
|
|
@@ -724,7 +724,7 @@ describe Mongoid::NestedAttributes do
|
|
724
724
|
end
|
725
725
|
|
726
726
|
it "instantiates an object of the given type" do
|
727
|
-
canvas.writer.class.
|
727
|
+
expect(canvas.writer.class).to eq(HtmlWriter)
|
728
728
|
end
|
729
729
|
end
|
730
730
|
end
|
@@ -746,7 +746,7 @@ describe Mongoid::NestedAttributes do
|
|
746
746
|
end
|
747
747
|
|
748
748
|
it "builds a new document" do
|
749
|
-
animal.person.title.
|
749
|
+
expect(animal.person.title).to eq("Sir")
|
750
750
|
end
|
751
751
|
|
752
752
|
end
|
@@ -755,12 +755,12 @@ describe Mongoid::NestedAttributes do
|
|
755
755
|
|
756
756
|
context "when allow_destroy is true" do
|
757
757
|
|
758
|
-
before
|
758
|
+
before do
|
759
759
|
Animal.send(:undef_method, :person_attributes=)
|
760
760
|
Animal.accepts_nested_attributes_for :person, allow_destroy: true
|
761
761
|
end
|
762
762
|
|
763
|
-
after
|
763
|
+
after do
|
764
764
|
Animal.send(:undef_method, :person_attributes=)
|
765
765
|
Animal.accepts_nested_attributes_for :person
|
766
766
|
end
|
@@ -770,18 +770,18 @@ describe Mongoid::NestedAttributes do
|
|
770
770
|
end
|
771
771
|
|
772
772
|
it "does not build a new document" do
|
773
|
-
animal.person.
|
773
|
+
expect(animal.person).to be_nil
|
774
774
|
end
|
775
775
|
end
|
776
776
|
|
777
777
|
context "when allow_destroy is false" do
|
778
778
|
|
779
|
-
before
|
779
|
+
before do
|
780
780
|
Animal.send(:undef_method, :person_attributes=)
|
781
781
|
Animal.accepts_nested_attributes_for :person, allow_destroy: false
|
782
782
|
end
|
783
783
|
|
784
|
-
after
|
784
|
+
after do
|
785
785
|
Animal.send(:undef_method, :person_attributes=)
|
786
786
|
Animal.accepts_nested_attributes_for :person
|
787
787
|
end
|
@@ -791,7 +791,7 @@ describe Mongoid::NestedAttributes do
|
|
791
791
|
end
|
792
792
|
|
793
793
|
it "builds a new document" do
|
794
|
-
animal.person.title.
|
794
|
+
expect(animal.person.title).to eq("Sir")
|
795
795
|
end
|
796
796
|
end
|
797
797
|
end
|
@@ -812,7 +812,7 @@ describe Mongoid::NestedAttributes do
|
|
812
812
|
end
|
813
813
|
|
814
814
|
it "updates the existing document" do
|
815
|
-
animal.person.title.
|
815
|
+
expect(animal.person.title).to eq("Sir")
|
816
816
|
end
|
817
817
|
end
|
818
818
|
end
|
@@ -825,12 +825,12 @@ describe Mongoid::NestedAttributes do
|
|
825
825
|
|
826
826
|
context "when allow destroy is true" do
|
827
827
|
|
828
|
-
before
|
828
|
+
before do
|
829
829
|
Animal.send(:undef_method, :person_attributes=)
|
830
830
|
Animal.accepts_nested_attributes_for :person, allow_destroy: true
|
831
831
|
end
|
832
832
|
|
833
|
-
after
|
833
|
+
after do
|
834
834
|
Animal.send(:undef_method, :person_attributes=)
|
835
835
|
Animal.accepts_nested_attributes_for :person
|
836
836
|
end
|
@@ -845,7 +845,7 @@ describe Mongoid::NestedAttributes do
|
|
845
845
|
end
|
846
846
|
|
847
847
|
it "destroys the existing document" do
|
848
|
-
animal.person.
|
848
|
+
expect(animal.person).to be_nil
|
849
849
|
end
|
850
850
|
end
|
851
851
|
end
|
@@ -860,7 +860,7 @@ describe Mongoid::NestedAttributes do
|
|
860
860
|
end
|
861
861
|
|
862
862
|
it "does not destroy the existing document" do
|
863
|
-
animal.person.
|
863
|
+
expect(animal.person).to eq(person)
|
864
864
|
end
|
865
865
|
end
|
866
866
|
end
|
@@ -868,12 +868,12 @@ describe Mongoid::NestedAttributes do
|
|
868
868
|
|
869
869
|
context "when allow destroy is false" do
|
870
870
|
|
871
|
-
before
|
871
|
+
before do
|
872
872
|
Animal.send(:undef_method, :person_attributes=)
|
873
873
|
Animal.accepts_nested_attributes_for :person, allow_destroy: false
|
874
874
|
end
|
875
875
|
|
876
|
-
after
|
876
|
+
after do
|
877
877
|
Animal.send(:undef_method, :person_attributes=)
|
878
878
|
Animal.accepts_nested_attributes_for :person
|
879
879
|
end
|
@@ -886,7 +886,7 @@ describe Mongoid::NestedAttributes do
|
|
886
886
|
end
|
887
887
|
|
888
888
|
it "does not delete the document" do
|
889
|
-
animal.person.
|
889
|
+
expect(animal.person).to eq(person)
|
890
890
|
end
|
891
891
|
end
|
892
892
|
end
|
@@ -909,7 +909,7 @@ describe Mongoid::NestedAttributes do
|
|
909
909
|
end
|
910
910
|
|
911
911
|
it "updates the existing document" do
|
912
|
-
animal.person.title.
|
912
|
+
expect(animal.person.title).to eq("Madam")
|
913
913
|
end
|
914
914
|
end
|
915
915
|
|
@@ -917,11 +917,11 @@ describe Mongoid::NestedAttributes do
|
|
917
917
|
|
918
918
|
before do
|
919
919
|
animal.person_attributes =
|
920
|
-
{ id:
|
920
|
+
{ id: BSON::ObjectId.new.to_s, title: "Madam" }
|
921
921
|
end
|
922
922
|
|
923
923
|
it "updates the existing document" do
|
924
|
-
animal.person.title.
|
924
|
+
expect(animal.person.title).to eq("Madam")
|
925
925
|
end
|
926
926
|
end
|
927
927
|
|
@@ -933,7 +933,7 @@ describe Mongoid::NestedAttributes do
|
|
933
933
|
end
|
934
934
|
|
935
935
|
it "deletes the existing document" do
|
936
|
-
animal.person.
|
936
|
+
expect(animal.person).to be_nil
|
937
937
|
end
|
938
938
|
end
|
939
939
|
end
|
@@ -942,11 +942,11 @@ describe Mongoid::NestedAttributes do
|
|
942
942
|
|
943
943
|
context "when the nested document is invalid" do
|
944
944
|
|
945
|
-
before
|
945
|
+
before do
|
946
946
|
Person.validates_format_of :ssn, without: /\$\$\$/
|
947
947
|
end
|
948
948
|
|
949
|
-
after
|
949
|
+
after do
|
950
950
|
Person.reset_callbacks(:validate)
|
951
951
|
end
|
952
952
|
|
@@ -955,8 +955,8 @@ describe Mongoid::NestedAttributes do
|
|
955
955
|
end
|
956
956
|
|
957
957
|
it "does not propagate invalidity to parent" do
|
958
|
-
animal.person.
|
959
|
-
animal.
|
958
|
+
expect(animal.person).to_not be_valid
|
959
|
+
expect(animal).to be_valid
|
960
960
|
end
|
961
961
|
end
|
962
962
|
end
|
@@ -972,7 +972,7 @@ describe Mongoid::NestedAttributes do
|
|
972
972
|
end
|
973
973
|
|
974
974
|
it "instantiates an object of the given type" do
|
975
|
-
tool.palette.class.
|
975
|
+
expect(tool.palette.class).to eq(BigPalette)
|
976
976
|
end
|
977
977
|
end
|
978
978
|
end
|
@@ -1006,11 +1006,11 @@ describe Mongoid::NestedAttributes do
|
|
1006
1006
|
end
|
1007
1007
|
|
1008
1008
|
it "sets the child documents" do
|
1009
|
-
person.addresses.first.street.
|
1009
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
1010
1010
|
end
|
1011
1011
|
|
1012
1012
|
it "does not persist the child documents" do
|
1013
|
-
person.addresses.first.
|
1013
|
+
expect(person.addresses.first).to_not be_persisted
|
1014
1014
|
end
|
1015
1015
|
|
1016
1016
|
context "when saving the parent" do
|
@@ -1021,7 +1021,7 @@ describe Mongoid::NestedAttributes do
|
|
1021
1021
|
end
|
1022
1022
|
|
1023
1023
|
it "saves the child documents" do
|
1024
|
-
person.addresses.first.
|
1024
|
+
expect(person.addresses.first).to be_persisted
|
1025
1025
|
end
|
1026
1026
|
end
|
1027
1027
|
end
|
@@ -1039,22 +1039,14 @@ describe Mongoid::NestedAttributes do
|
|
1039
1039
|
Address.new(street: "Kurfeurstendamm")
|
1040
1040
|
end
|
1041
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
1042
|
context "when a limit is specified" do
|
1051
1043
|
|
1052
|
-
before
|
1044
|
+
before do
|
1053
1045
|
Person.send(:undef_method, :addresses_attributes=)
|
1054
1046
|
Person.accepts_nested_attributes_for :addresses, limit: 2
|
1055
1047
|
end
|
1056
1048
|
|
1057
|
-
after
|
1049
|
+
after do
|
1058
1050
|
Person.send(:undef_method, :addresses_attributes=)
|
1059
1051
|
Person.accepts_nested_attributes_for :addresses
|
1060
1052
|
end
|
@@ -1090,7 +1082,7 @@ describe Mongoid::NestedAttributes do
|
|
1090
1082
|
end
|
1091
1083
|
|
1092
1084
|
it "sets the documents on the relation" do
|
1093
|
-
person.addresses.size.
|
1085
|
+
expect(person.addresses.size).to eq(2)
|
1094
1086
|
end
|
1095
1087
|
end
|
1096
1088
|
|
@@ -1108,17 +1100,17 @@ describe Mongoid::NestedAttributes do
|
|
1108
1100
|
end
|
1109
1101
|
|
1110
1102
|
it "sets the documents on the relation" do
|
1111
|
-
person.addresses.size.
|
1103
|
+
expect(person.addresses.size).to eq(2)
|
1112
1104
|
end
|
1113
1105
|
end
|
1114
1106
|
|
1115
1107
|
context "when cascading callbacks" do
|
1116
1108
|
|
1117
|
-
before
|
1109
|
+
before do
|
1118
1110
|
Band.accepts_nested_attributes_for :records
|
1119
1111
|
end
|
1120
1112
|
|
1121
|
-
after
|
1113
|
+
after do
|
1122
1114
|
Band.send(:undef_method, :records_attributes=)
|
1123
1115
|
end
|
1124
1116
|
|
@@ -1144,11 +1136,11 @@ describe Mongoid::NestedAttributes do
|
|
1144
1136
|
end
|
1145
1137
|
|
1146
1138
|
it "runs the first child create callbacks" do
|
1147
|
-
band.records.first.before_create_called.
|
1139
|
+
expect(band.records.first.before_create_called).to be true
|
1148
1140
|
end
|
1149
1141
|
|
1150
1142
|
it "runs the last child create callbacks" do
|
1151
|
-
band.records.last.before_create_called.
|
1143
|
+
expect(band.records.last.before_create_called).to be true
|
1152
1144
|
end
|
1153
1145
|
end
|
1154
1146
|
end
|
@@ -1173,15 +1165,15 @@ describe Mongoid::NestedAttributes do
|
|
1173
1165
|
end
|
1174
1166
|
|
1175
1167
|
it "updates the first existing document" do
|
1176
|
-
person.addresses.first.street.
|
1168
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
1177
1169
|
end
|
1178
1170
|
|
1179
1171
|
it "updates the second existing document" do
|
1180
|
-
person.addresses.second.street.
|
1172
|
+
expect(person.addresses.second.street).to eq("Alexander Platz")
|
1181
1173
|
end
|
1182
1174
|
|
1183
1175
|
it "does not add new documents" do
|
1184
|
-
person.addresses.size.
|
1176
|
+
expect(person.addresses.size).to eq(2)
|
1185
1177
|
end
|
1186
1178
|
end
|
1187
1179
|
|
@@ -1198,15 +1190,15 @@ describe Mongoid::NestedAttributes do
|
|
1198
1190
|
end
|
1199
1191
|
|
1200
1192
|
it "updates the first existing document" do
|
1201
|
-
person.addresses.collect { |a| a['street'] }.
|
1193
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Maybachufer')
|
1202
1194
|
end
|
1203
1195
|
|
1204
1196
|
it "updates the second existing document" do
|
1205
|
-
person.addresses.collect { |a| a['street'] }.
|
1197
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Alexander Platz')
|
1206
1198
|
end
|
1207
1199
|
|
1208
1200
|
it "does not add new documents" do
|
1209
|
-
person.addresses.size.
|
1201
|
+
expect(person.addresses.size).to eq(2)
|
1210
1202
|
end
|
1211
1203
|
end
|
1212
1204
|
|
@@ -1221,15 +1213,15 @@ describe Mongoid::NestedAttributes do
|
|
1221
1213
|
end
|
1222
1214
|
|
1223
1215
|
it "updates the first existing document" do
|
1224
|
-
person.addresses.collect { |a| a['street'] }.
|
1216
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Maybachufer')
|
1225
1217
|
end
|
1226
1218
|
|
1227
1219
|
it "updates the second existing document" do
|
1228
|
-
person.addresses.collect { |a| a['street'] }.
|
1220
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Alexander Platz')
|
1229
1221
|
end
|
1230
1222
|
|
1231
1223
|
it "does not add new documents" do
|
1232
|
-
person.addresses.size.
|
1224
|
+
expect(person.addresses.size).to eq(2)
|
1233
1225
|
end
|
1234
1226
|
end
|
1235
1227
|
end
|
@@ -1245,15 +1237,15 @@ describe Mongoid::NestedAttributes do
|
|
1245
1237
|
end
|
1246
1238
|
|
1247
1239
|
it "updates the first existing document" do
|
1248
|
-
person.addresses.collect { |a| a['street'] }.
|
1240
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Maybachufer')
|
1249
1241
|
end
|
1250
1242
|
|
1251
1243
|
it "updates the second existing document" do
|
1252
|
-
person.addresses.collect { |a| a['street'] }.
|
1244
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Alexander Platz')
|
1253
1245
|
end
|
1254
1246
|
|
1255
1247
|
it "does not add new documents" do
|
1256
|
-
person.addresses.size.
|
1248
|
+
expect(person.addresses.size).to eq(2)
|
1257
1249
|
end
|
1258
1250
|
end
|
1259
1251
|
|
@@ -1268,15 +1260,15 @@ describe Mongoid::NestedAttributes do
|
|
1268
1260
|
end
|
1269
1261
|
|
1270
1262
|
it "updates the first existing document" do
|
1271
|
-
person.addresses.collect { |a| a['street'] }.
|
1263
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Maybachufer')
|
1272
1264
|
end
|
1273
1265
|
|
1274
1266
|
it "updates the second existing document" do
|
1275
|
-
person.addresses.collect { |a| a['street'] }.
|
1267
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Alexander Platz')
|
1276
1268
|
end
|
1277
1269
|
|
1278
1270
|
it "does not add new documents" do
|
1279
|
-
person.addresses.size.
|
1271
|
+
expect(person.addresses.size).to eq(2)
|
1280
1272
|
end
|
1281
1273
|
end
|
1282
1274
|
|
@@ -1291,15 +1283,15 @@ describe Mongoid::NestedAttributes do
|
|
1291
1283
|
end
|
1292
1284
|
|
1293
1285
|
it "updates the first existing document" do
|
1294
|
-
person.addresses.collect { |a| a['street'] }.
|
1286
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Maybachufer')
|
1295
1287
|
end
|
1296
1288
|
|
1297
1289
|
it "updates the second existing document" do
|
1298
|
-
person.addresses.collect { |a| a['street'] }.
|
1290
|
+
expect(person.addresses.collect { |a| a['street'] }).to include('Alexander Platz')
|
1299
1291
|
end
|
1300
1292
|
|
1301
1293
|
it "does not add new documents" do
|
1302
|
-
person.addresses.size.
|
1294
|
+
expect(person.addresses.size).to eq(2)
|
1303
1295
|
end
|
1304
1296
|
end
|
1305
1297
|
|
@@ -1322,18 +1314,13 @@ describe Mongoid::NestedAttributes do
|
|
1322
1314
|
|
1323
1315
|
context "when the parent validation failed" do
|
1324
1316
|
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
end
|
1329
|
-
|
1330
|
-
after(:all) do
|
1331
|
-
Band.send(:undef_method, :records_attributes=)
|
1332
|
-
Band.reset_callbacks(:validate)
|
1317
|
+
class BandWithAllowDestroyedRecords < Band
|
1318
|
+
validates_presence_of :name
|
1319
|
+
accepts_nested_attributes_for :records, :allow_destroy => true
|
1333
1320
|
end
|
1334
1321
|
|
1335
1322
|
let!(:band) do
|
1336
|
-
|
1323
|
+
BandWithAllowDestroyedRecords.create(name: "Depeche Mode")
|
1337
1324
|
end
|
1338
1325
|
|
1339
1326
|
let!(:record) do
|
@@ -1352,25 +1339,25 @@ describe Mongoid::NestedAttributes do
|
|
1352
1339
|
end
|
1353
1340
|
|
1354
1341
|
it "does not remove the child document" do
|
1355
|
-
band.records.
|
1342
|
+
expect(band.records).to_not be_empty
|
1356
1343
|
end
|
1357
1344
|
|
1358
1345
|
it "keeps the child flagged for destruction" do
|
1359
|
-
record.
|
1346
|
+
expect(record).to be_flagged_for_destroy
|
1360
1347
|
end
|
1361
1348
|
|
1362
1349
|
it "does not persist any change" do
|
1363
|
-
band.reload.records.
|
1350
|
+
expect(band.reload.records).to eq([ record ])
|
1364
1351
|
end
|
1365
1352
|
end
|
1366
1353
|
|
1367
1354
|
context "when the child accesses the parent after destroy" do
|
1368
1355
|
|
1369
|
-
before
|
1356
|
+
before do
|
1370
1357
|
Band.accepts_nested_attributes_for :records, :allow_destroy => true
|
1371
1358
|
end
|
1372
1359
|
|
1373
|
-
after
|
1360
|
+
after do
|
1374
1361
|
Band.send(:undef_method, :records_attributes=)
|
1375
1362
|
end
|
1376
1363
|
|
@@ -1389,21 +1376,21 @@ describe Mongoid::NestedAttributes do
|
|
1389
1376
|
end
|
1390
1377
|
|
1391
1378
|
it "deletes the child document" do
|
1392
|
-
band.records.
|
1379
|
+
expect(band.records).to be_empty
|
1393
1380
|
end
|
1394
1381
|
|
1395
1382
|
it "persists the changes" do
|
1396
|
-
band.reload.records.
|
1383
|
+
expect(band.reload.records).to be_empty
|
1397
1384
|
end
|
1398
1385
|
end
|
1399
1386
|
|
1400
1387
|
context "when the child has defaults" do
|
1401
1388
|
|
1402
|
-
before
|
1389
|
+
before do
|
1403
1390
|
Person.accepts_nested_attributes_for :appointments, allow_destroy: true
|
1404
1391
|
end
|
1405
1392
|
|
1406
|
-
after
|
1393
|
+
after do
|
1407
1394
|
Person.send(:undef_method, :appointments_attributes=)
|
1408
1395
|
end
|
1409
1396
|
|
@@ -1415,31 +1402,6 @@ describe Mongoid::NestedAttributes do
|
|
1415
1402
|
|
1416
1403
|
context "when the child returns false in a before callback" do
|
1417
1404
|
|
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
1405
|
context "when the child is not paranoid" do
|
1444
1406
|
|
1445
1407
|
let(:actor) do
|
@@ -1457,7 +1419,7 @@ describe Mongoid::NestedAttributes do
|
|
1457
1419
|
end
|
1458
1420
|
|
1459
1421
|
it "does not destroy the child" do
|
1460
|
-
actor.reload.things.
|
1422
|
+
expect(actor.reload.things).to_not be_empty
|
1461
1423
|
end
|
1462
1424
|
end
|
1463
1425
|
end
|
@@ -1490,11 +1452,11 @@ describe Mongoid::NestedAttributes do
|
|
1490
1452
|
end
|
1491
1453
|
|
1492
1454
|
it "destroys both children" do
|
1493
|
-
from_db.appointments.
|
1455
|
+
expect(from_db.appointments).to be_empty
|
1494
1456
|
end
|
1495
1457
|
|
1496
1458
|
it "persists the deletes" do
|
1497
|
-
from_db.reload.appointments.
|
1459
|
+
expect(from_db.reload.appointments).to be_empty
|
1498
1460
|
end
|
1499
1461
|
end
|
1500
1462
|
end
|
@@ -1503,12 +1465,12 @@ describe Mongoid::NestedAttributes do
|
|
1503
1465
|
|
1504
1466
|
context "when the child is not paranoid" do
|
1505
1467
|
|
1506
|
-
before
|
1468
|
+
before do
|
1507
1469
|
Person.send(:undef_method, :addresses_attributes=)
|
1508
1470
|
Person.accepts_nested_attributes_for :addresses, allow_destroy: true
|
1509
1471
|
end
|
1510
1472
|
|
1511
|
-
after
|
1473
|
+
after do
|
1512
1474
|
Person.send(:undef_method, :addresses_attributes=)
|
1513
1475
|
Person.accepts_nested_attributes_for :addresses
|
1514
1476
|
end
|
@@ -1530,11 +1492,11 @@ describe Mongoid::NestedAttributes do
|
|
1530
1492
|
end
|
1531
1493
|
|
1532
1494
|
it "deletes the marked document" do
|
1533
|
-
person.addresses.size.
|
1495
|
+
expect(person.addresses.size).to eq(1)
|
1534
1496
|
end
|
1535
1497
|
|
1536
1498
|
it "does not delete the unmarked document" do
|
1537
|
-
person.addresses.first.street.
|
1499
|
+
expect(person.addresses.first.street).to eq("Alexander Platz")
|
1538
1500
|
end
|
1539
1501
|
end
|
1540
1502
|
|
@@ -1549,11 +1511,11 @@ describe Mongoid::NestedAttributes do
|
|
1549
1511
|
end
|
1550
1512
|
|
1551
1513
|
it "deletes the marked document" do
|
1552
|
-
person.addresses.size.
|
1514
|
+
expect(person.addresses.size).to eq(1)
|
1553
1515
|
end
|
1554
1516
|
|
1555
1517
|
it "does not delete the unmarked document" do
|
1556
|
-
person.addresses.first.street.
|
1518
|
+
expect(person.addresses.first.street).to eq("Alexander Platz")
|
1557
1519
|
end
|
1558
1520
|
end
|
1559
1521
|
end
|
@@ -1578,51 +1540,51 @@ describe Mongoid::NestedAttributes do
|
|
1578
1540
|
end
|
1579
1541
|
|
1580
1542
|
it "does not remove the first document from the relation" do
|
1581
|
-
persisted.addresses.size.
|
1543
|
+
expect(persisted.addresses.size).to eq(3)
|
1582
1544
|
end
|
1583
1545
|
|
1584
1546
|
it "flags the destroyed document for removal" do
|
1585
|
-
address_one.
|
1547
|
+
expect(address_one).to be_marked_for_destruction
|
1586
1548
|
end
|
1587
1549
|
|
1588
1550
|
it "does not delete the unmarked document" do
|
1589
|
-
persisted.addresses.second.street.
|
1551
|
+
expect(persisted.addresses.second.street).to eq(
|
1590
1552
|
"Alexander Platz"
|
1591
1553
|
)
|
1592
1554
|
end
|
1593
1555
|
|
1594
1556
|
it "adds the new document to the relation" do
|
1595
|
-
persisted.addresses.last.street.
|
1557
|
+
expect(persisted.addresses.last.street).to eq(
|
1596
1558
|
"Potsdammer Platz"
|
1597
1559
|
)
|
1598
1560
|
end
|
1599
1561
|
|
1600
1562
|
it "has the proper persisted count" do
|
1601
|
-
persisted.addresses.count.
|
1563
|
+
expect(persisted.addresses.count).to eq(2)
|
1602
1564
|
end
|
1603
1565
|
|
1604
1566
|
it "does not delete the removed document" do
|
1605
|
-
address_one.
|
1567
|
+
expect(address_one).to_not be_destroyed
|
1606
1568
|
end
|
1607
1569
|
|
1608
1570
|
context "when saving the parent" do
|
1609
1571
|
|
1610
1572
|
before do
|
1611
|
-
persisted.
|
1573
|
+
persisted.save
|
1612
1574
|
end
|
1613
1575
|
|
1614
1576
|
it "deletes the marked document from the relation" do
|
1615
|
-
persisted.reload.addresses.count.
|
1577
|
+
expect(persisted.reload.addresses.count).to eq(2)
|
1616
1578
|
end
|
1617
1579
|
|
1618
1580
|
it "does not delete the unmarked document" do
|
1619
|
-
persisted.reload.addresses.first.street.
|
1581
|
+
expect(persisted.reload.addresses.first.street).to eq(
|
1620
1582
|
"Alexander Platz"
|
1621
1583
|
)
|
1622
1584
|
end
|
1623
1585
|
|
1624
1586
|
it "persists the new document to the relation" do
|
1625
|
-
persisted.reload.addresses.last.street.
|
1587
|
+
expect(persisted.reload.addresses.last.street).to eq(
|
1626
1588
|
"Potsdammer Platz"
|
1627
1589
|
)
|
1628
1590
|
end
|
@@ -1640,39 +1602,39 @@ describe Mongoid::NestedAttributes do
|
|
1640
1602
|
end
|
1641
1603
|
|
1642
1604
|
it "does not remove the first document from the relation" do
|
1643
|
-
persisted.addresses.size.
|
1605
|
+
expect(persisted.addresses.size).to eq(3)
|
1644
1606
|
end
|
1645
1607
|
|
1646
1608
|
it "marks the first document for destruction" do
|
1647
|
-
address_one.
|
1609
|
+
expect(address_one).to be_marked_for_destruction
|
1648
1610
|
end
|
1649
1611
|
|
1650
1612
|
it "adds the new document to the relation" do
|
1651
|
-
persisted.addresses.last.street.
|
1613
|
+
expect(persisted.addresses.last.street).to eq(
|
1652
1614
|
"Potsdammer Platz"
|
1653
1615
|
)
|
1654
1616
|
end
|
1655
1617
|
|
1656
1618
|
it "has the proper persisted count" do
|
1657
|
-
persisted.addresses.count.
|
1619
|
+
expect(persisted.addresses.count).to eq(2)
|
1658
1620
|
end
|
1659
1621
|
|
1660
1622
|
it "does not delete the removed document" do
|
1661
|
-
address_one.
|
1623
|
+
expect(address_one).to_not be_destroyed
|
1662
1624
|
end
|
1663
1625
|
|
1664
1626
|
context "when saving the parent" do
|
1665
1627
|
|
1666
1628
|
before do
|
1667
|
-
persisted.
|
1629
|
+
persisted.save
|
1668
1630
|
end
|
1669
1631
|
|
1670
1632
|
it "deletes the marked document from the relation" do
|
1671
|
-
persisted.reload.addresses.count.
|
1633
|
+
expect(persisted.reload.addresses.count).to eq(2)
|
1672
1634
|
end
|
1673
1635
|
|
1674
1636
|
it "persists the new document to the relation" do
|
1675
|
-
persisted.reload.addresses.last.street.
|
1637
|
+
expect(persisted.reload.addresses.last.street).to eq(
|
1676
1638
|
"Potsdammer Platz"
|
1677
1639
|
)
|
1678
1640
|
end
|
@@ -1695,91 +1657,11 @@ describe Mongoid::NestedAttributes do
|
|
1695
1657
|
end
|
1696
1658
|
|
1697
1659
|
it "does not delete the marked document" do
|
1698
|
-
person.addresses.size.
|
1660
|
+
expect(person.addresses.size).to eq(2)
|
1699
1661
|
end
|
1700
1662
|
|
1701
1663
|
it "does not delete the unmarked document" do
|
1702
|
-
person.addresses.last.street.
|
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
|
1664
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
1783
1665
|
end
|
1784
1666
|
end
|
1785
1667
|
end
|
@@ -1788,12 +1670,12 @@ describe Mongoid::NestedAttributes do
|
|
1788
1670
|
|
1789
1671
|
context "when allow_destroy is false" do
|
1790
1672
|
|
1791
|
-
before
|
1673
|
+
before do
|
1792
1674
|
Person.send(:undef_method, :addresses_attributes=)
|
1793
1675
|
Person.accepts_nested_attributes_for :addresses, allow_destroy: false
|
1794
1676
|
end
|
1795
1677
|
|
1796
|
-
after
|
1678
|
+
after do
|
1797
1679
|
Person.send(:undef_method, :addresses_attributes=)
|
1798
1680
|
Person.accepts_nested_attributes_for :addresses
|
1799
1681
|
end
|
@@ -1812,15 +1694,15 @@ describe Mongoid::NestedAttributes do
|
|
1812
1694
|
end
|
1813
1695
|
|
1814
1696
|
it "does not ignore the marked document" do
|
1815
|
-
person.addresses.first.street.
|
1697
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
1816
1698
|
end
|
1817
1699
|
|
1818
1700
|
it "does not delete the unmarked document" do
|
1819
|
-
person.addresses.last.street.
|
1701
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
1820
1702
|
end
|
1821
1703
|
|
1822
1704
|
it "does not add additional documents" do
|
1823
|
-
person.addresses.size.
|
1705
|
+
expect(person.addresses.size).to eq(2)
|
1824
1706
|
end
|
1825
1707
|
end
|
1826
1708
|
end
|
@@ -1838,11 +1720,11 @@ describe Mongoid::NestedAttributes do
|
|
1838
1720
|
end
|
1839
1721
|
|
1840
1722
|
it "does not delete the marked document" do
|
1841
|
-
person.addresses.size.
|
1723
|
+
expect(person.addresses.size).to eq(2)
|
1842
1724
|
end
|
1843
1725
|
|
1844
1726
|
it "does not delete the unmarked document" do
|
1845
|
-
person.addresses.last.street.
|
1727
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
1846
1728
|
end
|
1847
1729
|
end
|
1848
1730
|
end
|
@@ -1850,7 +1732,7 @@ describe Mongoid::NestedAttributes do
|
|
1850
1732
|
|
1851
1733
|
context "when allow_destroy is undefined" do
|
1852
1734
|
|
1853
|
-
before
|
1735
|
+
before do
|
1854
1736
|
Person.send(:undef_method, :addresses_attributes=)
|
1855
1737
|
Person.accepts_nested_attributes_for :addresses
|
1856
1738
|
end
|
@@ -1869,15 +1751,15 @@ describe Mongoid::NestedAttributes do
|
|
1869
1751
|
end
|
1870
1752
|
|
1871
1753
|
it "does not ignore the marked document" do
|
1872
|
-
person.addresses.first.street.
|
1754
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
1873
1755
|
end
|
1874
1756
|
|
1875
1757
|
it "does not delete the unmarked document" do
|
1876
|
-
person.addresses.last.street.
|
1758
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
1877
1759
|
end
|
1878
1760
|
|
1879
1761
|
it "does not add additional documents" do
|
1880
|
-
person.addresses.size.
|
1762
|
+
expect(person.addresses.size).to eq(2)
|
1881
1763
|
end
|
1882
1764
|
end
|
1883
1765
|
end
|
@@ -1895,11 +1777,11 @@ describe Mongoid::NestedAttributes do
|
|
1895
1777
|
end
|
1896
1778
|
|
1897
1779
|
it "does not delete the marked document" do
|
1898
|
-
person.addresses.size.
|
1780
|
+
expect(person.addresses.size).to eq(2)
|
1899
1781
|
end
|
1900
1782
|
|
1901
1783
|
it "does not delete the unmarked document" do
|
1902
|
-
person.addresses.last.street.
|
1784
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
1903
1785
|
end
|
1904
1786
|
end
|
1905
1787
|
end
|
@@ -1922,23 +1804,23 @@ describe Mongoid::NestedAttributes do
|
|
1922
1804
|
end
|
1923
1805
|
|
1924
1806
|
it "builds a new first document" do
|
1925
|
-
person.addresses.first.street.
|
1807
|
+
expect(person.addresses.first.street).to eq("Frederichstrasse")
|
1926
1808
|
end
|
1927
1809
|
|
1928
1810
|
it "builds a new second document" do
|
1929
|
-
person.addresses.second.street.
|
1811
|
+
expect(person.addresses.second.street).to eq("Alexander Platz")
|
1930
1812
|
end
|
1931
1813
|
|
1932
1814
|
it "builds a new third document" do
|
1933
|
-
person.addresses.third.street.
|
1815
|
+
expect(person.addresses.third.street).to eq("Maybachufer")
|
1934
1816
|
end
|
1935
1817
|
|
1936
1818
|
it "does not add extra documents" do
|
1937
|
-
person.addresses.size.
|
1819
|
+
expect(person.addresses.size).to eq(3)
|
1938
1820
|
end
|
1939
1821
|
|
1940
1822
|
it "adds the documents in the sorted hash key order" do
|
1941
|
-
person.addresses.map(&:street).
|
1823
|
+
expect(person.addresses.map(&:street)).to eq(
|
1942
1824
|
[ "Frederichstrasse", "Alexander Platz", "Maybachufer" ]
|
1943
1825
|
)
|
1944
1826
|
end
|
@@ -1946,13 +1828,13 @@ describe Mongoid::NestedAttributes do
|
|
1946
1828
|
|
1947
1829
|
context "when a reject block is supplied" do
|
1948
1830
|
|
1949
|
-
before
|
1831
|
+
before do
|
1950
1832
|
Person.send(:undef_method, :addresses_attributes=)
|
1951
1833
|
Person.accepts_nested_attributes_for \
|
1952
1834
|
:addresses, reject_if: ->(attrs){ attrs["street"].blank? }
|
1953
1835
|
end
|
1954
1836
|
|
1955
|
-
after
|
1837
|
+
after do
|
1956
1838
|
Person.send(:undef_method, :addresses_attributes=)
|
1957
1839
|
Person.accepts_nested_attributes_for :addresses
|
1958
1840
|
end
|
@@ -1965,7 +1847,7 @@ describe Mongoid::NestedAttributes do
|
|
1965
1847
|
end
|
1966
1848
|
|
1967
1849
|
it "does not add the new document" do
|
1968
|
-
person.addresses.
|
1850
|
+
expect(person.addresses).to be_empty
|
1969
1851
|
end
|
1970
1852
|
end
|
1971
1853
|
|
@@ -1977,24 +1859,24 @@ describe Mongoid::NestedAttributes do
|
|
1977
1859
|
end
|
1978
1860
|
|
1979
1861
|
it "adds the new document" do
|
1980
|
-
person.addresses.size.
|
1862
|
+
expect(person.addresses.size).to eq(1)
|
1981
1863
|
end
|
1982
1864
|
|
1983
1865
|
it "sets the correct attributes" do
|
1984
|
-
person.addresses.first.street.
|
1866
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
1985
1867
|
end
|
1986
1868
|
end
|
1987
1869
|
end
|
1988
1870
|
|
1989
1871
|
context "when :reject_if => :all_blank is supplied" do
|
1990
1872
|
|
1991
|
-
before
|
1873
|
+
before do
|
1992
1874
|
Person.send(:undef_method, :addresses_attributes=)
|
1993
1875
|
Person.accepts_nested_attributes_for \
|
1994
1876
|
:addresses, reject_if: :all_blank
|
1995
1877
|
end
|
1996
1878
|
|
1997
|
-
after
|
1879
|
+
after do
|
1998
1880
|
Person.send(:undef_method, :addresses_attributes=)
|
1999
1881
|
Person.accepts_nested_attributes_for :addresses
|
2000
1882
|
end
|
@@ -2007,7 +1889,7 @@ describe Mongoid::NestedAttributes do
|
|
2007
1889
|
end
|
2008
1890
|
|
2009
1891
|
it "does not add the new document" do
|
2010
|
-
person.addresses.
|
1892
|
+
expect(person.addresses).to be_empty
|
2011
1893
|
end
|
2012
1894
|
end
|
2013
1895
|
|
@@ -2019,11 +1901,11 @@ describe Mongoid::NestedAttributes do
|
|
2019
1901
|
end
|
2020
1902
|
|
2021
1903
|
it "adds the new document" do
|
2022
|
-
person.addresses.size.
|
1904
|
+
expect(person.addresses.size).to eq(1)
|
2023
1905
|
end
|
2024
1906
|
|
2025
1907
|
it "sets the correct attributes" do
|
2026
|
-
person.addresses.first.street.
|
1908
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2027
1909
|
end
|
2028
1910
|
end
|
2029
1911
|
end
|
@@ -2032,12 +1914,12 @@ describe Mongoid::NestedAttributes do
|
|
2032
1914
|
|
2033
1915
|
context "when allow_destroy is true" do
|
2034
1916
|
|
2035
|
-
before
|
1917
|
+
before do
|
2036
1918
|
Person.send(:undef_method, :addresses_attributes=)
|
2037
1919
|
Person.accepts_nested_attributes_for :addresses, allow_destroy: true
|
2038
1920
|
end
|
2039
1921
|
|
2040
|
-
after
|
1922
|
+
after do
|
2041
1923
|
Person.send(:undef_method, :addresses_attributes=)
|
2042
1924
|
Person.accepts_nested_attributes_for :addresses
|
2043
1925
|
end
|
@@ -2055,11 +1937,11 @@ describe Mongoid::NestedAttributes do
|
|
2055
1937
|
end
|
2056
1938
|
|
2057
1939
|
it "ignores the the marked document" do
|
2058
|
-
person.addresses.size.
|
1940
|
+
expect(person.addresses.size).to eq(1)
|
2059
1941
|
end
|
2060
1942
|
|
2061
1943
|
it "adds the new unmarked document" do
|
2062
|
-
person.addresses.first.street.
|
1944
|
+
expect(person.addresses.first.street).to eq("Alexander Platz")
|
2063
1945
|
end
|
2064
1946
|
end
|
2065
1947
|
end
|
@@ -2077,15 +1959,15 @@ describe Mongoid::NestedAttributes do
|
|
2077
1959
|
end
|
2078
1960
|
|
2079
1961
|
it "adds the new marked document" do
|
2080
|
-
person.addresses.first.street.
|
1962
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2081
1963
|
end
|
2082
1964
|
|
2083
1965
|
it "adds the new unmarked document" do
|
2084
|
-
person.addresses.last.street.
|
1966
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
2085
1967
|
end
|
2086
1968
|
|
2087
1969
|
it "does not add extra documents" do
|
2088
|
-
person.addresses.size.
|
1970
|
+
expect(person.addresses.size).to eq(2)
|
2089
1971
|
end
|
2090
1972
|
end
|
2091
1973
|
end
|
@@ -2093,12 +1975,12 @@ describe Mongoid::NestedAttributes do
|
|
2093
1975
|
|
2094
1976
|
context "when allow destroy is false" do
|
2095
1977
|
|
2096
|
-
before
|
1978
|
+
before do
|
2097
1979
|
Person.send(:undef_method, :addresses_attributes=)
|
2098
1980
|
Person.accepts_nested_attributes_for :addresses, allow_destroy: false
|
2099
1981
|
end
|
2100
1982
|
|
2101
|
-
after
|
1983
|
+
after do
|
2102
1984
|
Person.send(:undef_method, :addresses_attributes=)
|
2103
1985
|
Person.accepts_nested_attributes_for :addresses
|
2104
1986
|
end
|
@@ -2116,15 +1998,15 @@ describe Mongoid::NestedAttributes do
|
|
2116
1998
|
end
|
2117
1999
|
|
2118
2000
|
it "adds the the marked document" do
|
2119
|
-
person.addresses.first.street.
|
2001
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2120
2002
|
end
|
2121
2003
|
|
2122
2004
|
it "adds the new unmarked document" do
|
2123
|
-
person.addresses.last.street.
|
2005
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
2124
2006
|
end
|
2125
2007
|
|
2126
2008
|
it "adds the correct number of documents" do
|
2127
|
-
person.addresses.size.
|
2009
|
+
expect(person.addresses.size).to eq(2)
|
2128
2010
|
end
|
2129
2011
|
end
|
2130
2012
|
end
|
@@ -2142,15 +2024,15 @@ describe Mongoid::NestedAttributes do
|
|
2142
2024
|
end
|
2143
2025
|
|
2144
2026
|
it "adds the new marked document" do
|
2145
|
-
person.addresses.first.street.
|
2027
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2146
2028
|
end
|
2147
2029
|
|
2148
2030
|
it "adds the new unmarked document" do
|
2149
|
-
person.addresses.last.street.
|
2031
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
2150
2032
|
end
|
2151
2033
|
|
2152
2034
|
it "does not add extra documents" do
|
2153
|
-
person.addresses.size.
|
2035
|
+
expect(person.addresses.size).to eq(2)
|
2154
2036
|
end
|
2155
2037
|
end
|
2156
2038
|
end
|
@@ -2158,7 +2040,7 @@ describe Mongoid::NestedAttributes do
|
|
2158
2040
|
|
2159
2041
|
context "when allow destroy is not defined" do
|
2160
2042
|
|
2161
|
-
before
|
2043
|
+
before do
|
2162
2044
|
Person.send(:undef_method, :addresses_attributes=)
|
2163
2045
|
Person.accepts_nested_attributes_for :addresses
|
2164
2046
|
end
|
@@ -2176,15 +2058,15 @@ describe Mongoid::NestedAttributes do
|
|
2176
2058
|
end
|
2177
2059
|
|
2178
2060
|
it "adds the the marked document" do
|
2179
|
-
person.addresses.first.street.
|
2061
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2180
2062
|
end
|
2181
2063
|
|
2182
2064
|
it "adds the new unmarked document" do
|
2183
|
-
person.addresses.last.street.
|
2065
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
2184
2066
|
end
|
2185
2067
|
|
2186
2068
|
it "adds the correct number of documents" do
|
2187
|
-
person.addresses.size.
|
2069
|
+
expect(person.addresses.size).to eq(2)
|
2188
2070
|
end
|
2189
2071
|
end
|
2190
2072
|
end
|
@@ -2202,15 +2084,15 @@ describe Mongoid::NestedAttributes do
|
|
2202
2084
|
end
|
2203
2085
|
|
2204
2086
|
it "adds the new marked document" do
|
2205
|
-
person.addresses.first.street.
|
2087
|
+
expect(person.addresses.first.street).to eq("Maybachufer")
|
2206
2088
|
end
|
2207
2089
|
|
2208
2090
|
it "adds the new unmarked document" do
|
2209
|
-
person.addresses.last.street.
|
2091
|
+
expect(person.addresses.last.street).to eq("Alexander Platz")
|
2210
2092
|
end
|
2211
2093
|
|
2212
2094
|
it "does not add extra documents" do
|
2213
|
-
person.addresses.size.
|
2095
|
+
expect(person.addresses.size).to eq(2)
|
2214
2096
|
end
|
2215
2097
|
end
|
2216
2098
|
end
|
@@ -2219,13 +2101,13 @@ describe Mongoid::NestedAttributes do
|
|
2219
2101
|
|
2220
2102
|
context "when 'reject_if: :all_blank' and 'allow_destroy: true' are specified" do
|
2221
2103
|
|
2222
|
-
before
|
2104
|
+
before do
|
2223
2105
|
Person.send(:undef_method, :addresses_attributes=)
|
2224
2106
|
Person.accepts_nested_attributes_for \
|
2225
2107
|
:addresses, reject_if: :all_blank, allow_destroy: true
|
2226
2108
|
end
|
2227
2109
|
|
2228
|
-
after
|
2110
|
+
after do
|
2229
2111
|
Person.send(:undef_method, :addresses_attributes=)
|
2230
2112
|
Person.accepts_nested_attributes_for :addresses
|
2231
2113
|
end
|
@@ -2238,7 +2120,7 @@ describe Mongoid::NestedAttributes do
|
|
2238
2120
|
end
|
2239
2121
|
|
2240
2122
|
it "does not add the document" do
|
2241
|
-
person.addresses.
|
2123
|
+
expect(person.addresses).to be_empty
|
2242
2124
|
end
|
2243
2125
|
end
|
2244
2126
|
end
|
@@ -2246,11 +2128,11 @@ describe Mongoid::NestedAttributes do
|
|
2246
2128
|
|
2247
2129
|
context "when the nested document is invalid" do
|
2248
2130
|
|
2249
|
-
before
|
2131
|
+
before do
|
2250
2132
|
Person.validates_associated(:addresses)
|
2251
2133
|
end
|
2252
2134
|
|
2253
|
-
after
|
2135
|
+
after do
|
2254
2136
|
Person.reset_callbacks(:validate)
|
2255
2137
|
end
|
2256
2138
|
|
@@ -2261,8 +2143,8 @@ describe Mongoid::NestedAttributes do
|
|
2261
2143
|
end
|
2262
2144
|
|
2263
2145
|
it "propagates invalidity to parent" do
|
2264
|
-
person.addresses.first.
|
2265
|
-
person.
|
2146
|
+
expect(person.addresses.first).to_not be_valid
|
2147
|
+
expect(person).to_not be_valid
|
2266
2148
|
end
|
2267
2149
|
end
|
2268
2150
|
|
@@ -2283,7 +2165,7 @@ describe Mongoid::NestedAttributes do
|
|
2283
2165
|
end
|
2284
2166
|
|
2285
2167
|
it "instantiates an object of the given type" do
|
2286
|
-
canvas.shapes.map(&:class).
|
2168
|
+
expect(canvas.shapes.map(&:class)).to eq([Square, Circle])
|
2287
2169
|
end
|
2288
2170
|
end
|
2289
2171
|
end
|
@@ -2296,13 +2178,13 @@ describe Mongoid::NestedAttributes do
|
|
2296
2178
|
|
2297
2179
|
context "when a reject proc is specified" do
|
2298
2180
|
|
2299
|
-
before
|
2181
|
+
before do
|
2300
2182
|
Person.send(:undef_method, :game_attributes=)
|
2301
2183
|
Person.accepts_nested_attributes_for \
|
2302
2184
|
:game, reject_if: ->(attrs){ attrs[:name].blank? }
|
2303
2185
|
end
|
2304
2186
|
|
2305
|
-
after
|
2187
|
+
after do
|
2306
2188
|
Person.send(:undef_method, :game_attributes=)
|
2307
2189
|
Person.accepts_nested_attributes_for :game
|
2308
2190
|
end
|
@@ -2314,7 +2196,7 @@ describe Mongoid::NestedAttributes do
|
|
2314
2196
|
end
|
2315
2197
|
|
2316
2198
|
it "does not add the document" do
|
2317
|
-
person.game.
|
2199
|
+
expect(person.game).to be_nil
|
2318
2200
|
end
|
2319
2201
|
end
|
2320
2202
|
|
@@ -2325,20 +2207,20 @@ describe Mongoid::NestedAttributes do
|
|
2325
2207
|
end
|
2326
2208
|
|
2327
2209
|
it "adds the document" do
|
2328
|
-
person.game.name.
|
2210
|
+
expect(person.game.name).to eq("Tron")
|
2329
2211
|
end
|
2330
2212
|
end
|
2331
2213
|
end
|
2332
2214
|
|
2333
2215
|
context "when reject_if => :all_blank is specified" do
|
2334
2216
|
|
2335
|
-
before
|
2217
|
+
before do
|
2336
2218
|
Person.send(:undef_method, :game_attributes=)
|
2337
2219
|
Person.accepts_nested_attributes_for \
|
2338
2220
|
:game, reject_if: :all_blank
|
2339
2221
|
end
|
2340
2222
|
|
2341
|
-
after
|
2223
|
+
after do
|
2342
2224
|
Person.send(:undef_method, :game_attributes=)
|
2343
2225
|
Person.accepts_nested_attributes_for :game
|
2344
2226
|
end
|
@@ -2350,7 +2232,7 @@ describe Mongoid::NestedAttributes do
|
|
2350
2232
|
end
|
2351
2233
|
|
2352
2234
|
it "does not add the document" do
|
2353
|
-
person.game.
|
2235
|
+
expect(person.game).to be_nil
|
2354
2236
|
end
|
2355
2237
|
end
|
2356
2238
|
|
@@ -2361,7 +2243,7 @@ describe Mongoid::NestedAttributes do
|
|
2361
2243
|
end
|
2362
2244
|
|
2363
2245
|
it "adds the document" do
|
2364
|
-
person.game.name.
|
2246
|
+
expect(person.game.name).to eq("Tron")
|
2365
2247
|
end
|
2366
2248
|
end
|
2367
2249
|
end
|
@@ -2375,7 +2257,7 @@ describe Mongoid::NestedAttributes do
|
|
2375
2257
|
end
|
2376
2258
|
|
2377
2259
|
it "builds a new document" do
|
2378
|
-
person.game.name.
|
2260
|
+
expect(person.game.name).to eq("Tron")
|
2379
2261
|
end
|
2380
2262
|
end
|
2381
2263
|
|
@@ -2383,12 +2265,12 @@ describe Mongoid::NestedAttributes do
|
|
2383
2265
|
|
2384
2266
|
context "when allow_destroy is true" do
|
2385
2267
|
|
2386
|
-
before
|
2268
|
+
before do
|
2387
2269
|
Person.send(:undef_method, :game_attributes=)
|
2388
2270
|
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2389
2271
|
end
|
2390
2272
|
|
2391
|
-
after
|
2273
|
+
after do
|
2392
2274
|
Person.send(:undef_method, :game_attributes=)
|
2393
2275
|
Person.accepts_nested_attributes_for :game
|
2394
2276
|
end
|
@@ -2398,18 +2280,18 @@ describe Mongoid::NestedAttributes do
|
|
2398
2280
|
end
|
2399
2281
|
|
2400
2282
|
it "does not build the document" do
|
2401
|
-
person.game.
|
2283
|
+
expect(person.game).to be_nil
|
2402
2284
|
end
|
2403
2285
|
end
|
2404
2286
|
|
2405
2287
|
context "when allow_destroy is false" do
|
2406
2288
|
|
2407
|
-
before
|
2289
|
+
before do
|
2408
2290
|
Person.send(:undef_method, :game_attributes=)
|
2409
2291
|
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2410
2292
|
end
|
2411
2293
|
|
2412
|
-
after
|
2294
|
+
after do
|
2413
2295
|
Person.send(:undef_method, :game_attributes=)
|
2414
2296
|
Person.accepts_nested_attributes_for :game
|
2415
2297
|
end
|
@@ -2419,7 +2301,7 @@ describe Mongoid::NestedAttributes do
|
|
2419
2301
|
end
|
2420
2302
|
|
2421
2303
|
it "builds the document" do
|
2422
|
-
person.game.name.
|
2304
|
+
expect(person.game.name).to eq("Tron")
|
2423
2305
|
end
|
2424
2306
|
end
|
2425
2307
|
end
|
@@ -2431,7 +2313,7 @@ describe Mongoid::NestedAttributes do
|
|
2431
2313
|
end
|
2432
2314
|
|
2433
2315
|
it "does not build the document" do
|
2434
|
-
person.game.
|
2316
|
+
expect(person.game).to be_nil
|
2435
2317
|
end
|
2436
2318
|
end
|
2437
2319
|
|
@@ -2445,7 +2327,7 @@ describe Mongoid::NestedAttributes do
|
|
2445
2327
|
end
|
2446
2328
|
|
2447
2329
|
it "replaces the document" do
|
2448
|
-
person.game.name.
|
2330
|
+
expect(person.game.name).to eq("Pong")
|
2449
2331
|
end
|
2450
2332
|
end
|
2451
2333
|
|
@@ -2461,7 +2343,7 @@ describe Mongoid::NestedAttributes do
|
|
2461
2343
|
end
|
2462
2344
|
|
2463
2345
|
it "persists the attribute changes" do
|
2464
|
-
pizza.reload.topping.name.
|
2346
|
+
expect(pizza.reload.topping.name).to eq("onions")
|
2465
2347
|
end
|
2466
2348
|
end
|
2467
2349
|
|
@@ -2469,12 +2351,12 @@ describe Mongoid::NestedAttributes do
|
|
2469
2351
|
|
2470
2352
|
context "when allow_destroy is true" do
|
2471
2353
|
|
2472
|
-
before
|
2354
|
+
before do
|
2473
2355
|
Person.send(:undef_method, :game_attributes=)
|
2474
2356
|
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2475
2357
|
end
|
2476
2358
|
|
2477
|
-
after
|
2359
|
+
after do
|
2478
2360
|
Person.send(:undef_method, :game_attributes=)
|
2479
2361
|
Person.accepts_nested_attributes_for :game
|
2480
2362
|
end
|
@@ -2485,18 +2367,18 @@ describe Mongoid::NestedAttributes do
|
|
2485
2367
|
end
|
2486
2368
|
|
2487
2369
|
it "does not replace the document" do
|
2488
|
-
person.game.name.
|
2370
|
+
expect(person.game.name).to eq("Tron")
|
2489
2371
|
end
|
2490
2372
|
end
|
2491
2373
|
|
2492
2374
|
context "when allow_destroy is false" do
|
2493
2375
|
|
2494
|
-
before
|
2376
|
+
before do
|
2495
2377
|
Person.send(:undef_method, :game_attributes=)
|
2496
2378
|
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2497
2379
|
end
|
2498
2380
|
|
2499
|
-
after
|
2381
|
+
after do
|
2500
2382
|
Person.send(:undef_method, :game_attributes=)
|
2501
2383
|
Person.accepts_nested_attributes_for :game
|
2502
2384
|
end
|
@@ -2507,7 +2389,7 @@ describe Mongoid::NestedAttributes do
|
|
2507
2389
|
end
|
2508
2390
|
|
2509
2391
|
it "replaces the document" do
|
2510
|
-
person.game.name.
|
2392
|
+
expect(person.game.name).to eq("Pong")
|
2511
2393
|
end
|
2512
2394
|
end
|
2513
2395
|
end
|
@@ -2536,7 +2418,7 @@ describe Mongoid::NestedAttributes do
|
|
2536
2418
|
end
|
2537
2419
|
|
2538
2420
|
it "updates the existing document" do
|
2539
|
-
person.game.name.
|
2421
|
+
expect(person.game.name).to eq("Pong")
|
2540
2422
|
end
|
2541
2423
|
end
|
2542
2424
|
|
@@ -2548,18 +2430,18 @@ describe Mongoid::NestedAttributes do
|
|
2548
2430
|
end
|
2549
2431
|
|
2550
2432
|
it "updates the existing document" do
|
2551
|
-
person.game.name.
|
2433
|
+
expect(person.game.name).to eq("Pong")
|
2552
2434
|
end
|
2553
2435
|
end
|
2554
2436
|
|
2555
2437
|
context "when allow_destroy is true" do
|
2556
2438
|
|
2557
|
-
before
|
2439
|
+
before do
|
2558
2440
|
Person.send(:undef_method, :game_attributes=)
|
2559
2441
|
Person.accepts_nested_attributes_for :game, allow_destroy: true
|
2560
2442
|
end
|
2561
2443
|
|
2562
|
-
after
|
2444
|
+
after do
|
2563
2445
|
Person.send(:undef_method, :game_attributes=)
|
2564
2446
|
Person.accepts_nested_attributes_for :game
|
2565
2447
|
end
|
@@ -2574,7 +2456,7 @@ describe Mongoid::NestedAttributes do
|
|
2574
2456
|
end
|
2575
2457
|
|
2576
2458
|
it "destroys the existing document" do
|
2577
|
-
person.game.
|
2459
|
+
expect(person.game).to be_nil
|
2578
2460
|
end
|
2579
2461
|
end
|
2580
2462
|
end
|
@@ -2589,7 +2471,7 @@ describe Mongoid::NestedAttributes do
|
|
2589
2471
|
end
|
2590
2472
|
|
2591
2473
|
it "does not destroy the existing document" do
|
2592
|
-
person.game.
|
2474
|
+
expect(person.game).to eq(game)
|
2593
2475
|
end
|
2594
2476
|
end
|
2595
2477
|
end
|
@@ -2597,12 +2479,12 @@ describe Mongoid::NestedAttributes do
|
|
2597
2479
|
|
2598
2480
|
context "when allow destroy is false" do
|
2599
2481
|
|
2600
|
-
before
|
2482
|
+
before do
|
2601
2483
|
Person.send(:undef_method, :game_attributes=)
|
2602
2484
|
Person.accepts_nested_attributes_for :game, allow_destroy: false
|
2603
2485
|
end
|
2604
2486
|
|
2605
|
-
after
|
2487
|
+
after do
|
2606
2488
|
Person.send(:undef_method, :game_attributes=)
|
2607
2489
|
Person.accepts_nested_attributes_for :game
|
2608
2490
|
end
|
@@ -2615,14 +2497,14 @@ describe Mongoid::NestedAttributes do
|
|
2615
2497
|
end
|
2616
2498
|
|
2617
2499
|
it "does not destroy the document" do
|
2618
|
-
person.game.
|
2500
|
+
expect(person.game).to eq(game)
|
2619
2501
|
end
|
2620
2502
|
end
|
2621
2503
|
end
|
2622
2504
|
|
2623
2505
|
context "when update only is true" do
|
2624
2506
|
|
2625
|
-
before
|
2507
|
+
before do
|
2626
2508
|
Person.send(:undef_method, :game_attributes=)
|
2627
2509
|
Person.accepts_nested_attributes_for \
|
2628
2510
|
:game,
|
@@ -2630,7 +2512,7 @@ describe Mongoid::NestedAttributes do
|
|
2630
2512
|
allow_destroy: true
|
2631
2513
|
end
|
2632
2514
|
|
2633
|
-
after
|
2515
|
+
after do
|
2634
2516
|
Person.send(:undef_method, :game_attributes=)
|
2635
2517
|
Person.accepts_nested_attributes_for :game
|
2636
2518
|
end
|
@@ -2643,7 +2525,7 @@ describe Mongoid::NestedAttributes do
|
|
2643
2525
|
end
|
2644
2526
|
|
2645
2527
|
it "updates the existing document" do
|
2646
|
-
person.game.name.
|
2528
|
+
expect(person.game.name).to eq("Donkey Kong")
|
2647
2529
|
end
|
2648
2530
|
end
|
2649
2531
|
|
@@ -2651,11 +2533,11 @@ describe Mongoid::NestedAttributes do
|
|
2651
2533
|
|
2652
2534
|
before do
|
2653
2535
|
person.game_attributes =
|
2654
|
-
{ id:
|
2536
|
+
{ id: BSON::ObjectId.new.to_s, name: "Pong" }
|
2655
2537
|
end
|
2656
2538
|
|
2657
2539
|
it "updates the existing document" do
|
2658
|
-
person.game.name.
|
2540
|
+
expect(person.game.name).to eq("Pong")
|
2659
2541
|
end
|
2660
2542
|
end
|
2661
2543
|
|
@@ -2667,7 +2549,7 @@ describe Mongoid::NestedAttributes do
|
|
2667
2549
|
end
|
2668
2550
|
|
2669
2551
|
it "destroys the existing document" do
|
2670
|
-
person.game.
|
2552
|
+
expect(person.game).to be_nil
|
2671
2553
|
end
|
2672
2554
|
end
|
2673
2555
|
end
|
@@ -2677,11 +2559,11 @@ describe Mongoid::NestedAttributes do
|
|
2677
2559
|
|
2678
2560
|
context "when the nested document is invalid" do
|
2679
2561
|
|
2680
|
-
before
|
2562
|
+
before do
|
2681
2563
|
Person.validates_associated(:game)
|
2682
2564
|
end
|
2683
2565
|
|
2684
|
-
after
|
2566
|
+
after do
|
2685
2567
|
Person.reset_callbacks(:validate)
|
2686
2568
|
end
|
2687
2569
|
|
@@ -2690,8 +2572,8 @@ describe Mongoid::NestedAttributes do
|
|
2690
2572
|
end
|
2691
2573
|
|
2692
2574
|
it "propagates invalidity to parent" do
|
2693
|
-
person.game.
|
2694
|
-
person.
|
2575
|
+
expect(person.game).to_not be_valid
|
2576
|
+
expect(person).to_not be_valid
|
2695
2577
|
end
|
2696
2578
|
end
|
2697
2579
|
|
@@ -2708,7 +2590,7 @@ describe Mongoid::NestedAttributes do
|
|
2708
2590
|
end
|
2709
2591
|
|
2710
2592
|
it "instantiates an object of the given type" do
|
2711
|
-
driver.vehicle.class.
|
2593
|
+
expect(driver.vehicle.class).to eq(Truck)
|
2712
2594
|
end
|
2713
2595
|
end
|
2714
2596
|
end
|
@@ -2730,7 +2612,7 @@ describe Mongoid::NestedAttributes do
|
|
2730
2612
|
end
|
2731
2613
|
|
2732
2614
|
it "builds a new document" do
|
2733
|
-
game.person.title.
|
2615
|
+
expect(game.person.title).to eq("Sir")
|
2734
2616
|
end
|
2735
2617
|
|
2736
2618
|
end
|
@@ -2739,12 +2621,12 @@ describe Mongoid::NestedAttributes do
|
|
2739
2621
|
|
2740
2622
|
context "when allow_destroy is true" do
|
2741
2623
|
|
2742
|
-
before
|
2624
|
+
before do
|
2743
2625
|
Game.send(:undef_method, :person_attributes=)
|
2744
2626
|
Game.accepts_nested_attributes_for :person, allow_destroy: true
|
2745
2627
|
end
|
2746
2628
|
|
2747
|
-
after
|
2629
|
+
after do
|
2748
2630
|
Game.send(:undef_method, :person_attributes=)
|
2749
2631
|
Game.accepts_nested_attributes_for :person
|
2750
2632
|
end
|
@@ -2754,18 +2636,18 @@ describe Mongoid::NestedAttributes do
|
|
2754
2636
|
end
|
2755
2637
|
|
2756
2638
|
it "does not build a new document" do
|
2757
|
-
game.person.
|
2639
|
+
expect(game.person).to be_nil
|
2758
2640
|
end
|
2759
2641
|
end
|
2760
2642
|
|
2761
2643
|
context "when allow_destroy is false" do
|
2762
2644
|
|
2763
|
-
before
|
2645
|
+
before do
|
2764
2646
|
Game.send(:undef_method, :person_attributes=)
|
2765
2647
|
Game.accepts_nested_attributes_for :person, allow_destroy: false
|
2766
2648
|
end
|
2767
2649
|
|
2768
|
-
after
|
2650
|
+
after do
|
2769
2651
|
Game.send(:undef_method, :person_attributes=)
|
2770
2652
|
Game.accepts_nested_attributes_for :person
|
2771
2653
|
end
|
@@ -2775,7 +2657,7 @@ describe Mongoid::NestedAttributes do
|
|
2775
2657
|
end
|
2776
2658
|
|
2777
2659
|
it "builds a new document" do
|
2778
|
-
game.person.title.
|
2660
|
+
expect(game.person.title).to eq("Sir")
|
2779
2661
|
end
|
2780
2662
|
end
|
2781
2663
|
end
|
@@ -2796,7 +2678,7 @@ describe Mongoid::NestedAttributes do
|
|
2796
2678
|
end
|
2797
2679
|
|
2798
2680
|
it "updates the existing document" do
|
2799
|
-
game.person.title.
|
2681
|
+
expect(game.person.title).to eq("Sir")
|
2800
2682
|
end
|
2801
2683
|
end
|
2802
2684
|
end
|
@@ -2809,12 +2691,12 @@ describe Mongoid::NestedAttributes do
|
|
2809
2691
|
|
2810
2692
|
context "when allow destroy is true" do
|
2811
2693
|
|
2812
|
-
before
|
2694
|
+
before do
|
2813
2695
|
Game.send(:undef_method, :person_attributes=)
|
2814
2696
|
Game.accepts_nested_attributes_for :person, allow_destroy: true
|
2815
2697
|
end
|
2816
2698
|
|
2817
|
-
after
|
2699
|
+
after do
|
2818
2700
|
Game.send(:undef_method, :person_attributes=)
|
2819
2701
|
Game.accepts_nested_attributes_for :person
|
2820
2702
|
end
|
@@ -2829,7 +2711,7 @@ describe Mongoid::NestedAttributes do
|
|
2829
2711
|
end
|
2830
2712
|
|
2831
2713
|
it "destroys the existing document" do
|
2832
|
-
game.person.
|
2714
|
+
expect(game.person).to be_nil
|
2833
2715
|
end
|
2834
2716
|
end
|
2835
2717
|
end
|
@@ -2844,7 +2726,7 @@ describe Mongoid::NestedAttributes do
|
|
2844
2726
|
end
|
2845
2727
|
|
2846
2728
|
it "does not destroy the existing document" do
|
2847
|
-
game.person.
|
2729
|
+
expect(game.person).to eq(person)
|
2848
2730
|
end
|
2849
2731
|
end
|
2850
2732
|
end
|
@@ -2852,12 +2734,12 @@ describe Mongoid::NestedAttributes do
|
|
2852
2734
|
|
2853
2735
|
context "when allow destroy is false" do
|
2854
2736
|
|
2855
|
-
before
|
2737
|
+
before do
|
2856
2738
|
Game.send(:undef_method, :person_attributes=)
|
2857
2739
|
Game.accepts_nested_attributes_for :person, allow_destroy: false
|
2858
2740
|
end
|
2859
2741
|
|
2860
|
-
after
|
2742
|
+
after do
|
2861
2743
|
Game.send(:undef_method, :person_attributes=)
|
2862
2744
|
Game.accepts_nested_attributes_for :person
|
2863
2745
|
end
|
@@ -2870,7 +2752,7 @@ describe Mongoid::NestedAttributes do
|
|
2870
2752
|
end
|
2871
2753
|
|
2872
2754
|
it "does not delete the document" do
|
2873
|
-
game.person.
|
2755
|
+
expect(game.person).to eq(person)
|
2874
2756
|
end
|
2875
2757
|
end
|
2876
2758
|
end
|
@@ -2893,7 +2775,7 @@ describe Mongoid::NestedAttributes do
|
|
2893
2775
|
end
|
2894
2776
|
|
2895
2777
|
it "updates the existing document" do
|
2896
|
-
game.person.title.
|
2778
|
+
expect(game.person.title).to eq("Madam")
|
2897
2779
|
end
|
2898
2780
|
end
|
2899
2781
|
|
@@ -2901,11 +2783,11 @@ describe Mongoid::NestedAttributes do
|
|
2901
2783
|
|
2902
2784
|
before do
|
2903
2785
|
game.person_attributes =
|
2904
|
-
{ id:
|
2786
|
+
{ id: BSON::ObjectId.new.to_s, title: "Madam" }
|
2905
2787
|
end
|
2906
2788
|
|
2907
2789
|
it "updates the existing document" do
|
2908
|
-
game.person.title.
|
2790
|
+
expect(game.person.title).to eq("Madam")
|
2909
2791
|
end
|
2910
2792
|
end
|
2911
2793
|
|
@@ -2917,7 +2799,7 @@ describe Mongoid::NestedAttributes do
|
|
2917
2799
|
end
|
2918
2800
|
|
2919
2801
|
it "deletes the existing document" do
|
2920
|
-
game.person.
|
2802
|
+
expect(game.person).to be_nil
|
2921
2803
|
end
|
2922
2804
|
end
|
2923
2805
|
end
|
@@ -2926,11 +2808,11 @@ describe Mongoid::NestedAttributes do
|
|
2926
2808
|
|
2927
2809
|
context "when the nested document is invalid" do
|
2928
2810
|
|
2929
|
-
before
|
2811
|
+
before do
|
2930
2812
|
Person.validates_format_of :ssn, without: /\$\$\$/
|
2931
2813
|
end
|
2932
2814
|
|
2933
|
-
after
|
2815
|
+
after do
|
2934
2816
|
Person.reset_callbacks(:validate)
|
2935
2817
|
end
|
2936
2818
|
|
@@ -2939,8 +2821,8 @@ describe Mongoid::NestedAttributes do
|
|
2939
2821
|
end
|
2940
2822
|
|
2941
2823
|
it "propagates invalidity to parent" do
|
2942
|
-
game.person.
|
2943
|
-
game.
|
2824
|
+
expect(game.person).to_not be_valid
|
2825
|
+
expect(game).to_not be_valid
|
2944
2826
|
end
|
2945
2827
|
end
|
2946
2828
|
end
|
@@ -2958,7 +2840,7 @@ describe Mongoid::NestedAttributes do
|
|
2958
2840
|
end
|
2959
2841
|
|
2960
2842
|
it "instantiates an object of the given type" do
|
2961
|
-
vehicle.driver.class.
|
2843
|
+
expect(vehicle.driver.class).to eq(Learner)
|
2962
2844
|
end
|
2963
2845
|
end
|
2964
2846
|
end
|
@@ -2979,12 +2861,12 @@ describe Mongoid::NestedAttributes do
|
|
2979
2861
|
|
2980
2862
|
context "when a limit is specified" do
|
2981
2863
|
|
2982
|
-
before
|
2864
|
+
before do
|
2983
2865
|
Person.send(:undef_method, :posts_attributes=)
|
2984
2866
|
Person.accepts_nested_attributes_for :posts, limit: 2
|
2985
2867
|
end
|
2986
2868
|
|
2987
|
-
after
|
2869
|
+
after do
|
2988
2870
|
Person.send(:undef_method, :posts_attributes=)
|
2989
2871
|
Person.accepts_nested_attributes_for :posts
|
2990
2872
|
end
|
@@ -3020,11 +2902,11 @@ describe Mongoid::NestedAttributes do
|
|
3020
2902
|
end
|
3021
2903
|
|
3022
2904
|
it "sets the documents on the relation" do
|
3023
|
-
person.posts.size.
|
2905
|
+
expect(person.posts.size).to eq(2)
|
3024
2906
|
end
|
3025
2907
|
|
3026
2908
|
it "does not persist the new documents" do
|
3027
|
-
person.posts.count.
|
2909
|
+
expect(person.posts.count).to eq(0)
|
3028
2910
|
end
|
3029
2911
|
end
|
3030
2912
|
end
|
@@ -3054,15 +2936,15 @@ describe Mongoid::NestedAttributes do
|
|
3054
2936
|
context "when reloading the document" do
|
3055
2937
|
|
3056
2938
|
it "updates the first existing document" do
|
3057
|
-
person.posts(true).first.title.
|
2939
|
+
expect(person.posts(true).first.title).to eq("First")
|
3058
2940
|
end
|
3059
2941
|
|
3060
2942
|
it "updates the second existing document" do
|
3061
|
-
person.posts(true).last.title.
|
2943
|
+
expect(person.posts(true).last.title).to eq("Second")
|
3062
2944
|
end
|
3063
2945
|
|
3064
2946
|
it "does not add new documents" do
|
3065
|
-
person.posts(true).size.
|
2947
|
+
expect(person.posts(true).size).to eq(2)
|
3066
2948
|
end
|
3067
2949
|
end
|
3068
2950
|
|
@@ -3076,7 +2958,7 @@ describe Mongoid::NestedAttributes do
|
|
3076
2958
|
expect {
|
3077
2959
|
person.posts_attributes =
|
3078
2960
|
{ "0" =>
|
3079
|
-
{ "id" =>
|
2961
|
+
{ "id" => BSON::ObjectId.new.to_s, "title" => "Rogue" }
|
3080
2962
|
}
|
3081
2963
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
3082
2964
|
end
|
@@ -3101,7 +2983,7 @@ describe Mongoid::NestedAttributes do
|
|
3101
2983
|
end
|
3102
2984
|
|
3103
2985
|
it "does not perist the invalid value" do
|
3104
|
-
post_two.reload.title.
|
2986
|
+
expect(post_two.reload.title).to eq("First response")
|
3105
2987
|
end
|
3106
2988
|
end
|
3107
2989
|
end
|
@@ -3148,11 +3030,11 @@ describe Mongoid::NestedAttributes do
|
|
3148
3030
|
context "when reloading the documents" do
|
3149
3031
|
|
3150
3032
|
it "deletes the marked document" do
|
3151
|
-
person.posts(true).size.
|
3033
|
+
expect(person.posts(true).size).to eq(1)
|
3152
3034
|
end
|
3153
3035
|
|
3154
3036
|
it "does not delete the unmarked document" do
|
3155
|
-
person.posts(true).first.title.
|
3037
|
+
expect(person.posts(true).first.title).to eq("My Blog")
|
3156
3038
|
end
|
3157
3039
|
end
|
3158
3040
|
end
|
@@ -3173,11 +3055,11 @@ describe Mongoid::NestedAttributes do
|
|
3173
3055
|
context "when reloading the document" do
|
3174
3056
|
|
3175
3057
|
it "does not delete the marked document" do
|
3176
|
-
person.posts(true).size.
|
3058
|
+
expect(person.posts(true).size).to eq(2)
|
3177
3059
|
end
|
3178
3060
|
|
3179
3061
|
it "does not delete the unmarked document" do
|
3180
|
-
person.posts(true).map(&:title).
|
3062
|
+
expect(person.posts(true).map(&:title)).to include("My Blog")
|
3181
3063
|
end
|
3182
3064
|
end
|
3183
3065
|
end
|
@@ -3212,15 +3094,15 @@ describe Mongoid::NestedAttributes do
|
|
3212
3094
|
context "when reloading the document" do
|
3213
3095
|
|
3214
3096
|
it "does not ignore the marked document" do
|
3215
|
-
person.posts(true).first.title.
|
3097
|
+
expect(person.posts(true).first.title).to eq("Another Title")
|
3216
3098
|
end
|
3217
3099
|
|
3218
3100
|
it "does not delete the unmarked document" do
|
3219
|
-
person.posts(true).last.title.
|
3101
|
+
expect(person.posts(true).last.title).to eq("New Title")
|
3220
3102
|
end
|
3221
3103
|
|
3222
3104
|
it "does not add additional documents" do
|
3223
|
-
person.posts(true).size.
|
3105
|
+
expect(person.posts(true).size).to eq(2)
|
3224
3106
|
end
|
3225
3107
|
end
|
3226
3108
|
end
|
@@ -3241,11 +3123,11 @@ describe Mongoid::NestedAttributes do
|
|
3241
3123
|
context "when reloading the documents" do
|
3242
3124
|
|
3243
3125
|
it "does not delete the marked document" do
|
3244
|
-
person.posts(true).size.
|
3126
|
+
expect(person.posts(true).size).to eq(2)
|
3245
3127
|
end
|
3246
3128
|
|
3247
3129
|
it "does not delete the unmarked document" do
|
3248
|
-
person.posts(true).last.title.
|
3130
|
+
expect(person.posts(true).last.title).to eq("New Title")
|
3249
3131
|
end
|
3250
3132
|
end
|
3251
3133
|
end
|
@@ -3254,12 +3136,12 @@ describe Mongoid::NestedAttributes do
|
|
3254
3136
|
|
3255
3137
|
context "when allow_destroy is undefined" do
|
3256
3138
|
|
3257
|
-
before
|
3139
|
+
before do
|
3258
3140
|
Person.send(:undef_method, :posts_attributes=)
|
3259
3141
|
Person.accepts_nested_attributes_for :posts
|
3260
3142
|
end
|
3261
3143
|
|
3262
|
-
after
|
3144
|
+
after do
|
3263
3145
|
Person.send(:undef_method, :posts_attributes=)
|
3264
3146
|
Person.accepts_nested_attributes_for :posts
|
3265
3147
|
end
|
@@ -3283,15 +3165,15 @@ describe Mongoid::NestedAttributes do
|
|
3283
3165
|
context "when reloading" do
|
3284
3166
|
|
3285
3167
|
it "does not ignore the marked document" do
|
3286
|
-
person.posts(true).find(post_one.id).title.
|
3168
|
+
expect(person.posts(true).find(post_one.id).title).to eq("Another Title")
|
3287
3169
|
end
|
3288
3170
|
|
3289
3171
|
it "does not delete the unmarked document" do
|
3290
|
-
person.posts(true).find(post_two.id).title.
|
3172
|
+
expect(person.posts(true).find(post_two.id).title).to eq("New Title")
|
3291
3173
|
end
|
3292
3174
|
|
3293
3175
|
it "does not add additional documents" do
|
3294
|
-
person.posts(true).size.
|
3176
|
+
expect(person.posts(true).size).to eq(2)
|
3295
3177
|
end
|
3296
3178
|
end
|
3297
3179
|
end
|
@@ -3312,11 +3194,11 @@ describe Mongoid::NestedAttributes do
|
|
3312
3194
|
context "when reloading" do
|
3313
3195
|
|
3314
3196
|
it "does not delete the marked document" do
|
3315
|
-
person.posts(true).size.
|
3197
|
+
expect(person.posts(true).size).to eq(2)
|
3316
3198
|
end
|
3317
3199
|
|
3318
3200
|
it "does not delete the unmarked document" do
|
3319
|
-
person.posts(true).last.title.
|
3201
|
+
expect(person.posts(true).last.title).to eq("New Title")
|
3320
3202
|
end
|
3321
3203
|
end
|
3322
3204
|
end
|
@@ -3342,27 +3224,27 @@ describe Mongoid::NestedAttributes do
|
|
3342
3224
|
end
|
3343
3225
|
|
3344
3226
|
it "builds a new first document" do
|
3345
|
-
person.posts.first.title.
|
3227
|
+
expect(person.posts.first.title).to eq("First")
|
3346
3228
|
end
|
3347
3229
|
|
3348
3230
|
it "builds a new second document" do
|
3349
|
-
person.posts.second.title.
|
3231
|
+
expect(person.posts.second.title).to eq("Second")
|
3350
3232
|
end
|
3351
3233
|
|
3352
3234
|
it "builds a new third document" do
|
3353
|
-
person.posts.third.title.
|
3235
|
+
expect(person.posts.third.title).to eq("Third")
|
3354
3236
|
end
|
3355
3237
|
|
3356
3238
|
it "does not add extra documents" do
|
3357
|
-
person.posts.size.
|
3239
|
+
expect(person.posts.size).to eq(3)
|
3358
3240
|
end
|
3359
3241
|
|
3360
3242
|
it "does not persist the documents" do
|
3361
|
-
person.posts.count.
|
3243
|
+
expect(person.posts.count).to eq(0)
|
3362
3244
|
end
|
3363
3245
|
|
3364
3246
|
it "adds the documents in the sorted hash key order" do
|
3365
|
-
person.posts.map(&:title).
|
3247
|
+
expect(person.posts.map(&:title)).to eq(
|
3366
3248
|
[ "First", "Second", "Third" ]
|
3367
3249
|
)
|
3368
3250
|
end
|
@@ -3383,23 +3265,23 @@ describe Mongoid::NestedAttributes do
|
|
3383
3265
|
end
|
3384
3266
|
|
3385
3267
|
it "builds a new first document" do
|
3386
|
-
person.posts.first.title.
|
3268
|
+
expect(person.posts.first.title).to eq("Third")
|
3387
3269
|
end
|
3388
3270
|
|
3389
3271
|
it "builds a new second document" do
|
3390
|
-
person.posts.second.title.
|
3272
|
+
expect(person.posts.second.title).to eq("First")
|
3391
3273
|
end
|
3392
3274
|
|
3393
3275
|
it "builds a new third document" do
|
3394
|
-
person.posts.third.title.
|
3276
|
+
expect(person.posts.third.title).to eq("Second")
|
3395
3277
|
end
|
3396
3278
|
|
3397
3279
|
it "does not add extra documents" do
|
3398
|
-
person.posts.size.
|
3280
|
+
expect(person.posts.size).to eq(3)
|
3399
3281
|
end
|
3400
3282
|
|
3401
3283
|
it "does not persist the documents" do
|
3402
|
-
person.posts.count.
|
3284
|
+
expect(person.posts.count).to eq(0)
|
3403
3285
|
end
|
3404
3286
|
end
|
3405
3287
|
end
|
@@ -3407,13 +3289,13 @@ describe Mongoid::NestedAttributes do
|
|
3407
3289
|
|
3408
3290
|
context "when a reject block is supplied" do
|
3409
3291
|
|
3410
|
-
before
|
3292
|
+
before do
|
3411
3293
|
Person.send(:undef_method, :posts_attributes=)
|
3412
3294
|
Person.accepts_nested_attributes_for \
|
3413
3295
|
:posts, reject_if: ->(attrs){ attrs["title"].blank? }
|
3414
3296
|
end
|
3415
3297
|
|
3416
|
-
after
|
3298
|
+
after do
|
3417
3299
|
Person.send(:undef_method, :posts_attributes=)
|
3418
3300
|
Person.accepts_nested_attributes_for :posts
|
3419
3301
|
end
|
@@ -3426,7 +3308,7 @@ describe Mongoid::NestedAttributes do
|
|
3426
3308
|
end
|
3427
3309
|
|
3428
3310
|
it "does not add the new document" do
|
3429
|
-
person.posts.
|
3311
|
+
expect(person.posts).to be_empty
|
3430
3312
|
end
|
3431
3313
|
end
|
3432
3314
|
|
@@ -3438,24 +3320,24 @@ describe Mongoid::NestedAttributes do
|
|
3438
3320
|
end
|
3439
3321
|
|
3440
3322
|
it "adds the new document" do
|
3441
|
-
person.posts.size.
|
3323
|
+
expect(person.posts.size).to eq(1)
|
3442
3324
|
end
|
3443
3325
|
|
3444
3326
|
it "sets the correct attributes" do
|
3445
|
-
person.posts.first.title.
|
3327
|
+
expect(person.posts.first.title).to eq("Blogging")
|
3446
3328
|
end
|
3447
3329
|
end
|
3448
3330
|
end
|
3449
3331
|
|
3450
3332
|
context "when :reject_if => :all_blank is supplied" do
|
3451
3333
|
|
3452
|
-
before
|
3334
|
+
before do
|
3453
3335
|
Person.send(:undef_method, :posts_attributes=)
|
3454
3336
|
Person.accepts_nested_attributes_for \
|
3455
3337
|
:posts, reject_if: :all_blank
|
3456
3338
|
end
|
3457
3339
|
|
3458
|
-
after
|
3340
|
+
after do
|
3459
3341
|
Person.send(:undef_method, :posts_attributes=)
|
3460
3342
|
Person.accepts_nested_attributes_for :posts
|
3461
3343
|
end
|
@@ -3468,7 +3350,7 @@ describe Mongoid::NestedAttributes do
|
|
3468
3350
|
end
|
3469
3351
|
|
3470
3352
|
it "does not add the new document" do
|
3471
|
-
person.posts.
|
3353
|
+
expect(person.posts).to be_empty
|
3472
3354
|
end
|
3473
3355
|
end
|
3474
3356
|
|
@@ -3480,11 +3362,11 @@ describe Mongoid::NestedAttributes do
|
|
3480
3362
|
end
|
3481
3363
|
|
3482
3364
|
it "adds the new document" do
|
3483
|
-
person.posts.size.
|
3365
|
+
expect(person.posts.size).to eq(1)
|
3484
3366
|
end
|
3485
3367
|
|
3486
3368
|
it "sets the correct attributes" do
|
3487
|
-
person.posts.first.title.
|
3369
|
+
expect(person.posts.first.title).to eq("Blogging")
|
3488
3370
|
end
|
3489
3371
|
end
|
3490
3372
|
end
|
@@ -3493,12 +3375,12 @@ describe Mongoid::NestedAttributes do
|
|
3493
3375
|
|
3494
3376
|
context "when allow_destroy is true" do
|
3495
3377
|
|
3496
|
-
before
|
3378
|
+
before do
|
3497
3379
|
Person.send(:undef_method, :posts_attributes=)
|
3498
3380
|
Person.accepts_nested_attributes_for :posts, allow_destroy: true
|
3499
3381
|
end
|
3500
3382
|
|
3501
|
-
after
|
3383
|
+
after do
|
3502
3384
|
Person.send(:undef_method, :posts_attributes=)
|
3503
3385
|
Person.accepts_nested_attributes_for :posts
|
3504
3386
|
end
|
@@ -3516,11 +3398,11 @@ describe Mongoid::NestedAttributes do
|
|
3516
3398
|
end
|
3517
3399
|
|
3518
3400
|
it "ignores the the marked document" do
|
3519
|
-
person.posts.size.
|
3401
|
+
expect(person.posts.size).to eq(1)
|
3520
3402
|
end
|
3521
3403
|
|
3522
3404
|
it "adds the new unmarked document" do
|
3523
|
-
person.posts.first.title.
|
3405
|
+
expect(person.posts.first.title).to eq("Blog Two")
|
3524
3406
|
end
|
3525
3407
|
end
|
3526
3408
|
end
|
@@ -3538,15 +3420,15 @@ describe Mongoid::NestedAttributes do
|
|
3538
3420
|
end
|
3539
3421
|
|
3540
3422
|
it "adds the new marked document" do
|
3541
|
-
person.posts.first.title.
|
3423
|
+
expect(person.posts.first.title).to eq("New Blog")
|
3542
3424
|
end
|
3543
3425
|
|
3544
3426
|
it "adds the new unmarked document" do
|
3545
|
-
person.posts.last.title.
|
3427
|
+
expect(person.posts.last.title).to eq("Blog Two")
|
3546
3428
|
end
|
3547
3429
|
|
3548
3430
|
it "does not add extra documents" do
|
3549
|
-
person.posts.size.
|
3431
|
+
expect(person.posts.size).to eq(2)
|
3550
3432
|
end
|
3551
3433
|
end
|
3552
3434
|
end
|
@@ -3554,12 +3436,12 @@ describe Mongoid::NestedAttributes do
|
|
3554
3436
|
|
3555
3437
|
context "when allow destroy is false" do
|
3556
3438
|
|
3557
|
-
before
|
3439
|
+
before do
|
3558
3440
|
Person.send(:undef_method, :posts_attributes=)
|
3559
3441
|
Person.accepts_nested_attributes_for :posts, allow_destroy: false
|
3560
3442
|
end
|
3561
3443
|
|
3562
|
-
after
|
3444
|
+
after do
|
3563
3445
|
Person.send(:undef_method, :posts_attributes=)
|
3564
3446
|
Person.accepts_nested_attributes_for :posts
|
3565
3447
|
end
|
@@ -3577,15 +3459,15 @@ describe Mongoid::NestedAttributes do
|
|
3577
3459
|
end
|
3578
3460
|
|
3579
3461
|
it "adds the the marked document" do
|
3580
|
-
person.posts.first.title.
|
3462
|
+
expect(person.posts.first.title).to eq("New Blog")
|
3581
3463
|
end
|
3582
3464
|
|
3583
3465
|
it "adds the new unmarked document" do
|
3584
|
-
person.posts.last.title.
|
3466
|
+
expect(person.posts.last.title).to eq("Blog Two")
|
3585
3467
|
end
|
3586
3468
|
|
3587
3469
|
it "adds the correct number of documents" do
|
3588
|
-
person.posts.size.
|
3470
|
+
expect(person.posts.size).to eq(2)
|
3589
3471
|
end
|
3590
3472
|
end
|
3591
3473
|
end
|
@@ -3603,15 +3485,15 @@ describe Mongoid::NestedAttributes do
|
|
3603
3485
|
end
|
3604
3486
|
|
3605
3487
|
it "adds the new marked document" do
|
3606
|
-
person.posts.first.title.
|
3488
|
+
expect(person.posts.first.title).to eq("New Blog")
|
3607
3489
|
end
|
3608
3490
|
|
3609
3491
|
it "adds the new unmarked document" do
|
3610
|
-
person.posts.last.title.
|
3492
|
+
expect(person.posts.last.title).to eq("Blog Two")
|
3611
3493
|
end
|
3612
3494
|
|
3613
3495
|
it "does not add extra documents" do
|
3614
|
-
person.posts.size.
|
3496
|
+
expect(person.posts.size).to eq(2)
|
3615
3497
|
end
|
3616
3498
|
end
|
3617
3499
|
end
|
@@ -3619,7 +3501,7 @@ describe Mongoid::NestedAttributes do
|
|
3619
3501
|
|
3620
3502
|
context "when allow destroy is not defined" do
|
3621
3503
|
|
3622
|
-
before
|
3504
|
+
before do
|
3623
3505
|
Person.send(:undef_method, :posts_attributes=)
|
3624
3506
|
Person.accepts_nested_attributes_for :posts
|
3625
3507
|
end
|
@@ -3637,15 +3519,15 @@ describe Mongoid::NestedAttributes do
|
|
3637
3519
|
end
|
3638
3520
|
|
3639
3521
|
it "adds the the marked document" do
|
3640
|
-
person.posts.first.title.
|
3522
|
+
expect(person.posts.first.title).to eq("New Blog")
|
3641
3523
|
end
|
3642
3524
|
|
3643
3525
|
it "adds the new unmarked document" do
|
3644
|
-
person.posts.last.title.
|
3526
|
+
expect(person.posts.last.title).to eq("Blog Two")
|
3645
3527
|
end
|
3646
3528
|
|
3647
3529
|
it "adds the correct number of documents" do
|
3648
|
-
person.posts.size.
|
3530
|
+
expect(person.posts.size).to eq(2)
|
3649
3531
|
end
|
3650
3532
|
end
|
3651
3533
|
end
|
@@ -3663,15 +3545,15 @@ describe Mongoid::NestedAttributes do
|
|
3663
3545
|
end
|
3664
3546
|
|
3665
3547
|
it "adds the new marked document" do
|
3666
|
-
person.posts.first.title.
|
3548
|
+
expect(person.posts.first.title).to eq("New Blog")
|
3667
3549
|
end
|
3668
3550
|
|
3669
3551
|
it "adds the new unmarked document" do
|
3670
|
-
person.posts.last.title.
|
3552
|
+
expect(person.posts.last.title).to eq("Blog Two")
|
3671
3553
|
end
|
3672
3554
|
|
3673
3555
|
it "does not add extra documents" do
|
3674
|
-
person.posts.size.
|
3556
|
+
expect(person.posts.size).to eq(2)
|
3675
3557
|
end
|
3676
3558
|
end
|
3677
3559
|
end
|
@@ -3681,11 +3563,11 @@ describe Mongoid::NestedAttributes do
|
|
3681
3563
|
|
3682
3564
|
context "when the nested document is invalid" do
|
3683
3565
|
|
3684
|
-
before
|
3566
|
+
before do
|
3685
3567
|
Person.validates_associated(:posts)
|
3686
3568
|
end
|
3687
3569
|
|
3688
|
-
after
|
3570
|
+
after do
|
3689
3571
|
Person.reset_callbacks(:validate)
|
3690
3572
|
end
|
3691
3573
|
|
@@ -3696,8 +3578,8 @@ describe Mongoid::NestedAttributes do
|
|
3696
3578
|
end
|
3697
3579
|
|
3698
3580
|
it "propagates invalidity to parent" do
|
3699
|
-
person.
|
3700
|
-
person.posts.first.
|
3581
|
+
expect(person).to_not be_valid
|
3582
|
+
expect(person.posts.first).to_not be_valid
|
3701
3583
|
end
|
3702
3584
|
end
|
3703
3585
|
|
@@ -3718,7 +3600,7 @@ describe Mongoid::NestedAttributes do
|
|
3718
3600
|
end
|
3719
3601
|
|
3720
3602
|
it "instantiates an object of the given type" do
|
3721
|
-
shipping_container.vehicles.map(&:class).
|
3603
|
+
expect(shipping_container.vehicles.map(&:class)).to eq([Car, Truck])
|
3722
3604
|
end
|
3723
3605
|
end
|
3724
3606
|
end
|
@@ -3739,12 +3621,12 @@ describe Mongoid::NestedAttributes do
|
|
3739
3621
|
|
3740
3622
|
context "when a limit is specified" do
|
3741
3623
|
|
3742
|
-
before
|
3624
|
+
before do
|
3743
3625
|
Person.send(:undef_method, :preferences_attributes=)
|
3744
3626
|
Person.accepts_nested_attributes_for :preferences, limit: 2
|
3745
3627
|
end
|
3746
3628
|
|
3747
|
-
after
|
3629
|
+
after do
|
3748
3630
|
Person.send(:undef_method, :preferences_attributes=)
|
3749
3631
|
Person.accepts_nested_attributes_for :preferences
|
3750
3632
|
end
|
@@ -3780,7 +3662,7 @@ describe Mongoid::NestedAttributes do
|
|
3780
3662
|
end
|
3781
3663
|
|
3782
3664
|
it "sets the documents on the relation" do
|
3783
|
-
person.preferences.size.
|
3665
|
+
expect(person.preferences.size).to eq(2)
|
3784
3666
|
end
|
3785
3667
|
end
|
3786
3668
|
end
|
@@ -3810,15 +3692,15 @@ describe Mongoid::NestedAttributes do
|
|
3810
3692
|
context "when reloading the document" do
|
3811
3693
|
|
3812
3694
|
it "updates the first existing document" do
|
3813
|
-
person.preferences(true).first.name.
|
3695
|
+
expect(person.preferences(true).first.name).to eq("First")
|
3814
3696
|
end
|
3815
3697
|
|
3816
3698
|
it "updates the second existing document" do
|
3817
|
-
person.preferences(true).second.name.
|
3699
|
+
expect(person.preferences(true).second.name).to eq("Second")
|
3818
3700
|
end
|
3819
3701
|
|
3820
3702
|
it "does not add new documents" do
|
3821
|
-
person.preferences(true).size.
|
3703
|
+
expect(person.preferences(true).size).to eq(2)
|
3822
3704
|
end
|
3823
3705
|
end
|
3824
3706
|
end
|
@@ -3840,12 +3722,12 @@ describe Mongoid::NestedAttributes do
|
|
3840
3722
|
|
3841
3723
|
context "when allow_destroy is true" do
|
3842
3724
|
|
3843
|
-
before
|
3725
|
+
before do
|
3844
3726
|
Person.send(:undef_method, :preferences_attributes=)
|
3845
3727
|
Person.accepts_nested_attributes_for :preferences, allow_destroy: true
|
3846
3728
|
end
|
3847
3729
|
|
3848
|
-
after
|
3730
|
+
after do
|
3849
3731
|
Person.send(:undef_method, :preferences_attributes=)
|
3850
3732
|
Person.accepts_nested_attributes_for :preferences
|
3851
3733
|
end
|
@@ -3865,11 +3747,11 @@ describe Mongoid::NestedAttributes do
|
|
3865
3747
|
context "when reloading the documents" do
|
3866
3748
|
|
3867
3749
|
it "deletes the marked document" do
|
3868
|
-
person.preferences(true).size.
|
3750
|
+
expect(person.preferences(true).size).to eq(1)
|
3869
3751
|
end
|
3870
3752
|
|
3871
3753
|
it "does not delete the unmarked document" do
|
3872
|
-
person.preferences(true).first.name.
|
3754
|
+
expect(person.preferences(true).first.name).to eq("My Blog")
|
3873
3755
|
end
|
3874
3756
|
end
|
3875
3757
|
end
|
@@ -3890,11 +3772,11 @@ describe Mongoid::NestedAttributes do
|
|
3890
3772
|
context "when reloading the document" do
|
3891
3773
|
|
3892
3774
|
it "does not delete the marked document" do
|
3893
|
-
person.preferences(true).size.
|
3775
|
+
expect(person.preferences(true).size).to eq(2)
|
3894
3776
|
end
|
3895
3777
|
|
3896
3778
|
it "does not delete the unmarked document" do
|
3897
|
-
person.preferences(true).last.name.
|
3779
|
+
expect(person.preferences(true).last.name).to eq("My Blog")
|
3898
3780
|
end
|
3899
3781
|
end
|
3900
3782
|
end
|
@@ -3903,12 +3785,12 @@ describe Mongoid::NestedAttributes do
|
|
3903
3785
|
|
3904
3786
|
context "when allow_destroy is false" do
|
3905
3787
|
|
3906
|
-
before
|
3788
|
+
before do
|
3907
3789
|
Person.send(:undef_method, :preferences_attributes=)
|
3908
3790
|
Person.accepts_nested_attributes_for :preferences, allow_destroy: false
|
3909
3791
|
end
|
3910
3792
|
|
3911
|
-
after
|
3793
|
+
after do
|
3912
3794
|
Person.send(:undef_method, :preferences_attributes=)
|
3913
3795
|
Person.accepts_nested_attributes_for :preferences
|
3914
3796
|
end
|
@@ -3929,15 +3811,15 @@ describe Mongoid::NestedAttributes do
|
|
3929
3811
|
context "when reloading the document" do
|
3930
3812
|
|
3931
3813
|
it "does not ignore the marked document" do
|
3932
|
-
person.preferences(true).first.name.
|
3814
|
+
expect(person.preferences(true).first.name).to eq("Another Title")
|
3933
3815
|
end
|
3934
3816
|
|
3935
3817
|
it "does not delete the unmarked document" do
|
3936
|
-
person.preferences(true).last.name.
|
3818
|
+
expect(person.preferences(true).last.name).to eq("New Title")
|
3937
3819
|
end
|
3938
3820
|
|
3939
3821
|
it "does not add additional documents" do
|
3940
|
-
person.preferences(true).size.
|
3822
|
+
expect(person.preferences(true).size).to eq(2)
|
3941
3823
|
end
|
3942
3824
|
end
|
3943
3825
|
end
|
@@ -3958,11 +3840,11 @@ describe Mongoid::NestedAttributes do
|
|
3958
3840
|
context "when reloading the documents" do
|
3959
3841
|
|
3960
3842
|
it "does not delete the marked document" do
|
3961
|
-
person.preferences(true).size.
|
3843
|
+
expect(person.preferences(true).size).to eq(2)
|
3962
3844
|
end
|
3963
3845
|
|
3964
3846
|
it "does not delete the unmarked document" do
|
3965
|
-
person.preferences(true).last.name.
|
3847
|
+
expect(person.preferences(true).last.name).to eq("New Title")
|
3966
3848
|
end
|
3967
3849
|
end
|
3968
3850
|
end
|
@@ -3971,7 +3853,7 @@ describe Mongoid::NestedAttributes do
|
|
3971
3853
|
|
3972
3854
|
context "when allow_destroy is undefined" do
|
3973
3855
|
|
3974
|
-
before
|
3856
|
+
before do
|
3975
3857
|
Person.send(:undef_method, :preferences_attributes=)
|
3976
3858
|
Person.accepts_nested_attributes_for :preferences
|
3977
3859
|
end
|
@@ -3992,15 +3874,15 @@ describe Mongoid::NestedAttributes do
|
|
3992
3874
|
context "when reloading" do
|
3993
3875
|
|
3994
3876
|
it "does not ignore the marked document" do
|
3995
|
-
person.preferences(true).first.name.
|
3877
|
+
expect(person.preferences(true).first.name).to eq("Another Title")
|
3996
3878
|
end
|
3997
3879
|
|
3998
3880
|
it "does not delete the unmarked document" do
|
3999
|
-
person.preferences(true).last.name.
|
3881
|
+
expect(person.preferences(true).last.name).to eq("New Title")
|
4000
3882
|
end
|
4001
3883
|
|
4002
3884
|
it "does not add additional documents" do
|
4003
|
-
person.preferences(true).size.
|
3885
|
+
expect(person.preferences(true).size).to eq(2)
|
4004
3886
|
end
|
4005
3887
|
end
|
4006
3888
|
end
|
@@ -4021,11 +3903,11 @@ describe Mongoid::NestedAttributes do
|
|
4021
3903
|
context "when reloading" do
|
4022
3904
|
|
4023
3905
|
it "does not delete the marked document" do
|
4024
|
-
person.preferences(true).size.
|
3906
|
+
expect(person.preferences(true).size).to eq(2)
|
4025
3907
|
end
|
4026
3908
|
|
4027
3909
|
it "does not delete the unmarked document" do
|
4028
|
-
person.preferences(true).last.name.
|
3910
|
+
expect(person.preferences(true).last.name).to eq("New Title")
|
4029
3911
|
end
|
4030
3912
|
end
|
4031
3913
|
end
|
@@ -4049,23 +3931,23 @@ describe Mongoid::NestedAttributes do
|
|
4049
3931
|
end
|
4050
3932
|
|
4051
3933
|
it "builds a new first document" do
|
4052
|
-
person.preferences.first.name.
|
3934
|
+
expect(person.preferences.first.name).to eq("First")
|
4053
3935
|
end
|
4054
3936
|
|
4055
3937
|
it "builds a new second document" do
|
4056
|
-
person.preferences.second.name.
|
3938
|
+
expect(person.preferences.second.name).to eq("Second")
|
4057
3939
|
end
|
4058
3940
|
|
4059
3941
|
it "builds a new third document" do
|
4060
|
-
person.preferences.third.name.
|
3942
|
+
expect(person.preferences.third.name).to eq("Third")
|
4061
3943
|
end
|
4062
3944
|
|
4063
3945
|
it "does not add extra documents" do
|
4064
|
-
person.preferences.size.
|
3946
|
+
expect(person.preferences.size).to eq(3)
|
4065
3947
|
end
|
4066
3948
|
|
4067
3949
|
it "adds the documents in the sorted hash key order" do
|
4068
|
-
person.preferences.map(&:name).
|
3950
|
+
expect(person.preferences.map(&:name)).to eq(
|
4069
3951
|
[ "First", "Second", "Third" ]
|
4070
3952
|
)
|
4071
3953
|
end
|
@@ -4073,13 +3955,13 @@ describe Mongoid::NestedAttributes do
|
|
4073
3955
|
|
4074
3956
|
context "when a reject block is supplied" do
|
4075
3957
|
|
4076
|
-
before
|
3958
|
+
before do
|
4077
3959
|
Person.send(:undef_method, :preferences_attributes=)
|
4078
3960
|
Person.accepts_nested_attributes_for \
|
4079
3961
|
:preferences, reject_if: ->(attrs){ attrs["name"].blank? }
|
4080
3962
|
end
|
4081
3963
|
|
4082
|
-
after
|
3964
|
+
after do
|
4083
3965
|
Person.send(:undef_method, :preferences_attributes=)
|
4084
3966
|
Person.accepts_nested_attributes_for :preferences
|
4085
3967
|
end
|
@@ -4092,7 +3974,7 @@ describe Mongoid::NestedAttributes do
|
|
4092
3974
|
end
|
4093
3975
|
|
4094
3976
|
it "does not add the new document" do
|
4095
|
-
person.preferences.
|
3977
|
+
expect(person.preferences).to be_empty
|
4096
3978
|
end
|
4097
3979
|
end
|
4098
3980
|
|
@@ -4104,24 +3986,24 @@ describe Mongoid::NestedAttributes do
|
|
4104
3986
|
end
|
4105
3987
|
|
4106
3988
|
it "adds the new document" do
|
4107
|
-
person.preferences.size.
|
3989
|
+
expect(person.preferences.size).to eq(1)
|
4108
3990
|
end
|
4109
3991
|
|
4110
3992
|
it "sets the correct attributes" do
|
4111
|
-
person.preferences.first.name.
|
3993
|
+
expect(person.preferences.first.name).to eq("Blogging")
|
4112
3994
|
end
|
4113
3995
|
end
|
4114
3996
|
end
|
4115
3997
|
|
4116
3998
|
context "when :reject_if => :all_blank is supplied" do
|
4117
3999
|
|
4118
|
-
before
|
4000
|
+
before do
|
4119
4001
|
Person.send(:undef_method, :preferences_attributes=)
|
4120
4002
|
Person.accepts_nested_attributes_for \
|
4121
4003
|
:preferences, reject_if: :all_blank
|
4122
4004
|
end
|
4123
4005
|
|
4124
|
-
after
|
4006
|
+
after do
|
4125
4007
|
Person.send(:undef_method, :preferences_attributes=)
|
4126
4008
|
Person.accepts_nested_attributes_for :preferences
|
4127
4009
|
end
|
@@ -4134,7 +4016,7 @@ describe Mongoid::NestedAttributes do
|
|
4134
4016
|
end
|
4135
4017
|
|
4136
4018
|
it "does not add the new document" do
|
4137
|
-
person.preferences.
|
4019
|
+
expect(person.preferences).to be_empty
|
4138
4020
|
end
|
4139
4021
|
end
|
4140
4022
|
|
@@ -4146,11 +4028,11 @@ describe Mongoid::NestedAttributes do
|
|
4146
4028
|
end
|
4147
4029
|
|
4148
4030
|
it "adds the new document" do
|
4149
|
-
person.preferences.size.
|
4031
|
+
expect(person.preferences.size).to eq(1)
|
4150
4032
|
end
|
4151
4033
|
|
4152
4034
|
it "sets the correct attributes" do
|
4153
|
-
person.preferences.first.name.
|
4035
|
+
expect(person.preferences.first.name).to eq("Blogging")
|
4154
4036
|
end
|
4155
4037
|
end
|
4156
4038
|
end
|
@@ -4159,12 +4041,12 @@ describe Mongoid::NestedAttributes do
|
|
4159
4041
|
|
4160
4042
|
context "when allow_destroy is true" do
|
4161
4043
|
|
4162
|
-
before
|
4044
|
+
before do
|
4163
4045
|
Person.send(:undef_method, :preferences_attributes=)
|
4164
4046
|
Person.accepts_nested_attributes_for :preferences, allow_destroy: true
|
4165
4047
|
end
|
4166
4048
|
|
4167
|
-
after
|
4049
|
+
after do
|
4168
4050
|
Person.send(:undef_method, :preferences_attributes=)
|
4169
4051
|
Person.accepts_nested_attributes_for :preferences
|
4170
4052
|
end
|
@@ -4182,11 +4064,11 @@ describe Mongoid::NestedAttributes do
|
|
4182
4064
|
end
|
4183
4065
|
|
4184
4066
|
it "ignores the the marked document" do
|
4185
|
-
person.preferences.size.
|
4067
|
+
expect(person.preferences.size).to eq(1)
|
4186
4068
|
end
|
4187
4069
|
|
4188
4070
|
it "adds the new unmarked document" do
|
4189
|
-
person.preferences.first.name.
|
4071
|
+
expect(person.preferences.first.name).to eq("Blog Two")
|
4190
4072
|
end
|
4191
4073
|
end
|
4192
4074
|
end
|
@@ -4204,15 +4086,15 @@ describe Mongoid::NestedAttributes do
|
|
4204
4086
|
end
|
4205
4087
|
|
4206
4088
|
it "adds the new marked document" do
|
4207
|
-
person.preferences.first.name.
|
4089
|
+
expect(person.preferences.first.name).to eq("New Blog")
|
4208
4090
|
end
|
4209
4091
|
|
4210
4092
|
it "adds the new unmarked document" do
|
4211
|
-
person.preferences.last.name.
|
4093
|
+
expect(person.preferences.last.name).to eq("Blog Two")
|
4212
4094
|
end
|
4213
4095
|
|
4214
4096
|
it "does not add extra documents" do
|
4215
|
-
person.preferences.size.
|
4097
|
+
expect(person.preferences.size).to eq(2)
|
4216
4098
|
end
|
4217
4099
|
end
|
4218
4100
|
end
|
@@ -4220,12 +4102,12 @@ describe Mongoid::NestedAttributes do
|
|
4220
4102
|
|
4221
4103
|
context "when allow destroy is false" do
|
4222
4104
|
|
4223
|
-
before
|
4105
|
+
before do
|
4224
4106
|
Person.send(:undef_method, :preferences_attributes=)
|
4225
4107
|
Person.accepts_nested_attributes_for :preferences, allow_destroy: false
|
4226
4108
|
end
|
4227
4109
|
|
4228
|
-
after
|
4110
|
+
after do
|
4229
4111
|
Person.send(:undef_method, :preferences_attributes=)
|
4230
4112
|
Person.accepts_nested_attributes_for :preferences
|
4231
4113
|
end
|
@@ -4243,15 +4125,15 @@ describe Mongoid::NestedAttributes do
|
|
4243
4125
|
end
|
4244
4126
|
|
4245
4127
|
it "adds the the marked document" do
|
4246
|
-
person.preferences.first.name.
|
4128
|
+
expect(person.preferences.first.name).to eq("New Blog")
|
4247
4129
|
end
|
4248
4130
|
|
4249
4131
|
it "adds the new unmarked document" do
|
4250
|
-
person.preferences.last.name.
|
4132
|
+
expect(person.preferences.last.name).to eq("Blog Two")
|
4251
4133
|
end
|
4252
4134
|
|
4253
4135
|
it "adds the correct number of documents" do
|
4254
|
-
person.preferences.size.
|
4136
|
+
expect(person.preferences.size).to eq(2)
|
4255
4137
|
end
|
4256
4138
|
end
|
4257
4139
|
end
|
@@ -4269,15 +4151,15 @@ describe Mongoid::NestedAttributes do
|
|
4269
4151
|
end
|
4270
4152
|
|
4271
4153
|
it "adds the new marked document" do
|
4272
|
-
person.preferences.first.name.
|
4154
|
+
expect(person.preferences.first.name).to eq("New Blog")
|
4273
4155
|
end
|
4274
4156
|
|
4275
4157
|
it "adds the new unmarked document" do
|
4276
|
-
person.preferences.last.name.
|
4158
|
+
expect(person.preferences.last.name).to eq("Blog Two")
|
4277
4159
|
end
|
4278
4160
|
|
4279
4161
|
it "does not add extra documents" do
|
4280
|
-
person.preferences.size.
|
4162
|
+
expect(person.preferences.size).to eq(2)
|
4281
4163
|
end
|
4282
4164
|
end
|
4283
4165
|
end
|
@@ -4285,7 +4167,7 @@ describe Mongoid::NestedAttributes do
|
|
4285
4167
|
|
4286
4168
|
context "when allow destroy is not defined" do
|
4287
4169
|
|
4288
|
-
before
|
4170
|
+
before do
|
4289
4171
|
Person.send(:undef_method, :preferences_attributes=)
|
4290
4172
|
Person.accepts_nested_attributes_for :preferences
|
4291
4173
|
end
|
@@ -4303,15 +4185,15 @@ describe Mongoid::NestedAttributes do
|
|
4303
4185
|
end
|
4304
4186
|
|
4305
4187
|
it "adds the the marked document" do
|
4306
|
-
person.preferences.first.name.
|
4188
|
+
expect(person.preferences.first.name).to eq("New Blog")
|
4307
4189
|
end
|
4308
4190
|
|
4309
4191
|
it "adds the new unmarked document" do
|
4310
|
-
person.preferences.last.name.
|
4192
|
+
expect(person.preferences.last.name).to eq("Blog Two")
|
4311
4193
|
end
|
4312
4194
|
|
4313
4195
|
it "adds the correct number of documents" do
|
4314
|
-
person.preferences.size.
|
4196
|
+
expect(person.preferences.size).to eq(2)
|
4315
4197
|
end
|
4316
4198
|
end
|
4317
4199
|
end
|
@@ -4329,15 +4211,15 @@ describe Mongoid::NestedAttributes do
|
|
4329
4211
|
end
|
4330
4212
|
|
4331
4213
|
it "adds the new marked document" do
|
4332
|
-
person.preferences.first.name.
|
4214
|
+
expect(person.preferences.first.name).to eq("New Blog")
|
4333
4215
|
end
|
4334
4216
|
|
4335
4217
|
it "adds the new unmarked document" do
|
4336
|
-
person.preferences.last.name.
|
4218
|
+
expect(person.preferences.last.name).to eq("Blog Two")
|
4337
4219
|
end
|
4338
4220
|
|
4339
4221
|
it "does not add extra documents" do
|
4340
|
-
person.preferences.size.
|
4222
|
+
expect(person.preferences.size).to eq(2)
|
4341
4223
|
end
|
4342
4224
|
end
|
4343
4225
|
end
|
@@ -4347,11 +4229,11 @@ describe Mongoid::NestedAttributes do
|
|
4347
4229
|
|
4348
4230
|
context "when the nested document is invalid" do
|
4349
4231
|
|
4350
|
-
before
|
4232
|
+
before do
|
4351
4233
|
Person.validates_associated(:preferences)
|
4352
4234
|
end
|
4353
4235
|
|
4354
|
-
after
|
4236
|
+
after do
|
4355
4237
|
Person.reset_callbacks(:validate)
|
4356
4238
|
end
|
4357
4239
|
|
@@ -4362,8 +4244,8 @@ describe Mongoid::NestedAttributes do
|
|
4362
4244
|
end
|
4363
4245
|
|
4364
4246
|
it "propagates invalidity to parent" do
|
4365
|
-
person.preferences.first.
|
4366
|
-
person.
|
4247
|
+
expect(person.preferences.first).to_not be_valid
|
4248
|
+
expect(person).to_not be_valid
|
4367
4249
|
end
|
4368
4250
|
end
|
4369
4251
|
end
|
@@ -4372,7 +4254,7 @@ describe Mongoid::NestedAttributes do
|
|
4372
4254
|
|
4373
4255
|
describe "#update_attributes" do
|
4374
4256
|
|
4375
|
-
before
|
4257
|
+
before do
|
4376
4258
|
Person.send(:undef_method, :addresses_attributes=)
|
4377
4259
|
Person.accepts_nested_attributes_for :addresses
|
4378
4260
|
end
|
@@ -4407,11 +4289,11 @@ describe Mongoid::NestedAttributes do
|
|
4407
4289
|
end
|
4408
4290
|
|
4409
4291
|
it "adds the new embedded document" do
|
4410
|
-
server.reload.filesystems.first.name.
|
4292
|
+
expect(server.reload.filesystems.first.name).to eq("NFS")
|
4411
4293
|
end
|
4412
4294
|
|
4413
4295
|
it "does not add more than one document" do
|
4414
|
-
server.reload.filesystems.count.
|
4296
|
+
expect(server.reload.filesystems.count).to eq(1)
|
4415
4297
|
end
|
4416
4298
|
end
|
4417
4299
|
end
|
@@ -4439,29 +4321,29 @@ describe Mongoid::NestedAttributes do
|
|
4439
4321
|
end
|
4440
4322
|
|
4441
4323
|
it "removes the document from the parent" do
|
4442
|
-
person.services.
|
4324
|
+
expect(person.services).to be_empty
|
4443
4325
|
end
|
4444
4326
|
|
4445
4327
|
it "deletes the document" do
|
4446
|
-
service.
|
4328
|
+
expect(service).to be_destroyed
|
4447
4329
|
end
|
4448
4330
|
|
4449
4331
|
it "runs the before destroy callbacks" do
|
4450
|
-
service.before_destroy_called.
|
4332
|
+
expect(service.before_destroy_called).to be true
|
4451
4333
|
end
|
4452
4334
|
|
4453
4335
|
it "runs the after destroy callbacks" do
|
4454
|
-
service.after_destroy_called.
|
4336
|
+
expect(service.after_destroy_called).to be true
|
4455
4337
|
end
|
4456
4338
|
|
4457
4339
|
it "clears the delayed atomic pulls from the parent" do
|
4458
|
-
person.delayed_atomic_pulls.
|
4340
|
+
expect(person.delayed_atomic_pulls).to be_empty
|
4459
4341
|
end
|
4460
4342
|
end
|
4461
4343
|
|
4462
4344
|
context "when nesting multiple levels and parent is timestamped" do
|
4463
4345
|
|
4464
|
-
before
|
4346
|
+
before do
|
4465
4347
|
class Address
|
4466
4348
|
after_save do
|
4467
4349
|
addressable.touch
|
@@ -4469,7 +4351,7 @@ describe Mongoid::NestedAttributes do
|
|
4469
4351
|
end
|
4470
4352
|
end
|
4471
4353
|
|
4472
|
-
after
|
4354
|
+
after do
|
4473
4355
|
Address.reset_callbacks(:save)
|
4474
4356
|
end
|
4475
4357
|
|
@@ -4494,12 +4376,12 @@ describe Mongoid::NestedAttributes do
|
|
4494
4376
|
end
|
4495
4377
|
|
4496
4378
|
before do
|
4497
|
-
address.
|
4379
|
+
address.update_attributes(attributes)
|
4498
4380
|
address.reload
|
4499
4381
|
end
|
4500
4382
|
|
4501
4383
|
it "does not add any extra locations" do
|
4502
|
-
address.locations.size.
|
4384
|
+
expect(address.locations.size).to eq(2)
|
4503
4385
|
end
|
4504
4386
|
end
|
4505
4387
|
|
@@ -4541,11 +4423,11 @@ describe Mongoid::NestedAttributes do
|
|
4541
4423
|
end
|
4542
4424
|
|
4543
4425
|
it "deletes the document from the relation" do
|
4544
|
-
address_one.locations.
|
4426
|
+
expect(address_one.locations).to be_empty
|
4545
4427
|
end
|
4546
4428
|
|
4547
4429
|
it "persists the change" do
|
4548
|
-
address_one.reload.locations.
|
4430
|
+
expect(address_one.reload.locations).to be_empty
|
4549
4431
|
end
|
4550
4432
|
end
|
4551
4433
|
|
@@ -4565,12 +4447,12 @@ describe Mongoid::NestedAttributes do
|
|
4565
4447
|
|
4566
4448
|
context "when cascading callbacks" do
|
4567
4449
|
|
4568
|
-
before
|
4450
|
+
before do
|
4569
4451
|
Band.accepts_nested_attributes_for :records
|
4570
4452
|
Record.accepts_nested_attributes_for :tracks, allow_destroy: true
|
4571
4453
|
end
|
4572
4454
|
|
4573
|
-
after
|
4455
|
+
after do
|
4574
4456
|
Band.send(:undef_method, :records_attributes=)
|
4575
4457
|
Record.send(:undef_method, :tracks_attributes=)
|
4576
4458
|
end
|
@@ -4591,15 +4473,15 @@ describe Mongoid::NestedAttributes do
|
|
4591
4473
|
end
|
4592
4474
|
|
4593
4475
|
it "removes the child from the relation" do
|
4594
|
-
record.tracks.
|
4476
|
+
expect(record.tracks).to be_empty
|
4595
4477
|
end
|
4596
4478
|
|
4597
4479
|
it "deletes the child document" do
|
4598
|
-
track.
|
4480
|
+
expect(track).to be_destroyed
|
4599
4481
|
end
|
4600
4482
|
|
4601
4483
|
it "runs the child's callbacks" do
|
4602
|
-
track.before_destroy_called.
|
4484
|
+
expect(track.before_destroy_called).to be true
|
4603
4485
|
end
|
4604
4486
|
end
|
4605
4487
|
end
|
@@ -4620,7 +4502,7 @@ describe Mongoid::NestedAttributes do
|
|
4620
4502
|
end
|
4621
4503
|
|
4622
4504
|
before do
|
4623
|
-
person.
|
4505
|
+
person.update_attributes(attributes)
|
4624
4506
|
end
|
4625
4507
|
|
4626
4508
|
let(:address) do
|
@@ -4632,11 +4514,11 @@ describe Mongoid::NestedAttributes do
|
|
4632
4514
|
end
|
4633
4515
|
|
4634
4516
|
it "adds the new first level embedded document" do
|
4635
|
-
address.street.
|
4517
|
+
expect(address.street).to eq("Alexanderstr")
|
4636
4518
|
end
|
4637
4519
|
|
4638
4520
|
it "adds the nested embedded document" do
|
4639
|
-
location.name.
|
4521
|
+
expect(location.name).to eq("Home")
|
4640
4522
|
end
|
4641
4523
|
end
|
4642
4524
|
|
@@ -4660,16 +4542,16 @@ describe Mongoid::NestedAttributes do
|
|
4660
4542
|
end
|
4661
4543
|
|
4662
4544
|
before do
|
4663
|
-
person.
|
4545
|
+
person.update_attributes(attributes)
|
4664
4546
|
person.reload
|
4665
4547
|
end
|
4666
4548
|
|
4667
4549
|
it "adds the new location to the existing address" do
|
4668
|
-
person.addresses.first.locations.count.
|
4550
|
+
expect(person.addresses.first.locations.count).to eq(2)
|
4669
4551
|
end
|
4670
4552
|
|
4671
4553
|
it "adds the new address" do
|
4672
|
-
person.addresses.count.
|
4554
|
+
expect(person.addresses.count).to eq(2)
|
4673
4555
|
end
|
4674
4556
|
end
|
4675
4557
|
end
|
@@ -4691,7 +4573,7 @@ describe Mongoid::NestedAttributes do
|
|
4691
4573
|
end
|
4692
4574
|
|
4693
4575
|
before do
|
4694
|
-
person.
|
4576
|
+
person.update_attributes(attributes)
|
4695
4577
|
end
|
4696
4578
|
|
4697
4579
|
let(:address) do
|
@@ -4703,11 +4585,11 @@ describe Mongoid::NestedAttributes do
|
|
4703
4585
|
end
|
4704
4586
|
|
4705
4587
|
it "adds the new first level embedded document" do
|
4706
|
-
address.street.
|
4588
|
+
expect(address.street).to eq("Alexanderstr")
|
4707
4589
|
end
|
4708
4590
|
|
4709
4591
|
it "adds the nested embedded document" do
|
4710
|
-
code.name.
|
4592
|
+
expect(code.name).to eq("Home")
|
4711
4593
|
end
|
4712
4594
|
end
|
4713
4595
|
end
|
@@ -4740,15 +4622,15 @@ describe Mongoid::NestedAttributes do
|
|
4740
4622
|
end
|
4741
4623
|
|
4742
4624
|
before do
|
4743
|
-
person.
|
4625
|
+
person.update_attributes(attributes)
|
4744
4626
|
end
|
4745
4627
|
|
4746
4628
|
it "updates the first level embedded document" do
|
4747
|
-
address.number.
|
4629
|
+
expect(address.number).to eq(45)
|
4748
4630
|
end
|
4749
4631
|
|
4750
4632
|
it "updates the nested embedded document" do
|
4751
|
-
code.name.
|
4633
|
+
expect(code.name).to eq("Work")
|
4752
4634
|
end
|
4753
4635
|
end
|
4754
4636
|
|
@@ -4780,15 +4662,15 @@ describe Mongoid::NestedAttributes do
|
|
4780
4662
|
end
|
4781
4663
|
|
4782
4664
|
before do
|
4783
|
-
person.
|
4665
|
+
person.update_attributes(attributes)
|
4784
4666
|
end
|
4785
4667
|
|
4786
4668
|
it "updates the first level embedded document" do
|
4787
|
-
address.number.
|
4669
|
+
expect(address.number).to eq(45)
|
4788
4670
|
end
|
4789
4671
|
|
4790
4672
|
it "updates the nested embedded document" do
|
4791
|
-
target.name.
|
4673
|
+
expect(target.name).to eq("updated")
|
4792
4674
|
end
|
4793
4675
|
end
|
4794
4676
|
|
@@ -4816,11 +4698,11 @@ describe Mongoid::NestedAttributes do
|
|
4816
4698
|
end
|
4817
4699
|
|
4818
4700
|
before do
|
4819
|
-
person.
|
4701
|
+
person.update_attributes(attributes)
|
4820
4702
|
end
|
4821
4703
|
|
4822
4704
|
it "updates the nested embedded document" do
|
4823
|
-
language.name.
|
4705
|
+
expect(language.name).to eq("deutsch")
|
4824
4706
|
end
|
4825
4707
|
end
|
4826
4708
|
end
|
@@ -4851,11 +4733,11 @@ describe Mongoid::NestedAttributes do
|
|
4851
4733
|
end
|
4852
4734
|
|
4853
4735
|
it "adds the new document to the relation" do
|
4854
|
-
post.title.
|
4736
|
+
expect(post.title).to eq("Testing")
|
4855
4737
|
end
|
4856
4738
|
|
4857
4739
|
it "autosaves the relation" do
|
4858
|
-
user.posts(true).first.title.
|
4740
|
+
expect(user.posts(true).first.title).to eq("Testing")
|
4859
4741
|
end
|
4860
4742
|
end
|
4861
4743
|
|
@@ -4882,15 +4764,15 @@ describe Mongoid::NestedAttributes do
|
|
4882
4764
|
end
|
4883
4765
|
|
4884
4766
|
it "returns false" do
|
4885
|
-
update.
|
4767
|
+
expect(update).to be false
|
4886
4768
|
end
|
4887
4769
|
|
4888
4770
|
it "does not update the child document" do
|
4889
|
-
server.reload.name.
|
4771
|
+
expect(server.reload.name).to eq("test")
|
4890
4772
|
end
|
4891
4773
|
|
4892
4774
|
it "adds the errors to the document" do
|
4893
|
-
node.errors[:servers].
|
4775
|
+
expect(node.errors[:servers]).to_not be_nil
|
4894
4776
|
end
|
4895
4777
|
end
|
4896
4778
|
end
|
@@ -4917,7 +4799,7 @@ describe Mongoid::NestedAttributes do
|
|
4917
4799
|
end
|
4918
4800
|
|
4919
4801
|
it "sets the nested attributes" do
|
4920
|
-
league.reload.divisions.first.name.
|
4802
|
+
expect(league.reload.divisions.first.name).to eq("New Name")
|
4921
4803
|
end
|
4922
4804
|
|
4923
4805
|
context "with corrupted data" do
|
@@ -4937,7 +4819,7 @@ describe Mongoid::NestedAttributes do
|
|
4937
4819
|
end
|
4938
4820
|
|
4939
4821
|
it "sets the nested attributes" do
|
4940
|
-
league.reload.divisions.first.name.
|
4822
|
+
expect(league.reload.divisions.first.name).to eq("Name")
|
4941
4823
|
end
|
4942
4824
|
end
|
4943
4825
|
end
|