Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8731

Show
Ignore:
Timestamp:
01/26/08 00:11:59 (9 months ago)
Author:
gbuesing
Message:

with_timezone test helper renamed with_env_tz, to distinguish between setting ENVTZ? and setting Time.zone in tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8730 r8731  
    11*SVN* 
     2 
     3* with_timezone test helper renamed with_env_tz, to distinguish between setting ENV['TZ'] and setting Time.zone in tests [Geoff Buesing] 
    24 
    35* Time#- coerces TimeWithZone argument to a Time instance so that difference in seconds can be calculated. Closes #10914 [Geoff Buesing, yyyc514] 
  • trunk/activesupport/test/core_ext/date_ext_test.rb

    r8563 r8731  
    176176   
    177177  def test_xmlschema 
    178     with_timezone 'US/Eastern' do 
     178    with_env_tz 'US/Eastern' do 
    179179      assert_match(/^1980-02-28T00:00:00-05:?00$/, Date.new(1980, 2, 28).xmlschema) 
    180180      assert_match(/^1980-06-28T00:00:00-04:?00$/, Date.new(1980, 6, 28).xmlschema) 
     
    188188 
    189189  protected 
    190     def with_timezone(new_tz = 'US/Eastern') 
     190    def with_env_tz(new_tz = 'US/Eastern') 
    191191      old_tz, ENV['TZ'] = ENV['TZ'], new_tz 
    192192      yield 
  • trunk/activesupport/test/core_ext/date_time_ext_test.rb

    r8720 r8731  
    213213 
    214214  def test_local_offset 
    215     with_timezone 'US/Eastern' do 
     215    with_env_tz 'US/Eastern' do 
    216216      assert_equal Rational(-5, 24), DateTime.local_offset 
    217217    end 
    218     with_timezone 'US/Central' do 
     218    with_env_tz 'US/Central' do 
    219219      assert_equal Rational(-6, 24), DateTime.local_offset 
    220220    end 
     
    274274 
    275275  protected 
    276     def with_timezone(new_tz = 'US/Eastern') 
     276    def with_env_tz(new_tz = 'US/Eastern') 
    277277      old_tz, ENV['TZ'] = ENV['TZ'], new_tz 
    278278      yield 
  • trunk/activesupport/test/core_ext/time_ext_test.rb

    r8730 r8731  
    1111 
    1212  def test_seconds_since_midnight_at_daylight_savings_time_start 
    13     with_timezone 'US/Eastern' do 
     13    with_env_tz 'US/Eastern' do 
    1414      # dt: US: 2005 April 3rd 2:00am ST => April 3rd 3:00am DT 
    1515      assert_equal 2*3600-1, Time.local(2005,4,3,1,59,59).seconds_since_midnight, 'just before DST start' 
     
    1717    end 
    1818 
    19     with_timezone 'NZ' do 
     19    with_env_tz 'NZ' do 
    2020      # dt: New Zealand: 2006 October 1st 2:00am ST => October 1st 3:00am DT 
    2121      assert_equal 2*3600-1, Time.local(2006,10,1,1,59,59).seconds_since_midnight, 'just before DST start' 
     
    2525 
    2626  def test_seconds_since_midnight_at_daylight_savings_time_end 
    27     with_timezone 'US/Eastern' do 
     27    with_env_tz 'US/Eastern' do 
    2828      # st: US: 2005 October 30th 2:00am DT => October 30th 1:00am ST 
    2929      # avoid setting a time between 1:00 and 2:00 since that requires specifying whether DST is active 
     
    3737    end 
    3838 
    39     with_timezone 'NZ' do 
     39    with_env_tz 'NZ' do 
    4040      # st: New Zealand: 2006 March 19th 3:00am DT => March 19th 2:00am ST 
    4141      # avoid setting a time between 2:00 and 3:00 since that requires specifying whether DST is active 
     
    6363  def test_beginning_of_day 
    6464    assert_equal Time.local(2005,2,4,0,0,0), Time.local(2005,2,4,10,10,10).beginning_of_day 
    65     with_timezone 'US/Eastern' do 
     65    with_env_tz 'US/Eastern' do 
    6666      assert_equal Time.local(2006,4,2,0,0,0), Time.local(2006,4,2,10,10,10).beginning_of_day, 'start DST' 
    6767      assert_equal Time.local(2006,10,29,0,0,0), Time.local(2006,10,29,10,10,10).beginning_of_day, 'ends DST' 
    6868    end 
    69     with_timezone 'NZ' do 
     69    with_env_tz 'NZ' do 
    7070      assert_equal Time.local(2006,3,19,0,0,0), Time.local(2006,3,19,10,10,10).beginning_of_day, 'ends DST' 
    7171      assert_equal Time.local(2006,10,1,0,0,0), Time.local(2006,10,1,10,10,10).beginning_of_day, 'start DST' 
     
    146146 
    147147  def test_daylight_savings_time_crossings_backward_start 
    148     with_timezone 'US/Eastern' do 
     148    with_env_tz 'US/Eastern' do 
    149149      # dt: US: 2005 April 3rd 4:18am 
    150150      assert_equal Time.local(2005,4,2,4,18,0), Time.local(2005,4,3,4,18,0).ago(86400), 'dt-1.day=>st' 
    151151      assert_equal Time.local(2005,4,1,4,18,0), Time.local(2005,4,2,4,18,0).ago(86400), 'st-1.day=>st' 
    152152    end 
    153     with_timezone 'NZ' do 
     153    with_env_tz 'NZ' do 
    154154      # dt: New Zealand: 2006 October 1st 4:18am 
    155155      assert_equal Time.local(2006,9,30,4,18,0), Time.local(2006,10,1,4,18,0).ago(86400), 'dt-1.day=>st' 
     
    159159 
    160160  def test_daylight_savings_time_crossings_backward_end 
    161     with_timezone 'US/Eastern' do 
     161    with_env_tz 'US/Eastern' do 
    162162      # st: US: 2005 October 30th 4:03am 
    163163      assert_equal Time.local(2005,10,29,4,3), Time.local(2005,10,30,4,3,0).ago(86400), 'st-1.day=>dt' 
    164164      assert_equal Time.local(2005,10,28,4,3), Time.local(2005,10,29,4,3,0).ago(86400), 'dt-1.day=>dt' 
    165165    end 
    166     with_timezone 'NZ' do 
     166    with_env_tz 'NZ' do 
    167167      # st: New Zealand: 2006 March 19th 4:03am 
    168168      assert_equal Time.local(2006,3,18,4,3), Time.local(2006,3,19,4,3,0).ago(86400), 'st-1.day=>dt' 
     
    181181 
    182182  def test_daylight_savings_time_crossings_forward_start 
    183     with_timezone 'US/Eastern' do 
     183    with_env_tz 'US/Eastern' do 
    184184      # st: US: 2005 April 2nd 7:27pm 
    185185      assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' 
    186186      assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' 
    187187    end 
    188     with_timezone 'NZ' do 
     188    with_env_tz 'NZ' do 
    189189      # st: New Zealand: 2006 September 30th 7:27pm 
    190190      assert_equal Time.local(2006,10,1,19,27,0), Time.local(2006,9,30,19,27,0).since(86400), 'st+1.day=>dt' 
     
    194194 
    195195  def test_daylight_savings_time_crossings_forward_end 
    196     with_timezone 'US/Eastern' do 
     196    with_env_tz 'US/Eastern' do 
    197197      # dt: US: 2005 October 30th 12:45am 
    198198      assert_equal Time.local(2005,10,31,0,45,0), Time.local(2005,10,30,0,45,0).since(86400), 'dt+1.day=>st' 
    199199      assert_equal Time.local(2005,11, 1,0,45,0), Time.local(2005,10,31,0,45,0).since(86400), 'st+1.day=>st' 
    200200    end 
    201     with_timezone 'NZ' do 
     201    with_env_tz 'NZ' do 
    202202      # dt: New Zealand: 2006 March 19th 1:45am 
    203203      assert_equal Time.local(2006,3,20,1,45,0), Time.local(2006,3,19,1,45,0).since(86400), 'dt+1.day=>st' 
     
    276276 
    277277  def test_next_week 
    278     with_timezone 'US/Eastern' do 
     278    with_env_tz 'US/Eastern' do 
    279279      assert_equal Time.local(2005,2,28), Time.local(2005,2,22,15,15,10).next_week 
    280280      assert_equal Time.local(2005,3,1), Time.local(2005,2,22,15,15,10).next_week(:tuesday) 
     
    286286 
    287287  def test_next_week_near_daylight_start 
    288     with_timezone 'US/Eastern' do 
     288    with_env_tz 'US/Eastern' do 
    289289      assert_equal Time.local(2006,4,3), Time.local(2006,4,2,23,1,0).next_week, 'just crossed standard => daylight' 
    290290    end 
    291     with_timezone 'NZ' do 
     291    with_env_tz 'NZ' do 
    292292      assert_equal Time.local(2006,10,2), Time.local(2006,10,1,23,1,0).next_week, 'just crossed standard => daylight' 
    293293    end 
     
    295295 
    296296  def test_next_week_near_daylight_end 
    297     with_timezone 'US/Eastern' do 
     297    with_env_tz 'US/Eastern' do 
    298298      assert_equal Time.local(2006,10,30), Time.local(2006,10,29,23,1,0).next_week, 'just crossed daylight => standard' 
    299299    end 
    300     with_timezone 'NZ' do 
     300    with_env_tz 'NZ' do 
    301301      assert_equal Time.local(2006,3,20), Time.local(2006,3,19,23,1,0).next_week, 'just crossed daylight => standard' 
    302302    end 
     
    312312    assert_equal "February 21, 2005 17:44",         time.to_s(:long) 
    313313    assert_equal "February 21st, 2005 17:44",       time.to_s(:long_ordinal) 
    314     with_timezone "UTC" do  
     314    with_env_tz "UTC" do  
    315315      assert_equal "Mon, 21 Feb 2005 17:44:30 +0000", time.to_s(:rfc822) 
    316316    end 
     
    329329  def test_to_datetime 
    330330    assert_equal Time.utc(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, 0, 0) 
    331     with_timezone 'US/Eastern' do 
     331    with_env_tz 'US/Eastern' do 
    332332      assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) 
    333333    end 
    334     with_timezone 'NZ' do 
     334    with_env_tz 'NZ' do 
    335335      assert_equal Time.local(2005, 2, 21, 17, 44, 30).to_datetime, DateTime.civil(2005, 2, 21, 17, 44, 30, Rational(Time.local(2005, 2, 21, 17, 44, 30).utc_offset, 86400), 0) 
    336336    end 
     
    430430   
    431431  def test_formatted_offset_with_local 
    432     with_timezone 'US/Eastern' do 
     432    with_env_tz 'US/Eastern' do 
    433433      assert_equal '-05:00', Time.local(2000).formatted_offset 
    434434      assert_equal '-0500', Time.local(2000).formatted_offset(false) 
     
    461461 
    462462  protected 
    463     def with_timezone(new_tz = 'US/Eastern') 
     463    def with_env_tz(new_tz = 'US/Eastern') 
    464464      old_tz, ENV['TZ'] = ENV['TZ'], new_tz 
    465465      yield