Methods that return nil should not be considered YAML

This commit is contained in:
Joshua Wehner 2011-03-03 15:43:42 -05:00
parent 8e55afb453
commit 2cef2d411a
4 changed files with 10 additions and 4 deletions

@ -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