提交 92306781 编写于 作者: J Jonathan del Strother 提交者: Pratik Naik

Use xmlschema when serializing TimeWithZones to xml [#2223 state:resolved]

When using Hash#to_xml, any TimeWithZone objects now use xmlschema (iso8601), rather than a simple TimeWithZone#to_s.
Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 d771e7d1
......@@ -24,11 +24,12 @@ def content_type
"Bignum" => "integer",
"BigDecimal" => "decimal",
"Float" => "float",
"TrueClass" => "boolean",
"FalseClass" => "boolean",
"Date" => "date",
"DateTime" => "datetime",
"Time" => "datetime",
"TrueClass" => "boolean",
"FalseClass" => "boolean"
"ActiveSupport::TimeWithZone" => "datetime"
} unless defined?(XML_TYPE_NAMES)
XML_FORMATTING = {
......
......@@ -497,6 +497,15 @@ def test_three_levels_with_array
assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>))
end
def test_timezoned_attributes
xml = {
:created_at => Time.utc(1999,2,2),
:local_created_at => Time.utc(1999,2,2).in_time_zone('Eastern Time (US & Canada)')
}.to_xml(@xml_options)
assert_match %r{<created-at type=\"datetime\">1999-02-02T00:00:00Z</created-at>}, xml
assert_match %r{<local-created-at type=\"datetime\">1999-02-01T19:00:00-05:00</local-created-at>}, xml
end
def test_single_record_from_xml
topic_xml = <<-EOT
<topic>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册