From 24a562f8856a80b0ea42e98c9d18ec6a11585c09 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 15 Nov 2023 17:53:38 +0000 Subject: [PATCH] Use html 'time' element for friendly date helpers This provides more structure than just a simple span. --- app/helpers/application_helper.rb | 4 ++-- test/helpers/application_helper_test.rb | 10 +++++----- test/helpers/note_helper_test.rb | 4 ++-- test/helpers/user_blocks_helper_test.rb | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 28c97e485..4932bcc5e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -26,11 +26,11 @@ module ApplicationHelper end def friendly_date(date) - tag.span(time_ago_in_words(date), :title => l(date, :format => :friendly)) + tag.time(time_ago_in_words(date), :title => l(date, :format => :friendly), :datetime => date.xmlschema) end def friendly_date_ago(date) - tag.span(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly)) + tag.time(time_ago_in_words(date, :scope => :"datetime.distance_in_words_ago"), :title => l(date, :format => :friendly), :datetime => date.xmlschema) end def body_class diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 7cd6bce89..e05196dfa 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -57,19 +57,19 @@ class ApplicationHelperTest < ActionView::TestCase def test_friendly_date date = friendly_date(Time.utc(2014, 3, 5, 18, 58, 23)) - assert_match %r{^.*$}, date + assert_match %r{^$}, date date = friendly_date(Time.now.utc - 1.hour) - assert_match %r{^about 1 hour$}, date + assert_match %r{^$}, date date = friendly_date(Time.now.utc - 2.days) - assert_match %r{^2 days$}, date + assert_match %r{^$}, date date = friendly_date(Time.now.utc - 3.weeks) - assert_match %r{^21 days$}, date + assert_match %r{^$}, date date = friendly_date(Time.now.utc - 4.months) - assert_match %r{^4 months$}, date + assert_match %r{^$}, date end def test_body_class; end diff --git a/test/helpers/note_helper_test.rb b/test/helpers/note_helper_test.rb index 37518fb3d..805906d55 100644 --- a/test/helpers/note_helper_test.rb +++ b/test/helpers/note_helper_test.rb @@ -8,8 +8,8 @@ class NoteHelperTest < ActionView::TestCase date = Time.utc(2014, 3, 5, 21, 37, 45) user = create(:user) - assert_match %r{^Created by anonymous .* ago$}, note_event("opened", date, nil) - assert_match %r{^Resolved by #{user.display_name} .* ago$}, note_event("closed", date, user) + assert_match %r{^Created by anonymous $}, note_event("opened", date, nil) + assert_match %r{^Resolved by #{user.display_name} $}, note_event("closed", date, user) end def test_note_author diff --git a/test/helpers/user_blocks_helper_test.rb b/test/helpers/user_blocks_helper_test.rb index 0c2ab42b5..db4fd87a4 100644 --- a/test/helpers/user_blocks_helper_test.rb +++ b/test/helpers/user_blocks_helper_test.rb @@ -8,10 +8,10 @@ class UserBlocksHelperTest < ActionView::TestCase assert_equal "Active until the user logs in.", block_status(block) block = create(:user_block, :needs_view, :ends_at => Time.now.utc + 1.hour) - assert_match %r{^Ends in about 1 hour and after the user has logged in\.$}, block_status(block) + assert_match %r{^Ends in and after the user has logged in\.$}, block_status(block) block = create(:user_block, :ends_at => Time.now.utc + 1.hour) - assert_match %r{^Ends in about 1 hour\.$}, block_status(block) + assert_match %r{^Ends in \.$}, block_status(block) end def test_block_duration_in_words -- 2.39.5