Unify sign in and sign up

This commit is contained in:
Stanko K.R.
2025-11-05 08:53:52 +01:00
parent ec540e31b6
commit 3f4d500103
16 changed files with 71 additions and 173 deletions
+37 -28
View File
@@ -1,10 +1,42 @@
require "test_helper"
class SessionsControllerTest < ActionDispatch::IntegrationTest
test "destroy" do
test "new" do
untenanted do
sign_in_as :kevin
get new_session_path
end
assert_response :success
end
test "create" do
identity = identities(:kevin)
untenanted do
assert_difference -> { MagicLink.count }, 1 do
post session_path, params: { email_address: identity.email_address }
end
assert_redirected_to session_magic_link_path
end
end
test "create for a new user" do
untenanted do
assert_difference -> { Identity.count }, +1 do
assert_difference -> { MagicLink.count }, +1 do
post session_path, params: { email_address: "nonexistent@example.com" }, headers: http_basic_auth_headers("testname", "testpassword")
end
end
assert_redirected_to session_magic_link_path
end
end
test "destroy" do
sign_in_as :kevin
untenanted do
delete session_path
assert_redirected_to new_session_path
@@ -12,31 +44,8 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest
end
end
test "new" do
untenanted do
get new_session_path
assert_response :success
private
def http_basic_auth_headers(user, password)
{ "Authorization" => ActionController::HttpAuthentication::Basic.encode_credentials(user, password) }
end
end
test "create" do
untenanted do
identity = identities(:kevin)
assert_difference -> { MagicLink.count }, 1 do
post session_path, params: { email_address: identity.email_address }
end
assert_redirected_to session_magic_link_path
end
untenanted do
assert_no_difference -> { MagicLink.count } do
post session_path, params: { email_address: "nonexistent@example.com" }
end
assert_redirected_to session_magic_link_path
end
end
end