diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index ee498da2d..330b3a3a5 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -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 diff --git a/app/helpers/authentication_helper.rb b/app/helpers/authentication_helper.rb index 2c19d9d59..be20e8b14 100644 --- a/app/helpers/authentication_helper.rb +++ b/app/helpers/authentication_helper.rb @@ -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? diff --git a/app/helpers/feature_flag.rb b/app/services/feature_flag.rb similarity index 78% rename from app/helpers/feature_flag.rb rename to app/services/feature_flag.rb index 737ce0c91..fe0c1abf4 100644 --- a/app/helpers/feature_flag.rb +++ b/app/services/feature_flag.rb @@ -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) diff --git a/config/routes.rb b/config/routes.rb index 66052ad39..22e3a6bdc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/models/profile_field_group_spec.rb b/spec/models/profile_field_group_spec.rb index 49a88be5b..843b25327 100644 --- a/spec/models/profile_field_group_spec.rb +++ b/spec/models/profile_field_group_spec.rb @@ -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) } diff --git a/spec/requests/admin/admin_portals_spec.rb b/spec/requests/admin/admin_portals_spec.rb index 19dc4bb03..f203c60a6 100644 --- a/spec/requests/admin/admin_portals_spec.rb +++ b/spec/requests/admin/admin_portals_spec.rb @@ -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 diff --git a/spec/requests/admin/profile_field_groups_spec.rb b/spec/requests/admin/profile_field_groups_spec.rb index b1a8eaaaa..533ff699a 100644 --- a/spec/requests/admin/profile_field_groups_spec.rb +++ b/spec/requests/admin/profile_field_groups_spec.rb @@ -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 diff --git a/spec/requests/admin/profile_fields_spec.rb b/spec/requests/admin/profile_fields_spec.rb index ca375701e..6d5ebd670 100644 --- a/spec/requests/admin/profile_fields_spec.rb +++ b/spec/requests/admin/profile_fields_spec.rb @@ -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 diff --git a/spec/requests/admin/sidebar_spec.rb b/spec/requests/admin/sidebar_spec.rb index eab10ef2d..27d559f2a 100644 --- a/spec/requests/admin/sidebar_spec.rb +++ b/spec/requests/admin/sidebar_spec.rb @@ -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 diff --git a/spec/requests/registrations_spec.rb b/spec/requests/registrations_spec.rb index afe0d4d24..8ee5c03c3 100644 --- a/spec/requests/registrations_spec.rb +++ b/spec/requests/registrations_spec.rb @@ -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)}", diff --git a/spec/routing/profile_admin_routes_spec.rb b/spec/routing/profile_admin_routes_spec.rb index 8677de9cd..26189d8b7 100644 --- a/spec/routing/profile_admin_routes_spec.rb +++ b/spec/routing/profile_admin_routes_spec.rb @@ -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", diff --git a/spec/helpers/feature_flag_spec.rb b/spec/services/feature_flag_spec.rb similarity index 80% rename from spec/helpers/feature_flag_spec.rb rename to spec/services/feature_flag_spec.rb index 97249eacb..ab28fc9fb 100644 --- a/spec/helpers/feature_flag_spec.rb +++ b/spec/services/feature_flag_spec.rb @@ -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")