aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/yaml_serialization_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-30 13:06:05 -0700
committerSean Griffin <sean@thoughtbot.com>2014-06-01 10:55:23 -0600
commit93734629a33591486b76e3b9884ea37650934eef (patch)
treedd4dd281a5db237c7e67ac01f1bfc0bbb725f98b /activerecord/test/cases/yaml_serialization_test.rb
parenta70b9ba62ed323347fe76be47afd80ee60729d9b (diff)
downloadrails-93734629a33591486b76e3b9884ea37650934eef.tar.gz
rails-93734629a33591486b76e3b9884ea37650934eef.tar.bz2
rails-93734629a33591486b76e3b9884ea37650934eef.zip
Don't change values in `@raw_attributes` during serialization
During `init_with`, the attributes given to the coder will be placed into `@raw_attributes`. As such, we should read from `@raw_attributes` when encoding, rather than `@attributes`, which has been type cast.
Diffstat (limited to 'activerecord/test/cases/yaml_serialization_test.rb')
-rw-r--r--activerecord/test/cases/yaml_serialization_test.rb19
1 files changed, 12 insertions, 7 deletions
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb
index 15815d56e4..f7af9a35cd 100644
--- a/activerecord/test/cases/yaml_serialization_test.rb
+++ b/activerecord/test/cases/yaml_serialization_test.rb
@@ -23,13 +23,6 @@ class YamlSerializationTest < ActiveRecord::TestCase
assert_equal({:omg=>:lol}, YAML.load(YAML.dump(topic)).content)
end
- def test_encode_with_coder
- topic = Topic.first
- coder = {}
- topic.encode_with coder
- assert_equal({'attributes' => topic.attributes}, coder)
- end
-
def test_psych_roundtrip
topic = Topic.first
assert topic
@@ -47,4 +40,16 @@ class YamlSerializationTest < ActiveRecord::TestCase
def test_active_record_relation_serialization
[Topic.all].to_yaml
end
+
+ def test_raw_types_are_not_changed_on_round_trip
+ topic = Topic.new(parent_id: "123")
+ assert_equal "123", topic.parent_id_before_type_cast
+ assert_equal "123", YAML.load(YAML.dump(topic)).parent_id_before_type_cast
+ end
+
+ def test_cast_types_are_not_changed_on_round_trip
+ topic = Topic.new(parent_id: "123")
+ assert_equal 123, topic.parent_id
+ assert_equal 123, YAML.load(YAML.dump(topic)).parent_id
+ end
end