diff options
author | Nikita Afanasenko <nikita@afanasenko.name> | 2012-10-31 00:14:16 +0400 |
---|---|---|
committer | Nikita Afanasenko <nafanasenko@spbtv.com> | 2012-11-09 11:53:55 +0400 |
commit | 8dbf5a4ddb1924b8460b166a29afb1265a1aaeff (patch) | |
tree | 1b4fbf2b97fc7819ac047998872544941fa119ab /activerecord/test/cases | |
parent | 90a5ec758dfb9698ecfd59bd08340ffecbda1d75 (diff) | |
download | rails-8dbf5a4ddb1924b8460b166a29afb1265a1aaeff.tar.gz rails-8dbf5a4ddb1924b8460b166a29afb1265a1aaeff.tar.bz2 rails-8dbf5a4ddb1924b8460b166a29afb1265a1aaeff.zip |
Backport #8078: 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/base_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 073e856e5e..d145486f64 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1293,6 +1293,16 @@ class BasicsTest < ActiveRecord::TestCase 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 klass = Class.new(ActiveRecord::Base) klass.table_name = "topics" |