Fixed a latent time zone bug in tests.

I created a new method accessible to all tests for forcing a user to the local time zone. The code was cribbed from Rails's rake tasks time:zones:local.
This commit is contained in:
Eric Allen 2009-10-13 23:39:36 -04:00
parent fe52c0ab3c
commit 00da0b36aa
2 changed files with 18 additions and 2 deletions

View file

@ -426,6 +426,7 @@ class TodosControllerTest < ActionController::TestCase
# link todo_1 and recurring_todo_1
recurring_todo_1 = RecurringTodo.find(1)
set_user_to_current_time_zone(recurring_todo_1.user)
todo_1 = Todo.find_by_recurring_todo_id(1)
today = Time.now.at_midnight

View file

@ -82,8 +82,23 @@ class ActiveSupport::TestCase
end
end
end
def set_user_to_current_time_zone(user)
jan_offset = Time.now.beginning_of_year.utc_offset
jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
offset = jan_offset < jul_offset ? jan_offset : jul_offset
offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
sign = $1 == '-' ? -1 : 1
hours, minutes = $2.to_f, $3.to_f
((hours * 3600) + (minutes.to_f * 60)) * sign
elsif offset.to_f.abs <= 13
offset.to_f * 3600
else
offset.to_f
end
zone = ActiveSupport::TimeZone.all.find{|t| t.utc_offset == offset}
user.prefs.update_attribute(:time_zone, zone.name)
end
end
class ActionController::IntegrationTest