mongoid 3.1.6 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- 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
@@ -21,35 +21,35 @@ describe Mongoid::Relations::Embedded::Many do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "appends to the target" do
|
24
|
-
person.addresses.
|
24
|
+
expect(person.addresses).to eq([ address ])
|
25
25
|
end
|
26
26
|
|
27
27
|
it "sets the base on the inverse relation" do
|
28
|
-
address.addressable.
|
28
|
+
expect(address.addressable).to eq(person)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "sets the same instance on the inverse relation" do
|
32
|
-
address.addressable.
|
32
|
+
expect(address.addressable).to eql(person)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "does not save the new document" do
|
36
|
-
address.
|
36
|
+
expect(address).to_not be_persisted
|
37
37
|
end
|
38
38
|
|
39
39
|
it "sets the parent on the child" do
|
40
|
-
address._parent.
|
40
|
+
expect(address._parent).to eq(person)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "sets the metadata on the child" do
|
44
|
-
address.
|
44
|
+
expect(address.__metadata).to_not be_nil
|
45
45
|
end
|
46
46
|
|
47
47
|
it "sets the index on the child" do
|
48
|
-
address._index.
|
48
|
+
expect(address._index).to eq(0)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "returns the relation" do
|
52
|
-
added.
|
52
|
+
expect(added).to eq(person.addresses)
|
53
53
|
end
|
54
54
|
|
55
55
|
context "with a limiting default scope" do
|
@@ -65,11 +65,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "appends to the target" do
|
68
|
-
person.appointments.target.
|
68
|
+
expect(person.appointments.target).to eq([ active ])
|
69
69
|
end
|
70
70
|
|
71
71
|
it "appends to the _unscoped" do
|
72
|
-
person.appointments.send(:_unscoped).
|
72
|
+
expect(person.appointments.send(:_unscoped)).to eq([ active ])
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -84,11 +84,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "doesn't append to the target" do
|
87
|
-
person.appointments.target.
|
87
|
+
expect(person.appointments.target).to_not eq([ inactive ])
|
88
88
|
end
|
89
89
|
|
90
90
|
it "appends to the _unscoped" do
|
91
|
-
person.appointments.send(:_unscoped).
|
91
|
+
expect(person.appointments.send(:_unscoped)).to eq([ inactive ])
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -109,7 +109,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
it "saves the new document" do
|
112
|
-
address.
|
112
|
+
expect(address).to be_persisted
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -132,15 +132,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "saves the first document" do
|
135
|
-
address_one.
|
135
|
+
expect(address_one).to be_persisted
|
136
136
|
end
|
137
137
|
|
138
138
|
it "saves the second document" do
|
139
|
-
address_two.
|
139
|
+
expect(address_two).to be_persisted
|
140
140
|
end
|
141
141
|
|
142
142
|
it "returns the relation" do
|
143
|
-
added.
|
143
|
+
expect(added).to eq(person.addresses)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -161,31 +161,31 @@ describe Mongoid::Relations::Embedded::Many do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it "appends to the target" do
|
164
|
-
parent_role.child_roles.
|
164
|
+
expect(parent_role.child_roles).to eq([ child_role ])
|
165
165
|
end
|
166
166
|
|
167
167
|
it "sets the base on the inverse relation" do
|
168
|
-
child_role.parent_role.
|
168
|
+
expect(child_role.parent_role).to eq(parent_role)
|
169
169
|
end
|
170
170
|
|
171
171
|
it "sets the same instance on the inverse relation" do
|
172
|
-
child_role.parent_role.
|
172
|
+
expect(child_role.parent_role).to eql(parent_role)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "does not save the new document" do
|
176
|
-
child_role.
|
176
|
+
expect(child_role).to_not be_persisted
|
177
177
|
end
|
178
178
|
|
179
179
|
it "sets the parent on the child" do
|
180
|
-
child_role._parent.
|
180
|
+
expect(child_role._parent).to eq(parent_role)
|
181
181
|
end
|
182
182
|
|
183
183
|
it "sets the metadata on the child" do
|
184
|
-
child_role.
|
184
|
+
expect(child_role.__metadata).to_not be_nil
|
185
185
|
end
|
186
186
|
|
187
187
|
it "sets the index on the child" do
|
188
|
-
child_role._index.
|
188
|
+
expect(child_role._index).to eq(0)
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -204,7 +204,38 @@ describe Mongoid::Relations::Embedded::Many do
|
|
204
204
|
end
|
205
205
|
|
206
206
|
it "saves the new document" do
|
207
|
-
child_role.
|
207
|
+
expect(child_role).to be_persisted
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "when the child has one sided many to many relation" do
|
213
|
+
let(:person) do
|
214
|
+
Person.create
|
215
|
+
end
|
216
|
+
|
217
|
+
let(:message) do
|
218
|
+
Message.new
|
219
|
+
end
|
220
|
+
|
221
|
+
context "assign parent first" do
|
222
|
+
before do
|
223
|
+
message.person = person
|
224
|
+
message.receviers.send(method, person)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "appends to the relation array" do
|
228
|
+
expect(message.receviers).to include(person)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context "not assign parent" do
|
233
|
+
before do
|
234
|
+
message.receviers.send(method, person)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "appends to the relation array" do
|
238
|
+
expect(message.receviers).to include(person)
|
208
239
|
end
|
209
240
|
end
|
210
241
|
end
|
@@ -228,35 +259,35 @@ describe Mongoid::Relations::Embedded::Many do
|
|
228
259
|
end
|
229
260
|
|
230
261
|
it "sets the target of the relation" do
|
231
|
-
person.addresses.
|
262
|
+
expect(person.addresses).to eq([ address ])
|
232
263
|
end
|
233
264
|
|
234
265
|
it "sets the _unscoped of the relation" do
|
235
|
-
person.addresses.send(:_unscoped).
|
266
|
+
expect(person.addresses.send(:_unscoped)).to eq([ address ])
|
236
267
|
end
|
237
268
|
|
238
269
|
it "sets the base on the inverse relation" do
|
239
|
-
address.addressable.
|
270
|
+
expect(address.addressable).to eq(person)
|
240
271
|
end
|
241
272
|
|
242
273
|
it "sets the same instance on the inverse relation" do
|
243
|
-
address.addressable.
|
274
|
+
expect(address.addressable).to eql(person)
|
244
275
|
end
|
245
276
|
|
246
277
|
it "does not save the target" do
|
247
|
-
address.
|
278
|
+
expect(address).to_not be_persisted
|
248
279
|
end
|
249
280
|
|
250
281
|
it "sets the parent on the child" do
|
251
|
-
address._parent.
|
282
|
+
expect(address._parent).to eq(person)
|
252
283
|
end
|
253
284
|
|
254
285
|
it "sets the metadata on the child" do
|
255
|
-
address.
|
286
|
+
expect(address.__metadata).to_not be_nil
|
256
287
|
end
|
257
288
|
|
258
289
|
it "sets the index on the child" do
|
259
|
-
address._index.
|
290
|
+
expect(address._index).to eq(0)
|
260
291
|
end
|
261
292
|
end
|
262
293
|
|
@@ -277,7 +308,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
277
308
|
end
|
278
309
|
|
279
310
|
it "saves the target" do
|
280
|
-
address.
|
311
|
+
expect(address).to be_persisted
|
281
312
|
end
|
282
313
|
end
|
283
314
|
|
@@ -300,7 +331,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
300
331
|
end
|
301
332
|
|
302
333
|
it "overwrites the existing addresses" do
|
303
|
-
person.reload.addresses.
|
334
|
+
expect(person.reload.addresses).to eq([ new_address ])
|
304
335
|
end
|
305
336
|
end
|
306
337
|
|
@@ -311,11 +342,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
311
342
|
end
|
312
343
|
|
313
344
|
it "sets the relation" do
|
314
|
-
person.addresses.
|
345
|
+
expect(person.addresses).to eq([ address ])
|
315
346
|
end
|
316
347
|
|
317
348
|
it "does not save the target" do
|
318
|
-
address.
|
349
|
+
expect(address).to_not be_persisted
|
319
350
|
end
|
320
351
|
|
321
352
|
context "when setting the relation multiple times" do
|
@@ -330,11 +361,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
330
361
|
end
|
331
362
|
|
332
363
|
it "sets the new documents" do
|
333
|
-
person.addresses.
|
364
|
+
expect(person.addresses).to eq([ address_two ])
|
334
365
|
end
|
335
366
|
|
336
367
|
it "persits only the new documents" do
|
337
|
-
person.reload.addresses.
|
368
|
+
expect(person.reload.addresses).to eq([ address_two ])
|
338
369
|
end
|
339
370
|
end
|
340
371
|
end
|
@@ -364,11 +395,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
364
395
|
end
|
365
396
|
|
366
397
|
it "sets the documents" do
|
367
|
-
doctor.addresses.
|
398
|
+
expect(doctor.addresses).to eq([ address_one ])
|
368
399
|
end
|
369
400
|
|
370
401
|
it "persists the document" do
|
371
|
-
doctor.reload.addresses.
|
402
|
+
expect(doctor.reload.addresses).to eq([ address_one ])
|
372
403
|
end
|
373
404
|
|
374
405
|
context "when setting the relation multiple times" do
|
@@ -383,11 +414,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
383
414
|
end
|
384
415
|
|
385
416
|
it "sets the new documents" do
|
386
|
-
doctor.addresses.
|
417
|
+
expect(doctor.addresses).to eq([ address_two ])
|
387
418
|
end
|
388
419
|
|
389
420
|
it "persits only the new documents" do
|
390
|
-
doctor.reload.addresses.
|
421
|
+
expect(doctor.reload.addresses).to eq([ address_two ])
|
391
422
|
end
|
392
423
|
end
|
393
424
|
end
|
@@ -412,7 +443,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
412
443
|
end
|
413
444
|
|
414
445
|
it "deletes the old documents" do
|
415
|
-
person.reload.addresses.
|
446
|
+
expect(person.reload.addresses).to eq([ address ])
|
416
447
|
end
|
417
448
|
end
|
418
449
|
|
@@ -434,7 +465,6 @@ describe Mongoid::Relations::Embedded::Many do
|
|
434
465
|
field :old_state, type: String
|
435
466
|
field :new_state, type: String
|
436
467
|
field :when_changed, type: DateTime
|
437
|
-
attr_protected :_id
|
438
468
|
embedded_in :tracking_id, class_name: "MyCompany::Model::TrackingId"
|
439
469
|
end
|
440
470
|
end
|
@@ -453,15 +483,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
453
483
|
end
|
454
484
|
|
455
485
|
it "allows creation of the embedded document" do
|
456
|
-
tracking_id.validation_history.size.
|
486
|
+
expect(tracking_id.validation_history.size).to eq(1)
|
457
487
|
end
|
458
488
|
|
459
489
|
it "saves the relation" do
|
460
|
-
history.
|
490
|
+
expect(history).to be_persisted
|
461
491
|
end
|
462
492
|
|
463
493
|
it "remains on reload" do
|
464
|
-
tracking_id.reload.validation_history.size.
|
494
|
+
expect(tracking_id.reload.validation_history.size).to eq(1)
|
465
495
|
end
|
466
496
|
end
|
467
497
|
|
@@ -480,7 +510,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
480
510
|
end
|
481
511
|
|
482
512
|
it "requires an inflection to determine the class" do
|
483
|
-
slave.reload.address_numbers.size.
|
513
|
+
expect(slave.reload.address_numbers.size).to eq(1)
|
484
514
|
end
|
485
515
|
end
|
486
516
|
|
@@ -510,11 +540,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
510
540
|
end
|
511
541
|
|
512
542
|
it "sets the new attributes" do
|
513
|
-
person.addresses.first.city.
|
543
|
+
expect(person.addresses.first.city).to eq("Berlin")
|
514
544
|
end
|
515
545
|
|
516
546
|
it "persists the changes" do
|
517
|
-
person.reload.addresses.first.city.
|
547
|
+
expect(person.reload.addresses.first.city).to eq("Berlin")
|
518
548
|
end
|
519
549
|
end
|
520
550
|
end
|
@@ -546,23 +576,23 @@ describe Mongoid::Relations::Embedded::Many do
|
|
546
576
|
end
|
547
577
|
|
548
578
|
it "sets the new attributes on the address" do
|
549
|
-
person.addresses.first.city.
|
579
|
+
expect(person.addresses.first.city).to eq("Berlin")
|
550
580
|
end
|
551
581
|
|
552
582
|
it "sets the new attributes on the location" do
|
553
|
-
person.addresses.first.locations.first.name.
|
583
|
+
expect(person.addresses.first.locations.first.name).to eq("Home")
|
554
584
|
end
|
555
585
|
|
556
586
|
it "persists the changes to the address" do
|
557
|
-
person.reload.addresses.first.city.
|
587
|
+
expect(person.reload.addresses.first.city).to eq("Berlin")
|
558
588
|
end
|
559
589
|
|
560
590
|
it "persists the changes to the location" do
|
561
|
-
person.reload.addresses.first.locations.first.name.
|
591
|
+
expect(person.reload.addresses.first.locations.first.name).to eq("Home")
|
562
592
|
end
|
563
593
|
|
564
594
|
it "does not persist the locations collection to the person document" do
|
565
|
-
person.reload[:locations].
|
595
|
+
expect(person.reload[:locations]).to be_nil
|
566
596
|
end
|
567
597
|
end
|
568
598
|
end
|
@@ -584,31 +614,31 @@ describe Mongoid::Relations::Embedded::Many do
|
|
584
614
|
end
|
585
615
|
|
586
616
|
it "sets the target of the relation" do
|
587
|
-
parent_role.child_roles.
|
617
|
+
expect(parent_role.child_roles).to eq([ child_role ])
|
588
618
|
end
|
589
619
|
|
590
620
|
it "sets the base on the inverse relation" do
|
591
|
-
child_role.parent_role.
|
621
|
+
expect(child_role.parent_role).to eq(parent_role)
|
592
622
|
end
|
593
623
|
|
594
624
|
it "sets the same instance on the inverse relation" do
|
595
|
-
child_role.parent_role.
|
625
|
+
expect(child_role.parent_role).to eql(parent_role)
|
596
626
|
end
|
597
627
|
|
598
628
|
it "does not save the target" do
|
599
|
-
child_role.
|
629
|
+
expect(child_role).to_not be_persisted
|
600
630
|
end
|
601
631
|
|
602
632
|
it "sets the parent on the child" do
|
603
|
-
child_role._parent.
|
633
|
+
expect(child_role._parent).to eq(parent_role)
|
604
634
|
end
|
605
635
|
|
606
636
|
it "sets the metadata on the child" do
|
607
|
-
child_role.
|
637
|
+
expect(child_role.__metadata).to_not be_nil
|
608
638
|
end
|
609
639
|
|
610
640
|
it "sets the index on the child" do
|
611
|
-
child_role._index.
|
641
|
+
expect(child_role._index).to eq(0)
|
612
642
|
end
|
613
643
|
end
|
614
644
|
|
@@ -627,7 +657,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
627
657
|
end
|
628
658
|
|
629
659
|
it "saves the target" do
|
630
|
-
child_role.
|
660
|
+
expect(child_role).to be_persisted
|
631
661
|
end
|
632
662
|
end
|
633
663
|
end
|
@@ -653,15 +683,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
653
683
|
end
|
654
684
|
|
655
685
|
it "sets the relation to empty" do
|
656
|
-
person.addresses.
|
686
|
+
expect(person.addresses).to be_empty
|
657
687
|
end
|
658
688
|
|
659
689
|
it "sets the unscoped to empty" do
|
660
|
-
person.addresses.send(:_unscoped).
|
690
|
+
expect(person.addresses.send(:_unscoped)).to be_empty
|
661
691
|
end
|
662
692
|
|
663
693
|
it "removes the inverse relation" do
|
664
|
-
address.addressable.
|
694
|
+
expect(address.addressable).to be_nil
|
665
695
|
end
|
666
696
|
end
|
667
697
|
|
@@ -676,7 +706,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
676
706
|
end
|
677
707
|
|
678
708
|
it "sets the relation to empty" do
|
679
|
-
person.addresses.
|
709
|
+
expect(person.addresses).to be_empty
|
680
710
|
end
|
681
711
|
end
|
682
712
|
|
@@ -698,19 +728,19 @@ describe Mongoid::Relations::Embedded::Many do
|
|
698
728
|
end
|
699
729
|
|
700
730
|
it "sets the relation to empty" do
|
701
|
-
person.addresses.
|
731
|
+
expect(person.addresses).to be_empty
|
702
732
|
end
|
703
733
|
|
704
734
|
it "sets the relation to empty in the database" do
|
705
|
-
person.reload.addresses.
|
735
|
+
expect(person.reload.addresses).to be_empty
|
706
736
|
end
|
707
737
|
|
708
738
|
it "removed the inverse relation" do
|
709
|
-
address.addressable.
|
739
|
+
expect(address.addressable).to be_nil
|
710
740
|
end
|
711
741
|
|
712
742
|
it "deletes the child document" do
|
713
|
-
address.
|
743
|
+
expect(address).to be_destroyed
|
714
744
|
end
|
715
745
|
end
|
716
746
|
|
@@ -722,11 +752,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
722
752
|
end
|
723
753
|
|
724
754
|
it "sets the relation to empty" do
|
725
|
-
person.addresses.
|
755
|
+
expect(person.addresses).to be_empty
|
726
756
|
end
|
727
757
|
|
728
758
|
it "deletes the child document" do
|
729
|
-
address.
|
759
|
+
expect(address).to be_destroyed
|
730
760
|
end
|
731
761
|
|
732
762
|
context "when saving the parent" do
|
@@ -737,7 +767,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
737
767
|
end
|
738
768
|
|
739
769
|
it "persists the deletion" do
|
740
|
-
person.addresses.
|
770
|
+
expect(person.addresses).to be_empty
|
741
771
|
end
|
742
772
|
end
|
743
773
|
end
|
@@ -763,11 +793,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
763
793
|
end
|
764
794
|
|
765
795
|
it "sets the relation to empty" do
|
766
|
-
person.addresses.
|
796
|
+
expect(person.addresses).to be_empty
|
767
797
|
end
|
768
798
|
|
769
799
|
it "sets the relation to empty in the database" do
|
770
|
-
reloaded.addresses.
|
800
|
+
expect(reloaded.addresses).to be_empty
|
771
801
|
end
|
772
802
|
end
|
773
803
|
end
|
@@ -790,11 +820,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
790
820
|
end
|
791
821
|
|
792
822
|
it "sets the relation to empty" do
|
793
|
-
parent_role.child_roles.
|
823
|
+
expect(parent_role.child_roles).to be_empty
|
794
824
|
end
|
795
825
|
|
796
826
|
it "removes the inverse relation" do
|
797
|
-
child_role.parent_role.
|
827
|
+
expect(child_role.parent_role).to be_nil
|
798
828
|
end
|
799
829
|
end
|
800
830
|
|
@@ -809,7 +839,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
809
839
|
end
|
810
840
|
|
811
841
|
it "sets the relation to empty" do
|
812
|
-
parent_role.child_roles.
|
842
|
+
expect(parent_role.child_roles).to be_empty
|
813
843
|
end
|
814
844
|
end
|
815
845
|
|
@@ -829,15 +859,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
829
859
|
end
|
830
860
|
|
831
861
|
it "sets the relation to empty" do
|
832
|
-
parent_role.child_roles.
|
862
|
+
expect(parent_role.child_roles).to be_empty
|
833
863
|
end
|
834
864
|
|
835
865
|
it "removed the inverse relation" do
|
836
|
-
child_role.parent_role.
|
866
|
+
expect(child_role.parent_role).to be_nil
|
837
867
|
end
|
838
868
|
|
839
869
|
it "deletes the child document" do
|
840
|
-
child_role.
|
870
|
+
expect(child_role).to be_destroyed
|
841
871
|
end
|
842
872
|
end
|
843
873
|
end
|
@@ -860,7 +890,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
860
890
|
end
|
861
891
|
|
862
892
|
it "returns the documents as an array of hashes" do
|
863
|
-
document.
|
893
|
+
expect(document).to eq([ address.as_document ])
|
864
894
|
end
|
865
895
|
end
|
866
896
|
|
@@ -885,7 +915,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
885
915
|
end
|
886
916
|
|
887
917
|
it "returns the unscoped documents as an array of hashes" do
|
888
|
-
document.
|
918
|
+
expect(document).to eq([ headache.as_document, cough.as_document ])
|
889
919
|
end
|
890
920
|
end
|
891
921
|
|
@@ -908,7 +938,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
908
938
|
end
|
909
939
|
|
910
940
|
it "returns the unscoped documents as an array of hashes" do
|
911
|
-
document.
|
941
|
+
expect(document).to eq([ active.as_document, inactive.as_document ])
|
912
942
|
end
|
913
943
|
end
|
914
944
|
end
|
@@ -918,28 +948,6 @@ describe Mongoid::Relations::Embedded::Many do
|
|
918
948
|
|
919
949
|
describe "#build" do
|
920
950
|
|
921
|
-
context "when providing scoped mass assignment" do
|
922
|
-
|
923
|
-
let(:person) do
|
924
|
-
Person.new
|
925
|
-
end
|
926
|
-
|
927
|
-
let(:video) do
|
928
|
-
person.videos.send(
|
929
|
-
method,
|
930
|
-
{ title: "Inception", year: 1999 }, as: :admin
|
931
|
-
)
|
932
|
-
end
|
933
|
-
|
934
|
-
it "sets the attributes for the provided role" do
|
935
|
-
video.title.should eq("Inception")
|
936
|
-
end
|
937
|
-
|
938
|
-
it "does not set the attributes for other roles" do
|
939
|
-
video.year.should be_nil
|
940
|
-
end
|
941
|
-
end
|
942
|
-
|
943
951
|
context "when the relation is not cyclic" do
|
944
952
|
|
945
953
|
let(:person) do
|
@@ -953,39 +961,39 @@ describe Mongoid::Relations::Embedded::Many do
|
|
953
961
|
end
|
954
962
|
|
955
963
|
it "appends to the target" do
|
956
|
-
person.addresses.
|
964
|
+
expect(person.addresses).to eq([ address ])
|
957
965
|
end
|
958
966
|
|
959
967
|
it "appends to the unscoped" do
|
960
|
-
person.addresses.send(:_unscoped).
|
968
|
+
expect(person.addresses.send(:_unscoped)).to eq([ address ])
|
961
969
|
end
|
962
970
|
|
963
971
|
it "sets the base on the inverse relation" do
|
964
|
-
address.addressable.
|
972
|
+
expect(address.addressable).to eq(person)
|
965
973
|
end
|
966
974
|
|
967
975
|
it "does not save the new document" do
|
968
|
-
address.
|
976
|
+
expect(address).to_not be_persisted
|
969
977
|
end
|
970
978
|
|
971
979
|
it "sets the parent on the child" do
|
972
|
-
address._parent.
|
980
|
+
expect(address._parent).to eq(person)
|
973
981
|
end
|
974
982
|
|
975
983
|
it "sets the metadata on the child" do
|
976
|
-
address.
|
984
|
+
expect(address.__metadata).to_not be_nil
|
977
985
|
end
|
978
986
|
|
979
987
|
it "sets the index on the child" do
|
980
|
-
address._index.
|
988
|
+
expect(address._index).to eq(0)
|
981
989
|
end
|
982
990
|
|
983
991
|
it "writes to the attributes" do
|
984
|
-
address.street.
|
992
|
+
expect(address.street).to eq("Bond")
|
985
993
|
end
|
986
994
|
|
987
995
|
it "calls the passed block" do
|
988
|
-
address.state.
|
996
|
+
expect(address.state).to eq("CA")
|
989
997
|
end
|
990
998
|
end
|
991
999
|
|
@@ -1000,31 +1008,31 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1000
1008
|
end
|
1001
1009
|
|
1002
1010
|
it "appends to the target" do
|
1003
|
-
parent_role.child_roles.
|
1011
|
+
expect(parent_role.child_roles).to eq([ child_role ])
|
1004
1012
|
end
|
1005
1013
|
|
1006
1014
|
it "sets the base on the inverse relation" do
|
1007
|
-
child_role.parent_role.
|
1015
|
+
expect(child_role.parent_role).to eq(parent_role)
|
1008
1016
|
end
|
1009
1017
|
|
1010
1018
|
it "does not save the new document" do
|
1011
|
-
child_role.
|
1019
|
+
expect(child_role).to_not be_persisted
|
1012
1020
|
end
|
1013
1021
|
|
1014
1022
|
it "sets the parent on the child" do
|
1015
|
-
child_role._parent.
|
1023
|
+
expect(child_role._parent).to eq(parent_role)
|
1016
1024
|
end
|
1017
1025
|
|
1018
1026
|
it "sets the metadata on the child" do
|
1019
|
-
child_role.
|
1027
|
+
expect(child_role.__metadata).to_not be_nil
|
1020
1028
|
end
|
1021
1029
|
|
1022
1030
|
it "sets the index on the child" do
|
1023
|
-
child_role._index.
|
1031
|
+
expect(child_role._index).to eq(0)
|
1024
1032
|
end
|
1025
1033
|
|
1026
1034
|
it "writes to the attributes" do
|
1027
|
-
child_role.name.
|
1035
|
+
expect(child_role.name).to eq("CTO")
|
1028
1036
|
end
|
1029
1037
|
end
|
1030
1038
|
|
@@ -1053,7 +1061,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1053
1061
|
end
|
1054
1062
|
|
1055
1063
|
it "persists the deeply embedded document" do
|
1056
|
-
location.name.
|
1064
|
+
expect(location.name).to eq("Home")
|
1057
1065
|
end
|
1058
1066
|
end
|
1059
1067
|
end
|
@@ -1083,8 +1091,9 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1083
1091
|
end
|
1084
1092
|
|
1085
1093
|
it "returns the many builder" do
|
1086
|
-
|
1087
|
-
|
1094
|
+
expect(
|
1095
|
+
described_class.builder(base, metadata, document)
|
1096
|
+
).to be_a(Mongoid::Relations::Builders::Embedded::Many)
|
1088
1097
|
end
|
1089
1098
|
end
|
1090
1099
|
|
@@ -1107,23 +1116,23 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1107
1116
|
end
|
1108
1117
|
|
1109
1118
|
it "clears out the relation" do
|
1110
|
-
person.addresses.
|
1119
|
+
expect(person.addresses).to be_empty
|
1111
1120
|
end
|
1112
1121
|
|
1113
1122
|
it "clears the unscoped" do
|
1114
|
-
person.addresses.send(:_unscoped).
|
1123
|
+
expect(person.addresses.send(:_unscoped)).to be_empty
|
1115
1124
|
end
|
1116
1125
|
|
1117
1126
|
it "marks the documents as deleted" do
|
1118
|
-
address.
|
1127
|
+
expect(address).to be_destroyed
|
1119
1128
|
end
|
1120
1129
|
|
1121
1130
|
it "deletes the documents from the db" do
|
1122
|
-
person.reload.addresses.
|
1131
|
+
expect(person.reload.addresses).to be_empty
|
1123
1132
|
end
|
1124
1133
|
|
1125
1134
|
it "returns the relation" do
|
1126
|
-
relation.
|
1135
|
+
expect(relation).to be_empty
|
1127
1136
|
end
|
1128
1137
|
end
|
1129
1138
|
|
@@ -1138,7 +1147,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1138
1147
|
end
|
1139
1148
|
|
1140
1149
|
it "clears out the relation" do
|
1141
|
-
person.addresses.
|
1150
|
+
expect(person.addresses).to be_empty
|
1142
1151
|
end
|
1143
1152
|
end
|
1144
1153
|
end
|
@@ -1158,7 +1167,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1158
1167
|
end
|
1159
1168
|
|
1160
1169
|
it "clears out the relation" do
|
1161
|
-
person.addresses.
|
1170
|
+
expect(person.addresses).to be_empty
|
1162
1171
|
end
|
1163
1172
|
end
|
1164
1173
|
end
|
@@ -1180,35 +1189,35 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1180
1189
|
end
|
1181
1190
|
|
1182
1191
|
it "appends to the target" do
|
1183
|
-
person.addresses.
|
1192
|
+
expect(person.addresses).to eq([ address ])
|
1184
1193
|
end
|
1185
1194
|
|
1186
1195
|
it "appends to the unscoped" do
|
1187
|
-
person.addresses.send(:_unscoped).
|
1196
|
+
expect(person.addresses.send(:_unscoped)).to eq([ address ])
|
1188
1197
|
end
|
1189
1198
|
|
1190
1199
|
it "sets the base on the inverse relation" do
|
1191
|
-
address.addressable.
|
1200
|
+
expect(address.addressable).to eq(person)
|
1192
1201
|
end
|
1193
1202
|
|
1194
1203
|
it "sets the same instance on the inverse relation" do
|
1195
|
-
address.addressable.
|
1204
|
+
expect(address.addressable).to eql(person)
|
1196
1205
|
end
|
1197
1206
|
|
1198
1207
|
it "does not save the new document" do
|
1199
|
-
address.
|
1208
|
+
expect(address).to_not be_persisted
|
1200
1209
|
end
|
1201
1210
|
|
1202
1211
|
it "sets the parent on the child" do
|
1203
|
-
address._parent.
|
1212
|
+
expect(address._parent).to eq(person)
|
1204
1213
|
end
|
1205
1214
|
|
1206
1215
|
it "sets the metadata on the child" do
|
1207
|
-
address.
|
1216
|
+
expect(address.__metadata).to_not be_nil
|
1208
1217
|
end
|
1209
1218
|
|
1210
1219
|
it "sets the index on the child" do
|
1211
|
-
address._index.
|
1220
|
+
expect(address._index).to eq(0)
|
1212
1221
|
end
|
1213
1222
|
end
|
1214
1223
|
|
@@ -1227,7 +1236,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1227
1236
|
end
|
1228
1237
|
|
1229
1238
|
it "saves the new document" do
|
1230
|
-
address.
|
1239
|
+
expect(address).to be_persisted
|
1231
1240
|
end
|
1232
1241
|
end
|
1233
1242
|
|
@@ -1238,12 +1247,12 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1238
1247
|
end
|
1239
1248
|
|
1240
1249
|
before do
|
1241
|
-
person.addresses.
|
1250
|
+
expect(person.addresses).to_not receive(:batch_insert)
|
1242
1251
|
person.addresses.concat([])
|
1243
1252
|
end
|
1244
1253
|
|
1245
1254
|
it "doesn't update the target" do
|
1246
|
-
person.addresses.
|
1255
|
+
expect(person.addresses).to be_empty
|
1247
1256
|
end
|
1248
1257
|
end
|
1249
1258
|
|
@@ -1266,11 +1275,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1266
1275
|
end
|
1267
1276
|
|
1268
1277
|
it "saves the first document" do
|
1269
|
-
address_one.
|
1278
|
+
expect(address_one).to be_persisted
|
1270
1279
|
end
|
1271
1280
|
|
1272
1281
|
it "saves the second document" do
|
1273
|
-
address_two.
|
1282
|
+
expect(address_two).to be_persisted
|
1274
1283
|
end
|
1275
1284
|
end
|
1276
1285
|
|
@@ -1291,31 +1300,31 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1291
1300
|
end
|
1292
1301
|
|
1293
1302
|
it "appends to the target" do
|
1294
|
-
parent_role.child_roles.
|
1303
|
+
expect(parent_role.child_roles).to eq([ child_role ])
|
1295
1304
|
end
|
1296
1305
|
|
1297
1306
|
it "sets the base on the inverse relation" do
|
1298
|
-
child_role.parent_role.
|
1307
|
+
expect(child_role.parent_role).to eq(parent_role)
|
1299
1308
|
end
|
1300
1309
|
|
1301
1310
|
it "sets the same instance on the inverse relation" do
|
1302
|
-
child_role.parent_role.
|
1311
|
+
expect(child_role.parent_role).to eql(parent_role)
|
1303
1312
|
end
|
1304
1313
|
|
1305
1314
|
it "does not save the new document" do
|
1306
|
-
child_role.
|
1315
|
+
expect(child_role).to_not be_persisted
|
1307
1316
|
end
|
1308
1317
|
|
1309
1318
|
it "sets the parent on the child" do
|
1310
|
-
child_role._parent.
|
1319
|
+
expect(child_role._parent).to eq(parent_role)
|
1311
1320
|
end
|
1312
1321
|
|
1313
1322
|
it "sets the metadata on the child" do
|
1314
|
-
child_role.
|
1323
|
+
expect(child_role.__metadata).to_not be_nil
|
1315
1324
|
end
|
1316
1325
|
|
1317
1326
|
it "sets the index on the child" do
|
1318
|
-
child_role._index.
|
1327
|
+
expect(child_role._index).to eq(0)
|
1319
1328
|
end
|
1320
1329
|
end
|
1321
1330
|
|
@@ -1334,7 +1343,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1334
1343
|
end
|
1335
1344
|
|
1336
1345
|
it "saves the new document" do
|
1337
|
-
child_role.
|
1346
|
+
expect(child_role).to be_persisted
|
1338
1347
|
end
|
1339
1348
|
end
|
1340
1349
|
end
|
@@ -1352,30 +1361,36 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1352
1361
|
end
|
1353
1362
|
|
1354
1363
|
it "returns the number of persisted documents" do
|
1355
|
-
person.addresses.count.
|
1364
|
+
expect(person.addresses.count).to eq(1)
|
1356
1365
|
end
|
1357
1366
|
end
|
1358
1367
|
|
1359
1368
|
describe "#create" do
|
1360
1369
|
|
1361
|
-
context "when providing
|
1370
|
+
context "when providing multiple attributes" do
|
1362
1371
|
|
1363
1372
|
let(:person) do
|
1364
1373
|
Person.create
|
1365
1374
|
end
|
1366
1375
|
|
1367
|
-
let(:
|
1368
|
-
person.
|
1369
|
-
|
1370
|
-
|
1376
|
+
let!(:addresses) do
|
1377
|
+
person.addresses.create([{ street: "Bond" }, { street: "Upper" }])
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
it "creates multiple documents" do
|
1381
|
+
expect(addresses.size).to eq(2)
|
1371
1382
|
end
|
1372
1383
|
|
1373
|
-
it "sets the attributes
|
1374
|
-
|
1384
|
+
it "sets the first attributes" do
|
1385
|
+
expect(addresses.first.street).to eq("Bond")
|
1375
1386
|
end
|
1376
1387
|
|
1377
|
-
it "
|
1378
|
-
|
1388
|
+
it "sets the second attributes" do
|
1389
|
+
expect(addresses.last.street).to eq("Upper")
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
it "persists the children" do
|
1393
|
+
expect(person.addresses.count).to eq(2)
|
1379
1394
|
end
|
1380
1395
|
end
|
1381
1396
|
|
@@ -1392,39 +1407,39 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1392
1407
|
end
|
1393
1408
|
|
1394
1409
|
it "appends to the target" do
|
1395
|
-
person.reload.addresses.
|
1410
|
+
expect(person.reload.addresses).to eq([ address ])
|
1396
1411
|
end
|
1397
1412
|
|
1398
1413
|
it "appends to the unscoped" do
|
1399
|
-
person.reload.addresses.send(:_unscoped).
|
1414
|
+
expect(person.reload.addresses.send(:_unscoped)).to eq([ address ])
|
1400
1415
|
end
|
1401
1416
|
|
1402
1417
|
it "sets the base on the inverse relation" do
|
1403
|
-
address.addressable.
|
1418
|
+
expect(address.addressable).to eq(person)
|
1404
1419
|
end
|
1405
1420
|
|
1406
1421
|
it "saves the document" do
|
1407
|
-
address.
|
1422
|
+
expect(address).to be_persisted
|
1408
1423
|
end
|
1409
1424
|
|
1410
1425
|
it "sets the parent on the child" do
|
1411
|
-
address._parent.
|
1426
|
+
expect(address._parent).to eq(person)
|
1412
1427
|
end
|
1413
1428
|
|
1414
1429
|
it "sets the metadata on the child" do
|
1415
|
-
address.
|
1430
|
+
expect(address.__metadata).to_not be_nil
|
1416
1431
|
end
|
1417
1432
|
|
1418
1433
|
it "sets the index on the child" do
|
1419
|
-
address._index.
|
1434
|
+
expect(address._index).to eq(0)
|
1420
1435
|
end
|
1421
1436
|
|
1422
1437
|
it "writes to the attributes" do
|
1423
|
-
address.street.
|
1438
|
+
expect(address.street).to eq("Bond")
|
1424
1439
|
end
|
1425
1440
|
|
1426
1441
|
it "calls the passed block" do
|
1427
|
-
address.state.
|
1442
|
+
expect(address.state).to eq("CA")
|
1428
1443
|
end
|
1429
1444
|
|
1430
1445
|
context "when embedding a multi word named document" do
|
@@ -1434,7 +1449,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1434
1449
|
end
|
1435
1450
|
|
1436
1451
|
it "saves the embedded document" do
|
1437
|
-
person.reload.address_components.first.
|
1452
|
+
expect(person.reload.address_components.first).to eq(component)
|
1438
1453
|
end
|
1439
1454
|
end
|
1440
1455
|
end
|
@@ -1450,7 +1465,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1450
1465
|
end
|
1451
1466
|
|
1452
1467
|
it "creates a new child" do
|
1453
|
-
child_entry.
|
1468
|
+
expect(child_entry).to be_persisted
|
1454
1469
|
end
|
1455
1470
|
end
|
1456
1471
|
end
|
@@ -1461,20 +1476,26 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1461
1476
|
Person.create
|
1462
1477
|
end
|
1463
1478
|
|
1464
|
-
context "when providing
|
1479
|
+
context "when providing multiple attributes" do
|
1465
1480
|
|
1466
|
-
let(:
|
1467
|
-
person.
|
1468
|
-
{ title: "Inception", year: 1999 }, as: :admin
|
1469
|
-
)
|
1481
|
+
let!(:addresses) do
|
1482
|
+
person.addresses.create!([{ street: "Bond" }, { street: "Upper" }])
|
1470
1483
|
end
|
1471
1484
|
|
1472
|
-
it "
|
1473
|
-
|
1485
|
+
it "creates multiple documents" do
|
1486
|
+
expect(addresses.size).to eq(2)
|
1474
1487
|
end
|
1475
1488
|
|
1476
|
-
it "
|
1477
|
-
|
1489
|
+
it "sets the first attributes" do
|
1490
|
+
expect(addresses.first.street).to eq("Bond")
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
it "sets the second attributes" do
|
1494
|
+
expect(addresses.last.street).to eq("Upper")
|
1495
|
+
end
|
1496
|
+
|
1497
|
+
it "persists the children" do
|
1498
|
+
expect(person.addresses.count).to eq(2)
|
1478
1499
|
end
|
1479
1500
|
end
|
1480
1501
|
|
@@ -1485,35 +1506,35 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1485
1506
|
end
|
1486
1507
|
|
1487
1508
|
it "appends to the target" do
|
1488
|
-
person.addresses.
|
1509
|
+
expect(person.addresses).to eq([ address ])
|
1489
1510
|
end
|
1490
1511
|
|
1491
1512
|
it "appends to the unscoped" do
|
1492
|
-
person.addresses.send(:_unscoped).
|
1513
|
+
expect(person.addresses.send(:_unscoped)).to eq([ address ])
|
1493
1514
|
end
|
1494
1515
|
|
1495
1516
|
it "sets the base on the inverse relation" do
|
1496
|
-
address.addressable.
|
1517
|
+
expect(address.addressable).to eq(person)
|
1497
1518
|
end
|
1498
1519
|
|
1499
1520
|
it "saves the document" do
|
1500
|
-
address.
|
1521
|
+
expect(address).to be_persisted
|
1501
1522
|
end
|
1502
1523
|
|
1503
1524
|
it "sets the parent on the child" do
|
1504
|
-
address._parent.
|
1525
|
+
expect(address._parent).to eq(person)
|
1505
1526
|
end
|
1506
1527
|
|
1507
1528
|
it "sets the metadata on the child" do
|
1508
|
-
address.
|
1529
|
+
expect(address.__metadata).to_not be_nil
|
1509
1530
|
end
|
1510
1531
|
|
1511
1532
|
it "sets the index on the child" do
|
1512
|
-
address._index.
|
1533
|
+
expect(address._index).to eq(0)
|
1513
1534
|
end
|
1514
1535
|
|
1515
1536
|
it "writes to the attributes" do
|
1516
|
-
address.street.
|
1537
|
+
expect(address.street).to eq("Bond")
|
1517
1538
|
end
|
1518
1539
|
end
|
1519
1540
|
|
@@ -1552,26 +1573,26 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1552
1573
|
end
|
1553
1574
|
|
1554
1575
|
it "deletes the document" do
|
1555
|
-
person.addresses.
|
1576
|
+
expect(person.addresses).to eq([ address_two ])
|
1556
1577
|
end
|
1557
1578
|
|
1558
1579
|
it "deletes the document from the unscoped" do
|
1559
|
-
person.addresses.send(:_unscoped).
|
1580
|
+
expect(person.addresses.send(:_unscoped)).to eq([ address_two ])
|
1560
1581
|
end
|
1561
1582
|
|
1562
1583
|
it "reindexes the relation" do
|
1563
|
-
address_two._index.
|
1584
|
+
expect(address_two._index).to eq(0)
|
1564
1585
|
end
|
1565
1586
|
|
1566
1587
|
it "returns the document" do
|
1567
|
-
deleted.
|
1588
|
+
expect(deleted).to eq(address_one)
|
1568
1589
|
end
|
1569
1590
|
end
|
1570
1591
|
|
1571
1592
|
context "when the document does not exist" do
|
1572
1593
|
|
1573
1594
|
it "returns nil" do
|
1574
|
-
person.addresses.delete(Address.new).
|
1595
|
+
expect(person.addresses.delete(Address.new)).to be_nil
|
1575
1596
|
end
|
1576
1597
|
end
|
1577
1598
|
end
|
@@ -1601,15 +1622,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1601
1622
|
end
|
1602
1623
|
|
1603
1624
|
it "removes the matching documents" do
|
1604
|
-
person.addresses.size.
|
1625
|
+
expect(person.addresses.size).to eq(1)
|
1605
1626
|
end
|
1606
1627
|
|
1607
1628
|
it "removes from the unscoped" do
|
1608
|
-
person.addresses.send(:_unscoped).size.
|
1629
|
+
expect(person.addresses.send(:_unscoped).size).to eq(1)
|
1609
1630
|
end
|
1610
1631
|
|
1611
1632
|
it "returns the relation" do
|
1612
|
-
deleted.
|
1633
|
+
expect(deleted).to eq(person.addresses)
|
1613
1634
|
end
|
1614
1635
|
end
|
1615
1636
|
|
@@ -1620,7 +1641,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1620
1641
|
end
|
1621
1642
|
|
1622
1643
|
it "returns an enumerator" do
|
1623
|
-
deleted.
|
1644
|
+
expect(deleted).to be_a(Enumerator)
|
1624
1645
|
end
|
1625
1646
|
end
|
1626
1647
|
end
|
@@ -1644,15 +1665,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1644
1665
|
end
|
1645
1666
|
|
1646
1667
|
it "deletes the matching documents" do
|
1647
|
-
person.addresses.count.
|
1668
|
+
expect(person.addresses.count).to eq(1)
|
1648
1669
|
end
|
1649
1670
|
|
1650
1671
|
it "deletes the matching documents from the db" do
|
1651
|
-
person.reload.addresses.count.
|
1672
|
+
expect(person.reload.addresses.count).to eq(1)
|
1652
1673
|
end
|
1653
1674
|
|
1654
1675
|
it "returns the relation" do
|
1655
|
-
deleted.
|
1676
|
+
expect(deleted).to eq(person.addresses)
|
1656
1677
|
end
|
1657
1678
|
end
|
1658
1679
|
end
|
@@ -1668,15 +1689,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1668
1689
|
end
|
1669
1690
|
|
1670
1691
|
it "deletes the matching documents" do
|
1671
|
-
person.addresses.count.
|
1692
|
+
expect(person.addresses.count).to eq(0)
|
1672
1693
|
end
|
1673
1694
|
|
1674
1695
|
it "deletes all the documents from the db" do
|
1675
|
-
person.reload.addresses.count.
|
1696
|
+
expect(person.reload.addresses.count).to eq(0)
|
1676
1697
|
end
|
1677
1698
|
|
1678
1699
|
it "returns the relation" do
|
1679
|
-
deleted.
|
1700
|
+
expect(deleted).to eq(person.addresses)
|
1680
1701
|
end
|
1681
1702
|
end
|
1682
1703
|
end
|
@@ -1710,15 +1731,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1710
1731
|
end
|
1711
1732
|
|
1712
1733
|
it "removes the matching documents" do
|
1713
|
-
person.addresses.size.
|
1734
|
+
expect(person.addresses.size).to eq(1)
|
1714
1735
|
end
|
1715
1736
|
|
1716
1737
|
it "removes from the unscoped" do
|
1717
|
-
person.addresses.send(:_unscoped).size.
|
1738
|
+
expect(person.addresses.send(:_unscoped).size).to eq(1)
|
1718
1739
|
end
|
1719
1740
|
|
1720
1741
|
it "returns the number deleted" do
|
1721
|
-
deleted.
|
1742
|
+
expect(deleted).to eq(1)
|
1722
1743
|
end
|
1723
1744
|
end
|
1724
1745
|
|
@@ -1729,11 +1750,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1729
1750
|
end
|
1730
1751
|
|
1731
1752
|
it "removes all documents" do
|
1732
|
-
person.addresses.size.
|
1753
|
+
expect(person.addresses.size).to eq(0)
|
1733
1754
|
end
|
1734
1755
|
|
1735
1756
|
it "returns the number deleted" do
|
1736
|
-
deleted.
|
1757
|
+
expect(deleted).to eq(2)
|
1737
1758
|
end
|
1738
1759
|
end
|
1739
1760
|
end
|
@@ -1758,15 +1779,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1758
1779
|
end
|
1759
1780
|
|
1760
1781
|
it "deletes the matching documents" do
|
1761
|
-
person.addresses.count.
|
1782
|
+
expect(person.addresses.count).to eq(1)
|
1762
1783
|
end
|
1763
1784
|
|
1764
1785
|
it "deletes the matching documents from the db" do
|
1765
|
-
person.reload.addresses.count.
|
1786
|
+
expect(person.reload.addresses.count).to eq(1)
|
1766
1787
|
end
|
1767
1788
|
|
1768
1789
|
it "returns the number deleted" do
|
1769
|
-
deleted.
|
1790
|
+
expect(deleted).to eq(1)
|
1770
1791
|
end
|
1771
1792
|
end
|
1772
1793
|
|
@@ -1777,15 +1798,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1777
1798
|
end
|
1778
1799
|
|
1779
1800
|
it "deletes all the documents" do
|
1780
|
-
person.addresses.count.
|
1801
|
+
expect(person.addresses.count).to eq(0)
|
1781
1802
|
end
|
1782
1803
|
|
1783
1804
|
it "deletes all the documents from the db" do
|
1784
|
-
person.reload.addresses.count.
|
1805
|
+
expect(person.reload.addresses.count).to eq(0)
|
1785
1806
|
end
|
1786
1807
|
|
1787
1808
|
it "returns the number deleted" do
|
1788
|
-
deleted.
|
1809
|
+
expect(deleted).to eq(2)
|
1789
1810
|
end
|
1790
1811
|
end
|
1791
1812
|
|
@@ -1803,13 +1824,13 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1803
1824
|
end
|
1804
1825
|
|
1805
1826
|
it "removes the documents" do
|
1806
|
-
owner.pet.vet_visits.
|
1827
|
+
expect(owner.pet.vet_visits).to be_empty
|
1807
1828
|
end
|
1808
1829
|
|
1809
1830
|
it "allows addition and a resave" do
|
1810
1831
|
owner.pet.vet_visits << VetVisit.new(date: Date.today)
|
1811
1832
|
owner.save!
|
1812
|
-
owner.pet.vet_visits.first.
|
1833
|
+
expect(owner.pet.vet_visits.first).to be_persisted
|
1813
1834
|
end
|
1814
1835
|
end
|
1815
1836
|
end
|
@@ -1822,15 +1843,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1822
1843
|
end
|
1823
1844
|
|
1824
1845
|
it "deletes all the documents" do
|
1825
|
-
person.addresses.count.
|
1846
|
+
expect(person.addresses.count).to eq(0)
|
1826
1847
|
end
|
1827
1848
|
|
1828
1849
|
it "deletes all the documents from the db" do
|
1829
|
-
person.reload.addresses.count.
|
1850
|
+
expect(person.reload.addresses.count).to eq(0)
|
1830
1851
|
end
|
1831
1852
|
|
1832
1853
|
it "returns the number deleted" do
|
1833
|
-
deleted.
|
1854
|
+
expect(deleted).to eq(0)
|
1834
1855
|
end
|
1835
1856
|
end
|
1836
1857
|
|
@@ -1844,15 +1865,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1844
1865
|
end
|
1845
1866
|
|
1846
1867
|
it "deletes all the documents" do
|
1847
|
-
person.addresses.count.
|
1868
|
+
expect(person.addresses.count).to eq(0)
|
1848
1869
|
end
|
1849
1870
|
|
1850
1871
|
it "deletes all the documents from the db" do
|
1851
|
-
person.reload.addresses.count.
|
1872
|
+
expect(person.reload.addresses.count).to eq(0)
|
1852
1873
|
end
|
1853
1874
|
|
1854
1875
|
it "returns the number deleted" do
|
1855
|
-
deleted.
|
1876
|
+
expect(deleted).to eq(0)
|
1856
1877
|
end
|
1857
1878
|
end
|
1858
1879
|
|
@@ -1863,15 +1884,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1863
1884
|
end
|
1864
1885
|
|
1865
1886
|
it "deletes all the documents" do
|
1866
|
-
person.addresses.count.
|
1887
|
+
expect(person.addresses.count).to eq(0)
|
1867
1888
|
end
|
1868
1889
|
|
1869
1890
|
it "deletes all the documents from the db" do
|
1870
|
-
person.reload.addresses.count.
|
1891
|
+
expect(person.reload.addresses.count).to eq(0)
|
1871
1892
|
end
|
1872
1893
|
|
1873
1894
|
it "returns the number deleted" do
|
1874
|
-
deleted.
|
1895
|
+
expect(deleted).to eq(0)
|
1875
1896
|
end
|
1876
1897
|
end
|
1877
1898
|
end
|
@@ -1881,14 +1902,14 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1881
1902
|
describe ".embedded?" do
|
1882
1903
|
|
1883
1904
|
it "returns true" do
|
1884
|
-
described_class.
|
1905
|
+
expect(described_class).to be_embedded
|
1885
1906
|
end
|
1886
1907
|
end
|
1887
1908
|
|
1888
1909
|
describe ".foreign_key_suffix" do
|
1889
1910
|
|
1890
1911
|
it "returns nil" do
|
1891
|
-
described_class.foreign_key_suffix.
|
1912
|
+
expect(described_class.foreign_key_suffix).to be_nil
|
1892
1913
|
end
|
1893
1914
|
end
|
1894
1915
|
|
@@ -1905,7 +1926,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1905
1926
|
end
|
1906
1927
|
|
1907
1928
|
it "returns true" do
|
1908
|
-
person.addresses.exists
|
1929
|
+
expect(person.addresses.exists?).to be true
|
1909
1930
|
end
|
1910
1931
|
end
|
1911
1932
|
|
@@ -1916,7 +1937,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1916
1937
|
end
|
1917
1938
|
|
1918
1939
|
it "returns false" do
|
1919
|
-
person.addresses.exists
|
1940
|
+
expect(person.addresses.exists?).to be false
|
1920
1941
|
end
|
1921
1942
|
end
|
1922
1943
|
end
|
@@ -1944,7 +1965,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1944
1965
|
end
|
1945
1966
|
|
1946
1967
|
it "returns the matching document" do
|
1947
|
-
address.
|
1968
|
+
expect(address).to eq(address_one)
|
1948
1969
|
end
|
1949
1970
|
end
|
1950
1971
|
|
@@ -1958,7 +1979,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1958
1979
|
|
1959
1980
|
it "raises an error" do
|
1960
1981
|
expect {
|
1961
|
-
person.addresses.find(
|
1982
|
+
person.addresses.find(BSON::ObjectId.new)
|
1962
1983
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
1963
1984
|
end
|
1964
1985
|
end
|
@@ -1966,7 +1987,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1966
1987
|
context "when config set not to raise error" do
|
1967
1988
|
|
1968
1989
|
let(:address) do
|
1969
|
-
person.addresses.find(
|
1990
|
+
person.addresses.find(BSON::ObjectId.new)
|
1970
1991
|
end
|
1971
1992
|
|
1972
1993
|
before do
|
@@ -1978,7 +1999,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1978
1999
|
end
|
1979
2000
|
|
1980
2001
|
it "returns nil" do
|
1981
|
-
address.
|
2002
|
+
expect(address).to be_nil
|
1982
2003
|
end
|
1983
2004
|
end
|
1984
2005
|
end
|
@@ -1993,7 +2014,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
1993
2014
|
end
|
1994
2015
|
|
1995
2016
|
it "returns the matching documents" do
|
1996
|
-
addresses.
|
2017
|
+
expect(addresses).to eq([ address_one, address_two ])
|
1997
2018
|
end
|
1998
2019
|
end
|
1999
2020
|
|
@@ -2007,7 +2028,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2007
2028
|
|
2008
2029
|
it "raises an error" do
|
2009
2030
|
expect {
|
2010
|
-
person.addresses.find([
|
2031
|
+
person.addresses.find([ BSON::ObjectId.new ])
|
2011
2032
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2012
2033
|
end
|
2013
2034
|
end
|
@@ -2015,7 +2036,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2015
2036
|
context "when config set not to raise error" do
|
2016
2037
|
|
2017
2038
|
let(:addresses) do
|
2018
|
-
person.addresses.find([
|
2039
|
+
person.addresses.find([ BSON::ObjectId.new ])
|
2019
2040
|
end
|
2020
2041
|
|
2021
2042
|
before do
|
@@ -2027,7 +2048,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2027
2048
|
end
|
2028
2049
|
|
2029
2050
|
it "returns an empty array" do
|
2030
|
-
addresses.
|
2051
|
+
expect(addresses).to be_empty
|
2031
2052
|
end
|
2032
2053
|
end
|
2033
2054
|
end
|
@@ -2051,7 +2072,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2051
2072
|
end
|
2052
2073
|
|
2053
2074
|
it "returns the document" do
|
2054
|
-
found.
|
2075
|
+
expect(found).to eq(address)
|
2055
2076
|
end
|
2056
2077
|
end
|
2057
2078
|
|
@@ -2064,15 +2085,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2064
2085
|
end
|
2065
2086
|
|
2066
2087
|
it "sets the new document attributes" do
|
2067
|
-
found.street.
|
2088
|
+
expect(found.street).to eq("King")
|
2068
2089
|
end
|
2069
2090
|
|
2070
2091
|
it "returns a newly persisted document" do
|
2071
|
-
found.
|
2092
|
+
expect(found).to be_persisted
|
2072
2093
|
end
|
2073
2094
|
|
2074
2095
|
it "calls the passed block" do
|
2075
|
-
found.state.
|
2096
|
+
expect(found.state).to eq("CA")
|
2076
2097
|
end
|
2077
2098
|
end
|
2078
2099
|
|
@@ -2094,7 +2115,81 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2094
2115
|
end
|
2095
2116
|
|
2096
2117
|
it "properly creates the document" do
|
2097
|
-
line_item.product.
|
2118
|
+
expect(line_item.product).to eq(product)
|
2119
|
+
end
|
2120
|
+
end
|
2121
|
+
end
|
2122
|
+
|
2123
|
+
describe "#find_or_create_by!" do
|
2124
|
+
|
2125
|
+
let(:person) do
|
2126
|
+
Person.create
|
2127
|
+
end
|
2128
|
+
|
2129
|
+
let!(:address) do
|
2130
|
+
person.addresses.build(street: "Bourke", city: "Melbourne")
|
2131
|
+
end
|
2132
|
+
|
2133
|
+
context "when the document exists" do
|
2134
|
+
|
2135
|
+
let(:found) do
|
2136
|
+
person.addresses.find_or_create_by!(street: "Bourke")
|
2137
|
+
end
|
2138
|
+
|
2139
|
+
it "returns the document" do
|
2140
|
+
expect(found).to eq(address)
|
2141
|
+
end
|
2142
|
+
end
|
2143
|
+
|
2144
|
+
context "when the document does not exist" do
|
2145
|
+
|
2146
|
+
let(:found) do
|
2147
|
+
person.addresses.find_or_create_by!(street: "King") do |address|
|
2148
|
+
address.state = "CA"
|
2149
|
+
end
|
2150
|
+
end
|
2151
|
+
|
2152
|
+
it "sets the new document attributes" do
|
2153
|
+
expect(found.street).to eq("King")
|
2154
|
+
end
|
2155
|
+
|
2156
|
+
it "returns a newly persisted document" do
|
2157
|
+
expect(found).to be_persisted
|
2158
|
+
end
|
2159
|
+
|
2160
|
+
it "calls the passed block" do
|
2161
|
+
expect(found.state).to eq("CA")
|
2162
|
+
end
|
2163
|
+
|
2164
|
+
context "when validation fails" do
|
2165
|
+
|
2166
|
+
it "raises an error" do
|
2167
|
+
expect {
|
2168
|
+
person.addresses.find_or_create_by!(street: "1")
|
2169
|
+
}.to raise_error(Mongoid::Errors::Validations)
|
2170
|
+
end
|
2171
|
+
end
|
2172
|
+
end
|
2173
|
+
|
2174
|
+
context "when the child belongs to another document" do
|
2175
|
+
|
2176
|
+
let(:product) do
|
2177
|
+
Product.create
|
2178
|
+
end
|
2179
|
+
|
2180
|
+
let(:purchase) do
|
2181
|
+
Purchase.create
|
2182
|
+
end
|
2183
|
+
|
2184
|
+
let(:line_item) do
|
2185
|
+
purchase.line_items.find_or_create_by(
|
2186
|
+
product_id: product.id,
|
2187
|
+
product_type: product.class.name
|
2188
|
+
)
|
2189
|
+
end
|
2190
|
+
|
2191
|
+
it "properly creates the document" do
|
2192
|
+
expect(line_item.product).to eq(product)
|
2098
2193
|
end
|
2099
2194
|
end
|
2100
2195
|
end
|
@@ -2116,7 +2211,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2116
2211
|
end
|
2117
2212
|
|
2118
2213
|
it "returns the document" do
|
2119
|
-
found.
|
2214
|
+
expect(found).to eq(address)
|
2120
2215
|
end
|
2121
2216
|
end
|
2122
2217
|
|
@@ -2129,15 +2224,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2129
2224
|
end
|
2130
2225
|
|
2131
2226
|
it "sets the new document attributes" do
|
2132
|
-
found.street.
|
2227
|
+
expect(found.street).to eq("King")
|
2133
2228
|
end
|
2134
2229
|
|
2135
2230
|
it "returns a non persisted document" do
|
2136
|
-
found.
|
2231
|
+
expect(found).to_not be_persisted
|
2137
2232
|
end
|
2138
2233
|
|
2139
2234
|
it "calls the passed block" do
|
2140
|
-
found.state.
|
2235
|
+
expect(found.state).to eq("CA")
|
2141
2236
|
end
|
2142
2237
|
end
|
2143
2238
|
end
|
@@ -2145,7 +2240,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2145
2240
|
describe ".macro" do
|
2146
2241
|
|
2147
2242
|
it "returns embeds_many" do
|
2148
|
-
described_class.macro.
|
2243
|
+
expect(described_class.macro).to eq(:embeds_many)
|
2149
2244
|
end
|
2150
2245
|
end
|
2151
2246
|
|
@@ -2174,7 +2269,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2174
2269
|
end
|
2175
2270
|
|
2176
2271
|
it "returns the document with the max value of the supplied field" do
|
2177
|
-
max.
|
2272
|
+
expect(max).to eq(address_two)
|
2178
2273
|
end
|
2179
2274
|
end
|
2180
2275
|
|
@@ -2201,7 +2296,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2201
2296
|
end
|
2202
2297
|
|
2203
2298
|
it "returns the document with the max value of the supplied field" do
|
2204
|
-
max.
|
2299
|
+
expect(max).to eq(address_two)
|
2205
2300
|
end
|
2206
2301
|
end
|
2207
2302
|
|
@@ -2236,7 +2331,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2236
2331
|
end
|
2237
2332
|
|
2238
2333
|
it "applies the criteria to the documents" do
|
2239
|
-
addresses.
|
2334
|
+
expect(addresses).to eq([ address_one ])
|
2240
2335
|
end
|
2241
2336
|
end
|
2242
2337
|
|
@@ -2247,7 +2342,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2247
2342
|
end
|
2248
2343
|
|
2249
2344
|
it "applies the criteria to the documents" do
|
2250
|
-
addresses.
|
2345
|
+
expect(addresses).to eq([ address_one, address_two ])
|
2251
2346
|
end
|
2252
2347
|
end
|
2253
2348
|
|
@@ -2258,7 +2353,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2258
2353
|
end
|
2259
2354
|
|
2260
2355
|
it "applies the criteria to the documents" do
|
2261
|
-
addresses.
|
2356
|
+
expect(addresses).to eq([ address_one, address_two ])
|
2262
2357
|
end
|
2263
2358
|
end
|
2264
2359
|
end
|
@@ -2270,7 +2365,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2270
2365
|
end
|
2271
2366
|
|
2272
2367
|
it "applies the criteria to the documents" do
|
2273
|
-
addresses.
|
2368
|
+
expect(addresses).to eq([ address_one ])
|
2274
2369
|
end
|
2275
2370
|
end
|
2276
2371
|
|
@@ -2281,7 +2376,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2281
2376
|
end
|
2282
2377
|
|
2283
2378
|
it "applies the criteria to the documents" do
|
2284
|
-
addresses.
|
2379
|
+
expect(addresses).to eq([ address_one ])
|
2285
2380
|
end
|
2286
2381
|
end
|
2287
2382
|
|
@@ -2290,8 +2385,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2290
2385
|
describe "#distinct" do
|
2291
2386
|
|
2292
2387
|
it "returns the distinct values for the fields" do
|
2293
|
-
person.addresses.distinct(:street).
|
2294
|
-
[ "Market", "Madison"]
|
2388
|
+
expect(person.addresses.distinct(:street)).to eq([ "Market", "Madison"])
|
2295
2389
|
end
|
2296
2390
|
end
|
2297
2391
|
end
|
@@ -2322,7 +2416,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2322
2416
|
end
|
2323
2417
|
|
2324
2418
|
it "returns the min value of the supplied field" do
|
2325
|
-
min.
|
2419
|
+
expect(min).to eq(address_one)
|
2326
2420
|
end
|
2327
2421
|
end
|
2328
2422
|
|
@@ -2349,7 +2443,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2349
2443
|
end
|
2350
2444
|
|
2351
2445
|
it "returns the min value of the supplied field" do
|
2352
|
-
min.
|
2446
|
+
expect(min).to eq(address_one)
|
2353
2447
|
end
|
2354
2448
|
end
|
2355
2449
|
|
@@ -2360,8 +2454,9 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2360
2454
|
end
|
2361
2455
|
|
2362
2456
|
it "returns the many nested builder class" do
|
2363
|
-
|
2364
|
-
|
2457
|
+
expect(
|
2458
|
+
described_class.nested_builder(metadata, {}, {})
|
2459
|
+
).to be_a(Mongoid::Relations::Builders::NestedAttributes::Many)
|
2365
2460
|
end
|
2366
2461
|
end
|
2367
2462
|
|
@@ -2386,15 +2481,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2386
2481
|
end
|
2387
2482
|
|
2388
2483
|
it "returns the popped document" do
|
2389
|
-
popped.
|
2484
|
+
expect(popped).to eq(address_two)
|
2390
2485
|
end
|
2391
2486
|
|
2392
2487
|
it "removes the document from the relation" do
|
2393
|
-
person.addresses.
|
2488
|
+
expect(person.addresses).to eq([ address_one ])
|
2394
2489
|
end
|
2395
2490
|
|
2396
2491
|
it "persists the pop" do
|
2397
|
-
person.reload.addresses.
|
2492
|
+
expect(person.reload.addresses).to eq([ address_one ])
|
2398
2493
|
end
|
2399
2494
|
end
|
2400
2495
|
|
@@ -2415,15 +2510,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2415
2510
|
end
|
2416
2511
|
|
2417
2512
|
it "returns the popped documents" do
|
2418
|
-
popped.
|
2513
|
+
expect(popped).to eq([ address_one, address_two ])
|
2419
2514
|
end
|
2420
2515
|
|
2421
2516
|
it "removes the document from the relation" do
|
2422
|
-
person.addresses.
|
2517
|
+
expect(person.addresses).to be_empty
|
2423
2518
|
end
|
2424
2519
|
|
2425
2520
|
it "persists the pop" do
|
2426
|
-
person.reload.addresses.
|
2521
|
+
expect(person.reload.addresses).to be_empty
|
2427
2522
|
end
|
2428
2523
|
end
|
2429
2524
|
|
@@ -2434,15 +2529,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2434
2529
|
end
|
2435
2530
|
|
2436
2531
|
it "returns the popped documents" do
|
2437
|
-
popped.
|
2532
|
+
expect(popped).to eq([ address_one, address_two ])
|
2438
2533
|
end
|
2439
2534
|
|
2440
2535
|
it "removes the document from the relation" do
|
2441
|
-
person.addresses.
|
2536
|
+
expect(person.addresses).to be_empty
|
2442
2537
|
end
|
2443
2538
|
|
2444
2539
|
it "persists the pop" do
|
2445
|
-
person.reload.addresses.
|
2540
|
+
expect(person.reload.addresses).to be_empty
|
2446
2541
|
end
|
2447
2542
|
end
|
2448
2543
|
end
|
@@ -2452,14 +2547,14 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2452
2547
|
context "when providing no number" do
|
2453
2548
|
|
2454
2549
|
it "returns nil" do
|
2455
|
-
person.addresses.pop.
|
2550
|
+
expect(person.addresses.pop).to be_nil
|
2456
2551
|
end
|
2457
2552
|
end
|
2458
2553
|
|
2459
2554
|
context "when providing a number" do
|
2460
2555
|
|
2461
2556
|
it "returns nil" do
|
2462
|
-
person.addresses.pop(2).
|
2557
|
+
expect(person.addresses.pop(2)).to be_nil
|
2463
2558
|
end
|
2464
2559
|
end
|
2465
2560
|
end
|
@@ -2476,11 +2571,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2476
2571
|
end
|
2477
2572
|
|
2478
2573
|
it "returns the relation criteria" do
|
2479
|
-
scoped.
|
2574
|
+
expect(scoped).to be_a(Mongoid::Criteria)
|
2480
2575
|
end
|
2481
2576
|
|
2482
2577
|
it "returns with an empty selector" do
|
2483
|
-
scoped.selector.
|
2578
|
+
expect(scoped.selector).to be_empty
|
2484
2579
|
end
|
2485
2580
|
end
|
2486
2581
|
|
@@ -2499,7 +2594,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2499
2594
|
context "when checking #{method}" do
|
2500
2595
|
|
2501
2596
|
it "returns true" do
|
2502
|
-
addresses.respond_to?(method).
|
2597
|
+
expect(addresses.respond_to?(method)).to be true
|
2503
2598
|
end
|
2504
2599
|
end
|
2505
2600
|
end
|
@@ -2509,7 +2604,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2509
2604
|
context "when checking #{method}" do
|
2510
2605
|
|
2511
2606
|
it "returns true" do
|
2512
|
-
addresses.respond_to?(method).
|
2607
|
+
expect(addresses.respond_to?(method)).to be true
|
2513
2608
|
end
|
2514
2609
|
end
|
2515
2610
|
end
|
@@ -2519,7 +2614,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2519
2614
|
context "when checking #{method}" do
|
2520
2615
|
|
2521
2616
|
it "returns true" do
|
2522
|
-
addresses.respond_to?(method).
|
2617
|
+
expect(addresses.respond_to?(method)).to be true
|
2523
2618
|
end
|
2524
2619
|
end
|
2525
2620
|
end
|
@@ -2543,7 +2638,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2543
2638
|
end
|
2544
2639
|
|
2545
2640
|
it "returns the number of persisted documents" do
|
2546
|
-
person.addresses.send(method).
|
2641
|
+
expect(person.addresses.send(method)).to eq(2)
|
2547
2642
|
end
|
2548
2643
|
end
|
2549
2644
|
end
|
@@ -2559,15 +2654,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2559
2654
|
end
|
2560
2655
|
|
2561
2656
|
it "returns the relation criteria" do
|
2562
|
-
unscoped.
|
2657
|
+
expect(unscoped).to be_a(Mongoid::Criteria)
|
2563
2658
|
end
|
2564
2659
|
|
2565
2660
|
it "returns with empty options" do
|
2566
|
-
unscoped.options.
|
2661
|
+
expect(unscoped.options).to be_empty
|
2567
2662
|
end
|
2568
2663
|
|
2569
2664
|
it "returns with an empty selector" do
|
2570
|
-
unscoped.selector.
|
2665
|
+
expect(unscoped.selector).to be_empty
|
2571
2666
|
end
|
2572
2667
|
end
|
2573
2668
|
|
@@ -2580,7 +2675,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2580
2675
|
end
|
2581
2676
|
|
2582
2677
|
it "updates nothing" do
|
2583
|
-
person.addresses.update_all(street: "test").
|
2678
|
+
expect(person.addresses.update_all(street: "test")).to be false
|
2584
2679
|
end
|
2585
2680
|
end
|
2586
2681
|
|
@@ -2603,19 +2698,19 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2603
2698
|
end
|
2604
2699
|
|
2605
2700
|
it "resets the matching dirty flags" do
|
2606
|
-
address.
|
2701
|
+
expect(address).to_not be_changed
|
2607
2702
|
end
|
2608
2703
|
|
2609
2704
|
it "updates the first field" do
|
2610
|
-
address.reload.number.
|
2705
|
+
expect(address.reload.number).to eq(26)
|
2611
2706
|
end
|
2612
2707
|
|
2613
2708
|
it "updates the second field" do
|
2614
|
-
address.reload.post_code.
|
2709
|
+
expect(address.reload.post_code).to eq("12437")
|
2615
2710
|
end
|
2616
2711
|
|
2617
2712
|
it "does not wipe out other fields" do
|
2618
|
-
address.reload.street.
|
2713
|
+
expect(address.reload.street).to eq("Hobrecht")
|
2619
2714
|
end
|
2620
2715
|
end
|
2621
2716
|
end
|
@@ -2624,9 +2719,9 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2624
2719
|
describe ".valid_options" do
|
2625
2720
|
|
2626
2721
|
it "returns the valid options" do
|
2627
|
-
described_class.valid_options.
|
2722
|
+
expect(described_class.valid_options).to eq(
|
2628
2723
|
[
|
2629
|
-
:as, :cascade_callbacks, :cyclic, :order,
|
2724
|
+
:as, :cascade_callbacks, :cyclic, :order,
|
2630
2725
|
:store_as, :before_add, :after_add, :before_remove, :after_remove
|
2631
2726
|
]
|
2632
2727
|
)
|
@@ -2636,7 +2731,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2636
2731
|
describe ".validation_default" do
|
2637
2732
|
|
2638
2733
|
it "returns true" do
|
2639
|
-
described_class.validation_default.
|
2734
|
+
expect(described_class.validation_default).to be true
|
2640
2735
|
end
|
2641
2736
|
end
|
2642
2737
|
|
@@ -2663,15 +2758,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2663
2758
|
end
|
2664
2759
|
|
2665
2760
|
it "updates the attributes" do
|
2666
|
-
address.locations.first.name.
|
2761
|
+
expect(address.locations.first.name).to eq("home")
|
2667
2762
|
end
|
2668
2763
|
|
2669
2764
|
it "overwrites the existing documents" do
|
2670
|
-
address.locations.count.
|
2765
|
+
expect(address.locations.count).to eq(1)
|
2671
2766
|
end
|
2672
2767
|
|
2673
2768
|
it "persists the changes" do
|
2674
|
-
address.reload.locations.count.
|
2769
|
+
expect(address.reload.locations.count).to eq(1)
|
2675
2770
|
end
|
2676
2771
|
end
|
2677
2772
|
end
|
@@ -2701,15 +2796,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2701
2796
|
end
|
2702
2797
|
|
2703
2798
|
it "sets up the hierarchy" do
|
2704
|
-
animal.circus.
|
2799
|
+
expect(animal.circus).to eq(circus)
|
2705
2800
|
end
|
2706
2801
|
|
2707
2802
|
it "assigns the attributes" do
|
2708
|
-
animal.name.
|
2803
|
+
expect(animal.name).to eq(animal_name)
|
2709
2804
|
end
|
2710
2805
|
|
2711
2806
|
it "uses custom writer methods" do
|
2712
|
-
animal.tag_list.
|
2807
|
+
expect(animal.tag_list).to eq(tag_list)
|
2713
2808
|
end
|
2714
2809
|
end
|
2715
2810
|
|
@@ -2720,15 +2815,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2720
2815
|
end
|
2721
2816
|
|
2722
2817
|
it "sets up the hierarchy" do
|
2723
|
-
animal.circus.
|
2818
|
+
expect(animal.circus).to eq(circus)
|
2724
2819
|
end
|
2725
2820
|
|
2726
2821
|
it "assigns the attributes" do
|
2727
|
-
animal.name.
|
2822
|
+
expect(animal.name).to eq(animal_name)
|
2728
2823
|
end
|
2729
2824
|
|
2730
2825
|
it "uses custom writer methods" do
|
2731
|
-
animal.tag_list.
|
2826
|
+
expect(animal.tag_list).to eq(tag_list)
|
2732
2827
|
end
|
2733
2828
|
end
|
2734
2829
|
end
|
@@ -2757,7 +2852,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2757
2852
|
end
|
2758
2853
|
|
2759
2854
|
it "sets up the hierarchy" do
|
2760
|
-
question.
|
2855
|
+
expect(question).to eq(page_question)
|
2761
2856
|
end
|
2762
2857
|
end
|
2763
2858
|
|
@@ -2780,7 +2875,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2780
2875
|
end
|
2781
2876
|
|
2782
2877
|
it "sets up the hierarchy" do
|
2783
|
-
question.
|
2878
|
+
expect(question).to eq(page_question)
|
2784
2879
|
end
|
2785
2880
|
end
|
2786
2881
|
|
@@ -2808,7 +2903,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2808
2903
|
end
|
2809
2904
|
|
2810
2905
|
it "sets up the hierarchy" do
|
2811
|
-
question.
|
2906
|
+
expect(question).to eq(page_question)
|
2812
2907
|
end
|
2813
2908
|
|
2814
2909
|
context "when reloading" do
|
@@ -2822,7 +2917,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2822
2917
|
end
|
2823
2918
|
|
2824
2919
|
it "reloads the entire tree" do
|
2825
|
-
reloaded_question.
|
2920
|
+
expect(reloaded_question).to eq(question)
|
2826
2921
|
end
|
2827
2922
|
end
|
2828
2923
|
end
|
@@ -2856,11 +2951,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2856
2951
|
end
|
2857
2952
|
|
2858
2953
|
it "persists the first level document" do
|
2859
|
-
person.reload.addresses.first.
|
2954
|
+
expect(person.reload.addresses.first).to eq(address)
|
2860
2955
|
end
|
2861
2956
|
|
2862
2957
|
it "persists the second level document" do
|
2863
|
-
person.reload.addresses[0].locations.
|
2958
|
+
expect(person.reload.addresses[0].locations).to eq([ location ])
|
2864
2959
|
end
|
2865
2960
|
end
|
2866
2961
|
end
|
@@ -2895,7 +2990,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2895
2990
|
|
2896
2991
|
it "ignores the nil and persist the remaining items" do
|
2897
2992
|
reloaded = Person.find(person.id)
|
2898
|
-
reloaded.phone_numbers.
|
2993
|
+
expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
|
2899
2994
|
end
|
2900
2995
|
end
|
2901
2996
|
|
@@ -2916,7 +3011,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2916
3011
|
|
2917
3012
|
it "ignores the nil and persist the remaining items" do
|
2918
3013
|
reloaded = Person.find(person.id)
|
2919
|
-
reloaded.phone_numbers.
|
3014
|
+
expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
|
2920
3015
|
end
|
2921
3016
|
end
|
2922
3017
|
|
@@ -2937,7 +3032,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2937
3032
|
|
2938
3033
|
it "ignores the nil and persist the remaining items" do
|
2939
3034
|
reloaded = Person.find(person.id)
|
2940
|
-
reloaded.phone_numbers.
|
3035
|
+
expect(reloaded.phone_numbers).to eq([ home_phone, office_phone ])
|
2941
3036
|
end
|
2942
3037
|
end
|
2943
3038
|
end
|
@@ -2959,7 +3054,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2959
3054
|
|
2960
3055
|
it "ignores the nil and persist the remaining items" do
|
2961
3056
|
reloaded = Person.find(person.id)
|
2962
|
-
reloaded.phone_numbers.
|
3057
|
+
expect(reloaded.phone_numbers).to eq(person.phone_numbers)
|
2963
3058
|
end
|
2964
3059
|
end
|
2965
3060
|
|
@@ -2978,7 +3073,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2978
3073
|
|
2979
3074
|
it "ignores the nil and persist the remaining items" do
|
2980
3075
|
reloaded = Person.find(person.id)
|
2981
|
-
reloaded.phone_numbers.
|
3076
|
+
expect(reloaded.phone_numbers).to eq(person.phone_numbers)
|
2982
3077
|
end
|
2983
3078
|
end
|
2984
3079
|
|
@@ -2997,7 +3092,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
2997
3092
|
|
2998
3093
|
it "ignores the nil and persist the remaining items" do
|
2999
3094
|
reloaded = Person.find(person.id)
|
3000
|
-
reloaded.phone_numbers.
|
3095
|
+
expect(reloaded.phone_numbers).to eq(person.phone_numbers)
|
3001
3096
|
end
|
3002
3097
|
end
|
3003
3098
|
end
|
@@ -3018,7 +3113,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3018
3113
|
end
|
3019
3114
|
|
3020
3115
|
it "retains the reference to the parent" do
|
3021
|
-
league.name.
|
3116
|
+
expect(league.name).to eq("Destroyed")
|
3022
3117
|
end
|
3023
3118
|
end
|
3024
3119
|
|
@@ -3037,11 +3132,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3037
3132
|
end
|
3038
3133
|
|
3039
3134
|
it "does not duplicate the embedded documents" do
|
3040
|
-
person.addresses.
|
3135
|
+
expect(person.addresses).to eq([ address ])
|
3041
3136
|
end
|
3042
3137
|
|
3043
3138
|
it "does not persist duplicate embedded documents" do
|
3044
|
-
person.reload.addresses.
|
3139
|
+
expect(person.reload.addresses).to eq([ address ])
|
3045
3140
|
end
|
3046
3141
|
end
|
3047
3142
|
|
@@ -3058,7 +3153,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3058
3153
|
end
|
3059
3154
|
|
3060
3155
|
it "allows the operation" do
|
3061
|
-
version.number.
|
3156
|
+
expect(version.number).to eq(1)
|
3062
3157
|
end
|
3063
3158
|
|
3064
3159
|
context "when reloading the parent" do
|
@@ -3068,7 +3163,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3068
3163
|
end
|
3069
3164
|
|
3070
3165
|
it "saves the child versions" do
|
3071
|
-
from_db.versions.
|
3166
|
+
expect(from_db.versions).to eq([ version ])
|
3072
3167
|
end
|
3073
3168
|
end
|
3074
3169
|
end
|
@@ -3095,7 +3190,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3095
3190
|
end
|
3096
3191
|
|
3097
3192
|
it "does not lose the parent reference" do
|
3098
|
-
from_db.memberships.first.account.
|
3193
|
+
expect(from_db.memberships.first.account).to eq(account)
|
3099
3194
|
end
|
3100
3195
|
end
|
3101
3196
|
|
@@ -3106,7 +3201,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3106
3201
|
end
|
3107
3202
|
|
3108
3203
|
it "does not lose the parent reference" do
|
3109
|
-
from_db.memberships.first.account.
|
3204
|
+
expect(from_db.memberships.first.account).to eq(account)
|
3110
3205
|
end
|
3111
3206
|
end
|
3112
3207
|
end
|
@@ -3130,11 +3225,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3130
3225
|
end
|
3131
3226
|
|
3132
3227
|
it "adds the document to the new paarent" do
|
3133
|
-
person_two.addresses.
|
3228
|
+
expect(person_two.addresses).to eq([ address ])
|
3134
3229
|
end
|
3135
3230
|
|
3136
3231
|
it "sets the new parent on the document" do
|
3137
|
-
address._parent.
|
3232
|
+
expect(address._parent).to eq(person_two)
|
3138
3233
|
end
|
3139
3234
|
|
3140
3235
|
context "when reloading the documents" do
|
@@ -3145,11 +3240,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3145
3240
|
end
|
3146
3241
|
|
3147
3242
|
it "persists the change to the new parent" do
|
3148
|
-
person_two.addresses.
|
3243
|
+
expect(person_two.addresses).to eq([ address ])
|
3149
3244
|
end
|
3150
3245
|
|
3151
3246
|
it "keeps the address on the previous document" do
|
3152
|
-
person_one.addresses.
|
3247
|
+
expect(person_one.addresses).to eq([ address ])
|
3153
3248
|
end
|
3154
3249
|
end
|
3155
3250
|
end
|
@@ -3185,7 +3280,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3185
3280
|
end
|
3186
3281
|
|
3187
3282
|
it "applies the default scope" do
|
3188
|
-
symptoms.
|
3283
|
+
expect(symptoms).to eq([ cough, headache, nausea ])
|
3189
3284
|
end
|
3190
3285
|
end
|
3191
3286
|
|
@@ -3206,7 +3301,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3206
3301
|
end
|
3207
3302
|
|
3208
3303
|
it "applies the default scope" do
|
3209
|
-
symptoms.
|
3304
|
+
expect(symptoms).to eq([ constipation, cough, headache, nausea ])
|
3210
3305
|
end
|
3211
3306
|
end
|
3212
3307
|
end
|
@@ -3218,7 +3313,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3218
3313
|
end
|
3219
3314
|
|
3220
3315
|
it "removes the default scope" do
|
3221
|
-
unscoped.
|
3316
|
+
expect(unscoped).to eq([ nausea, cough, headache ])
|
3222
3317
|
end
|
3223
3318
|
end
|
3224
3319
|
end
|
@@ -3249,11 +3344,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3249
3344
|
end
|
3250
3345
|
|
3251
3346
|
it "retains the unscoped index for the excluded document" do
|
3252
|
-
relation.send(:_unscoped).first._index.
|
3347
|
+
expect(relation.send(:_unscoped).first._index).to eq(0)
|
3253
3348
|
end
|
3254
3349
|
|
3255
3350
|
it "retains the unscoped index for the included document" do
|
3256
|
-
relation.first._index.
|
3351
|
+
expect(relation.first._index).to eq(1)
|
3257
3352
|
end
|
3258
3353
|
|
3259
3354
|
context "when a reindexing operation occurs" do
|
@@ -3263,11 +3358,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3263
3358
|
end
|
3264
3359
|
|
3265
3360
|
it "retains the unscoped index for the excluded document" do
|
3266
|
-
relation.send(:_unscoped).first._index.
|
3361
|
+
expect(relation.send(:_unscoped).first._index).to eq(0)
|
3267
3362
|
end
|
3268
3363
|
|
3269
3364
|
it "retains the unscoped index for the included document" do
|
3270
|
-
relation.first._index.
|
3365
|
+
expect(relation.first._index).to eq(1)
|
3271
3366
|
end
|
3272
3367
|
end
|
3273
3368
|
end
|
@@ -3291,11 +3386,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3291
3386
|
end
|
3292
3387
|
|
3293
3388
|
it "sets the value" do
|
3294
|
-
video.genres.
|
3389
|
+
expect(video.genres).to eq([ "horror", "scifi" ])
|
3295
3390
|
end
|
3296
3391
|
|
3297
3392
|
it "persists the value" do
|
3298
|
-
video.reload.genres.
|
3393
|
+
expect(video.reload.genres).to eq([ "horror", "scifi" ])
|
3299
3394
|
end
|
3300
3395
|
|
3301
3396
|
context "when reloading the parent" do
|
@@ -3316,11 +3411,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3316
3411
|
end
|
3317
3412
|
|
3318
3413
|
it "sets the new value" do
|
3319
|
-
loaded_video.genres.
|
3414
|
+
expect(loaded_video.genres).to eq([ "comedy" ])
|
3320
3415
|
end
|
3321
3416
|
|
3322
3417
|
it "persists the new value" do
|
3323
|
-
loaded_video.reload.genres.
|
3418
|
+
expect(loaded_video.reload.genres).to eq([ "comedy" ])
|
3324
3419
|
end
|
3325
3420
|
end
|
3326
3421
|
end
|
@@ -3346,15 +3441,15 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3346
3441
|
end
|
3347
3442
|
|
3348
3443
|
it "destroys the document" do
|
3349
|
-
address_one.
|
3444
|
+
expect(address_one).to be_destroyed
|
3350
3445
|
end
|
3351
3446
|
|
3352
3447
|
it "reindexes the relation" do
|
3353
|
-
address_two._index.
|
3448
|
+
expect(address_two._index).to eq(0)
|
3354
3449
|
end
|
3355
3450
|
|
3356
3451
|
it "removes the document from the unscoped" do
|
3357
|
-
person.addresses.send(:_unscoped).
|
3452
|
+
expect(person.addresses.send(:_unscoped)).to_not include(address_one)
|
3358
3453
|
end
|
3359
3454
|
|
3360
3455
|
context "when subsequently updating the next document" do
|
@@ -3368,11 +3463,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3368
3463
|
end
|
3369
3464
|
|
3370
3465
|
it "updates the correct document" do
|
3371
|
-
addresses.first.number.
|
3466
|
+
expect(addresses.first.number).to eq(10)
|
3372
3467
|
end
|
3373
3468
|
|
3374
3469
|
it "does not add additional documents" do
|
3375
|
-
addresses.count.
|
3470
|
+
expect(addresses.count).to eq(1)
|
3376
3471
|
end
|
3377
3472
|
end
|
3378
3473
|
end
|
@@ -3402,7 +3497,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3402
3497
|
end
|
3403
3498
|
|
3404
3499
|
it "adds both documents" do
|
3405
|
-
result.
|
3500
|
+
expect(result).to eq([ address_one, address_two ])
|
3406
3501
|
end
|
3407
3502
|
end
|
3408
3503
|
end
|
@@ -3426,7 +3521,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3426
3521
|
end
|
3427
3522
|
|
3428
3523
|
it "allows the dot notation criteria" do
|
3429
|
-
criteria.
|
3524
|
+
expect(criteria).to eq([ address ])
|
3430
3525
|
end
|
3431
3526
|
end
|
3432
3527
|
|
@@ -3459,7 +3554,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3459
3554
|
end
|
3460
3555
|
|
3461
3556
|
it "updates the nested document" do
|
3462
|
-
updated.name.
|
3557
|
+
expect(updated.name).to eq("work")
|
3463
3558
|
end
|
3464
3559
|
end
|
3465
3560
|
end
|
@@ -3479,7 +3574,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3479
3574
|
end
|
3480
3575
|
|
3481
3576
|
it "orders properly with the boolean" do
|
3482
|
-
circuit.reload.buses.
|
3577
|
+
expect(circuit.reload.buses).to eq([ bus_two, bus_one ])
|
3483
3578
|
end
|
3484
3579
|
end
|
3485
3580
|
|
@@ -3517,11 +3612,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3517
3612
|
end
|
3518
3613
|
|
3519
3614
|
it "does not duplicate the first relation" do
|
3520
|
-
person.reload.symptoms.count.
|
3615
|
+
expect(person.reload.symptoms.count).to eq(2)
|
3521
3616
|
end
|
3522
3617
|
|
3523
3618
|
it "does not duplicate the second relation" do
|
3524
|
-
person.reload.appointments.count.
|
3619
|
+
expect(person.reload.appointments.count).to eq(2)
|
3525
3620
|
end
|
3526
3621
|
end
|
3527
3622
|
|
@@ -3542,29 +3637,29 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3542
3637
|
end
|
3543
3638
|
|
3544
3639
|
it "executes the callback" do
|
3545
|
-
artist.before_add_called.
|
3640
|
+
expect(artist.before_add_called).to be true
|
3546
3641
|
end
|
3547
3642
|
|
3548
3643
|
it "executes the callback as proc" do
|
3549
|
-
song.before_add_called.
|
3644
|
+
expect(song.before_add_called).to be true
|
3550
3645
|
end
|
3551
3646
|
|
3552
3647
|
it "adds the document to the relation" do
|
3553
|
-
artist.songs.
|
3648
|
+
expect(artist.songs).to eq([song])
|
3554
3649
|
end
|
3555
3650
|
end
|
3556
3651
|
|
3557
3652
|
context "with errors" do
|
3558
3653
|
|
3559
3654
|
before do
|
3560
|
-
artist.
|
3655
|
+
expect(artist).to receive(:before_add_song).and_raise
|
3561
3656
|
end
|
3562
3657
|
|
3563
3658
|
it "does not add the document to the relation" do
|
3564
3659
|
expect {
|
3565
3660
|
artist.songs << song
|
3566
3661
|
}.to raise_error
|
3567
|
-
artist.songs.
|
3662
|
+
expect(artist.songs).to be_empty
|
3568
3663
|
end
|
3569
3664
|
end
|
3570
3665
|
end
|
@@ -3581,20 +3676,20 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3581
3676
|
|
3582
3677
|
it "executes the callback" do
|
3583
3678
|
artist.labels << label
|
3584
|
-
artist.after_add_called.
|
3679
|
+
expect(artist.after_add_called).to be true
|
3585
3680
|
end
|
3586
3681
|
|
3587
3682
|
context "when errors are raised" do
|
3588
3683
|
|
3589
3684
|
before do
|
3590
|
-
artist.
|
3685
|
+
expect(artist).to receive(:after_add_label).and_raise
|
3591
3686
|
end
|
3592
3687
|
|
3593
3688
|
it "adds the document to the relation" do
|
3594
3689
|
expect {
|
3595
3690
|
artist.labels << label
|
3596
3691
|
}.to raise_error
|
3597
|
-
artist.labels.
|
3692
|
+
expect(artist.labels).to eq([ label ])
|
3598
3693
|
end
|
3599
3694
|
end
|
3600
3695
|
end
|
@@ -3622,11 +3717,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3622
3717
|
end
|
3623
3718
|
|
3624
3719
|
it "executes the callback" do
|
3625
|
-
artist.before_remove_embedded_called.
|
3720
|
+
expect(artist.before_remove_embedded_called).to be true
|
3626
3721
|
end
|
3627
3722
|
|
3628
3723
|
it "removes the document from the relation" do
|
3629
|
-
artist.songs.
|
3724
|
+
expect(artist.songs).to be_empty
|
3630
3725
|
end
|
3631
3726
|
end
|
3632
3727
|
|
@@ -3637,18 +3732,18 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3637
3732
|
end
|
3638
3733
|
|
3639
3734
|
it "executes the callback" do
|
3640
|
-
artist.before_remove_embedded_called.
|
3735
|
+
expect(artist.before_remove_embedded_called).to be true
|
3641
3736
|
end
|
3642
3737
|
|
3643
3738
|
it "shoud clear the relation" do
|
3644
|
-
artist.songs.
|
3739
|
+
expect(artist.songs).to be_empty
|
3645
3740
|
end
|
3646
3741
|
end
|
3647
3742
|
|
3648
3743
|
context "when errors are raised" do
|
3649
3744
|
|
3650
3745
|
before do
|
3651
|
-
artist.
|
3746
|
+
expect(artist).to receive(:before_remove_song).and_raise
|
3652
3747
|
end
|
3653
3748
|
|
3654
3749
|
describe "#delete" do
|
@@ -3657,7 +3752,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3657
3752
|
expect {
|
3658
3753
|
artist.songs.delete(song)
|
3659
3754
|
}.to raise_error
|
3660
|
-
artist.songs.
|
3755
|
+
expect(artist.songs).to eq([ song ])
|
3661
3756
|
end
|
3662
3757
|
end
|
3663
3758
|
|
@@ -3667,7 +3762,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3667
3762
|
expect {
|
3668
3763
|
artist.songs.clear
|
3669
3764
|
}.to raise_error
|
3670
|
-
artist.songs.
|
3765
|
+
expect(artist.songs).to eq([ song ])
|
3671
3766
|
end
|
3672
3767
|
end
|
3673
3768
|
end
|
@@ -3696,7 +3791,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3696
3791
|
end
|
3697
3792
|
|
3698
3793
|
it "executes the callback" do
|
3699
|
-
artist.after_remove_embedded_called.
|
3794
|
+
expect(artist.after_remove_embedded_called).to be true
|
3700
3795
|
end
|
3701
3796
|
end
|
3702
3797
|
|
@@ -3708,7 +3803,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3708
3803
|
|
3709
3804
|
it "executes the callback" do
|
3710
3805
|
artist.labels.clear
|
3711
|
-
artist.after_remove_embedded_called.
|
3806
|
+
expect(artist.after_remove_embedded_called).to be true
|
3712
3807
|
end
|
3713
3808
|
end
|
3714
3809
|
end
|
@@ -3716,7 +3811,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3716
3811
|
context "when errors are raised" do
|
3717
3812
|
|
3718
3813
|
before do
|
3719
|
-
artist.
|
3814
|
+
expect(artist).to receive(:after_remove_label).and_raise
|
3720
3815
|
end
|
3721
3816
|
|
3722
3817
|
describe "#delete" do
|
@@ -3728,7 +3823,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3728
3823
|
end
|
3729
3824
|
|
3730
3825
|
it "removes the document from the relation" do
|
3731
|
-
artist.labels.
|
3826
|
+
expect(artist.labels).to be_empty
|
3732
3827
|
end
|
3733
3828
|
end
|
3734
3829
|
|
@@ -3741,7 +3836,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3741
3836
|
end
|
3742
3837
|
|
3743
3838
|
it "should remove from collection" do
|
3744
|
-
artist.labels.
|
3839
|
+
expect(artist.labels).to be_empty
|
3745
3840
|
end
|
3746
3841
|
end
|
3747
3842
|
end
|
@@ -3764,7 +3859,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3764
3859
|
end
|
3765
3860
|
|
3766
3861
|
it "does not push the embedded documents twice" do
|
3767
|
-
server.reload.filesystems.count.
|
3862
|
+
expect(server.reload.filesystems.count).to eq(1)
|
3768
3863
|
end
|
3769
3864
|
end
|
3770
3865
|
end
|
@@ -3792,11 +3887,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3792
3887
|
end
|
3793
3888
|
|
3794
3889
|
it "creates proper documents from the db" do
|
3795
|
-
record.name.
|
3890
|
+
expect(record.name).to eq("Moderat")
|
3796
3891
|
end
|
3797
3892
|
|
3798
3893
|
it "assigns ids to the documents" do
|
3799
|
-
record.id.
|
3894
|
+
expect(record.id).to_not be_nil
|
3800
3895
|
end
|
3801
3896
|
|
3802
3897
|
context "when subsequently updating the documents" do
|
@@ -3806,11 +3901,11 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3806
3901
|
end
|
3807
3902
|
|
3808
3903
|
it "updates the document" do
|
3809
|
-
record.name.
|
3904
|
+
expect(record.name).to eq("Apparat")
|
3810
3905
|
end
|
3811
3906
|
|
3812
3907
|
it "persists the change" do
|
3813
|
-
record.reload.name.
|
3908
|
+
expect(record.reload.name).to eq("Apparat")
|
3814
3909
|
end
|
3815
3910
|
end
|
3816
3911
|
end
|
@@ -3835,7 +3930,7 @@ describe Mongoid::Relations::Embedded::Many do
|
|
3835
3930
|
end
|
3836
3931
|
|
3837
3932
|
it "keeps the proxy extensions when remarshalling" do
|
3838
|
-
loaded.extension.
|
3933
|
+
expect(loaded.extension).to eq("Testing")
|
3839
3934
|
end
|
3840
3935
|
end
|
3841
3936
|
end
|