about summary refs log tree commit diff
path: root/spec/controllers/admin/settings
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-10-28 11:36:25 +0200
committerClaire <claire.github-309c@sitedethib.com>2022-10-28 19:23:58 +0200
commitcb19be67d1b47dd04cb5bb88e09f0101a614bd1c (patch)
tree6c85ccc6ac0279ae7b1ed4dff56c8e83f71a0c95 /spec/controllers/admin/settings
parent371563b0e249b6369e04709fb974a8e57413529f (diff)
parent8dfe5179ee7186e549dbe1186a151ffa848fe8ab (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'spec/controllers/admin/settings')
-rw-r--r--spec/controllers/admin/settings/branding_controller_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/controllers/admin/settings/branding_controller_spec.rb b/spec/controllers/admin/settings/branding_controller_spec.rb
new file mode 100644
index 000000000..ee1c441bc
--- /dev/null
+++ b/spec/controllers/admin/settings/branding_controller_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Admin::Settings::BrandingController, type: :controller do
+  render_views
+
+  describe 'When signed in as an admin' do
+    before 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
+      before do
+        allow_any_instance_of(Form::AdminSettings).to receive(:valid?).and_return(true)
+      end
+
+      around do |example|
+        before = Setting.site_short_description
+        Setting.site_short_description = nil
+        example.run
+        Setting.site_short_description = before
+        Setting.new_setting_key = nil
+      end
+
+      it 'cannot create a setting value for a non-admin key' do
+        expect(Setting.new_setting_key).to be_blank
+
+        patch :update, params: { form_admin_settings: { new_setting_key: 'New key value' } }
+
+        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