Permalink
Browse files

Merge pull request #8853 from zmoazeni/3-0-xml-serialization-fix

Methods that return nil should not be considered YAML
  • Loading branch information...
2 parents ca8b0bd + 477f0e7 commit 583e5fd2089fdfe28b10e39c76fc698e0184f35b @carlosantoniodasilva carlosantoniodasilva committed Jan 9, 2013
View
@@ -1,3 +1,7 @@
+## Rails 3.0.20 (unreleased)
+
+* Fix XML serialization of methods that return nil to not be considered as YAML (GH #8853 and GH #492)
+
## Rails 3.0.18
## Rails 3.0.17 (Aug 9, 2012)
@@ -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
@@ -86,6 +86,10 @@ def setup
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
end
@@ -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 583e5fd

Please sign in to comment.