Skip to content

Commit

Permalink
nil in a serialized column should serialize to NULL, as it did in all…
Browse files Browse the repository at this point in the history
… previous versions of Rails
  • Loading branch information
willbryant committed Dec 17, 2011
1 parent df932c4 commit a074c09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/coders/yaml_column.rb
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1222,6 +1222,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
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/cases/coders/yaml_column_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit a074c09

Please sign in to comment.