Skip to content

Commit

Permalink
[tz_time plugin] fix previous attempt at fixing #10058
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Mar 18, 2008
1 parent be9d8cd commit c6729af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/tz_time_helpers/active_record_methods.rb
Expand Up @@ -18,11 +18,11 @@ def tz_time_attributes(*attributes)
time time
end end
end end
end

define_method "#{attribute}=" do |local_time|
define_method "#{attribute}=" do |local_time| fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil
fixed = (local_time.acts_like?(:time) || local_time.acts_like?(:date)) ? TzTime.at(local_time) : nil write_attribute attribute, fixed
write_attribute(attribute, fixed) end
end end
end end
end end
Expand Down
12 changes: 3 additions & 9 deletions test/active_record_methods_test.rb
Expand Up @@ -34,29 +34,23 @@ class ActiveRecordMethodsTest < Test::Unit::TestCase
def setup def setup
TzTime.zone = TimeZone["Central Time (US & Canada)"] TzTime.zone = TimeZone["Central Time (US & Canada)"]
@record = MockRecord.new @record = MockRecord.new
@record.instance_variable_set(:@due_on, Time.utc(2006, 1, 1))
end end


def test_should_access_utc_time_as_local_with_getter_method 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 assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on
end end


def test_should_fix_local_timezones def test_should_fix_local_timezones
@record.due_on = Time.utc(2006, 1, 1) @record.due_on = Time.utc(2006, 1, 1)
assert_equal TzTime.local(2005, 12, 31, 18), @record.due_on assert_equal TzTime.local(2006, 1, 1), @record.due_on
@record.send :fix_timezone assert_equal TzTime.local(2006, 1, 1), @record[:due_on]
assert_equal Time.utc(2006, 1, 1), @record[:due_on]
end end


def test_should_not_fix_utc_timezones 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] assert_equal Time.utc(2006, 1, 1), @record[:due_on]
end end

def test_should_only_fix_timezones_that_have_been_written 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 assert_equal TzTime.utc(2006, 1, 1), @record.due_on
end end
end end
Expand Down

0 comments on commit c6729af

Please sign in to comment.