diff --git a/lib/ingestors/material_csv_ingestor.rb b/lib/ingestors/material_csv_ingestor.rb index d91790d98..1c13f97c0 100644 --- a/lib/ingestors/material_csv_ingestor.rb +++ b/lib/ingestors/material_csv_ingestor.rb @@ -32,7 +32,7 @@ def read(url) material.description = process_description row, 'Description' material.keywords = process_array row, 'Keywords' material.contact = get_column row, 'Contact' - material.licence = get_column row, 'Licence' + material.licence = process_licence row, 'Licence' material.status = get_column row, 'Status' # copy optional values @@ -69,6 +69,10 @@ def process_competency(row, header) row[header].nil? ? 'notspecified' : row[header] end + def process_licence(row, header) + row[header].nil? ? 'notspecified' : row[header]&.to_s&.lstrip + end + # if url is a raw google spreadsheet # it returns the Google spreadsheet CSV export # else it returns the url diff --git a/test/unit/ingestors/material_csv_ingestor_test.rb b/test/unit/ingestors/material_csv_ingestor_test.rb index 7f6bbc10d..9cfe8f24d 100644 --- a/test/unit/ingestors/material_csv_ingestor_test.rb +++ b/test/unit/ingestors/material_csv_ingestor_test.rb @@ -222,6 +222,23 @@ def run assert_not_equal url_spreadsheet, url_export_spreadsheet end + test 'read logs error when exception is raised' do + source = @content_provider.sources.build( + url: 'https://app.com/materials.csv', + method: 'material_csv', + enabled: true + ) + + ingestor = Ingestors::MaterialCsvIngestor.new + + # Stub a method that will raise an error + ingestor.stub(:get_column, -> (*) { raise CSV::MalformedCSVError.new('test failure', 11) }) do + ingestor.read(source.url) + end + + assert_equal ingestor.messages.last, 'parse table failed with: test failure in line 11.' + end + private def get_material(title, url, provider = nil)