Permalink
Browse files

Methods that return nil should not be considered YAML

  • Loading branch information...
1 parent 8e55afb commit 2cef2d411a20b89b71fb76876c33b331f94d0cc5 @jaw6 jaw6 committed Mar 3, 2011
@@ -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

0 comments on commit 2cef2d4

Please sign in to comment.