diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-22 16:25:40 -0600 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-26 06:45:57 -0300 |
commit | 14b1208dd313f643f72aa2d92874198342e9fe14 (patch) | |
tree | 82af9d0a1dbcaafb4061c50ffa6d1a595d339e95 /activerecord/test/cases/attribute_test.rb | |
parent | 2571c3f415ac0c6eacedbc199e31b1c77e7bacc4 (diff) | |
download | rails-14b1208dd313f643f72aa2d92874198342e9fe14.tar.gz rails-14b1208dd313f643f72aa2d92874198342e9fe14.tar.bz2 rails-14b1208dd313f643f72aa2d92874198342e9fe14.zip |
Encapsulate the creation of `Attribute` objects
This will make it less painful to add additional properties, which
should persist across writes, such as `name`.
Conflicts:
activerecord/lib/active_record/attribute_set.rb
Diffstat (limited to 'activerecord/test/cases/attribute_test.rb')
-rw-r--r-- | activerecord/test/cases/attribute_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_test.rb b/activerecord/test/cases/attribute_test.rb index 57dd2e9a5e..0adf9545b8 100644 --- a/activerecord/test/cases/attribute_test.rb +++ b/activerecord/test/cases/attribute_test.rb @@ -99,5 +99,31 @@ module ActiveRecord attribute = Attribute.from_database('a value', @type) attribute.dup end + + class MyType + def type_cast_from_user(value) + value + " from user" + end + + def type_cast_from_database(value) + value + " from database" + end + end + + test "with_value_from_user returns a new attribute with the value from the user" do + old = Attribute.from_database("old", MyType.new) + new = old.with_value_from_user("new") + + assert_equal "old from database", old.value + assert_equal "new from user", new.value + end + + test "with_value_from_database returns a new attribute with the value from the database" do + old = Attribute.from_user("old", MyType.new) + new = old.with_value_from_database("new") + + assert_equal "old from user", old.value + assert_equal "new from database", new.value + end end end |