From c09d232ee33f14a17b32ead7caa3aa2332d4b3d3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 27 Aug 2024 03:42:35 -0400 Subject: [PATCH] Convert `api/web/settings` controller spec to request spec (#31606) --- .../api/web/settings_controller_spec.rb | 24 ----------- spec/requests/api/web/settings_spec.rb | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 24 deletions(-) delete mode 100644 spec/controllers/api/web/settings_controller_spec.rb create mode 100644 spec/requests/api/web/settings_spec.rb diff --git a/spec/controllers/api/web/settings_controller_spec.rb b/spec/controllers/api/web/settings_controller_spec.rb deleted file mode 100644 index 815da04c47..0000000000 --- a/spec/controllers/api/web/settings_controller_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Api::Web::SettingsController do - render_views - - let!(:user) { Fabricate(:user) } - - describe 'PATCH #update' do - it 'redirects to about page' do - sign_in(user) - patch :update, format: :json, params: { data: { 'onboarded' => true } } - - user.reload - expect(response).to have_http_status(200) - expect(user_web_setting.data['onboarded']).to eq('true') - end - - def user_web_setting - Web::Setting.where(user: user).first - end - end -end diff --git a/spec/requests/api/web/settings_spec.rb b/spec/requests/api/web/settings_spec.rb new file mode 100644 index 0000000000..81b8b44953 --- /dev/null +++ b/spec/requests/api/web/settings_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe '/api/web/settings' do + describe 'PATCH /api/web/settings' do + let(:user) { Fabricate :user } + + context 'when signed in' do + before { sign_in(user) } + + it 'updates setting and responds with success' do + patch '/api/web/settings', params: { data: { 'onboarded' => true } } + + expect(user_web_setting.data) + .to include('onboarded' => 'true') + + expect(response) + .to have_http_status(200) + end + end + + context 'when not signed in' do + it 'responds with unprocessable and does not modify setting' do + patch '/api/web/settings', params: { data: { 'onboarded' => true } } + + expect(user_web_setting) + .to be_nil + + expect(response) + .to have_http_status(422) + end + end + + def user_web_setting + Web::Setting + .where(user: user) + .first + end + end +end