Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ def new
end

def create
if identity = Identity.find_by_email_address(email_address)
magic_link = identity.send_magic_link
serve_development_magic_link(magic_link)
identity = Identity.find_by_email_address(email_address)

magic_link = if identity
identity.send_magic_link
else
Signup.new(email_address: email_address).create_identity
end

serve_development_magic_link(magic_link)

redirect_to session_magic_link_path
end

Expand Down
9 changes: 6 additions & 3 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest

test "create for a new user" do
untenanted do
assert_no_difference -> { MagicLink.count } do
post session_path,
params: { email_address: "nonexistent-#{SecureRandom.hex(6)}@example.com" }
assert_difference -> { MagicLink.count }, +1 do
assert_difference -> { Identity.count }, +1 do
post session_path,
params: { email_address: "nonexistent-#{SecureRandom.hex(6)}@example.com" }
end
end

assert_redirected_to session_magic_link_path
assert MagicLink.last.for_sign_up?
end
end

Expand Down