From 87c65577476ca97529d6e2013eed913cacc3cb06 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Mon, 15 Dec 2025 09:47:47 +0000 Subject: [PATCH] Limit length of full name during signup If we don't validate for length, then signups that overflow the database columns will unnecessarily create and cancel a tenant. Adding a validation means we can avoid this. --- app/models/signup.rb | 1 + app/views/signups/completions/new.html.erb | 2 +- test/models/signup_test.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/signup.rb b/app/models/signup.rb index 110c253ef..041f461ac 100644 --- a/app/models/signup.rb +++ b/app/models/signup.rb @@ -8,6 +8,7 @@ class Signup validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }, on: :identity_creation validates :full_name, :identity, presence: true, on: :completion + validates :full_name, length: { maximum: 240 } def initialize(...) super diff --git a/app/views/signups/completions/new.html.erb b/app/views/signups/completions/new.html.erb index 5be760843..6d4c4c6cf 100644 --- a/app/views/signups/completions/new.html.erb +++ b/app/views/signups/completions/new.html.erb @@ -4,7 +4,7 @@

<%= @page_title %>

<%= form_with model: @signup, url: signup_completion_path, scope: "signup", class: "flex flex-column gap", data: { controller: "form" } do |form| %> - <%= form.text_field :full_name, class: "input txt-large", autocomplete: "name", placeholder: "Enter your full name…", autofocus: true, required: true %> + <%= form.text_field :full_name, class: "input txt-large", autocomplete: "name", placeholder: "Enter your full name…", autofocus: true, required: true, maxlength: 240 %>

You're one step away. Just enter your name to get your own Fizzy account.

diff --git a/test/models/signup_test.rb b/test/models/signup_test.rb index 589bcd49a..947d55d6b 100644 --- a/test/models/signup_test.rb +++ b/test/models/signup_test.rb @@ -72,4 +72,17 @@ class SignupTest < ActiveSupport::TestCase assert_nil signup.user end end + + test "#complete with name that is too long" do + Current.without_account do + signup = Signup.new(full_name: "A" * 241, identity: identities(:kevin)) + signup.expects(:create_tenant).never + + assert_not signup.complete + + assert signup.errors[:full_name].any? + assert_nil signup.account + assert_nil signup.user + end + end end