mirror of
https://github.com/we-promise/sure.git
synced 2026-05-08 13:14:58 +00:00
Fix invite code being consumed on failed registration in invite-only mode (#1576)
* Fix:Bug:invite-code-inproper-burn * added docstring according to coderabbitai warning * updated feedback for merge
This commit is contained in:
@@ -59,15 +59,46 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
assert_difference "User.count", +1 do
|
||||
invite_code = InviteCode.generate!
|
||||
post registration_url, params: { user: {
|
||||
email: "john@example.com",
|
||||
password: "Password1!",
|
||||
invite_code: InviteCode.generate! } }
|
||||
invite_code: invite_code } }
|
||||
assert_redirected_to root_url
|
||||
assert_not InviteCode.exists?(token: invite_code)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "invite code is not consumed when signup fails validation" do
|
||||
with_env_overrides REQUIRE_INVITE_CODE: "true" do
|
||||
invite_code = InviteCode.generate!
|
||||
|
||||
assert_no_difference "User.count" do
|
||||
post registration_url, params: { user: {
|
||||
email: "validationfail@example.com",
|
||||
password: "weak",
|
||||
invite_code: invite_code } }
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
assert InviteCode.exists?(token: invite_code)
|
||||
end
|
||||
end
|
||||
|
||||
test "invalid invite code does not create a user" do
|
||||
with_env_overrides REQUIRE_INVITE_CODE: "true" do
|
||||
assert_no_difference "User.count" do
|
||||
post registration_url, params: { user: {
|
||||
email: "valid@example.com",
|
||||
password: "Password1!",
|
||||
invite_code: "invalid-token-that-does-not-exist" } }
|
||||
end
|
||||
|
||||
assert_redirected_to new_registration_url
|
||||
end
|
||||
end
|
||||
|
||||
test "creating account from guest invitation assigns guest role and intro layout" do
|
||||
invitation = invitations(:one)
|
||||
invitation.update!(role: "guest", email: "guest-signup@example.com")
|
||||
|
||||
Reference in New Issue
Block a user