2017-05-05 01:12:44 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::SettingsController, type: :controller do
|
2017-04-21 00:18:09 +09:00
|
|
|
render_views
|
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
before do
|
|
|
|
Rails.cache.clear
|
|
|
|
end
|
|
|
|
|
2017-04-21 00:18:09 +09:00
|
|
|
describe 'When signed in as an admin' do
|
2017-04-11 04:27:03 +09:00
|
|
|
before do
|
|
|
|
sign_in Fabricate(:user, admin: true), scope: :user
|
|
|
|
end
|
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
describe 'GET #edit' do
|
2017-04-21 00:18:09 +09:00
|
|
|
it 'returns http success' do
|
2017-05-05 01:12:44 +09:00
|
|
|
get :edit
|
2017-04-21 00:18:09 +09:00
|
|
|
|
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
describe 'for a record that doesnt exist' do
|
|
|
|
after do
|
|
|
|
Setting.new_setting_key = nil
|
|
|
|
end
|
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
it 'cannot create a setting value for a non-admin key' do
|
2017-04-21 00:18:09 +09:00
|
|
|
expect(Setting.new_setting_key).to be_nil
|
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
patch :update, params: { new_setting_key: 'New key value' }
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
patch :update, params: { site_extended_description: 'New key value' }
|
2017-04-21 00:18:09 +09:00
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
|
|
|
expect(Setting.site_extended_description).to eq 'New key value'
|
2017-04-21 00:18:09 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates a settings value' do
|
|
|
|
Setting.site_title = 'Original'
|
2017-05-05 01:12:44 +09:00
|
|
|
patch :update, params: { site_title: 'New title' }
|
2017-04-21 00:18:09 +09:00
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
2017-04-21 00:18:09 +09:00
|
|
|
expect(Setting.site_title).to eq 'New title'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'typecasts open_registrations to boolean' do
|
|
|
|
Setting.open_registrations = false
|
2017-05-05 01:12:44 +09:00
|
|
|
patch :update, params: { open_registrations: 'true' }
|
2017-04-21 00:18:09 +09:00
|
|
|
|
2017-05-05 01:12:44 +09:00
|
|
|
expect(response).to redirect_to(edit_admin_settings_path)
|
2017-04-21 00:18:09 +09:00
|
|
|
expect(Setting.open_registrations).to eq true
|
|
|
|
end
|
2017-04-11 04:27:03 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|