Changeset 9058
- Timestamp:
- 03/18/08 22:31:19 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/tztime/lib/tz_time_helpers/active_record_methods.rb
r8815 r9058 19 19 end 20 20 end 21 end 22 23 define_method "#{attribute}=" do |local_time|24 fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil25 write_attribute(attribute, fixed)21 22 define_method "#{attribute}=" do |local_time| 23 fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil 24 write_attribute attribute, fixed 25 end 26 26 end 27 27 end plugins/tztime/test/active_record_methods_test.rb
r8815 r9058 35 35 TzTime.zone = TimeZone["Central Time (US & Canada)"] 36 36 @record = MockRecord.new 37 @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1)) 37 38 end 38 39 39 40 def test_should_access_utc_time_as_local_with_getter_method 40 @record.due_on = Time.utc(2006, 1, 1)41 41 assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on 42 42 end … … 44 44 def test_should_fix_local_timezones 45 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] 46 assert_equal TzTime.local(2006, 1, 1), @record.due_on 47 assert_equal TzTime.local(2006, 1, 1), @record[:due_on] 49 48 end 50 49 51 50 def test_should_not_fix_utc_timezones 52 @record.due_on = Time.utc(2006, 1, 1)53 @record.send :fix_timezone54 51 assert_equal Time.utc(2006, 1, 1), @record[:due_on] 55 52 end 56 57 53 def test_should_only_fix_timezones_that_have_been_written 58 @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1))59 @record.send :fix_timezone60 54 assert_equal TzTime.utc(2006, 1, 1), @record.due_on 61 55 end