Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 97e9d8860b277e5ca9f4187c213ddd35d7f76e9b 1 parent 75faf54
@asanghi asanghi authored tenderlove committed
View
3  activerecord/lib/active_record/attribute_methods/read.rb
@@ -75,7 +75,8 @@ def define_read_method(symbol, attr_name, column)
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]).nil?
+ value = @attributes[attr_name]
+ unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
View
2  activerecord/lib/active_record/base.rb
@@ -1715,7 +1715,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
View
16 activerecord/test/cases/base_test.rb
@@ -984,6 +984,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)
Please sign in to comment.
Something went wrong with that request. Please try again.