提交 2cef2d41 编写于 作者: J Joshua Wehner

Methods that return nil should not be considered YAML

上级 8e55afb4
......@@ -33,6 +33,7 @@ def decorations
protected
def compute_type
return if value.nil?
type = ActiveSupport::XmlMini::TYPE_NAMES[value.class.name]
type ||= :string if value.respond_to?(:to_str)
type ||= :yaml
......
......@@ -92,6 +92,10 @@ def setup
test "should serialize string" do
assert_match %r{<name>aaron stack</name>}, @contact.to_xml
end
test "should serialize nil" do
assert_match %r{<pseudonyms nil=\"true\"></pseudonyms>}, @contact.to_xml(:methods => :pseudonyms)
end
test "should serialize integer" do
assert_match %r{<age type="integer">25</age>}, @contact.to_xml
......
......@@ -16,6 +16,10 @@ def initialize(options = {})
options.each { |name, value| send("#{name}=", value) }
end
def pseudonyms
nil
end
def persisted?
id
end
......
......@@ -143,10 +143,7 @@ def test_should_serialize_boolean
end
def test_should_serialize_yaml
assert %r{<preferences(.*)></preferences>}.match(@xml)
attributes = $1
assert_match %r{type="yaml"}, attributes
assert_match %r{nil="true"}, attributes
assert_match %r{<preferences nil=\"true\"></preferences>}, @xml
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册