Conditionally removing listing from Admin > Consumer Apps menu (#17182)

Related to forem/forem#16437
This commit is contained in:
Jeremy Friesen 2022-04-08 21:55:45 -04:00 committed by GitHub
parent 7f1fdc7324
commit 168698fe28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

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

View file

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