mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-19 13:48:09 +01:00
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:
parent
fe52c0ab3c
commit
00da0b36aa
2 changed files with 18 additions and 2 deletions
|
|
@ -426,6 +426,7 @@ class TodosControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
# link todo_1 and recurring_todo_1
|
# link todo_1 and recurring_todo_1
|
||||||
recurring_todo_1 = RecurringTodo.find(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)
|
todo_1 = Todo.find_by_recurring_todo_id(1)
|
||||||
today = Time.now.at_midnight
|
today = Time.now.at_midnight
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,22 @@ class ActiveSupport::TestCase
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class ActionController::IntegrationTest
|
class ActionController::IntegrationTest
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue