diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-23 12:56:16 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-23 12:56:16 +0000 |
commit | 6329daf5acc8f5f2f040cf46f33098fb21a622b5 (patch) | |
tree | 18a283acc12de9931c7f487e5afcfd5e7a71822d /activerecord/test | |
parent | 2bf29b3485151f819318437561bea8abebe9427b (diff) | |
download | rails-6329daf5acc8f5f2f040cf46f33098fb21a622b5.tar.gz rails-6329daf5acc8f5f2f040cf46f33098fb21a622b5.tar.bz2 rails-6329daf5acc8f5f2f040cf46f33098fb21a622b5.zip |
Added TimeZone as the first of a number of value objects that Active Record will start shipping to provide incentatives to use rich value objects using composed_of #688 [Jamis Buck]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@760 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/time_zone_test.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/activerecord/test/time_zone_test.rb b/activerecord/test/time_zone_test.rb new file mode 100644 index 0000000000..1fbfb95a62 --- /dev/null +++ b/activerecord/test/time_zone_test.rb @@ -0,0 +1,78 @@ +require 'test/unit' +require File.dirname(__FILE__)+'/../lib/active_record/values/time_zone' + +class TimeZoneTest < Test::Unit::TestCase + + class MockTime + def self.now + Time.utc( 2004, 7, 25, 14, 49, 00 ) + 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_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_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 |