Permalink
Browse files

nil in a serialized column should serialize to NULL, as it did in all…

… previous versions of Rails
  • Loading branch information...
1 parent 1b4e6ca commit 3fe1ee7dbb138a188bdcbe6f96819511a472bb78 @willbryant committed Dec 17, 2011
@@ -15,7 +15,7 @@ def initialize(object_class = Object)
end
def dump(obj)
- YAML.dump obj
+ YAML.dump obj unless obj.nil?
end
def load(yaml)
@@ -1288,6 +1288,13 @@ def test_serialized_string_attribute
assert_equal(myobj, topic.content)
end
+ def test_serialized_nil_attribute_is_null_in_database
+ myobj = nil
+ topic = Topic.create("content" => myobj).reload
+ assert_equal(myobj, topic.content)
+ assert Topic.where("content IS NULL").exists?(topic.id)
+ end
+
def test_nil_serialized_attribute_with_class_constraint
topic = Topic.new
assert_nil topic.content
@@ -19,6 +19,7 @@ def test_type_mismatch_on_different_classes
def test_nil_is_ok
coder = YAMLColumn.new
assert_nil coder.load "--- "
+ assert_nil coder.load nil
end
def test_returns_new_with_different_class

0 comments on commit 3fe1ee7

Please sign in to comment.