diff options
author | Matt Jankowski <mjankowski@thoughtbot.com> | 2017-04-20 11:18:09 -0400 |
---|---|---|
committer | Eugen <eugen@zeonfederated.com> | 2017-04-20 17:18:09 +0200 |
commit | 1ada494bb21658c92a58f8bd9e5cc4d7ebf59b6e (patch) | |
tree | 9032e9e73ff1279ad031a77400530bbd40e6ebbd /spec/controllers | |
parent | 4df26b262184ebc75344369f236e2a37e3722513 (diff) |
Admin settings controller refactor, add specs, cleanup (#2225)
* Add render_views for admin/settings spec * Add coverage for admin/settings#update * Add coverage for admin/settings typecasting open_registrations setting * Simplify how admin/settings finds the value for updating * Rely on activerecord to not update a value that hasnt changed * Add coverage for non-existent setting * Use a constant for boolean settings
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/admin/settings_controller_spec.rb | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb index c126b645b..889f78bc1 100644 --- a/spec/controllers/admin/settings_controller_spec.rb +++ b/spec/controllers/admin/settings_controller_spec.rb @@ -1,14 +1,53 @@ require 'rails_helper' RSpec.describe Admin::SettingsController, type: :controller do - describe 'GET #index' do + render_views + + describe 'When signed in as an admin' do before do sign_in Fabricate(:user, admin: true), scope: :user end - it 'returns http success' do - get :index - expect(response).to have_http_status(:success) + describe 'GET #index' do + it 'returns http success' do + get :index + + 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 + + it 'creates a settings value that didnt exist before' do + expect(Setting.new_setting_key).to be_nil + + patch :update, params: { id: 'new_setting_key', setting: { value: 'New key value' } } + + expect(response).to redirect_to(admin_settings_path) + expect(Setting.new_setting_key).to eq 'New key value' + end + end + + it 'updates a settings value' do + Setting.site_title = 'Original' + patch :update, params: { id: 'site_title', setting: { value: 'New title' } } + + expect(response).to redirect_to(admin_settings_path) + expect(Setting.site_title).to eq 'New title' + end + + it 'typecasts open_registrations to boolean' do + Setting.open_registrations = false + patch :update, params: { id: 'open_registrations', setting: { value: 'true' } } + + expect(response).to redirect_to(admin_settings_path) + expect(Setting.open_registrations).to eq true + end end end end |