diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:42:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2016-05-07 10:42:22 +0000 |
commit | ed50d42210eaf7ca216e9cd3a043b36aa68eb51d (patch) | |
tree | fbc801683ee622f43e790ec6cf2785fd8f94a43c /test/unit/issue_test.rb | |
parent | 40c9c3e922e15ab7d88b5d06c60e51ed1ba40a7f (diff) | |
download | redmine-ed50d42210eaf7ca216e9cd3a043b36aa68eb51d.tar.gz redmine-ed50d42210eaf7ca216e9cd3a043b36aa68eb51d.zip |
Replace Date.today with User.current.today (#22320).
Depending on the offset between a user's configured timezone and the server
timezone, Date.today may be more or less often wrong from the user's
perspective, leading to things like issues marked as overdue too early or too
late, or yesterday / tomorrow being displayed / selected where 'today' is
intended.
A test case illustrating the problem with Issue#overdue? is included
Patch by Jens Kraemer.
git-svn-id: http://svn.redmine.org/redmine/trunk@15379 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/issue_test.rb')
-rw-r--r-- | test/unit/issue_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 03dd57229..d7c7d231b 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -2756,4 +2756,30 @@ class IssueTest < ActiveSupport::TestCase issue.reload.assigned_to = nil assert_equal group, issue.assigned_to_was end + + def test_issue_overdue_should_respect_user_timezone + user_in_europe = users(:users_001) + user_in_europe.pref.update_attribute :time_zone, 'UTC' + + user_in_asia = users(:users_002) + user_in_asia.pref.update_attribute :time_zone, 'Hongkong' + + issue = Issue.generate! :due_date => Date.parse('2016-03-20') + + # server time is UTC + time = Time.parse '2016-03-20 20:00 UTC' + Time.stubs(:now).returns(time) + Date.stubs(:today).returns(time.to_date) + + # for a user in the same time zone as the server the issue is not overdue + # yet + User.current = user_in_europe + assert !issue.overdue? + + # at the same time, a user in East Asia looks at the issue - it's already + # March 21st and the issue should be marked overdue + User.current = user_in_asia + assert issue.overdue? + + end end |