From 557c15123bcd26505eef3a7b702bef4ef7d92a55 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 27 Mar 2020 01:34:54 -0500 Subject: [PATCH] comments: fix exception with group_by=comment param. --- app/views/comments/partials/show/_comment.html.erb | 2 +- test/functional/comments_controller_test.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 6a4365ba6..9df4db8b5 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -12,7 +12,7 @@ data-is-deleted="<%= comment.is_deleted? %>" data-is-sticky="<%= comment.is_sticky? %>" data-below-threshold="<%= comment.score < CurrentUser.user.comment_threshold %>" - <% if policy(moderation_reports).show? %> + <% if moderation_reports.present? && policy(moderation_reports).show? %> data-is-reported="<%= moderation_reports.pluck(:model_id).include?(comment.id) %>" <% end %> data-is-voted="<%= comment.voted_by?(CurrentUser.user) %>"> diff --git a/test/functional/comments_controller_test.rb b/test/functional/comments_controller_test.rb index 8686b5cb3..43e8c2770 100644 --- a/test/functional/comments_controller_test.rb +++ b/test/functional/comments_controller_test.rb @@ -20,6 +20,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest context "index action" do context "grouped by post" do should "render all comments for .js" do + @comment = as(@user) { create(:comment, post: @post) } get comments_path(post_id: @post.id), xhr: true assert_response :success @@ -87,6 +88,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest end should "render by comment" do + @comment = as(@user) { create(:comment, post: @post) } get comments_path(group_by: "comment") assert_response :success end