提交 7a237d56 编写于 作者: A Aditya Sanghi 提交者: Aaron Patterson

Ensure that boolean false is properly serialized [#6079 state:resolved]

上级 285f4563
......@@ -85,7 +85,8 @@ def read_attribute(attr_name)
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
if value = @attributes[attr_name]
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
......
......@@ -1680,7 +1680,7 @@ def arel_attributes_values(include_primary_key = true, include_readonly_attribut
if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name))
value = read_attribute(name)
if value && self.class.serialized_attributes.key?(name)
if !value.nil? && self.class.serialized_attributes.key?(name)
value = YAML.dump value
end
attrs[self.class.arel_table[name]] = value
......
......@@ -997,6 +997,22 @@ def test_serialized_attribute_with_class_constraint
Topic.serialize(:content)
end
def test_serialized_boolean_value_true
Topic.serialize(:content)
topic = Topic.new(:content => true)
assert topic.save
topic = topic.reload
assert_equal topic.content, true
end
def test_serialized_boolean_value_false
Topic.serialize(:content)
topic = Topic.new(:content => false)
assert topic.save
topic = topic.reload
assert_equal topic.content, false
end
def test_quote
author_name = "\\ \001 ' \n \\n \""
topic = Topic.create('author_name' => author_name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册