Replace calls to Flipper with FeatureFlag (#11386)

This commit is contained in:
rhymes 2020-11-12 14:15:33 +01:00 committed by GitHub
parent de5a22ecf7
commit 1bb53651b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 34 additions and 26 deletions

View file

@ -39,7 +39,7 @@ module AdminHelper
PROFILE_ADMIN = { name: "config: profile setup", controller: "profile_fields" }.freeze
def admin_menu_items
return MENU_ITEMS unless Flipper.enabled?(:profile_admin)
return MENU_ITEMS unless FeatureFlag.enabled?(:profile_admin)
MENU_ITEMS.dup.insert(7, PROFILE_ADMIN)
end

View file

@ -30,7 +30,7 @@ module AuthenticationHelper
end
def forem_creator_flow_enabled?
Flipper.enabled?(:creator_onboarding) && waiting_on_first_user?
FeatureFlag.enabled?(:creator_onboarding) && waiting_on_first_user?
end
def waiting_on_first_user?

View file

@ -1,6 +1,6 @@
module FeatureFlag
class << self
delegate :enabled?, :exist?, to: Flipper
delegate :enable, :enabled?, :exist?, to: Flipper
def accessible?(feature_flag_name, *args)
feature_flag_name.blank? || !exist?(feature_flag_name) || enabled?(feature_flag_name, *args)

View file

@ -85,7 +85,7 @@ Rails.application.routes.draw do
# NOTE: @citizen428 The next two resources have a temporary constraint
# while profile generalization is still WIP
constraints(->(_request) { Flipper.enabled?(:profile_admin) }) do
constraints(->(_request) { FeatureFlag.enabled?(:profile_admin) }) do
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end

View file

@ -4,7 +4,7 @@ RSpec.describe ProfileFieldGroup, type: :model do
subject { group }
before do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
let!(:group) { create(:profile_field_group) }

View file

@ -7,7 +7,7 @@ RSpec.describe "/admin", type: :request do
describe "profile admin feature flag" do
it "shows the option when the feature flag is enabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
get admin_path
@ -15,7 +15,7 @@ RSpec.describe "/admin", type: :request do
end
it "does not show the option when the feature flag is disabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(false)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
get admin_path

View file

@ -5,7 +5,7 @@ RSpec.describe "/admin/profile_field_groups", type: :request do
before do
sign_in admin
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
describe "POST /admin/profile_field_groups" do

View file

@ -5,7 +5,7 @@ RSpec.describe "/admin/profile_fields", type: :request do
before do
sign_in admin
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
describe "GET /admin/profile_fields" do

View file

@ -7,7 +7,7 @@ RSpec.describe "admin sidebar", type: :request do
describe "profile admin feature flag" do
it "shows the option in the sidebar when the feature flag is enabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
get admin_articles_path
@ -15,7 +15,7 @@ RSpec.describe "admin sidebar", type: :request do
end
it "does not show the option in the sidebar when the feature flag is disabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(false)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
get admin_articles_path

View file

@ -111,14 +111,10 @@ RSpec.describe "Registrations", type: :request do
context "with the creator_onboarding feature flag" do
before do
Flipper.enable(:creator_onboarding)
allow(FeatureFlag).to receive(:enabled?).with(:creator_onboarding).and_return(true)
allow(SiteConfig).to receive(:waiting_on_first_user).and_return(true)
end
after do
Flipper.disable(:creator_onboarding)
end
it "renders the creator onboarding form" do
get new_user_registration_path
expect(response.body).to include("Let's create an admin account for your community.")
@ -176,7 +172,7 @@ RSpec.describe "Registrations", type: :request do
end
it "does not raise disallowed if community is set to allow email" do
expect { post "/users" }.not_to raise_error Pundit::NotAuthorizedError
expect { post "/users" }.not_to raise_error
end
it "does not create user with invalid params" do
@ -269,7 +265,7 @@ RSpec.describe "Registrations", type: :request do
end
it "does not raise disallowed" do
expect { post "/users" }.not_to raise_error Pundit::NotAuthorizedError
expect { post "/users" }.not_to raise_error
end
it "creates user with valid params passed" do
@ -323,14 +319,10 @@ RSpec.describe "Registrations", type: :request do
context "with the creator_onboarding feature flag" do
before do
Flipper.enable(:creator_onboarding)
allow(FeatureFlag).to receive(:enabled?).with(:creator_onboarding).and_return(true)
allow(SiteConfig).to receive(:waiting_on_first_user).and_return(true)
end
after do
Flipper.disable(:creator_onboarding)
end
it "creates user with valid params passed" do
post "/users", params:
{ user: { name: "test #{rand(10)}",

View file

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe "Profile admin routes", type: :routing do
it "renders the profile admin route if the feature flag is enabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(true)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
expect(get: admin_profile_fields_path).to route_to(
controller: "admin/profile_fields",
@ -12,7 +12,7 @@ RSpec.describe "Profile admin routes", type: :routing do
end
it "does not render the profile admin route if the feature flag is disabled" do
allow(Flipper).to receive(:enabled?).with(:profile_admin).and_return(false)
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
expect(get: admin_profile_fields_path).not_to route_to(
controller: "admin/profile_fields",

View file

@ -2,7 +2,23 @@ require "rails_helper"
UserStruct = Struct.new(:flipper_id)
describe FeatureFlag, type: :helper do
describe FeatureFlag, type: :service do
describe ".enable" do
it "calls Flipper's enable method" do
allow(Flipper).to receive(:enable).with("foo")
described_class.enable("foo")
expect(Flipper).to have_received(:enable).with("foo")
end
it "enables the feature" do
described_class.enable("foo")
expect(described_class.enabled?("foo")).to be(true)
end
end
describe ".enabled?" do
it "calls Flipper's enabled? method" do
allow(Flipper).to receive(:enabled?).with("foo")