Skip to content

Commit

Permalink
Allows CSV grad data to have extra quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
rotated8 committed Jun 20, 2023
1 parent 4004bc3 commit f277278
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions app/services/graduation_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ 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
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)
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/registrar_feeds/registrar_sample.csv
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions spec/services/graduation_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' =>
Expand All @@ -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

Expand Down

0 comments on commit f277278

Please sign in to comment.