diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 16:46:46 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-03 16:46:46 +0000 |
commit | 9c172b29311452a0e8eed42dfca64dbb5b168a94 (patch) | |
tree | 772a80571e77842d22759b015f60798d136db1ad /activerecord/test | |
parent | de24ed9f2d582096fcc5b83984f187c2a094e83a (diff) | |
download | rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.tar.gz rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.tar.bz2 rails-9c172b29311452a0e8eed42dfca64dbb5b168a94.zip |
Fix #3837.
We also need to time zone convert time zone aware attributes when
accessed via read_attribute, not only when via direct access.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index a7cad329e8..cec5822acb 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -553,6 +553,17 @@ class AttributeMethodsTest < ActiveRecord::TestCase end end + def test_setting_time_zone_aware_read_attribute + utc_time = Time.utc(2008, 1, 1) + cst_time = utc_time.in_time_zone("Central Time (US & Canada)") + in_time_zone "Pacific Time (US & Canada)" do + record = @target.create(:written_on => cst_time).reload + assert_equal utc_time, record[:written_on] + assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record[:written_on].time_zone + assert_equal Time.utc(2007, 12, 31, 16), record[:written_on].time + end + end + def test_setting_time_zone_aware_attribute_with_string utc_time = Time.utc(2008, 1, 1) (-11..13).each do |timezone_offset| @@ -572,6 +583,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase record = @target.new record.written_on = ' ' assert_nil record.written_on + assert_nil record[:written_on] end end |