Add first name and last name support in liquid variables

This commit is contained in:
Muhsin 2022-12-23 11:56:17 +05:30
parent 289ad1e7f3
commit 322b253c97
2 changed files with 28 additions and 0 deletions

View file

@ -6,4 +6,12 @@ class ContactDrop < BaseDrop
def phone_number
@obj.try(:phone_number)
end
def first_name
@obj.try(:name).try(:split, ' ').try(:first)
end
def last_name
@obj.try(:name).try(:split, ' ').try(:last) if @obj.try(:name).try(:split, ' ').try(:size) > 1
end
end

View file

@ -41,6 +41,26 @@ shared_examples_for 'liqudable' do
message.save!
expect(message.content).to eq 'hey john how are you? ``` code: {{contact.name}} ``` ``` code: {{contact.name}} ``` test'
end
it 'will extract first name from contact name' do
message.content = 'hey {{contact.first_name}} how are you?'
message.save!
expect(message.content).to eq 'hey john how are you?'
end
it 'return empty last name when value is not available' do
message.content = 'hey {{contact.last_name}} how are you?'
message.save!
expect(message.content).to eq 'hey how are you?'
end
it 'will extract first name and last name from contact name' do
contact.name = 'john doe'
contact.save!
message.content = 'hey {{contact.first_name}} {{contact.last_name}} how are you?'
message.save!
expect(message.content).to eq 'hey john doe how are you?'
end
end
end
end