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

Methods that return nil should not be considered YAML

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