branding_controller_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::Settings::BrandingController, type: :controller do
  4. render_views
  5. describe 'When signed in as an admin' do
  6. before do
  7. sign_in Fabricate(:user, role: UserRole.find_by(name: 'Admin')), scope: :user
  8. end
  9. describe 'GET #show' do
  10. it 'returns http success' do
  11. get :show
  12. expect(response).to have_http_status(200)
  13. end
  14. end
  15. describe 'PUT #update' do
  16. before do
  17. allow_any_instance_of(Form::AdminSettings).to receive(:valid?).and_return(true)
  18. end
  19. around do |example|
  20. before = Setting.site_short_description
  21. Setting.site_short_description = nil
  22. example.run
  23. Setting.site_short_description = before
  24. Setting.new_setting_key = nil
  25. end
  26. it 'cannot create a setting value for a non-admin key' do
  27. expect(Setting.new_setting_key).to be_blank
  28. patch :update, params: { form_admin_settings: { new_setting_key: 'New key value' } }
  29. expect(response).to redirect_to(admin_settings_branding_path)
  30. expect(Setting.new_setting_key).to be_nil
  31. end
  32. it 'creates a settings value that didnt exist before for eligible key' do
  33. expect(Setting.site_short_description).to be_blank
  34. patch :update, params: { form_admin_settings: { site_short_description: 'New key value' } }
  35. expect(response).to redirect_to(admin_settings_branding_path)
  36. expect(Setting.site_short_description).to eq 'New key value'
  37. end
  38. end
  39. end
  40. end