mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 10:38:07 +01:00
Convert admin/settings
controller specs to system specs (#31548)
This commit is contained in:
parent
ef4920c6c9
commit
928390c2ba
14 changed files with 170 additions and 162 deletions
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
19
spec/support/system_helpers.rb
Normal file
19
spec/support/system_helpers.rb
Normal file
|
@ -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
|
22
spec/system/admin/settings/about_spec.rb
Normal file
22
spec/system/admin/settings/about_spec.rb
Normal file
|
@ -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
|
22
spec/system/admin/settings/appearance_spec.rb
Normal file
22
spec/system/admin/settings/appearance_spec.rb
Normal file
|
@ -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
|
37
spec/system/admin/settings/branding_spec.rb
Normal file
37
spec/system/admin/settings/branding_spec.rb
Normal file
|
@ -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
|
22
spec/system/admin/settings/content_retention_spec.rb
Normal file
22
spec/system/admin/settings/content_retention_spec.rb
Normal file
|
@ -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
|
21
spec/system/admin/settings/discovery_spec.rb
Normal file
21
spec/system/admin/settings/discovery_spec.rb
Normal file
|
@ -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
|
26
spec/system/admin/settings/registrations_spec.rb
Normal file
26
spec/system/admin/settings/registrations_spec.rb
Normal file
|
@ -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
|
Loading…
Reference in a new issue