The personal finance app for everyone
Set last_login_at only at login instead of every single action (#1017)
Tony Vincent75ded1c18f05
diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rbindex 01a4f297..0f1c6913 100644--- a/app/controllers/concerns/authentication.rb+++ b/app/controllers/concerns/authentication.rb@@ -3,13 +3,11 @@ module Authenticationincluded dobefore_action :authenticate_user!- after_action :set_last_login_at, if: -> { Current.user }endclass_methods dodef skip_authentication(**options)skip_before_action :authenticate_user!, **options- skip_after_action :set_last_login_at, **optionsendend@@ -27,6 +25,7 @@ module AuthenticationCurrent.user = userreset_sessionsession[:user_id] = user.id+ set_last_login_atenddef logoutdiff --git a/test/controllers/registrations_controller_test.rb b/test/controllers/registrations_controller_test.rbindex 1c3169f6..87b4405a 100644--- a/test/controllers/registrations_controller_test.rb+++ b/test/controllers/registrations_controller_test.rb@@ -24,6 +24,14 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTestendend+ test "sets last_login_at on successful registration" do+ post registration_url, params: { user: {+ email: "[email protected]",+ password: "password",+ password_confirmation: "password" } }+ assert_not_nil User.find_by(email: "[email protected]").last_login_at+ end+test "create when hosted requires an invite code" dowith_env_overrides REQUIRE_INVITE_CODE: "true" doassert_no_difference "User.count" dodiff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rbnew file mode 100644index 00000000..43915424--- /dev/null+++ b/test/controllers/sessions_controller_test.rb@@ -0,0 +1,18 @@+require "test_helper"++class SessionsControllerTest < ActionDispatch::IntegrationTest+ setup do+ @user = users(:family_admin)+ end++ test "can sign in" do+ post session_url, params: { email: @user.email, password: "password" }+ assert_redirected_to root_url+ end++ test "sets last_login_at on successful login" do+ assert_changes -> { @user.reload.last_login_at }, from: nil do+ post session_url, params: { email: @user.email, password: "password" }+ end+ end+end