Skip to content
This repository
Browse code

Merge pull request #1131 from joshk/active_model_xml_fix

Attributes with :string type should not be given the type passed in model. Closes #1058.
  • Loading branch information...
commit 200708e7ed4928548bcd07b68e0ad8a60d8b6d86 2 parents 3a5a378 + fbf9965
José Valim josevalim authored
2  activemodel/lib/active_model/serializers/xml.rb
@@ -25,7 +25,7 @@ def initialize(name, serializable, raw_value=nil)
25 25 def decorations
26 26 decorations = {}
27 27 decorations[:encoding] = 'base64' if type == :binary
28   - decorations[:type] = type unless type == :string
  28 + decorations[:type] = (type == :string) ? nil : type
29 29 decorations[:nil] = true if value.nil?
30 30 decorations
31 31 end
8 activemodel/test/cases/serializers/xml_serialization_test.rb
@@ -92,7 +92,7 @@ def setup
92 92 test "should serialize string" do
93 93 assert_match %r{<name>aaron stack</name>}, @contact.to_xml
94 94 end
95   -
  95 +
96 96 test "should serialize nil" do
97 97 assert_match %r{<pseudonyms nil=\"true\"></pseudonyms>}, @contact.to_xml(:methods => :pseudonyms)
98 98 end
@@ -132,4 +132,10 @@ def setup
132 132 xml = @contact.to_xml(:procs => [ proc ])
133 133 assert_match %r{<name-reverse>kcats noraa</name-reverse>}, xml
134 134 end
  135 +
  136 + test "should serialize string correctly when type passed" do
  137 + xml = @contact.to_xml :type => 'Contact'
  138 + assert_match %r{<contact type="Contact">}, xml
  139 + assert_match %r{<name>aaron stack</name>}, xml
  140 + end
135 141 end

0 comments on commit 200708e

Please sign in to comment.
Something went wrong with that request. Please try again.