Pull to concern
This commit is contained in:
parent
cb47e6bb73
commit
28620e27d7
3 changed files with 22 additions and 7 deletions
|
@ -1,9 +1,3 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
before_action :authenticate_user
|
include Authenticatable
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def authenticate_user
|
|
||||||
Current.user = User.find_by(id: session[:current_user_id])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
13
app/controllers/concerns/authenticatable.rb
Normal file
13
app/controllers/concerns/authenticatable.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
module Authenticatable
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
before_action :authenticate_user
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def authenticate_user
|
||||||
|
Current.user = User.find_by(id: session[:current_user_id])
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,6 +17,14 @@ class SessionsTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy Session" do
|
test "should destroy Session" do
|
||||||
|
visit new_session_url
|
||||||
|
|
||||||
|
fill_in "Email", with: @user.email
|
||||||
|
fill_in "Password", with: "secret"
|
||||||
|
|
||||||
|
click_on "Create Session"
|
||||||
|
assert_text "Session was successfully created"
|
||||||
|
|
||||||
visit root_url
|
visit root_url
|
||||||
click_on "Log out", match: :first
|
click_on "Log out", match: :first
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue