diff options
author | gbuesing <gbuesing@gmail.com> | 2008-05-18 11:48:33 -0500 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-05-18 11:48:33 -0500 |
commit | cee9297c9bd43ca8975dc7ca9b707a6aa94c275d (patch) | |
tree | c9ec24413cfd557c0ab0e2d15ab1877fb489e544 /activesupport/test | |
parent | cde9c09a524a21214ea9cd0f9ee4489e4d185af2 (diff) | |
download | rails-cee9297c9bd43ca8975dc7ca9b707a6aa94c275d.tar.gz rails-cee9297c9bd43ca8975dc7ca9b707a6aa94c275d.tar.bz2 rails-cee9297c9bd43ca8975dc7ca9b707a6aa94c275d.zip |
Hash.from_xml: datetime xml types overflow to Ruby DateTime class when out of range of Time. Adding tests for utc offsets
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 706e218abc..69028a123f 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -733,6 +733,44 @@ class HashToXmlTest < Test::Unit::TestCase assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))['person'] end + + def test_datetime_xml_type_with_utc_time + alert_xml = <<-XML + <alert> + <alert_at type="datetime">2008-02-10T15:30:45Z</alert_at> + </alert> + XML + alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + assert alert_at.utc? + assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at + end + + def test_datetime_xml_type_with_non_utc_time + alert_xml = <<-XML + <alert> + <alert_at type="datetime">2008-02-10T10:30:45-05:00</alert_at> + </alert> + XML + alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + assert alert_at.utc? + assert_equal Time.utc(2008, 2, 10, 15, 30, 45), alert_at + end + + def test_datetime_xml_type_with_far_future_date + alert_xml = <<-XML + <alert> + <alert_at type="datetime">2050-02-10T15:30:45Z</alert_at> + </alert> + XML + alert_at = Hash.from_xml(alert_xml)['alert']['alert_at'] + assert alert_at.utc? + assert_equal 2050, alert_at.year + assert_equal 2, alert_at.month + assert_equal 10, alert_at.day + assert_equal 15, alert_at.hour + assert_equal 30, alert_at.min + assert_equal 45, alert_at.sec + end end class QueryTest < Test::Unit::TestCase |