mongoid 3.1.6 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +479 -8
- data/README.md +10 -7
- data/lib/config/locales/en.yml +34 -20
- data/lib/mongoid.rb +10 -76
- data/lib/mongoid/atomic.rb +3 -14
- data/lib/mongoid/atomic/paths/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/embedded/many.rb +1 -1
- data/lib/mongoid/atomic/paths/embedded/one.rb +1 -1
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/attributes.rb +65 -101
- data/lib/mongoid/attributes/dynamic.rb +154 -0
- data/lib/mongoid/attributes/nested.rb +82 -0
- data/lib/mongoid/attributes/processing.rb +13 -66
- data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
- data/lib/mongoid/composable.rb +105 -0
- data/lib/mongoid/config.rb +3 -9
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/contextual.rb +2 -0
- data/lib/mongoid/contextual/aggregable/memory.rb +2 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +7 -9
- data/lib/mongoid/contextual/atomic.rb +53 -53
- data/lib/mongoid/contextual/geo_near.rb +1 -1
- data/lib/mongoid/contextual/map_reduce.rb +4 -2
- data/lib/mongoid/contextual/memory.rb +23 -11
- data/lib/mongoid/contextual/mongo.rb +75 -57
- data/lib/mongoid/contextual/none.rb +90 -0
- data/lib/mongoid/contextual/text_search.rb +178 -0
- data/lib/mongoid/copyable.rb +2 -3
- data/lib/mongoid/criteria.rb +39 -34
- data/lib/mongoid/criteria/#findable.rb# +141 -0
- data/lib/mongoid/{criterion → criteria}/findable.rb +7 -47
- data/lib/mongoid/{criterion/inspection.rb → criteria/inspectable.rb} +2 -2
- data/lib/mongoid/{criterion → criteria}/marshalable.rb +3 -1
- data/lib/mongoid/{criterion → criteria}/modifiable.rb +28 -8
- data/lib/mongoid/criteria/permission.rb +70 -0
- data/lib/mongoid/{criterion/scoping.rb → criteria/scopable.rb} +2 -2
- data/lib/mongoid/document.rb +39 -24
- data/lib/mongoid/errors.rb +4 -1
- data/lib/mongoid/errors/document_not_destroyed.rb +25 -0
- data/lib/mongoid/errors/document_not_found.rb +2 -1
- data/lib/mongoid/errors/invalid_storage_options.rb +1 -1
- data/lib/mongoid/errors/invalid_storage_parent.rb +26 -0
- data/lib/mongoid/errors/invalid_value.rb +16 -0
- data/lib/mongoid/errors/mongoid_error.rb +1 -1
- data/lib/mongoid/errors/readonly_document.rb +24 -0
- data/lib/mongoid/extensions.rb +15 -7
- data/lib/mongoid/extensions/array.rb +3 -3
- data/lib/mongoid/extensions/big_decimal.rb +1 -1
- data/lib/mongoid/extensions/boolean.rb +15 -17
- data/lib/mongoid/extensions/date.rb +1 -1
- data/lib/mongoid/extensions/date_time.rb +3 -3
- data/lib/mongoid/extensions/float.rb +2 -1
- data/lib/mongoid/extensions/hash.rb +3 -3
- data/lib/mongoid/extensions/integer.rb +1 -1
- data/lib/mongoid/extensions/object.rb +7 -7
- data/lib/mongoid/extensions/object_id.rb +5 -5
- data/lib/mongoid/extensions/range.rb +9 -3
- data/lib/mongoid/extensions/regexp.rb +1 -1
- data/lib/mongoid/extensions/set.rb +1 -1
- data/lib/mongoid/extensions/string.rb +6 -18
- data/lib/mongoid/extensions/symbol.rb +1 -1
- data/lib/mongoid/extensions/time.rb +3 -3
- data/lib/mongoid/extensions/time_with_zone.rb +1 -1
- data/lib/mongoid/factory.rb +8 -6
- data/lib/mongoid/fields.rb +41 -8
- data/lib/mongoid/fields/foreign_key.rb +3 -3
- data/lib/mongoid/fields/localized.rb +1 -1
- data/lib/mongoid/fields/standard.rb +5 -17
- data/lib/mongoid/fields/validators/macro.rb +15 -5
- data/lib/mongoid/{finders.rb → findable.rb} +35 -7
- data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
- data/lib/mongoid/indexable/specification.rb +104 -0
- data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
- data/lib/mongoid/{inspection.rb → inspectable.rb} +15 -11
- data/lib/mongoid/{callbacks.rb → interceptable.rb} +30 -62
- data/lib/mongoid/log_subscriber.rb +55 -0
- data/lib/mongoid/matchable.rb +152 -0
- data/lib/mongoid/{matchers → matchable}/all.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/and.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/default.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/exists.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/gte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/in.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/lt.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/lte.rb +1 -1
- data/lib/mongoid/{matchers → matchable}/ne.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
- data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
- data/lib/mongoid/persistable.rb +216 -0
- data/lib/mongoid/persistable/creatable.rb +189 -0
- data/lib/mongoid/persistable/deletable.rb +149 -0
- data/lib/mongoid/persistable/destroyable.rb +60 -0
- data/lib/mongoid/persistable/incrementable.rb +36 -0
- data/lib/mongoid/persistable/logical.rb +38 -0
- data/lib/mongoid/persistable/poppable.rb +39 -0
- data/lib/mongoid/persistable/pullable.rb +55 -0
- data/lib/mongoid/persistable/pushable.rb +62 -0
- data/lib/mongoid/persistable/renamable.rb +35 -0
- data/lib/mongoid/persistable/savable.rb +52 -0
- data/lib/mongoid/persistable/settable.rb +33 -0
- data/lib/mongoid/persistable/unsettable.rb +36 -0
- data/lib/mongoid/persistable/updatable.rb +153 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/query_cache.rb +255 -0
- data/lib/mongoid/railtie.rb +34 -60
- data/lib/mongoid/railties/database.rake +9 -25
- data/lib/mongoid/relations.rb +11 -25
- data/lib/mongoid/relations/accessors.rb +15 -51
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +2 -25
- data/lib/mongoid/relations/bindings/embedded/in.rb +1 -1
- data/lib/mongoid/relations/bindings/embedded/many.rb +1 -3
- data/lib/mongoid/relations/bindings/referenced/in.rb +3 -8
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +4 -2
- data/lib/mongoid/relations/builder.rb +1 -1
- data/lib/mongoid/relations/builders.rb +2 -2
- data/lib/mongoid/relations/builders/embedded/one.rb +1 -1
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +10 -13
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +5 -6
- data/lib/mongoid/relations/builders/referenced/in.rb +1 -1
- data/lib/mongoid/relations/builders/referenced/many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +1 -2
- data/lib/mongoid/relations/builders/referenced/one.rb +1 -1
- data/lib/mongoid/relations/cascading.rb +3 -5
- data/lib/mongoid/relations/constraint.rb +1 -1
- data/lib/mongoid/relations/conversions.rb +1 -1
- data/lib/mongoid/relations/counter_cache.rb +39 -15
- data/lib/mongoid/relations/eager.rb +46 -0
- data/lib/mongoid/relations/eager/base.rb +149 -0
- data/lib/mongoid/relations/eager/belongs_to.rb +31 -0
- data/lib/mongoid/relations/eager/has_and_belongs_to_many.rb +47 -0
- data/lib/mongoid/relations/eager/has_many.rb +38 -0
- data/lib/mongoid/relations/eager/has_one.rb +30 -0
- data/lib/mongoid/relations/embedded/batchable.rb +4 -5
- data/lib/mongoid/relations/embedded/in.rb +4 -4
- data/lib/mongoid/relations/embedded/many.rb +14 -32
- data/lib/mongoid/relations/embedded/one.rb +1 -1
- data/lib/mongoid/relations/macros.rb +3 -4
- data/lib/mongoid/relations/many.rb +51 -31
- data/lib/mongoid/relations/marshalable.rb +3 -3
- data/lib/mongoid/relations/metadata.rb +14 -79
- data/lib/mongoid/relations/nested_builder.rb +2 -2
- data/lib/mongoid/relations/one.rb +1 -1
- data/lib/mongoid/relations/options.rb +1 -0
- data/lib/mongoid/relations/polymorphic.rb +0 -1
- data/lib/mongoid/relations/proxy.rb +21 -41
- data/lib/mongoid/relations/referenced/in.rb +4 -20
- data/lib/mongoid/relations/referenced/many.rb +22 -35
- data/lib/mongoid/relations/referenced/many_to_many.rb +19 -42
- data/lib/mongoid/relations/referenced/one.rb +6 -25
- data/lib/mongoid/relations/synchronization.rb +4 -4
- data/lib/mongoid/relations/targets/enumerable.rb +10 -10
- data/lib/mongoid/relations/touchable.rb +34 -1
- data/lib/mongoid/{reloading.rb → reloadable.rb} +7 -5
- data/lib/mongoid/{scoping.rb → scopable.rb} +36 -36
- data/lib/mongoid/selectable.rb +59 -0
- data/lib/mongoid/{serialization.rb → serializable.rb} +11 -2
- data/lib/mongoid/sessions.rb +37 -345
- data/lib/mongoid/sessions/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +185 -0
- data/lib/mongoid/sessions/storage_options.rb +140 -0
- data/lib/mongoid/sessions/thread_options.rb +19 -0
- data/lib/mongoid/sessions/validators/storage.rb +16 -3
- data/lib/mongoid/{sharding.rb → shardable.rb} +5 -1
- data/lib/mongoid/{state.rb → stateful.rb} +13 -1
- data/lib/mongoid/support/query_counter.rb +23 -0
- data/lib/mongoid/tasks/database.rake +31 -0
- data/lib/mongoid/tasks/database.rb +107 -0
- data/lib/mongoid/threaded.rb +26 -172
- data/lib/mongoid/threaded/lifecycle.rb +0 -28
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
- data/lib/mongoid/{validations → validatable}/associated.rb +4 -2
- data/lib/mongoid/{validations → validatable}/format.rb +1 -1
- data/lib/mongoid/{validations → validatable}/length.rb +1 -1
- data/lib/mongoid/{validations → validatable}/localizable.rb +1 -1
- data/lib/mongoid/{validations → validatable}/macros.rb +4 -3
- data/lib/mongoid/{validations → validatable}/presence.rb +1 -1
- data/lib/mongoid/{validations → validatable}/queryable.rb +1 -2
- data/lib/mongoid/{validations → validatable}/uniqueness.rb +25 -21
- data/lib/mongoid/version.rb +1 -1
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +46 -25
- data/lib/rails/generators/mongoid/model/model_generator.rb +0 -1
- data/lib/rails/generators/mongoid/model/templates/model.rb.tt +0 -3
- data/lib/rails/generators/mongoid_generator.rb +3 -40
- data/lib/rails/mongoid.rb +0 -122
- data/lib/support/ruby_version.rb +1 -1
- data/spec/app/models/account.rb +2 -6
- data/spec/app/models/acolyte.rb +2 -1
- data/spec/app/models/actor.rb +0 -1
- data/spec/app/models/address.rb +8 -3
- data/spec/app/models/animal.rb +1 -1
- data/spec/app/models/appointment.rb +3 -3
- data/spec/app/models/article.rb +1 -4
- data/spec/app/models/audio.rb +5 -0
- data/spec/app/models/author.rb +0 -2
- data/spec/app/models/band.rb +3 -2
- data/spec/app/models/bar.rb +1 -0
- data/spec/app/models/book.rb +1 -0
- data/spec/app/models/building.rb +0 -2
- data/spec/app/models/building_address.rb +0 -2
- data/spec/app/models/bus.rb +1 -1
- data/spec/app/models/canvas.rb +1 -1
- data/spec/app/models/contextable_item.rb +5 -0
- data/spec/app/models/contractor.rb +0 -2
- data/spec/app/models/country_code.rb +1 -1
- data/spec/app/models/definition.rb +2 -2
- data/spec/app/models/dog.rb +1 -1
- data/spec/app/models/draft.rb +9 -0
- data/spec/app/models/dragon.rb +4 -0
- data/spec/app/models/drug.rb +1 -3
- data/spec/app/models/dungeon.rb +4 -0
- data/spec/app/models/edit.rb +5 -0
- data/spec/app/models/even.rb +7 -0
- data/spec/app/models/event.rb +1 -1
- data/spec/app/models/filesystem.rb +1 -0
- data/spec/app/models/fish.rb +0 -1
- data/spec/app/models/fruits.rb +6 -0
- data/spec/app/models/game.rb +0 -2
- data/spec/app/models/house.rb +1 -3
- data/spec/app/models/id_key.rb +6 -0
- data/spec/app/models/item.rb +1 -5
- data/spec/app/models/jar.rb +1 -1
- data/spec/app/models/label.rb +4 -4
- data/spec/app/models/line_item.rb +1 -1
- data/spec/app/models/login.rb +1 -1
- data/spec/app/models/message.rb +8 -0
- data/spec/app/models/movie.rb +1 -0
- data/spec/app/models/name.rb +3 -3
- data/spec/app/models/note.rb +3 -1
- data/spec/app/models/odd.rb +7 -0
- data/spec/app/models/oscar.rb +1 -1
- data/spec/app/models/parent_doc.rb +1 -1
- data/spec/app/models/person.rb +16 -10
- data/spec/app/models/phone.rb +1 -3
- data/spec/app/models/player.rb +3 -3
- data/spec/app/models/post.rb +5 -3
- data/spec/app/models/preference.rb +1 -1
- data/spec/app/models/quiz.rb +0 -3
- data/spec/app/models/record.rb +10 -5
- data/spec/app/models/registry.rb +1 -1
- data/spec/app/models/server.rb +1 -1
- data/spec/app/models/service.rb +3 -3
- data/spec/app/models/sound.rb +5 -0
- data/spec/app/models/symptom.rb +1 -1
- data/spec/app/models/template.rb +1 -1
- data/spec/app/models/title.rb +0 -1
- data/spec/app/models/track.rb +5 -5
- data/spec/app/models/tree.rb +3 -3
- data/spec/app/models/video.rb +1 -5
- data/spec/app/models/wiki_page.rb +2 -5
- data/spec/app/models/word.rb +3 -0
- data/spec/app/models/word_origin.rb +1 -1
- data/spec/config/mongoid.yml +7 -8
- data/spec/helpers.rb +18 -0
- data/spec/mongoid/#atomic_spec.rb# +365 -0
- data/spec/mongoid/atomic/modifiers_spec.rb +22 -22
- data/spec/mongoid/atomic/paths/embedded/many_spec.rb +8 -49
- data/spec/mongoid/atomic/paths/embedded/one_spec.rb +7 -49
- data/spec/mongoid/atomic/paths/root_spec.rb +3 -61
- data/spec/mongoid/atomic/paths_spec.rb +19 -19
- data/spec/mongoid/atomic_spec.rb +19 -19
- data/spec/mongoid/{nested_attributes_spec.rb → attributes/nested_spec.rb} +474 -592
- data/spec/mongoid/attributes/readonly_spec.rb +58 -18
- data/spec/mongoid/attributes_spec.rb +349 -434
- data/spec/mongoid/{dirty_spec.rb → changeable_spec.rb} +203 -153
- data/spec/mongoid/{components_spec.rb → composable_spec.rb} +3 -3
- data/spec/mongoid/config/environment_spec.rb +3 -3
- data/spec/mongoid/config/options_spec.rb +6 -6
- data/spec/mongoid/config_spec.rb +24 -48
- data/spec/mongoid/contextual/aggregable/memory_spec.rb +12 -12
- data/spec/mongoid/contextual/aggregable/mongo_spec.rb +78 -38
- data/spec/mongoid/contextual/atomic_spec.rb +60 -56
- data/spec/mongoid/contextual/find_and_modify_spec.rb +14 -14
- data/spec/mongoid/contextual/geo_near_spec.rb +22 -22
- data/spec/mongoid/contextual/map_reduce_spec.rb +27 -27
- data/spec/mongoid/contextual/memory_spec.rb +156 -94
- data/spec/mongoid/contextual/mongo_spec.rb +238 -150
- data/spec/mongoid/contextual/none_spec.rb +127 -0
- data/spec/mongoid/contextual/text_search_spec.rb +209 -0
- data/spec/mongoid/copyable_spec.rb +56 -68
- data/spec/mongoid/criteria/findable_spec.rb +991 -0
- data/spec/mongoid/{criterion/inspection_spec.rb → criteria/inspectable_spec.rb} +5 -5
- data/spec/mongoid/{criterion → criteria}/marshalable_spec.rb +2 -2
- data/spec/mongoid/criteria/modifiable_spec.rb +1252 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
- data/spec/mongoid/criteria_spec.rb +715 -2421
- data/spec/mongoid/document_spec.rb +171 -121
- data/spec/mongoid/equality_spec.rb +22 -22
- data/spec/mongoid/errors/ambiguous_relationship_spec.rb +3 -3
- data/spec/mongoid/errors/callback_spec.rb +3 -3
- data/spec/mongoid/errors/delete_restriction_spec.rb +3 -3
- data/spec/mongoid/errors/document_not_destroyed_spec.rb +33 -0
- data/spec/mongoid/errors/document_not_found_spec.rb +11 -11
- data/spec/mongoid/errors/eager_load_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_collection_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_config_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_option_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_field_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_find_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_includes_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_index_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_path_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_scope_spec.rb +5 -5
- data/spec/mongoid/errors/invalid_set_polymorphic_relation_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_storage_options_spec.rb +3 -3
- data/spec/mongoid/errors/invalid_time_spec.rb +3 -3
- data/spec/mongoid/errors/inverse_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_relations_spec.rb +3 -3
- data/spec/mongoid/errors/mixed_session_configuration_spec.rb +3 -3
- data/spec/mongoid/errors/mongoid_error_spec.rb +8 -8
- data/spec/mongoid/errors/nested_attributes_metadata_not_found_spec.rb +3 -3
- data/spec/mongoid/errors/no_environment_spec.rb +3 -3
- data/spec/mongoid/errors/no_map_reduce_output_spec.rb +3 -3
- data/spec/mongoid/errors/no_metadata_spec.rb +3 -3
- data/spec/mongoid/errors/no_parent_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_config_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_database_spec.rb +3 -3
- data/spec/mongoid/errors/no_session_hosts_spec.rb +3 -3
- data/spec/mongoid/errors/no_sessions_config_spec.rb +3 -3
- data/spec/mongoid/errors/readonly_attribute_spec.rb +3 -3
- data/spec/mongoid/errors/readonly_document_spec.rb +29 -0
- data/spec/mongoid/errors/scope_overwrite_spec.rb +3 -3
- data/spec/mongoid/errors/too_many_nested_attribute_records_spec.rb +3 -3
- data/spec/mongoid/errors/unknown_attribute_spec.rb +5 -5
- data/spec/mongoid/errors/unsaved_document_spec.rb +3 -3
- data/spec/mongoid/errors/unsupported_javascript_spec.rb +3 -3
- data/spec/mongoid/errors/validations_spec.rb +7 -7
- data/spec/mongoid/extensions/array_spec.rb +61 -61
- data/spec/mongoid/extensions/big_decimal_spec.rb +11 -11
- data/spec/mongoid/extensions/binary_spec.rb +12 -12
- data/spec/mongoid/extensions/boolean_spec.rb +18 -18
- data/spec/mongoid/extensions/date_spec.rb +13 -13
- data/spec/mongoid/extensions/date_time_spec.rb +8 -8
- data/spec/mongoid/extensions/false_class_spec.rb +5 -5
- data/spec/mongoid/extensions/float_spec.rb +29 -15
- data/spec/mongoid/extensions/hash_spec.rb +29 -29
- data/spec/mongoid/extensions/integer_spec.rb +15 -15
- data/spec/mongoid/extensions/module_spec.rb +2 -2
- data/spec/mongoid/extensions/nil_class_spec.rb +1 -1
- data/spec/mongoid/extensions/object_id_spec.rb +134 -134
- data/spec/mongoid/extensions/object_spec.rb +26 -26
- data/spec/mongoid/extensions/range_spec.rb +61 -12
- data/spec/mongoid/extensions/regexp_spec.rb +4 -4
- data/spec/mongoid/extensions/set_spec.rb +4 -4
- data/spec/mongoid/extensions/string_spec.rb +35 -46
- data/spec/mongoid/extensions/symbol_spec.rb +9 -9
- data/spec/mongoid/extensions/time_spec.rb +49 -49
- data/spec/mongoid/extensions/time_with_zone_spec.rb +34 -34
- data/spec/mongoid/extensions/true_class_spec.rb +5 -5
- data/spec/mongoid/extensions_spec.rb +29 -0
- data/spec/mongoid/factory_spec.rb +15 -15
- data/spec/mongoid/fields/foreign_key_spec.rb +73 -66
- data/spec/mongoid/fields/internal/foreign_keys/array_spec.rb +15 -15
- data/spec/mongoid/fields/internal/foreign_keys/object_spec.rb +22 -22
- data/spec/mongoid/fields/localized_spec.rb +38 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +263 -217
- data/spec/mongoid/findable_spec.rb +509 -0
- data/spec/mongoid/indexable/specification_spec.rb +102 -0
- data/spec/mongoid/{indexes_spec.rb → indexable_spec.rb} +171 -51
- data/spec/mongoid/{inspection_spec.rb → inspectable_spec.rb} +6 -14
- data/spec/mongoid/{callbacks_spec.rb → interceptable_spec.rb} +117 -116
- data/spec/mongoid/log_subscriber_spec.rb +75 -0
- data/spec/mongoid/loggable_spec.rb +1 -1
- data/spec/mongoid/{matchers → matchable}/all_spec.rb +4 -4
- data/spec/mongoid/{matchers → matchable}/and_spec.rb +11 -11
- data/spec/mongoid/{matchers → matchable}/default_spec.rb +15 -15
- data/spec/mongoid/{matchers → matchable}/exists_spec.rb +5 -5
- data/spec/mongoid/{matchers → matchable}/gt_spec.rb +9 -8
- data/spec/mongoid/{matchers → matchable}/gte_spec.rb +7 -7
- data/spec/mongoid/matchable/in_spec.rb +49 -0
- data/spec/mongoid/{matchers → matchable}/lt_spec.rb +7 -7
- data/spec/mongoid/{matchers → matchable}/lte_spec.rb +7 -7
- data/spec/mongoid/matchable/ne_spec.rb +46 -0
- data/spec/mongoid/matchable/nin_spec.rb +48 -0
- data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
- data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
- data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
- data/spec/mongoid/persistable/creatable_spec.rb +553 -0
- data/spec/mongoid/persistable/deletable_spec.rb +218 -0
- data/spec/mongoid/persistable/destroyable_spec.rb +192 -0
- data/spec/mongoid/persistable/incrementable_spec.rb +173 -0
- data/spec/mongoid/persistable/logical_spec.rb +143 -0
- data/spec/mongoid/persistable/poppable_spec.rb +115 -0
- data/spec/mongoid/persistable/pullable_spec.rb +228 -0
- data/spec/mongoid/persistable/pushable_spec.rb +258 -0
- data/spec/mongoid/persistable/renamable_spec.rb +135 -0
- data/spec/mongoid/persistable/savable_spec.rb +498 -0
- data/spec/mongoid/persistable/settable_spec.rb +162 -0
- data/spec/mongoid/persistable/unsettable_spec.rb +155 -0
- data/spec/mongoid/persistable/updatable_spec.rb +558 -0
- data/spec/mongoid/persistable/upsertable_spec.rb +106 -0
- data/spec/mongoid/persistable_spec.rb +206 -0
- data/spec/mongoid/{atomic/positionable_spec.rb → positional_spec.rb} +14 -19
- data/spec/mongoid/query_cache_spec.rb +263 -0
- data/spec/mongoid/railties/document_spec.rb +2 -2
- data/spec/mongoid/relations/accessors_spec.rb +53 -145
- data/spec/mongoid/relations/auto_save_spec.rb +37 -17
- data/spec/mongoid/relations/bindings/embedded/in_spec.rb +12 -12
- data/spec/mongoid/relations/bindings/embedded/many_spec.rb +3 -3
- data/spec/mongoid/relations/bindings/embedded/one_spec.rb +5 -5
- data/spec/mongoid/relations/bindings/referenced/in_spec.rb +26 -26
- data/spec/mongoid/relations/bindings/referenced/many_spec.rb +10 -10
- data/spec/mongoid/relations/bindings/referenced/many_to_many_spec.rb +19 -19
- data/spec/mongoid/relations/bindings/referenced/one_spec.rb +12 -12
- data/spec/mongoid/relations/builders/embedded/in_spec.rb +4 -4
- data/spec/mongoid/relations/builders/embedded/many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/embedded/one_spec.rb +11 -11
- data/spec/mongoid/relations/builders/nested_attributes/many_spec.rb +12 -13
- data/spec/mongoid/relations/builders/nested_attributes/one_spec.rb +14 -14
- data/spec/mongoid/relations/builders/referenced/in_spec.rb +24 -35
- data/spec/mongoid/relations/builders/referenced/many_spec.rb +15 -15
- data/spec/mongoid/relations/builders/referenced/many_to_many_spec.rb +18 -18
- data/spec/mongoid/relations/builders/referenced/one_spec.rb +12 -25
- data/spec/mongoid/relations/builders_spec.rb +21 -21
- data/spec/mongoid/relations/cascading/delete_spec.rb +9 -9
- data/spec/mongoid/relations/cascading/destroy_spec.rb +6 -6
- data/spec/mongoid/relations/cascading/nullify_spec.rb +4 -4
- data/spec/mongoid/relations/cascading/restrict_spec.rb +7 -7
- data/spec/mongoid/relations/cascading_spec.rb +16 -16
- data/spec/mongoid/relations/constraint_spec.rb +8 -7
- data/spec/mongoid/relations/conversions_spec.rb +16 -14
- data/spec/mongoid/relations/counter_cache_spec.rb +85 -0
- data/spec/mongoid/relations/cyclic_spec.rb +18 -18
- data/spec/mongoid/relations/eager/belongs_to_spec.rb +154 -0
- data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +117 -0
- data/spec/mongoid/relations/eager/has_many_spec.rb +207 -0
- data/spec/mongoid/relations/eager/has_one_spec.rb +163 -0
- data/spec/mongoid/relations/eager_spec.rb +228 -0
- data/spec/mongoid/relations/embedded/dirty_spec.rb +8 -8
- data/spec/mongoid/relations/embedded/in_spec.rb +56 -57
- data/spec/mongoid/relations/embedded/many_spec.rb +467 -372
- data/spec/mongoid/relations/embedded/one_spec.rb +108 -141
- data/spec/mongoid/relations/macros_spec.rb +108 -102
- data/spec/mongoid/relations/metadata_spec.rb +180 -255
- data/spec/mongoid/relations/options_spec.rb +1 -1
- data/spec/mongoid/relations/polymorphic_spec.rb +13 -17
- data/spec/mongoid/relations/proxy_spec.rb +2 -2
- data/spec/mongoid/relations/referenced/in_spec.rb +128 -303
- data/spec/mongoid/relations/referenced/many_spec.rb +587 -527
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +401 -424
- data/spec/mongoid/relations/referenced/one_spec.rb +149 -264
- data/spec/mongoid/relations/reflections_spec.rb +6 -6
- data/spec/mongoid/relations/synchronization_spec.rb +46 -50
- data/spec/mongoid/relations/targets/enumerable_spec.rb +118 -118
- data/spec/mongoid/relations/touchable_spec.rb +333 -0
- data/spec/mongoid/relations_spec.rb +16 -15
- data/spec/mongoid/{reloading_spec.rb → reloadable_spec.rb} +38 -55
- data/spec/mongoid/{scoping_spec.rb → scopable_spec.rb} +89 -164
- data/spec/mongoid/selectable_spec.rb +134 -0
- data/spec/mongoid/{serialization_spec.rb → serializable_spec.rb} +129 -82
- data/spec/mongoid/sessions/factory_spec.rb +49 -28
- data/spec/mongoid/sessions/mongo_uri_spec.rb +7 -7
- data/spec/mongoid/sessions/options_spec.rb +108 -0
- data/spec/mongoid/sessions_spec.rb +319 -178
- data/spec/mongoid/{sharding_spec.rb → shardable_spec.rb} +8 -8
- data/spec/mongoid/{state_spec.rb → stateful_spec.rb} +36 -11
- data/spec/mongoid/tasks/database_rake_spec.rb +285 -0
- data/spec/mongoid/tasks/database_spec.rb +160 -0
- data/spec/mongoid/threaded_spec.rb +17 -70
- data/spec/mongoid/timestamps/created/short_spec.rb +6 -6
- data/spec/mongoid/timestamps/created_spec.rb +5 -5
- data/spec/mongoid/timestamps/timeless_spec.rb +6 -6
- data/spec/mongoid/timestamps/updated/short_spec.rb +11 -11
- data/spec/mongoid/timestamps/updated_spec.rb +9 -13
- data/spec/mongoid/timestamps_spec.rb +9 -13
- data/spec/mongoid/{hierarchy_spec.rb → traversable_spec.rb} +19 -19
- data/spec/mongoid/{validations → validatable}/associated_spec.rb +45 -22
- data/spec/mongoid/{validations → validatable}/format_spec.rb +6 -6
- data/spec/mongoid/{validations → validatable}/length_spec.rb +14 -14
- data/spec/mongoid/{validations → validatable}/numericality_spec.rb +1 -1
- data/spec/mongoid/{validations → validatable}/presence_spec.rb +37 -44
- data/spec/mongoid/{validations → validatable}/uniqueness_spec.rb +184 -192
- data/spec/mongoid/{validations_spec.rb → validatable_spec.rb} +28 -28
- data/spec/mongoid_spec.rb +8 -8
- data/spec/rails/mongoid_spec.rb +19 -335
- data/spec/spec_helper.rb +31 -13
- metadata +303 -283
- data/lib/mongoid/atomic/positionable.rb +0 -73
- data/lib/mongoid/components.rb +0 -92
- data/lib/mongoid/config/inflections.rb +0 -6
- data/lib/mongoid/contextual/eager.rb +0 -158
- data/lib/mongoid/errors/versioning_not_on_root.rb +0 -23
- data/lib/mongoid/identity_map.rb +0 -163
- data/lib/mongoid/json.rb +0 -16
- data/lib/mongoid/matchers.rb +0 -32
- data/lib/mongoid/matchers/strategies.rb +0 -97
- data/lib/mongoid/multi_parameter_attributes.rb +0 -105
- data/lib/mongoid/nested_attributes.rb +0 -78
- data/lib/mongoid/observer.rb +0 -192
- data/lib/mongoid/paranoia.rb +0 -136
- data/lib/mongoid/persistence.rb +0 -357
- data/lib/mongoid/persistence/atomic.rb +0 -231
- data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
- data/lib/mongoid/persistence/atomic/bit.rb +0 -35
- data/lib/mongoid/persistence/atomic/inc.rb +0 -45
- data/lib/mongoid/persistence/atomic/operation.rb +0 -154
- data/lib/mongoid/persistence/atomic/pop.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
- data/lib/mongoid/persistence/atomic/push.rb +0 -25
- data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
- data/lib/mongoid/persistence/atomic/rename.rb +0 -30
- data/lib/mongoid/persistence/atomic/sets.rb +0 -28
- data/lib/mongoid/persistence/atomic/unset.rb +0 -27
- data/lib/mongoid/persistence/deletion.rb +0 -31
- data/lib/mongoid/persistence/insertion.rb +0 -38
- data/lib/mongoid/persistence/modification.rb +0 -35
- data/lib/mongoid/persistence/operations.rb +0 -214
- data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
- data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
- data/lib/mongoid/persistence/operations/insert.rb +0 -34
- data/lib/mongoid/persistence/operations/remove.rb +0 -33
- data/lib/mongoid/persistence/operations/update.rb +0 -59
- data/lib/mongoid/persistence/operations/upsert.rb +0 -28
- data/lib/mongoid/persistence/upsertion.rb +0 -31
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid.rb +0 -2
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
- data/spec/app/models/actor_observer.rb +0 -15
- data/spec/app/models/callback_recorder.rb +0 -25
- data/spec/app/models/paranoid_phone.rb +0 -25
- data/spec/app/models/paranoid_post.rb +0 -36
- data/spec/app/models/phone_observer.rb +0 -6
- data/spec/mongoid/attributes/processing_spec.rb +0 -149
- data/spec/mongoid/criterion/destructive_spec.rb +0 -101
- data/spec/mongoid/criterion/modifiable_spec.rb +0 -409
- data/spec/mongoid/criterion/modification_spec.rb +0 -402
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +0 -29
- data/spec/mongoid/finders_spec.rb +0 -321
- data/spec/mongoid/identity_map_spec.rb +0 -564
- data/spec/mongoid/json_spec.rb +0 -33
- data/spec/mongoid/matchers/in_spec.rb +0 -25
- data/spec/mongoid/matchers/ne_spec.rb +0 -25
- data/spec/mongoid/matchers/nin_spec.rb +0 -25
- data/spec/mongoid/multi_parameter_attributes_spec.rb +0 -128
- data/spec/mongoid/observer_spec.rb +0 -290
- data/spec/mongoid/paranoia_spec.rb +0 -759
- data/spec/mongoid/persistence/atomic/add_to_set_spec.rb +0 -262
- data/spec/mongoid/persistence/atomic/bit_spec.rb +0 -88
- data/spec/mongoid/persistence/atomic/inc_spec.rb +0 -133
- data/spec/mongoid/persistence/atomic/pop_spec.rb +0 -111
- data/spec/mongoid/persistence/atomic/pull_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/pull_spec.rb +0 -80
- data/spec/mongoid/persistence/atomic/push_all_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/push_spec.rb +0 -77
- data/spec/mongoid/persistence/atomic/rename_spec.rb +0 -42
- data/spec/mongoid/persistence/atomic/sets_spec.rb +0 -154
- data/spec/mongoid/persistence/atomic/unset_spec.rb +0 -65
- data/spec/mongoid/persistence/atomic_spec.rb +0 -216
- data/spec/mongoid/persistence/operations/embedded/insert_spec.rb +0 -191
- data/spec/mongoid/persistence/operations/embedded/remove_spec.rb +0 -8
- data/spec/mongoid/persistence/operations/insert_spec.rb +0 -149
- data/spec/mongoid/persistence/operations/remove_spec.rb +0 -113
- data/spec/mongoid/persistence/operations/update_spec.rb +0 -141
- data/spec/mongoid/persistence/operations/upsert_spec.rb +0 -59
- data/spec/mongoid/persistence/operations_spec.rb +0 -313
- data/spec/mongoid/persistence_spec.rb +0 -2279
- data/spec/mongoid/unit_of_work_spec.rb +0 -196
- data/spec/mongoid/versioning_spec.rb +0 -540
- data/spec/rack/mongoid/middleware/identity_map_spec.rb +0 -72
@@ -15,7 +15,7 @@ describe Mongoid::Relations::Metadata do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "returns false" do
|
18
|
-
metadata.
|
18
|
+
expect(metadata).to_not be_counter_cached
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -30,7 +30,7 @@ describe Mongoid::Relations::Metadata do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns true" do
|
33
|
-
metadata.
|
33
|
+
expect(metadata).to be_counter_cached
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -45,7 +45,7 @@ describe Mongoid::Relations::Metadata do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns true" do
|
48
|
-
metadata.
|
48
|
+
expect(metadata).to be_counter_cached
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -59,7 +59,7 @@ describe Mongoid::Relations::Metadata do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it "returns false" do
|
62
|
-
metadata.
|
62
|
+
expect(metadata).to_not be_counter_cached
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -82,7 +82,7 @@ describe Mongoid::Relations::Metadata do
|
|
82
82
|
end
|
83
83
|
|
84
84
|
before do
|
85
|
-
metadata.
|
85
|
+
expect(metadata).to receive(:inverse).and_return(:wheels)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "returns inverse name + _count" do
|
@@ -104,7 +104,7 @@ describe Mongoid::Relations::Metadata do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
it "returns the name given" do
|
107
|
-
metadata.counter_cache_column_name.
|
107
|
+
expect(metadata.counter_cache_column_name).to eq(counter_cache_name)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -121,7 +121,7 @@ describe Mongoid::Relations::Metadata do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
it "returns true" do
|
124
|
-
metadata.
|
124
|
+
expect(metadata).to be_autobuilding
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -135,7 +135,7 @@ describe Mongoid::Relations::Metadata do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "returns false" do
|
138
|
-
metadata.
|
138
|
+
expect(metadata).to_not be_autobuilding
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
@@ -148,7 +148,7 @@ describe Mongoid::Relations::Metadata do
|
|
148
148
|
end
|
149
149
|
|
150
150
|
it "returns false" do
|
151
|
-
metadata.
|
151
|
+
expect(metadata).to_not be_autobuilding
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -160,16 +160,17 @@ describe Mongoid::Relations::Metadata do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
let(:object) do
|
163
|
-
|
163
|
+
double
|
164
164
|
end
|
165
165
|
|
166
166
|
let(:base) do
|
167
|
-
|
167
|
+
double
|
168
168
|
end
|
169
169
|
|
170
170
|
it "returns the builder from the relation" do
|
171
|
-
|
172
|
-
|
171
|
+
expect(
|
172
|
+
metadata.builder(base, object)
|
173
|
+
).to be_a_kind_of(Mongoid::Relations::Builders::Embedded::One)
|
173
174
|
end
|
174
175
|
end
|
175
176
|
|
@@ -185,7 +186,7 @@ describe Mongoid::Relations::Metadata do
|
|
185
186
|
end
|
186
187
|
|
187
188
|
it "returns true" do
|
188
|
-
metadata.
|
189
|
+
expect(metadata).to be_cascading_callbacks
|
189
190
|
end
|
190
191
|
end
|
191
192
|
|
@@ -199,7 +200,7 @@ describe Mongoid::Relations::Metadata do
|
|
199
200
|
end
|
200
201
|
|
201
202
|
it "returns false" do
|
202
|
-
metadata.
|
203
|
+
expect(metadata).to_not be_cascading_callbacks
|
203
204
|
end
|
204
205
|
end
|
205
206
|
|
@@ -212,7 +213,7 @@ describe Mongoid::Relations::Metadata do
|
|
212
213
|
end
|
213
214
|
|
214
215
|
it "returns false" do
|
215
|
-
metadata.
|
216
|
+
expect(metadata).to_not be_cascading_callbacks
|
216
217
|
end
|
217
218
|
end
|
218
219
|
end
|
@@ -229,7 +230,7 @@ describe Mongoid::Relations::Metadata do
|
|
229
230
|
end
|
230
231
|
|
231
232
|
it "returns nil" do
|
232
|
-
metadata.cascade_strategy.
|
233
|
+
expect(metadata.cascade_strategy).to be_nil
|
233
234
|
end
|
234
235
|
end
|
235
236
|
|
@@ -244,7 +245,7 @@ describe Mongoid::Relations::Metadata do
|
|
244
245
|
end
|
245
246
|
|
246
247
|
it "returns the delete strategy" do
|
247
|
-
metadata.cascade_strategy.
|
248
|
+
expect(metadata.cascade_strategy).to eq(
|
248
249
|
Mongoid::Relations::Cascading::Delete
|
249
250
|
)
|
250
251
|
end
|
@@ -261,7 +262,7 @@ describe Mongoid::Relations::Metadata do
|
|
261
262
|
end
|
262
263
|
|
263
264
|
it "returns the destroy strategy" do
|
264
|
-
metadata.cascade_strategy.
|
265
|
+
expect(metadata.cascade_strategy).to eq(
|
265
266
|
Mongoid::Relations::Cascading::Destroy
|
266
267
|
)
|
267
268
|
end
|
@@ -278,7 +279,7 @@ describe Mongoid::Relations::Metadata do
|
|
278
279
|
end
|
279
280
|
|
280
281
|
it "returns the nullify strategy" do
|
281
|
-
metadata.cascade_strategy.
|
282
|
+
expect(metadata.cascade_strategy).to eq(
|
282
283
|
Mongoid::Relations::Cascading::Nullify
|
283
284
|
)
|
284
285
|
end
|
@@ -295,7 +296,7 @@ describe Mongoid::Relations::Metadata do
|
|
295
296
|
end
|
296
297
|
|
297
298
|
it "returns the constraint object" do
|
298
|
-
metadata.constraint.
|
299
|
+
expect(metadata.constraint).to be_a(Mongoid::Relations::Constraint)
|
299
300
|
end
|
300
301
|
end
|
301
302
|
|
@@ -314,12 +315,12 @@ describe Mongoid::Relations::Metadata do
|
|
314
315
|
end
|
315
316
|
|
316
317
|
before do
|
317
|
-
Mongoid::Relations::Options.
|
318
|
+
expect(Mongoid::Relations::Options).to receive(:validate!).at_least(:once)
|
318
319
|
end
|
319
320
|
|
320
321
|
it "concatenates the result from #find_module and name.classify" do
|
321
|
-
metadata.
|
322
|
-
classified.
|
322
|
+
expect(metadata).to receive(:find_module).once.and_return("Fruit")
|
323
|
+
expect(classified).to eq("Fruit::Name")
|
323
324
|
end
|
324
325
|
end
|
325
326
|
|
@@ -338,7 +339,7 @@ describe Mongoid::Relations::Metadata do
|
|
338
339
|
end
|
339
340
|
|
340
341
|
before do
|
341
|
-
Mongoid::Relations::Options.
|
342
|
+
expect(Mongoid::Relations::Options).to receive(:validate!).at_least(:once)
|
342
343
|
end
|
343
344
|
|
344
345
|
context "when inverse_class_name is nil" do
|
@@ -348,7 +349,7 @@ describe Mongoid::Relations::Metadata do
|
|
348
349
|
end
|
349
350
|
|
350
351
|
it "returns nil" do
|
351
|
-
mod.
|
352
|
+
expect(mod).to be_nil
|
352
353
|
end
|
353
354
|
end
|
354
355
|
|
@@ -359,7 +360,7 @@ describe Mongoid::Relations::Metadata do
|
|
359
360
|
end
|
360
361
|
|
361
362
|
it "returns nil" do
|
362
|
-
mod.
|
363
|
+
expect(mod).to be_nil
|
363
364
|
end
|
364
365
|
end
|
365
366
|
|
@@ -378,7 +379,7 @@ describe Mongoid::Relations::Metadata do
|
|
378
379
|
end
|
379
380
|
|
380
381
|
it "returns nil" do
|
381
|
-
mod.
|
382
|
+
expect(mod).to be_nil
|
382
383
|
end
|
383
384
|
end
|
384
385
|
|
@@ -389,7 +390,7 @@ describe Mongoid::Relations::Metadata do
|
|
389
390
|
end
|
390
391
|
|
391
392
|
it "returns root namespace" do
|
392
|
-
mod.
|
393
|
+
expect(mod).to be_nil
|
393
394
|
end
|
394
395
|
end
|
395
396
|
|
@@ -406,7 +407,7 @@ describe Mongoid::Relations::Metadata do
|
|
406
407
|
end
|
407
408
|
|
408
409
|
it "returns Fruits" do
|
409
|
-
mod.
|
410
|
+
expect(mod).to eq("Fruits")
|
410
411
|
end
|
411
412
|
end
|
412
413
|
|
@@ -421,7 +422,7 @@ describe Mongoid::Relations::Metadata do
|
|
421
422
|
end
|
422
423
|
|
423
424
|
it "returns Fruits" do
|
424
|
-
mod.
|
425
|
+
expect(mod).to eq("Fruits")
|
425
426
|
end
|
426
427
|
end
|
427
428
|
|
@@ -436,7 +437,7 @@ describe Mongoid::Relations::Metadata do
|
|
436
437
|
end
|
437
438
|
|
438
439
|
it "returns nil" do
|
439
|
-
mod.
|
440
|
+
expect(mod).to be_nil
|
440
441
|
end
|
441
442
|
end
|
442
443
|
end
|
@@ -458,7 +459,7 @@ describe Mongoid::Relations::Metadata do
|
|
458
459
|
end
|
459
460
|
|
460
461
|
it "returns the stripped class name" do
|
461
|
-
metadata.class_name.
|
462
|
+
expect(metadata.class_name).to eq("Person")
|
462
463
|
end
|
463
464
|
end
|
464
465
|
|
@@ -472,7 +473,7 @@ describe Mongoid::Relations::Metadata do
|
|
472
473
|
end
|
473
474
|
|
474
475
|
it "constantizes the class name" do
|
475
|
-
metadata.class_name.
|
476
|
+
expect(metadata.class_name).to eq("Person")
|
476
477
|
end
|
477
478
|
end
|
478
479
|
end
|
@@ -494,7 +495,7 @@ describe Mongoid::Relations::Metadata do
|
|
494
495
|
end
|
495
496
|
|
496
497
|
it "classifies and constantizes the association name and adds the module" do
|
497
|
-
metadata.class_name.
|
498
|
+
expect(metadata.class_name).to eq("Name")
|
498
499
|
end
|
499
500
|
end
|
500
501
|
|
@@ -509,7 +510,7 @@ describe Mongoid::Relations::Metadata do
|
|
509
510
|
end
|
510
511
|
|
511
512
|
it "classifies and constantizes the association name and adds the module" do
|
512
|
-
metadata.class_name.
|
513
|
+
expect(metadata.class_name).to eq("Address")
|
513
514
|
end
|
514
515
|
end
|
515
516
|
|
@@ -528,7 +529,7 @@ describe Mongoid::Relations::Metadata do
|
|
528
529
|
end
|
529
530
|
|
530
531
|
it "classifies and constantizes the association name and adds the module" do
|
531
|
-
metadata.class_name.
|
532
|
+
expect(metadata.class_name).to eq("Fruits::Apple")
|
532
533
|
end
|
533
534
|
end
|
534
535
|
|
@@ -543,7 +544,7 @@ describe Mongoid::Relations::Metadata do
|
|
543
544
|
end
|
544
545
|
|
545
546
|
it "classifies and constantizes the association name and adds the module" do
|
546
|
-
metadata.class_name.
|
547
|
+
expect(metadata.class_name).to eq("Fruits::Apple")
|
547
548
|
end
|
548
549
|
end
|
549
550
|
|
@@ -563,7 +564,7 @@ describe Mongoid::Relations::Metadata do
|
|
563
564
|
end
|
564
565
|
|
565
566
|
it "classifies and constantizes the association name" do
|
566
|
-
metadata.class_name.
|
567
|
+
expect(metadata.class_name).to eq("Name")
|
567
568
|
end
|
568
569
|
end
|
569
570
|
|
@@ -578,7 +579,7 @@ describe Mongoid::Relations::Metadata do
|
|
578
579
|
end
|
579
580
|
|
580
581
|
it "classifies and constantizes the association name" do
|
581
|
-
metadata.class_name.
|
582
|
+
expect(metadata.class_name).to eq("Address")
|
582
583
|
end
|
583
584
|
end
|
584
585
|
end
|
@@ -597,7 +598,7 @@ describe Mongoid::Relations::Metadata do
|
|
597
598
|
end
|
598
599
|
|
599
600
|
it "returns true" do
|
600
|
-
metadata.
|
601
|
+
expect(metadata).to be_destructive
|
601
602
|
end
|
602
603
|
end
|
603
604
|
|
@@ -610,7 +611,7 @@ describe Mongoid::Relations::Metadata do
|
|
610
611
|
end
|
611
612
|
|
612
613
|
it "returns false" do
|
613
|
-
metadata.
|
614
|
+
expect(metadata).to_not be_destructive
|
614
615
|
end
|
615
616
|
end
|
616
617
|
end
|
@@ -626,7 +627,7 @@ describe Mongoid::Relations::Metadata do
|
|
626
627
|
end
|
627
628
|
|
628
629
|
it "returns true" do
|
629
|
-
metadata.
|
630
|
+
expect(metadata).to be_embedded
|
630
631
|
end
|
631
632
|
end
|
632
633
|
|
@@ -639,7 +640,7 @@ describe Mongoid::Relations::Metadata do
|
|
639
640
|
end
|
640
641
|
|
641
642
|
it "returns false" do
|
642
|
-
metadata.
|
643
|
+
expect(metadata).to_not be_embedded
|
643
644
|
end
|
644
645
|
end
|
645
646
|
end
|
@@ -654,7 +655,7 @@ describe Mongoid::Relations::Metadata do
|
|
654
655
|
end
|
655
656
|
|
656
657
|
it "returns the extend property" do
|
657
|
-
metadata.extension.
|
658
|
+
expect(metadata.extension).to eq(:value)
|
658
659
|
end
|
659
660
|
end
|
660
661
|
|
@@ -670,7 +671,7 @@ describe Mongoid::Relations::Metadata do
|
|
670
671
|
end
|
671
672
|
|
672
673
|
it "returns true" do
|
673
|
-
metadata.extension
|
674
|
+
expect(metadata.extension?).to be true
|
674
675
|
end
|
675
676
|
end
|
676
677
|
|
@@ -683,7 +684,7 @@ describe Mongoid::Relations::Metadata do
|
|
683
684
|
end
|
684
685
|
|
685
686
|
it "returns false" do
|
686
|
-
metadata.extension
|
687
|
+
expect(metadata.extension?).to be false
|
687
688
|
end
|
688
689
|
end
|
689
690
|
end
|
@@ -706,7 +707,7 @@ describe Mongoid::Relations::Metadata do
|
|
706
707
|
end
|
707
708
|
|
708
709
|
it "returns the foreign_key" do
|
709
|
-
metadata.foreign_key.
|
710
|
+
expect(metadata.foreign_key).to eq("person_id")
|
710
711
|
end
|
711
712
|
end
|
712
713
|
|
@@ -721,7 +722,7 @@ describe Mongoid::Relations::Metadata do
|
|
721
722
|
end
|
722
723
|
|
723
724
|
it "returns the foreign_key" do
|
724
|
-
metadata.foreign_key.
|
725
|
+
expect(metadata.foreign_key).to eq("person_id")
|
725
726
|
end
|
726
727
|
end
|
727
728
|
|
@@ -736,7 +737,7 @@ describe Mongoid::Relations::Metadata do
|
|
736
737
|
end
|
737
738
|
|
738
739
|
it "returns the foreign_key without the module name" do
|
739
|
-
metadata.foreign_key.
|
740
|
+
expect(metadata.foreign_key).to eq("apple_id")
|
740
741
|
end
|
741
742
|
end
|
742
743
|
end
|
@@ -751,7 +752,7 @@ describe Mongoid::Relations::Metadata do
|
|
751
752
|
end
|
752
753
|
|
753
754
|
it "returns the foreign_key" do
|
754
|
-
metadata.foreign_key.
|
755
|
+
expect(metadata.foreign_key).to eq("person_ids")
|
755
756
|
end
|
756
757
|
|
757
758
|
context "given a specific foreign key" do
|
@@ -765,7 +766,7 @@ describe Mongoid::Relations::Metadata do
|
|
765
766
|
end
|
766
767
|
|
767
768
|
it "returns the foreign_key" do
|
768
|
-
metadata.foreign_key.
|
769
|
+
expect(metadata.foreign_key).to eq("follower_list")
|
769
770
|
end
|
770
771
|
end
|
771
772
|
|
@@ -780,7 +781,7 @@ describe Mongoid::Relations::Metadata do
|
|
780
781
|
end
|
781
782
|
|
782
783
|
it "returns the foreign_key" do
|
783
|
-
metadata.foreign_key.
|
784
|
+
expect(metadata.foreign_key).to eq("follower_ids")
|
784
785
|
end
|
785
786
|
end
|
786
787
|
|
@@ -796,11 +797,11 @@ describe Mongoid::Relations::Metadata do
|
|
796
797
|
end
|
797
798
|
|
798
799
|
it "returns the foreign_key without the module name" do
|
799
|
-
metadata.foreign_key.
|
800
|
+
expect(metadata.foreign_key).to eq("banana_ids")
|
800
801
|
end
|
801
802
|
|
802
803
|
it "returns the inverse_foreign_key without the module name" do
|
803
|
-
metadata.inverse_foreign_key.
|
804
|
+
expect(metadata.inverse_foreign_key).to eq("apple_ids")
|
804
805
|
end
|
805
806
|
end
|
806
807
|
end
|
@@ -819,7 +820,7 @@ describe Mongoid::Relations::Metadata do
|
|
819
820
|
end
|
820
821
|
|
821
822
|
it "returns the inverse foreign key" do
|
822
|
-
metadata.foreign_key.
|
823
|
+
expect(metadata.foreign_key).to eq("person_id")
|
823
824
|
end
|
824
825
|
end
|
825
826
|
|
@@ -837,7 +838,7 @@ describe Mongoid::Relations::Metadata do
|
|
837
838
|
end
|
838
839
|
|
839
840
|
it "returns the inverse_of plus suffix" do
|
840
|
-
metadata.foreign_key.
|
841
|
+
expect(metadata.foreign_key).to eq("creator_id")
|
841
842
|
end
|
842
843
|
end
|
843
844
|
|
@@ -852,23 +853,42 @@ describe Mongoid::Relations::Metadata do
|
|
852
853
|
end
|
853
854
|
|
854
855
|
it "returns the inverse foreign key" do
|
855
|
-
metadata.foreign_key.
|
856
|
+
expect(metadata.foreign_key).to eq("person_id")
|
856
857
|
end
|
857
858
|
end
|
858
859
|
|
859
860
|
context "when the class is namespaced" do
|
860
861
|
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
862
|
+
context "when name doesnt include namespace" do
|
863
|
+
|
864
|
+
let(:metadata) do
|
865
|
+
described_class.new(
|
866
|
+
name: :bananas,
|
867
|
+
relation: Mongoid::Relations::Referenced::Many,
|
868
|
+
inverse_class_name: "Fruits::Apple",
|
869
|
+
class_name: "Fruits::Banana"
|
870
|
+
)
|
871
|
+
end
|
872
|
+
|
873
|
+
it "returns the foreign_key without the module name" do
|
874
|
+
expect(metadata.foreign_key).to eq("apple_id")
|
875
|
+
end
|
868
876
|
end
|
869
877
|
|
870
|
-
|
871
|
-
|
878
|
+
context "when name include namespace" do
|
879
|
+
|
880
|
+
let(:metadata) do
|
881
|
+
described_class.new(
|
882
|
+
name: :fruits_melons,
|
883
|
+
relation: Mongoid::Relations::Referenced::Many,
|
884
|
+
inverse_class_name: "Fruits::Apple",
|
885
|
+
class_name: "Fruits::Melon"
|
886
|
+
)
|
887
|
+
end
|
888
|
+
|
889
|
+
it "returns the foreign_key with the module name" do
|
890
|
+
expect(metadata.foreign_key).to eq("fruit_apple_id")
|
891
|
+
end
|
872
892
|
end
|
873
893
|
end
|
874
894
|
end
|
@@ -882,8 +902,8 @@ describe Mongoid::Relations::Metadata do
|
|
882
902
|
)
|
883
903
|
end
|
884
904
|
|
885
|
-
it "returns
|
886
|
-
metadata.foreign_key.
|
905
|
+
it "returns a nil foreign key" do
|
906
|
+
expect(metadata.foreign_key).to be_nil
|
887
907
|
end
|
888
908
|
end
|
889
909
|
end
|
@@ -900,7 +920,7 @@ describe Mongoid::Relations::Metadata do
|
|
900
920
|
end
|
901
921
|
|
902
922
|
it "returns the foreign_key" do
|
903
|
-
metadata.foreign_key.
|
923
|
+
expect(metadata.foreign_key).to eq("blog_post_id")
|
904
924
|
end
|
905
925
|
end
|
906
926
|
end
|
@@ -918,7 +938,7 @@ describe Mongoid::Relations::Metadata do
|
|
918
938
|
end
|
919
939
|
|
920
940
|
it "returns an empty array" do
|
921
|
-
metadata.foreign_key_default.
|
941
|
+
expect(metadata.foreign_key_default).to be_empty
|
922
942
|
end
|
923
943
|
end
|
924
944
|
|
@@ -933,7 +953,7 @@ describe Mongoid::Relations::Metadata do
|
|
933
953
|
end
|
934
954
|
|
935
955
|
it "returns an empty array" do
|
936
|
-
metadata.foreign_key_default.
|
956
|
+
expect(metadata.foreign_key_default).to be_nil
|
937
957
|
end
|
938
958
|
end
|
939
959
|
end
|
@@ -951,7 +971,7 @@ describe Mongoid::Relations::Metadata do
|
|
951
971
|
end
|
952
972
|
|
953
973
|
it "returns the foreign_key plus =" do
|
954
|
-
metadata.foreign_key_setter.
|
974
|
+
expect(metadata.foreign_key_setter).to eq("person_id=")
|
955
975
|
end
|
956
976
|
end
|
957
977
|
|
@@ -967,7 +987,7 @@ describe Mongoid::Relations::Metadata do
|
|
967
987
|
end
|
968
988
|
|
969
989
|
it "returns the polymorphic foreign_key plus =" do
|
970
|
-
metadata.foreign_key_setter.
|
990
|
+
expect(metadata.foreign_key_setter).to eq("ratable_id=")
|
971
991
|
end
|
972
992
|
end
|
973
993
|
end
|
@@ -985,7 +1005,7 @@ describe Mongoid::Relations::Metadata do
|
|
985
1005
|
end
|
986
1006
|
|
987
1007
|
it "returns nil" do
|
988
|
-
metadata.inverse_type.
|
1008
|
+
expect(metadata.inverse_type).to be_nil
|
989
1009
|
end
|
990
1010
|
end
|
991
1011
|
|
@@ -1001,7 +1021,7 @@ describe Mongoid::Relations::Metadata do
|
|
1001
1021
|
end
|
1002
1022
|
|
1003
1023
|
it "returns the polymorphic name plus type" do
|
1004
|
-
metadata.inverse_type.
|
1024
|
+
expect(metadata.inverse_type).to eq("ratable_type")
|
1005
1025
|
end
|
1006
1026
|
end
|
1007
1027
|
end
|
@@ -1019,7 +1039,7 @@ describe Mongoid::Relations::Metadata do
|
|
1019
1039
|
end
|
1020
1040
|
|
1021
1041
|
it "returns nil" do
|
1022
|
-
metadata.inverse_type_setter.
|
1042
|
+
expect(metadata.inverse_type_setter).to be_nil
|
1023
1043
|
end
|
1024
1044
|
end
|
1025
1045
|
|
@@ -1035,75 +1055,7 @@ describe Mongoid::Relations::Metadata do
|
|
1035
1055
|
end
|
1036
1056
|
|
1037
1057
|
it "returns the inverse type plus =" do
|
1038
|
-
metadata.inverse_type_setter.
|
1039
|
-
end
|
1040
|
-
end
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
describe "#inverse_of_field" do
|
1044
|
-
|
1045
|
-
context "when the relation is not polymorphic" do
|
1046
|
-
|
1047
|
-
let(:metadata) do
|
1048
|
-
described_class.new(
|
1049
|
-
name: :person,
|
1050
|
-
relation: Mongoid::Relations::Referenced::In,
|
1051
|
-
foreign_key: "person_id"
|
1052
|
-
)
|
1053
|
-
end
|
1054
|
-
|
1055
|
-
it "returns nil" do
|
1056
|
-
metadata.inverse_of_field.should be_nil
|
1057
|
-
end
|
1058
|
-
end
|
1059
|
-
|
1060
|
-
context "when the relation is polymorphic" do
|
1061
|
-
|
1062
|
-
let(:metadata) do
|
1063
|
-
described_class.new(
|
1064
|
-
name: :ratable,
|
1065
|
-
relation: Mongoid::Relations::Referenced::In,
|
1066
|
-
polymorphic: true,
|
1067
|
-
inverse_class_name: "Rating"
|
1068
|
-
)
|
1069
|
-
end
|
1070
|
-
|
1071
|
-
it "returns the polymorphic name plus field" do
|
1072
|
-
metadata.inverse_of_field.should eq("ratable_field")
|
1073
|
-
end
|
1074
|
-
end
|
1075
|
-
end
|
1076
|
-
|
1077
|
-
describe "#inverse_of_field_setter" do
|
1078
|
-
|
1079
|
-
context "when the relation is not polymorphic" do
|
1080
|
-
|
1081
|
-
let(:metadata) do
|
1082
|
-
described_class.new(
|
1083
|
-
name: :person,
|
1084
|
-
relation: Mongoid::Relations::Referenced::In,
|
1085
|
-
foreign_key: "person_id"
|
1086
|
-
)
|
1087
|
-
end
|
1088
|
-
|
1089
|
-
it "returns nil" do
|
1090
|
-
metadata.inverse_of_field_setter.should be_nil
|
1091
|
-
end
|
1092
|
-
end
|
1093
|
-
|
1094
|
-
context "when the relation is polymorphic" do
|
1095
|
-
|
1096
|
-
let(:metadata) do
|
1097
|
-
described_class.new(
|
1098
|
-
name: :ratable,
|
1099
|
-
relation: Mongoid::Relations::Referenced::In,
|
1100
|
-
polymorphic: true,
|
1101
|
-
inverse_class_name: "Rating"
|
1102
|
-
)
|
1103
|
-
end
|
1104
|
-
|
1105
|
-
it "returns the inverse of field plus =" do
|
1106
|
-
metadata.inverse_of_field_setter.should eq("ratable_field=")
|
1058
|
+
expect(metadata.inverse_type_setter).to eq("ratable_type=")
|
1107
1059
|
end
|
1108
1060
|
end
|
1109
1061
|
end
|
@@ -1124,7 +1076,7 @@ describe Mongoid::Relations::Metadata do
|
|
1124
1076
|
end
|
1125
1077
|
|
1126
1078
|
it "returns only the inverse_of" do
|
1127
|
-
metadata.inverses(nil).
|
1079
|
+
expect(metadata.inverses(nil)).to eq([ "my_ratings" ])
|
1128
1080
|
end
|
1129
1081
|
end
|
1130
1082
|
end
|
@@ -1142,7 +1094,7 @@ describe Mongoid::Relations::Metadata do
|
|
1142
1094
|
end
|
1143
1095
|
|
1144
1096
|
it "returns true" do
|
1145
|
-
metadata.indexed
|
1097
|
+
expect(metadata.indexed?).to be true
|
1146
1098
|
end
|
1147
1099
|
end
|
1148
1100
|
|
@@ -1155,7 +1107,7 @@ describe Mongoid::Relations::Metadata do
|
|
1155
1107
|
end
|
1156
1108
|
|
1157
1109
|
it "returns false" do
|
1158
|
-
metadata.indexed
|
1110
|
+
expect(metadata.indexed?).to be false
|
1159
1111
|
end
|
1160
1112
|
end
|
1161
1113
|
|
@@ -1169,7 +1121,7 @@ describe Mongoid::Relations::Metadata do
|
|
1169
1121
|
end
|
1170
1122
|
|
1171
1123
|
it "returns false" do
|
1172
|
-
metadata.indexed
|
1124
|
+
expect(metadata.indexed?).to be false
|
1173
1125
|
end
|
1174
1126
|
end
|
1175
1127
|
end
|
@@ -1185,7 +1137,7 @@ describe Mongoid::Relations::Metadata do
|
|
1185
1137
|
end
|
1186
1138
|
|
1187
1139
|
it "returns the name of the inverse with the matching foreign_key" do
|
1188
|
-
metadata.inverse.
|
1140
|
+
expect(metadata.inverse).to eq(:creator)
|
1189
1141
|
end
|
1190
1142
|
end
|
1191
1143
|
|
@@ -1202,7 +1154,7 @@ describe Mongoid::Relations::Metadata do
|
|
1202
1154
|
end
|
1203
1155
|
|
1204
1156
|
it "returns the name of the inverse with the matching inverse of" do
|
1205
|
-
metadata.inverse.
|
1157
|
+
expect(metadata.inverse).to eq(:user)
|
1206
1158
|
end
|
1207
1159
|
end
|
1208
1160
|
|
@@ -1219,7 +1171,7 @@ describe Mongoid::Relations::Metadata do
|
|
1219
1171
|
end
|
1220
1172
|
|
1221
1173
|
it "returns the name of the relation" do
|
1222
|
-
metadata.inverse.
|
1174
|
+
expect(metadata.inverse).to eq(:eyeable)
|
1223
1175
|
end
|
1224
1176
|
end
|
1225
1177
|
|
@@ -1235,7 +1187,7 @@ describe Mongoid::Relations::Metadata do
|
|
1235
1187
|
end
|
1236
1188
|
|
1237
1189
|
it "returns nil" do
|
1238
|
-
metadata.inverse(Face.new).
|
1190
|
+
expect(metadata.inverse(Face.new)).to be_nil
|
1239
1191
|
end
|
1240
1192
|
end
|
1241
1193
|
end
|
@@ -1252,7 +1204,7 @@ describe Mongoid::Relations::Metadata do
|
|
1252
1204
|
end
|
1253
1205
|
|
1254
1206
|
it "returns nil" do
|
1255
|
-
metadata.inverse.
|
1207
|
+
expect(metadata.inverse).to be_nil
|
1256
1208
|
end
|
1257
1209
|
end
|
1258
1210
|
|
@@ -1266,7 +1218,7 @@ describe Mongoid::Relations::Metadata do
|
|
1266
1218
|
end
|
1267
1219
|
|
1268
1220
|
it "returns the name of the inverse_of property" do
|
1269
|
-
metadata.inverse.
|
1221
|
+
expect(metadata.inverse).to eq(:crazy_name)
|
1270
1222
|
end
|
1271
1223
|
end
|
1272
1224
|
end
|
@@ -1283,7 +1235,7 @@ describe Mongoid::Relations::Metadata do
|
|
1283
1235
|
end
|
1284
1236
|
|
1285
1237
|
it "returns the name of the relation" do
|
1286
|
-
metadata.inverse.
|
1238
|
+
expect(metadata.inverse).to eq(:person)
|
1287
1239
|
end
|
1288
1240
|
end
|
1289
1241
|
|
@@ -1299,7 +1251,7 @@ describe Mongoid::Relations::Metadata do
|
|
1299
1251
|
end
|
1300
1252
|
|
1301
1253
|
it "returns the name of the relation" do
|
1302
|
-
metadata.inverse.
|
1254
|
+
expect(metadata.inverse).to eq(:addressable)
|
1303
1255
|
end
|
1304
1256
|
end
|
1305
1257
|
|
@@ -1315,7 +1267,7 @@ describe Mongoid::Relations::Metadata do
|
|
1315
1267
|
end
|
1316
1268
|
|
1317
1269
|
it "returns the name of the relation" do
|
1318
|
-
metadata.inverse(Person.new).
|
1270
|
+
expect(metadata.inverse(Person.new)).to eq(:addresses)
|
1319
1271
|
end
|
1320
1272
|
end
|
1321
1273
|
|
@@ -1334,7 +1286,7 @@ describe Mongoid::Relations::Metadata do
|
|
1334
1286
|
end
|
1335
1287
|
|
1336
1288
|
it "returns the name of the relation" do
|
1337
|
-
metadata.inverse(Role.new).
|
1289
|
+
expect(metadata.inverse(Role.new)).to eq(:child_roles)
|
1338
1290
|
end
|
1339
1291
|
end
|
1340
1292
|
|
@@ -1351,7 +1303,7 @@ describe Mongoid::Relations::Metadata do
|
|
1351
1303
|
end
|
1352
1304
|
|
1353
1305
|
it "returns the name of the relation" do
|
1354
|
-
metadata.inverse(Entry.new).
|
1306
|
+
expect(metadata.inverse(Entry.new)).to eq(:child_entries)
|
1355
1307
|
end
|
1356
1308
|
end
|
1357
1309
|
end
|
@@ -1373,7 +1325,7 @@ describe Mongoid::Relations::Metadata do
|
|
1373
1325
|
end
|
1374
1326
|
|
1375
1327
|
it "returns the inverse class name plus suffix" do
|
1376
|
-
metadata.inverse_foreign_key.
|
1328
|
+
expect(metadata.inverse_foreign_key).to eq("person_ids")
|
1377
1329
|
end
|
1378
1330
|
end
|
1379
1331
|
|
@@ -1389,7 +1341,7 @@ describe Mongoid::Relations::Metadata do
|
|
1389
1341
|
end
|
1390
1342
|
|
1391
1343
|
it "returns nil" do
|
1392
|
-
metadata.inverse_foreign_key.
|
1344
|
+
expect(metadata.inverse_foreign_key).to be_nil
|
1393
1345
|
end
|
1394
1346
|
end
|
1395
1347
|
end
|
@@ -1404,7 +1356,7 @@ describe Mongoid::Relations::Metadata do
|
|
1404
1356
|
end
|
1405
1357
|
|
1406
1358
|
it "constantizes the inverse_class_name" do
|
1407
|
-
metadata.inverse_klass.
|
1359
|
+
expect(metadata.inverse_klass).to eq(Person)
|
1408
1360
|
end
|
1409
1361
|
end
|
1410
1362
|
|
@@ -1422,7 +1374,7 @@ describe Mongoid::Relations::Metadata do
|
|
1422
1374
|
end
|
1423
1375
|
|
1424
1376
|
it "returns a string for the setter" do
|
1425
|
-
metadata.inverse_setter.
|
1377
|
+
expect(metadata.inverse_setter).to eq("person=")
|
1426
1378
|
end
|
1427
1379
|
end
|
1428
1380
|
|
@@ -1445,7 +1397,7 @@ describe Mongoid::Relations::Metadata do
|
|
1445
1397
|
end
|
1446
1398
|
|
1447
1399
|
it "returns nil" do
|
1448
|
-
metadata.inverse_setter(other).
|
1400
|
+
expect(metadata.inverse_setter(other)).to be_nil
|
1449
1401
|
end
|
1450
1402
|
end
|
1451
1403
|
|
@@ -1461,7 +1413,7 @@ describe Mongoid::Relations::Metadata do
|
|
1461
1413
|
end
|
1462
1414
|
|
1463
1415
|
it "returns a string for the setter" do
|
1464
|
-
metadata.inverse_setter.
|
1416
|
+
expect(metadata.inverse_setter).to eq("eyeable=")
|
1465
1417
|
end
|
1466
1418
|
end
|
1467
1419
|
end
|
@@ -1482,7 +1434,7 @@ describe Mongoid::Relations::Metadata do
|
|
1482
1434
|
end
|
1483
1435
|
|
1484
1436
|
it "returns a string for the setter" do
|
1485
|
-
metadata.inverse_setter(other).
|
1437
|
+
expect(metadata.inverse_setter(other)).to eq("ratings=")
|
1486
1438
|
end
|
1487
1439
|
end
|
1488
1440
|
|
@@ -1498,7 +1450,7 @@ describe Mongoid::Relations::Metadata do
|
|
1498
1450
|
end
|
1499
1451
|
|
1500
1452
|
it "returns a string for the setter" do
|
1501
|
-
metadata.inverse_setter.
|
1453
|
+
expect(metadata.inverse_setter).to eq("ratable=")
|
1502
1454
|
end
|
1503
1455
|
end
|
1504
1456
|
end
|
@@ -1516,7 +1468,7 @@ describe Mongoid::Relations::Metadata do
|
|
1516
1468
|
end
|
1517
1469
|
|
1518
1470
|
it "returns the name as a string" do
|
1519
|
-
metadata.key.
|
1471
|
+
expect(metadata.key).to eq("addresses")
|
1520
1472
|
end
|
1521
1473
|
|
1522
1474
|
context "with a store_as option defined" do
|
@@ -1530,7 +1482,7 @@ describe Mongoid::Relations::Metadata do
|
|
1530
1482
|
end
|
1531
1483
|
|
1532
1484
|
it "return the name define by store_as option" do
|
1533
|
-
metadata.key.
|
1485
|
+
expect(metadata.key).to eq("user_comments")
|
1534
1486
|
end
|
1535
1487
|
end
|
1536
1488
|
end
|
@@ -1549,7 +1501,7 @@ describe Mongoid::Relations::Metadata do
|
|
1549
1501
|
end
|
1550
1502
|
|
1551
1503
|
it "returns the foreign_key" do
|
1552
|
-
metadata.key.
|
1504
|
+
expect(metadata.key).to eq("post_ids")
|
1553
1505
|
end
|
1554
1506
|
end
|
1555
1507
|
|
@@ -1564,7 +1516,7 @@ describe Mongoid::Relations::Metadata do
|
|
1564
1516
|
end
|
1565
1517
|
|
1566
1518
|
it "returns the polymorphic foreign_key" do
|
1567
|
-
metadata.key.
|
1519
|
+
expect(metadata.key).to eq("ratable_id")
|
1568
1520
|
end
|
1569
1521
|
end
|
1570
1522
|
end
|
@@ -1580,7 +1532,7 @@ describe Mongoid::Relations::Metadata do
|
|
1580
1532
|
end
|
1581
1533
|
|
1582
1534
|
it "returns _id" do
|
1583
|
-
metadata.key.
|
1535
|
+
expect(metadata.key).to eq("_id")
|
1584
1536
|
end
|
1585
1537
|
end
|
1586
1538
|
end
|
@@ -1596,7 +1548,7 @@ describe Mongoid::Relations::Metadata do
|
|
1596
1548
|
end
|
1597
1549
|
|
1598
1550
|
it "returns self" do
|
1599
|
-
metadata.options.
|
1551
|
+
expect(metadata.options).to eq(metadata)
|
1600
1552
|
end
|
1601
1553
|
end
|
1602
1554
|
|
@@ -1610,7 +1562,7 @@ describe Mongoid::Relations::Metadata do
|
|
1610
1562
|
end
|
1611
1563
|
|
1612
1564
|
it "returns order criteria" do
|
1613
|
-
metadata.order.
|
1565
|
+
expect(metadata.order).to eq(:rating.asc)
|
1614
1566
|
end
|
1615
1567
|
end
|
1616
1568
|
|
@@ -1626,7 +1578,7 @@ describe Mongoid::Relations::Metadata do
|
|
1626
1578
|
end
|
1627
1579
|
|
1628
1580
|
it "constantizes the class_name" do
|
1629
|
-
metadata.klass.
|
1581
|
+
expect(metadata.klass).to eq(Address)
|
1630
1582
|
end
|
1631
1583
|
end
|
1632
1584
|
|
@@ -1640,7 +1592,7 @@ describe Mongoid::Relations::Metadata do
|
|
1640
1592
|
end
|
1641
1593
|
|
1642
1594
|
it "returns the class" do
|
1643
|
-
metadata.klass.
|
1595
|
+
expect(metadata.klass).to eq(Address)
|
1644
1596
|
end
|
1645
1597
|
end
|
1646
1598
|
end
|
@@ -1654,7 +1606,7 @@ describe Mongoid::Relations::Metadata do
|
|
1654
1606
|
end
|
1655
1607
|
|
1656
1608
|
it "returns true" do
|
1657
|
-
metadata.
|
1609
|
+
expect(metadata).to be_many
|
1658
1610
|
end
|
1659
1611
|
end
|
1660
1612
|
|
@@ -1665,7 +1617,7 @@ describe Mongoid::Relations::Metadata do
|
|
1665
1617
|
end
|
1666
1618
|
|
1667
1619
|
it "returns false" do
|
1668
|
-
metadata.
|
1620
|
+
expect(metadata).to_not be_many
|
1669
1621
|
end
|
1670
1622
|
end
|
1671
1623
|
end
|
@@ -1677,7 +1629,7 @@ describe Mongoid::Relations::Metadata do
|
|
1677
1629
|
end
|
1678
1630
|
|
1679
1631
|
it "returns the macro from the relation" do
|
1680
|
-
metadata.macro.
|
1632
|
+
expect(metadata.macro).to eq(:embeds_one)
|
1681
1633
|
end
|
1682
1634
|
end
|
1683
1635
|
|
@@ -1696,8 +1648,9 @@ describe Mongoid::Relations::Metadata do
|
|
1696
1648
|
end
|
1697
1649
|
|
1698
1650
|
it "returns the nested builder from the relation" do
|
1699
|
-
|
1700
|
-
|
1651
|
+
expect(
|
1652
|
+
metadata.nested_builder(attributes, options)
|
1653
|
+
).to be_a_kind_of(Mongoid::Relations::Builders::NestedAttributes::One)
|
1701
1654
|
end
|
1702
1655
|
end
|
1703
1656
|
|
@@ -1714,7 +1667,7 @@ describe Mongoid::Relations::Metadata do
|
|
1714
1667
|
end
|
1715
1668
|
|
1716
1669
|
it "returns _id" do
|
1717
|
-
metadata.primary_key.
|
1670
|
+
expect(metadata.primary_key).to eq("_id")
|
1718
1671
|
end
|
1719
1672
|
end
|
1720
1673
|
|
@@ -1730,7 +1683,7 @@ describe Mongoid::Relations::Metadata do
|
|
1730
1683
|
end
|
1731
1684
|
|
1732
1685
|
it "returns the primary key" do
|
1733
|
-
metadata.primary_key.
|
1686
|
+
expect(metadata.primary_key).to eq("something_id")
|
1734
1687
|
end
|
1735
1688
|
end
|
1736
1689
|
end
|
@@ -1751,7 +1704,7 @@ describe Mongoid::Relations::Metadata do
|
|
1751
1704
|
end
|
1752
1705
|
|
1753
1706
|
it "returns true" do
|
1754
|
-
metadata.validate
|
1707
|
+
expect(metadata.validate?).to be true
|
1755
1708
|
end
|
1756
1709
|
end
|
1757
1710
|
|
@@ -1767,7 +1720,7 @@ describe Mongoid::Relations::Metadata do
|
|
1767
1720
|
end
|
1768
1721
|
|
1769
1722
|
it "returns false" do
|
1770
|
-
metadata.validate
|
1723
|
+
expect(metadata.validate?).to be false
|
1771
1724
|
end
|
1772
1725
|
end
|
1773
1726
|
end
|
@@ -1783,54 +1736,7 @@ describe Mongoid::Relations::Metadata do
|
|
1783
1736
|
end
|
1784
1737
|
|
1785
1738
|
it "returns the relation default" do
|
1786
|
-
metadata.validate
|
1787
|
-
end
|
1788
|
-
end
|
1789
|
-
end
|
1790
|
-
|
1791
|
-
describe "#versioned?" do
|
1792
|
-
|
1793
|
-
context "when versioned is true" do
|
1794
|
-
|
1795
|
-
let(:metadata) do
|
1796
|
-
described_class.new(
|
1797
|
-
name: :versions,
|
1798
|
-
relation: Mongoid::Relations::Embedded::Many,
|
1799
|
-
versioned: true
|
1800
|
-
)
|
1801
|
-
end
|
1802
|
-
|
1803
|
-
it "returns true" do
|
1804
|
-
metadata.should be_versioned
|
1805
|
-
end
|
1806
|
-
end
|
1807
|
-
|
1808
|
-
context "when versioned is false" do
|
1809
|
-
|
1810
|
-
let(:metadata) do
|
1811
|
-
described_class.new(
|
1812
|
-
name: :versions,
|
1813
|
-
relation: Mongoid::Relations::Embedded::Many,
|
1814
|
-
versioned: false
|
1815
|
-
)
|
1816
|
-
end
|
1817
|
-
|
1818
|
-
it "returns false" do
|
1819
|
-
metadata.should_not be_versioned
|
1820
|
-
end
|
1821
|
-
end
|
1822
|
-
|
1823
|
-
context "when versioned is nil" do
|
1824
|
-
|
1825
|
-
let(:metadata) do
|
1826
|
-
described_class.new(
|
1827
|
-
name: :versions,
|
1828
|
-
relation: Mongoid::Relations::Embedded::Many
|
1829
|
-
)
|
1830
|
-
end
|
1831
|
-
|
1832
|
-
it "returns false" do
|
1833
|
-
metadata.should_not be_versioned
|
1739
|
+
expect(metadata.validate?).to be true
|
1834
1740
|
end
|
1835
1741
|
end
|
1836
1742
|
end
|
@@ -1848,7 +1754,7 @@ describe Mongoid::Relations::Metadata do
|
|
1848
1754
|
end
|
1849
1755
|
|
1850
1756
|
it "returns the value" do
|
1851
|
-
metadata.store_as.
|
1757
|
+
expect(metadata.store_as).to eq("user_comments")
|
1852
1758
|
end
|
1853
1759
|
end
|
1854
1760
|
|
@@ -1862,7 +1768,7 @@ describe Mongoid::Relations::Metadata do
|
|
1862
1768
|
end
|
1863
1769
|
|
1864
1770
|
it "returns false" do
|
1865
|
-
metadata.store_as.
|
1771
|
+
expect(metadata.store_as).to eq("comments")
|
1866
1772
|
end
|
1867
1773
|
end
|
1868
1774
|
end
|
@@ -1893,32 +1799,51 @@ describe Mongoid::Relations::Metadata do
|
|
1893
1799
|
end
|
1894
1800
|
|
1895
1801
|
it "returns nil" do
|
1896
|
-
inverse_relation.
|
1802
|
+
expect(inverse_relation).to be_nil
|
1897
1803
|
end
|
1898
1804
|
end
|
1899
1805
|
|
1900
1806
|
context "when one match" do
|
1901
1807
|
|
1902
1808
|
it "returns correct relation" do
|
1903
|
-
inverse_relation.
|
1809
|
+
expect(inverse_relation).to eq(:drugs)
|
1904
1810
|
end
|
1905
1811
|
end
|
1906
1812
|
|
1907
1813
|
context "when multiple matches" do
|
1908
1814
|
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1815
|
+
context "when the inverse_of is not nil" do
|
1816
|
+
|
1817
|
+
before do
|
1818
|
+
class_name.constantize.has_many(:evil_drugs, class_name: "Drug")
|
1819
|
+
end
|
1820
|
+
|
1821
|
+
after do
|
1822
|
+
class_name.constantize.relations.delete("evil_drugs")
|
1823
|
+
Person.reset_callbacks(:validate)
|
1824
|
+
end
|
1912
1825
|
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1826
|
+
it "raises AmbiguousRelationship" do
|
1827
|
+
expect {
|
1828
|
+
inverse_relation
|
1829
|
+
}.to raise_error(Mongoid::Errors::AmbiguousRelationship)
|
1830
|
+
end
|
1916
1831
|
end
|
1917
1832
|
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1833
|
+
context "when the inverse_of is nil" do
|
1834
|
+
|
1835
|
+
before do
|
1836
|
+
class_name.constantize.has_many(:evil_drugs, class_name: "Drug", inverse_of: nil)
|
1837
|
+
end
|
1838
|
+
|
1839
|
+
after do
|
1840
|
+
class_name.constantize.relations.delete("evil_drugs")
|
1841
|
+
Person.reset_callbacks(:validate)
|
1842
|
+
end
|
1843
|
+
|
1844
|
+
it "returns the non-nil inverses" do
|
1845
|
+
expect(inverse_relation).to eq(:drugs)
|
1846
|
+
end
|
1922
1847
|
end
|
1923
1848
|
end
|
1924
1849
|
end
|
@@ -1936,7 +1861,7 @@ describe Mongoid::Relations::Metadata do
|
|
1936
1861
|
end
|
1937
1862
|
|
1938
1863
|
it "returns false" do
|
1939
|
-
metadata.
|
1864
|
+
expect(metadata).to_not be_touchable
|
1940
1865
|
end
|
1941
1866
|
end
|
1942
1867
|
|
@@ -1951,7 +1876,7 @@ describe Mongoid::Relations::Metadata do
|
|
1951
1876
|
end
|
1952
1877
|
|
1953
1878
|
it "returns true" do
|
1954
|
-
metadata.
|
1879
|
+
expect(metadata).to be_touchable
|
1955
1880
|
end
|
1956
1881
|
end
|
1957
1882
|
|
@@ -1965,7 +1890,7 @@ describe Mongoid::Relations::Metadata do
|
|
1965
1890
|
end
|
1966
1891
|
|
1967
1892
|
it "returns false" do
|
1968
|
-
metadata.
|
1893
|
+
expect(metadata).to_not be_touchable
|
1969
1894
|
end
|
1970
1895
|
end
|
1971
1896
|
end
|
@@ -1991,7 +1916,7 @@ describe Mongoid::Relations::Metadata do
|
|
1991
1916
|
end
|
1992
1917
|
|
1993
1918
|
it "returns the #{property} property" do
|
1994
|
-
metadata.send(property).
|
1919
|
+
expect(metadata.send(property)).to eq(:value)
|
1995
1920
|
end
|
1996
1921
|
end
|
1997
1922
|
|
@@ -2007,7 +1932,7 @@ describe Mongoid::Relations::Metadata do
|
|
2007
1932
|
end
|
2008
1933
|
|
2009
1934
|
it "returns true" do
|
2010
|
-
metadata.send("#{property}?").
|
1935
|
+
expect(metadata.send("#{property}?")).to be true
|
2011
1936
|
end
|
2012
1937
|
end
|
2013
1938
|
|
@@ -2020,7 +1945,7 @@ describe Mongoid::Relations::Metadata do
|
|
2020
1945
|
end
|
2021
1946
|
|
2022
1947
|
it "returns false" do
|
2023
|
-
metadata.send("#{property}?").
|
1948
|
+
expect(metadata.send("#{property}?")).to be false
|
2024
1949
|
end
|
2025
1950
|
end
|
2026
1951
|
end
|