diff options
author | Nick Rivadeneira <nicholas.rivadeneira@gmail.com> | 2017-06-22 10:35:40 -0400 |
---|---|---|
committer | Nick Rivadeneira <nicholas.rivadeneira@gmail.com> | 2017-06-22 10:37:36 -0400 |
commit | dbf8ab7f1db400473dd2ac8cd67fc9462f51bc15 (patch) | |
tree | d4640333bc492a560efade3a363d9734701f7914 | |
parent | 55a443b847ccf37aa8fb62fbc827f5b540980dd9 (diff) | |
download | rails-dbf8ab7f1db400473dd2ac8cd67fc9462f51bc15.tar.gz rails-dbf8ab7f1db400473dd2ac8cd67fc9462f51bc15.tar.bz2 rails-dbf8ab7f1db400473dd2ac8cd67fc9462f51bc15.zip |
Ensure `false` is preserved in attr serialization
-rw-r--r-- | activerecord/lib/active_record/attribute.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/yaml_serialization_test.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute.rb b/activerecord/lib/active_record/attribute.rb index 38281158d8..78662433eb 100644 --- a/activerecord/lib/active_record/attribute.rb +++ b/activerecord/lib/active_record/attribute.rb @@ -122,7 +122,7 @@ module ActiveRecord def encode_with(coder) coder["name"] = name - coder["value_before_type_cast"] = value_before_type_cast if value_before_type_cast + coder["value_before_type_cast"] = value_before_type_cast unless value_before_type_cast.nil? coder["type"] = type if type coder["original_attribute"] = original_attribute if original_attribute coder["value"] = value if defined?(@value) diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index bfc13d683d..dd8d2c1178 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -119,6 +119,14 @@ class YamlSerializationTest < ActiveRecord::TestCase assert_equal author.changes, dumped.changes end + def test_yaml_encoding_keeps_false_values + topic = Topic.first + topic.approved = false + dumped = YAML.load(YAML.dump(topic)) + + assert_equal false, dumped.approved + end + private def yaml_fixture(file_name) |