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 <muhsinkeramam@gmail.com>
Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Muhsin Keloth
Muhsin
Claude Opus 4.8
Copilot Autofix powered by AI
parent
ec43975f3f
commit
9d808a18df
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user