chore: Fix contact model silently discarding invalid attributes (#4994)
fixes: #4775
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user