From: Go MAEDA Date: Mon, 2 Jan 2023 06:56:47 +0000 (+0000) Subject: Add guard clause to time_tag method to handle nil time (#38139). X-Git-Tag: 5.1.0~306 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=025323f5ba7b48d001ba59cc94b26967fdf1d4a1;p=redmine.git Add guard clause to time_tag method to handle nil time (#38139). Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22022 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e599cc32e..a4bf27e57 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -694,6 +694,8 @@ module ApplicationHelper end def time_tag(time) + return if time.nil? + text = distance_of_time_in_words(Time.now, time) if @project link_to(text, diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index bb6b37390..cf7c4ff3a 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -2211,6 +2211,22 @@ class ApplicationHelperTest < Redmine::HelperTest end end + def test_time_tag + user = User.find(1) + user.pref.update(time_zone: 'UTC') + User.current = user + + assert_nil time_tag(nil) + with_locale 'en' do + travel_to Time.zone.parse('2022-12-30T01:00:00Z') do + assert_equal "2 days", time_tag(2.days.ago) + + @project = Project.find(1) + assert_equal "2 days", time_tag(2.days.ago) + end + end + end + private def wiki_links_with_special_characters