Skip to content

Commit 3e42d3f

Browse files
committed
feat: Add GET route for sign out on static error pages
- Add GET route for sign out in devise_scope block in routes - Add sign_out action to sessions controller - Add feature tests for logout on error pages - Remove data-method="delete" from error pages
1 parent 0269df1 commit 3e42d3f

7 files changed

Lines changed: 63 additions & 4 deletions

File tree

app/controllers/users/sessions_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def create
2121
UsersRole.set_last_role_for(current_user, @role)
2222
end
2323

24+
# GET /resource/sign_out
25+
def sign_out
26+
sign_out(current_user) if user_signed_in?
27+
redirect_to root_path, notice: "Signed out successfully"
28+
end
29+
2430
# DELETE /resource/sign_out
2531
# def destroy
2632
# super

config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ def set_up_flipper
1414
omniauth_callbacks: 'users/omniauth_callbacks'
1515
}
1616

17+
devise_scope :user do
18+
get 'users/sign_out', to: 'users/sessions#sign_out', as: :user_sign_out
19+
end
20+
1721
#
1822
# Mount web interface to see delayed job status and queue length.
1923
# Visible only to logged in users with the `super_admin` role

public/403.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<div class="navbar-custom-menu">
3535
<ul class="nav navbar-nav">
3636
<li class="user user-menu">
37-
<a rel="nofollow" class=" btn btn-danger btn-md " data-method="delete" href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
37+
<a rel="nofollow" class=" btn btn-danger btn-md " href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
3838
</li>
3939
</ul>
4040
</div>

public/404.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<div class="navbar-custom-menu">
3636
<ul class="nav navbar-nav">
3737
<li class="user user-menu">
38-
<a rel="nofollow" class=" btn btn-danger btn-md " data-method="delete" href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
38+
<a rel="nofollow" class=" btn btn-danger btn-md " href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
3939
</li>
4040
</ul>
4141
</div>

public/422.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<div class="navbar-custom-menu">
3434
<ul class="nav navbar-nav">
3535
<li class="user user-menu">
36-
<a rel="nofollow" class=" btn btn-danger btn-md " data-method="delete" href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
36+
<a rel="nofollow" class=" btn btn-danger btn-md " href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
3737
</li>
3838
</ul>
3939
</div>

public/500.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<div class="navbar-custom-menu">
3434
<ul class="nav navbar-nav">
3535
<li class="user user-menu">
36-
<a rel="nofollow" class=" btn btn-danger btn-md " data-method="delete" href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
36+
<a rel="nofollow" class=" btn btn-danger btn-md " href="/users/sign_out"><i class="fa fa-sign-out"></i> Log out</a>
3737
</li>
3838
</ul>
3939
</div>

spec/features/error_pages_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Error Pages", type: :feature do
4+
let(:user) { create(:user) }
5+
6+
before do
7+
sign_in(user)
8+
end
9+
10+
context "on 403 error page" do
11+
it "allows user to log out" do
12+
visit "/403"
13+
expect(page).to have_link("Log out")
14+
15+
click_link "Log out"
16+
expect(page).to have_content("Signed out successfully")
17+
end
18+
end
19+
20+
context "on 404 error page" do
21+
it "allows user to log out" do
22+
visit "/404"
23+
expect(page).to have_link("Log out")
24+
25+
click_link "Log out"
26+
expect(page).to have_content("Signed out successfully")
27+
end
28+
end
29+
30+
context "on 422 error page" do
31+
it "allows user to log out" do
32+
visit "/422"
33+
expect(page).to have_link("Log out")
34+
35+
click_link "Log out"
36+
expect(page).to have_content("Signed out successfully")
37+
end
38+
end
39+
40+
context "on 500 error page" do
41+
it "allows user to log out" do
42+
visit "/500"
43+
expect(page).to have_link("Log out")
44+
45+
click_link "Log out"
46+
expect(page).to have_content("Signed out successfully")
47+
end
48+
end
49+
end

0 commit comments

Comments
 (0)