From a780de064da3b45f019db7f348683fb3608fc8aa Mon Sep 17 00:00:00 2001 From: iamsivin Date: Fri, 8 May 2026 21:03:09 +0530 Subject: [PATCH] chore: Review fix --- app/services/data_import/contact_manager.rb | 9 +++++++-- spec/jobs/data_import_job_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/services/data_import/contact_manager.rb b/app/services/data_import/contact_manager.rb index 966f24266..812ca79c3 100644 --- a/app/services/data_import/contact_manager.rb +++ b/app/services/data_import/contact_manager.rb @@ -68,7 +68,12 @@ class DataImport::ContactManager 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.additional_attributes[:country_code] = params[:country_code] if params[:country_code].present? + assign_country_attributes(params, contact) + end + + def assign_country_attributes(params, contact) + contact.additional_attributes['country'] = params[:country] if params[:country].present? + contact.additional_attributes['country_code'] = params[:country_code] if params[:country_code].present? + contact.country_code = params[:country] if params[:country].present? end end diff --git a/spec/jobs/data_import_job_spec.rb b/spec/jobs/data_import_job_spec.rb index 4205d2861..e4374eada 100644 --- a/spec/jobs/data_import_job_spec.rb +++ b/spec/jobs/data_import_job_spec.rb @@ -214,6 +214,22 @@ RSpec.describe DataImportJob do expect(bob.additional_attributes['country']).to be_nil expect(bob.additional_attributes['country_code']).to be_nil end + + it 'populates the country_code column for new contacts via the bulk import path' do + described_class.perform_now(country_data_import) + + expect(Contact.from_email('john-country@example.com').country_code).to eq('United States') + expect(Contact.from_email('jane-country@example.com').country_code).to eq('India') + expect(Contact.from_email('bob-country@example.com').country_code).to eq('') + end + + it 'populates the country_code column when updating an existing contact' do + existing = create(:contact, account: country_data_import.account, email: 'john-country@example.com') + + described_class.perform_now(country_data_import) + + expect(existing.reload.country_code).to eq('United States') + end end context 'when the data contains labels column' do