aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/serialized_attribute_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-07-15 08:43:18 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-07-15 08:43:18 -0700
commita66aeb84e215c8a6e365a7fd0197c5703a14f241 (patch)
treee7fc06a0499ba62d089fc36a4d5ea4a1d17e9e48 /activerecord/test/cases/serialized_attribute_test.rb
parentdffc6a43f4df05039693380c5cd2bd8762fb0382 (diff)
downloadrails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.tar.gz
rails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.tar.bz2
rails-a66aeb84e215c8a6e365a7fd0197c5703a14f241.zip
Revert "Revert "Merge pull request #16059 from jenncoop/json-serialized-attr""
This reverts commit 6f3c64eeb1dc8288dae49f114aaf619adc7dcb7f. Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test/cases/serialized_attribute_test.rb')
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb16
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)