diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_with_zone_test.rb | 7 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 8 |
3 files changed, 10 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 9db6bbafca..bc4fb77f9c 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -317,9 +317,7 @@ module ActiveSupport # TODO: Preload instead of lazy load for thread safety def self.find_tzinfo(name) require 'tzinfo' unless defined?(::TZInfo) - ::TZInfo::Timezone.get(MAPPING[name] || name) - rescue TZInfo::InvalidTimezoneIdentifier - nil + ::TZInfo::TimezoneProxy.new(MAPPING[name] || name) end unless const_defined?(:ZONES) diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index d88f79ae4f..a808a25821 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -823,9 +823,12 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < Test::Unit::TestCase assert_equal(-18_000, Time.zone.utc_offset) end - def test_time_zone_setter_with_non_identifying_argument_returns_nil + def test_time_zone_setter_with_invalid_zone Time.zone = 'foo' - assert_equal nil, Time.zone + assert_not_nil Time.zone + assert_equal 'foo', Time.zone.name + assert_raise(TZInfo::InvalidTimezoneIdentifier) { Time.zone.utc_offset } + Time.zone = -15.hours assert_equal nil, Time.zone end diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 3b7fbb7808..516da7a14c 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -268,16 +268,16 @@ class TimeZoneTest < Test::Unit::TestCase end def test_index - assert_nil ActiveSupport::TimeZone["bogus"] + assert_not_nil ActiveSupport::TimeZone["bogus"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone["Central Time (US & Canada)"] assert_instance_of ActiveSupport::TimeZone, ActiveSupport::TimeZone[8] assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] } end - def test_unknown_zone_shouldnt_have_tzinfo_nor_utc_offset + def test_unknown_zone_should_have_tzinfo_but_exception_on_utc_offset zone = ActiveSupport::TimeZone.create("bogus") - assert_nil zone.tzinfo - assert_nil zone.utc_offset + assert_instance_of TZInfo::TimezoneProxy, zone.tzinfo + assert_raise(TZInfo::InvalidTimezoneIdentifier) { zone.utc_offset } end def test_unknown_zone_with_utc_offset |