From 168698fe28078029db2fdb8555321b5445ad56a7 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Fri, 8 Apr 2022 21:55:45 -0400 Subject: [PATCH] Conditionally removing listing from Admin > Consumer Apps menu (#17182) Related to forem/forem#16437 --- app/models/admin_menu.rb | 2 +- spec/models/admin_menu_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/admin_menu.rb b/app/models/admin_menu.rb index 8b3c07223..d5ca12bc4 100644 --- a/app/models/admin_menu.rb +++ b/app/models/admin_menu.rb @@ -55,7 +55,7 @@ class AdminMenu scope :apps, "palette-line", [ item(name: "consumer apps", controller: "consumer_apps"), - item(name: "listings"), + item(name: "listings", visible: -> { Listing.feature_enabled? }), item(name: "welcome"), ] end.freeze diff --git a/spec/models/admin_menu_spec.rb b/spec/models/admin_menu_spec.rb index 0a147512e..375d8b9cf 100644 --- a/spec/models/admin_menu_spec.rb +++ b/spec/models/admin_menu_spec.rb @@ -97,4 +97,22 @@ RSpec.describe AdminMenu do it { is_expected.to be_visible } end end + + describe "scope :apps" do + subject(:listing) { apps.children.detect { |child| child.name == "listings" } } + + let(:apps) { described_class.navigation_items.fetch(:apps) } + + context "when Listing.feature_enabled? is true" do + before { allow(Listing).to receive(:feature_enabled?).and_return(true) } + + it { is_expected.to be_visible } + end + + context "when Listing.feature_enabled? is false" do + before { allow(Listing).to receive(:feature_enabled?).and_return(false) } + + it { is_expected.not_to be_visible } + end + end end