mongoid 3.1.7 → 4.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +317 -11
- data/README.md +4 -5
- data/lib/config/locales/en.yml +9 -12
- data/lib/mongoid.rb +6 -75
- data/lib/mongoid/atomic.rb +0 -11
- data/lib/mongoid/atomic/paths/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/attributes.rb +30 -108
- 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} +5 -2
- data/lib/mongoid/composable.rb +104 -0
- data/lib/mongoid/config.rb +3 -9
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual/aggregable/mongo.rb +5 -9
- data/lib/mongoid/contextual/atomic.rb +53 -53
- data/lib/mongoid/contextual/command.rb +26 -0
- data/lib/mongoid/contextual/map_reduce.rb +1 -1
- data/lib/mongoid/contextual/memory.rb +6 -5
- data/lib/mongoid/contextual/mongo.rb +59 -28
- data/lib/mongoid/contextual/text_search.rb +180 -0
- data/lib/mongoid/copyable.rb +2 -3
- data/lib/mongoid/criteria.rb +13 -33
- data/lib/mongoid/criteria/{#findable.rb# → findable.rb} +0 -2
- 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 +1 -1
- data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
- data/lib/mongoid/document.rb +28 -12
- data/lib/mongoid/errors.rb +1 -1
- data/lib/mongoid/errors/document_not_found.rb +2 -1
- data/lib/mongoid/errors/invalid_value.rb +16 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/extensions.rb +2 -7
- data/lib/mongoid/extensions/array.rb +2 -2
- data/lib/mongoid/extensions/boolean.rb +14 -17
- data/lib/mongoid/extensions/float.rb +1 -0
- data/lib/mongoid/extensions/hash.rb +1 -1
- data/lib/mongoid/extensions/object.rb +4 -4
- data/lib/mongoid/extensions/object_id.rb +5 -5
- data/lib/mongoid/extensions/range.rb +8 -2
- data/lib/mongoid/extensions/string.rb +5 -17
- data/lib/mongoid/extensions/time.rb +2 -2
- data/lib/mongoid/factory.rb +3 -3
- data/lib/mongoid/fields.rb +9 -8
- data/lib/mongoid/fields/foreign_key.rb +3 -3
- data/lib/mongoid/fields/standard.rb +4 -16
- data/lib/mongoid/fields/validators/macro.rb +11 -3
- data/lib/mongoid/{finders.rb → findable.rb} +6 -2
- 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} +3 -52
- data/lib/mongoid/log_subscriber.rb +22 -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 +1 -1
- 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 +212 -0
- data/lib/mongoid/persistable/creatable.rb +188 -0
- data/lib/mongoid/persistable/deletable.rb +148 -0
- data/lib/mongoid/persistable/destroyable.rb +55 -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 +151 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/railtie.rb +32 -45
- data/lib/mongoid/railties/database.rake +12 -6
- data/lib/mongoid/relations.rb +3 -3
- data/lib/mongoid/relations/accessors.rb +13 -46
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +0 -23
- 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 +3 -1
- data/lib/mongoid/relations/builder.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +4 -5
- 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 +47 -0
- data/lib/mongoid/relations/eager/base.rb +57 -0
- data/lib/mongoid/relations/eager/belongs_to.rb +30 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +40 -0
- data/lib/mongoid/relations/eager/has_many.rb +37 -0
- data/lib/mongoid/relations/eager/has_one.rb +29 -0
- data/lib/mongoid/relations/embedded/batchable.rb +3 -4
- data/lib/mongoid/relations/embedded/many.rb +7 -27
- data/lib/mongoid/relations/macros.rb +2 -4
- data/lib/mongoid/relations/many.rb +30 -31
- data/lib/mongoid/relations/metadata.rb +6 -75
- data/lib/mongoid/relations/nested_builder.rb +2 -2
- data/lib/mongoid/relations/options.rb +1 -0
- data/lib/mongoid/relations/polymorphic.rb +0 -1
- data/lib/mongoid/relations/proxy.rb +10 -32
- data/lib/mongoid/relations/referenced/in.rb +2 -18
- data/lib/mongoid/relations/referenced/many.rb +9 -22
- data/lib/mongoid/relations/referenced/many_to_many.rb +10 -33
- data/lib/mongoid/relations/referenced/one.rb +2 -21
- data/lib/mongoid/relations/synchronization.rb +3 -3
- data/lib/mongoid/relations/touchable.rb +33 -0
- data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
- data/lib/mongoid/{scoping.rb → scopable.rb} +26 -3
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/{serialization.rb → serializable.rb} +10 -1
- data/lib/mongoid/sessions.rb +37 -345
- data/lib/mongoid/sessions/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +176 -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 +15 -1
- data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
- data/lib/mongoid/support/query_counter.rb +23 -0
- data/lib/mongoid/threaded.rb +0 -110
- data/lib/mongoid/threaded/lifecycle.rb +0 -28
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -9
- data/lib/mongoid/{validations → validatable}/associated.rb +3 -1
- 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 +3 -3
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +9 -13
- 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 +59 -57
- data/lib/support/ruby_version.rb +1 -1
- data/spec/app/models/account.rb +2 -6
- data/spec/app/models/acolyte.rb +1 -0
- data/spec/app/models/actor.rb +0 -1
- data/spec/app/models/address.rb +6 -1
- data/spec/app/models/animal.rb +1 -1
- data/spec/app/models/appointment.rb +2 -2
- 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/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/dragon.rb +4 -0
- data/spec/app/models/drug.rb +1 -3
- data/spec/app/models/dungeon.rb +4 -0
- 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 +0 -2
- 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/login.rb +1 -1
- data/spec/app/models/movie.rb +1 -0
- data/spec/app/models/name.rb +3 -3
- data/spec/app/models/note.rb +1 -1
- data/spec/app/models/oscar.rb +1 -1
- data/spec/app/models/parent_doc.rb +1 -1
- data/spec/app/models/person.rb +13 -8
- data/spec/app/models/phone.rb +1 -3
- data/spec/app/models/player.rb +1 -1
- data/spec/app/models/post.rb +2 -1
- data/spec/app/models/quiz.rb +0 -3
- data/spec/app/models/record.rb +5 -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/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 +1 -1
- data/spec/app/models/video.rb +0 -4
- data/spec/app/models/wiki_page.rb +1 -4
- 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/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} +335 -448
- data/spec/mongoid/attributes/readonly_spec.rb +16 -16
- data/spec/mongoid/attributes_spec.rb +188 -434
- data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +117 -148
- 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 +46 -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 +94 -94
- data/spec/mongoid/contextual/mongo_spec.rb +225 -139
- data/spec/mongoid/contextual/text_search_spec.rb +207 -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 +1063 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +31 -31
- data/spec/mongoid/criteria_spec.rb +530 -2207
- data/spec/mongoid/document_spec.rb +166 -120
- 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_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 +3 -3
- 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 +7 -7
- 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/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 +9 -9
- 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 +15 -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 +23 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +168 -209
- data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +62 -27
- 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} +105 -105
- data/spec/mongoid/log_subscriber_spec.rb +74 -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/{matchers → matchable}/ne_spec.rb +3 -3
- 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 +512 -0
- data/spec/mongoid/persistable/deletable_spec.rb +205 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +148 -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 +432 -0
- data/spec/mongoid/persistable/settable_spec.rb +139 -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} +19 -14
- 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 +36 -16
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +6 -6
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +2 -2
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +3 -3
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +12 -12
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +6 -6
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +9 -9
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +6 -6
- 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 +22 -33
- 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 +11 -24
- data/spec/mongoid/relations/builders_spec.rb +21 -21
- data/spec/mongoid/relations/cascading/delete_spec.rb +7 -7
- data/spec/mongoid/relations/cascading/destroy_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/nullify_spec.rb +2 -2
- data/spec/mongoid/relations/cascading/restrict_spec.rb +3 -3
- 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 +143 -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 +55 -56
- data/spec/mongoid/relations/embedded/many_spec.rb +357 -367
- data/spec/mongoid/relations/embedded/one_spec.rb +98 -139
- data/spec/mongoid/relations/macros_spec.rb +108 -102
- data/spec/mongoid/relations/metadata_spec.rb +147 -241
- 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 +379 -522
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +345 -417
- data/spec/mongoid/relations/referenced/one_spec.rb +148 -263
- 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 +116 -116
- data/spec/mongoid/relations/touchable_spec.rb +296 -0
- data/spec/mongoid/relations_spec.rb +16 -15
- data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +20 -60
- data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +74 -126
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +111 -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 +92 -0
- data/spec/mongoid/sessions_spec.rb +288 -177
- data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
- data/spec/mongoid/state_spec.rb +10 -10
- 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/updated/short_spec.rb +10 -10
- data/spec/mongoid/timestamps/updated_spec.rb +8 -12
- data/spec/mongoid/timestamps_spec.rb +7 -11
- data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
- data/spec/mongoid/{validations → validatable}/associated_spec.rb +18 -18
- data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
- data/spec/mongoid/{validations → validatable}/length_spec.rb +7 -7
- data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
- data/spec/mongoid/{validations → validatable}/presence_spec.rb +31 -38
- data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +126 -183
- data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
- data/spec/mongoid_spec.rb +8 -8
- data/spec/rails/mongoid_spec.rb +72 -87
- data/spec/spec_helper.rb +19 -17
- metadata +261 -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/criterion/findable.rb +0 -179
- 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/draft.rb +0 -9
- 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/#atomic_spec.rb# +0 -365
- 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/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/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
@@ -56,27 +56,27 @@ describe Mongoid::Relations::Referenced::Many do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "sets the foreign key on the relation" do
|
59
|
-
post.person_id.
|
59
|
+
expect(post.person_id).to eq(person.id)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "sets the base on the inverse relation" do
|
63
|
-
post.person.
|
63
|
+
expect(post.person).to eq(person)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "sets the same instance on the inverse relation" do
|
67
|
-
post.person.
|
67
|
+
expect(post.person).to eql(person)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "does not save the target" do
|
71
|
-
post.
|
71
|
+
expect(post).to be_new_record
|
72
72
|
end
|
73
73
|
|
74
74
|
it "adds the document to the target" do
|
75
|
-
person.posts.size.
|
75
|
+
expect(person.posts.size).to eq(1)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "returns the relation" do
|
79
|
-
added.
|
79
|
+
expect(added).to eq(person.posts)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -91,23 +91,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it "sets the foreign key on the relation" do
|
94
|
-
post.person_id.
|
94
|
+
expect(post.person_id).to eq(person.id)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "sets the base on the inverse relation" do
|
98
|
-
post.person.
|
98
|
+
expect(post.person).to eq(person)
|
99
99
|
end
|
100
100
|
|
101
101
|
it "sets the same instance on the inverse relation" do
|
102
|
-
post.person.
|
102
|
+
expect(post.person).to eql(person)
|
103
103
|
end
|
104
104
|
|
105
105
|
it "does not save the parent" do
|
106
|
-
person.
|
106
|
+
expect(person).to be_new_record
|
107
107
|
end
|
108
108
|
|
109
109
|
it "adds the document to the target" do
|
110
|
-
person.posts.size.
|
110
|
+
expect(person.posts.size).to eq(1)
|
111
111
|
end
|
112
112
|
|
113
113
|
context "when subsequently saving the parent" do
|
@@ -118,7 +118,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it "returns the correct count of the relation" do
|
121
|
-
person.posts.count.
|
121
|
+
expect(person.posts.count).to eq(1)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
@@ -137,23 +137,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
137
137
|
end
|
138
138
|
|
139
139
|
it "adds the documents to the relation" do
|
140
|
-
person.posts.
|
140
|
+
expect(person.posts).to eq([ post ])
|
141
141
|
end
|
142
142
|
|
143
143
|
it "sets the foreign key on the inverse relation" do
|
144
|
-
post.person_id.
|
144
|
+
expect(post.person_id).to eq(person.id)
|
145
145
|
end
|
146
146
|
|
147
147
|
it "saves the target" do
|
148
|
-
post.
|
148
|
+
expect(post).to be_persisted
|
149
149
|
end
|
150
150
|
|
151
151
|
it "adds the correct number of documents" do
|
152
|
-
person.posts.size.
|
152
|
+
expect(person.posts.size).to eq(1)
|
153
153
|
end
|
154
154
|
|
155
155
|
it "persists the link" do
|
156
|
-
person.reload.posts.
|
156
|
+
expect(person.reload.posts).to eq([ post ])
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
@@ -172,27 +172,43 @@ describe Mongoid::Relations::Referenced::Many do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it "sets the foreign key on the relation" do
|
175
|
-
post.person_id.
|
175
|
+
expect(post.person_id).to eq(person.id)
|
176
176
|
end
|
177
177
|
|
178
178
|
it "sets the base on the inverse relation" do
|
179
|
-
post.person.
|
179
|
+
expect(post.person).to eq(person)
|
180
180
|
end
|
181
181
|
|
182
182
|
it "sets the same instance on the inverse relation" do
|
183
|
-
post.person.
|
183
|
+
expect(post.person).to eql(person)
|
184
184
|
end
|
185
185
|
|
186
186
|
it "saves the target" do
|
187
|
-
post.
|
187
|
+
expect(post).to be_persisted
|
188
188
|
end
|
189
189
|
|
190
190
|
it "adds the document to the target" do
|
191
|
-
person.posts.count.
|
191
|
+
expect(person.posts.count).to eq(1)
|
192
192
|
end
|
193
193
|
|
194
194
|
it "increments the counter cache" do
|
195
|
-
person
|
195
|
+
expect(person[:posts_count]).to eq(1)
|
196
|
+
expect(person.posts_count).to eq(1)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "doesnt change the list of changes" do
|
200
|
+
expect(person.changed).to eq([])
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when saving another post" do
|
204
|
+
|
205
|
+
before do
|
206
|
+
person.posts.send(method, Post.new)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "increments the counter cache" do
|
210
|
+
expect(person.posts_count).to eq(2)
|
211
|
+
end
|
196
212
|
end
|
197
213
|
|
198
214
|
context "when documents already exist on the relation" do
|
@@ -206,41 +222,41 @@ describe Mongoid::Relations::Referenced::Many do
|
|
206
222
|
end
|
207
223
|
|
208
224
|
it "sets the foreign key on the relation" do
|
209
|
-
post_two.person_id.
|
225
|
+
expect(post_two.person_id).to eq(person.id)
|
210
226
|
end
|
211
227
|
|
212
228
|
it "sets the base on the inverse relation" do
|
213
|
-
post_two.person.
|
229
|
+
expect(post_two.person).to eq(person)
|
214
230
|
end
|
215
231
|
|
216
232
|
it "sets the same instance on the inverse relation" do
|
217
|
-
post_two.person.
|
233
|
+
expect(post_two.person).to eql(person)
|
218
234
|
end
|
219
235
|
|
220
236
|
it "saves the target" do
|
221
|
-
post_two.
|
237
|
+
expect(post_two).to be_persisted
|
222
238
|
end
|
223
239
|
|
224
240
|
it "adds the document to the target" do
|
225
|
-
person.posts.count.
|
241
|
+
expect(person.posts.count).to eq(2)
|
226
242
|
end
|
227
243
|
|
228
244
|
it "increments the counter cache" do
|
229
|
-
person.reload.posts_count.
|
245
|
+
expect(person.reload.posts_count).to eq(2)
|
230
246
|
end
|
231
247
|
|
232
248
|
it "contains the initial document in the target" do
|
233
|
-
person.posts.
|
249
|
+
expect(person.posts).to include(post)
|
234
250
|
end
|
235
251
|
|
236
252
|
it "contains the added document in the target" do
|
237
|
-
person.posts.
|
253
|
+
expect(person.posts).to include(post_two)
|
238
254
|
end
|
239
255
|
end
|
240
256
|
end
|
241
257
|
end
|
242
258
|
|
243
|
-
context "when.
|
259
|
+
context "when.adding to the relation" do
|
244
260
|
|
245
261
|
let(:person) do
|
246
262
|
Person.create
|
@@ -253,11 +269,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
253
269
|
end
|
254
270
|
|
255
271
|
before do
|
256
|
-
person.posts.
|
272
|
+
person.posts.send(method, post)
|
257
273
|
end
|
258
274
|
|
259
275
|
it "adds the document to the relation" do
|
260
|
-
person.posts.
|
276
|
+
expect(person.posts).to eq([ post ])
|
261
277
|
end
|
262
278
|
end
|
263
279
|
|
@@ -275,7 +291,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
275
291
|
|
276
292
|
it "raises an error" do
|
277
293
|
expect {
|
278
|
-
person.posts.
|
294
|
+
person.posts.send(method, post)
|
279
295
|
}.to raise_error(Moped::Errors::OperationFailure)
|
280
296
|
end
|
281
297
|
end
|
@@ -298,23 +314,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
298
314
|
end
|
299
315
|
|
300
316
|
it "sets the foreign key on the relation" do
|
301
|
-
rating.ratable_id.
|
302
|
-
end
|
303
|
-
|
304
|
-
it "does not set the inverse field on the relation" do
|
305
|
-
rating.ratable_field.should be_nil
|
317
|
+
expect(rating.ratable_id).to eq(movie.id)
|
306
318
|
end
|
307
319
|
|
308
320
|
it "sets the base on the inverse relation" do
|
309
|
-
rating.ratable.
|
321
|
+
expect(rating.ratable).to eq(movie)
|
310
322
|
end
|
311
323
|
|
312
324
|
it "does not save the target" do
|
313
|
-
rating.
|
325
|
+
expect(rating).to be_new_record
|
314
326
|
end
|
315
327
|
|
316
328
|
it "adds the document to the target" do
|
317
|
-
movie.ratings.size.
|
329
|
+
expect(movie.ratings.size).to eq(1)
|
318
330
|
end
|
319
331
|
end
|
320
332
|
|
@@ -333,23 +345,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
333
345
|
end
|
334
346
|
|
335
347
|
it "sets the foreign key on the relation" do
|
336
|
-
rating.ratable_id.
|
337
|
-
end
|
338
|
-
|
339
|
-
it "does not set the inverse field on the relation" do
|
340
|
-
rating.ratable_field.should be_nil
|
348
|
+
expect(rating.ratable_id).to eq(movie.id)
|
341
349
|
end
|
342
350
|
|
343
351
|
it "sets the base on the inverse relation" do
|
344
|
-
rating.ratable.
|
352
|
+
expect(rating.ratable).to eq(movie)
|
345
353
|
end
|
346
354
|
|
347
355
|
it "saves the target" do
|
348
|
-
rating.
|
356
|
+
expect(rating).to be_persisted
|
349
357
|
end
|
350
358
|
|
351
359
|
it "adds the document to the target" do
|
352
|
-
movie.ratings.count.
|
360
|
+
expect(movie.ratings.count).to eq(1)
|
353
361
|
end
|
354
362
|
end
|
355
363
|
end
|
@@ -375,19 +383,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
375
383
|
end
|
376
384
|
|
377
385
|
it "sets the target of the relation" do
|
378
|
-
person.posts.target.
|
386
|
+
expect(person.posts.target).to eq([ post ])
|
379
387
|
end
|
380
388
|
|
381
389
|
it "sets the foreign key on the relation" do
|
382
|
-
post.person_id.
|
390
|
+
expect(post.person_id).to eq(person.id)
|
383
391
|
end
|
384
392
|
|
385
393
|
it "sets the base on the inverse relation" do
|
386
|
-
post.person.
|
394
|
+
expect(post.person).to eq(person)
|
387
395
|
end
|
388
396
|
|
389
397
|
it "does not save the target" do
|
390
|
-
post.
|
398
|
+
expect(post).to_not be_persisted
|
391
399
|
end
|
392
400
|
end
|
393
401
|
|
@@ -406,19 +414,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
406
414
|
end
|
407
415
|
|
408
416
|
it "sets the target of the relation" do
|
409
|
-
person.posts.target.
|
417
|
+
expect(person.posts.target).to eq([ post ])
|
410
418
|
end
|
411
419
|
|
412
420
|
it "sets the foreign key of the relation" do
|
413
|
-
post.person_id.
|
421
|
+
expect(post.person_id).to eq(person.id)
|
414
422
|
end
|
415
423
|
|
416
424
|
it "sets the base on the inverse relation" do
|
417
|
-
post.person.
|
425
|
+
expect(post.person).to eq(person)
|
418
426
|
end
|
419
427
|
|
420
428
|
it "saves the target" do
|
421
|
-
post.
|
429
|
+
expect(post).to be_persisted
|
422
430
|
end
|
423
431
|
|
424
432
|
context "when replacing the relation with the same documents" do
|
@@ -430,11 +438,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
430
438
|
end
|
431
439
|
|
432
440
|
it "keeps the relation intact" do
|
433
|
-
person.posts.
|
441
|
+
expect(person.posts).to eq([ post ])
|
434
442
|
end
|
435
443
|
|
436
444
|
it "does not delete the relation" do
|
437
|
-
person.reload.posts.
|
445
|
+
expect(person.reload.posts).to eq([ post ])
|
438
446
|
end
|
439
447
|
end
|
440
448
|
|
@@ -449,11 +457,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
449
457
|
end
|
450
458
|
|
451
459
|
it "keeps the relation intact" do
|
452
|
-
from_db.posts.
|
460
|
+
expect(from_db.posts).to eq([ post ])
|
453
461
|
end
|
454
462
|
|
455
463
|
it "does not delete the relation" do
|
456
|
-
from_db.reload.posts.
|
464
|
+
expect(from_db.reload.posts).to eq([ post ])
|
457
465
|
end
|
458
466
|
end
|
459
467
|
end
|
@@ -471,19 +479,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
471
479
|
end
|
472
480
|
|
473
481
|
it "keeps the relation intact" do
|
474
|
-
person.posts.size.
|
482
|
+
expect(person.posts.size).to eq(2)
|
475
483
|
end
|
476
484
|
|
477
485
|
it "keeps the first post" do
|
478
|
-
person.posts.
|
486
|
+
expect(person.posts).to include(post)
|
479
487
|
end
|
480
488
|
|
481
489
|
it "keeps the second post" do
|
482
|
-
person.posts.
|
490
|
+
expect(person.posts).to include(new_post)
|
483
491
|
end
|
484
492
|
|
485
493
|
it "does not delete the relation" do
|
486
|
-
person.reload.posts.
|
494
|
+
expect(person.reload.posts).to eq([ post, new_post ])
|
487
495
|
end
|
488
496
|
end
|
489
497
|
|
@@ -498,11 +506,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
498
506
|
end
|
499
507
|
|
500
508
|
it "keeps the relation intact" do
|
501
|
-
from_db.posts.
|
509
|
+
expect(from_db.posts).to eq([ post, new_post ])
|
502
510
|
end
|
503
511
|
|
504
512
|
it "does not delete the relation" do
|
505
|
-
from_db.reload.posts.
|
513
|
+
expect(from_db.reload.posts).to eq([ post, new_post ])
|
506
514
|
end
|
507
515
|
end
|
508
516
|
end
|
@@ -520,11 +528,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
520
528
|
end
|
521
529
|
|
522
530
|
it "keeps the relation intact" do
|
523
|
-
person.posts.
|
531
|
+
expect(person.posts).to eq([ new_post ])
|
524
532
|
end
|
525
533
|
|
526
534
|
it "does not delete the relation" do
|
527
|
-
person.reload.posts.
|
535
|
+
expect(person.reload.posts).to eq([ new_post ])
|
528
536
|
end
|
529
537
|
end
|
530
538
|
|
@@ -539,11 +547,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
539
547
|
end
|
540
548
|
|
541
549
|
it "keeps the relation intact" do
|
542
|
-
from_db.posts.
|
550
|
+
expect(from_db.posts).to eq([ new_post ])
|
543
551
|
end
|
544
552
|
|
545
553
|
it "does not delete the relation" do
|
546
|
-
from_db.reload.posts.
|
554
|
+
expect(from_db.reload.posts).to eq([ new_post ])
|
547
555
|
end
|
548
556
|
end
|
549
557
|
end
|
@@ -567,19 +575,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
567
575
|
end
|
568
576
|
|
569
577
|
it "sets the target of the relation" do
|
570
|
-
movie.ratings.target.
|
578
|
+
expect(movie.ratings.target).to eq([ rating ])
|
571
579
|
end
|
572
580
|
|
573
581
|
it "sets the foreign key on the relation" do
|
574
|
-
rating.ratable_id.
|
582
|
+
expect(rating.ratable_id).to eq(movie.id)
|
575
583
|
end
|
576
584
|
|
577
585
|
it "sets the base on the inverse relation" do
|
578
|
-
rating.ratable.
|
586
|
+
expect(rating.ratable).to eq(movie)
|
579
587
|
end
|
580
588
|
|
581
589
|
it "does not save the target" do
|
582
|
-
rating.
|
590
|
+
expect(rating).to_not be_persisted
|
583
591
|
end
|
584
592
|
end
|
585
593
|
|
@@ -598,19 +606,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
598
606
|
end
|
599
607
|
|
600
608
|
it "sets the target of the relation" do
|
601
|
-
movie.ratings.target.
|
609
|
+
expect(movie.ratings.target).to eq([ rating ])
|
602
610
|
end
|
603
611
|
|
604
612
|
it "sets the foreign key of the relation" do
|
605
|
-
rating.ratable_id.
|
613
|
+
expect(rating.ratable_id).to eq(movie.id)
|
606
614
|
end
|
607
615
|
|
608
616
|
it "sets the base on the inverse relation" do
|
609
|
-
rating.ratable.
|
617
|
+
expect(rating.ratable).to eq(movie)
|
610
618
|
end
|
611
619
|
|
612
620
|
it "saves the target" do
|
613
|
-
rating.
|
621
|
+
expect(rating).to be_persisted
|
614
622
|
end
|
615
623
|
end
|
616
624
|
end
|
@@ -635,11 +643,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
635
643
|
end
|
636
644
|
|
637
645
|
it "removes all the children" do
|
638
|
-
person.posts.
|
646
|
+
expect(person.posts).to be_empty
|
639
647
|
end
|
640
648
|
|
641
649
|
it "persists the changes" do
|
642
|
-
person.posts(true).
|
650
|
+
expect(person.posts(true)).to be_empty
|
643
651
|
end
|
644
652
|
end
|
645
653
|
end
|
@@ -665,15 +673,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
665
673
|
end
|
666
674
|
|
667
675
|
it "sets the relation to an empty array" do
|
668
|
-
person.posts.
|
676
|
+
expect(person.posts).to be_empty
|
669
677
|
end
|
670
678
|
|
671
679
|
it "removed the inverse relation" do
|
672
|
-
post.person.
|
680
|
+
expect(post.person).to be_nil
|
673
681
|
end
|
674
682
|
|
675
683
|
it "removes the foreign key value" do
|
676
|
-
post.person_id.
|
684
|
+
expect(post.person_id).to be_nil
|
677
685
|
end
|
678
686
|
end
|
679
687
|
|
@@ -695,19 +703,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
695
703
|
end
|
696
704
|
|
697
705
|
it "sets the relation to empty" do
|
698
|
-
person.posts.
|
706
|
+
expect(person.posts).to be_empty
|
699
707
|
end
|
700
708
|
|
701
709
|
it "removed the inverse relation" do
|
702
|
-
post.person.
|
710
|
+
expect(post.person).to be_nil
|
703
711
|
end
|
704
712
|
|
705
713
|
it "removes the foreign key value" do
|
706
|
-
post.person_id.
|
714
|
+
expect(post.person_id).to be_nil
|
707
715
|
end
|
708
716
|
|
709
717
|
it "deletes the target from the database" do
|
710
|
-
post.
|
718
|
+
expect(post).to be_destroyed
|
711
719
|
end
|
712
720
|
end
|
713
721
|
|
@@ -723,19 +731,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
723
731
|
end
|
724
732
|
|
725
733
|
it "sets the relation to empty" do
|
726
|
-
person.drugs.
|
734
|
+
expect(person.drugs).to be_empty
|
727
735
|
end
|
728
736
|
|
729
737
|
it "removed the inverse relation" do
|
730
|
-
drug.person.
|
738
|
+
expect(drug.person).to be_nil
|
731
739
|
end
|
732
740
|
|
733
741
|
it "removes the foreign key value" do
|
734
|
-
drug.person_id.
|
742
|
+
expect(drug.person_id).to be_nil
|
735
743
|
end
|
736
744
|
|
737
745
|
it "nullifies the relation" do
|
738
|
-
drug.
|
746
|
+
expect(drug).to_not be_destroyed
|
739
747
|
end
|
740
748
|
end
|
741
749
|
end
|
@@ -759,15 +767,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
759
767
|
end
|
760
768
|
|
761
769
|
it "sets the relation to an empty array" do
|
762
|
-
movie.ratings.
|
770
|
+
expect(movie.ratings).to be_empty
|
763
771
|
end
|
764
772
|
|
765
773
|
it "removed the inverse relation" do
|
766
|
-
rating.ratable.
|
774
|
+
expect(rating.ratable).to be_nil
|
767
775
|
end
|
768
776
|
|
769
777
|
it "removes the foreign key value" do
|
770
|
-
rating.ratable_id.
|
778
|
+
expect(rating.ratable_id).to be_nil
|
771
779
|
end
|
772
780
|
end
|
773
781
|
|
@@ -787,21 +795,21 @@ describe Mongoid::Relations::Referenced::Many do
|
|
787
795
|
end
|
788
796
|
|
789
797
|
it "sets the relation to empty" do
|
790
|
-
movie.ratings.
|
798
|
+
expect(movie.ratings).to be_empty
|
791
799
|
end
|
792
800
|
|
793
801
|
it "removed the inverse relation" do
|
794
|
-
rating.ratable.
|
802
|
+
expect(rating.ratable).to be_nil
|
795
803
|
end
|
796
804
|
|
797
805
|
it "removes the foreign key value" do
|
798
|
-
rating.ratable_id.
|
806
|
+
expect(rating.ratable_id).to be_nil
|
799
807
|
end
|
800
808
|
|
801
809
|
context "when dependent is nullify" do
|
802
810
|
|
803
811
|
it "does not delete the target from the database" do
|
804
|
-
rating.
|
812
|
+
expect(rating).to_not be_destroyed
|
805
813
|
end
|
806
814
|
end
|
807
815
|
end
|
@@ -827,7 +835,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
827
835
|
end
|
828
836
|
|
829
837
|
it "calls setter with documents find by given ids" do
|
830
|
-
person.posts.
|
838
|
+
expect(person.posts).to eq([ post_one, post_two ])
|
831
839
|
end
|
832
840
|
end
|
833
841
|
|
@@ -842,7 +850,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
842
850
|
end
|
843
851
|
|
844
852
|
it "returns ids of documents that are in the relation" do
|
845
|
-
person.post_ids.
|
853
|
+
expect(person.post_ids).to eq(posts.map(&:id))
|
846
854
|
end
|
847
855
|
end
|
848
856
|
|
@@ -850,28 +858,6 @@ describe Mongoid::Relations::Referenced::Many do
|
|
850
858
|
|
851
859
|
describe "##{method}" do
|
852
860
|
|
853
|
-
context "when providing scoped mass assignment" do
|
854
|
-
|
855
|
-
let(:person) do
|
856
|
-
Person.new
|
857
|
-
end
|
858
|
-
|
859
|
-
let(:drug) do
|
860
|
-
person.drugs.send(
|
861
|
-
method,
|
862
|
-
{ name: "Oxycontin", generic: false }, as: :admin
|
863
|
-
)
|
864
|
-
end
|
865
|
-
|
866
|
-
it "sets the attributes for the provided role" do
|
867
|
-
drug.name.should eq("Oxycontin")
|
868
|
-
end
|
869
|
-
|
870
|
-
it "does not set the attributes for other roles" do
|
871
|
-
drug.generic.should be_nil
|
872
|
-
end
|
873
|
-
end
|
874
|
-
|
875
861
|
context "when the relation is not polymorphic" do
|
876
862
|
|
877
863
|
context "when the parent is a new record" do
|
@@ -885,31 +871,31 @@ describe Mongoid::Relations::Referenced::Many do
|
|
885
871
|
end
|
886
872
|
|
887
873
|
it "sets the foreign key on the relation" do
|
888
|
-
post.person_id.
|
874
|
+
expect(post.person_id).to eq(person.id)
|
889
875
|
end
|
890
876
|
|
891
877
|
it "sets the base on the inverse relation" do
|
892
|
-
post.person.
|
878
|
+
expect(post.person).to eq(person)
|
893
879
|
end
|
894
880
|
|
895
881
|
it "sets the attributes" do
|
896
|
-
post.title.
|
882
|
+
expect(post.title).to eq("$$$")
|
897
883
|
end
|
898
884
|
|
899
885
|
it "sets the post processed defaults" do
|
900
|
-
post.person_title.
|
886
|
+
expect(post.person_title).to eq(person.title)
|
901
887
|
end
|
902
888
|
|
903
889
|
it "does not save the target" do
|
904
|
-
post.
|
890
|
+
expect(post).to be_new_record
|
905
891
|
end
|
906
892
|
|
907
893
|
it "adds the document to the target" do
|
908
|
-
person.posts.size.
|
894
|
+
expect(person.posts.size).to eq(1)
|
909
895
|
end
|
910
896
|
|
911
897
|
it "does not perform validation" do
|
912
|
-
post.errors.
|
898
|
+
expect(post.errors).to be_empty
|
913
899
|
end
|
914
900
|
end
|
915
901
|
|
@@ -924,23 +910,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
924
910
|
end
|
925
911
|
|
926
912
|
it "sets the foreign key on the relation" do
|
927
|
-
post.person_id.
|
913
|
+
expect(post.person_id).to eq(person.id)
|
928
914
|
end
|
929
915
|
|
930
916
|
it "sets the base on the inverse relation" do
|
931
|
-
post.person.
|
917
|
+
expect(post.person).to eq(person)
|
932
918
|
end
|
933
919
|
|
934
920
|
it "sets the attributes" do
|
935
|
-
post.text.
|
921
|
+
expect(post.text).to eq("Testing")
|
936
922
|
end
|
937
923
|
|
938
924
|
it "does not save the target" do
|
939
|
-
post.
|
925
|
+
expect(post).to be_new_record
|
940
926
|
end
|
941
927
|
|
942
928
|
it "adds the document to the target" do
|
943
|
-
person.posts.size.
|
929
|
+
expect(person.posts.size).to eq(1)
|
944
930
|
end
|
945
931
|
end
|
946
932
|
end
|
@@ -977,27 +963,27 @@ describe Mongoid::Relations::Referenced::Many do
|
|
977
963
|
end
|
978
964
|
|
979
965
|
it "sets the foreign key on the relation" do
|
980
|
-
rating.ratable_id.
|
966
|
+
expect(rating.ratable_id).to eq(movie.id)
|
981
967
|
end
|
982
968
|
|
983
969
|
it "sets the base on the inverse relation" do
|
984
|
-
rating.ratable.
|
970
|
+
expect(rating.ratable).to eq(movie)
|
985
971
|
end
|
986
972
|
|
987
973
|
it "sets the attributes" do
|
988
|
-
rating.value.
|
974
|
+
expect(rating.value).to eq(3)
|
989
975
|
end
|
990
976
|
|
991
977
|
it "does not save the target" do
|
992
|
-
rating.
|
978
|
+
expect(rating).to be_new_record
|
993
979
|
end
|
994
980
|
|
995
981
|
it "adds the document to the target" do
|
996
|
-
movie.ratings.size.
|
982
|
+
expect(movie.ratings.size).to eq(1)
|
997
983
|
end
|
998
984
|
|
999
985
|
it "does not perform validation" do
|
1000
|
-
rating.errors.
|
986
|
+
expect(rating.errors).to be_empty
|
1001
987
|
end
|
1002
988
|
end
|
1003
989
|
|
@@ -1012,23 +998,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1012
998
|
end
|
1013
999
|
|
1014
1000
|
it "sets the foreign key on the relation" do
|
1015
|
-
rating.ratable_id.
|
1001
|
+
expect(rating.ratable_id).to eq(movie.id)
|
1016
1002
|
end
|
1017
1003
|
|
1018
1004
|
it "sets the base on the inverse relation" do
|
1019
|
-
rating.ratable.
|
1005
|
+
expect(rating.ratable).to eq(movie)
|
1020
1006
|
end
|
1021
1007
|
|
1022
1008
|
it "sets the attributes" do
|
1023
|
-
rating.value.
|
1009
|
+
expect(rating.value).to eq(4)
|
1024
1010
|
end
|
1025
1011
|
|
1026
1012
|
it "does not save the target" do
|
1027
|
-
rating.
|
1013
|
+
expect(rating).to be_new_record
|
1028
1014
|
end
|
1029
1015
|
|
1030
1016
|
it "adds the document to the target" do
|
1031
|
-
movie.ratings.size.
|
1017
|
+
expect(movie.ratings.size).to eq(1)
|
1032
1018
|
end
|
1033
1019
|
end
|
1034
1020
|
end
|
@@ -1042,16 +1028,17 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1042
1028
|
end
|
1043
1029
|
|
1044
1030
|
let(:document) do
|
1045
|
-
|
1031
|
+
double
|
1046
1032
|
end
|
1047
1033
|
|
1048
1034
|
let(:metadata) do
|
1049
|
-
|
1035
|
+
double(extension?: false)
|
1050
1036
|
end
|
1051
1037
|
|
1052
1038
|
it "returns the embedded in builder" do
|
1053
|
-
|
1054
|
-
|
1039
|
+
expect(
|
1040
|
+
described_class.builder(nil, metadata, document)
|
1041
|
+
).to be_a_kind_of(builder_klass)
|
1055
1042
|
end
|
1056
1043
|
end
|
1057
1044
|
|
@@ -1076,19 +1063,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1076
1063
|
end
|
1077
1064
|
|
1078
1065
|
it "clears out the relation" do
|
1079
|
-
person.posts.
|
1066
|
+
expect(person.posts).to be_empty
|
1080
1067
|
end
|
1081
1068
|
|
1082
1069
|
it "marks the documents as deleted" do
|
1083
|
-
post.
|
1070
|
+
expect(post).to be_destroyed
|
1084
1071
|
end
|
1085
1072
|
|
1086
1073
|
it "deletes the documents from the db" do
|
1087
|
-
person.reload.posts.
|
1074
|
+
expect(person.reload.posts).to be_empty
|
1088
1075
|
end
|
1089
1076
|
|
1090
1077
|
it "returns the relation" do
|
1091
|
-
relation.
|
1078
|
+
expect(relation).to be_empty
|
1092
1079
|
end
|
1093
1080
|
end
|
1094
1081
|
|
@@ -1103,7 +1090,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1103
1090
|
end
|
1104
1091
|
|
1105
1092
|
it "clears out the relation" do
|
1106
|
-
person.posts.
|
1093
|
+
expect(person.posts).to be_empty
|
1107
1094
|
end
|
1108
1095
|
end
|
1109
1096
|
end
|
@@ -1123,7 +1110,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1123
1110
|
end
|
1124
1111
|
|
1125
1112
|
it "clears out the relation" do
|
1126
|
-
person.posts.
|
1113
|
+
expect(person.posts).to be_empty
|
1127
1114
|
end
|
1128
1115
|
end
|
1129
1116
|
end
|
@@ -1147,19 +1134,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1147
1134
|
end
|
1148
1135
|
|
1149
1136
|
it "clears out the relation" do
|
1150
|
-
movie.ratings.
|
1137
|
+
expect(movie.ratings).to be_empty
|
1151
1138
|
end
|
1152
1139
|
|
1153
1140
|
it "handles the proper dependent strategy" do
|
1154
|
-
rating.
|
1141
|
+
expect(rating).to_not be_destroyed
|
1155
1142
|
end
|
1156
1143
|
|
1157
1144
|
it "deletes the documents from the db" do
|
1158
|
-
movie.reload.ratings.
|
1145
|
+
expect(movie.reload.ratings).to be_empty
|
1159
1146
|
end
|
1160
1147
|
|
1161
1148
|
it "returns the relation" do
|
1162
|
-
relation.
|
1149
|
+
expect(relation).to be_empty
|
1163
1150
|
end
|
1164
1151
|
end
|
1165
1152
|
|
@@ -1174,7 +1161,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1174
1161
|
end
|
1175
1162
|
|
1176
1163
|
it "clears out the relation" do
|
1177
|
-
movie.ratings.
|
1164
|
+
expect(movie.ratings).to be_empty
|
1178
1165
|
end
|
1179
1166
|
end
|
1180
1167
|
end
|
@@ -1194,7 +1181,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1194
1181
|
end
|
1195
1182
|
|
1196
1183
|
it "clears out the relation" do
|
1197
|
-
movie.ratings.
|
1184
|
+
expect(movie.ratings).to be_empty
|
1198
1185
|
end
|
1199
1186
|
end
|
1200
1187
|
end
|
@@ -1219,23 +1206,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1219
1206
|
end
|
1220
1207
|
|
1221
1208
|
it "sets the foreign key on the relation" do
|
1222
|
-
post.person_id.
|
1209
|
+
expect(post.person_id).to eq(person.id)
|
1223
1210
|
end
|
1224
1211
|
|
1225
1212
|
it "sets the base on the inverse relation" do
|
1226
|
-
post.person.
|
1213
|
+
expect(post.person).to eq(person)
|
1227
1214
|
end
|
1228
1215
|
|
1229
1216
|
it "sets the same instance on the inverse relation" do
|
1230
|
-
post.person.
|
1217
|
+
expect(post.person).to eql(person)
|
1231
1218
|
end
|
1232
1219
|
|
1233
1220
|
it "does not save the target" do
|
1234
|
-
post.
|
1221
|
+
expect(post).to be_new_record
|
1235
1222
|
end
|
1236
1223
|
|
1237
1224
|
it "adds the document to the target" do
|
1238
|
-
person.posts.size.
|
1225
|
+
expect(person.posts.size).to eq(1)
|
1239
1226
|
end
|
1240
1227
|
end
|
1241
1228
|
|
@@ -1252,23 +1239,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1252
1239
|
end
|
1253
1240
|
|
1254
1241
|
it "adds the documents to the relation" do
|
1255
|
-
person.posts.
|
1242
|
+
expect(person.posts).to eq([ post ])
|
1256
1243
|
end
|
1257
1244
|
|
1258
1245
|
it "sets the foreign key on the inverse relation" do
|
1259
|
-
post.person_id.
|
1246
|
+
expect(post.person_id).to eq(person.id)
|
1260
1247
|
end
|
1261
1248
|
|
1262
1249
|
it "saves the target" do
|
1263
|
-
post.
|
1250
|
+
expect(post).to be_persisted
|
1264
1251
|
end
|
1265
1252
|
|
1266
1253
|
it "adds the correct number of documents" do
|
1267
|
-
person.posts.size.
|
1254
|
+
expect(person.posts.size).to eq(1)
|
1268
1255
|
end
|
1269
1256
|
|
1270
1257
|
it "persists the link" do
|
1271
|
-
person.reload.posts.
|
1258
|
+
expect(person.reload.posts).to eq([ post ])
|
1272
1259
|
end
|
1273
1260
|
end
|
1274
1261
|
|
@@ -1291,23 +1278,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1291
1278
|
end
|
1292
1279
|
|
1293
1280
|
it "sets the foreign key on the relation" do
|
1294
|
-
post.person_id.
|
1281
|
+
expect(post.person_id).to eq(person.id)
|
1295
1282
|
end
|
1296
1283
|
|
1297
1284
|
it "sets the base on the inverse relation" do
|
1298
|
-
post.person.
|
1285
|
+
expect(post.person).to eq(person)
|
1299
1286
|
end
|
1300
1287
|
|
1301
1288
|
it "sets the same instance on the inverse relation" do
|
1302
|
-
post.person.
|
1289
|
+
expect(post.person).to eql(person)
|
1303
1290
|
end
|
1304
1291
|
|
1305
1292
|
it "saves the target" do
|
1306
|
-
post.
|
1293
|
+
expect(post).to be_persisted
|
1307
1294
|
end
|
1308
1295
|
|
1309
1296
|
it "adds the document to the target" do
|
1310
|
-
person.posts.count.
|
1297
|
+
expect(person.posts.count).to eq(2)
|
1311
1298
|
end
|
1312
1299
|
|
1313
1300
|
context "when documents already exist on the relation" do
|
@@ -1321,31 +1308,31 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1321
1308
|
end
|
1322
1309
|
|
1323
1310
|
it "sets the foreign key on the relation" do
|
1324
|
-
post_two.person_id.
|
1311
|
+
expect(post_two.person_id).to eq(person.id)
|
1325
1312
|
end
|
1326
1313
|
|
1327
1314
|
it "sets the base on the inverse relation" do
|
1328
|
-
post_two.person.
|
1315
|
+
expect(post_two.person).to eq(person)
|
1329
1316
|
end
|
1330
1317
|
|
1331
1318
|
it "sets the same instance on the inverse relation" do
|
1332
|
-
post_two.person.
|
1319
|
+
expect(post_two.person).to eql(person)
|
1333
1320
|
end
|
1334
1321
|
|
1335
1322
|
it "saves the target" do
|
1336
|
-
post_two.
|
1323
|
+
expect(post_two).to be_persisted
|
1337
1324
|
end
|
1338
1325
|
|
1339
1326
|
it "adds the document to the target" do
|
1340
|
-
person.posts.count.
|
1327
|
+
expect(person.posts.count).to eq(3)
|
1341
1328
|
end
|
1342
1329
|
|
1343
1330
|
it "contains the initial document in the target" do
|
1344
|
-
person.posts.
|
1331
|
+
expect(person.posts).to include(post)
|
1345
1332
|
end
|
1346
1333
|
|
1347
1334
|
it "contains the added document in the target" do
|
1348
|
-
person.posts.
|
1335
|
+
expect(person.posts).to include(post_two)
|
1349
1336
|
end
|
1350
1337
|
end
|
1351
1338
|
end
|
@@ -1369,19 +1356,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1369
1356
|
end
|
1370
1357
|
|
1371
1358
|
it "sets the foreign key on the relation" do
|
1372
|
-
rating.ratable_id.
|
1359
|
+
expect(rating.ratable_id).to eq(movie.id)
|
1373
1360
|
end
|
1374
1361
|
|
1375
1362
|
it "sets the base on the inverse relation" do
|
1376
|
-
rating.ratable.
|
1363
|
+
expect(rating.ratable).to eq(movie)
|
1377
1364
|
end
|
1378
1365
|
|
1379
1366
|
it "does not save the target" do
|
1380
|
-
rating.
|
1367
|
+
expect(rating).to be_new_record
|
1381
1368
|
end
|
1382
1369
|
|
1383
1370
|
it "adds the document to the target" do
|
1384
|
-
movie.ratings.size.
|
1371
|
+
expect(movie.ratings.size).to eq(1)
|
1385
1372
|
end
|
1386
1373
|
end
|
1387
1374
|
|
@@ -1400,19 +1387,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1400
1387
|
end
|
1401
1388
|
|
1402
1389
|
it "sets the foreign key on the relation" do
|
1403
|
-
rating.ratable_id.
|
1390
|
+
expect(rating.ratable_id).to eq(movie.id)
|
1404
1391
|
end
|
1405
1392
|
|
1406
1393
|
it "sets the base on the inverse relation" do
|
1407
|
-
rating.ratable.
|
1394
|
+
expect(rating.ratable).to eq(movie)
|
1408
1395
|
end
|
1409
1396
|
|
1410
1397
|
it "saves the target" do
|
1411
|
-
rating.
|
1398
|
+
expect(rating).to be_persisted
|
1412
1399
|
end
|
1413
1400
|
|
1414
1401
|
it "adds the document to the target" do
|
1415
|
-
movie.ratings.count.
|
1402
|
+
expect(movie.ratings.count).to eq(1)
|
1416
1403
|
end
|
1417
1404
|
end
|
1418
1405
|
end
|
@@ -1430,7 +1417,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1430
1417
|
end
|
1431
1418
|
|
1432
1419
|
it "returns the number of persisted documents" do
|
1433
|
-
movie.ratings.count.
|
1420
|
+
expect(movie.ratings.count).to eq(1)
|
1434
1421
|
end
|
1435
1422
|
end
|
1436
1423
|
|
@@ -1441,7 +1428,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1441
1428
|
end
|
1442
1429
|
|
1443
1430
|
it "returns 0" do
|
1444
|
-
movie.ratings.count.
|
1431
|
+
expect(movie.ratings.count).to eq(0)
|
1445
1432
|
end
|
1446
1433
|
end
|
1447
1434
|
|
@@ -1454,7 +1441,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1454
1441
|
end
|
1455
1442
|
|
1456
1443
|
it "returns the count from the db" do
|
1457
|
-
movie.ratings.count.
|
1444
|
+
expect(movie.ratings.count).to eq(1)
|
1458
1445
|
end
|
1459
1446
|
end
|
1460
1447
|
|
@@ -1465,7 +1452,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1465
1452
|
end
|
1466
1453
|
|
1467
1454
|
it "returns the count from the db" do
|
1468
|
-
movie.ratings.count.
|
1455
|
+
expect(movie.ratings.count).to eq(0)
|
1469
1456
|
end
|
1470
1457
|
end
|
1471
1458
|
end
|
@@ -1473,24 +1460,30 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1473
1460
|
|
1474
1461
|
describe "#create" do
|
1475
1462
|
|
1476
|
-
context "when providing
|
1463
|
+
context "when providing multiple attributes" do
|
1477
1464
|
|
1478
1465
|
let(:person) do
|
1479
1466
|
Person.create
|
1480
1467
|
end
|
1481
1468
|
|
1482
|
-
let(:
|
1483
|
-
person.
|
1484
|
-
|
1485
|
-
|
1469
|
+
let!(:posts) do
|
1470
|
+
person.posts.create([{ text: "Test1" }, { text: "Test2" }])
|
1471
|
+
end
|
1472
|
+
|
1473
|
+
it "creates multiple documents" do
|
1474
|
+
expect(posts.size).to eq(2)
|
1486
1475
|
end
|
1487
1476
|
|
1488
|
-
it "sets the attributes
|
1489
|
-
|
1477
|
+
it "sets the first attributes" do
|
1478
|
+
expect(posts.first.text).to eq("Test1")
|
1490
1479
|
end
|
1491
1480
|
|
1492
|
-
it "
|
1493
|
-
|
1481
|
+
it "sets the second attributes" do
|
1482
|
+
expect(posts.last.text).to eq("Test2")
|
1483
|
+
end
|
1484
|
+
|
1485
|
+
it "persists the children" do
|
1486
|
+
expect(person.posts.count).to eq(2)
|
1494
1487
|
end
|
1495
1488
|
end
|
1496
1489
|
|
@@ -1511,7 +1504,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1511
1504
|
end
|
1512
1505
|
end
|
1513
1506
|
|
1514
|
-
context "when.
|
1507
|
+
context "when.creating the document" do
|
1515
1508
|
|
1516
1509
|
context "when the operation is successful" do
|
1517
1510
|
|
@@ -1520,11 +1513,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1520
1513
|
end
|
1521
1514
|
|
1522
1515
|
let!(:post) do
|
1523
|
-
person.posts.
|
1516
|
+
person.posts.create(text: "Testing")
|
1524
1517
|
end
|
1525
1518
|
|
1526
1519
|
it "creates the document" do
|
1527
|
-
person.posts.
|
1520
|
+
expect(person.posts).to eq([ post ])
|
1528
1521
|
end
|
1529
1522
|
end
|
1530
1523
|
|
@@ -1540,7 +1533,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1540
1533
|
|
1541
1534
|
it "raises an error" do
|
1542
1535
|
expect {
|
1543
|
-
person.posts.
|
1536
|
+
person.posts.create do |doc|
|
1544
1537
|
doc._id = existing.id
|
1545
1538
|
end
|
1546
1539
|
}.to raise_error(Moped::Errors::OperationFailure)
|
@@ -1561,27 +1554,27 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1561
1554
|
end
|
1562
1555
|
|
1563
1556
|
it "sets the foreign key on the relation" do
|
1564
|
-
post.person_id.
|
1557
|
+
expect(post.person_id).to eq(person.id)
|
1565
1558
|
end
|
1566
1559
|
|
1567
1560
|
it "sets the base on the inverse relation" do
|
1568
|
-
post.person.
|
1561
|
+
expect(post.person).to eq(person)
|
1569
1562
|
end
|
1570
1563
|
|
1571
1564
|
it "sets the attributes" do
|
1572
|
-
post.text.
|
1565
|
+
expect(post.text).to eq("Testing")
|
1573
1566
|
end
|
1574
1567
|
|
1575
1568
|
it "saves the target" do
|
1576
|
-
post.
|
1569
|
+
expect(post).to_not be_a_new_record
|
1577
1570
|
end
|
1578
1571
|
|
1579
1572
|
it "calls the passed block" do
|
1580
|
-
post.content.
|
1573
|
+
expect(post.content).to eq("The Content")
|
1581
1574
|
end
|
1582
1575
|
|
1583
1576
|
it "adds the document to the target" do
|
1584
|
-
person.posts.count.
|
1577
|
+
expect(person.posts.count).to eq(1)
|
1585
1578
|
end
|
1586
1579
|
end
|
1587
1580
|
end
|
@@ -1614,23 +1607,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1614
1607
|
end
|
1615
1608
|
|
1616
1609
|
it "sets the foreign key on the relation" do
|
1617
|
-
rating.ratable_id.
|
1610
|
+
expect(rating.ratable_id).to eq(movie.id)
|
1618
1611
|
end
|
1619
1612
|
|
1620
1613
|
it "sets the base on the inverse relation" do
|
1621
|
-
rating.ratable.
|
1614
|
+
expect(rating.ratable).to eq(movie)
|
1622
1615
|
end
|
1623
1616
|
|
1624
1617
|
it "sets the attributes" do
|
1625
|
-
rating.value.
|
1618
|
+
expect(rating.value).to eq(3)
|
1626
1619
|
end
|
1627
1620
|
|
1628
1621
|
it "saves the target" do
|
1629
|
-
rating.
|
1622
|
+
expect(rating).to_not be_new_record
|
1630
1623
|
end
|
1631
1624
|
|
1632
1625
|
it "adds the document to the target" do
|
1633
|
-
movie.ratings.count.
|
1626
|
+
expect(movie.ratings.count).to eq(1)
|
1634
1627
|
end
|
1635
1628
|
end
|
1636
1629
|
end
|
@@ -1646,31 +1639,37 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1646
1639
|
end
|
1647
1640
|
|
1648
1641
|
it 'saves pk value on fk field' do
|
1649
|
-
drug.person_id.
|
1642
|
+
expect(drug.person_id).to eq('arthurnn')
|
1650
1643
|
end
|
1651
1644
|
end
|
1652
1645
|
end
|
1653
1646
|
|
1654
1647
|
describe "#create!" do
|
1655
1648
|
|
1656
|
-
context "when providing
|
1649
|
+
context "when providing multiple attributes" do
|
1657
1650
|
|
1658
1651
|
let(:person) do
|
1659
1652
|
Person.create
|
1660
1653
|
end
|
1661
1654
|
|
1662
|
-
let(:
|
1663
|
-
person.
|
1664
|
-
{ name: "Oxycontin", generic: false }, as: :admin
|
1665
|
-
)
|
1655
|
+
let!(:posts) do
|
1656
|
+
person.posts.create!([{ text: "Test1" }, { text: "Test2" }])
|
1666
1657
|
end
|
1667
1658
|
|
1668
|
-
it "
|
1669
|
-
|
1659
|
+
it "creates multiple documents" do
|
1660
|
+
expect(posts.size).to eq(2)
|
1670
1661
|
end
|
1671
1662
|
|
1672
|
-
it "
|
1673
|
-
|
1663
|
+
it "sets the first attributes" do
|
1664
|
+
expect(posts.first.text).to eq("Test1")
|
1665
|
+
end
|
1666
|
+
|
1667
|
+
it "sets the second attributes" do
|
1668
|
+
expect(posts.last.text).to eq("Test2")
|
1669
|
+
end
|
1670
|
+
|
1671
|
+
it "persists the children" do
|
1672
|
+
expect(person.posts.count).to eq(2)
|
1674
1673
|
end
|
1675
1674
|
end
|
1676
1675
|
|
@@ -1702,23 +1701,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1702
1701
|
end
|
1703
1702
|
|
1704
1703
|
it "sets the foreign key on the relation" do
|
1705
|
-
post.person_id.
|
1704
|
+
expect(post.person_id).to eq(person.id)
|
1706
1705
|
end
|
1707
1706
|
|
1708
1707
|
it "sets the base on the inverse relation" do
|
1709
|
-
post.person.
|
1708
|
+
expect(post.person).to eq(person)
|
1710
1709
|
end
|
1711
1710
|
|
1712
1711
|
it "sets the attributes" do
|
1713
|
-
post.title.
|
1712
|
+
expect(post.title).to eq("Testing")
|
1714
1713
|
end
|
1715
1714
|
|
1716
1715
|
it "saves the target" do
|
1717
|
-
post.
|
1716
|
+
expect(post).to_not be_a_new_record
|
1718
1717
|
end
|
1719
1718
|
|
1720
1719
|
it "adds the document to the target" do
|
1721
|
-
person.posts.count.
|
1720
|
+
expect(person.posts.count).to eq(1)
|
1722
1721
|
end
|
1723
1722
|
|
1724
1723
|
context "when validation fails" do
|
@@ -1760,23 +1759,23 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1760
1759
|
end
|
1761
1760
|
|
1762
1761
|
it "sets the foreign key on the relation" do
|
1763
|
-
rating.ratable_id.
|
1762
|
+
expect(rating.ratable_id).to eq(movie.id)
|
1764
1763
|
end
|
1765
1764
|
|
1766
1765
|
it "sets the base on the inverse relation" do
|
1767
|
-
rating.ratable.
|
1766
|
+
expect(rating.ratable).to eq(movie)
|
1768
1767
|
end
|
1769
1768
|
|
1770
1769
|
it "sets the attributes" do
|
1771
|
-
rating.value.
|
1770
|
+
expect(rating.value).to eq(4)
|
1772
1771
|
end
|
1773
1772
|
|
1774
1773
|
it "saves the target" do
|
1775
|
-
rating.
|
1774
|
+
expect(rating).to_not be_new_record
|
1776
1775
|
end
|
1777
1776
|
|
1778
1777
|
it "adds the document to the target" do
|
1779
|
-
movie.ratings.count.
|
1778
|
+
expect(movie.ratings.count).to eq(1)
|
1780
1779
|
end
|
1781
1780
|
|
1782
1781
|
context "when validation fails" do
|
@@ -1794,7 +1793,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1794
1793
|
describe ".criteria" do
|
1795
1794
|
|
1796
1795
|
let(:id) do
|
1797
|
-
|
1796
|
+
BSON::ObjectId.new
|
1798
1797
|
end
|
1799
1798
|
|
1800
1799
|
context "when the relation is polymorphic" do
|
@@ -1808,11 +1807,10 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1808
1807
|
end
|
1809
1808
|
|
1810
1809
|
it "includes the type in the criteria" do
|
1811
|
-
criteria.selector.
|
1810
|
+
expect(criteria.selector).to eq(
|
1812
1811
|
{
|
1813
1812
|
"ratable_id" => id,
|
1814
|
-
"ratable_type" => "Movie"
|
1815
|
-
"ratable_field" => { "$in" => [ :ratings, nil ] }
|
1813
|
+
"ratable_type" => "Movie"
|
1816
1814
|
}
|
1817
1815
|
)
|
1818
1816
|
end
|
@@ -1829,7 +1827,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1829
1827
|
end
|
1830
1828
|
|
1831
1829
|
it "does not include the type in the criteria" do
|
1832
|
-
criteria.selector.
|
1830
|
+
expect(criteria.selector).to eq({ "person_id" => id })
|
1833
1831
|
end
|
1834
1832
|
end
|
1835
1833
|
end
|
@@ -1863,7 +1861,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1863
1861
|
end
|
1864
1862
|
|
1865
1863
|
it "does not cascade" do
|
1866
|
-
deleted.changes.keys.
|
1864
|
+
expect(deleted.changes.keys).to eq([ "person_id" ])
|
1867
1865
|
end
|
1868
1866
|
end
|
1869
1867
|
|
@@ -1878,15 +1876,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1878
1876
|
end
|
1879
1877
|
|
1880
1878
|
it "returns the document" do
|
1881
|
-
deleted.
|
1879
|
+
expect(deleted).to eq(drug)
|
1882
1880
|
end
|
1883
1881
|
|
1884
1882
|
it "deletes the foreign key" do
|
1885
|
-
drug.person_id.
|
1883
|
+
expect(drug.person_id).to be_nil
|
1886
1884
|
end
|
1887
1885
|
|
1888
1886
|
it "removes the document from the relation" do
|
1889
|
-
person.drugs.
|
1887
|
+
expect(person.drugs).to_not include(drug)
|
1890
1888
|
end
|
1891
1889
|
end
|
1892
1890
|
|
@@ -1901,15 +1899,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1901
1899
|
end
|
1902
1900
|
|
1903
1901
|
it "returns the document" do
|
1904
|
-
deleted.
|
1902
|
+
expect(deleted).to eq(drug)
|
1905
1903
|
end
|
1906
1904
|
|
1907
1905
|
it "deletes the foreign key" do
|
1908
|
-
drug.person_id.
|
1906
|
+
expect(drug.person_id).to be_nil
|
1909
1907
|
end
|
1910
1908
|
|
1911
1909
|
it "removes the document from the relation" do
|
1912
|
-
person.drugs.
|
1910
|
+
expect(person.drugs).to_not include(drug)
|
1913
1911
|
end
|
1914
1912
|
end
|
1915
1913
|
end
|
@@ -1927,15 +1925,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1927
1925
|
end
|
1928
1926
|
|
1929
1927
|
it "returns the document" do
|
1930
|
-
deleted.
|
1928
|
+
expect(deleted).to eq(post)
|
1931
1929
|
end
|
1932
1930
|
|
1933
1931
|
it "deletes the document" do
|
1934
|
-
post.
|
1932
|
+
expect(post).to be_destroyed
|
1935
1933
|
end
|
1936
1934
|
|
1937
1935
|
it "removes the document from the relation" do
|
1938
|
-
person.posts.
|
1936
|
+
expect(person.posts).to_not include(post)
|
1939
1937
|
end
|
1940
1938
|
end
|
1941
1939
|
|
@@ -1950,15 +1948,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1950
1948
|
end
|
1951
1949
|
|
1952
1950
|
it "returns the document" do
|
1953
|
-
deleted.
|
1951
|
+
expect(deleted).to eq(post)
|
1954
1952
|
end
|
1955
1953
|
|
1956
1954
|
it "deletes the document" do
|
1957
|
-
post.
|
1955
|
+
expect(post).to be_destroyed
|
1958
1956
|
end
|
1959
1957
|
|
1960
1958
|
it "removes the document from the relation" do
|
1961
|
-
person.posts.
|
1959
|
+
expect(person.posts).to_not include(post)
|
1962
1960
|
end
|
1963
1961
|
end
|
1964
1962
|
end
|
@@ -1975,11 +1973,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
1975
1973
|
end
|
1976
1974
|
|
1977
1975
|
it "returns nil" do
|
1978
|
-
deleted.
|
1976
|
+
expect(deleted).to be_nil
|
1979
1977
|
end
|
1980
1978
|
|
1981
1979
|
it "does not delete the document" do
|
1982
|
-
post.
|
1980
|
+
expect(post).to be_persisted
|
1983
1981
|
end
|
1984
1982
|
end
|
1985
1983
|
end
|
@@ -2002,18 +2000,18 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2002
2000
|
end
|
2003
2001
|
|
2004
2002
|
it "removes the correct posts" do
|
2005
|
-
person.posts.send(method,
|
2006
|
-
person.posts.count.
|
2007
|
-
person.reload.posts_count.
|
2003
|
+
person.posts.send(method, { title: "Testing" })
|
2004
|
+
expect(person.posts.count).to eq(1)
|
2005
|
+
expect(person.reload.posts_count).to eq(1) if method == :destroy_all
|
2008
2006
|
end
|
2009
2007
|
|
2010
2008
|
it "deletes the documents from the database" do
|
2011
|
-
person.posts.send(method,
|
2012
|
-
Post.where(title: "Testing").count.
|
2009
|
+
person.posts.send(method, { title: "Testing" })
|
2010
|
+
expect(Post.where(title: "Testing").count).to eq(0)
|
2013
2011
|
end
|
2014
2012
|
|
2015
2013
|
it "returns the number of documents deleted" do
|
2016
|
-
person.posts.send(method,
|
2014
|
+
expect(person.posts.send(method, { title: "Testing" })).to eq(1)
|
2017
2015
|
end
|
2018
2016
|
end
|
2019
2017
|
|
@@ -2030,16 +2028,16 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2030
2028
|
|
2031
2029
|
it "removes the correct posts" do
|
2032
2030
|
person.posts.send(method)
|
2033
|
-
person.posts.count.
|
2031
|
+
expect(person.posts.count).to eq(0)
|
2034
2032
|
end
|
2035
2033
|
|
2036
2034
|
it "deletes the documents from the database" do
|
2037
2035
|
person.posts.send(method)
|
2038
|
-
Post.where(title: "Testing").count.
|
2036
|
+
expect(Post.where(title: "Testing").count).to eq(0)
|
2039
2037
|
end
|
2040
2038
|
|
2041
2039
|
it "returns the number of documents deleted" do
|
2042
|
-
person.posts.send(method).
|
2040
|
+
expect(person.posts.send(method)).to eq(2)
|
2043
2041
|
end
|
2044
2042
|
end
|
2045
2043
|
end
|
@@ -2058,17 +2056,17 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2058
2056
|
end
|
2059
2057
|
|
2060
2058
|
it "removes the correct ratings" do
|
2061
|
-
movie.ratings.send(method,
|
2062
|
-
movie.ratings.count.
|
2059
|
+
movie.ratings.send(method, { value: 1 })
|
2060
|
+
expect(movie.ratings.count).to eq(1)
|
2063
2061
|
end
|
2064
2062
|
|
2065
2063
|
it "deletes the documents from the database" do
|
2066
|
-
movie.ratings.send(method,
|
2067
|
-
Rating.where(value: 1).count.
|
2064
|
+
movie.ratings.send(method, { value: 1 })
|
2065
|
+
expect(Rating.where(value: 1).count).to eq(0)
|
2068
2066
|
end
|
2069
2067
|
|
2070
2068
|
it "returns the number of documents deleted" do
|
2071
|
-
movie.ratings.send(method,
|
2069
|
+
expect(movie.ratings.send(method, { value: 1 })).to eq(1)
|
2072
2070
|
end
|
2073
2071
|
end
|
2074
2072
|
|
@@ -2085,164 +2083,26 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2085
2083
|
|
2086
2084
|
it "removes the correct ratings" do
|
2087
2085
|
movie.ratings.send(method)
|
2088
|
-
movie.ratings.count.
|
2086
|
+
expect(movie.ratings.count).to eq(0)
|
2089
2087
|
end
|
2090
2088
|
|
2091
2089
|
it "deletes the documents from the database" do
|
2092
2090
|
movie.ratings.send(method)
|
2093
|
-
Rating.where(value: 1).count.
|
2091
|
+
expect(Rating.where(value: 1).count).to eq(0)
|
2094
2092
|
end
|
2095
2093
|
|
2096
2094
|
it "returns the number of documents deleted" do
|
2097
|
-
movie.ratings.send(method).
|
2095
|
+
expect(movie.ratings.send(method)).to eq(2)
|
2098
2096
|
end
|
2099
2097
|
end
|
2100
2098
|
end
|
2101
2099
|
end
|
2102
2100
|
end
|
2103
2101
|
|
2104
|
-
describe ".eager_load" do
|
2105
|
-
|
2106
|
-
before do
|
2107
|
-
Mongoid.identity_map_enabled = true
|
2108
|
-
end
|
2109
|
-
|
2110
|
-
after do
|
2111
|
-
Mongoid.identity_map_enabled = false
|
2112
|
-
end
|
2113
|
-
|
2114
|
-
context "when the relation is not polymorphic" do
|
2115
|
-
|
2116
|
-
context "when the eager load has returned documents" do
|
2117
|
-
|
2118
|
-
let!(:person) do
|
2119
|
-
Person.create
|
2120
|
-
end
|
2121
|
-
|
2122
|
-
let!(:post) do
|
2123
|
-
person.posts.create(title: "testing")
|
2124
|
-
end
|
2125
|
-
|
2126
|
-
let(:metadata) do
|
2127
|
-
Person.relations["posts"]
|
2128
|
-
end
|
2129
|
-
|
2130
|
-
let!(:eager) do
|
2131
|
-
described_class.eager_load(metadata, Person.all.map(&:_id))
|
2132
|
-
end
|
2133
|
-
|
2134
|
-
let(:map) do
|
2135
|
-
Mongoid::IdentityMap.get(Post, {"person_id" => person.id})
|
2136
|
-
end
|
2137
|
-
|
2138
|
-
it "puts the documents in the identity map" do
|
2139
|
-
map.should eq({ post.id => post })
|
2140
|
-
end
|
2141
|
-
end
|
2142
|
-
|
2143
|
-
context "when the eager load has not returned documents" do
|
2144
|
-
|
2145
|
-
let!(:person) do
|
2146
|
-
Person.create
|
2147
|
-
end
|
2148
|
-
|
2149
|
-
let(:metadata) do
|
2150
|
-
Person.relations["posts"]
|
2151
|
-
end
|
2152
|
-
|
2153
|
-
let!(:eager) do
|
2154
|
-
described_class.eager_load(metadata, Person.all.map(&:_id))
|
2155
|
-
end
|
2156
|
-
|
2157
|
-
let(:map) do
|
2158
|
-
Mongoid::IdentityMap.get(Post, {"person_id" => person.id})
|
2159
|
-
end
|
2160
|
-
|
2161
|
-
it "puts an empty array in the identity map" do
|
2162
|
-
map.should be_empty
|
2163
|
-
end
|
2164
|
-
end
|
2165
|
-
|
2166
|
-
context "when the eager load has not returned documents for some" do
|
2167
|
-
|
2168
|
-
let!(:person_one) do
|
2169
|
-
Person.create
|
2170
|
-
end
|
2171
|
-
|
2172
|
-
let!(:person_two) do
|
2173
|
-
Person.create
|
2174
|
-
end
|
2175
|
-
|
2176
|
-
let!(:post) do
|
2177
|
-
person_one.posts.create(title: "testing")
|
2178
|
-
end
|
2179
|
-
|
2180
|
-
let(:metadata) do
|
2181
|
-
Person.relations["posts"]
|
2182
|
-
end
|
2183
|
-
|
2184
|
-
let!(:eager) do
|
2185
|
-
described_class.eager_load(metadata, Person.all.map(&:_id))
|
2186
|
-
end
|
2187
|
-
|
2188
|
-
let(:map_one) do
|
2189
|
-
Mongoid::IdentityMap.get(Post, {"person_id" => person_one.id})
|
2190
|
-
end
|
2191
|
-
|
2192
|
-
let(:map_two) do
|
2193
|
-
Mongoid::IdentityMap.get(Post, {"person_id" => person_two.id})
|
2194
|
-
end
|
2195
|
-
|
2196
|
-
it "puts the found documents in the identity map" do
|
2197
|
-
map_one.should eq({ post.id => post })
|
2198
|
-
end
|
2199
|
-
|
2200
|
-
it "puts an empty array for parents with no docs" do
|
2201
|
-
map_two.should be_empty
|
2202
|
-
end
|
2203
|
-
end
|
2204
|
-
end
|
2205
|
-
|
2206
|
-
context "when the relation is polymorphic" do
|
2207
|
-
|
2208
|
-
let!(:movie) do
|
2209
|
-
Movie.create(name: "Bladerunner")
|
2210
|
-
end
|
2211
|
-
|
2212
|
-
let!(:book) do
|
2213
|
-
Book.create(name: "Game of Thrones")
|
2214
|
-
end
|
2215
|
-
|
2216
|
-
let!(:movie_rating) do
|
2217
|
-
movie.ratings.create(value: 10)
|
2218
|
-
end
|
2219
|
-
|
2220
|
-
let!(:book_rating) do
|
2221
|
-
book.create_rating(value: 10)
|
2222
|
-
end
|
2223
|
-
|
2224
|
-
let(:metadata) do
|
2225
|
-
Movie.relations["ratings"]
|
2226
|
-
end
|
2227
|
-
|
2228
|
-
let!(:eager) do
|
2229
|
-
described_class.eager_load(metadata, Movie.all.map(&:_id))
|
2230
|
-
end
|
2231
|
-
|
2232
|
-
let(:map) do
|
2233
|
-
Mongoid::IdentityMap.get(Rating, {"ratable_id" => movie.id})
|
2234
|
-
end
|
2235
|
-
|
2236
|
-
it "puts the documents in the identity map" do
|
2237
|
-
map.should eq({ movie_rating.id => movie_rating })
|
2238
|
-
end
|
2239
|
-
end
|
2240
|
-
end
|
2241
|
-
|
2242
2102
|
describe ".embedded?" do
|
2243
2103
|
|
2244
2104
|
it "returns false" do
|
2245
|
-
described_class.
|
2105
|
+
expect(described_class).to_not be_embedded
|
2246
2106
|
end
|
2247
2107
|
end
|
2248
2108
|
|
@@ -2259,7 +2119,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2259
2119
|
end
|
2260
2120
|
|
2261
2121
|
it "returns true" do
|
2262
|
-
person.posts.exists
|
2122
|
+
expect(person.posts.exists?).to be true
|
2263
2123
|
end
|
2264
2124
|
end
|
2265
2125
|
|
@@ -2270,7 +2130,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2270
2130
|
end
|
2271
2131
|
|
2272
2132
|
it "returns false" do
|
2273
|
-
person.posts.exists
|
2133
|
+
expect(person.posts.exists?).to be false
|
2274
2134
|
end
|
2275
2135
|
end
|
2276
2136
|
end
|
@@ -2279,14 +2139,6 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2279
2139
|
|
2280
2140
|
context "when the identity map is enabled" do
|
2281
2141
|
|
2282
|
-
before do
|
2283
|
-
Mongoid.identity_map_enabled = true
|
2284
|
-
end
|
2285
|
-
|
2286
|
-
after do
|
2287
|
-
Mongoid.identity_map_enabled = false
|
2288
|
-
end
|
2289
|
-
|
2290
2142
|
context "when the document is in the map" do
|
2291
2143
|
|
2292
2144
|
let(:person) do
|
@@ -2335,7 +2187,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2335
2187
|
end
|
2336
2188
|
|
2337
2189
|
it "returns the matching document" do
|
2338
|
-
post.
|
2190
|
+
expect(post).to eq(post_one)
|
2339
2191
|
end
|
2340
2192
|
end
|
2341
2193
|
|
@@ -2362,7 +2214,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2362
2214
|
|
2363
2215
|
it "raises an error" do
|
2364
2216
|
expect {
|
2365
|
-
person.posts.find(
|
2217
|
+
person.posts.find(BSON::ObjectId.new)
|
2366
2218
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2367
2219
|
end
|
2368
2220
|
end
|
@@ -2370,7 +2222,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2370
2222
|
context "when config set not to raise error" do
|
2371
2223
|
|
2372
2224
|
let(:post) do
|
2373
|
-
person.posts.find(
|
2225
|
+
person.posts.find(BSON::ObjectId.new)
|
2374
2226
|
end
|
2375
2227
|
|
2376
2228
|
before do
|
@@ -2382,7 +2234,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2382
2234
|
end
|
2383
2235
|
|
2384
2236
|
it "returns nil" do
|
2385
|
-
post.
|
2237
|
+
expect(post).to be_nil
|
2386
2238
|
end
|
2387
2239
|
end
|
2388
2240
|
end
|
@@ -2397,7 +2249,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2397
2249
|
end
|
2398
2250
|
|
2399
2251
|
it "returns the matching documents" do
|
2400
|
-
posts.
|
2252
|
+
expect(posts).to eq([ post_one, post_two ])
|
2401
2253
|
end
|
2402
2254
|
end
|
2403
2255
|
|
@@ -2411,7 +2263,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2411
2263
|
|
2412
2264
|
it "raises an error" do
|
2413
2265
|
expect {
|
2414
|
-
person.posts.find([
|
2266
|
+
person.posts.find([ BSON::ObjectId.new ])
|
2415
2267
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2416
2268
|
end
|
2417
2269
|
end
|
@@ -2419,7 +2271,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2419
2271
|
context "when config set not to raise error" do
|
2420
2272
|
|
2421
2273
|
let(:posts) do
|
2422
|
-
person.posts.find([
|
2274
|
+
person.posts.find([ BSON::ObjectId.new ])
|
2423
2275
|
end
|
2424
2276
|
|
2425
2277
|
before do
|
@@ -2431,7 +2283,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2431
2283
|
end
|
2432
2284
|
|
2433
2285
|
it "returns an empty array" do
|
2434
|
-
posts.
|
2286
|
+
expect(posts).to be_empty
|
2435
2287
|
end
|
2436
2288
|
end
|
2437
2289
|
end
|
@@ -2461,7 +2313,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2461
2313
|
end
|
2462
2314
|
|
2463
2315
|
it "returns the matching document" do
|
2464
|
-
rating.
|
2316
|
+
expect(rating).to eq(rating_one)
|
2465
2317
|
end
|
2466
2318
|
end
|
2467
2319
|
|
@@ -2475,7 +2327,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2475
2327
|
|
2476
2328
|
it "raises an error" do
|
2477
2329
|
expect {
|
2478
|
-
movie.ratings.find(
|
2330
|
+
movie.ratings.find(BSON::ObjectId.new)
|
2479
2331
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2480
2332
|
end
|
2481
2333
|
end
|
@@ -2483,7 +2335,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2483
2335
|
context "when config set not to raise error" do
|
2484
2336
|
|
2485
2337
|
let(:rating) do
|
2486
|
-
movie.ratings.find(
|
2338
|
+
movie.ratings.find(BSON::ObjectId.new)
|
2487
2339
|
end
|
2488
2340
|
|
2489
2341
|
before do
|
@@ -2495,7 +2347,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2495
2347
|
end
|
2496
2348
|
|
2497
2349
|
it "returns nil" do
|
2498
|
-
rating.
|
2350
|
+
expect(rating).to be_nil
|
2499
2351
|
end
|
2500
2352
|
end
|
2501
2353
|
end
|
@@ -2510,7 +2362,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2510
2362
|
end
|
2511
2363
|
|
2512
2364
|
it "returns the matching documents" do
|
2513
|
-
ratings.
|
2365
|
+
expect(ratings).to eq([ rating_one, rating_two ])
|
2514
2366
|
end
|
2515
2367
|
end
|
2516
2368
|
|
@@ -2524,7 +2376,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2524
2376
|
|
2525
2377
|
it "raises an error" do
|
2526
2378
|
expect {
|
2527
|
-
movie.ratings.find([
|
2379
|
+
movie.ratings.find([ BSON::ObjectId.new ])
|
2528
2380
|
}.to raise_error(Mongoid::Errors::DocumentNotFound)
|
2529
2381
|
end
|
2530
2382
|
end
|
@@ -2532,7 +2384,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2532
2384
|
context "when config set not to raise error" do
|
2533
2385
|
|
2534
2386
|
let(:ratings) do
|
2535
|
-
movie.ratings.find([
|
2387
|
+
movie.ratings.find([ BSON::ObjectId.new ])
|
2536
2388
|
end
|
2537
2389
|
|
2538
2390
|
before do
|
@@ -2544,7 +2396,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2544
2396
|
end
|
2545
2397
|
|
2546
2398
|
it "returns an empty array" do
|
2547
|
-
ratings.
|
2399
|
+
expect(ratings).to be_empty
|
2548
2400
|
end
|
2549
2401
|
end
|
2550
2402
|
end
|
@@ -2571,11 +2423,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2571
2423
|
end
|
2572
2424
|
|
2573
2425
|
it "returns the document" do
|
2574
|
-
found.
|
2426
|
+
expect(found).to eq(post)
|
2575
2427
|
end
|
2576
2428
|
|
2577
2429
|
it "keeps the document in the relation" do
|
2578
|
-
found.person.
|
2430
|
+
expect(found.person).to eq(person)
|
2579
2431
|
end
|
2580
2432
|
end
|
2581
2433
|
|
@@ -2590,19 +2442,19 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2590
2442
|
end
|
2591
2443
|
|
2592
2444
|
it "sets the new document attributes" do
|
2593
|
-
found.title.
|
2445
|
+
expect(found.title).to eq("Test")
|
2594
2446
|
end
|
2595
2447
|
|
2596
2448
|
it "returns a newly persisted document" do
|
2597
|
-
found.
|
2449
|
+
expect(found).to be_persisted
|
2598
2450
|
end
|
2599
2451
|
|
2600
2452
|
it "calls the passed block" do
|
2601
|
-
found.content.
|
2453
|
+
expect(found.content).to eq("The Content")
|
2602
2454
|
end
|
2603
2455
|
|
2604
2456
|
it "keeps the document in the relation" do
|
2605
|
-
found.person.
|
2457
|
+
expect(found.person).to eq(person)
|
2606
2458
|
end
|
2607
2459
|
end
|
2608
2460
|
|
@@ -2613,15 +2465,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2613
2465
|
end
|
2614
2466
|
|
2615
2467
|
it "sets the new document attributes" do
|
2616
|
-
found.title.
|
2468
|
+
expect(found.title).to eq("Test")
|
2617
2469
|
end
|
2618
2470
|
|
2619
2471
|
it "returns a newly persisted document" do
|
2620
|
-
found.
|
2472
|
+
expect(found).to be_persisted
|
2621
2473
|
end
|
2622
2474
|
|
2623
2475
|
it "keeps the document in the relation" do
|
2624
|
-
found.person.
|
2476
|
+
expect(found.person).to eq(person)
|
2625
2477
|
end
|
2626
2478
|
end
|
2627
2479
|
end
|
@@ -2644,11 +2496,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2644
2496
|
end
|
2645
2497
|
|
2646
2498
|
it "returns the document" do
|
2647
|
-
found.
|
2499
|
+
expect(found).to eq(rating)
|
2648
2500
|
end
|
2649
2501
|
|
2650
2502
|
it "keeps the document in the relation" do
|
2651
|
-
found.ratable.
|
2503
|
+
expect(found.ratable).to eq(movie)
|
2652
2504
|
end
|
2653
2505
|
end
|
2654
2506
|
|
@@ -2659,15 +2511,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2659
2511
|
end
|
2660
2512
|
|
2661
2513
|
it "sets the new document attributes" do
|
2662
|
-
found.value.
|
2514
|
+
expect(found.value).to eq(3)
|
2663
2515
|
end
|
2664
2516
|
|
2665
2517
|
it "returns a newly persisted document" do
|
2666
|
-
found.
|
2518
|
+
expect(found).to be_persisted
|
2667
2519
|
end
|
2668
2520
|
|
2669
2521
|
it "keeps the document in the relation" do
|
2670
|
-
found.ratable.
|
2522
|
+
expect(found.ratable).to eq(movie)
|
2671
2523
|
end
|
2672
2524
|
end
|
2673
2525
|
end
|
@@ -2692,7 +2544,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2692
2544
|
end
|
2693
2545
|
|
2694
2546
|
it "returns the document" do
|
2695
|
-
found.
|
2547
|
+
expect(found).to eq(post)
|
2696
2548
|
end
|
2697
2549
|
end
|
2698
2550
|
|
@@ -2705,15 +2557,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2705
2557
|
end
|
2706
2558
|
|
2707
2559
|
it "sets the new document attributes" do
|
2708
|
-
found.title.
|
2560
|
+
expect(found.title).to eq("Test")
|
2709
2561
|
end
|
2710
2562
|
|
2711
2563
|
it "returns a non persisted document" do
|
2712
|
-
found.
|
2564
|
+
expect(found).to_not be_persisted
|
2713
2565
|
end
|
2714
2566
|
|
2715
2567
|
it "calls the passed block" do
|
2716
|
-
found.content.
|
2568
|
+
expect(found.content).to eq("The Content")
|
2717
2569
|
end
|
2718
2570
|
end
|
2719
2571
|
end
|
@@ -2735,7 +2587,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2735
2587
|
end
|
2736
2588
|
|
2737
2589
|
it "returns the document" do
|
2738
|
-
found.
|
2590
|
+
expect(found).to eq(rating)
|
2739
2591
|
end
|
2740
2592
|
end
|
2741
2593
|
|
@@ -2746,11 +2598,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2746
2598
|
end
|
2747
2599
|
|
2748
2600
|
it "sets the new document attributes" do
|
2749
|
-
found.value.
|
2601
|
+
expect(found.value).to eq(3)
|
2750
2602
|
end
|
2751
2603
|
|
2752
2604
|
it "returns a non persisted document" do
|
2753
|
-
found.
|
2605
|
+
expect(found).to_not be_persisted
|
2754
2606
|
end
|
2755
2607
|
end
|
2756
2608
|
end
|
@@ -2759,7 +2611,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2759
2611
|
describe ".foreign_key_suffix" do
|
2760
2612
|
|
2761
2613
|
it "returns _id" do
|
2762
|
-
described_class.foreign_key_suffix.
|
2614
|
+
expect(described_class.foreign_key_suffix).to eq("_id")
|
2763
2615
|
end
|
2764
2616
|
end
|
2765
2617
|
|
@@ -2785,7 +2637,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2785
2637
|
end
|
2786
2638
|
|
2787
2639
|
it "does not raise an error" do
|
2788
|
-
post.roles.
|
2640
|
+
expect(post.roles).to be_empty
|
2789
2641
|
end
|
2790
2642
|
end
|
2791
2643
|
end
|
@@ -2793,7 +2645,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2793
2645
|
describe ".macro" do
|
2794
2646
|
|
2795
2647
|
it "returns has_many" do
|
2796
|
-
described_class.macro.
|
2648
|
+
expect(described_class.macro).to eq(:has_many)
|
2797
2649
|
end
|
2798
2650
|
end
|
2799
2651
|
|
@@ -2822,7 +2674,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2822
2674
|
end
|
2823
2675
|
|
2824
2676
|
it "returns the document with the max value of the supplied field" do
|
2825
|
-
max.
|
2677
|
+
expect(max).to eq(post_two)
|
2826
2678
|
end
|
2827
2679
|
end
|
2828
2680
|
|
@@ -2849,7 +2701,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2849
2701
|
end
|
2850
2702
|
|
2851
2703
|
it "returns the document with the max value of the supplied field" do
|
2852
|
-
max.
|
2704
|
+
expect(max).to eq(post_two)
|
2853
2705
|
end
|
2854
2706
|
end
|
2855
2707
|
|
@@ -2874,7 +2726,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2874
2726
|
end
|
2875
2727
|
|
2876
2728
|
it "applies the criteria to the documents" do
|
2877
|
-
posts.
|
2729
|
+
expect(posts).to eq([ post_one ])
|
2878
2730
|
end
|
2879
2731
|
end
|
2880
2732
|
|
@@ -2885,7 +2737,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2885
2737
|
end
|
2886
2738
|
|
2887
2739
|
it "applies the criteria to the documents" do
|
2888
|
-
posts.
|
2740
|
+
expect(posts).to eq([ post_one ])
|
2889
2741
|
end
|
2890
2742
|
end
|
2891
2743
|
|
@@ -2896,7 +2748,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2896
2748
|
end
|
2897
2749
|
|
2898
2750
|
it "applies the criteria to the documents" do
|
2899
|
-
posts.
|
2751
|
+
expect(posts).to eq([ post_one ])
|
2900
2752
|
end
|
2901
2753
|
end
|
2902
2754
|
|
@@ -2904,8 +2756,13 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2904
2756
|
|
2905
2757
|
describe "#distinct" do
|
2906
2758
|
|
2759
|
+
let(:values) do
|
2760
|
+
person.posts.distinct(:title)
|
2761
|
+
end
|
2762
|
+
|
2907
2763
|
it "returns the distinct values for the fields" do
|
2908
|
-
|
2764
|
+
expect(values).to include("First")
|
2765
|
+
expect(values).to include("Second")
|
2909
2766
|
end
|
2910
2767
|
end
|
2911
2768
|
end
|
@@ -2936,7 +2793,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2936
2793
|
end
|
2937
2794
|
|
2938
2795
|
it "returns the min value of the supplied field" do
|
2939
|
-
min.
|
2796
|
+
expect(min).to eq(post_one)
|
2940
2797
|
end
|
2941
2798
|
end
|
2942
2799
|
|
@@ -2963,7 +2820,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2963
2820
|
end
|
2964
2821
|
|
2965
2822
|
it "returns the min value of the supplied field" do
|
2966
|
-
min.
|
2823
|
+
expect(min).to eq(post_one)
|
2967
2824
|
end
|
2968
2825
|
end
|
2969
2826
|
|
@@ -2992,16 +2849,16 @@ describe Mongoid::Relations::Referenced::Many do
|
|
2992
2849
|
end
|
2993
2850
|
|
2994
2851
|
it "loads the targets before nullifying" do
|
2995
|
-
from_db.posts.
|
2852
|
+
expect(from_db.posts).to be_empty
|
2996
2853
|
end
|
2997
2854
|
|
2998
2855
|
it "persists the base nullifications" do
|
2999
|
-
Person.first.posts.
|
2856
|
+
expect(Person.first.posts).to be_empty
|
3000
2857
|
end
|
3001
2858
|
|
3002
2859
|
it "persists the inverse nullifications" do
|
3003
2860
|
Post.all.each do |post|
|
3004
|
-
post.person.
|
2861
|
+
expect(post.person).to be_nil
|
3005
2862
|
end
|
3006
2863
|
end
|
3007
2864
|
end
|
@@ -3026,18 +2883,18 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3026
2883
|
|
3027
2884
|
it "removes all the foreign keys from the target" do
|
3028
2885
|
[ post_one, post_two ].each do |post|
|
3029
|
-
post.person_id.
|
2886
|
+
expect(post.person_id).to be_nil
|
3030
2887
|
end
|
3031
2888
|
end
|
3032
2889
|
|
3033
2890
|
it "removes all the references from the target" do
|
3034
2891
|
[ post_one, post_two ].each do |post|
|
3035
|
-
post.person.
|
2892
|
+
expect(post.person).to be_nil
|
3036
2893
|
end
|
3037
2894
|
end
|
3038
2895
|
|
3039
2896
|
it "saves the documents" do
|
3040
|
-
post_one.reload.person.
|
2897
|
+
expect(post_one.reload.person).to be_nil
|
3041
2898
|
end
|
3042
2899
|
|
3043
2900
|
context "when adding a nullified document back to the relation" do
|
@@ -3047,7 +2904,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3047
2904
|
end
|
3048
2905
|
|
3049
2906
|
it "persists the relation" do
|
3050
|
-
person.posts(true).
|
2907
|
+
expect(person.posts(true)).to eq([ post_one ])
|
3051
2908
|
end
|
3052
2909
|
end
|
3053
2910
|
end
|
@@ -3072,13 +2929,13 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3072
2929
|
|
3073
2930
|
it "removes all the foreign keys from the target" do
|
3074
2931
|
[ rating_one, rating_two ].each do |rating|
|
3075
|
-
rating.ratable_id.
|
2932
|
+
expect(rating.ratable_id).to be_nil
|
3076
2933
|
end
|
3077
2934
|
end
|
3078
2935
|
|
3079
2936
|
it "removes all the references from the target" do
|
3080
2937
|
[ rating_one, rating_two ].each do |rating|
|
3081
|
-
rating.ratable.
|
2938
|
+
expect(rating.ratable).to be_nil
|
3082
2939
|
end
|
3083
2940
|
end
|
3084
2941
|
end
|
@@ -3099,7 +2956,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3099
2956
|
context "when checking #{method}" do
|
3100
2957
|
|
3101
2958
|
it "returns true" do
|
3102
|
-
posts.respond_to?(method).
|
2959
|
+
expect(posts.respond_to?(method)).to be true
|
3103
2960
|
end
|
3104
2961
|
end
|
3105
2962
|
end
|
@@ -3109,7 +2966,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3109
2966
|
context "when checking #{method}" do
|
3110
2967
|
|
3111
2968
|
it "returns true" do
|
3112
|
-
posts.respond_to?(method).
|
2969
|
+
expect(posts.respond_to?(method)).to be true
|
3113
2970
|
end
|
3114
2971
|
end
|
3115
2972
|
end
|
@@ -3119,7 +2976,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3119
2976
|
context "when checking #{method}" do
|
3120
2977
|
|
3121
2978
|
it "returns true" do
|
3122
|
-
posts.respond_to?(method).
|
2979
|
+
expect(posts.respond_to?(method)).to be true
|
3123
2980
|
end
|
3124
2981
|
end
|
3125
2982
|
end
|
@@ -3128,7 +2985,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3128
2985
|
describe ".stores_foreign_key?" do
|
3129
2986
|
|
3130
2987
|
it "returns false" do
|
3131
|
-
described_class.stores_foreign_key
|
2988
|
+
expect(described_class.stores_foreign_key?).to be false
|
3132
2989
|
end
|
3133
2990
|
end
|
3134
2991
|
|
@@ -3143,11 +3000,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3143
3000
|
end
|
3144
3001
|
|
3145
3002
|
it "returns the relation criteria" do
|
3146
|
-
scoped.
|
3003
|
+
expect(scoped).to be_a(Mongoid::Criteria)
|
3147
3004
|
end
|
3148
3005
|
|
3149
3006
|
it "returns with an empty selector" do
|
3150
|
-
scoped.selector.
|
3007
|
+
expect(scoped.selector).to eq({ "person_id" => person.id })
|
3151
3008
|
end
|
3152
3009
|
end
|
3153
3010
|
|
@@ -3166,7 +3023,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3166
3023
|
end
|
3167
3024
|
|
3168
3025
|
it "returns 1" do
|
3169
|
-
movie.ratings.send(method).
|
3026
|
+
expect(movie.ratings.send(method)).to eq(1)
|
3170
3027
|
end
|
3171
3028
|
end
|
3172
3029
|
|
@@ -3178,7 +3035,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3178
3035
|
end
|
3179
3036
|
|
3180
3037
|
it "returns the total number of documents" do
|
3181
|
-
movie.ratings.send(method).
|
3038
|
+
expect(movie.ratings.send(method)).to eq(2)
|
3182
3039
|
end
|
3183
3040
|
end
|
3184
3041
|
end
|
@@ -3205,7 +3062,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3205
3062
|
end
|
3206
3063
|
|
3207
3064
|
it "returns only the associated documents" do
|
3208
|
-
unscoped.
|
3065
|
+
expect(unscoped).to eq([ post_one ])
|
3209
3066
|
end
|
3210
3067
|
end
|
3211
3068
|
|
@@ -3228,11 +3085,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3228
3085
|
end
|
3229
3086
|
|
3230
3087
|
it "only returns associated documents" do
|
3231
|
-
unscoped.
|
3088
|
+
expect(unscoped).to eq([ acolyte_one ])
|
3232
3089
|
end
|
3233
3090
|
|
3234
3091
|
it "removes the default scoping options" do
|
3235
|
-
unscoped.options.
|
3092
|
+
expect(unscoped.options).to eq({})
|
3236
3093
|
end
|
3237
3094
|
end
|
3238
3095
|
end
|
@@ -3240,7 +3097,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3240
3097
|
describe ".valid_options" do
|
3241
3098
|
|
3242
3099
|
it "returns the valid options" do
|
3243
|
-
described_class.valid_options.
|
3100
|
+
expect(described_class.valid_options).to eq(
|
3244
3101
|
[
|
3245
3102
|
:after_add,
|
3246
3103
|
:after_remove,
|
@@ -3260,7 +3117,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3260
3117
|
describe ".validation_default" do
|
3261
3118
|
|
3262
3119
|
it "returns true" do
|
3263
|
-
described_class.validation_default.
|
3120
|
+
expect(described_class.validation_default).to be true
|
3264
3121
|
end
|
3265
3122
|
end
|
3266
3123
|
|
@@ -3288,13 +3145,13 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3288
3145
|
end
|
3289
3146
|
|
3290
3147
|
it "order documents" do
|
3291
|
-
person.ordered_posts(true).
|
3148
|
+
expect(person.ordered_posts(true)).to eq(
|
3292
3149
|
[post_two, post_three, post_one]
|
3293
3150
|
)
|
3294
3151
|
end
|
3295
3152
|
|
3296
3153
|
it "chaining order criterias" do
|
3297
|
-
person.ordered_posts.order_by(:title.desc).to_a.
|
3154
|
+
expect(person.ordered_posts.order_by(:title.desc).to_a).to eq(
|
3298
3155
|
[post_three, post_two, post_one]
|
3299
3156
|
)
|
3300
3157
|
end
|
@@ -3330,7 +3187,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3330
3187
|
end
|
3331
3188
|
|
3332
3189
|
it "reloads the document from the database" do
|
3333
|
-
reloaded.first.title.
|
3190
|
+
expect(reloaded.first.title).to eq("reloaded")
|
3334
3191
|
end
|
3335
3192
|
end
|
3336
3193
|
|
@@ -3345,11 +3202,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3345
3202
|
end
|
3346
3203
|
|
3347
3204
|
it "reloads the first document from the database" do
|
3348
|
-
reloaded.
|
3205
|
+
expect(reloaded).to include(post_one)
|
3349
3206
|
end
|
3350
3207
|
|
3351
3208
|
it "reloads the new document from the database" do
|
3352
|
-
reloaded.
|
3209
|
+
expect(reloaded).to include(post_two)
|
3353
3210
|
end
|
3354
3211
|
end
|
3355
3212
|
end
|
@@ -3363,7 +3220,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3363
3220
|
end
|
3364
3221
|
|
3365
3222
|
it "allows creation of the document" do
|
3366
|
-
jar.id.
|
3223
|
+
expect(jar.id).to eq(1)
|
3367
3224
|
end
|
3368
3225
|
end
|
3369
3226
|
|
@@ -3392,7 +3249,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3392
3249
|
end
|
3393
3250
|
|
3394
3251
|
it "adds both documents" do
|
3395
|
-
result.
|
3252
|
+
expect(result).to eq([ post_one, post_two ])
|
3396
3253
|
end
|
3397
3254
|
end
|
3398
3255
|
end
|
@@ -3414,15 +3271,15 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3414
3271
|
end
|
3415
3272
|
|
3416
3273
|
it "it executes method callbacks" do
|
3417
|
-
artist.before_add_referenced_called.
|
3274
|
+
expect(artist.before_add_referenced_called).to be true
|
3418
3275
|
end
|
3419
3276
|
|
3420
3277
|
it "it executes proc callbacks" do
|
3421
|
-
album.before_add_called.
|
3278
|
+
expect(album.before_add_called).to be true
|
3422
3279
|
end
|
3423
3280
|
|
3424
3281
|
it "adds the document to the relation" do
|
3425
|
-
artist.albums.
|
3282
|
+
expect(artist.albums).to eq([ album ])
|
3426
3283
|
end
|
3427
3284
|
end
|
3428
3285
|
|
@@ -3436,7 +3293,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3436
3293
|
expect {
|
3437
3294
|
artist.albums << album
|
3438
3295
|
}.to raise_error
|
3439
|
-
artist.albums.
|
3296
|
+
expect(artist.albums).to be_empty
|
3440
3297
|
end
|
3441
3298
|
end
|
3442
3299
|
end
|
@@ -3453,7 +3310,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3453
3310
|
|
3454
3311
|
it "executes the callback" do
|
3455
3312
|
artist.albums << album
|
3456
|
-
artist.after_add_referenced_called.
|
3313
|
+
expect(artist.after_add_referenced_called).to be true
|
3457
3314
|
end
|
3458
3315
|
|
3459
3316
|
context "when execution raises errors" do
|
@@ -3466,7 +3323,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3466
3323
|
expect {
|
3467
3324
|
artist.albums << album
|
3468
3325
|
}.to raise_error
|
3469
|
-
artist.albums.
|
3326
|
+
expect(artist.albums).to eq([ album ])
|
3470
3327
|
end
|
3471
3328
|
end
|
3472
3329
|
end
|
@@ -3494,11 +3351,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3494
3351
|
end
|
3495
3352
|
|
3496
3353
|
it "executes the callback" do
|
3497
|
-
artist.before_remove_referenced_called.
|
3354
|
+
expect(artist.before_remove_referenced_called).to be true
|
3498
3355
|
end
|
3499
3356
|
|
3500
3357
|
it "removes the document from the relation" do
|
3501
|
-
artist.albums.
|
3358
|
+
expect(artist.albums).to be_empty
|
3502
3359
|
end
|
3503
3360
|
end
|
3504
3361
|
|
@@ -3509,11 +3366,11 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3509
3366
|
end
|
3510
3367
|
|
3511
3368
|
it "executes the callback" do
|
3512
|
-
artist.before_remove_referenced_called.
|
3369
|
+
expect(artist.before_remove_referenced_called).to be true
|
3513
3370
|
end
|
3514
3371
|
|
3515
3372
|
it "clears the relation" do
|
3516
|
-
artist.albums.
|
3373
|
+
expect(artist.albums).to be_empty
|
3517
3374
|
end
|
3518
3375
|
end
|
3519
3376
|
|
@@ -3532,7 +3389,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3532
3389
|
end
|
3533
3390
|
|
3534
3391
|
it "does not remove the document from the relation" do
|
3535
|
-
artist.albums.
|
3392
|
+
expect(artist.albums).to eq([ album ])
|
3536
3393
|
end
|
3537
3394
|
end
|
3538
3395
|
|
@@ -3545,7 +3402,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3545
3402
|
end
|
3546
3403
|
|
3547
3404
|
it "does not clear the relation" do
|
3548
|
-
artist.albums.
|
3405
|
+
expect(artist.albums).to eq([ album ])
|
3549
3406
|
end
|
3550
3407
|
end
|
3551
3408
|
end
|
@@ -3575,7 +3432,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3575
3432
|
end
|
3576
3433
|
|
3577
3434
|
it "executes the callback" do
|
3578
|
-
artist.after_remove_referenced_called.
|
3435
|
+
expect(artist.after_remove_referenced_called).to be true
|
3579
3436
|
end
|
3580
3437
|
end
|
3581
3438
|
|
@@ -3587,7 +3444,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3587
3444
|
|
3588
3445
|
it "executes the callback" do
|
3589
3446
|
artist.albums.clear
|
3590
|
-
artist.after_remove_referenced_called.
|
3447
|
+
expect(artist.after_remove_referenced_called).to be true
|
3591
3448
|
end
|
3592
3449
|
end
|
3593
3450
|
end
|
@@ -3607,7 +3464,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3607
3464
|
end
|
3608
3465
|
|
3609
3466
|
it "removes the documents from the relation" do
|
3610
|
-
artist.albums.
|
3467
|
+
expect(artist.albums).to be_empty
|
3611
3468
|
end
|
3612
3469
|
end
|
3613
3470
|
|
@@ -3620,7 +3477,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3620
3477
|
end
|
3621
3478
|
|
3622
3479
|
it "removes the documents from the relation" do
|
3623
|
-
artist.albums.
|
3480
|
+
expect(artist.albums).to be_empty
|
3624
3481
|
end
|
3625
3482
|
end
|
3626
3483
|
end
|
@@ -3645,7 +3502,7 @@ describe Mongoid::Relations::Referenced::Many do
|
|
3645
3502
|
end
|
3646
3503
|
|
3647
3504
|
it "does not drop the ordering" do
|
3648
|
-
criteria.
|
3505
|
+
expect(criteria).to eq([ post_two, post_one ])
|
3649
3506
|
end
|
3650
3507
|
end
|
3651
3508
|
end
|