1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 07:09:39 +02:00

Use DB for auth sessions (#1233)

* DB sessions

* Validations for profile image
This commit is contained in:
Zach Gollwitzer 2024-10-03 14:42:22 -04:00 committed by GitHub
parent 82c298307d
commit 1ffa13f3b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 118 additions and 76 deletions

View file

@ -24,14 +24,6 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
end
end
test "sets last_login_at on successful registration" do
post registration_url, params: { user: {
email: "john@example.com",
password: "password",
password_confirmation: "password" } }
assert_not_nil User.find_by(email: "john@example.com").last_login_at
end
test "create when hosted requires an invite code" do
with_env_overrides REQUIRE_INVITE_CODE: "true" do
assert_no_difference "User.count" do

View file

@ -5,14 +5,30 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
@user = users(:family_admin)
end
test "can sign in" do
post session_url, params: { email: @user.email, password: "password" }
assert_redirected_to root_url
test "login page" do
get new_session_url
assert_response :success
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
test "can sign in" do
sign_in @user
assert_redirected_to root_url
get root_url
assert_response :success
end
test "fails to sign in with bad password" do
post sessions_url, params: { email: @user.email, password: "bad" }
assert_response :unprocessable_entity
assert_equal "Invalid email or password.", flash[:alert]
end
test "can sign out" do
sign_in @user
delete session_url(@user.sessions.order(:created_at).last)
assert_redirected_to root_url
assert_equal "You have signed out successfully.", flash[:notice]
end
end

4
test/fixtures/sessions.yml vendored Normal file
View file

@ -0,0 +1,4 @@
one:
user: family_admin
user_agent: MyString
ip_address: MyString

View file

@ -3,7 +3,7 @@ require "test_helper"
class CurrentTest < ActiveSupport::TestCase
test "family returns user family" do
user = users(:family_admin)
Current.user = user
Current.session = user.sessions.create!
assert_equal user.family, Current.family
end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class SessionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -49,7 +49,7 @@ module ActiveSupport
# Add more helper methods to be used by all tests here...
def sign_in(user)
post session_path, params: { email: user.email, password: "password" }
post sessions_path, params: { email: user.email, password: "password" }
end
def with_env_overrides(overrides = {}, &block)