Skip to content
Browse files

[tz_time plugin] fix previous attempt at fixing #10058

  • Loading branch information...
1 parent be9d8cd commit c6729afb8c459217293ce1d50d5fc3600a4e90e3 @technoweenie technoweenie committed Mar 18, 2008
Showing with 8 additions and 14 deletions.
  1. +5 −5 lib/tz_time_helpers/active_record_methods.rb
  2. +3 −9 test/active_record_methods_test.rb
View
10 lib/tz_time_helpers/active_record_methods.rb
@@ -18,11 +18,11 @@ def tz_time_attributes(*attributes)
time
end
end
- end
-
- define_method "#{attribute}=" do |local_time|
- fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil
- write_attribute(attribute, fixed)
+
+ define_method "#{attribute}=" do |local_time|
+ fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil
+ write_attribute attribute, fixed
+ end
end
end
end
View
12 test/active_record_methods_test.rb
@@ -34,29 +34,23 @@ class ActiveRecordMethodsTest < Test::Unit::TestCase
def setup
TzTime.zone = TimeZone["Central Time (US & Canada)"]
@record = MockRecord.new
+ @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1))
end
def test_should_access_utc_time_as_local_with_getter_method
- @record.due_on = Time.utc(2006, 1, 1)
assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on
end
def test_should_fix_local_timezones
@record.due_on = Time.utc(2006, 1, 1)
- assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on
- @record.send :fix_timezone
- assert_equal Time.utc(2006, 1, 1), @record[:due_on]
+ assert_equal TzTime.local(2006, 1, 1), @record.due_on
+ assert_equal TzTime.local(2006, 1, 1), @record[:due_on]
end
def test_should_not_fix_utc_timezones
- @record.due_on = Time.utc(2006, 1, 1)
- @record.send :fix_timezone
assert_equal Time.utc(2006, 1, 1), @record[:due_on]
end
-
def test_should_only_fix_timezones_that_have_been_written
- @record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1))
- @record.send :fix_timezone
assert_equal TzTime.utc(2006, 1, 1), @record.due_on
end
end

0 comments on commit c6729af

Please sign in to comment.
Something went wrong with that request. Please try again.