Project

General

Profile

Patch #38139 ยป add-guard-clause-to-time-tag.patch

Go MAEDA, 2023-01-01 07:42

View differences:

app/helpers/application_helper.rb
694 694
  end
695 695

  
696 696
  def time_tag(time)
697
    return if time.nil?
698

  
697 699
    text = distance_of_time_in_words(Time.now, time)
698 700
    if @project
699 701
      link_to(text,
test/helpers/application_helper_test.rb
2211 2211
    end
2212 2212
  end
2213 2213

  
2214
  def test_time_tag
2215
    user = User.find(1)
2216
    user.pref.update(time_zone: 'UTC')
2217
    User.current = user
2218

  
2219
    assert_nil time_tag(nil)
2220
    with_locale 'en' do
2221
      travel_to Time.zone.parse('2022-12-30T01:00:00Z') do
2222
        assert_equal "<abbr title=\"12/28/2022 01:00 AM\">2 days</abbr>", time_tag(2.days.ago)
2223

  
2224
        @project = Project.find(1)
2225
        assert_equal "<a title=\"12/28/2022 01:00 AM\" href=\"/projects/ecookbook/activity?from=2022-12-28\">2 days</a>", time_tag(2.days.ago)
2226
      end
2227
    end
2228
  end
2229

  
2214 2230
  private
2215 2231

  
2216 2232
  def wiki_links_with_special_characters
    (1-1/1)