diff options
author | Nikita Afanasenko <nikita@afanasenko.name> | 2012-10-31 00:14:16 +0400 |
---|---|---|
committer | Nikita Afanasenko <nafanasenko@spbtv.com> | 2012-10-31 13:16:44 +0400 |
commit | e7e59a75aad6c52b44cd97753b3dfce216833f1f (patch) | |
tree | 2881faff3383dc4207798cded01752ff397920f2 /activerecord/test/cases | |
parent | 85039d4b75ceb41a020e2cc8e3a0f39709b1fbc4 (diff) | |
download | rails-e7e59a75aad6c52b44cd97753b3dfce216833f1f.tar.gz rails-e7e59a75aad6c52b44cd97753b3dfce216833f1f.tar.bz2 rails-e7e59a75aad6c52b44cd97753b3dfce216833f1f.zip |
Fix `attributes_before_type_cast` for serialised attributes.
Public method `attributes_before_type_cast` used to return internal AR structure (ActiveRecord::AttributeMethods::Serialization::Attribute), patch fixes this. Now behaves like `read_attribute_before_type_cast` and returns unserialised values.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index f24ee54cd2..068f3cf3cd 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -56,11 +56,21 @@ class SerializedAttributeTest < ActiveRecord::TestCase def test_serialized_attribute_before_type_cast_returns_unserialized_value Topic.serialize :content, Hash - t = Topic.new(:content => { :foo => :bar }) - assert_equal({ :foo => :bar }, t.content_before_type_cast) + t = Topic.new(content: { foo: :bar }) + assert_equal({ foo: :bar }, t.content_before_type_cast) t.save! t.reload - assert_equal({ :foo => :bar }, t.content_before_type_cast) + assert_equal({ foo: :bar }, t.content_before_type_cast) + end + + def test_serialized_attributes_before_type_cast_returns_unserialized_value + Topic.serialize :content, Hash + + t = Topic.new(content: { foo: :bar }) + assert_equal({ foo: :bar }, t.attributes_before_type_cast["content"]) + t.save! + t.reload + assert_equal({ foo: :bar }, t.attributes_before_type_cast["content"]) end def test_serialized_attribute_calling_dup_method |