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.
This commit is contained in:
Javi Martín
2021-09-04 23:16:11 +02:00
parent af53b2159c
commit 5c1a7044cd
3 changed files with 34 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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