diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-18 13:59:57 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-18 13:59:57 +0200 |
commit | 911b282cf0b8ffd988a009f09eca6c66ad398d10 (patch) | |
tree | acca4628d297adae6ab9b31894cb38a9da7823f7 /activesupport/test/time_zone_test_helpers.rb | |
parent | dccf6da66bf4a63971e1f12b98cb1bb1fe5a9015 (diff) | |
parent | 9c492885d178b1a3d0de2f710a8a276db3d867b2 (diff) | |
download | rails-911b282cf0b8ffd988a009f09eca6c66ad398d10.tar.gz rails-911b282cf0b8ffd988a009f09eca6c66ad398d10.tar.bz2 rails-911b282cf0b8ffd988a009f09eca6c66ad398d10.zip |
Merge pull request #15799 from zuhao/refactor_activesupport_time_zone_test_helpers
Extract out with_env_tz helper method.
Diffstat (limited to 'activesupport/test/time_zone_test_helpers.rb')
-rw-r--r-- | activesupport/test/time_zone_test_helpers.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activesupport/test/time_zone_test_helpers.rb b/activesupport/test/time_zone_test_helpers.rb new file mode 100644 index 0000000000..9632b89d09 --- /dev/null +++ b/activesupport/test/time_zone_test_helpers.rb @@ -0,0 +1,16 @@ +module TimeZoneTestHelpers + def with_tz_default(tz = nil) + old_tz = Time.zone + Time.zone = tz + yield + ensure + Time.zone = old_tz + end + + def with_env_tz(new_tz = 'US/Eastern') + old_tz, ENV['TZ'] = ENV['TZ'], new_tz + yield + ensure + old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') + end +end |