Adds a feature flag for Data Update Scripts (#12641)
* feat: add a feature flag for data update scripts * feat: write some tests for it * chore: oops * stub the data update scripts out wherever the profile admin is * chore: remove some unneeded ones * refactor: use call_original * feat: add a feature flag to all the Forems (but not enable it as yet)
This commit is contained in:
parent
4e1745ce4a
commit
a61f88fc16
12 changed files with 140 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
|||
module FeatureFlag
|
||||
class << self
|
||||
delegate :disable, :enable, :enabled?, :exist?, :remove, to: Flipper
|
||||
delegate :add, :disable, :enable, :enabled?, :exist?, :remove, to: Flipper
|
||||
|
||||
def accessible?(feature_flag_name, *args)
|
||||
feature_flag_name.blank? || !exist?(feature_flag_name) || enabled?(feature_flag_name, *args)
|
||||
|
|
|
|||
|
|
@ -22,19 +22,21 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2 m:gap-4 l:gap-6 m:grid-cols-2 l:grid-cols-3 px-2 m:px-0">
|
||||
<div>
|
||||
<div class="mt-6 mb-2"> Tech Resources </div>
|
||||
<% AdminHelper::TECH_MENU_ITEMS.each do |tech_menu_item| %>
|
||||
<div class="tag-card crayons-card branded-4 p-4 m:p-6 m:pt-4 flex flex-col relative">
|
||||
<h3 class="crayons-tag crayons-tag--l mb-2">
|
||||
<a href="/admin/<%= tech_menu_item[:controller] %>" class="crayons-link">
|
||||
<%= tech_menu_item[:name].to_s.titleize %>
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if FeatureFlag.enabled?(:data_update_scripts) %>
|
||||
<div class="grid gap-2 m:gap-4 l:gap-6 m:grid-cols-2 l:grid-cols-3 px-2 m:px-0">
|
||||
<div>
|
||||
<div class="mt-6 mb-2"> Tech Resources </div>
|
||||
<% AdminHelper::TECH_MENU_ITEMS.each do |tech_menu_item| %>
|
||||
<div class="tag-card crayons-card branded-4 p-4 m:p-6 m:pt-4 flex flex-col relative">
|
||||
<h3 class="crayons-tag crayons-tag--l mb-2">
|
||||
<a href="/admin/<%= tech_menu_item[:controller] %>" class="crayons-link">
|
||||
<%= tech_menu_item[:name].to_s.titleize %>
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -59,8 +59,10 @@
|
|||
<div class="crayons-layout__left-sidebar">
|
||||
<nav class="hidden m:block">
|
||||
<%= render "admin/shared/navbar", menu_items: admin_menu_items %>
|
||||
<p class="crayons-field__description mt-4 mb-3">Tech Resources</p>
|
||||
<%= render "admin/shared/navbar", menu_items: AdminHelper::TECH_MENU_ITEMS %>
|
||||
<% if FeatureFlag.enabled?(:data_update_scripts) %>
|
||||
<p class="crayons-field__description mt-4 mb-3">Tech Resources</p>
|
||||
<%= render "admin/shared/navbar", menu_items: AdminHelper::TECH_MENU_ITEMS %>
|
||||
<% end %>
|
||||
</nav>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -63,9 +63,12 @@ Rails.application.routes.draw do
|
|||
destroy], path: "listings/categories"
|
||||
|
||||
resources :comments, only: [:index]
|
||||
resources :data_update_scripts, only: %i[index show] do
|
||||
member do
|
||||
post :force_run
|
||||
# We do not expose the Data Update Scripts to all Forems by default.
|
||||
constraints(->(_request) { FeatureFlag.enabled?(:data_update_scripts) }) do
|
||||
resources :data_update_scripts, only: %i[index show] do
|
||||
member do
|
||||
post :force_run
|
||||
end
|
||||
end
|
||||
end
|
||||
resources :events, only: %i[index create update new edit]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
module DataUpdateScripts
|
||||
class AddDataUpdatesScriptsFeatureFlag
|
||||
def run
|
||||
FeatureFlag.add(:data_update_scripts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
require "rails_helper"
|
||||
require Rails.root.join(
|
||||
"lib/data_update_scripts/20210210124346_add_data_updates_scripts_feature_flag.rb",
|
||||
)
|
||||
|
||||
describe DataUpdateScripts::AddDataUpdatesScriptsFeatureFlag do
|
||||
after do
|
||||
FeatureFlag.remove(:data_update_scripts)
|
||||
end
|
||||
|
||||
it "adds the :data_update_scripts flag", :aggregate_failures do
|
||||
expect do
|
||||
described_class.new.run
|
||||
end.to change { FeatureFlag.exist?(:data_update_scripts) }.from(false).to(true)
|
||||
end
|
||||
|
||||
it "works if the flag is already available" do
|
||||
FeatureFlag.add(:data_update_scripts)
|
||||
|
||||
expect do
|
||||
described_class.new.run
|
||||
end.not_to change { FeatureFlag.exist?(:data_update_scripts) }
|
||||
end
|
||||
end
|
||||
|
|
@ -3,7 +3,10 @@ require "rails_helper"
|
|||
RSpec.describe "/admin", type: :request do
|
||||
let(:super_admin) { create(:user, :super_admin) }
|
||||
|
||||
before { sign_in super_admin }
|
||||
before do
|
||||
sign_in super_admin
|
||||
allow(FeatureFlag).to receive(:enabled?).and_call_original
|
||||
end
|
||||
|
||||
describe "profile admin feature flag" do
|
||||
it "shows the option when the feature flag is enabled" do
|
||||
|
|
@ -40,4 +43,25 @@ RSpec.describe "/admin", type: :request do
|
|||
expect(response.body).to include(ENV["HEROKU_RELEASE_CREATED_AT"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "data update scripts admin feature flag" do
|
||||
it "shows the option when the feature flag is enabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
||||
|
||||
get admin_path
|
||||
|
||||
expect(response.body).to include("Tech Resources")
|
||||
expect(response.body).to include("Data Update Scripts")
|
||||
end
|
||||
|
||||
it "does not show the option when the feature flag is disabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
|
||||
|
||||
get admin_path
|
||||
|
||||
expect(response.body).not_to include("Tech Resources")
|
||||
expect(response.body).not_to include("Data Update Scripts")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ RSpec.describe "/admin/data_update_scripts", type: :request do
|
|||
context "when the user is not an tech admin" do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before { sign_in user }
|
||||
before do
|
||||
sign_in user
|
||||
allow(Flipper).to receive(:enabled?).and_call_original
|
||||
allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
||||
end
|
||||
|
||||
describe "GET /admin/data_update_scripts" do
|
||||
it "blocks the request" do
|
||||
|
|
@ -18,7 +22,11 @@ RSpec.describe "/admin/data_update_scripts", type: :request do
|
|||
context "when the user is a tech admin" do
|
||||
let(:user) { create(:user, :admin, :tech_admin) }
|
||||
|
||||
before { sign_in user }
|
||||
before do
|
||||
sign_in user
|
||||
allow(Flipper).to receive(:enabled?).and_call_original
|
||||
allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
||||
end
|
||||
|
||||
describe "GET /admin/data_update_scripts" do
|
||||
it "allows the request" do
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ RSpec.describe "/admin/profile_fields", type: :request do
|
|||
|
||||
before do
|
||||
sign_in admin
|
||||
allow(FeatureFlag).to receive(:enabled?).and_call_original
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ require "rails_helper"
|
|||
RSpec.describe "admin sidebar", type: :request do
|
||||
let(:super_admin) { create(:user, :super_admin) }
|
||||
|
||||
before { sign_in super_admin }
|
||||
before do
|
||||
sign_in super_admin
|
||||
allow(FeatureFlag).to receive(:enabled?).and_call_original
|
||||
end
|
||||
|
||||
describe "profile admin feature flag" do
|
||||
it "shows the option in the sidebar when the feature flag is enabled" do
|
||||
|
|
@ -22,4 +25,23 @@ RSpec.describe "admin sidebar", type: :request do
|
|||
expect(response.body).not_to include("Config: Profile Setup")
|
||||
end
|
||||
end
|
||||
|
||||
describe "data update script admin feature flag" do
|
||||
it "shows the option in the sidebar when the feature flag is enabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
||||
|
||||
get admin_articles_path
|
||||
|
||||
expect(response.body).to include("Tech Resources")
|
||||
expect(response.body).to include("Data Update Scripts")
|
||||
end
|
||||
|
||||
it "does not show the option in the sidebar when the feature flag is disabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
|
||||
|
||||
get admin_articles_path
|
||||
|
||||
expect(response.body).not_to include("Data Update Scripts")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
23
spec/routing/data_update_scripts_admin_routes_spec.rb
Normal file
23
spec/routing/data_update_scripts_admin_routes_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe "Data Update Scripts admin routes", type: :routing do
|
||||
it "renders the data update scripts admin route if the feature flag is enabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
||||
|
||||
expect(get: admin_data_update_scripts_path).to route_to(
|
||||
controller: "admin/data_update_scripts",
|
||||
action: "index",
|
||||
locale: nil,
|
||||
)
|
||||
end
|
||||
|
||||
it "does not render the data update scripts admin route if the feature flag is disabled" do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:data_update_scripts).and_return(false)
|
||||
|
||||
expect(get: admin_data_update_scripts_path).not_to route_to(
|
||||
controller: "admin/data_update_scripts",
|
||||
action: "index",
|
||||
locale: nil,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -8,6 +8,7 @@ RSpec.describe "Admin manages profile fields", type: :system do
|
|||
before do
|
||||
create(:profile_field, profile_field_group: profile_field_group, label: label)
|
||||
Profile.refresh_attributes!
|
||||
allow(FeatureFlag).to receive(:enabled?).and_call_original
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
|
||||
|
||||
sign_in admin
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue