Remove guard clauses and update expectations (#17138)

This commit is contained in:
Daniel Uber 2022-04-08 15:20:19 -05:00 committed by GitHub
parent 88109368ae
commit 2ddefcbba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 12 additions and 36 deletions

View file

@ -27,7 +27,7 @@ class AdminMenu
item(name: "display ads"),
item(name: "navigation links"),
item(name: "pages"),
item(name: "profile fields", visible: -> { FeatureFlag.enabled?(:profile_admin) }),
item(name: "profile fields"),
]
scope :admin_team, "user-line", [

View file

@ -100,13 +100,8 @@ namespace :admin do
resources :html_variants, only: %i[index edit update new create show destroy]
resources :navigation_links, only: %i[index update create destroy]
resources :pages, only: %i[index new create edit update destroy]
# NOTE: The next two resources have a temporary constraint while profile
# generalization is still WIP
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
resources :profile_field_groups, only: %i[update create destroy]
resources :profile_fields, only: %i[index update create destroy]
end
scope :moderation do

View file

@ -88,17 +88,13 @@ RSpec.describe AdminMenu do
let(:customization) { described_class.navigation_items.fetch(:customization) }
it { is_expected.to be_a(Menu::Item) }
it { is_expected.to be_visible }
context "when :profile_field FeatureFlag is enabled" do
before { allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true) }
context "when :profile_field FeatureFlag is not enabled" do
# leaving this in place to make sure item is visible even if flag not enabled
before { allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false) }
it { is_expected.to be_visible }
end
context "when :profile_field FeatureFlag is not enabled" do
before { allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false) }
it { is_expected.not_to be_visible }
end
end
end

View file

@ -3,10 +3,6 @@ require "rails_helper"
RSpec.describe ProfileFieldGroup, type: :model do
subject { group }
before do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
end
let!(:group) { create(:profile_field_group) }
it { is_expected.to have_many(:profile_fields).dependent(:nullify) }

View file

@ -27,17 +27,15 @@ RSpec.describe "admin sidebar", type: :request do
end
describe "profile admin feature flag" do
it "does not show the option in the sidebar when the feature flag is disabled" do
it "shows the option in the sidebar even when the feature flag is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
get admin_articles_path
expect(response.body).not_to include("Profile Fields")
expect(response.body).to include("Profile Fields")
end
it "shows the option in the sidebar when the feature flag is enabled" do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
it "shows the option in the sidebar" do
get admin_articles_path
expect(response.body).to include("Profile Fields")

View file

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

View file

@ -5,8 +5,6 @@ RSpec.describe "/admin/customization/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
describe "GET /admin/customization/profile_fields" do

View file

@ -2,8 +2,6 @@ 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(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
expect(get: admin_profile_fields_path).to route_to(
controller: "admin/profile_fields",
action: "index",
@ -11,10 +9,10 @@ RSpec.describe "Profile admin routes", type: :routing do
)
end
it "does not render the profile admin route if the feature flag is disabled" do
it "renders the profile admin route even if the feature flag is disabled" do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(false)
expect(get: admin_profile_fields_path).not_to route_to(
expect(get: admin_profile_fields_path).to route_to(
controller: "admin/profile_fields",
action: "index",
locale: nil,

View file

@ -8,9 +8,6 @@ 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
visit admin_profile_fields_path
end

View file

@ -42,7 +42,6 @@ RSpec.describe "User edits their profile", type: :system do
describe "editing admin created profile fields" do
before do
allow(FeatureFlag).to receive(:enabled?).with(:profile_admin).and_return(true)
Profile.refresh_attributes!
end