From 9d808a18df0713506ced79ed08771d296f01354a Mon Sep 17 00:00:00 2001 From: Petterson <58094725+hahuma@users.noreply.github.com> Date: Fri, 5 Jun 2026 03:03:24 -0300 Subject: [PATCH] fix(drops): Resolve first_name for single-word contact and agent names (#13488) WhatsApp template variables like `{{contact.first_name}}` previously resolved to an empty string whenever a contact or agent had a single-word name (e.g. "Petterson"). Because the variable came back blank, WhatsApp template sends would either fail validation or get stuck indefinitely in the "Sending" state. With this fix, `first_name` falls back to the full single-word name, so templates render correctly for everyone regardless of how many words their name has. ## Closes - Fixes #13222 ## How to reproduce 1. Create a contact with a single-word name (e.g. `Petterson`). 2. Configure a WhatsApp template action that uses `{{contact.first_name}}`. 3. Send the template message. 4. **Before:** the variable resolves to an empty string and the message fails / stays in "Sending". **After:** the variable resolves to `Petterson` and the message sends. ## What changed - Removed the "name must have 2+ words" guard from `first_name` in `ContactDrop` and `UserDrop`, so a single-word name is returned (still capitalized). - Capitalization behavior introduced in #6758 is preserved; only the single-word edge case changes. - `last_name` still returns `nil` for single-word names, which is the expected behavior. - Added specs covering single-word names for both `ContactDrop` and `UserDrop`. --------- Co-authored-by: Muhsin Keloth Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- app/drops/contact_drop.rb | 2 +- app/drops/user_drop.rb | 2 +- spec/drops/contact_drop_spec.rb | 5 +++++ spec/drops/user_drop_spec.rb | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/drops/contact_drop.rb b/app/drops/contact_drop.rb index 1d450adb7..16240ec06 100644 --- a/app/drops/contact_drop.rb +++ b/app/drops/contact_drop.rb @@ -12,7 +12,7 @@ class ContactDrop < BaseDrop end def first_name - @obj.try(:name).try(:split).try(:first).try(:capitalize) if @obj.try(:name).try(:split).try(:size) > 1 + @obj.try(:name).try(:split).try(:first).try(:capitalize) end def last_name diff --git a/app/drops/user_drop.rb b/app/drops/user_drop.rb index cf6f1b6a1..83d5e2347 100644 --- a/app/drops/user_drop.rb +++ b/app/drops/user_drop.rb @@ -12,7 +12,7 @@ class UserDrop < BaseDrop end def first_name - @obj.try(:name).try(:split).try(:first).try(:capitalize) if @obj.try(:name).try(:split).try(:size).to_i > 1 + @obj.try(:name).try(:split).try(:first).try(:capitalize) end def last_name diff --git a/spec/drops/contact_drop_spec.rb b/spec/drops/contact_drop_spec.rb index d00a0924d..cd6d1a185 100644 --- a/spec/drops/contact_drop_spec.rb +++ b/spec/drops/contact_drop_spec.rb @@ -11,6 +11,11 @@ describe ContactDrop do expect(subject.first_name).to eq 'John' end + it 'returns the single word (capitalized) as first name when name has only one word' do + contact.update!(name: 'john') + expect(subject.first_name).to eq 'John' + end + it('return the capitalized name') do contact.update!(name: 'john doe') expect(subject.name).to eq 'John Doe' diff --git a/spec/drops/user_drop_spec.rb b/spec/drops/user_drop_spec.rb index 1093ec4a0..34f8f5eaa 100644 --- a/spec/drops/user_drop_spec.rb +++ b/spec/drops/user_drop_spec.rb @@ -11,6 +11,11 @@ describe UserDrop do expect(subject.first_name).to eq 'John' end + it 'returns the single word as first name when name has only one word' do + user.update!(name: 'John') + expect(subject.first_name).to eq 'John' + end + it('return the capitalized first name') do user.update!(name: 'john doe') expect(subject.first_name).to eq 'John'