Browse files

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...
2 parents 3a5a378 + fbf9965 commit 200708e7ed4928548bcd07b68e0ad8a60d8b6d86 @josevalim josevalim committed May 18, 2011
View
2 activemodel/lib/active_model/serializers/xml.rb
@@ -25,7 +25,7 @@ def initialize(name, serializable, raw_value=nil)
def decorations
decorations = {}
decorations[:encoding] = 'base64' if type == :binary
- decorations[:type] = type unless type == :string
+ decorations[:type] = (type == :string) ? nil : type
decorations[:nil] = true if value.nil?
decorations
end
View
8 activemodel/test/cases/serializers/xml_serialization_test.rb
@@ -92,7 +92,7 @@ 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
@@ -132,4 +132,10 @@ def setup
xml = @contact.to_xml(:procs => [ proc ])
assert_match %r{<name-reverse>kcats noraa</name-reverse>}, xml
end
+
+ test "should serialize string correctly when type passed" do
+ xml = @contact.to_xml :type => 'Contact'
+ assert_match %r{<contact type="Contact">}, xml
+ assert_match %r{<name>aaron stack</name>}, xml
+ end
end

0 comments on commit 200708e

Please sign in to comment.