diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-05 14:23:01 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-07-05 14:34:13 -0700 |
commit | a03097759bd7103bb9db253e7ba095f011453f75 (patch) | |
tree | 4a20132e2c7fe66f25e7170ae751d3b67d92b3f5 /activerecord/test/cases/serialized_attribute_test.rb | |
parent | acec038b38dc248c5c2f350de69ab89d9b1402c7 (diff) | |
download | rails-a03097759bd7103bb9db253e7ba095f011453f75.tar.gz rails-a03097759bd7103bb9db253e7ba095f011453f75.tar.bz2 rails-a03097759bd7103bb9db253e7ba095f011453f75.zip |
Merge pull request #16059 from jenncoop/json-serialized-attr
Fixed issue with ActiveRecord serialize object as JSON
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/attribute_methods/serialization.rb
Diffstat (limited to 'activerecord/test/cases/serialized_attribute_test.rb')
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index 186a1a2ade..a8f667c732 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -3,10 +3,11 @@ require 'models/topic' require 'models/reply' require 'models/person' require 'models/traffic_light' +require 'models/post' require 'bcrypt' class SerializedAttributeTest < ActiveRecord::TestCase - fixtures :topics + fixtures :topics, :posts MyObject = Struct.new :attribute1, :attribute2 @@ -67,6 +68,19 @@ class SerializedAttributeTest < ActiveRecord::TestCase assert_equal(orig.content, clone.content) end + def test_serialized_json_attribute_returns_unserialized_value + Topic.serialize :content, JSON + my_post = posts(:welcome) + + t = Topic.new(content: my_post) + t.save! + t.reload + + assert_instance_of(Hash, t.content) + assert_equal(my_post.id, t.content["id"]) + assert_equal(my_post.title, t.content["title"]) + end + def test_serialized_attribute_declared_in_subclass hash = { 'important1' => 'value1', 'important2' => 'value2' } important_topic = ImportantTopic.create("important" => hash) |