Render friendly error message when using an invalid token

This commit is contained in:
Stanko K.R.
2025-12-03 15:37:27 +01:00
parent 372d46f2cc
commit 84213265e7
5 changed files with 42 additions and 26 deletions
@@ -3,6 +3,7 @@ require "test_helper"
class Users::EmailAddresses::ConfirmationsControllerTest < ActionDispatch::IntegrationTest
setup do
@user = users(:david)
@old_email = @user.identity.email_address
@new_email = "newemail@example.com"
@token = @user.send(:generate_email_address_change_token, to: @new_email)
end
@@ -13,8 +14,6 @@ class Users::EmailAddresses::ConfirmationsControllerTest < ActionDispatch::Integ
end
test "create" do
old_email = @user.identity.email_address
post user_email_address_confirmation_path(user_id: @user.id, email_address_token: @token, script_name: @user.account.slug)
assert_equal @new_email, @user.reload.identity.email_address
@@ -22,8 +21,10 @@ class Users::EmailAddresses::ConfirmationsControllerTest < ActionDispatch::Integ
end
test "create with invalid token" do
assert_raises(ArgumentError) do
post user_email_address_confirmation_path(user_id: @user.id, email_address_token: "invalid", script_name: @user.account.slug)
end
post user_email_address_confirmation_path(user_id: @user.id, email_address_token: "invalid", script_name: @user.account.slug)
assert_equal @user.identity.email_address, @old_email
assert_response :unprocessable_entity
assert_match /Something went wrong/, response.body
end
end