From 9c492885d178b1a3d0de2f710a8a276db3d867b2 Mon Sep 17 00:00:00 2001 From: Zuhao Wan Date: Wed, 18 Jun 2014 19:46:04 +0800 Subject: Extract out with_env_tz helper method. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s used at so many places that extracting it out into a helper file is worth doing. --- activesupport/test/time_zone_test_helpers.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 activesupport/test/time_zone_test_helpers.rb (limited to 'activesupport/test/time_zone_test_helpers.rb') 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 -- cgit v1.2.3