diff --git a/app/controllers/admin/comments_controller.rb b/app/controllers/admin/comments_controller.rb index 98283ffed..ebe2f1066 100644 --- a/app/controllers/admin/comments_controller.rb +++ b/app/controllers/admin/comments_controller.rb @@ -4,7 +4,7 @@ class Admin::CommentsController < Admin::BaseController before_action :load_comment, only: [:confirm_hide, :restore] def index - @comments = Comment.only_hidden.send(@current_filter).order(hidden_at: :desc).page(params[:page]) + @comments = Comment.only_hidden.with_visible_author.send(@current_filter).order(hidden_at: :desc).page(params[:page]) end def confirm_hide diff --git a/app/models/comment.rb b/app/models/comment.rb index 227448da2..52192cc7f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -18,10 +18,9 @@ class Comment < ActiveRecord::Base belongs_to :user, -> { with_hidden } scope :recent, -> { order(id: :desc) } - scope :sort_for_moderation, -> { order(flags_count: :desc, updated_at: :desc) } - scope :for_render, -> { with_hidden.includes(user: :organization) } + scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } after_create :call_after_commented diff --git a/spec/features/admin/comments_spec.rb b/spec/features/admin/comments_spec.rb index 833e01717..ffb8122d2 100644 --- a/spec/features/admin/comments_spec.rb +++ b/spec/features/admin/comments_spec.rb @@ -7,7 +7,26 @@ feature 'Admin comments' do login_as(admin.user) end - scenario 'Restore', :js do + scenario "Do not show comments from blocked users" do + comment = create(:comment, :hidden, body: "SPAM from SPAMMER") + proposal = create(:proposal, author: comment.author) + create(:comment, commentable: proposal, user: comment.author, body: "Good Proposal!") + + visit admin_comments_path + expect(page).to have_content("SPAM from SPAMMER") + expect(page).not_to have_content("Good Proposal!") + + visit proposal_path(proposal) + within("#proposal_#{proposal.id}") do + click_link 'Ban author' + end + + visit admin_comments_path + expect(page).to_not have_content("SPAM from SPAMMER") + expect(page).not_to have_content("Good Proposal!") + end + + scenario "Restore" do comment = create(:comment, :hidden, body: 'Not really SPAM') visit admin_comments_path @@ -18,7 +37,7 @@ feature 'Admin comments' do expect(comment.reload).to_not be_hidden end - scenario 'Confirm hide' do + scenario "Confirm hide" do comment = create(:comment, :hidden, body: 'SPAM') visit admin_comments_path