From eecb4a999d4613124300844aa9514bbf8f32ce00 Mon Sep 17 00:00:00 2001 From: Mrsandeep27 Date: Mon, 20 Apr 2026 00:46:04 +0530 Subject: [PATCH] fix: store contact CSV import company under additional_attributes[:company_name] The rest of the product reads the contact company from additional_attributes[:company_name] (Contact.order_on_company_name scope, ContactInfo.vue, ContactForm.vue, ContactSortMenu, widget contacts store). DataImport::ContactManager was writing to additional_attributes[:company] instead, so imported values silently never appeared in the Company field. - Write to additional_attributes[:company_name] - Accept either `company` or `company_name` CSV columns so existing import templates keep working (`company_name` wins when both are set). - Update the existing specs to assert against company_name and add a new spec that verifies the company_name CSV column path. Closes #14096 Revives the never-fully-resolved #9907. Co-Authored-By: Claude --- app/services/data_import/contact_manager.rb | 6 +++++- spec/jobs/data_import_job_spec.rb | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/services/data_import/contact_manager.rb b/app/services/data_import/contact_manager.rb index 460a83726..d374f4e80 100644 --- a/app/services/data_import/contact_manager.rb +++ b/app/services/data_import/contact_manager.rb @@ -61,7 +61,11 @@ class DataImport::ContactManager def update_contact_attributes(params, contact) contact.name = params[:name] if params[:name].present? contact.additional_attributes ||= {} - contact.additional_attributes[:company] = params[:company] if params[:company].present? + # The rest of the app (contact model scope, serializer, dashboard UI) reads + # `additional_attributes[:company_name]`. Accept either `company` or + # `company_name` from the CSV so older import templates keep working. + company_name = params[:company_name].presence || params[:company].presence + contact.additional_attributes[:company_name] = company_name if company_name.present? contact.additional_attributes[:city] = params[:city] if params[:city].present? contact.assign_attributes(custom_attributes: contact.custom_attributes.merge(params.except(:identifier, :email, :name, :phone_number))) end diff --git a/spec/jobs/data_import_job_spec.rb b/spec/jobs/data_import_job_spec.rb index 19178b177..76c1908f9 100644 --- a/spec/jobs/data_import_job_spec.rb +++ b/spec/jobs/data_import_job_spec.rb @@ -41,7 +41,18 @@ RSpec.describe DataImportJob do expect(data_import.reload.processed_records).to eq(csv_length) contact = Contact.find_by(phone_number: '+918080808080') expect(contact).to be_truthy - expect(contact['additional_attributes']['company']).to eq('My Company Name') + expect(contact['additional_attributes']['company_name']).to eq('My Company Name') + end + + it 'stores the company_name CSV column into additional_attributes[:company_name]' do + csv_data = [ + %w[id name email phone_number company_name], + ['1', 'Clarice Uzzell', 'cuzzell0@mozilla.org', '918080808080', 'Acmecorp'] + ] + import = create(:data_import, import_file: generate_csv_file(csv_data)) + described_class.perform_now(import) + contact = Contact.find_by(phone_number: '+918080808080') + expect(contact.additional_attributes['company_name']).to eq('Acmecorp') end end @@ -118,7 +129,7 @@ RSpec.describe DataImportJob do expect(contact).to be_present expect(contact.phone_number).to eq("+#{csv_data[0]['phone_number']}") expect(contact.name).to eq((csv_data[0]['name']).to_s) - expect(contact.additional_attributes['company']).to eq((csv_data[0]['company']).to_s) + expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company']).to_s) end end @@ -135,7 +146,7 @@ RSpec.describe DataImportJob do expect(contact).to be_present expect(contact.email).to eq(csv_data[0]['email']) expect(contact.name).to eq((csv_data[0]['name']).to_s) - expect(contact.additional_attributes['company']).to eq((csv_data[0]['company']).to_s) + expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company']).to_s) end end