From 3aa26cfb1903c770c5b561be5e64b97388ee84c7 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Mon, 20 Oct 2014 09:12:35 +0100 Subject: Improve ActiveSupport::TimeWithZone conversion to YAML Previously when converting AS::TimeWithZone to YAML it would be output as a UTC timestamp. Whilst this preserves the time information accurately it loses the timezone information. This commit changes that so that it is saved along with the time information. It also provides nicer encoding of AS::TimeZone instances themselves which previously embedded all of the data from the TZInfo records. Fixes #9183. --- activesupport/test/time_zone_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activesupport/test/time_zone_test.rb') diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index ea90caa143..5e0474f449 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -487,4 +487,13 @@ class TimeZoneTest < ActiveSupport::TestCase assert ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Hawaii"]) assert !ActiveSupport::TimeZone.us_zones.include?(ActiveSupport::TimeZone["Kuala Lumpur"]) end + + def test_to_yaml + assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Pacific/Honolulu\n", ActiveSupport::TimeZone["Hawaii"].to_yaml) + assert_equal("--- !ruby/object:ActiveSupport::TimeZone\nname: Europe/London\n", ActiveSupport::TimeZone["Europe/London"].to_yaml) + end + + def test_yaml_load + assert_equal(ActiveSupport::TimeZone["Pacific/Honolulu"], YAML.load("--- !ruby/object:ActiveSupport::TimeZone\nname: Pacific/Honolulu\n")) + end end -- cgit v1.2.3