Publicly indicate if someone edits their comments (#10524)

* Publicly indicate if someone edits their comments

Signed-off-by: Efereyan Karen Simisola <thedevkaren@gmail.com>

* Implement required changes for date edited

* Add methods for readable publish date and edited at in comment decorator

Signed-off-by: Efereyan Karen Simisola <thedevkaren@gmail.com>

* Fix syntax error and decorator naming error

* Add tests

* Update app/views/comments/_comment_date.erb

Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>

Co-authored-by: rhymes <rhymes@hey.com>
Co-authored-by: Michael Kohl <me@citizen428.net>
Co-authored-by: Vaidehi Joshi <vaidehi.sj@gmail.com>
This commit is contained in:
Efereyan Karen Simisola 2021-03-02 03:47:25 +01:00 committed by GitHub
parent 92217be4ed
commit fc7ed20a9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View file

@ -14,4 +14,18 @@ class CommentDecorator < ApplicationDecorator
def published_at_int
created_at.to_i
end
def edited_timestamp
return "" if edited_at.nil?
edited_at.utc.iso8601
end
def readable_publish_date
if created_at.year == Time.current.year
created_at.strftime("%b %e")
else
created_at.strftime("%b %e '%y")
end
end
end

View file

@ -1,6 +1,15 @@
<span class="color-base-30 px-2" role="presentation">&bull;</span>
<a href="<%= URL.comment(decorated_comment) %>" class="comment-date crayons-link crayons-link--secondary fs-s">
<time datetime="<%= decorated_comment.published_timestamp %>">
<%= decorated_comment.readable_publish_date %>
</time>
<% if decorated_comment.edited_at.present? %>
&bull; Edited
<span class="hidden m:inline-block">
on <time datetime="<%= decorated_comment.edited_timestamp %>">
<%= decorated_comment.edited_at.strftime('%b %-d') %></time>
</span>
<% end %>
</a>

View file

@ -10,6 +10,7 @@ RSpec.describe "Editing A Comment", type: :system, js: true do
user: user,
body_markdown: Faker::Lorem.paragraph)
end
let(:iso8601_datetime_regexp) { /^((\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z)$/ }
before do
sign_in user
@ -19,8 +20,16 @@ RSpec.describe "Editing A Comment", type: :system, js: true do
expect(page).to have_css("textarea")
expect(page).to have_text("Editing comment")
fill_in "text-area", with: new_comment_text
click_button("Submit")
expect(page).to have_text(new_comment_text)
expect(page).to have_text("Edited on")
# using .last here because the first `<time>` element is the creation date,
# the second one is the time of editing
timestamp = page.all(".comment-date time").last[:datetime]
expect(timestamp).to match(iso8601_datetime_regexp)
end
context "when user edits comment on the bottom of the article" do