Skip to content

Commit 313181a

Browse files
Add missing active sessions controller
Issues ------ - Closes #42
1 parent 9f40bcf commit 313181a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/generators/rails_mvp_authentication/install_generator.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def perform
1717
create_current_model
1818
create_users_controller
1919
create_user_views
20+
create_active_sessions_controller
2021
create_confirmations_controller
2122
create_confirmation_views
2223
ceate_user_mailer
@@ -105,6 +106,10 @@ def configure_hosts
105106
end
106107
end
107108

109+
def create_active_sessions_controller
110+
template "active_sessions_controller.rb", "app/controllers/active_sessions_controller.rb"
111+
end
112+
108113
def create_active_session_model
109114
template "active_session.rb", "app/models/active_session.rb"
110115
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class ActiveSessionsController < ApplicationController
2+
before_action :authenticate_user!
3+
4+
def destroy
5+
@active_session = current_user.active_sessions.find(params[:id])
6+
7+
@active_session.destroy
8+
9+
if current_user
10+
redirect_to account_path, notice: "Session deleted."
11+
else
12+
forget_active_session
13+
reset_session
14+
redirect_to root_path, notice: "Signed out."
15+
end
16+
end
17+
18+
def destroy_all
19+
forget_active_session
20+
current_user.active_sessions.destroy_all
21+
reset_session
22+
23+
redirect_to root_path, notice: "Signed out."
24+
end
25+
end

test/lib/generators/rails_mvp_authentication/install_generator_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ class RailsMvpAuthentication::InstallGeneratorTest < Rails::Generators::TestCase
253253
end
254254
end
255255

256+
test "should create active sessions controller" do
257+
run_generator
258+
259+
assert_file "app/controllers/active_sessions_controller.rb"
260+
end
261+
256262
private
257263

258264
def backup_file(path)
@@ -290,6 +296,7 @@ def restore_destination
290296
remove_if_exists("app/controllers/passwords_controller.rb")
291297
remove_if_exists("app/views/passwords/new.html.erb")
292298
remove_if_exists("app/views/passwords/edit.html.erb")
299+
remove_if_exists("app/controllers/active_sessions_controller.rb")
293300
remove_if_exists("test")
294301
restore_file("config/routes.rb")
295302
restore_file("config/environments/test.rb")

0 commit comments

Comments
 (0)