From 928390c2ba4e8c6f433025f3eb3ecd89337a2660 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 3 Sep 2024 11:29:32 -0400 Subject: [PATCH] Convert `admin/settings` controller specs to system specs (#31548) --- .../admin/settings/about_controller_spec.rb | 29 --------------- .../settings/appearance_controller_spec.rb | 29 --------------- .../settings/branding_controller_spec.rb | 17 --------- .../content_retention_controller_spec.rb | 29 --------------- .../settings/discovery_controller_spec.rb | 29 --------------- .../settings/registrations_controller_spec.rb | 29 --------------- spec/rails_helper.rb | 1 + spec/support/system_helpers.rb | 19 ++++++++++ spec/system/admin/settings/about_spec.rb | 22 +++++++++++ spec/system/admin/settings/appearance_spec.rb | 22 +++++++++++ spec/system/admin/settings/branding_spec.rb | 37 +++++++++++++++++++ .../admin/settings/content_retention_spec.rb | 22 +++++++++++ spec/system/admin/settings/discovery_spec.rb | 21 +++++++++++ .../admin/settings/registrations_spec.rb | 26 +++++++++++++ 14 files changed, 170 insertions(+), 162 deletions(-) delete mode 100644 spec/controllers/admin/settings/about_controller_spec.rb delete mode 100644 spec/controllers/admin/settings/appearance_controller_spec.rb delete mode 100644 spec/controllers/admin/settings/content_retention_controller_spec.rb delete mode 100644 spec/controllers/admin/settings/discovery_controller_spec.rb delete mode 100644 spec/controllers/admin/settings/registrations_controller_spec.rb create mode 100644 spec/support/system_helpers.rb create mode 100644 spec/system/admin/settings/about_spec.rb create mode 100644 spec/system/admin/settings/appearance_spec.rb create mode 100644 spec/system/admin/settings/branding_spec.rb create mode 100644 spec/system/admin/settings/content_retention_spec.rb create mode 100644 spec/system/admin/settings/discovery_spec.rb create mode 100644 spec/system/admin/settings/registrations_spec.rb diff --git a/spec/controllers/admin/settings/about_controller_spec.rb b/spec/controllers/admin/settings/about_controller_spec.rb deleted file mode 100644 index f322cb4434..0000000000 --- a/spec/controllers/admin/settings/about_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Admin::Settings::AboutController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - it 'updates the settings' do - put :update, params: { form_admin_settings: { site_extended_description: 'new site description' } } - - expect(response).to redirect_to(admin_settings_about_path) - end - end -end diff --git a/spec/controllers/admin/settings/appearance_controller_spec.rb b/spec/controllers/admin/settings/appearance_controller_spec.rb deleted file mode 100644 index ea6f3b7833..0000000000 --- a/spec/controllers/admin/settings/appearance_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Admin::Settings::AppearanceController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - it 'updates the settings' do - put :update, params: { form_admin_settings: { custom_css: 'html { display: inline; }' } } - - expect(response).to redirect_to(admin_settings_appearance_path) - end - end -end diff --git a/spec/controllers/admin/settings/branding_controller_spec.rb b/spec/controllers/admin/settings/branding_controller_spec.rb index e30300b4e4..5e46910cc6 100644 --- a/spec/controllers/admin/settings/branding_controller_spec.rb +++ b/spec/controllers/admin/settings/branding_controller_spec.rb @@ -10,14 +10,6 @@ RSpec.describe Admin::Settings::BrandingController do sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user end - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(200) - end - end - describe 'PUT #update' do it 'cannot create a setting value for a non-admin key' do expect(Setting.new_setting_key).to be_blank @@ -27,15 +19,6 @@ RSpec.describe Admin::Settings::BrandingController do expect(response).to redirect_to(admin_settings_branding_path) expect(Setting.new_setting_key).to be_nil end - - it 'creates a settings value that didnt exist before for eligible key' do - expect(Setting.site_short_description).to be_blank - - patch :update, params: { form_admin_settings: { site_short_description: 'New key value' } } - - expect(response).to redirect_to(admin_settings_branding_path) - expect(Setting.site_short_description).to eq 'New key value' - end end end end diff --git a/spec/controllers/admin/settings/content_retention_controller_spec.rb b/spec/controllers/admin/settings/content_retention_controller_spec.rb deleted file mode 100644 index fb6a3d2848..0000000000 --- a/spec/controllers/admin/settings/content_retention_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Admin::Settings::ContentRetentionController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - it 'updates the settings' do - put :update, params: { form_admin_settings: { media_cache_retention_period: '2' } } - - expect(response).to redirect_to(admin_settings_content_retention_path) - end - end -end diff --git a/spec/controllers/admin/settings/discovery_controller_spec.rb b/spec/controllers/admin/settings/discovery_controller_spec.rb deleted file mode 100644 index 33109e3c01..0000000000 --- a/spec/controllers/admin/settings/discovery_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Admin::Settings::DiscoveryController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - it 'updates the settings' do - put :update, params: { form_admin_settings: { trends: '1' } } - - expect(response).to redirect_to(admin_settings_discovery_path) - end - end -end diff --git a/spec/controllers/admin/settings/registrations_controller_spec.rb b/spec/controllers/admin/settings/registrations_controller_spec.rb deleted file mode 100644 index e076544603..0000000000 --- a/spec/controllers/admin/settings/registrations_controller_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Admin::Settings::RegistrationsController do - render_views - - let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - - expect(response).to have_http_status(:success) - end - end - - describe 'PUT #update' do - it 'updates the settings' do - put :update, params: { form_admin_settings: { registrations_mode: 'open' } } - - expect(response).to redirect_to(admin_settings_registrations_path) - end - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0c3d01c785..2a602d113a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -112,6 +112,7 @@ RSpec.configure do |config| config.include ThreadingHelpers config.include SignedRequestHelpers, type: :request config.include CommandLineHelpers, type: :cli + config.include SystemHelpers, type: :system config.around(:each, use_transactional_tests: false) do |example| self.use_transactional_tests = false diff --git a/spec/support/system_helpers.rb b/spec/support/system_helpers.rb new file mode 100644 index 0000000000..05c9d3b125 --- /dev/null +++ b/spec/support/system_helpers.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module SystemHelpers + def admin_user + Fabricate(:user, role: UserRole.find_by(name: 'Admin')) + end + + def submit_button + I18n.t('generic.save_changes') + end + + def success_message + I18n.t('generic.changes_saved_msg') + end + + def form_label(key) + I18n.t key, scope: 'simple_form.labels' + end +end diff --git a/spec/system/admin/settings/about_spec.rb b/spec/system/admin/settings/about_spec.rb new file mode 100644 index 0000000000..0f8ae5605c --- /dev/null +++ b/spec/system/admin/settings/about_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::About' do + it 'Saves changes to about settings' do + sign_in admin_user + visit admin_settings_about_path + + fill_in extended_description_field, + with: 'new site description' + + click_on submit_button + + expect(page) + .to have_content(success_message) + end + + def extended_description_field + form_label 'form_admin_settings.site_extended_description' + end +end diff --git a/spec/system/admin/settings/appearance_spec.rb b/spec/system/admin/settings/appearance_spec.rb new file mode 100644 index 0000000000..99e97ea4d1 --- /dev/null +++ b/spec/system/admin/settings/appearance_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::Appearance' do + it 'Saves changes to appearance settings' do + sign_in admin_user + visit admin_settings_appearance_path + + fill_in custom_css_field, + with: 'html { display: inline; }' + + click_on submit_button + + expect(page) + .to have_content(success_message) + end + + def custom_css_field + form_label 'form_admin_settings.custom_css' + end +end diff --git a/spec/system/admin/settings/branding_spec.rb b/spec/system/admin/settings/branding_spec.rb new file mode 100644 index 0000000000..ac47e04d53 --- /dev/null +++ b/spec/system/admin/settings/branding_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::Branding' do + it 'Saves changes to branding settings' do + sign_in admin_user + visit admin_settings_branding_path + + fill_in short_description_field, + with: 'new key value' + + fill_in site_contact_email_field, + with: User.last.email + + fill_in site_contact_username_field, + with: Account.last.username + + expect { click_on submit_button } + .to change(Setting, :site_short_description).to('new key value') + + expect(page) + .to have_content(success_message) + end + + def short_description_field + form_label 'form_admin_settings.site_short_description' + end + + def site_contact_email_field + form_label 'form_admin_settings.site_contact_email' + end + + def site_contact_username_field + form_label 'form_admin_settings.site_contact_username' + end +end diff --git a/spec/system/admin/settings/content_retention_spec.rb b/spec/system/admin/settings/content_retention_spec.rb new file mode 100644 index 0000000000..9867122675 --- /dev/null +++ b/spec/system/admin/settings/content_retention_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::ContentRetention' do + it 'Saves changes to content retention settings' do + sign_in admin_user + visit admin_settings_content_retention_path + + fill_in media_cache_retention_period_field, + with: '2' + + click_on submit_button + + expect(page) + .to have_content(success_message) + end + + def media_cache_retention_period_field + form_label 'form_admin_settings.media_cache_retention_period' + end +end diff --git a/spec/system/admin/settings/discovery_spec.rb b/spec/system/admin/settings/discovery_spec.rb new file mode 100644 index 0000000000..bdab91107d --- /dev/null +++ b/spec/system/admin/settings/discovery_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::Discovery' do + it 'Saves changes to discovery settings' do + sign_in admin_user + visit admin_settings_discovery_path + + check trends_box + + click_on submit_button + + expect(page) + .to have_content(success_message) + end + + def trends_box + form_label 'form_admin_settings.trends' + end +end diff --git a/spec/system/admin/settings/registrations_spec.rb b/spec/system/admin/settings/registrations_spec.rb new file mode 100644 index 0000000000..88c750e8ee --- /dev/null +++ b/spec/system/admin/settings/registrations_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Admin::Settings::Registrations' do + it 'Saves changes to registrations settings' do + sign_in admin_user + visit admin_settings_registrations_path + + select open_mode_option, + from: registrations_mode_field + + click_on submit_button + + expect(page) + .to have_content(success_message) + end + + def open_mode_option + I18n.t('admin.settings.registrations_mode.modes.open') + end + + def registrations_mode_field + form_label 'form_admin_settings.registrations_mode' + end +end