chore: Fix contact model silently discarding invalid attributes (#4994)

fixes: #4775
This commit is contained in:
Sojan Jose
2022-07-08 10:28:09 +02:00
committed by GitHub
parent bca347149a
commit e4b159dd54
6 changed files with 38 additions and 24 deletions

View File

@@ -115,5 +115,23 @@ describe ::ContactIdentifyAction do
expect { contact.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'when discard_invalid_attrs is set to false' do
it 'will not update the name of the existing contact' do
params = { email: 'blah blah blah', name: 'new name' }
expect do
described_class.new(contact: contact, params: params, retain_original_contact_name: true).perform
end.to raise_error(ActiveRecord::RecordInvalid)
end
end
context 'when discard_invalid_attrs is set to true' do
it 'will not update the name of the existing contact' do
params = { phone_number: 'blahblah blah', name: 'new name' }
described_class.new(contact: contact, params: params, discard_invalid_attrs: true).perform
expect(contact.reload.name).to eq 'new name'
expect(contact.phone_number).to eq nil
end
end
end
end