From 28620e27d7b439b8abdaf420f0d2e5ef3f568c0a Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 16 Aug 2024 19:21:44 -0400 Subject: [PATCH] Pull to concern --- app/controllers/application_controller.rb | 8 +------- app/controllers/concerns/authenticatable.rb | 13 +++++++++++++ test/system/sessions_test.rb | 8 ++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 app/controllers/concerns/authenticatable.rb 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