2017-05-04 12:12:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 15:27:03 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::SettingsController, type: :controller do
|
2017-04-20 11:18:09 -04:00
|
|
|
render_views
|
|
|
|
|
|
|
|
describe 'When signed in as an admin' do
|
2017-04-10 15:27:03 -04:00
|
|
|
before do
|
|
|
|
sign_in Fabricate(:user, admin: true), scope: :user
|
|
|
|
end
|
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
describe 'GET #edit' do
|
2017-04-20 11:18:09 -04:00
|
|
|
it 'returns http success' do
|
2017-05-04 12:12:44 -04:00
|
|
|
get :edit
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2018-04-21 15:35:07 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-04-20 11:18:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
describe 'for a record that doesnt exist' do
|
2017-05-04 14:53:39 -04:00
|
|
|
around do |example|
|
|
|
|
before = Setting.site_extended_description
|
|
|
|
Setting.site_extended_description = nil
|
|
|
|
example.run
|
|
|
|
Setting.site_extended_description = before
|
2017-04-20 11:18:09 -04:00
|
|
|
Setting.new_setting_key = nil
|
|
|
|
end
|
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
it 'cannot create a setting value for a non-admin key' do
|
2017-05-04 14:53:39 -04:00
|
|
|
expect(Setting.new_setting_key).to be_blank
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-07-11 21:24:04 -04:00
|
|
|
patch :update, params: { form_admin_settings: { new_setting_key: 'New key value' } }
|
2017-05-04 12:12:44 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(edit_admin_settings_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_extended_description).to be_blank
|
|
|
|
|
2017-07-11 21:24:04 -04:00
|
|
|
patch :update, params: { form_admin_settings: { site_extended_description: 'New key value' } }
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-05-04 12:12:44 -04:00
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
|
|
|
expect(Setting.site_extended_description).to eq 'New key value'
|
2017-04-20 11:18:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-30 06:32:09 -04:00
|
|
|
context do
|
|
|
|
around do |example|
|
|
|
|
site_title = Setting.site_title
|
|
|
|
example.run
|
|
|
|
Setting.site_title = site_title
|
|
|
|
end
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-05-30 06:32:09 -04:00
|
|
|
it 'updates a settings value' do
|
|
|
|
Setting.site_title = 'Original'
|
2017-07-11 21:24:04 -04:00
|
|
|
patch :update, params: { form_admin_settings: { site_title: 'New title' } }
|
2017-05-30 06:32:09 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
|
|
|
expect(Setting.site_title).to eq 'New title'
|
|
|
|
end
|
2017-04-20 11:18:09 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 06:32:09 -04:00
|
|
|
context do
|
|
|
|
around do |example|
|
|
|
|
open_registrations = Setting.open_registrations
|
|
|
|
example.run
|
|
|
|
Setting.open_registrations = open_registrations
|
|
|
|
end
|
2017-04-20 11:18:09 -04:00
|
|
|
|
2017-05-30 06:32:09 -04:00
|
|
|
it 'typecasts open_registrations to boolean' do
|
|
|
|
Setting.open_registrations = false
|
2017-07-11 21:24:04 -04:00
|
|
|
patch :update, params: { form_admin_settings: { open_registrations: '1' } }
|
2017-05-30 06:32:09 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
|
|
|
expect(Setting.open_registrations).to eq true
|
|
|
|
end
|
2017-04-20 11:18:09 -04:00
|
|
|
end
|
2017-04-10 15:27:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|