1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/test/time_zone_test.rb
Jeremy Kemper 71234daef1 r4487@asus: jeremy | 2006-04-29 12:21:39 -0700
Check whether @flash is defined? for warnings-safety.
 r4488@asus:  jeremy | 2006-04-29 12:23:15 -0700
 Check whether @flash is defined? for warnings-safety. Obviates nil? check.
 r4489@asus:  jeremy | 2006-04-29 12:45:18 -0700
 Check whether @session is defined? for warnings-safety.
 r4490@asus:  jeremy | 2006-04-29 12:50:41 -0700
 Check whether @rendering_runtime is defined? for warnings-safety.
 r4491@asus:  jeremy | 2006-04-29 12:55:01 -0700
 Check whether @_cycles is defined? for warnings-safety.
 r4492@asus:  jeremy | 2006-04-29 12:59:19 -0700
 Check whether instance variables are defined? for warnings-safety.
 r4493@asus:  jeremy | 2006-04-29 13:14:09 -0700
 Add nil @template to PrototypeHelperTest to suppress unitialized instance variable warning.
 r4494@asus:  jeremy | 2006-04-29 13:31:34 -0700
 Check whether @auto_index defined? for warnings-safety.
 r4495@asus:  jeremy | 2006-04-29 13:32:24 -0700
 Wrap content_columns redefinitions with silence_warnings.
 r4496@asus:  jeremy | 2006-04-29 13:35:28 -0700
 Wrap more redefinitions with silence_warnings.
 r4829@asus:  jeremy | 2006-07-08 10:59:20 -0700
 abstract unit, fix warnings
 r4830@asus:  jeremy | 2006-07-08 11:06:12 -0700
 Use parens to silence warning.
 r4831@asus:  jeremy | 2006-07-08 11:06:48 -0700
 Use parens to silence warning.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4595 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2006-07-08 18:14:49 +00:00

91 lines
2.2 KiB
Ruby

require File.dirname(__FILE__) + '/abstract_unit'
class TimeZoneTest < Test::Unit::TestCase
class MockTime
def self.now
Time.utc( 2004, 7, 25, 14, 49, 00 )
end
def self.local(*args)
Time.utc(*args)
end
end
TimeZone::Time = MockTime
def test_formatted_offset_positive
zone = TimeZone.create( "Test", 4200 )
assert_equal "+01:10", zone.formatted_offset
end
def test_formatted_offset_negative
zone = TimeZone.create( "Test", -4200 )
assert_equal "-01:10", zone.formatted_offset
end
def test_now
zone = TimeZone.create( "Test", 4200 )
assert_equal Time.local(2004,7,25,15,59,00).to_a[0,6], zone.now.to_a[0,6]
end
def test_today
zone = TimeZone.create( "Test", 43200 )
assert_equal Date.new(2004,7,26), zone.today
end
def test_adjust_negative
zone = TimeZone.create( "Test", -4200 )
assert_equal Time.utc(2004,7,24,23,55,0), zone.adjust(Time.utc(2004,7,25,1,5,0))
end
def test_adjust_positive
zone = TimeZone.create( "Test", 4200 )
assert_equal Time.utc(2004,7,26,1,5,0), zone.adjust(Time.utc(2004,7,25,23,55,0))
end
def test_unadjust
zone = TimeZone.create( "Test", 4200 )
expect = Time.utc(2004,7,24,23,55,0).to_a[0,6]
actual = zone.unadjust(Time.utc(2004,7,25,1,5,0)).to_a[0,6]
assert_equal expect, actual
end
def test_zone_compare
zone1 = TimeZone.create( "Test1", 4200 )
zone2 = TimeZone.create( "Test1", 5600 )
assert zone1 < zone2
assert zone2 > zone1
zone1 = TimeZone.create( "Able", 10000 )
zone2 = TimeZone.create( "Zone", 10000 )
assert zone1 < zone2
assert zone2 > zone1
zone1 = TimeZone.create( "Able", 10000 )
assert zone1 == zone1
end
def test_to_s
zone = TimeZone.create( "Test", 4200 )
assert_equal "(GMT+01:10) Test", zone.to_s
end
def test_all_sorted
all = TimeZone.all
1.upto( all.length-1 ) do |i|
assert all[i-1] < all[i]
end
end
def test_index
assert_nil TimeZone["bogus"]
assert_not_nil TimeZone["Central Time (US & Canada)"]
end
def test_new
a = TimeZone.new("Berlin")
b = TimeZone.new("Berlin")
assert_same a, b
assert_nil TimeZone.new("bogus")
end
end