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:
parent
92217be4ed
commit
fc7ed20a9f
3 changed files with 32 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
<span class="color-base-30 px-2" role="presentation">•</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? %>
|
||||
• 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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue