Changeset 8547
- Timestamp:
- 01/03/08 21:33:40 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/tztime/lib/tz_time_helpers/active_record_methods.rb
r6523 r8547 24 24 def fix_timezone 25 25 tz_time_attributes.each do |attribute| 26 time = read_attribute(attribute) 27 fixed = (time.acts_like?(:time) || time.acts_like?(:date)) ? TzTime.at(time) : nil 28 write_attribute(attribute, fixed) 26 time = read_attribute(attribute) 27 if (time.acts_like?(:time) || time.acts_like?(:date)) && !time.utc? 28 write_attribute(attribute, Time.at(TzTime.zone.local_to_utc(time))) 29 end 29 30 end 30 31 end plugins/tztime/test/active_record_methods_test.rb
r6521 r8547 2 2 require 'rubygems' 3 3 require 'test/unit' 4 begin 5 require 'ruby-debug' 6 Debugger.start 7 rescue LoadError 8 # no debugger for you 9 end 4 10 5 11 class MockRecord 6 12 attr_writer :due_on 7 13 def self.before_validation(*args) nil end 14 15 def [](attribute) 16 read_attribute(attribute) 17 end 8 18 9 19 protected … … 29 39 def test_should_access_utc_time_as_local_with_getter_method 30 40 @record.due_on = Time.utc(2006, 1, 1) 31 assert_equal @record.due_on, TzTime.local(2005, 12, 31, 18)41 assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on 32 42 end 33 43 34 def test_should_fix_timezones 44 def test_should_fix_local_timezones 45 @record.due_on = Time.utc(2006, 1, 1) 46 assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on 47 @record.send :fix_timezone 48 assert_equal Time.utc(2006, 1, 1), @record[:due_on] 49 end 50 51 def test_should_not_fix_utc_timezones 35 52 @record.due_on = Time.utc(2006, 1, 1) 36 53 @record.send :fix_timezone 37 assert_equal @record.due_on, TzTime.local(2006, 1, 1)54 assert_equal Time.utc(2006, 1, 1), @record[:due_on] 38 55 end 39 56 end