Skip to content

Commit

Permalink
Merge pull request #29536 from nickrivadeneira/fix-yaml
Browse files Browse the repository at this point in the history
Ensure `false` is preserved in attr serialization
  • Loading branch information
matthewd authored and sgrif committed Aug 8, 2017
1 parent 27e0a38 commit cb5a586
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def init_with(coder)

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)
Expand Down
8 changes: 8 additions & 0 deletions activerecord/test/cases/yaml_serialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def test_yaml_encoding_keeps_mutations
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)
Expand Down

0 comments on commit cb5a586

Please sign in to comment.