mongoid 3.1.7 → 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 +470 -9
- data/README.md +10 -7
- data/lib/config/locales/en.yml +34 -20
- 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 +3 -14
- 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 -99
- 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/memory.rb +2 -2
- data/lib/mongoid/contextual/aggregable/mongo.rb +5 -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/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 +39 -24
- 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 +15 -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} +35 -7
- 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 +1 -1
- data/lib/mongoid/{matchers → matchable}/nin.rb +3 -2
- data/lib/mongoid/{matchers → matchable}/or.rb +2 -2
- data/lib/mongoid/{matchers → matchable}/size.rb +1 -1
- data/lib/mongoid/matchable.rb +152 -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/persistable.rb +216 -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/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/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/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 +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/relations.rb +11 -25
- 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/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/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 +26 -172
- data/lib/mongoid/timestamps/updated/short.rb +2 -2
- data/lib/mongoid/{hierarchy.rb → traversable.rb} +15 -7
- 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/{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 +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/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/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 +334 -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 +46 -38
- data/spec/mongoid/contextual/atomic_spec.rb +59 -55
- 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 +713 -2419
- 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/{matchers → matchable}/ne_spec.rb +3 -3
- data/spec/mongoid/matchable/nin_spec.rb +48 -0
- data/spec/mongoid/{matchers → matchable}/or_spec.rb +6 -6
- data/spec/mongoid/{matchers → matchable}/size_spec.rb +3 -3
- data/spec/mongoid/{matchers_spec.rb → matchable_spec.rb} +41 -41
- data/spec/mongoid/persistable/creatable_spec.rb +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} +9 -9
- 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 -350
- data/spec/spec_helper.rb +26 -15
- metadata +262 -247
- 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/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/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,293 +210,66 @@ 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)
|
|
233
|
+
expect(person.terms).to be true
|
|
143
234
|
end
|
|
144
235
|
|
|
145
|
-
it "
|
|
146
|
-
|
|
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
|
|
236
|
+
it "returns the set value" do
|
|
237
|
+
expect(terms).to eq(true)
|
|
255
238
|
end
|
|
256
239
|
end
|
|
257
240
|
end
|
|
258
241
|
|
|
259
|
-
describe "
|
|
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
|
|
242
|
+
describe "#_id" do
|
|
288
243
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
end
|
|
244
|
+
let(:person) do
|
|
245
|
+
Person.new
|
|
292
246
|
end
|
|
293
247
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
let(:person) do
|
|
297
|
-
Person.new
|
|
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
|
|
248
|
+
it "delegates to #id" do
|
|
249
|
+
expect(person._id).to eq(person.id)
|
|
304
250
|
end
|
|
305
251
|
|
|
306
|
-
context "when
|
|
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
|
|
252
|
+
context "when #id alias is overridden" do
|
|
348
253
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
it "does not set the title field" do
|
|
354
|
-
item.title.should be_nil
|
|
355
|
-
end
|
|
254
|
+
let(:object) do
|
|
255
|
+
IdKey.new(key: 'foo')
|
|
356
256
|
end
|
|
357
257
|
|
|
358
|
-
|
|
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
|
|
258
|
+
it "delegates to another method" do
|
|
259
|
+
expect(object.id).to eq(object.key)
|
|
380
260
|
end
|
|
381
261
|
end
|
|
382
262
|
end
|
|
383
263
|
|
|
384
|
-
describe "#_id" do
|
|
385
|
-
|
|
386
|
-
let(:person) do
|
|
387
|
-
Person.new
|
|
388
|
-
end
|
|
389
|
-
|
|
390
|
-
it "delegates to #id" do
|
|
391
|
-
person._id.should eq(person.id)
|
|
392
|
-
end
|
|
393
|
-
end
|
|
394
|
-
|
|
395
264
|
describe "#_id=" do
|
|
396
265
|
|
|
397
266
|
after(:all) do
|
|
398
267
|
Person.field(
|
|
399
268
|
:_id,
|
|
400
|
-
type:
|
|
269
|
+
type: BSON::ObjectId,
|
|
401
270
|
pre_processed: true,
|
|
402
|
-
default: ->{
|
|
271
|
+
default: ->{ BSON::ObjectId.new },
|
|
272
|
+
overwrite: true
|
|
403
273
|
)
|
|
404
274
|
end
|
|
405
275
|
|
|
@@ -408,9 +278,10 @@ describe Mongoid::Attributes do
|
|
|
408
278
|
before(:all) do
|
|
409
279
|
Person.field(
|
|
410
280
|
:_id,
|
|
411
|
-
type:
|
|
281
|
+
type: BSON::ObjectId,
|
|
412
282
|
pre_processed: true,
|
|
413
|
-
default: ->{
|
|
283
|
+
default: ->{ BSON::ObjectId.new },
|
|
284
|
+
overwrite: true
|
|
414
285
|
)
|
|
415
286
|
end
|
|
416
287
|
|
|
@@ -419,7 +290,7 @@ describe Mongoid::Attributes do
|
|
|
419
290
|
end
|
|
420
291
|
|
|
421
292
|
let(:bson_id) do
|
|
422
|
-
|
|
293
|
+
BSON::ObjectId.new
|
|
423
294
|
end
|
|
424
295
|
|
|
425
296
|
context "when providing an object id" do
|
|
@@ -429,7 +300,7 @@ describe Mongoid::Attributes do
|
|
|
429
300
|
end
|
|
430
301
|
|
|
431
302
|
it "sets the id as the object id" do
|
|
432
|
-
person.id.
|
|
303
|
+
expect(person.id).to eq(bson_id)
|
|
433
304
|
end
|
|
434
305
|
end
|
|
435
306
|
|
|
@@ -440,7 +311,7 @@ describe Mongoid::Attributes do
|
|
|
440
311
|
end
|
|
441
312
|
|
|
442
313
|
it "sets the id as the object id" do
|
|
443
|
-
person.id.
|
|
314
|
+
expect(person.id).to eq(bson_id)
|
|
444
315
|
end
|
|
445
316
|
end
|
|
446
317
|
|
|
@@ -451,9 +322,22 @@ describe Mongoid::Attributes do
|
|
|
451
322
|
end
|
|
452
323
|
|
|
453
324
|
it "sets the id as the supplied value to_s" do
|
|
454
|
-
person.id.
|
|
325
|
+
expect(person.id).to eq(2)
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
context "when #id= alias is overridden" do
|
|
330
|
+
|
|
331
|
+
let(:object) do
|
|
332
|
+
IdKey.new(key: 'foo')
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
it "delegates to another method" do
|
|
336
|
+
object.id = 'bar'
|
|
337
|
+
expect(object.id).to eq('bar')
|
|
455
338
|
end
|
|
456
339
|
end
|
|
340
|
+
|
|
457
341
|
end
|
|
458
342
|
|
|
459
343
|
context "when using string ids" do
|
|
@@ -463,7 +347,8 @@ describe Mongoid::Attributes do
|
|
|
463
347
|
:_id,
|
|
464
348
|
type: String,
|
|
465
349
|
pre_processed: true,
|
|
466
|
-
default: ->{
|
|
350
|
+
default: ->{ BSON::ObjectId.new.to_s },
|
|
351
|
+
overwrite: true
|
|
467
352
|
)
|
|
468
353
|
end
|
|
469
354
|
|
|
@@ -472,7 +357,7 @@ describe Mongoid::Attributes do
|
|
|
472
357
|
end
|
|
473
358
|
|
|
474
359
|
let(:bson_id) do
|
|
475
|
-
|
|
360
|
+
BSON::ObjectId.new
|
|
476
361
|
end
|
|
477
362
|
|
|
478
363
|
context "when providing an object id" do
|
|
@@ -482,7 +367,7 @@ describe Mongoid::Attributes do
|
|
|
482
367
|
end
|
|
483
368
|
|
|
484
369
|
it "sets the id as the string of the object id" do
|
|
485
|
-
person.id.
|
|
370
|
+
expect(person.id).to eq(bson_id.to_s)
|
|
486
371
|
end
|
|
487
372
|
end
|
|
488
373
|
|
|
@@ -493,7 +378,7 @@ describe Mongoid::Attributes do
|
|
|
493
378
|
end
|
|
494
379
|
|
|
495
380
|
it "sets the id as the string" do
|
|
496
|
-
person.id.
|
|
381
|
+
expect(person.id).to eq(bson_id.to_s)
|
|
497
382
|
end
|
|
498
383
|
end
|
|
499
384
|
|
|
@@ -504,7 +389,7 @@ describe Mongoid::Attributes do
|
|
|
504
389
|
end
|
|
505
390
|
|
|
506
391
|
it "sets the id as the supplied value to_s" do
|
|
507
|
-
person.id.
|
|
392
|
+
expect(person.id).to eq("2")
|
|
508
393
|
end
|
|
509
394
|
end
|
|
510
395
|
end
|
|
@@ -512,7 +397,7 @@ describe Mongoid::Attributes do
|
|
|
512
397
|
context "when using integer ids" do
|
|
513
398
|
|
|
514
399
|
before(:all) do
|
|
515
|
-
Person.field(:_id, type: Integer)
|
|
400
|
+
Person.field(:_id, type: Integer, overwrite: true)
|
|
516
401
|
end
|
|
517
402
|
|
|
518
403
|
let(:person) do
|
|
@@ -526,7 +411,7 @@ describe Mongoid::Attributes do
|
|
|
526
411
|
end
|
|
527
412
|
|
|
528
413
|
it "sets the id as the integer" do
|
|
529
|
-
person.id.
|
|
414
|
+
expect(person.id).to eq(1)
|
|
530
415
|
end
|
|
531
416
|
end
|
|
532
417
|
|
|
@@ -537,7 +422,7 @@ describe Mongoid::Attributes do
|
|
|
537
422
|
end
|
|
538
423
|
|
|
539
424
|
it "sets the id as the supplied value" do
|
|
540
|
-
person.id.
|
|
425
|
+
expect(person.id).to eq(2)
|
|
541
426
|
end
|
|
542
427
|
end
|
|
543
428
|
end
|
|
@@ -553,27 +438,23 @@ describe Mongoid::Attributes do
|
|
|
553
438
|
Person.new(attributes)
|
|
554
439
|
end
|
|
555
440
|
|
|
556
|
-
before do
|
|
557
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
558
|
-
end
|
|
559
|
-
|
|
560
441
|
context "when an attribute exists" do
|
|
561
442
|
|
|
562
443
|
it "allows the getter" do
|
|
563
|
-
person.testing.
|
|
444
|
+
expect(person.testing).to eq("Testing")
|
|
564
445
|
end
|
|
565
446
|
|
|
566
447
|
it "allows the setter" do
|
|
567
448
|
person.testing = "Test"
|
|
568
|
-
person.testing.
|
|
449
|
+
expect(person.testing).to eq("Test")
|
|
569
450
|
end
|
|
570
451
|
|
|
571
452
|
it "allows the getter before_type_cast" do
|
|
572
|
-
person.testing_before_type_cast.
|
|
453
|
+
expect(person.testing_before_type_cast).to eq("Testing")
|
|
573
454
|
end
|
|
574
455
|
|
|
575
456
|
it "returns true for respond_to?" do
|
|
576
|
-
person.respond_to?(:testing).
|
|
457
|
+
expect(person.respond_to?(:testing)).to be true
|
|
577
458
|
end
|
|
578
459
|
end
|
|
579
460
|
|
|
@@ -588,28 +469,17 @@ describe Mongoid::Attributes do
|
|
|
588
469
|
end
|
|
589
470
|
|
|
590
471
|
it "mongoizes the dynamic field" do
|
|
591
|
-
person.new_years.
|
|
472
|
+
expect(person.new_years).to be_a(Time)
|
|
592
473
|
end
|
|
593
474
|
|
|
594
475
|
it "keeps the same value" do
|
|
595
|
-
person.new_years.
|
|
476
|
+
expect(person.new_years).to eq(new_years)
|
|
596
477
|
end
|
|
597
478
|
end
|
|
598
479
|
end
|
|
599
480
|
|
|
600
481
|
describe "#process" do
|
|
601
482
|
|
|
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
483
|
context "when attributes dont have fields defined" do
|
|
614
484
|
|
|
615
485
|
let(:attributes) do
|
|
@@ -626,43 +496,26 @@ describe Mongoid::Attributes do
|
|
|
626
496
|
Person.new(attributes)
|
|
627
497
|
end
|
|
628
498
|
|
|
629
|
-
before do
|
|
630
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
631
|
-
end
|
|
632
|
-
|
|
633
499
|
context "when attribute is a string" do
|
|
634
500
|
|
|
635
501
|
it "adds the string to the attributes" do
|
|
636
|
-
person.attributes["nofieldstring"].
|
|
502
|
+
expect(person.attributes["nofieldstring"]).to eq("Testing")
|
|
637
503
|
end
|
|
638
504
|
end
|
|
639
505
|
|
|
640
506
|
context "when attribute is not a string" do
|
|
641
507
|
|
|
642
508
|
it "adds a cast value to the attributes" do
|
|
643
|
-
person.attributes["nofieldint"].
|
|
509
|
+
expect(person.attributes["nofieldint"]).to eq(5)
|
|
644
510
|
end
|
|
645
511
|
end
|
|
646
512
|
end
|
|
647
513
|
|
|
648
514
|
context "when not allowing dynamic fields" do
|
|
649
515
|
|
|
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
|
|
516
|
+
it "raises an unknown attribute error on instantiation" do
|
|
664
517
|
expect {
|
|
665
|
-
|
|
518
|
+
Account.new({ anothernew: "Test" })
|
|
666
519
|
}.to raise_error(Mongoid::Errors::UnknownAttribute)
|
|
667
520
|
end
|
|
668
521
|
end
|
|
@@ -671,7 +524,7 @@ describe Mongoid::Attributes do
|
|
|
671
524
|
context "when supplied hash has string values" do
|
|
672
525
|
|
|
673
526
|
let(:bson_id) do
|
|
674
|
-
|
|
527
|
+
BSON::ObjectId.new
|
|
675
528
|
end
|
|
676
529
|
|
|
677
530
|
let!(:attributes) do
|
|
@@ -695,15 +548,15 @@ describe Mongoid::Attributes do
|
|
|
695
548
|
end
|
|
696
549
|
|
|
697
550
|
it "casts integers" do
|
|
698
|
-
person[:age].
|
|
551
|
+
expect(person[:age]).to eq(30)
|
|
699
552
|
end
|
|
700
553
|
|
|
701
554
|
it "casts booleans" do
|
|
702
|
-
person[:terms].
|
|
555
|
+
expect(person[:terms]).to be true
|
|
703
556
|
end
|
|
704
557
|
|
|
705
558
|
it "sets empty strings to nil" do
|
|
706
|
-
person[:score].
|
|
559
|
+
expect(person[:score]).to be_nil
|
|
707
560
|
end
|
|
708
561
|
end
|
|
709
562
|
|
|
@@ -724,7 +577,7 @@ describe Mongoid::Attributes do
|
|
|
724
577
|
end
|
|
725
578
|
|
|
726
579
|
it "sets the associations" do
|
|
727
|
-
person.name.
|
|
580
|
+
expect(person.name).to eq(name)
|
|
728
581
|
end
|
|
729
582
|
end
|
|
730
583
|
|
|
@@ -743,11 +596,11 @@ describe Mongoid::Attributes do
|
|
|
743
596
|
end
|
|
744
597
|
|
|
745
598
|
it "sets the parent association" do
|
|
746
|
-
person.game.
|
|
599
|
+
expect(person.game).to eq(game)
|
|
747
600
|
end
|
|
748
601
|
|
|
749
602
|
it "sets the inverse association" do
|
|
750
|
-
game.person.
|
|
603
|
+
expect(game.person).to eq(person)
|
|
751
604
|
end
|
|
752
605
|
end
|
|
753
606
|
|
|
@@ -762,7 +615,7 @@ describe Mongoid::Attributes do
|
|
|
762
615
|
end
|
|
763
616
|
|
|
764
617
|
it "sets the association" do
|
|
765
|
-
name.person.
|
|
618
|
+
expect(name.person).to eq(person)
|
|
766
619
|
end
|
|
767
620
|
end
|
|
768
621
|
end
|
|
@@ -782,7 +635,7 @@ describe Mongoid::Attributes do
|
|
|
782
635
|
end
|
|
783
636
|
|
|
784
637
|
it "calls the setter for the association" do
|
|
785
|
-
person.employer_id.
|
|
638
|
+
expect(person.employer_id).to eq("1")
|
|
786
639
|
end
|
|
787
640
|
end
|
|
788
641
|
|
|
@@ -797,7 +650,7 @@ describe Mongoid::Attributes do
|
|
|
797
650
|
end
|
|
798
651
|
|
|
799
652
|
it "sets the empty array" do
|
|
800
|
-
person.aliases.
|
|
653
|
+
expect(person.aliases).to be_empty
|
|
801
654
|
end
|
|
802
655
|
end
|
|
803
656
|
|
|
@@ -812,7 +665,20 @@ describe Mongoid::Attributes do
|
|
|
812
665
|
end
|
|
813
666
|
|
|
814
667
|
it "sets the empty hash" do
|
|
815
|
-
person.map.
|
|
668
|
+
expect(person.map).to eq({})
|
|
669
|
+
end
|
|
670
|
+
end
|
|
671
|
+
|
|
672
|
+
context "when providing tainted parameters" do
|
|
673
|
+
|
|
674
|
+
let(:params) do
|
|
675
|
+
ActionController::Parameters.new(title: "sir")
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
it "raises an error" do
|
|
679
|
+
expect {
|
|
680
|
+
Person.new(params)
|
|
681
|
+
}.to raise_error(ActiveModel::ForbiddenAttributesError)
|
|
816
682
|
end
|
|
817
683
|
end
|
|
818
684
|
end
|
|
@@ -832,7 +698,7 @@ describe Mongoid::Attributes do
|
|
|
832
698
|
end
|
|
833
699
|
|
|
834
700
|
it "only overwrites supplied attributes" do
|
|
835
|
-
person.title.
|
|
701
|
+
expect(person.title).to eq("Sir")
|
|
836
702
|
end
|
|
837
703
|
end
|
|
838
704
|
|
|
@@ -847,8 +713,8 @@ describe Mongoid::Attributes do
|
|
|
847
713
|
context "when attribute does not exist" do
|
|
848
714
|
|
|
849
715
|
it "returns the default value" do
|
|
850
|
-
person.age.
|
|
851
|
-
person.pets.
|
|
716
|
+
expect(person.age).to eq(100)
|
|
717
|
+
expect(person.pets).to be false
|
|
852
718
|
end
|
|
853
719
|
|
|
854
720
|
end
|
|
@@ -860,7 +726,7 @@ describe Mongoid::Attributes do
|
|
|
860
726
|
end
|
|
861
727
|
|
|
862
728
|
it "returns the value" do
|
|
863
|
-
person.read_attribute(:owner_id).
|
|
729
|
+
expect(person.read_attribute(:owner_id)).to eq(5)
|
|
864
730
|
end
|
|
865
731
|
end
|
|
866
732
|
end
|
|
@@ -883,7 +749,7 @@ describe Mongoid::Attributes do
|
|
|
883
749
|
end
|
|
884
750
|
|
|
885
751
|
it "returns the default value" do
|
|
886
|
-
person.age.
|
|
752
|
+
expect(person.age).to eq(100)
|
|
887
753
|
end
|
|
888
754
|
end
|
|
889
755
|
end
|
|
@@ -905,6 +771,7 @@ describe Mongoid::Attributes do
|
|
|
905
771
|
end
|
|
906
772
|
|
|
907
773
|
describe "#read_attribute_before_type_cast" do
|
|
774
|
+
|
|
908
775
|
let(:person) do
|
|
909
776
|
Person.create
|
|
910
777
|
end
|
|
@@ -912,7 +779,7 @@ describe Mongoid::Attributes do
|
|
|
912
779
|
context "when the attribute has not yet been assigned" do
|
|
913
780
|
|
|
914
781
|
it "returns the default value" do
|
|
915
|
-
person.age_before_type_cast.
|
|
782
|
+
expect(person.age_before_type_cast).to eq(100)
|
|
916
783
|
end
|
|
917
784
|
end
|
|
918
785
|
|
|
@@ -920,12 +787,11 @@ describe Mongoid::Attributes do
|
|
|
920
787
|
|
|
921
788
|
it "returns the default value" do
|
|
922
789
|
person.age = "old"
|
|
923
|
-
person.age_before_type_cast.
|
|
790
|
+
expect(person.age_before_type_cast).to eq("old")
|
|
924
791
|
end
|
|
925
792
|
end
|
|
926
793
|
end
|
|
927
794
|
|
|
928
|
-
|
|
929
795
|
describe "#attribute_present?" do
|
|
930
796
|
|
|
931
797
|
context "when document is a new record" do
|
|
@@ -937,7 +803,7 @@ describe Mongoid::Attributes do
|
|
|
937
803
|
context "when attribute does not exist" do
|
|
938
804
|
|
|
939
805
|
it "returns false" do
|
|
940
|
-
person.attribute_present?(:owner_id).
|
|
806
|
+
expect(person.attribute_present?(:owner_id)).to be false
|
|
941
807
|
end
|
|
942
808
|
end
|
|
943
809
|
|
|
@@ -947,7 +813,7 @@ describe Mongoid::Attributes do
|
|
|
947
813
|
end
|
|
948
814
|
|
|
949
815
|
it "returns true" do
|
|
950
|
-
person.attribute_present?(:owner_id).
|
|
816
|
+
expect(person.attribute_present?(:owner_id)).to be true
|
|
951
817
|
end
|
|
952
818
|
end
|
|
953
819
|
end
|
|
@@ -970,7 +836,7 @@ describe Mongoid::Attributes do
|
|
|
970
836
|
end
|
|
971
837
|
|
|
972
838
|
it "returns true" do
|
|
973
|
-
person.attribute_present?(:age).
|
|
839
|
+
expect(person.attribute_present?(:age)).to be true
|
|
974
840
|
end
|
|
975
841
|
end
|
|
976
842
|
end
|
|
@@ -987,7 +853,7 @@ describe Mongoid::Attributes do
|
|
|
987
853
|
|
|
988
854
|
it "return true" do
|
|
989
855
|
person.terms = false
|
|
990
|
-
person.attribute_present?(:terms).
|
|
856
|
+
expect(person.attribute_present?(:terms)).to be true
|
|
991
857
|
end
|
|
992
858
|
end
|
|
993
859
|
|
|
@@ -995,7 +861,7 @@ describe Mongoid::Attributes do
|
|
|
995
861
|
|
|
996
862
|
it "return true" do
|
|
997
863
|
person.terms = false
|
|
998
|
-
person.attribute_present?(:terms).
|
|
864
|
+
expect(person.attribute_present?(:terms)).to be true
|
|
999
865
|
end
|
|
1000
866
|
end
|
|
1001
867
|
end
|
|
@@ -1008,7 +874,19 @@ describe Mongoid::Attributes do
|
|
|
1008
874
|
end
|
|
1009
875
|
|
|
1010
876
|
it "return false" do
|
|
1011
|
-
person.attribute_present?(:title).
|
|
877
|
+
expect(person.attribute_present?(:title)).to be false
|
|
878
|
+
end
|
|
879
|
+
end
|
|
880
|
+
|
|
881
|
+
context "when the attribute is not on only list" do
|
|
882
|
+
|
|
883
|
+
before { Person.create }
|
|
884
|
+
let(:person) do
|
|
885
|
+
Person.only(:id).first
|
|
886
|
+
end
|
|
887
|
+
|
|
888
|
+
it "return false" do
|
|
889
|
+
expect(person.attribute_present?(:foobar)).to be false
|
|
1012
890
|
end
|
|
1013
891
|
end
|
|
1014
892
|
end
|
|
@@ -1024,14 +902,14 @@ describe Mongoid::Attributes do
|
|
|
1024
902
|
context "when provided a symbol" do
|
|
1025
903
|
|
|
1026
904
|
it "returns true" do
|
|
1027
|
-
person.has_attribute?(:title).
|
|
905
|
+
expect(person.has_attribute?(:title)).to be true
|
|
1028
906
|
end
|
|
1029
907
|
end
|
|
1030
908
|
|
|
1031
909
|
context "when provided a string" do
|
|
1032
910
|
|
|
1033
911
|
it "returns true" do
|
|
1034
|
-
person.has_attribute?("title").
|
|
912
|
+
expect(person.has_attribute?("title")).to be true
|
|
1035
913
|
end
|
|
1036
914
|
end
|
|
1037
915
|
end
|
|
@@ -1039,7 +917,7 @@ describe Mongoid::Attributes do
|
|
|
1039
917
|
context "when the key is not in the attributes" do
|
|
1040
918
|
|
|
1041
919
|
it "returns false" do
|
|
1042
|
-
person.has_attribute?(:employer_id).
|
|
920
|
+
expect(person.has_attribute?(:employer_id)).to be false
|
|
1043
921
|
end
|
|
1044
922
|
end
|
|
1045
923
|
end
|
|
@@ -1053,7 +931,7 @@ describe Mongoid::Attributes do
|
|
|
1053
931
|
context "before the attribute has been assigned" do
|
|
1054
932
|
|
|
1055
933
|
it "returns false" do
|
|
1056
|
-
person.has_attribute_before_type_cast?(:age).
|
|
934
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be false
|
|
1057
935
|
end
|
|
1058
936
|
end
|
|
1059
937
|
|
|
@@ -1061,7 +939,7 @@ describe Mongoid::Attributes do
|
|
|
1061
939
|
|
|
1062
940
|
it "returns true" do
|
|
1063
941
|
person.age = 'old'
|
|
1064
|
-
person.has_attribute_before_type_cast?(:age).
|
|
942
|
+
expect(person.has_attribute_before_type_cast?(:age)).to be true
|
|
1065
943
|
end
|
|
1066
944
|
end
|
|
1067
945
|
end
|
|
@@ -1079,11 +957,11 @@ describe Mongoid::Attributes do
|
|
|
1079
957
|
end
|
|
1080
958
|
|
|
1081
959
|
it "removes the attribute" do
|
|
1082
|
-
person.title.
|
|
960
|
+
expect(person.title).to be_nil
|
|
1083
961
|
end
|
|
1084
962
|
|
|
1085
963
|
it "removes the key from the attributes hash" do
|
|
1086
|
-
person.has_attribute?(:title).
|
|
964
|
+
expect(person.has_attribute?(:title)).to be false
|
|
1087
965
|
end
|
|
1088
966
|
|
|
1089
967
|
context "when saving after the removal" do
|
|
@@ -1093,7 +971,7 @@ describe Mongoid::Attributes do
|
|
|
1093
971
|
end
|
|
1094
972
|
|
|
1095
973
|
it "persists the removal" do
|
|
1096
|
-
person.reload.has_attribute?(:title).
|
|
974
|
+
expect(person.reload.has_attribute?(:title)).to be false
|
|
1097
975
|
end
|
|
1098
976
|
end
|
|
1099
977
|
end
|
|
@@ -1114,11 +992,11 @@ describe Mongoid::Attributes do
|
|
|
1114
992
|
end
|
|
1115
993
|
|
|
1116
994
|
it "removes the attribute" do
|
|
1117
|
-
person.pet.name.
|
|
995
|
+
expect(person.pet.name).to be_nil
|
|
1118
996
|
end
|
|
1119
997
|
|
|
1120
998
|
it "removes the key from the attributes hash" do
|
|
1121
|
-
person.pet.has_attribute?(:name).
|
|
999
|
+
expect(person.pet.has_attribute?(:name)).to be false
|
|
1122
1000
|
end
|
|
1123
1001
|
|
|
1124
1002
|
context "when saving after the removal" do
|
|
@@ -1128,7 +1006,7 @@ describe Mongoid::Attributes do
|
|
|
1128
1006
|
end
|
|
1129
1007
|
|
|
1130
1008
|
it "persists the removal" do
|
|
1131
|
-
person.reload.pet.has_attribute?(:name).
|
|
1009
|
+
expect(person.reload.pet.has_attribute?(:name)).to be false
|
|
1132
1010
|
end
|
|
1133
1011
|
end
|
|
1134
1012
|
|
|
@@ -1145,7 +1023,7 @@ describe Mongoid::Attributes do
|
|
|
1145
1023
|
end
|
|
1146
1024
|
|
|
1147
1025
|
it "does not fail" do
|
|
1148
|
-
person.title.
|
|
1026
|
+
expect(person.title).to be_nil
|
|
1149
1027
|
end
|
|
1150
1028
|
end
|
|
1151
1029
|
|
|
@@ -1160,7 +1038,7 @@ describe Mongoid::Attributes do
|
|
|
1160
1038
|
end
|
|
1161
1039
|
|
|
1162
1040
|
it "does not add a delayed unset operation" do
|
|
1163
|
-
person.delayed_atomic_unsets.
|
|
1041
|
+
expect(person.delayed_atomic_unsets).to be_empty
|
|
1164
1042
|
end
|
|
1165
1043
|
end
|
|
1166
1044
|
end
|
|
@@ -1173,10 +1051,6 @@ describe Mongoid::Attributes do
|
|
|
1173
1051
|
Person.new
|
|
1174
1052
|
end
|
|
1175
1053
|
|
|
1176
|
-
before(:all) do
|
|
1177
|
-
Mongoid.allow_dynamic_fields = true
|
|
1178
|
-
end
|
|
1179
|
-
|
|
1180
1054
|
context "when asking for the getter" do
|
|
1181
1055
|
|
|
1182
1056
|
context "when the attribute exists" do
|
|
@@ -1186,14 +1060,14 @@ describe Mongoid::Attributes do
|
|
|
1186
1060
|
end
|
|
1187
1061
|
|
|
1188
1062
|
it "returns true" do
|
|
1189
|
-
person.
|
|
1063
|
+
expect(person).to respond_to(:attr)
|
|
1190
1064
|
end
|
|
1191
1065
|
end
|
|
1192
1066
|
|
|
1193
1067
|
context "when the attribute does not exist" do
|
|
1194
1068
|
|
|
1195
1069
|
it "returns false" do
|
|
1196
|
-
person.
|
|
1070
|
+
expect(person).to_not respond_to(:attr)
|
|
1197
1071
|
end
|
|
1198
1072
|
end
|
|
1199
1073
|
end
|
|
@@ -1207,14 +1081,14 @@ describe Mongoid::Attributes do
|
|
|
1207
1081
|
end
|
|
1208
1082
|
|
|
1209
1083
|
it "returns true" do
|
|
1210
|
-
person.
|
|
1084
|
+
expect(person).to respond_to(:attr=)
|
|
1211
1085
|
end
|
|
1212
1086
|
end
|
|
1213
1087
|
|
|
1214
1088
|
context "when the attribute does not exist" do
|
|
1215
1089
|
|
|
1216
1090
|
it "returns false" do
|
|
1217
|
-
person.
|
|
1091
|
+
expect(person).to_not respond_to(:attr=)
|
|
1218
1092
|
end
|
|
1219
1093
|
end
|
|
1220
1094
|
end
|
|
@@ -1222,29 +1096,21 @@ describe Mongoid::Attributes do
|
|
|
1222
1096
|
|
|
1223
1097
|
context "when not allowing dynamic fields" do
|
|
1224
1098
|
|
|
1225
|
-
let(:
|
|
1226
|
-
|
|
1227
|
-
end
|
|
1228
|
-
|
|
1229
|
-
before(:all) do
|
|
1230
|
-
Mongoid.allow_dynamic_fields = false
|
|
1231
|
-
end
|
|
1232
|
-
|
|
1233
|
-
after(:all) do
|
|
1234
|
-
Mongoid.allow_dynamic_fields = true
|
|
1099
|
+
let(:bar) do
|
|
1100
|
+
Bar.new
|
|
1235
1101
|
end
|
|
1236
1102
|
|
|
1237
1103
|
context "when asking for the getter" do
|
|
1238
1104
|
|
|
1239
1105
|
it "returns false" do
|
|
1240
|
-
|
|
1106
|
+
expect(bar).to_not respond_to(:attr)
|
|
1241
1107
|
end
|
|
1242
1108
|
end
|
|
1243
1109
|
|
|
1244
1110
|
context "when asking for the setter" do
|
|
1245
1111
|
|
|
1246
1112
|
it "returns false" do
|
|
1247
|
-
|
|
1113
|
+
expect(bar).to_not respond_to(:attr=)
|
|
1248
1114
|
end
|
|
1249
1115
|
end
|
|
1250
1116
|
end
|
|
@@ -1259,7 +1125,7 @@ describe Mongoid::Attributes do
|
|
|
1259
1125
|
end
|
|
1260
1126
|
|
|
1261
1127
|
it "returns the default value" do
|
|
1262
|
-
person.age.
|
|
1128
|
+
expect(person.age).to eq(100)
|
|
1263
1129
|
end
|
|
1264
1130
|
end
|
|
1265
1131
|
|
|
@@ -1269,7 +1135,7 @@ describe Mongoid::Attributes do
|
|
|
1269
1135
|
end
|
|
1270
1136
|
|
|
1271
1137
|
it "should store the attribute before type cast" do
|
|
1272
|
-
person.age_before_type_cast.
|
|
1138
|
+
expect(person.age_before_type_cast).to eq("old")
|
|
1273
1139
|
end
|
|
1274
1140
|
end
|
|
1275
1141
|
|
|
@@ -1280,7 +1146,7 @@ describe Mongoid::Attributes do
|
|
|
1280
1146
|
end
|
|
1281
1147
|
|
|
1282
1148
|
it "does not use the default value" do
|
|
1283
|
-
person.age.
|
|
1149
|
+
expect(person.age).to be_nil
|
|
1284
1150
|
end
|
|
1285
1151
|
end
|
|
1286
1152
|
|
|
@@ -1295,7 +1161,7 @@ describe Mongoid::Attributes do
|
|
|
1295
1161
|
end
|
|
1296
1162
|
|
|
1297
1163
|
it "allows overwriting of the default value" do
|
|
1298
|
-
person.terms.
|
|
1164
|
+
expect(person.terms).to be true
|
|
1299
1165
|
end
|
|
1300
1166
|
end
|
|
1301
1167
|
|
|
@@ -1310,7 +1176,35 @@ describe Mongoid::Attributes do
|
|
|
1310
1176
|
end
|
|
1311
1177
|
|
|
1312
1178
|
it "allows the field name to be udpated" do
|
|
1313
|
-
person.t.
|
|
1179
|
+
expect(person.t).to eq("aliased field to test")
|
|
1180
|
+
end
|
|
1181
|
+
end
|
|
1182
|
+
|
|
1183
|
+
context "when attribute is a Hash" do
|
|
1184
|
+
let(:person) { Person.new map: { somekey: "somevalue" } }
|
|
1185
|
+
|
|
1186
|
+
it "raises an error when try to set an invalid value" do
|
|
1187
|
+
expect {
|
|
1188
|
+
person.map = []
|
|
1189
|
+
}.to raise_error(Mongoid::Errors::InvalidValue)
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
it "can set a Hash value" do
|
|
1193
|
+
expect(person.map).to eq( { somekey: "somevalue" } )
|
|
1194
|
+
end
|
|
1195
|
+
end
|
|
1196
|
+
|
|
1197
|
+
context "when attribute is an Array" do
|
|
1198
|
+
let(:person) { Person.new aliases: [ :alias_1 ] }
|
|
1199
|
+
|
|
1200
|
+
it "can set an Array Value" do
|
|
1201
|
+
expect(person.aliases).to eq([ :alias_1 ])
|
|
1202
|
+
end
|
|
1203
|
+
|
|
1204
|
+
it "raises an error when try to set an invalid value" do
|
|
1205
|
+
expect {
|
|
1206
|
+
person.aliases = {}
|
|
1207
|
+
}.to raise_error(Mongoid::Errors::InvalidValue)
|
|
1314
1208
|
end
|
|
1315
1209
|
end
|
|
1316
1210
|
end
|
|
@@ -1331,11 +1225,11 @@ describe Mongoid::Attributes do
|
|
|
1331
1225
|
context "when the key has not been specified as a field" do
|
|
1332
1226
|
|
|
1333
1227
|
before do
|
|
1334
|
-
person.
|
|
1228
|
+
allow(person).to receive(:fields).and_return({})
|
|
1335
1229
|
end
|
|
1336
1230
|
|
|
1337
1231
|
it "returns the value" do
|
|
1338
|
-
person.send(:typed_value_for, "age", "51").
|
|
1232
|
+
person.send(:typed_value_for, "age", expect("51")).to eq("51")
|
|
1339
1233
|
end
|
|
1340
1234
|
end
|
|
1341
1235
|
end
|
|
@@ -1347,7 +1241,7 @@ describe Mongoid::Attributes do
|
|
|
1347
1241
|
end
|
|
1348
1242
|
|
|
1349
1243
|
it "typecasts proc values" do
|
|
1350
|
-
person.age.
|
|
1244
|
+
expect(person.age).to eq(100)
|
|
1351
1245
|
end
|
|
1352
1246
|
end
|
|
1353
1247
|
|
|
@@ -1366,7 +1260,7 @@ describe Mongoid::Attributes do
|
|
|
1366
1260
|
end
|
|
1367
1261
|
|
|
1368
1262
|
it "sets nested documents" do
|
|
1369
|
-
person.videos.first.title.
|
|
1263
|
+
expect(person.videos.first.title).to eq("Fight Club")
|
|
1370
1264
|
end
|
|
1371
1265
|
end
|
|
1372
1266
|
|
|
@@ -1387,7 +1281,7 @@ describe Mongoid::Attributes do
|
|
|
1387
1281
|
end
|
|
1388
1282
|
|
|
1389
1283
|
it "properly casts values" do
|
|
1390
|
-
person.age.
|
|
1284
|
+
expect(person.age).to eq(50)
|
|
1391
1285
|
end
|
|
1392
1286
|
end
|
|
1393
1287
|
|
|
@@ -1398,11 +1292,38 @@ describe Mongoid::Attributes do
|
|
|
1398
1292
|
end
|
|
1399
1293
|
|
|
1400
1294
|
it "does not set anything" do
|
|
1401
|
-
person.age.
|
|
1295
|
+
expect(person.age).to eq(100)
|
|
1402
1296
|
end
|
|
1403
1297
|
end
|
|
1404
1298
|
end
|
|
1405
1299
|
|
|
1300
|
+
context "copying from instance" do
|
|
1301
|
+
|
|
1302
|
+
let(:person) do
|
|
1303
|
+
Person.new
|
|
1304
|
+
end
|
|
1305
|
+
|
|
1306
|
+
let(:instance) do
|
|
1307
|
+
Person.new(attributes)
|
|
1308
|
+
end
|
|
1309
|
+
|
|
1310
|
+
let(:attributes) do
|
|
1311
|
+
{ age: 50, range: 1..100 }
|
|
1312
|
+
end
|
|
1313
|
+
|
|
1314
|
+
before do
|
|
1315
|
+
person.send(method, instance.attributes)
|
|
1316
|
+
end
|
|
1317
|
+
|
|
1318
|
+
it "properly copies values" do
|
|
1319
|
+
expect(person.age).to eq(50)
|
|
1320
|
+
end
|
|
1321
|
+
|
|
1322
|
+
it "properly copies ranges" do
|
|
1323
|
+
expect(person.range).to eq(1..100)
|
|
1324
|
+
end
|
|
1325
|
+
end
|
|
1326
|
+
|
|
1406
1327
|
context "on a parent document" do
|
|
1407
1328
|
|
|
1408
1329
|
context "when the parent has a has many through a has one" do
|
|
@@ -1426,8 +1347,8 @@ describe Mongoid::Attributes do
|
|
|
1426
1347
|
end
|
|
1427
1348
|
|
|
1428
1349
|
it "does not overwrite child attributes if not in the hash" do
|
|
1429
|
-
owner.pet.name.
|
|
1430
|
-
owner.pet.vet_visits.size.
|
|
1350
|
+
expect(owner.pet.name).to eq("Bingo")
|
|
1351
|
+
expect(owner.pet.vet_visits.size).to eq(1)
|
|
1431
1352
|
end
|
|
1432
1353
|
end
|
|
1433
1354
|
|
|
@@ -1451,11 +1372,11 @@ describe Mongoid::Attributes do
|
|
|
1451
1372
|
end
|
|
1452
1373
|
|
|
1453
1374
|
it "has 3 new entries" do
|
|
1454
|
-
pet.vet_visits.count.
|
|
1375
|
+
expect(pet.vet_visits.count).to eq(3)
|
|
1455
1376
|
end
|
|
1456
1377
|
|
|
1457
1378
|
it "persists the changes" do
|
|
1458
|
-
pet.reload.vet_visits.count.
|
|
1379
|
+
expect(pet.reload.vet_visits.count).to eq(3)
|
|
1459
1380
|
end
|
|
1460
1381
|
end
|
|
1461
1382
|
|
|
@@ -1493,7 +1414,7 @@ describe Mongoid::Attributes do
|
|
|
1493
1414
|
end
|
|
1494
1415
|
|
|
1495
1416
|
it "sets the child attributes on the parent" do
|
|
1496
|
-
name.attributes.
|
|
1417
|
+
expect(name.attributes).to eq(
|
|
1497
1418
|
{ "_id" => "Test-User", "first_name" => "Test2", "last_name" => "User2" }
|
|
1498
1419
|
)
|
|
1499
1420
|
end
|
|
@@ -1515,7 +1436,7 @@ describe Mongoid::Attributes do
|
|
|
1515
1436
|
end
|
|
1516
1437
|
|
|
1517
1438
|
it "updates the child attributes on the parent" do
|
|
1518
|
-
address.attributes.
|
|
1439
|
+
expect(address.attributes).to eq(
|
|
1519
1440
|
{ "_id" => "test", "street" => "Test2" }
|
|
1520
1441
|
)
|
|
1521
1442
|
end
|
|
@@ -1536,38 +1457,42 @@ describe Mongoid::Attributes do
|
|
|
1536
1457
|
product.cost = 500
|
|
1537
1458
|
end
|
|
1538
1459
|
|
|
1460
|
+
it "adds the alias for criteria" do
|
|
1461
|
+
expect(Product.where(cost: 500).selector).to eq("price" => 500)
|
|
1462
|
+
end
|
|
1463
|
+
|
|
1539
1464
|
it "aliases the getter" do
|
|
1540
|
-
product.cost.
|
|
1465
|
+
expect(product.cost).to eq(500)
|
|
1541
1466
|
end
|
|
1542
1467
|
|
|
1543
1468
|
it "aliases the existance check" do
|
|
1544
|
-
product.cost
|
|
1469
|
+
expect(product.cost?).to be true
|
|
1545
1470
|
end
|
|
1546
1471
|
|
|
1547
1472
|
it "aliases *_changed?" do
|
|
1548
|
-
product.cost_changed
|
|
1473
|
+
expect(product.cost_changed?).to be true
|
|
1549
1474
|
end
|
|
1550
1475
|
|
|
1551
1476
|
it "aliases *_change" do
|
|
1552
|
-
product.cost_change.
|
|
1477
|
+
expect(product.cost_change).to eq([ nil, 500 ])
|
|
1553
1478
|
end
|
|
1554
1479
|
|
|
1555
1480
|
it "aliases *_will_change!" do
|
|
1556
|
-
product.
|
|
1481
|
+
expect(product).to respond_to(:cost_will_change!)
|
|
1557
1482
|
end
|
|
1558
1483
|
|
|
1559
1484
|
it "aliases *_was" do
|
|
1560
|
-
product.cost_was.
|
|
1485
|
+
expect(product.cost_was).to be_nil
|
|
1561
1486
|
end
|
|
1562
1487
|
|
|
1563
1488
|
it "aliases reset_*!" do
|
|
1564
1489
|
product.reset_cost!
|
|
1565
|
-
product.cost.
|
|
1490
|
+
expect(product.cost).to be_nil
|
|
1566
1491
|
end
|
|
1567
1492
|
|
|
1568
1493
|
it "aliases *_before_type_cast" do
|
|
1569
1494
|
product.cost = "expensive"
|
|
1570
|
-
product.cost_before_type_cast.
|
|
1495
|
+
expect(product.cost_before_type_cast).to eq("expensive")
|
|
1571
1496
|
end
|
|
1572
1497
|
end
|
|
1573
1498
|
|
|
@@ -1578,32 +1503,32 @@ describe Mongoid::Attributes do
|
|
|
1578
1503
|
end
|
|
1579
1504
|
|
|
1580
1505
|
it "aliases the getter" do
|
|
1581
|
-
product.price.
|
|
1506
|
+
expect(product.price).to eq(500)
|
|
1582
1507
|
end
|
|
1583
1508
|
|
|
1584
1509
|
it "aliases the existance check" do
|
|
1585
|
-
product.price
|
|
1510
|
+
expect(product.price?).to be true
|
|
1586
1511
|
end
|
|
1587
1512
|
|
|
1588
1513
|
it "aliases *_changed?" do
|
|
1589
|
-
product.price_changed
|
|
1514
|
+
expect(product.price_changed?).to be true
|
|
1590
1515
|
end
|
|
1591
1516
|
|
|
1592
1517
|
it "aliases *_change" do
|
|
1593
|
-
product.price_change.
|
|
1518
|
+
expect(product.price_change).to eq([ nil, 500 ])
|
|
1594
1519
|
end
|
|
1595
1520
|
|
|
1596
1521
|
it "aliases *_will_change!" do
|
|
1597
|
-
product.
|
|
1522
|
+
expect(product).to respond_to(:price_will_change!)
|
|
1598
1523
|
end
|
|
1599
1524
|
|
|
1600
1525
|
it "aliases *_was" do
|
|
1601
|
-
product.price_was.
|
|
1526
|
+
expect(product.price_was).to be_nil
|
|
1602
1527
|
end
|
|
1603
1528
|
|
|
1604
1529
|
it "aliases reset_*!" do
|
|
1605
1530
|
product.reset_price!
|
|
1606
|
-
product.price.
|
|
1531
|
+
expect(product.price).to be_nil
|
|
1607
1532
|
end
|
|
1608
1533
|
end
|
|
1609
1534
|
end
|
|
@@ -1615,7 +1540,7 @@ describe Mongoid::Attributes do
|
|
|
1615
1540
|
end
|
|
1616
1541
|
|
|
1617
1542
|
it "has an entry in the attributes" do
|
|
1618
|
-
person.reload.attributes.
|
|
1543
|
+
expect(person.reload.attributes).to have_key("score")
|
|
1619
1544
|
end
|
|
1620
1545
|
end
|
|
1621
1546
|
|
|
@@ -1627,7 +1552,7 @@ describe Mongoid::Attributes do
|
|
|
1627
1552
|
|
|
1628
1553
|
it "saves the default" do
|
|
1629
1554
|
expect { person.save }.to_not raise_error
|
|
1630
|
-
person.last_drink_taken_at.
|
|
1555
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
|
1631
1556
|
end
|
|
1632
1557
|
end
|
|
1633
1558
|
|
|
@@ -1640,7 +1565,7 @@ describe Mongoid::Attributes do
|
|
|
1640
1565
|
end
|
|
1641
1566
|
|
|
1642
1567
|
it "applies the default value" do
|
|
1643
|
-
person.last_drink_taken_at.
|
|
1568
|
+
expect(person.last_drink_taken_at).to eq(1.day.ago.in_time_zone("Alaska").to_date)
|
|
1644
1569
|
end
|
|
1645
1570
|
end
|
|
1646
1571
|
|
|
@@ -1657,7 +1582,7 @@ describe Mongoid::Attributes do
|
|
|
1657
1582
|
end
|
|
1658
1583
|
|
|
1659
1584
|
it "does not set the default" do
|
|
1660
|
-
from_db.age.
|
|
1585
|
+
expect(from_db.age).to eq(50)
|
|
1661
1586
|
end
|
|
1662
1587
|
end
|
|
1663
1588
|
|
|
@@ -1672,7 +1597,7 @@ describe Mongoid::Attributes do
|
|
|
1672
1597
|
end
|
|
1673
1598
|
|
|
1674
1599
|
it "does not set the default" do
|
|
1675
|
-
from_db.age.
|
|
1600
|
+
expect(from_db.age).to be_nil
|
|
1676
1601
|
end
|
|
1677
1602
|
end
|
|
1678
1603
|
|
|
@@ -1687,32 +1612,7 @@ describe Mongoid::Attributes do
|
|
|
1687
1612
|
end
|
|
1688
1613
|
|
|
1689
1614
|
it "applies the defaults after all attributes are set" do
|
|
1690
|
-
from_db.
|
|
1691
|
-
end
|
|
1692
|
-
end
|
|
1693
|
-
end
|
|
1694
|
-
end
|
|
1695
|
-
|
|
1696
|
-
context "when dynamic fields are not allowed" do
|
|
1697
|
-
|
|
1698
|
-
before do
|
|
1699
|
-
Mongoid.configure.allow_dynamic_fields = false
|
|
1700
|
-
end
|
|
1701
|
-
|
|
1702
|
-
after do
|
|
1703
|
-
Mongoid.configure.allow_dynamic_fields = true
|
|
1704
|
-
end
|
|
1705
|
-
|
|
1706
|
-
context "when an embedded document has been persisted" do
|
|
1707
|
-
|
|
1708
|
-
context "when the field is no longer recognized" do
|
|
1709
|
-
|
|
1710
|
-
before do
|
|
1711
|
-
Person.collection.insert 'pet' => { 'unrecognized_field' => true }
|
|
1712
|
-
end
|
|
1713
|
-
|
|
1714
|
-
it "allows access to the legacy data" do
|
|
1715
|
-
Person.first.pet.read_attribute(:unrecognized_field).should be_true
|
|
1615
|
+
expect(from_db).to be_balanced
|
|
1716
1616
|
end
|
|
1717
1617
|
end
|
|
1718
1618
|
end
|