From f277278a316936e3270fdcf0fdd30b6b29c787cc Mon Sep 17 00:00:00 2001 From: Collin Brittle Date: Tue, 20 Jun 2023 11:23:54 -0400 Subject: [PATCH] Allows CSV grad data to have extra quotes --- app/services/graduation_service.rb | 4 +--- spec/fixtures/registrar_feeds/registrar_sample.csv | 2 +- spec/services/graduation_service_spec.rb | 8 ++++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/services/graduation_service.rb b/app/services/graduation_service.rb index 31318563..32e746b2 100644 --- a/app/services/graduation_service.rb +++ b/app/services/graduation_service.rb @@ -42,8 +42,6 @@ def run update_registrar_feed(approved_etds, publishable_etds) end - DOWNCASE_CONVERTER = ->(header) { header.downcase } - # Read registrar data from CSV or JSON source file # responsible for massaging the input file into the same json structure # @return [Hash] a hash of registrar keys pointing at the associated student graduation records @@ -51,7 +49,7 @@ def parse_registrar_file grad_records = @registrar_feed.graduation_records case grad_records.content_type when 'text/csv', 'application/vnd.ms-excel' - registrar_csv = CSV.parse(grad_records.download, headers: true, header_converters: DOWNCASE_CONVERTER) + registrar_csv = CSV.parse(grad_records.download, headers: true, header_converters: :downcase, liberal_parsing: true) registrar_csv.map { |row| [row['etd record key'], row.to_hash] }.to_h when 'application/json' JSON.parse(grad_records.download) diff --git a/spec/fixtures/registrar_feeds/registrar_sample.csv b/spec/fixtures/registrar_feeds/registrar_sample.csv index e6c4cacc..0bdb3d3f 100644 --- a/spec/fixtures/registrar_feeds/registrar_sample.csv +++ b/spec/fixtures/registrar_feeds/registrar_sample.csv @@ -1,6 +1,6 @@ etd record key,public person id,directory last name,directory first name,directory middle name,preferred email address,home address 1,home address 2,home address 3,home address city,home address state,home address postal code,home address country code,home address country descr,ferpa suppression flag,acad career code,acad career descr,acad program code,acad program descr,primary acad plan code,primary acad plan descr,secondary acad plan code,secondary acad plan descr,program status descr,degree code,degree status descr,degree status date P0000001-GSAS-PHD,P0000001,Doe,John, ,jdoe@example.com,123 Fake St, , ,Atlanta,GA,30301,USA,United States,N,GSAS,School of Graduate Studies,PHD,Doctor of Philosophy,BBSPHD,Biological and Biomedical Sci., , ,AC,PHD, , -P0000002-UCOL-LIBAS,P0000002,Smith,Jane,Cinderlla,jsmith@example.com,321 Ash Way, , ,Atlanta,GA,30301,USA,United States,N,UCOL,Undergraduate Emory College,LIBAS,Liberal Arts & Sciences,POLISCIBA,Political Science,LACSND,Latin Amer. & Caribbean Stu.,AC,BS,Awarded,2017-05-18 +P0000002-UCOL-LIBAS,P0000002,Smith,Jane,Cinderlla,jsmith@example.com,"321 "Ash" Way", , ,Atlanta,GA,30301,USA,United States,N,UCOL,Undergraduate Emory College,LIBAS,Liberal Arts & Sciences,POLISCIBA,Political Science,LACSND,Latin Amer. & Caribbean Stu.,AC,BS,Awarded,2017-05-18 P0000003-UCOL-LIBAS,P0000003,Hood,Riding,Red,rhood@example.com,12 Nana Ct,"","",Atlanta,GA,30301,USA,United States,N,UCOL,Undergraduate Emory College,LIBAS,Liberal Arts & Sciences,MATHCSBS,Mathematics & Computer Science, , ,CM,BS,Awarded,2017-03-16 P0000004-THEO-MDV,P0000004,Smith,Jim,James,jim.s@example.com,123 Fake Dr,"","",Atlanta,GA,30301,USA,United States,N,THEO,Theology,MDV,Master of Divinity,MDVDIVIN,Divinity, , ,CM,MDV,Awarded,2018-01-12 P0000004-THEO-THD,P0000004,Smith,Jim,James,jim.s@example.com,123 Fake Dr,"","",Atlanta,GA,30301,USA,United States,N,THEO,Theology,THD,Doctor of Theology,THDCOUNSEL,Pastoral Counseling, , ,AC,THD,Awarded,2020-05-23 diff --git a/spec/services/graduation_service_spec.rb b/spec/services/graduation_service_spec.rb index 6abadf53..7faed305 100644 --- a/spec/services/graduation_service_spec.rb +++ b/spec/services/graduation_service_spec.rb @@ -44,7 +44,7 @@ describe "#parse_registrar_file" do context 'with JSON data' do let(:feed) { FactoryBot.create(:json_registrar_feed) } - it "exrtracts records successfully" do + it "extracts records successfully" do parsed_data = grad_service.parse_registrar_file expect(parsed_data) .to include('P0000006-UBUS-BBA' => @@ -56,13 +56,17 @@ context 'with CSV data' do let(:feed) { FactoryBot.create(:registrar_feed) } - it 'exrtracts records successfully' do + it 'extracts records successfully' do parsed_data = grad_service.parse_registrar_file expect(parsed_data) .to include('P0000006-UBUS-BBA' => hash_including('public person id' => 'P0000006', 'directory last name' => 'Dieu-le-Veut', 'degree status date' => '2022-05-25')) + expect(parsed_data) + .to include('P0000002-UCOL-LIBAS' => + hash_including('public person id' => 'P0000002', + 'home address 1' => '\"321 \"Ash\" Way\"')) end end