diff options
author | Mike Dvorkin <mike@dvorkin.net> | 2010-12-08 20:39:46 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-12-09 09:01:49 +0100 |
commit | f572a02b94ce85bb8db64e838aa159cf3ef4b1fa (patch) | |
tree | fd3151aaa4e99a442a7055ec463a5f30bc73989d /activerecord/test | |
parent | 07b0e59988beb1b29bdfadd02f0d015eae9191cf (diff) | |
download | rails-f572a02b94ce85bb8db64e838aa159cf3ef4b1fa.tar.gz rails-f572a02b94ce85bb8db64e838aa159cf3ef4b1fa.tar.bz2 rails-f572a02b94ce85bb8db64e838aa159cf3ef4b1fa.zip |
Take into account current time zone when serializing datetime values [#6096 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/xml_serialization_test.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/xml_serialization_test.rb b/activerecord/test/cases/xml_serialization_test.rb index b11b340e94..2003e25e35 100644 --- a/activerecord/test/cases/xml_serialization_test.rb +++ b/activerecord/test/cases/xml_serialization_test.rb @@ -4,6 +4,7 @@ require 'models/post' require 'models/author' require 'models/comment' require 'models/company_in_module' +require 'models/toy' class XmlSerializationTest < ActiveRecord::TestCase def test_should_serialize_default_root @@ -83,6 +84,26 @@ class DefaultXmlSerializationTest < ActiveRecord::TestCase end end +class DefaultXmlSerializationTimezoneTest < ActiveRecord::TestCase + def test_should_serialize_datetime_with_timezone + timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" + + toy = Toy.create(:name => 'Mickey', :updated_at => Time.utc(2006, 8, 1)) + assert_match %r{<updated-at type=\"datetime\">2006-07-31T17:00:00-07:00</updated-at>}, toy.to_xml + ensure + Time.zone = timezone + end + + def test_should_serialize_datetime_with_timezone_reloaded + timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" + + toy = Toy.create(:name => 'Minnie', :updated_at => Time.utc(2006, 8, 1)).reload + assert_match %r{<updated-at type=\"datetime\">2006-07-31T17:00:00-07:00</updated-at>}, toy.to_xml + ensure + Time.zone = timezone + end +end + class NilXmlSerializationTest < ActiveRecord::TestCase def setup @xml = Contact.new.to_xml(:root => 'xml_contact') |