diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1a6caa2..1374ee0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,3 @@ class ApplicationController < ActionController::Base - before_action :authenticate_user - - private - - def authenticate_user - Current.user = User.find_by(id: session[:current_user_id]) - end + include Authenticatable end diff --git a/app/controllers/concerns/authenticatable.rb b/app/controllers/concerns/authenticatable.rb new file mode 100644 index 0000000..9314cc9 --- /dev/null +++ b/app/controllers/concerns/authenticatable.rb @@ -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 diff --git a/test/system/sessions_test.rb b/test/system/sessions_test.rb index 7715288..d0ea7fc 100644 --- a/test/system/sessions_test.rb +++ b/test/system/sessions_test.rb @@ -17,6 +17,14 @@ class SessionsTest < ApplicationSystemTestCase end 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 click_on "Log out", match: :first