Render 404 when root comment has low score and no children (#20560)
This commit is contained in:
parent
afa73e06e3
commit
58bd07d729
3 changed files with 27 additions and 1 deletions
|
|
@ -16,6 +16,11 @@ class CommentsController < ApplicationController
|
|||
|
||||
@root_comment = Comment.find(params[:id_code].to_i(26)) if params[:id_code].present?
|
||||
|
||||
# hide low quality comments w/o children
|
||||
if @root_comment && @root_comment.decorate.low_quality && !@root_comment.has_children?
|
||||
not_found
|
||||
end
|
||||
|
||||
if @podcast
|
||||
@user = @podcast
|
||||
@commentable = @user.podcast_episodes.find_by(slug: params[:slug]) if @user.podcast_episodes
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<%= javascript_include_tag "postCommentsPage", defer: true %>
|
||||
<% if @root_comment.present? %>
|
||||
<% if @root_comment.present? && !@root_comment.decorate.low_quality %>
|
||||
<% title(@root_comment.title.to_s) %>
|
||||
<% else %>
|
||||
<% title(t("views.comments.meta.title_root", title: @commentable.title)) %>
|
||||
|
|
|
|||
|
|
@ -161,6 +161,27 @@ RSpec.describe "Comments" do
|
|||
end
|
||||
end
|
||||
|
||||
context "when the comment is low quality" do
|
||||
let(:low_comment) do
|
||||
create(:comment, commentable: article, user: user, score: -1000, body_markdown: "low-comment")
|
||||
end
|
||||
|
||||
it "raises 404 when no children" do
|
||||
expect do
|
||||
get low_comment.path
|
||||
end.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "is displayed as deleted when has children", :aggregate_failures do
|
||||
create(:comment, commentable: article, user: user, parent: low_comment,
|
||||
body_markdown: "child of a low-quality comment")
|
||||
get low_comment.path
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include("Comment deleted")
|
||||
expect(response.body).to include("child of a low-quality comment")
|
||||
end
|
||||
end
|
||||
|
||||
context "when the comment is for a podcast's episode" do
|
||||
it "is successful" do
|
||||
podcast_comment = create(:comment, commentable: podcast_episode, user: user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue