From 189c299a6e7328c2f7e0b9c13bb697c5a985b8e5 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 22 Jan 2021 09:09:30 +0100 Subject: [PATCH] Do not render component when the feature is disabled --- .../sdg/related_list_selector_component.rb | 4 ++++ .../related_list_selector_component_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/components/sdg/related_list_selector_component.rb b/app/components/sdg/related_list_selector_component.rb index 42584fdad..b183765de 100644 --- a/app/components/sdg/related_list_selector_component.rb +++ b/app/components/sdg/related_list_selector_component.rb @@ -28,6 +28,10 @@ class SDG::RelatedListSelectorComponent < ApplicationComponent } end + def render? + SDG::ProcessEnabled.new(f.object).enabled? + end + private def goals diff --git a/spec/components/sdg/related_list_selector_component_spec.rb b/spec/components/sdg/related_list_selector_component_spec.rb index ca0db193e..7326400e0 100644 --- a/spec/components/sdg/related_list_selector_component_spec.rb +++ b/spec/components/sdg/related_list_selector_component_spec.rb @@ -5,6 +5,27 @@ describe SDG::RelatedListSelectorComponent, type: :component do let(:form) { ConsulFormBuilder.new(:debate, debate, ActionView::Base.new, {}) } let(:component) { SDG::RelatedListSelectorComponent.new(form) } + before do + Setting["feature.sdg"] = true + Setting["sdg.process.debates"] = true + end + + it "does not render when the feature is disabled" do + Setting["feature.sdg"] = false + + render_inline component + + expect(page).not_to have_css ".sdg-related-list-selector" + end + + it "does not render when the SDG process feature is disabled" do + Setting["sdg.process.debates"] = false + + render_inline component + + expect(page).not_to have_css ".sdg-related-list-selector" + end + it "renders sdg_related_list field" do render_inline component