From 5c1a7044cd880a3d8d2c9b3c67366b241fe5b012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 4 Sep 2021 23:16:11 +0200 Subject: [PATCH] Hide comments when features are disabled We were already doing so for debates and investments. We probably never noticed because this is an edge case that requires enabling a feature, people adding comments, and then disabling the feature. --- .../users/public_activity_component.rb | 9 +++++-- .../users/public_activity_component_spec.rb | 25 +++++++++++++++++++ spec/factories/comments.rb | 3 ++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/components/users/public_activity_component.rb b/app/components/users/public_activity_component.rb index 653bf89c7..61c1fbb8e 100644 --- a/app/components/users/public_activity_component.rb +++ b/app/components/users/public_activity_component.rb @@ -73,7 +73,12 @@ class Users::PublicActivityComponent < ApplicationComponent def disabled_commentables [ ("Debate" unless feature?(:debates)), - ("Budget::Investment" unless feature?(:budgets)) - ].compact + ("Budget::Investment" unless feature?(:budgets)), + (["Legislation::Question", + "Legislation::Proposal", + "Legislation::Annotation"] unless feature?(:legislation)), + (["Poll", "Poll::Question"] unless feature?(:polls)), + ("Proposal" unless feature?(:proposals)) + ].flatten.compact end end diff --git a/spec/components/users/public_activity_component_spec.rb b/spec/components/users/public_activity_component_spec.rb index 39ae4010d..2f72c8495 100644 --- a/spec/components/users/public_activity_component_spec.rb +++ b/spec/components/users/public_activity_component_spec.rb @@ -79,4 +79,29 @@ describe Users::PublicActivityComponent, controller: UsersController do end end end + + describe "comments" do + let(:user) { create(:user) } + let(:component) { Users::PublicActivityComponent.new(user) } + + it "doesn't show comments for disabled features" do + Setting["process.budgets"] = false + Setting["process.debates"] = false + Setting["process.legislation"] = false + Setting["process.polls"] = false + Setting["process.proposals"] = false + + create(:budget_investment_comment, user: user) + create(:debate_comment, user: user) + create(:legislation_annotation_comment, user: user) + create(:legislation_question_comment, user: user) + create(:legislation_proposal_comment, user: user) + create(:poll_comment, user: user) + create(:proposal_comment, user: user) + + render_inline component + + expect(page).not_to have_content "Comments" + end + end end diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 79402c448..f55581f88 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -4,7 +4,8 @@ FactoryBot.define do user sequence(:body) { |n| "Comment body #{n}" } - %i[budget_investment debate legislation_annotation legislation_question proposal topic_with_community].each do |model| + %i[budget_investment debate legislation_annotation legislation_question legislation_proposal + poll proposal topic_with_community].each do |model| factory :"#{model}_comment" do association :commentable, factory: model end