From 08fb9d300a01e48559ec4a9239a15dbc4ac6414c Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 3 May 2023 23:44:27 -0400 Subject: [PATCH] Spec coverage for settings/preferences/* controllers (#24825) --- .../settings/preferences/appearance_controller.rb | 2 +- .../base_controller.rb} | 4 ++-- .../settings/preferences/notifications_controller.rb | 2 +- .../settings/preferences/other_controller.rb | 2 +- .../preferences/appearance_controller_spec.rb | 6 ++++++ .../settings/preferences/base_controller_spec.rb | 11 +++++++++++ 6 files changed, 22 insertions(+), 5 deletions(-) rename app/controllers/settings/{preferences_controller.rb => preferences/base_controller.rb} (81%) create mode 100644 spec/controllers/settings/preferences/base_controller_spec.rb diff --git a/app/controllers/settings/preferences/appearance_controller.rb b/app/controllers/settings/preferences/appearance_controller.rb index 80ea57bd2..4d7d12bb7 100644 --- a/app/controllers/settings/preferences/appearance_controller.rb +++ b/app/controllers/settings/preferences/appearance_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Settings::Preferences::AppearanceController < Settings::PreferencesController +class Settings::Preferences::AppearanceController < Settings::Preferences::BaseController private def after_update_redirect_path diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences/base_controller.rb similarity index 81% rename from app/controllers/settings/preferences_controller.rb rename to app/controllers/settings/preferences/base_controller.rb index 281deb64d..faf778a7e 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences/base_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Settings::PreferencesController < Settings::BaseController +class Settings::Preferences::BaseController < Settings::BaseController def show; end def update @@ -15,7 +15,7 @@ class Settings::PreferencesController < Settings::BaseController private def after_update_redirect_path - settings_preferences_path + raise 'Override in controller' end def user_params diff --git a/app/controllers/settings/preferences/notifications_controller.rb b/app/controllers/settings/preferences/notifications_controller.rb index a16ae6a67..66d6c9a2f 100644 --- a/app/controllers/settings/preferences/notifications_controller.rb +++ b/app/controllers/settings/preferences/notifications_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Settings::Preferences::NotificationsController < Settings::PreferencesController +class Settings::Preferences::NotificationsController < Settings::Preferences::BaseController private def after_update_redirect_path diff --git a/app/controllers/settings/preferences/other_controller.rb b/app/controllers/settings/preferences/other_controller.rb index 07eb89a76..a19fbf5c4 100644 --- a/app/controllers/settings/preferences/other_controller.rb +++ b/app/controllers/settings/preferences/other_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Settings::Preferences::OtherController < Settings::PreferencesController +class Settings::Preferences::OtherController < Settings::Preferences::BaseController private def after_update_redirect_path diff --git a/spec/controllers/settings/preferences/appearance_controller_spec.rb b/spec/controllers/settings/preferences/appearance_controller_spec.rb index 083bf4954..9a98a4188 100644 --- a/spec/controllers/settings/preferences/appearance_controller_spec.rb +++ b/spec/controllers/settings/preferences/appearance_controller_spec.rb @@ -31,5 +31,11 @@ describe Settings::Preferences::AppearanceController do expect(response).to redirect_to(settings_preferences_appearance_path) end + + it 'renders show on failure' do + put :update, params: { user: { locale: 'fake option' } } + + expect(response).to render_template('preferences/appearance/show') + end end end diff --git a/spec/controllers/settings/preferences/base_controller_spec.rb b/spec/controllers/settings/preferences/base_controller_spec.rb new file mode 100644 index 000000000..53b3a461e --- /dev/null +++ b/spec/controllers/settings/preferences/base_controller_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Settings::Preferences::BaseController do + describe 'after_update_redirect_path' do + it 'raises error when called' do + expect { described_class.new.send(:after_update_redirect_path) }.to raise_error(/Override/) + end + end +end