From 9b5e694e9c9f06d16330a498101977e7e00b0f88 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Mon, 11 Jan 2021 16:17:52 -0500 Subject: [PATCH] Ben/new branch noindex spam comments (#12210) * noindex google any comment permalinks with negative score * Add commentable noindex * Give dummy score to podcast episodes --- app/models/podcast_episode.rb | 4 ++++ app/views/comments/index.html.erb | 4 ++++ spec/requests/comments_spec.rb | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/models/podcast_episode.rb b/app/models/podcast_episode.rb index 788064a7b..7e8460cd8 100644 --- a/app/models/podcast_episode.rb +++ b/app/models/podcast_episode.rb @@ -73,6 +73,10 @@ class PodcastEpisode < ApplicationRecord ActionView::Base.full_sanitizer.sanitize(processed_html) end + def score + 1 # When it is expected that a "commentable" has a score, this is the fallback. + end + def zero_method 0 end diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index 42e674629..24046ae39 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -25,6 +25,10 @@ + <% if @root_comment.score < 0 || @commentable.score < 0 %> + + + <% end %> <% else %> " /> " /> diff --git a/spec/requests/comments_spec.rb b/spec/requests/comments_spec.rb index db6c2aefa..b44b88bc0 100644 --- a/spec/requests/comments_spec.rb +++ b/spec/requests/comments_spec.rb @@ -49,6 +49,23 @@ RSpec.describe "Comments", type: :request do get comment.path expect(response.body).to include(comment.processed_html) end + + it "displays noindex if comment has score of less than 0" do + comment.update_column(:score, -5) + get comment.path + expect(response.body).to include('') + end + + it "displays does not display noindex if comment has 0 or more score" do + get comment.path + expect(response.body).not_to include('') + end + + it "displays noindex if comment has score of less than 0" do + comment.commentable.update_column(:score, -5) + get comment.path + expect(response.body).to include('') + end end context "when the comment is a child comment" do