diff --git a/app/controllers/sdg_management/base_controller.rb b/app/controllers/sdg_management/base_controller.rb index a5028f7d0..4fcfb39be 100644 --- a/app/controllers/sdg_management/base_controller.rb +++ b/app/controllers/sdg_management/base_controller.rb @@ -1,4 +1,7 @@ class SDGManagement::BaseController < ApplicationController + include FeatureFlags + feature_flag :sdg + layout "admin" before_action :authenticate_user! diff --git a/app/views/shared/_admin_login_items.html.erb b/app/views/shared/_admin_login_items.html.erb index 32c70fe73..5c764ebf5 100644 --- a/app/views/shared/_admin_login_items.html.erb +++ b/app/views/shared/_admin_login_items.html.erb @@ -33,7 +33,7 @@ <% end %> - <% if current_user.administrator? %> + <% if feature?(:sdg) && current_user.administrator? %>
  • <%= link_to t("sdg_management.header.title"), sdg_management_root_path %>
  • diff --git a/spec/system/sdg_management/goals_spec.rb b/spec/system/sdg_management/goals_spec.rb index 6ceca8107..77d508853 100644 --- a/spec/system/sdg_management/goals_spec.rb +++ b/spec/system/sdg_management/goals_spec.rb @@ -5,6 +5,8 @@ describe "Goals", :js do describe "Index" do scenario "Visit the index" do + Setting["feature.sdg"] = true + visit sdg_management_root_path within("#side_menu") do diff --git a/spec/system/sdg_management/sdg_spec.rb b/spec/system/sdg_management/sdg_spec.rb new file mode 100644 index 000000000..6f5dd5d37 --- /dev/null +++ b/spec/system/sdg_management/sdg_spec.rb @@ -0,0 +1,31 @@ +require "rails_helper" + +describe "SDG Management" do + before { login_as(create(:administrator).user) } + + context "SDG feature flag is enabled", :js do + before { Setting["feature.sdg"] = true } + + scenario "shows the SDG content link" do + visit root_path + click_link "Menu" + + expect(page).to have_link "SDG content" + end + end + + context "SDG feature is disabled" do + before { Setting["feature.sdg"] = false } + + scenario "does not show the SDG Content link", :js do + visit root_path + click_link "Menu" + + expect(page).not_to have_link "SDG content" + end + + scenario "does not allow visits to the SDG content" do + expect { visit sdg_management_root_path }.to raise_exception(FeatureFlags::FeatureDisabled) + end + end +end