chore: Clean up
This commit is contained in:
@@ -61,14 +61,9 @@ class DataImport::ContactManager
|
||||
def update_contact_attributes(params, contact)
|
||||
contact.name = params[:name] if params[:name].present?
|
||||
contact.additional_attributes ||= {}
|
||||
assign_additional_attributes(params, contact)
|
||||
contact.country_code = params[:country] if params[:country].present?
|
||||
contact.assign_attributes(custom_attributes: contact.custom_attributes.merge(params.except(:identifier, :email, :name, :phone_number)))
|
||||
end
|
||||
|
||||
def assign_additional_attributes(params, contact)
|
||||
contact.additional_attributes[:company_name] = params[:company_name] if params[:company_name].present?
|
||||
contact.additional_attributes[:city] = params[:city] if params[:city].present?
|
||||
contact.additional_attributes[:country] = params[:country] if params[:country].present?
|
||||
contact.assign_attributes(custom_attributes: contact.custom_attributes.merge(params.except(:identifier, :email, :name, :phone_number)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -199,18 +199,17 @@ RSpec.describe DataImportJob do
|
||||
end
|
||||
let(:country_data_import) { create(:data_import, import_file: generate_csv_file(data_with_country)) }
|
||||
|
||||
it 'maps the country column to the standard country_code field' do
|
||||
it 'maps the country column to additional_attributes country' do
|
||||
described_class.perform_now(country_data_import)
|
||||
|
||||
john = Contact.from_email('john-country@example.com')
|
||||
expect(john.country_code).to eq('United States')
|
||||
expect(john.additional_attributes['country']).to eq('United States')
|
||||
|
||||
jane = Contact.from_email('jane-country@example.com')
|
||||
expect(jane.country_code).to eq('India')
|
||||
expect(jane.additional_attributes['country']).to eq('India')
|
||||
|
||||
bob = Contact.from_email('bob-country@example.com')
|
||||
expect(bob.country_code).to eq('')
|
||||
expect(bob.additional_attributes['country']).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user