summaryrefslogtreecommitdiffstats
path: root/test/unit/user_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-05-26 12:07:56 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-05-26 12:07:56 +0000
commit189be55235b75c32908a4037825b453513673e64 (patch)
treea1bfcc244fa32c7e326487d145ec1b6232d51a5b /test/unit/user_test.rb
parent84084b01689718ea901dcd66d66ab676c7bc4790 (diff)
downloadredmine-189be55235b75c32908a4037825b453513673e64.tar.gz
redmine-189be55235b75c32908a4037825b453513673e64.zip
Fixed time zone issues introduced by r9719 (#10996).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9726 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/user_test.rb')
-rw-r--r--test/unit/user_test.rb33
1 files changed, 32 insertions, 1 deletions
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 2b658a1dc..2ff55f9f3 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -424,7 +424,38 @@ class UserTest < ActiveSupport::TestCase
assert_equal 'jsmith', @jsmith.reload.name
end
end
-
+
+ def test_today_should_return_the_day_according_to_user_time_zone
+ preference = User.find(1).pref
+ date = Date.new(2012, 05, 15)
+ time = Time.gm(2012, 05, 15, 23, 30).utc # 2012-05-15 23:30 UTC
+ Date.stubs(:today).returns(date)
+ Time.stubs(:now).returns(time)
+
+ preference.update_attribute :time_zone, 'Baku' # UTC+4
+ assert_equal '2012-05-16', User.find(1).today.to_s
+
+ preference.update_attribute :time_zone, 'La Paz' # UTC-4
+ assert_equal '2012-05-15', User.find(1).today.to_s
+
+ preference.update_attribute :time_zone, ''
+ assert_equal '2012-05-15', User.find(1).today.to_s
+ end
+
+ def test_time_to_date_should_return_the_date_according_to_user_time_zone
+ preference = User.find(1).pref
+ time = Time.gm(2012, 05, 15, 23, 30).utc # 2012-05-15 23:30 UTC
+
+ preference.update_attribute :time_zone, 'Baku' # UTC+4
+ assert_equal '2012-05-16', User.find(1).time_to_date(time).to_s
+
+ preference.update_attribute :time_zone, 'La Paz' # UTC-4
+ assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s
+
+ preference.update_attribute :time_zone, ''
+ assert_equal '2012-05-15', User.find(1).time_to_date(time).to_s
+ end
+
def test_fields_for_order_statement_should_return_fields_according_user_format_setting
with_settings :user_format => 'lastname_coma_firstname' do
assert_equal ['users.lastname', 'users.firstname', 'users.id'], User.fields_for_order_statement