From a0b3139fda59d553b05d7df6f3b6721bfd923d41 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Thu, 24 Oct 2024 11:38:36 +0100 Subject: [PATCH] upload eligible FE CSV now handles currency values --- app/models/eligible_fe_providers_importer.rb | 4 ++-- spec/models/eligible_fe_providers_importer_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/eligible_fe_providers_importer.rb b/app/models/eligible_fe_providers_importer.rb index fdbf66582e..b710a4a3bb 100644 --- a/app/models/eligible_fe_providers_importer.rb +++ b/app/models/eligible_fe_providers_importer.rb @@ -31,8 +31,8 @@ def delete_all_scope def row_to_hash(row) { ukprn: row.fetch("ukprn"), - max_award_amount: row.fetch("max_award_amount"), - lower_award_amount: row.fetch("lower_award_amount"), + max_award_amount: row.fetch("max_award_amount").gsub(/£|,/, ""), + lower_award_amount: row.fetch("lower_award_amount").gsub(/£|,/, ""), primary_key_contact_email_address: row.fetch("primary_key_contact_email_address"), academic_year: } diff --git a/spec/models/eligible_fe_providers_importer_spec.rb b/spec/models/eligible_fe_providers_importer_spec.rb index 5a4cb62e44..deb73f54e0 100644 --- a/spec/models/eligible_fe_providers_importer_spec.rb +++ b/spec/models/eligible_fe_providers_importer_spec.rb @@ -120,7 +120,7 @@ def to_row(hash) file.write correct_headers 3.times do - file.write to_row(attributes_for(:eligible_fe_provider)) + file.write to_row(attributes_for(:eligible_fe_provider).merge(max_award_amount: '"£6,000"', lower_award_amount: '"£3,000"')) end file.close @@ -128,6 +128,8 @@ def to_row(hash) it "ignores superfluous characters and imports new records" do expect { subject.run }.to change { EligibleFeProvider.count }.by(3) + expect(EligibleFeProvider.pluck(:max_award_amount).uniq).to eql([6000]) + expect(EligibleFeProvider.pluck(:lower_award_amount).uniq).to eql([3000]) end context "when there are existing records" do