diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 75c939f24f6324b02be3d4195ac3811f72b04296..eb6723bbf3db40170e4c5b6172522de884ab5c8e 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -357,10 +357,16 @@ def test_native_types # Test DateTime column and defaults, including timezone. # FIXME: moment of truth may be Time on 64-bit platforms. if bob.moment_of_truth.is_a?(DateTime) - assert_equal DateTime.local_offset, bob.moment_of_truth.offset - assert_not_equal 0, bob.moment_of_truth.offset - assert_not_equal "Z", bob.moment_of_truth.zone - assert_equal DateTime::ITALY, bob.moment_of_truth.start + + with_env_tz 'US/Eastern' do + assert_equal DateTime.local_offset, bob.moment_of_truth.offset + assert_not_equal 0, bob.moment_of_truth.offset + assert_not_equal "Z", bob.moment_of_truth.zone + # US/Eastern is -5 hours from GMT + assert_equal Rational(-5, 24), bob.moment_of_truth.offset + assert_equal "-05:00", bob.moment_of_truth.zone + assert_equal DateTime::ITALY, bob.moment_of_truth.start + end end assert_equal TrueClass, bob.male?.class @@ -960,6 +966,15 @@ def test_create_table_with_custom_sequence_name Person.connection.execute("select suitably_short_seq.nextval from dual") end end + + protected + 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 uses_mocha 'Sexy migration tests' do