Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Attributes with :string type should not be given the type passed in model. Closes #1058. #1131

Merged
merged 1 commit into from

3 participants

Josh Kalderimis José Valim Jim Herzberg
Josh Kalderimis

Hey Guys,

This is a fixed patch for #1058.

Enjoy,

Josh

José Valim josevalim merged commit 200708e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 18, 2011
  1. Jim Herzberg Josh Kalderimis

    Attributes with :string type should not be given the type passed in m…

    jimherz authored joshk committed
    …odel serialization options. Closes #1058
This page is out of date. Refresh to see the latest.
2  activemodel/lib/active_model/serializers/xml.rb
View
@@ -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
8 activemodel/test/cases/serializers/xml_serialization_test.rb
View
@@ -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
Something went wrong with that request. Please try again.