From 6fed0fcbaa1ac5866443e6af6424a78a78b78688 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 19 Dec 2023 16:17:22 +0100 Subject: [PATCH] Remove unneeded settings cleanup from specs (#28425) --- .../settings/branding_controller_spec.rb | 8 ---- .../api/v1/trends/links_controller_spec.rb | 6 --- .../api/v1/trends/statuses_controller_spec.rb | 6 --- .../api/v1/trends/tags_controller_spec.rb | 6 --- .../auth/registrations_controller_spec.rb | 44 ------------------- .../account_controller_concern_spec.rb | 6 --- spec/helpers/application_helper_spec.rb | 12 ----- spec/helpers/instance_helper_spec.rb | 6 --- spec/models/user_spec.rb | 34 ++------------ spec/presenters/instance_presenter_spec.rb | 24 ---------- .../api/v1/instances/activity_spec.rb | 6 --- .../api/v1/instances/domain_blocks_spec.rb | 6 --- spec/requests/api/v1/instances/peers_spec.rb | 6 --- spec/requests/cache_spec.rb | 20 ++------- spec/services/app_sign_up_service_spec.rb | 7 +-- 15 files changed, 8 insertions(+), 189 deletions(-) diff --git a/spec/controllers/admin/settings/branding_controller_spec.rb b/spec/controllers/admin/settings/branding_controller_spec.rb index 435616022a..e30300b4e4 100644 --- a/spec/controllers/admin/settings/branding_controller_spec.rb +++ b/spec/controllers/admin/settings/branding_controller_spec.rb @@ -19,14 +19,6 @@ RSpec.describe Admin::Settings::BrandingController do end describe 'PUT #update' do - around do |example| - before = Setting.site_short_description - Setting.site_short_description = nil - example.run - Setting.site_short_description = before - Setting.new_setting_key = nil - end - it 'cannot create a setting value for a non-admin key' do expect(Setting.new_setting_key).to be_blank diff --git a/spec/controllers/api/v1/trends/links_controller_spec.rb b/spec/controllers/api/v1/trends/links_controller_spec.rb index 12d4198aaf..bcaf066f16 100644 --- a/spec/controllers/api/v1/trends/links_controller_spec.rb +++ b/spec/controllers/api/v1/trends/links_controller_spec.rb @@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::LinksController do render_views describe 'GET #index' do - around do |example| - previous = Setting.trends - example.run - Setting.trends = previous - end - context 'when trends are disabled' do before { Setting.trends = false } diff --git a/spec/controllers/api/v1/trends/statuses_controller_spec.rb b/spec/controllers/api/v1/trends/statuses_controller_spec.rb index 69fdb270d5..25ab5f228a 100644 --- a/spec/controllers/api/v1/trends/statuses_controller_spec.rb +++ b/spec/controllers/api/v1/trends/statuses_controller_spec.rb @@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::StatusesController do render_views describe 'GET #index' do - around do |example| - previous = Setting.trends - example.run - Setting.trends = previous - end - context 'when trends are disabled' do before { Setting.trends = false } diff --git a/spec/controllers/api/v1/trends/tags_controller_spec.rb b/spec/controllers/api/v1/trends/tags_controller_spec.rb index 9311392cd9..c889f1c5b9 100644 --- a/spec/controllers/api/v1/trends/tags_controller_spec.rb +++ b/spec/controllers/api/v1/trends/tags_controller_spec.rb @@ -6,12 +6,6 @@ RSpec.describe Api::V1::Trends::TagsController do render_views describe 'GET #index' do - around do |example| - previous = Setting.trends - example.run - Setting.trends = previous - end - context 'when trends are disabled' do before { Setting.trends = false } diff --git a/spec/controllers/auth/registrations_controller_spec.rb b/spec/controllers/auth/registrations_controller_spec.rb index a9b24a1004..37172f8d24 100644 --- a/spec/controllers/auth/registrations_controller_spec.rb +++ b/spec/controllers/auth/registrations_controller_spec.rb @@ -6,12 +6,6 @@ RSpec.describe Auth::RegistrationsController do render_views shared_examples 'checks for enabled registrations' do |path| - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'redirects if it is in single user mode while it is open for registration' do Fabricate(:account) Setting.registrations_mode = 'open' @@ -82,12 +76,6 @@ RSpec.describe Auth::RegistrationsController do end context 'with open registrations' do - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'returns http success' do Setting.registrations_mode = 'open' get :new @@ -120,12 +108,6 @@ RSpec.describe Auth::RegistrationsController do post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } } end - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'redirects to setup' do subject expect(response).to redirect_to auth_setup_path @@ -146,12 +128,6 @@ RSpec.describe Auth::RegistrationsController do post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'false' } } end - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'does not create user' do subject user = User.find_by(email: 'test@example.com') @@ -166,12 +142,6 @@ RSpec.describe Auth::RegistrationsController do post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } } end - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'redirects to setup' do subject expect(response).to redirect_to auth_setup_path @@ -194,12 +164,6 @@ RSpec.describe Auth::RegistrationsController do post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } } end - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - it 'redirects to setup' do subject expect(response).to redirect_to auth_setup_path @@ -224,14 +188,6 @@ RSpec.describe Auth::RegistrationsController do post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } } end - around do |example| - registrations_mode = Setting.registrations_mode - require_invite_text = Setting.require_invite_text - example.run - Setting.require_invite_text = require_invite_text - Setting.registrations_mode = registrations_mode - end - it 'redirects to setup' do subject expect(response).to redirect_to auth_setup_path diff --git a/spec/controllers/concerns/account_controller_concern_spec.rb b/spec/controllers/concerns/account_controller_concern_spec.rb index 56ffcfb047..e3295204aa 100644 --- a/spec/controllers/concerns/account_controller_concern_spec.rb +++ b/spec/controllers/concerns/account_controller_concern_spec.rb @@ -11,12 +11,6 @@ describe AccountControllerConcern do end end - around do |example| - registrations_mode = Setting.registrations_mode - example.run - Setting.registrations_mode = registrations_mode - end - before do routes.draw { get 'success' => 'anonymous#success' } end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 0a55770bad..ef1463e64c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -292,12 +292,6 @@ describe ApplicationHelper do end describe 'title' do - around do |example| - site_title = Setting.site_title - example.run - Setting.site_title = site_title - end - it 'returns site title on production environment' do Setting.site_title = 'site title' allow(Rails.env).to receive(:production?).and_return(true) @@ -318,12 +312,6 @@ describe ApplicationHelper do allow(Rails.env).to receive(:production?).and_return(true) end - around do |example| - site_title = Setting.site_title - example.run - Setting.site_title = site_title - end - context 'with a page_title content_for value' do it 'uses the value in the html title' do Setting.site_title = 'Site Title' diff --git a/spec/helpers/instance_helper_spec.rb b/spec/helpers/instance_helper_spec.rb index cdbce56598..7e39b7cb3d 100644 --- a/spec/helpers/instance_helper_spec.rb +++ b/spec/helpers/instance_helper_spec.rb @@ -4,12 +4,6 @@ require 'rails_helper' describe InstanceHelper do describe 'site_title' do - around do |example| - site_title = Setting.site_title - example.run - Setting.site_title = site_title - end - it 'Uses the Setting.site_title value when it exists' do Setting.site_title = 'New site title' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a2f8d2ca44..9111fd7c73 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -175,16 +175,8 @@ RSpec.describe User do let(:user) { Fabricate(:user, confirmed_at: nil, unconfirmed_email: new_email) } context 'when the user is already approved' do - around do |example| - registrations_mode = Setting.registrations_mode - Setting.registrations_mode = 'approved' - - example.run - - Setting.registrations_mode = registrations_mode - end - before do + Setting.registrations_mode = 'approved' user.approve! end @@ -199,13 +191,8 @@ RSpec.describe User do end context 'when the user does not require explicit approval' do - around do |example| - registrations_mode = Setting.registrations_mode + before do Setting.registrations_mode = 'open' - - example.run - - Setting.registrations_mode = registrations_mode end it 'sets email to unconfirmed_email' do @@ -219,13 +206,8 @@ RSpec.describe User do end context 'when the user requires explicit approval but is not approved' do - around do |example| - registrations_mode = Setting.registrations_mode + before do Setting.registrations_mode = 'approved' - - example.run - - Setting.registrations_mode = registrations_mode end it 'sets email to unconfirmed_email' do @@ -243,16 +225,8 @@ RSpec.describe User do describe '#approve!' do subject { user.approve! } - around do |example| - registrations_mode = Setting.registrations_mode - Setting.registrations_mode = 'approved' - - example.run - - Setting.registrations_mode = registrations_mode - end - before do + Setting.registrations_mode = 'approved' allow(TriggerWebhookWorker).to receive(:perform_async) end diff --git a/spec/presenters/instance_presenter_spec.rb b/spec/presenters/instance_presenter_spec.rb index 2a1d668ceb..516c7e9896 100644 --- a/spec/presenters/instance_presenter_spec.rb +++ b/spec/presenters/instance_presenter_spec.rb @@ -6,12 +6,6 @@ describe InstancePresenter do let(:instance_presenter) { described_class.new } describe '#description' do - around do |example| - site_description = Setting.site_short_description - example.run - Setting.site_short_description = site_description - end - it 'delegates site_description to Setting' do Setting.site_short_description = 'Site desc' expect(instance_presenter.description).to eq 'Site desc' @@ -19,12 +13,6 @@ describe InstancePresenter do end describe '#extended_description' do - around do |example| - site_extended_description = Setting.site_extended_description - example.run - Setting.site_extended_description = site_extended_description - end - it 'delegates site_extended_description to Setting' do Setting.site_extended_description = 'Extended desc' expect(instance_presenter.extended_description).to eq 'Extended desc' @@ -32,12 +20,6 @@ describe InstancePresenter do end describe '#email' do - around do |example| - site_contact_email = Setting.site_contact_email - example.run - Setting.site_contact_email = site_contact_email - end - it 'delegates contact_email to Setting' do Setting.site_contact_email = 'admin@example.com' expect(instance_presenter.contact.email).to eq 'admin@example.com' @@ -45,12 +27,6 @@ describe InstancePresenter do end describe '#account' do - around do |example| - site_contact_username = Setting.site_contact_username - example.run - Setting.site_contact_username = site_contact_username - end - it 'returns the account for the site contact username' do Setting.site_contact_username = 'aaa' account = Fabricate(:account, username: 'aaa') diff --git a/spec/requests/api/v1/instances/activity_spec.rb b/spec/requests/api/v1/instances/activity_spec.rb index d1f92ef36e..4f2bc91ad6 100644 --- a/spec/requests/api/v1/instances/activity_spec.rb +++ b/spec/requests/api/v1/instances/activity_spec.rb @@ -4,12 +4,6 @@ require 'rails_helper' RSpec.describe 'Activity' do describe 'GET /api/v1/instance/activity' do - around do |example| - original = Setting.activity_api_enabled - example.run - Setting.activity_api_enabled = original - end - context 'with activity api enabled' do before { Setting.activity_api_enabled = true } diff --git a/spec/requests/api/v1/instances/domain_blocks_spec.rb b/spec/requests/api/v1/instances/domain_blocks_spec.rb index 99b5e2b6aa..397ecff084 100644 --- a/spec/requests/api/v1/instances/domain_blocks_spec.rb +++ b/spec/requests/api/v1/instances/domain_blocks_spec.rb @@ -4,12 +4,6 @@ require 'rails_helper' RSpec.describe 'Domain Blocks' do describe 'GET /api/v1/instance/domain_blocks' do - around do |example| - original = Setting.show_domain_blocks - example.run - Setting.show_domain_blocks = original - end - before do Fabricate(:domain_block) end diff --git a/spec/requests/api/v1/instances/peers_spec.rb b/spec/requests/api/v1/instances/peers_spec.rb index d3400ae8fd..1a7975f8b7 100644 --- a/spec/requests/api/v1/instances/peers_spec.rb +++ b/spec/requests/api/v1/instances/peers_spec.rb @@ -4,12 +4,6 @@ require 'rails_helper' RSpec.describe 'Peers' do describe 'GET /api/v1/instance/peers' do - around do |example| - original = Setting.peers_api_enabled - example.run - Setting.peers_api_enabled = original - end - context 'with peers api enabled' do before { Setting.peers_api_enabled = true } diff --git a/spec/requests/cache_spec.rb b/spec/requests/cache_spec.rb index ce73d3af75..dbba228740 100644 --- a/spec/requests/cache_spec.rb +++ b/spec/requests/cache_spec.rb @@ -242,17 +242,11 @@ describe 'Caching behavior' do end describe '/api/v1/instance/domain_blocks' do - around do |example| - old_setting = Setting.show_domain_blocks + before do Setting.show_domain_blocks = show_domain_blocks - - example.run - - Setting.show_domain_blocks = old_setting + get '/api/v1/instance/domain_blocks' end - before { get '/api/v1/instance/domain_blocks' } - context 'when set to be publicly-available' do let(:show_domain_blocks) { 'all' } @@ -365,16 +359,8 @@ describe 'Caching behavior' do end describe '/api/v1/instance/domain_blocks' do - around do |example| - old_setting = Setting.show_domain_blocks - Setting.show_domain_blocks = show_domain_blocks - - example.run - - Setting.show_domain_blocks = old_setting - end - before do + Setting.show_domain_blocks = show_domain_blocks get '/api/v1/instance/domain_blocks', headers: { 'Authorization' => "Bearer #{token.token}" } end diff --git a/spec/services/app_sign_up_service_spec.rb b/spec/services/app_sign_up_service_spec.rb index d5946cf9b0..0adb473f17 100644 --- a/spec/services/app_sign_up_service_spec.rb +++ b/spec/services/app_sign_up_service_spec.rb @@ -28,13 +28,8 @@ RSpec.describe AppSignUpService, type: :service do end context 'when registrations are closed' do - around do |example| - tmp = Setting.registrations_mode + before do Setting.registrations_mode = 'none' - - example.run - - Setting.registrations_mode = tmp end it 'raises an error', :aggregate_failures do