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>
62 lines
1.8 KiB
Ruby
62 lines
1.8 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe ContactDrop do
|
|
subject(:contact_drop) { described_class.new(contact) }
|
|
|
|
let!(:contact) { create(:contact, custom_attributes: { car_model: 'Tesla Model S', car_year: '2022' }) }
|
|
|
|
context 'when first name' do
|
|
it 'returns first name' do
|
|
contact.update!(name: 'John Doe')
|
|
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'
|
|
end
|
|
|
|
it('return the capitalized first name') do
|
|
contact.update!(name: 'john doe')
|
|
expect(subject.last_name).to eq 'Doe'
|
|
end
|
|
end
|
|
|
|
context 'when last name' do
|
|
it 'returns the last name' do
|
|
contact.update!(name: 'John Doe')
|
|
expect(subject.last_name).to eq 'Doe'
|
|
end
|
|
|
|
it 'returns empty when last name not present' do
|
|
contact.update!(name: 'John')
|
|
expect(subject.last_name).to be_nil
|
|
end
|
|
|
|
it('return the capitalized last name') do
|
|
contact.update!(name: 'john doe')
|
|
expect(subject.last_name).to eq 'Doe'
|
|
end
|
|
end
|
|
|
|
context 'when accessing custom attributes' do
|
|
it 'returns the correct car model from custom attributes' do
|
|
expect(contact_drop.custom_attribute['car_model']).to eq 'Tesla Model S'
|
|
end
|
|
|
|
it 'returns the correct car year from custom attributes' do
|
|
expect(contact_drop.custom_attribute['car_year']).to eq '2022'
|
|
end
|
|
|
|
it 'returns empty hash when there are no custom attributes' do
|
|
contact.update!(custom_attributes: nil)
|
|
expect(contact_drop.custom_attribute).to eq({})
|
|
end
|
|
end
|
|
end
|