diff options
author | Adam Meehan <adam.meehan@gmail.com> | 2011-03-01 22:18:46 +1100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-23 15:38:51 -0700 |
commit | c5908a86492271ca55a6f54ccfd62b521cdc47c9 (patch) | |
tree | 2ac01ddaca8102c0afb68cad0e7645f3a86f799a /activerecord/test | |
parent | 54c963c89b81cfc4fd7dcad6779e41c85d1180ce (diff) | |
download | rails-c5908a86492271ca55a6f54ccfd62b521cdc47c9.tar.gz rails-c5908a86492271ca55a6f54ccfd62b521cdc47c9.tar.bz2 rails-c5908a86492271ca55a6f54ccfd62b521cdc47c9.zip |
Fix before_type_cast for timezone aware attributes by caching converted value on write. Also remove read method reload arg on timezone attributes.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index dfacf58da8..d8638ee776 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -118,22 +118,18 @@ class AttributeMethodsTest < ActiveRecord::TestCase end def test_read_attributes_before_type_cast_on_datetime - developer = Developer.find(:first) - if current_adapter?(:Mysql2Adapter, :OracleAdapter) - # Mysql2 and Oracle adapters keep the value in Time instance - assert_equal developer.created_at.to_s(:db), developer.attributes_before_type_cast["created_at"].to_s(:db) - else - assert_equal developer.created_at.to_s(:db), developer.attributes_before_type_cast["created_at"].to_s + in_time_zone "Pacific Time (US & Canada)" do + record = @target.new + + record.written_on = "345643456" + assert_equal "345643456", record.written_on_before_type_cast + assert_equal nil, record.written_on + + record.written_on = "2009-10-11 12:13:14" + assert_equal "2009-10-11 12:13:14", record.written_on_before_type_cast + assert_equal Time.zone.parse("2009-10-11 12:13:14"), record.written_on + assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone end - - developer.created_at = "345643456" - - assert_equal developer.created_at_before_type_cast, "345643456" - assert_equal developer.created_at, nil - - developer.created_at = "2010-03-21 21:23:32" - assert_equal developer.created_at_before_type_cast, "2010-03-21 21:23:32" - assert_equal developer.created_at, Time.parse("2010-03-21 21:23:32") end def test_hash_content |