diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index a17d196660..27e43b93d4 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -21,6 +21,12 @@ def create UsersRole.set_last_role_for(current_user, @role) end + # GET /resource/sign_out + def sign_out_error_page + sign_out(current_user) if user_signed_in? + redirect_to root_path, notice: "Signed out successfully" + end + # DELETE /resource/sign_out # def destroy # super diff --git a/config/routes.rb b/config/routes.rb index 0c0d275a36..ef61303f67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,10 @@ def set_up_flipper omniauth_callbacks: 'users/omniauth_callbacks' } + devise_scope :user do + get 'users/sign_out', to: 'users/sessions#sign_out_error_page', as: :user_sign_out + end + # # Mount web interface to see delayed job status and queue length. # Visible only to logged in users with the `super_admin` role diff --git a/public/403.html b/public/403.html index 233a2b2e47..634ab0090d 100644 --- a/public/403.html +++ b/public/403.html @@ -34,7 +34,7 @@ diff --git a/public/404.html b/public/404.html index bb6356bebd..4ea354538a 100644 --- a/public/404.html +++ b/public/404.html @@ -35,7 +35,7 @@ diff --git a/public/422.html b/public/422.html index 057cb5032c..0df3724f83 100644 --- a/public/422.html +++ b/public/422.html @@ -33,7 +33,7 @@ diff --git a/public/500.html b/public/500.html index b589b6445c..9d105bc690 100644 --- a/public/500.html +++ b/public/500.html @@ -33,7 +33,7 @@ diff --git a/spec/features/error_pages_spec.rb b/spec/features/error_pages_spec.rb new file mode 100644 index 0000000000..62d9c9e2d1 --- /dev/null +++ b/spec/features/error_pages_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe "Error Pages", type: :feature do + let(:user) { create(:user) } + + before do + sign_in(user) + end + + context "on 403 error page" do + it "allows user to log out" do + visit "/403" + expect(page).to have_link("Log out") + + click_link "Log out" + expect(page).to have_content("Signed out successfully") + end + end + + context "on 404 error page" do + it "allows user to log out" do + visit "/404" + expect(page).to have_link("Log out") + + click_link "Log out" + expect(page).to have_content("Signed out successfully") + end + end + + context "on 422 error page" do + it "allows user to log out" do + visit "/422" + expect(page).to have_link("Log out") + + click_link "Log out" + expect(page).to have_content("Signed out successfully") + end + end + + context "on 500 error page" do + it "allows user to log out" do + visit "/500" + expect(page).to have_link("Log out") + + click_link "Log out" + expect(page).to have_content("Signed out successfully") + end + end +end