mongoid 3.1.6 → 4.0.0
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 +432 -8
- data/README.md +5 -6
- data/lib/config/locales/en.yml +32 -18
- 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/embedded.rb +0 -30
- data/lib/mongoid/atomic/paths/root.rb +0 -13
- data/lib/mongoid/atomic.rb +1 -12
- 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/attributes.rb +63 -101
- data/lib/mongoid/{dirty.rb → changeable.rb} +32 -2
- data/lib/mongoid/composable.rb +105 -0
- data/lib/mongoid/config/options.rb +1 -1
- data/lib/mongoid/config.rb +3 -9
- 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 +18 -6
- data/lib/mongoid/contextual/mongo.rb +64 -56
- data/lib/mongoid/contextual/none.rb +90 -0
- data/lib/mongoid/contextual/text_search.rb +178 -0
- data/lib/mongoid/contextual.rb +2 -0
- data/lib/mongoid/copyable.rb +2 -3
- 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/criteria.rb +39 -34
- data/lib/mongoid/document.rb +32 -17
- 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/errors.rb +4 -1
- 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/extensions.rb +2 -7
- data/lib/mongoid/factory.rb +8 -6
- 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/fields.rb +41 -8
- data/lib/mongoid/{finders.rb → findable.rb} +8 -2
- data/lib/mongoid/indexable/specification.rb +104 -0
- data/lib/mongoid/{indexes → indexable}/validators/options.rb +2 -1
- data/lib/mongoid/{indexes.rb → indexable.rb} +50 -55
- 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/{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/matchable.rb +152 -0
- data/lib/mongoid/persistable/creatable.rb +188 -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 +152 -0
- data/lib/mongoid/persistable/upsertable.rb +55 -0
- data/lib/mongoid/persistable.rb +216 -0
- data/lib/mongoid/positional.rb +71 -0
- data/lib/mongoid/query_cache.rb +247 -0
- data/lib/mongoid/railtie.rb +32 -45
- data/lib/mongoid/railties/database.rake +9 -25
- data/lib/mongoid/relations/accessors.rb +13 -49
- data/lib/mongoid/relations/auto_save.rb +15 -36
- data/lib/mongoid/relations/binding.rb +1 -24
- 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 +3 -1
- data/lib/mongoid/relations/builder.rb +1 -1
- 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/builders.rb +2 -2
- 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/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/eager.rb +46 -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 +30 -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/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 +19 -32
- data/lib/mongoid/relations/referenced/many_to_many.rb +15 -38
- data/lib/mongoid/relations/referenced/one.rb +6 -25
- data/lib/mongoid/relations/synchronization.rb +3 -3
- data/lib/mongoid/relations/touchable.rb +34 -1
- data/lib/mongoid/relations.rb +11 -25
- data/lib/mongoid/{reloading.rb → reloadable.rb} +6 -4
- 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/factory.rb +2 -0
- data/lib/mongoid/sessions/options.rb +180 -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/sessions.rb +37 -345
- 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/lifecycle.rb +0 -28
- data/lib/mongoid/threaded.rb +0 -157
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +9 -5
- 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 +23 -19
- data/lib/mongoid/{validations.rb → validatable.rb} +23 -10
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid.rb +10 -76
- data/lib/rails/generators/mongoid/config/templates/mongoid.yml +13 -24
- 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/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/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/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 +58 -18
- data/spec/mongoid/attributes_spec.rb +315 -436
- 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 +68 -58
- 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 +151 -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 +1255 -0
- data/spec/mongoid/{criterion/scoping_spec.rb → criteria/scopable_spec.rb} +37 -37
- data/spec/mongoid/criteria_spec.rb +578 -2295
- 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_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 +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 +38 -23
- data/spec/mongoid/fields/standard_spec.rb +12 -12
- data/spec/mongoid/fields_spec.rb +263 -217
- data/spec/mongoid/{finders_spec.rb → findable_spec.rb} +127 -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} +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 +512 -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 +461 -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} +9 -9
- data/spec/mongoid/query_cache_spec.rb +231 -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 +393 -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 +434 -527
- data/spec/mongoid/relations/referenced/many_to_many_spec.rb +352 -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} +20 -60
- 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 +107 -0
- data/spec/mongoid/sessions_spec.rb +289 -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 +29 -13
- metadata +296 -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/strategies.rb +0 -97
- data/lib/mongoid/matchers.rb +0 -32
- data/lib/mongoid/multi_parameter_attributes.rb +0 -105
- data/lib/mongoid/nested_attributes.rb +0 -78
- data/lib/mongoid/observer.rb +0 -192
- data/lib/mongoid/paranoia.rb +0 -136
- data/lib/mongoid/persistence/atomic/add_to_set.rb +0 -47
- data/lib/mongoid/persistence/atomic/bit.rb +0 -35
- data/lib/mongoid/persistence/atomic/inc.rb +0 -45
- data/lib/mongoid/persistence/atomic/operation.rb +0 -154
- data/lib/mongoid/persistence/atomic/pop.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull.rb +0 -32
- data/lib/mongoid/persistence/atomic/pull_all.rb +0 -32
- data/lib/mongoid/persistence/atomic/push.rb +0 -25
- data/lib/mongoid/persistence/atomic/push_all.rb +0 -25
- data/lib/mongoid/persistence/atomic/rename.rb +0 -30
- data/lib/mongoid/persistence/atomic/sets.rb +0 -28
- data/lib/mongoid/persistence/atomic/unset.rb +0 -27
- data/lib/mongoid/persistence/atomic.rb +0 -231
- data/lib/mongoid/persistence/deletion.rb +0 -31
- data/lib/mongoid/persistence/insertion.rb +0 -38
- data/lib/mongoid/persistence/modification.rb +0 -35
- data/lib/mongoid/persistence/operations/embedded/insert.rb +0 -46
- data/lib/mongoid/persistence/operations/embedded/remove.rb +0 -43
- data/lib/mongoid/persistence/operations/insert.rb +0 -34
- data/lib/mongoid/persistence/operations/remove.rb +0 -33
- data/lib/mongoid/persistence/operations/update.rb +0 -59
- data/lib/mongoid/persistence/operations/upsert.rb +0 -28
- data/lib/mongoid/persistence/operations.rb +0 -214
- data/lib/mongoid/persistence/upsertion.rb +0 -31
- data/lib/mongoid/persistence.rb +0 -357
- data/lib/mongoid/unit_of_work.rb +0 -61
- data/lib/mongoid/versioning.rb +0 -217
- data/lib/rack/mongoid/middleware/identity_map.rb +0 -39
- data/lib/rack/mongoid.rb +0 -2
- data/lib/rails/generators/mongoid/observer/observer_generator.rb +0 -17
- data/lib/rails/generators/mongoid/observer/templates/observer.rb.tt +0 -4
- data/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/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
|
@@ -11,7 +11,75 @@ describe Mongoid::Attributes do
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "does not cause an infinite loop" do
|
|
14
|
-
account.overridden.
|
|
14
|
+
expect(account.overridden).to eq("not recommended")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "when the attribute was excluded in a criteria" do
|
|
19
|
+
|
|
20
|
+
let!(:person) do
|
|
21
|
+
Person.create(title: "sir")
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "when the attribute is localized" do
|
|
25
|
+
|
|
26
|
+
before do
|
|
27
|
+
person.update_attribute(:desc, "test")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "when the context includes" do
|
|
31
|
+
|
|
32
|
+
context "when the attribute exists" do
|
|
33
|
+
|
|
34
|
+
let(:from_db) do
|
|
35
|
+
Person.only(:desc).first
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "does not raise an error" do
|
|
39
|
+
expect(from_db.desc).to eq("test")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when the context excludes" do
|
|
45
|
+
|
|
46
|
+
context "when the attribute exists" do
|
|
47
|
+
|
|
48
|
+
let(:from_db) do
|
|
49
|
+
Person.without(:pets).first
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "does not raise an error" do
|
|
53
|
+
expect(from_db.desc).to eq("test")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "when excluding with only" do
|
|
60
|
+
|
|
61
|
+
let(:from_db) do
|
|
62
|
+
Person.only(:_id).first
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "raises an error" do
|
|
66
|
+
expect {
|
|
67
|
+
from_db.title
|
|
68
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "when excluding with without" do
|
|
73
|
+
|
|
74
|
+
let(:from_db) do
|
|
75
|
+
Person.without(:title).first
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "raises an error" do
|
|
79
|
+
expect {
|
|
80
|
+
from_db.title
|
|
81
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
82
|
+
end
|
|
15
83
|
end
|
|
16
84
|
end
|
|
17
85
|
end
|
|
@@ -33,14 +101,14 @@ describe Mongoid::Attributes do
|
|
|
33
101
|
context "when passing just the name" do
|
|
34
102
|
|
|
35
103
|
it "returns the full value" do
|
|
36
|
-
person[:desc].
|
|
104
|
+
expect(person[:desc]).to eq("en" => "testing")
|
|
37
105
|
end
|
|
38
106
|
end
|
|
39
107
|
|
|
40
108
|
context "when passing the name with locale" do
|
|
41
109
|
|
|
42
110
|
it "returns the value for the locale" do
|
|
43
|
-
person["desc.en"].
|
|
111
|
+
expect(person["desc.en"]).to eq("testing")
|
|
44
112
|
end
|
|
45
113
|
end
|
|
46
114
|
end
|
|
@@ -48,7 +116,7 @@ describe Mongoid::Attributes do
|
|
|
48
116
|
context "when attribute does not exist" do
|
|
49
117
|
|
|
50
118
|
it "returns the default value" do
|
|
51
|
-
person[:age].
|
|
119
|
+
expect(person[:age]).to eq(100)
|
|
52
120
|
end
|
|
53
121
|
end
|
|
54
122
|
|
|
@@ -59,7 +127,7 @@ describe Mongoid::Attributes do
|
|
|
59
127
|
end
|
|
60
128
|
|
|
61
129
|
it "returns the value" do
|
|
62
|
-
person[:owner_id].
|
|
130
|
+
expect(person[:owner_id]).to eq(5)
|
|
63
131
|
end
|
|
64
132
|
end
|
|
65
133
|
end
|
|
@@ -70,6 +138,35 @@ describe Mongoid::Attributes do
|
|
|
70
138
|
Person.create(title: "sir")
|
|
71
139
|
end
|
|
72
140
|
|
|
141
|
+
context "when the attribute was excluded in a criteria" do
|
|
142
|
+
|
|
143
|
+
context "when excluding with only" do
|
|
144
|
+
|
|
145
|
+
let(:from_db) do
|
|
146
|
+
Person.only(:_id).first
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "raises an error" do
|
|
150
|
+
expect {
|
|
151
|
+
from_db[:title]
|
|
152
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
context "when excluding with without" do
|
|
157
|
+
|
|
158
|
+
let(:from_db) do
|
|
159
|
+
Person.without(:title).first
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
it "raises an error" do
|
|
163
|
+
expect {
|
|
164
|
+
from_db[:title]
|
|
165
|
+
}.to raise_error(ActiveModel::MissingAttributeError)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
73
170
|
context "when the attribute does not exist" do
|
|
74
171
|
|
|
75
172
|
before do
|
|
@@ -85,7 +182,7 @@ describe Mongoid::Attributes do
|
|
|
85
182
|
end
|
|
86
183
|
|
|
87
184
|
it "returns the default value" do
|
|
88
|
-
found[:age].
|
|
185
|
+
expect(found[:age]).to eq(100)
|
|
89
186
|
end
|
|
90
187
|
end
|
|
91
188
|
|
|
@@ -98,7 +195,7 @@ describe Mongoid::Attributes do
|
|
|
98
195
|
end
|
|
99
196
|
|
|
100
197
|
it "returns the default value" do
|
|
101
|
-
person[:age].
|
|
198
|
+
expect(person[:age]).to eq(100)
|
|
102
199
|
end
|
|
103
200
|
end
|
|
104
201
|
end
|
|
@@ -113,270 +210,31 @@ describe Mongoid::Attributes do
|
|
|
113
210
|
|
|
114
211
|
context "when setting the attribute to nil" do
|
|
115
212
|
|
|
116
|
-
|
|
213
|
+
let!(:age) do
|
|
117
214
|
person[:age] = nil
|
|
118
215
|
end
|
|
119
216
|
|
|
120
217
|
it "does not use the default value" do
|
|
121
|
-
person.age.
|
|
218
|
+
expect(person.age).to be_nil
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
it "returns the set value" do
|
|
222
|
+
expect(age).to be_nil
|
|
122
223
|
end
|
|
123
224
|
end
|
|
124
225
|
|
|
125
226
|
context "when field has a default value" do
|
|
126
227
|
|
|
127
|
-
|
|
228
|
+
let!(:terms) do
|
|
128
229
|
person[:terms] = true
|
|
129
230
|
end
|
|
130
231
|
|
|
131
232
|
it "allows overwriting of the default value" do
|
|
132
|
-
person.terms.
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe ".attr_accessible" do
|
|
138
|
-
|
|
139
|
-
context "when the field is not _id" do
|
|
140
|
-
|
|
141
|
-
let(:account) do
|
|
142
|
-
Account.new(number: 999999)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "prevents setting via mass assignment" do
|
|
146
|
-
account.number.should be_nil
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "when the field is _id" do
|
|
151
|
-
|
|
152
|
-
let(:account) do
|
|
153
|
-
Account.new(_id: "ABBA")
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "prevents setting via mass assignment" do
|
|
157
|
-
account._id.should_not eq("ABBA")
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
context "when using instantiate" do
|
|
162
|
-
|
|
163
|
-
let(:account) do
|
|
164
|
-
Account.instantiate("_id" => "1", "balance" => "ABBA")
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "ignores any protected attribute" do
|
|
168
|
-
account.balance.should eq("ABBA")
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context "when using override" do
|
|
173
|
-
|
|
174
|
-
let(:account) do
|
|
175
|
-
Account.new
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it "ignores any protected attribute" do
|
|
179
|
-
account.write_attributes({balance: "ABBA"}, false)
|
|
180
|
-
account.balance.should eq("ABBA")
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "when mass assignment role is indicated" do
|
|
185
|
-
|
|
186
|
-
context "when attributes assigned from default role" do
|
|
187
|
-
|
|
188
|
-
let(:article) do
|
|
189
|
-
Article.new(
|
|
190
|
-
title: "Some Title",
|
|
191
|
-
is_rss: true,
|
|
192
|
-
user_login: "SomeLogin"
|
|
193
|
-
)
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
it "sets the title field for default role" do
|
|
197
|
-
article.title.should eq("Some Title")
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
it "sets the user login field for the default role" do
|
|
201
|
-
article.user_login.should eq("SomeLogin")
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "sets the rss field for the default role" do
|
|
205
|
-
article.is_rss.should be_false
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
context "when attributes assigned from parser role" do
|
|
210
|
-
|
|
211
|
-
let(:article) do
|
|
212
|
-
Article.new({
|
|
213
|
-
title: "Some Title",
|
|
214
|
-
is_rss: true,
|
|
215
|
-
user_login: "SomeLogin"
|
|
216
|
-
}, as: :parser
|
|
217
|
-
)
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
it "sets the title field" do
|
|
221
|
-
article.title.should eq("Some Title")
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it "sets the rss field" do
|
|
225
|
-
article.is_rss.should be_true
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
it "does not set the user login field" do
|
|
229
|
-
article.user_login.should be_nil
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
context "when attributes assigned without protection" do
|
|
234
|
-
|
|
235
|
-
let(:article) do
|
|
236
|
-
Article.new(
|
|
237
|
-
{ title: "Some Title",
|
|
238
|
-
is_rss: true,
|
|
239
|
-
user_login: "SomeLogin"
|
|
240
|
-
}, without_protection: true
|
|
241
|
-
)
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
it "sets the title field" do
|
|
245
|
-
article.title.should eq("Some Title")
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it "sets the user login field" do
|
|
249
|
-
article.user_login.should eq("SomeLogin")
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it "sets the rss field" do
|
|
253
|
-
article.is_rss.should be_true
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
describe ".attr_protected" do
|
|
260
|
-
|
|
261
|
-
context "when the field is not _id" do
|
|
262
|
-
|
|
263
|
-
let(:person) do
|
|
264
|
-
Person.new(security_code: "ABBA")
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
it "prevents setting via mass assignment" do
|
|
268
|
-
person.security_code.should be_nil
|
|
269
|
-
end
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
context "when the field is _id" do
|
|
273
|
-
|
|
274
|
-
let(:game) do
|
|
275
|
-
Game.new(_id: "ABBA")
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
it "prevents setting via mass assignment" do
|
|
279
|
-
game._id.should_not eq("ABBA")
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
context "when using instantiate" do
|
|
284
|
-
|
|
285
|
-
let(:person) do
|
|
286
|
-
Person.instantiate("_id" => "1", "security_code" => "ABBA")
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it "ignores any protected attribute" do
|
|
290
|
-
person.security_code.should eq("ABBA")
|
|
233
|
+
expect(person.terms).to be true
|
|
291
234
|
end
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
context "when using override" do
|
|
295
235
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
it "ignores any protected attribute" do
|
|
301
|
-
person.write_attributes({security_code: "ABBA"}, false)
|
|
302
|
-
person.security_code.should eq("ABBA")
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
context "when mass assignment role is indicated" do
|
|
307
|
-
|
|
308
|
-
let(:item) do
|
|
309
|
-
Item.new
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
context "when attributes assigned from default role" do
|
|
313
|
-
|
|
314
|
-
before do
|
|
315
|
-
item.assign_attributes(
|
|
316
|
-
title: "Some Title",
|
|
317
|
-
is_rss: true,
|
|
318
|
-
user_login: "SomeLogin"
|
|
319
|
-
)
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
it "sets the field for the default role" do
|
|
323
|
-
item.is_rss.should be_true
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
it "does not set the field for non default role title" do
|
|
327
|
-
item.title.should be_nil
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it "does not set the field for non default role user login" do
|
|
331
|
-
item.user_login.should be_nil
|
|
332
|
-
end
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
context "when attributes assigned from parser role" do
|
|
336
|
-
|
|
337
|
-
before do
|
|
338
|
-
item.assign_attributes(
|
|
339
|
-
{ title: "Some Title",
|
|
340
|
-
is_rss: true,
|
|
341
|
-
user_login: "SomeLogin" }, as: :parser
|
|
342
|
-
)
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
it "sets the user login field for parser role" do
|
|
346
|
-
item.user_login.should eq("SomeLogin")
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
it "sets the is rss field for parse role" do
|
|
350
|
-
item.is_rss.should be_false
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
it "does not set the title field" do
|
|
354
|
-
item.title.should be_nil
|
|
355
|
-
end
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
context "when attributes assigned without protection" do
|
|
359
|
-
|
|
360
|
-
before do
|
|
361
|
-
item.assign_attributes(
|
|
362
|
-
{ title: "Some Title",
|
|
363
|
-
is_rss: true,
|
|
364
|
-
user_login: "SomeLogin"
|
|
365
|
-
}, without_protection: true
|
|
366
|
-
)
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
it "sets the title attribute" do
|
|
370
|
-
item.title.should eq("Some Title")
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
it "sets the user login attribute" do
|
|
374
|
-
item.user_login.should eq("SomeLogin")
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
it "sets the rss attribute" do
|
|
378
|
-
item.is_rss.should be_true
|
|
379
|
-
end
|
|
236
|
+
it "returns the set value" do
|
|
237
|
+
expect(terms).to eq(true)
|
|
380
238
|
end
|
|
381
239
|
end
|
|
382
240
|
end
|
|
@@ -388,7 +246,7 @@ describe Mongoid::Attributes do
|
|
|
388
246
|
end
|
|
389
247
|
|
|
390
248
|
it "delegates to #id" do
|
|
391
|
-
person._id.
|
|
249
|
+
expect(person._id).to eq(person.id)
|
|
392
250
|
end
|
|
393
251
|
end
|
|
394
252
|
|
|
@@ -397,9 +255,10 @@ describe Mongoid::Attributes do
|
|
|
397
255
|
after(:all) do
|
|
398
256
|
Person.field(
|
|
399
257
|
:_id,
|
|
400
|
-
type:
|
|
258
|
+
type: BSON::ObjectId,
|
|
401
259
|
pre_processed: true,
|
|
402
|
-
default: ->{
|
|
260
|
+
default: ->{ BSON::ObjectId.new },
|
|
261
|
+
overwrite: true
|
|
403
262
|
)
|
|
404
263
|
end
|
|
405
264
|
|
|
@@ -408,9 +267,10 @@ describe Mongoid::Attributes do
|
|
|
408
267
|
before(:all) do
|
|
409
268
|
Person.field(
|
|
410
269
|
:_id,
|
|
411
|
-
type:
|
|
270
|
+
type: BSON::ObjectId,
|
|
412
271
|
pre_processed: true,
|
|
413
|
-
default: ->{
|
|
272
|
+
default: ->{ BSON::ObjectId.new },
|
|
273
|
+
overwrite: true
|
|
414
274
|
)
|
|
415
275
|
end
|
|
416
276
|
|
|
@@ -419,7 +279,7 @@ describe Mongoid::Attributes do
|
|
|
419
279
|
end
|
|
420
280
|
|
|
421
281
|
let(:bson_id) do
|
|
422
|
-
|
|
282
|
+
BSON::ObjectId.new
|
|
423
283
|
end
|
|
424
284
|
|
|
425
285
|
context "when providing an object id" do
|
|
@@ -429,7 +289,7 @@ describe Mongoid::Attributes do
|
|
|
429
289
|
end
|
|
430
290
|
|
|
431
291
|
it "sets the id as the object id" do
|
|
432
|
-
person.id.
|
|
292
|
+
expect(person.id).to eq(bson_id)
|
|
433
293
|
end
|
|
434
294
|
end
|
|
435
295
|
|
|
@@ -440,7 +300,7 @@ describe Mongoid::Attributes do
|
|
|
440
300
|
end
|
|
441
301
|
|
|
442
302
|
it "sets the id as the object id" do
|
|
443
|
-
person.id.
|
|
303
|
+
expect(person.id).to eq(bson_id)
|
|
444
304
|
end
|
|
445
305
|
end
|
|
446
306
|
|
|
@@ -451,7 +311,7 @@ describe Mongoid::Attributes do
|
|
|
451
311
|
end
|
|
452
312
|
|
|
453
313
|
it "sets the id as the supplied value to_s" do
|
|
454
|
-
person.id.
|
|
314
|
+
expect(person.id).to eq(2)
|
|
455
315
|
end
|
|
456
316
|
end
|
|
457
317
|
end
|
|
@@ -463,7 +323,8 @@ describe Mongoid::Attributes do
|
|
|
463
323
|
:_id,
|
|
464
324
|
type: String,
|
|
465
325
|
pre_processed: true,
|
|
466
|
-
default: ->{
|
|
326
|
+
default: ->{ BSON::ObjectId.new.to_s },
|
|
327
|
+
overwrite: true
|
|
467
328
|
)
|
|
468
329
|
end
|
|
469
330
|
|
|
@@ -472,7 +333,7 @@ describe Mongoid::Attributes do
|
|
|
472
333
|
end
|
|
473
334
|
|
|
474
335
|
let(:bson_id) do
|
|
475
|
-
|
|
336
|
+
BSON::ObjectId.new
|
|
476
337
|
end
|
|
477
338
|
|
|
478
339
|
context "when providing an object id" do
|
|
@@ -482,7 +343,7 @@ describe Mongoid::Attributes do
|
|
|
482
343
|
end
|
|
483
344
|
|
|
484
345
|
it "sets the id as the string of the object id" do
|
|
485
|
-
person.id.
|
|
346
|
+
expect(person.id).to eq(bson_id.to_s)
|
|
486
347
|
end
|
|
487
348
|
end
|
|
488
349
|
|
|
@@ -493,7 +354,7 @@ describe Mongoid::Attributes do
|
|
|
493
354
|
end
|
|
494
355
|
|
|
495
356
|
it "sets the id as the string" do
|
|
496
|
-
person.id.
|
|
357
|
+
expect(person.id).to eq(bson_id.to_s)
|
|
497
358
|
end
|
|
498
359
|
end
|
|
499
360
|
|
|
@@ -504,7 +365,7 @@ describe Mongoid::Attributes do
|
|
|
504
365
|
end
|
|
505
366
|
|
|
506
367
|
it "sets the id as the supplied value to_s" do
|
|
507
|
-
person.id.
|
|
368
|
+
expect(person.id).to eq("2")
|
|
508
369
|
end
|
|
509
370
|
end
|
|
510
371
|
end
|
|
@@ -512,7 +373,7 @@ describe Mongoid::Attributes do
|
|
|
512
373
|
context "when using integer ids" do
|
|
513
374
|
|
|
514
375
|
before(:all) do
|
|
515
|
-
Person.field(:_id, type: Integer)
|
|
376
|
+
Person.field(:_id, type: Integer, overwrite: true)
|
|
516
377
|
end
|
|
517
378
|
|
|
518
379
|
let(:person) do
|
|
@@ -526,7 +387,7 @@ describe Mongoid::Attributes do
|
|
|
526
387
|
end
|
|
527
388
|
|
|
528
389
|
it "sets the id as the integer" do
|
|
529
|
-
person.id.
|
|
390
|
+
expect(person.id).to eq(1)
|
|
530
391
|
end
|
|
531
392
|
end
|
|
532
393
|
|
|
@@ -537,7 +398,7 @@ describe Mongoid::Attributes do
|
|
|
537
398
|
end
|
|
538
399
|
|
|
539
400
|
it "sets the id as the supplied value" do
|
|
540
|
-
person.id.
|
|
401
|
+
expect(person.id).to eq(2)
|
|
541
402
|
end
|
|
542
403
|
end
|
|
543
404
|
end
|
|
@@ -553,27 +414,23 @@ describe Mongoid::Attributes do
|
|
|
553
414
|
Person.new(attributes)
|
|
554
415
|
end
|
|
555
416
|
|
|
556
|
-
before do
|
|
557
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
558
|
-
end
|
|
559
|
-
|
|
560
417
|
context "when an attribute exists" do
|
|
561
418
|
|
|
562
419
|
it "allows the getter" do
|
|
563
|
-
person.testing.
|
|
420
|
+
expect(person.testing).to eq("Testing")
|
|
564
421
|
end
|
|
565
422
|
|
|
566
423
|
it "allows the setter" do
|
|
567
424
|
person.testing = "Test"
|
|
568
|
-
person.testing.
|
|
425
|
+
expect(person.testing).to eq("Test")
|
|
569
426
|
end
|
|
570
427
|
|
|
571
428
|
it "allows the getter before_type_cast" do
|
|
572
|
-
person.testing_before_type_cast.
|
|
429
|
+
expect(person.testing_before_type_cast).to eq("Testing")
|
|
573
430
|
end
|
|
574
431
|
|
|
575
432
|
it "returns true for respond_to?" do
|
|
576
|
-
person.respond_to?(:testing).
|
|
433
|
+
expect(person.respond_to?(:testing)).to be true
|
|
577
434
|
end
|
|
578
435
|
end
|
|
579
436
|
|
|
@@ -588,28 +445,17 @@ describe Mongoid::Attributes do
|
|
|
588
445
|
end
|
|
589
446
|
|
|
590
447
|
it "mongoizes the dynamic field" do
|
|
591
|
-
person.new_years.
|
|
448
|
+
expect(person.new_years).to be_a(Time)
|
|
592
449
|
end
|
|
593
450
|
|
|
594
451
|
it "keeps the same value" do
|
|
595
|
-
person.new_years.
|
|
452
|
+
expect(person.new_years).to eq(new_years)
|
|
596
453
|
end
|
|
597
454
|
end
|
|
598
455
|
end
|
|
599
456
|
|
|
600
457
|
describe "#process" do
|
|
601
458
|
|
|
602
|
-
context "when passing non accessible fields" do
|
|
603
|
-
|
|
604
|
-
let(:person) do
|
|
605
|
-
Person.new(owner_id: 6)
|
|
606
|
-
end
|
|
607
|
-
|
|
608
|
-
it "does not set the value" do
|
|
609
|
-
person.owner_id.should be_nil
|
|
610
|
-
end
|
|
611
|
-
end
|
|
612
|
-
|
|
613
459
|
context "when attributes dont have fields defined" do
|
|
614
460
|
|
|
615
461
|
let(:attributes) do
|
|
@@ -626,43 +472,26 @@ describe Mongoid::Attributes do
|
|
|
626
472
|
Person.new(attributes)
|
|
627
473
|
end
|
|
628
474
|
|
|
629
|
-
before do
|
|
630
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
631
|
-
end
|
|
632
|
-
|
|
633
475
|
context "when attribute is a string" do
|
|
634
476
|
|
|
635
477
|
it "adds the string to the attributes" do
|
|
636
|
-
person.attributes["nofieldstring"].
|
|
478
|
+
expect(person.attributes["nofieldstring"]).to eq("Testing")
|
|
637
479
|
end
|
|
638
480
|
end
|
|
639
481
|
|
|
640
482
|
context "when attribute is not a string" do
|
|
641
483
|
|
|
642
484
|
it "adds a cast value to the attributes" do
|
|
643
|
-
person.attributes["nofieldint"].
|
|
485
|
+
expect(person.attributes["nofieldint"]).to eq(5)
|
|
644
486
|
end
|
|
645
487
|
end
|
|
646
488
|
end
|
|
647
489
|
|
|
648
490
|
context "when not allowing dynamic fields" do
|
|
649
491
|
|
|
650
|
-
|
|
651
|
-
{ nofieldstring: "Testing" }
|
|
652
|
-
end
|
|
653
|
-
|
|
654
|
-
before do
|
|
655
|
-
Mongoid.configure.allow_dynamic_fields = false
|
|
656
|
-
Person.fields.delete(:nofieldstring)
|
|
657
|
-
end
|
|
658
|
-
|
|
659
|
-
after do
|
|
660
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
661
|
-
end
|
|
662
|
-
|
|
663
|
-
it "raises an unknown attribute error" do
|
|
492
|
+
it "raises an unknown attribute error on instantiation" do
|
|
664
493
|
expect {
|
|
665
|
-
|
|
494
|
+
Account.new({ anothernew: "Test" })
|
|
666
495
|
}.to raise_error(Mongoid::Errors::UnknownAttribute)
|
|
667
496
|
end
|
|
668
497
|
end
|
|
@@ -671,7 +500,7 @@ describe Mongoid::Attributes do
|
|
|
671
500
|
context "when supplied hash has string values" do
|
|
672
501
|
|
|
673
502
|
let(:bson_id) do
|
|
674
|
-
|
|
503
|
+
BSON::ObjectId.new
|
|
675
504
|
end
|
|
676
505
|
|
|
677
506
|
let!(:attributes) do
|
|
@@ -695,15 +524,15 @@ describe Mongoid::Attributes do
|
|
|
695
524
|
end
|
|
696
525
|
|
|
697
526
|
it "casts integers" do
|
|
698
|
-
person[:age].
|
|
527
|
+
expect(person[:age]).to eq(30)
|
|
699
528
|
end
|
|
700
529
|
|
|
701
530
|
it "casts booleans" do
|
|
702
|
-
person[:terms].
|
|
531
|
+
expect(person[:terms]).to be true
|
|
703
532
|
end
|
|
704
533
|
|
|
705
534
|
it "sets empty strings to nil" do
|
|
706
|
-
person[:score].
|
|
535
|
+
expect(person[:score]).to be_nil
|
|
707
536
|
end
|
|
708
537
|
end
|
|
709
538
|
|
|
@@ -724,7 +553,7 @@ describe Mongoid::Attributes do
|
|
|
724
553
|
end
|
|
725
554
|
|
|
726
555
|
it "sets the associations" do
|
|
727
|
-
person.name.
|
|
556
|
+
expect(person.name).to eq(name)
|
|
728
557
|
end
|
|
729
558
|
end
|
|
730
559
|
|
|
@@ -743,11 +572,11 @@ describe Mongoid::Attributes do
|
|
|
743
572
|
end
|
|
744
573
|
|
|
745
574
|
it "sets the parent association" do
|
|
746
|
-
person.game.
|
|
575
|
+
expect(person.game).to eq(game)
|
|
747
576
|
end
|
|
748
577
|
|
|
749
578
|
it "sets the inverse association" do
|
|
750
|
-
game.person.
|
|
579
|
+
expect(game.person).to eq(person)
|
|
751
580
|
end
|
|
752
581
|
end
|
|
753
582
|
|
|
@@ -762,7 +591,7 @@ describe Mongoid::Attributes do
|
|
|
762
591
|
end
|
|
763
592
|
|
|
764
593
|
it "sets the association" do
|
|
765
|
-
name.person.
|
|
594
|
+
expect(name.person).to eq(person)
|
|
766
595
|
end
|
|
767
596
|
end
|
|
768
597
|
end
|
|
@@ -782,7 +611,7 @@ describe Mongoid::Attributes do
|
|
|
782
611
|
end
|
|
783
612
|
|
|
784
613
|
it "calls the setter for the association" do
|
|
785
|
-
person.employer_id.
|
|
614
|
+
expect(person.employer_id).to eq("1")
|
|
786
615
|
end
|
|
787
616
|
end
|
|
788
617
|
|
|
@@ -797,7 +626,7 @@ describe Mongoid::Attributes do
|
|
|
797
626
|
end
|
|
798
627
|
|
|
799
628
|
it "sets the empty array" do
|
|
800
|
-
person.aliases.
|
|
629
|
+
expect(person.aliases).to be_empty
|
|
801
630
|
end
|
|
802
631
|
end
|
|
803
632
|
|
|
@@ -812,7 +641,20 @@ describe Mongoid::Attributes do
|
|
|
812
641
|
end
|
|
813
642
|
|
|
814
643
|
it "sets the empty hash" do
|
|
815
|
-
person.map.
|
|
644
|
+
expect(person.map).to eq({})
|
|
645
|
+
end
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
context "when providing tainted parameters" do
|
|
649
|
+
|
|
650
|
+
let(:params) do
|
|
651
|
+
ActionController::Parameters.new(title: "sir")
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
it "raises an error" do
|
|
655
|
+
expect {
|
|
656
|
+
Person.new(params)
|
|
657
|
+
}.to raise_error(ActiveModel::ForbiddenAttributesError)
|
|
816
658
|
end
|
|
817
659
|
end
|
|
818
660
|
end
|
|
@@ -832,7 +674,7 @@ describe Mongoid::Attributes do
|
|
|
832
674
|
end
|
|
833
675
|
|
|
834
676
|
it "only overwrites supplied attributes" do
|
|
835
|
-
person.title.
|
|
677
|
+
expect(person.title).to eq("Sir")
|
|
836
678
|
end
|
|
837
679
|
end
|
|
838
680
|
|
|
@@ -847,8 +689,8 @@ describe Mongoid::Attributes do
|
|
|
847
689
|
context "when attribute does not exist" do
|
|
848
690
|
|
|
849
691
|
it "returns the default value" do
|
|
850
|
-
person.age.
|
|
851
|
-
person.pets.
|
|
692
|
+
expect(person.age).to eq(100)
|
|
693
|
+
expect(person.pets).to be false
|
|
852
694
|
end
|
|
853
695
|
|
|
854
696
|
end
|
|
@@ -860,7 +702,7 @@ describe Mongoid::Attributes do
|
|
|
860
702
|
end
|
|
861
703
|
|
|
862
704
|
it "returns the value" do
|
|
863
|
-
person.read_attribute(:owner_id).
|
|
705
|
+
expect(person.read_attribute(:owner_id)).to eq(5)
|
|
864
706
|
end
|
|
865
707
|
end
|
|
866
708
|
end
|
|
@@ -883,13 +725,29 @@ describe Mongoid::Attributes do
|
|
|
883
725
|
end
|
|
884
726
|
|
|
885
727
|
it "returns the default value" do
|
|
886
|
-
person.age.
|
|
728
|
+
expect(person.age).to eq(100)
|
|
887
729
|
end
|
|
888
730
|
end
|
|
889
731
|
end
|
|
732
|
+
|
|
733
|
+
context "when attribute has an aliased name" do
|
|
734
|
+
|
|
735
|
+
let(:person) do
|
|
736
|
+
Person.new
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
before(:each) do
|
|
740
|
+
person.write_attribute(:t, "aliased field to test")
|
|
741
|
+
end
|
|
742
|
+
|
|
743
|
+
it "returns the value of the aliased field" do
|
|
744
|
+
expect(person.read_attribute(:test)).to eq("aliased field to test")
|
|
745
|
+
end
|
|
746
|
+
end
|
|
890
747
|
end
|
|
891
748
|
|
|
892
749
|
describe "#read_attribute_before_type_cast" do
|
|
750
|
+
|
|
893
751
|
let(:person) do
|
|
894
752
|
Person.create
|
|
895
753
|
end
|
|
@@ -897,7 +755,7 @@ describe Mongoid::Attributes do
|
|
|
897
755
|
context "when the attribute has not yet been assigned" do
|
|
898
756
|
|
|
899
757
|
it "returns the default value" do
|
|
900
|
-
person.age_before_type_cast.
|
|
758
|
+
expect(person.age_before_type_cast).to eq(100)
|
|
901
759
|
end
|
|
902
760
|
end
|
|
903
761
|
|
|
@@ -905,12 +763,11 @@ describe Mongoid::Attributes do
|
|
|
905
763
|
|
|
906
764
|
it "returns the default value" do
|
|
907
765
|
person.age = "old"
|
|
908
|
-
person.age_before_type_cast.
|
|
766
|
+
expect(person.age_before_type_cast).to eq("old")
|
|
909
767
|
end
|
|
910
768
|
end
|
|
911
769
|
end
|
|
912
770
|
|
|
913
|
-
|
|
914
771
|
describe "#attribute_present?" do
|
|
915
772
|
|
|
916
773
|
context "when document is a new record" do
|
|
@@ -922,7 +779,7 @@ describe Mongoid::Attributes do
|
|
|
922
779
|
context "when attribute does not exist" do
|
|
923
780
|
|
|
924
781
|
it "returns false" do
|
|
925
|
-
person.attribute_present?(:owner_id).
|
|
782
|
+
expect(person.attribute_present?(:owner_id)).to be false
|
|
926
783
|
end
|
|
927
784
|
end
|
|
928
785
|
|
|
@@ -932,7 +789,7 @@ describe Mongoid::Attributes do
|
|
|
932
789
|
end
|
|
933
790
|
|
|
934
791
|
it "returns true" do
|
|
935
|
-
person.attribute_present?(:owner_id).
|
|
792
|
+
expect(person.attribute_present?(:owner_id)).to be true
|
|
936
793
|
end
|
|
937
794
|
end
|
|
938
795
|
end
|
|
@@ -955,7 +812,7 @@ describe Mongoid::Attributes do
|
|
|
955
812
|
end
|
|
956
813
|
|
|
957
814
|
it "returns true" do
|
|
958
|
-
person.attribute_present?(:age).
|
|
815
|
+
expect(person.attribute_present?(:age)).to be true
|
|
959
816
|
end
|
|
960
817
|
end
|
|
961
818
|
end
|
|
@@ -972,7 +829,7 @@ describe Mongoid::Attributes do
|
|
|
972
829
|
|
|
973
830
|
it "return true" do
|
|
974
831
|
person.terms = false
|
|
975
|
-
person.attribute_present?(:terms).
|
|
832
|
+
expect(person.attribute_present?(:terms)).to be true
|
|
976
833
|
end
|
|
977
834
|
end
|
|
978
835
|
|
|
@@ -980,7 +837,7 @@ describe Mongoid::Attributes do
|
|
|
980
837
|
|
|
981
838
|
it "return true" do
|
|
982
839
|
person.terms = false
|
|
983
|
-
person.attribute_present?(:terms).
|
|
840
|
+
expect(person.attribute_present?(:terms)).to be true
|
|
984
841
|
end
|
|
985
842
|
end
|
|
986
843
|
end
|
|
@@ -993,7 +850,7 @@ describe Mongoid::Attributes do
|
|
|
993
850
|
end
|
|
994
851
|
|
|
995
852
|
it "return false" do
|
|
996
|
-
person.attribute_present?(:title).
|
|
853
|
+
expect(person.attribute_present?(:title)).to be false
|
|
997
854
|
end
|
|
998
855
|
end
|
|
999
856
|
end
|
|
@@ -1009,14 +866,14 @@ describe Mongoid::Attributes do
|
|
|
1009
866
|
context "when provided a symbol" do
|
|
1010
867
|
|
|
1011
868
|
it "returns true" do
|
|
1012
|
-
person.has_attribute?(:title).
|
|
869
|
+
expect(person.has_attribute?(:title)).to be true
|
|
1013
870
|
end
|
|
1014
871
|
end
|
|
1015
872
|
|
|
1016
873
|
context "when provided a string" do
|
|
1017
874
|
|
|
1018
875
|
it "returns true" do
|
|
1019
|
-
person.has_attribute?("title").
|
|
876
|
+
expect(person.has_attribute?("title")).to be true
|
|
1020
877
|
end
|
|
1021
878
|
end
|
|
1022
879
|
end
|
|
@@ -1024,7 +881,7 @@ describe Mongoid::Attributes do
|
|
|
1024
881
|
context "when the key is not in the attributes" do
|
|
1025
882
|
|
|
1026
883
|
it "returns false" do
|
|
1027
|
-
person.has_attribute?(:employer_id).
|
|
884
|
+
expect(person.has_attribute?(:employer_id)).to be false
|
|
1028
885
|
end
|
|
1029
886
|
end
|
|
1030
887
|
end
|
|
@@ -1038,7 +895,7 @@ describe Mongoid::Attributes do
|
|
|
1038
895
|
context "before the attribute has been assigned" do
|
|
1039
896
|
|
|
1040
897
|
it "returns false" do
|
|
1041
|
-
person.has_attribute_before_type_cast?(:age).
|
|
898
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be false
|
|
1042
899
|
end
|
|
1043
900
|
end
|
|
1044
901
|
|
|
@@ -1046,7 +903,7 @@ describe Mongoid::Attributes do
|
|
|
1046
903
|
|
|
1047
904
|
it "returns true" do
|
|
1048
905
|
person.age = 'old'
|
|
1049
|
-
person.has_attribute_before_type_cast?(:age).
|
|
906
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be true
|
|
1050
907
|
end
|
|
1051
908
|
end
|
|
1052
909
|
end
|
|
@@ -1064,11 +921,11 @@ describe Mongoid::Attributes do
|
|
|
1064
921
|
end
|
|
1065
922
|
|
|
1066
923
|
it "removes the attribute" do
|
|
1067
|
-
person.title.
|
|
924
|
+
expect(person.title).to be_nil
|
|
1068
925
|
end
|
|
1069
926
|
|
|
1070
927
|
it "removes the key from the attributes hash" do
|
|
1071
|
-
person.has_attribute?(:title).
|
|
928
|
+
expect(person.has_attribute?(:title)).to be false
|
|
1072
929
|
end
|
|
1073
930
|
|
|
1074
931
|
context "when saving after the removal" do
|
|
@@ -1078,7 +935,7 @@ describe Mongoid::Attributes do
|
|
|
1078
935
|
end
|
|
1079
936
|
|
|
1080
937
|
it "persists the removal" do
|
|
1081
|
-
person.reload.has_attribute?(:title).
|
|
938
|
+
expect(person.reload.has_attribute?(:title)).to be false
|
|
1082
939
|
end
|
|
1083
940
|
end
|
|
1084
941
|
end
|
|
@@ -1099,11 +956,11 @@ describe Mongoid::Attributes do
|
|
|
1099
956
|
end
|
|
1100
957
|
|
|
1101
958
|
it "removes the attribute" do
|
|
1102
|
-
person.pet.name.
|
|
959
|
+
expect(person.pet.name).to be_nil
|
|
1103
960
|
end
|
|
1104
961
|
|
|
1105
962
|
it "removes the key from the attributes hash" do
|
|
1106
|
-
person.pet.has_attribute?(:name).
|
|
963
|
+
expect(person.pet.has_attribute?(:name)).to be false
|
|
1107
964
|
end
|
|
1108
965
|
|
|
1109
966
|
context "when saving after the removal" do
|
|
@@ -1113,7 +970,7 @@ describe Mongoid::Attributes do
|
|
|
1113
970
|
end
|
|
1114
971
|
|
|
1115
972
|
it "persists the removal" do
|
|
1116
|
-
person.reload.pet.has_attribute?(:name).
|
|
973
|
+
expect(person.reload.pet.has_attribute?(:name)).to be false
|
|
1117
974
|
end
|
|
1118
975
|
end
|
|
1119
976
|
|
|
@@ -1130,7 +987,7 @@ describe Mongoid::Attributes do
|
|
|
1130
987
|
end
|
|
1131
988
|
|
|
1132
989
|
it "does not fail" do
|
|
1133
|
-
person.title.
|
|
990
|
+
expect(person.title).to be_nil
|
|
1134
991
|
end
|
|
1135
992
|
end
|
|
1136
993
|
|
|
@@ -1145,7 +1002,7 @@ describe Mongoid::Attributes do
|
|
|
1145
1002
|
end
|
|
1146
1003
|
|
|
1147
1004
|
it "does not add a delayed unset operation" do
|
|
1148
|
-
person.delayed_atomic_unsets.
|
|
1005
|
+
expect(person.delayed_atomic_unsets).to be_empty
|
|
1149
1006
|
end
|
|
1150
1007
|
end
|
|
1151
1008
|
end
|
|
@@ -1158,10 +1015,6 @@ describe Mongoid::Attributes do
|
|
|
1158
1015
|
Person.new
|
|
1159
1016
|
end
|
|
1160
1017
|
|
|
1161
|
-
before(:all) do
|
|
1162
|
-
Mongoid.allow_dynamic_fields = true
|
|
1163
|
-
end
|
|
1164
|
-
|
|
1165
1018
|
context "when asking for the getter" do
|
|
1166
1019
|
|
|
1167
1020
|
context "when the attribute exists" do
|
|
@@ -1171,14 +1024,14 @@ describe Mongoid::Attributes do
|
|
|
1171
1024
|
end
|
|
1172
1025
|
|
|
1173
1026
|
it "returns true" do
|
|
1174
|
-
person.
|
|
1027
|
+
expect(person).to respond_to(:attr)
|
|
1175
1028
|
end
|
|
1176
1029
|
end
|
|
1177
1030
|
|
|
1178
1031
|
context "when the attribute does not exist" do
|
|
1179
1032
|
|
|
1180
1033
|
it "returns false" do
|
|
1181
|
-
person.
|
|
1034
|
+
expect(person).to_not respond_to(:attr)
|
|
1182
1035
|
end
|
|
1183
1036
|
end
|
|
1184
1037
|
end
|
|
@@ -1192,14 +1045,14 @@ describe Mongoid::Attributes do
|
|
|
1192
1045
|
end
|
|
1193
1046
|
|
|
1194
1047
|
it "returns true" do
|
|
1195
|
-
person.
|
|
1048
|
+
expect(person).to respond_to(:attr=)
|
|
1196
1049
|
end
|
|
1197
1050
|
end
|
|
1198
1051
|
|
|
1199
1052
|
context "when the attribute does not exist" do
|
|
1200
1053
|
|
|
1201
1054
|
it "returns false" do
|
|
1202
|
-
person.
|
|
1055
|
+
expect(person).to_not respond_to(:attr=)
|
|
1203
1056
|
end
|
|
1204
1057
|
end
|
|
1205
1058
|
end
|
|
@@ -1207,29 +1060,21 @@ describe Mongoid::Attributes do
|
|
|
1207
1060
|
|
|
1208
1061
|
context "when not allowing dynamic fields" do
|
|
1209
1062
|
|
|
1210
|
-
let(:
|
|
1211
|
-
|
|
1212
|
-
end
|
|
1213
|
-
|
|
1214
|
-
before(:all) do
|
|
1215
|
-
Mongoid.allow_dynamic_fields = false
|
|
1216
|
-
end
|
|
1217
|
-
|
|
1218
|
-
after(:all) do
|
|
1219
|
-
Mongoid.allow_dynamic_fields = true
|
|
1063
|
+
let(:bar) do
|
|
1064
|
+
Bar.new
|
|
1220
1065
|
end
|
|
1221
1066
|
|
|
1222
1067
|
context "when asking for the getter" do
|
|
1223
1068
|
|
|
1224
1069
|
it "returns false" do
|
|
1225
|
-
|
|
1070
|
+
expect(bar).to_not respond_to(:attr)
|
|
1226
1071
|
end
|
|
1227
1072
|
end
|
|
1228
1073
|
|
|
1229
1074
|
context "when asking for the setter" do
|
|
1230
1075
|
|
|
1231
1076
|
it "returns false" do
|
|
1232
|
-
|
|
1077
|
+
expect(bar).to_not respond_to(:attr=)
|
|
1233
1078
|
end
|
|
1234
1079
|
end
|
|
1235
1080
|
end
|
|
@@ -1244,7 +1089,7 @@ describe Mongoid::Attributes do
|
|
|
1244
1089
|
end
|
|
1245
1090
|
|
|
1246
1091
|
it "returns the default value" do
|
|
1247
|
-
person.age.
|
|
1092
|
+
expect(person.age).to eq(100)
|
|
1248
1093
|
end
|
|
1249
1094
|
end
|
|
1250
1095
|
|
|
@@ -1254,7 +1099,7 @@ describe Mongoid::Attributes do
|
|
|
1254
1099
|
end
|
|
1255
1100
|
|
|
1256
1101
|
it "should store the attribute before type cast" do
|
|
1257
|
-
person.age_before_type_cast.
|
|
1102
|
+
expect(person.age_before_type_cast).to eq("old")
|
|
1258
1103
|
end
|
|
1259
1104
|
end
|
|
1260
1105
|
|
|
@@ -1265,7 +1110,7 @@ describe Mongoid::Attributes do
|
|
|
1265
1110
|
end
|
|
1266
1111
|
|
|
1267
1112
|
it "does not use the default value" do
|
|
1268
|
-
person.age.
|
|
1113
|
+
expect(person.age).to be_nil
|
|
1269
1114
|
end
|
|
1270
1115
|
end
|
|
1271
1116
|
|
|
@@ -1280,7 +1125,7 @@ describe Mongoid::Attributes do
|
|
|
1280
1125
|
end
|
|
1281
1126
|
|
|
1282
1127
|
it "allows overwriting of the default value" do
|
|
1283
|
-
person.terms.
|
|
1128
|
+
expect(person.terms).to be true
|
|
1284
1129
|
end
|
|
1285
1130
|
end
|
|
1286
1131
|
|
|
@@ -1295,7 +1140,35 @@ describe Mongoid::Attributes do
|
|
|
1295
1140
|
end
|
|
1296
1141
|
|
|
1297
1142
|
it "allows the field name to be udpated" do
|
|
1298
|
-
person.t.
|
|
1143
|
+
expect(person.t).to eq("aliased field to test")
|
|
1144
|
+
end
|
|
1145
|
+
end
|
|
1146
|
+
|
|
1147
|
+
context "when attribute is a Hash" do
|
|
1148
|
+
let(:person) { Person.new map: { somekey: "somevalue" } }
|
|
1149
|
+
|
|
1150
|
+
it "raises an error when try to set an invalid value" do
|
|
1151
|
+
expect {
|
|
1152
|
+
person.map = []
|
|
1153
|
+
}.to raise_error(Mongoid::Errors::InvalidValue)
|
|
1154
|
+
end
|
|
1155
|
+
|
|
1156
|
+
it "can set a Hash value" do
|
|
1157
|
+
expect(person.map).to eq( { somekey: "somevalue" } )
|
|
1158
|
+
end
|
|
1159
|
+
end
|
|
1160
|
+
|
|
1161
|
+
context "when attribute is an Array" do
|
|
1162
|
+
let(:person) { Person.new aliases: [ :alias_1 ] }
|
|
1163
|
+
|
|
1164
|
+
it "can set an Array Value" do
|
|
1165
|
+
expect(person.aliases).to eq([ :alias_1 ])
|
|
1166
|
+
end
|
|
1167
|
+
|
|
1168
|
+
it "raises an error when try to set an invalid value" do
|
|
1169
|
+
expect {
|
|
1170
|
+
person.aliases = {}
|
|
1171
|
+
}.to raise_error(Mongoid::Errors::InvalidValue)
|
|
1299
1172
|
end
|
|
1300
1173
|
end
|
|
1301
1174
|
end
|
|
@@ -1316,11 +1189,11 @@ describe Mongoid::Attributes do
|
|
|
1316
1189
|
context "when the key has not been specified as a field" do
|
|
1317
1190
|
|
|
1318
1191
|
before do
|
|
1319
|
-
person.
|
|
1192
|
+
allow(person).to receive(:fields).and_return({})
|
|
1320
1193
|
end
|
|
1321
1194
|
|
|
1322
1195
|
it "returns the value" do
|
|
1323
|
-
person.send(:typed_value_for, "age", "51").
|
|
1196
|
+
person.send(:typed_value_for, "age", expect("51")).to eq("51")
|
|
1324
1197
|
end
|
|
1325
1198
|
end
|
|
1326
1199
|
end
|
|
@@ -1332,7 +1205,7 @@ describe Mongoid::Attributes do
|
|
|
1332
1205
|
end
|
|
1333
1206
|
|
|
1334
1207
|
it "typecasts proc values" do
|
|
1335
|
-
person.age.
|
|
1208
|
+
expect(person.age).to eq(100)
|
|
1336
1209
|
end
|
|
1337
1210
|
end
|
|
1338
1211
|
|
|
@@ -1351,7 +1224,7 @@ describe Mongoid::Attributes do
|
|
|
1351
1224
|
end
|
|
1352
1225
|
|
|
1353
1226
|
it "sets nested documents" do
|
|
1354
|
-
person.videos.first.title.
|
|
1227
|
+
expect(person.videos.first.title).to eq("Fight Club")
|
|
1355
1228
|
end
|
|
1356
1229
|
end
|
|
1357
1230
|
|
|
@@ -1372,7 +1245,7 @@ describe Mongoid::Attributes do
|
|
|
1372
1245
|
end
|
|
1373
1246
|
|
|
1374
1247
|
it "properly casts values" do
|
|
1375
|
-
person.age.
|
|
1248
|
+
expect(person.age).to eq(50)
|
|
1376
1249
|
end
|
|
1377
1250
|
end
|
|
1378
1251
|
|
|
@@ -1383,11 +1256,38 @@ describe Mongoid::Attributes do
|
|
|
1383
1256
|
end
|
|
1384
1257
|
|
|
1385
1258
|
it "does not set anything" do
|
|
1386
|
-
person.age.
|
|
1259
|
+
expect(person.age).to eq(100)
|
|
1387
1260
|
end
|
|
1388
1261
|
end
|
|
1389
1262
|
end
|
|
1390
1263
|
|
|
1264
|
+
context "copying from instance" do
|
|
1265
|
+
|
|
1266
|
+
let(:person) do
|
|
1267
|
+
Person.new
|
|
1268
|
+
end
|
|
1269
|
+
|
|
1270
|
+
let(:instance) do
|
|
1271
|
+
Person.new(attributes)
|
|
1272
|
+
end
|
|
1273
|
+
|
|
1274
|
+
let(:attributes) do
|
|
1275
|
+
{ age: 50, range: 1..100 }
|
|
1276
|
+
end
|
|
1277
|
+
|
|
1278
|
+
before do
|
|
1279
|
+
person.send(method, instance.attributes)
|
|
1280
|
+
end
|
|
1281
|
+
|
|
1282
|
+
it "properly copies values" do
|
|
1283
|
+
expect(person.age).to eq(50)
|
|
1284
|
+
end
|
|
1285
|
+
|
|
1286
|
+
it "properly copies ranges" do
|
|
1287
|
+
expect(person.range).to eq(1..100)
|
|
1288
|
+
end
|
|
1289
|
+
end
|
|
1290
|
+
|
|
1391
1291
|
context "on a parent document" do
|
|
1392
1292
|
|
|
1393
1293
|
context "when the parent has a has many through a has one" do
|
|
@@ -1411,8 +1311,8 @@ describe Mongoid::Attributes do
|
|
|
1411
1311
|
end
|
|
1412
1312
|
|
|
1413
1313
|
it "does not overwrite child attributes if not in the hash" do
|
|
1414
|
-
owner.pet.name.
|
|
1415
|
-
owner.pet.vet_visits.size.
|
|
1314
|
+
expect(owner.pet.name).to eq("Bingo")
|
|
1315
|
+
expect(owner.pet.vet_visits.size).to eq(1)
|
|
1416
1316
|
end
|
|
1417
1317
|
end
|
|
1418
1318
|
|
|
@@ -1436,11 +1336,11 @@ describe Mongoid::Attributes do
|
|
|
1436
1336
|
end
|
|
1437
1337
|
|
|
1438
1338
|
it "has 3 new entries" do
|
|
1439
|
-
pet.vet_visits.count.
|
|
1339
|
+
expect(pet.vet_visits.count).to eq(3)
|
|
1440
1340
|
end
|
|
1441
1341
|
|
|
1442
1342
|
it "persists the changes" do
|
|
1443
|
-
pet.reload.vet_visits.count.
|
|
1343
|
+
expect(pet.reload.vet_visits.count).to eq(3)
|
|
1444
1344
|
end
|
|
1445
1345
|
end
|
|
1446
1346
|
|
|
@@ -1478,7 +1378,7 @@ describe Mongoid::Attributes do
|
|
|
1478
1378
|
end
|
|
1479
1379
|
|
|
1480
1380
|
it "sets the child attributes on the parent" do
|
|
1481
|
-
name.attributes.
|
|
1381
|
+
expect(name.attributes).to eq(
|
|
1482
1382
|
{ "_id" => "Test-User", "first_name" => "Test2", "last_name" => "User2" }
|
|
1483
1383
|
)
|
|
1484
1384
|
end
|
|
@@ -1500,7 +1400,7 @@ describe Mongoid::Attributes do
|
|
|
1500
1400
|
end
|
|
1501
1401
|
|
|
1502
1402
|
it "updates the child attributes on the parent" do
|
|
1503
|
-
address.attributes.
|
|
1403
|
+
expect(address.attributes).to eq(
|
|
1504
1404
|
{ "_id" => "test", "street" => "Test2" }
|
|
1505
1405
|
)
|
|
1506
1406
|
end
|
|
@@ -1521,38 +1421,42 @@ describe Mongoid::Attributes do
|
|
|
1521
1421
|
product.cost = 500
|
|
1522
1422
|
end
|
|
1523
1423
|
|
|
1424
|
+
it "adds the alias for criteria" do
|
|
1425
|
+
expect(Product.where(cost: 500).selector).to eq("price" => 500)
|
|
1426
|
+
end
|
|
1427
|
+
|
|
1524
1428
|
it "aliases the getter" do
|
|
1525
|
-
product.cost.
|
|
1429
|
+
expect(product.cost).to eq(500)
|
|
1526
1430
|
end
|
|
1527
1431
|
|
|
1528
1432
|
it "aliases the existance check" do
|
|
1529
|
-
product.cost
|
|
1433
|
+
expect(product.cost?).to be true
|
|
1530
1434
|
end
|
|
1531
1435
|
|
|
1532
1436
|
it "aliases *_changed?" do
|
|
1533
|
-
product.cost_changed
|
|
1437
|
+
expect(product.cost_changed?).to be true
|
|
1534
1438
|
end
|
|
1535
1439
|
|
|
1536
1440
|
it "aliases *_change" do
|
|
1537
|
-
product.cost_change.
|
|
1441
|
+
expect(product.cost_change).to eq([ nil, 500 ])
|
|
1538
1442
|
end
|
|
1539
1443
|
|
|
1540
1444
|
it "aliases *_will_change!" do
|
|
1541
|
-
product.
|
|
1445
|
+
expect(product).to respond_to(:cost_will_change!)
|
|
1542
1446
|
end
|
|
1543
1447
|
|
|
1544
1448
|
it "aliases *_was" do
|
|
1545
|
-
product.cost_was.
|
|
1449
|
+
expect(product.cost_was).to be_nil
|
|
1546
1450
|
end
|
|
1547
1451
|
|
|
1548
1452
|
it "aliases reset_*!" do
|
|
1549
1453
|
product.reset_cost!
|
|
1550
|
-
product.cost.
|
|
1454
|
+
expect(product.cost).to be_nil
|
|
1551
1455
|
end
|
|
1552
1456
|
|
|
1553
1457
|
it "aliases *_before_type_cast" do
|
|
1554
1458
|
product.cost = "expensive"
|
|
1555
|
-
product.cost_before_type_cast.
|
|
1459
|
+
expect(product.cost_before_type_cast).to eq("expensive")
|
|
1556
1460
|
end
|
|
1557
1461
|
end
|
|
1558
1462
|
|
|
@@ -1563,32 +1467,32 @@ describe Mongoid::Attributes do
|
|
|
1563
1467
|
end
|
|
1564
1468
|
|
|
1565
1469
|
it "aliases the getter" do
|
|
1566
|
-
product.price.
|
|
1470
|
+
expect(product.price).to eq(500)
|
|
1567
1471
|
end
|
|
1568
1472
|
|
|
1569
1473
|
it "aliases the existance check" do
|
|
1570
|
-
product.price
|
|
1474
|
+
expect(product.price?).to be true
|
|
1571
1475
|
end
|
|
1572
1476
|
|
|
1573
1477
|
it "aliases *_changed?" do
|
|
1574
|
-
product.price_changed
|
|
1478
|
+
expect(product.price_changed?).to be true
|
|
1575
1479
|
end
|
|
1576
1480
|
|
|
1577
1481
|
it "aliases *_change" do
|
|
1578
|
-
product.price_change.
|
|
1482
|
+
expect(product.price_change).to eq([ nil, 500 ])
|
|
1579
1483
|
end
|
|
1580
1484
|
|
|
1581
1485
|
it "aliases *_will_change!" do
|
|
1582
|
-
product.
|
|
1486
|
+
expect(product).to respond_to(:price_will_change!)
|
|
1583
1487
|
end
|
|
1584
1488
|
|
|
1585
1489
|
it "aliases *_was" do
|
|
1586
|
-
product.price_was.
|
|
1490
|
+
expect(product.price_was).to be_nil
|
|
1587
1491
|
end
|
|
1588
1492
|
|
|
1589
1493
|
it "aliases reset_*!" do
|
|
1590
1494
|
product.reset_price!
|
|
1591
|
-
product.price.
|
|
1495
|
+
expect(product.price).to be_nil
|
|
1592
1496
|
end
|
|
1593
1497
|
end
|
|
1594
1498
|
end
|
|
@@ -1600,7 +1504,7 @@ describe Mongoid::Attributes do
|
|
|
1600
1504
|
end
|
|
1601
1505
|
|
|
1602
1506
|
it "has an entry in the attributes" do
|
|
1603
|
-
person.reload.attributes.
|
|
1507
|
+
expect(person.reload.attributes).to have_key("score")
|
|
1604
1508
|
end
|
|
1605
1509
|
end
|
|
1606
1510
|
|
|
@@ -1612,7 +1516,7 @@ describe Mongoid::Attributes do
|
|
|
1612
1516
|
|
|
1613
1517
|
it "saves the default" do
|
|
1614
1518
|
expect { person.save }.to_not raise_error
|
|
1615
|
-
person.last_drink_taken_at.
|
|
1519
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
|
1616
1520
|
end
|
|
1617
1521
|
end
|
|
1618
1522
|
|
|
@@ -1625,7 +1529,7 @@ describe Mongoid::Attributes do
|
|
|
1625
1529
|
end
|
|
1626
1530
|
|
|
1627
1531
|
it "applies the default value" do
|
|
1628
|
-
person.last_drink_taken_at.
|
|
1532
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
|
1629
1533
|
end
|
|
1630
1534
|
end
|
|
1631
1535
|
|
|
@@ -1642,7 +1546,7 @@ describe Mongoid::Attributes do
|
|
|
1642
1546
|
end
|
|
1643
1547
|
|
|
1644
1548
|
it "does not set the default" do
|
|
1645
|
-
from_db.age.
|
|
1549
|
+
expect(from_db.age).to eq(50)
|
|
1646
1550
|
end
|
|
1647
1551
|
end
|
|
1648
1552
|
|
|
@@ -1657,7 +1561,7 @@ describe Mongoid::Attributes do
|
|
|
1657
1561
|
end
|
|
1658
1562
|
|
|
1659
1563
|
it "does not set the default" do
|
|
1660
|
-
from_db.age.
|
|
1564
|
+
expect(from_db.age).to be_nil
|
|
1661
1565
|
end
|
|
1662
1566
|
end
|
|
1663
1567
|
|
|
@@ -1672,32 +1576,7 @@ describe Mongoid::Attributes do
|
|
|
1672
1576
|
end
|
|
1673
1577
|
|
|
1674
1578
|
it "applies the defaults after all attributes are set" do
|
|
1675
|
-
from_db.
|
|
1676
|
-
end
|
|
1677
|
-
end
|
|
1678
|
-
end
|
|
1679
|
-
end
|
|
1680
|
-
|
|
1681
|
-
context "when dynamic fields are not allowed" do
|
|
1682
|
-
|
|
1683
|
-
before do
|
|
1684
|
-
Mongoid.configure.allow_dynamic_fields = false
|
|
1685
|
-
end
|
|
1686
|
-
|
|
1687
|
-
after do
|
|
1688
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
1689
|
-
end
|
|
1690
|
-
|
|
1691
|
-
context "when an embedded document has been persisted" do
|
|
1692
|
-
|
|
1693
|
-
context "when the field is no longer recognized" do
|
|
1694
|
-
|
|
1695
|
-
before do
|
|
1696
|
-
Person.collection.insert 'pet' => { 'unrecognized_field' => true }
|
|
1697
|
-
end
|
|
1698
|
-
|
|
1699
|
-
it "allows access to the legacy data" do
|
|
1700
|
-
Person.first.pet.read_attribute(:unrecognized_field).should be_true
|
|
1579
|
+
expect(from_db).to be_balanced
|
|
1701
1580
|
end
|
|
1702
1581
|
end
|
|
1703
1582
|
end
|