Skip to content

Commit b476768

Browse files
authored
Merge pull request #1163 from kennethrioja/fix-gsheet
[csv ingestor] Fix `material.licence` when nil
2 parents 92634aa + c316e9d commit b476768

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

lib/ingestors/material_csv_ingestor.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read(url)
3232
material.description = process_description row, 'Description'
3333
material.keywords = process_array row, 'Keywords'
3434
material.contact = get_column row, 'Contact'
35-
material.licence = get_column row, 'Licence'
35+
material.licence = process_licence row, 'Licence'
3636
material.status = get_column row, 'Status'
3737

3838
# copy optional values
@@ -69,6 +69,10 @@ def process_competency(row, header)
6969
row[header].nil? ? 'notspecified' : row[header]
7070
end
7171

72+
def process_licence(row, header)
73+
row[header].nil? ? 'notspecified' : row[header]&.to_s&.lstrip
74+
end
75+
7276
# if url is a raw google spreadsheet
7377
# it returns the Google spreadsheet CSV export
7478
# else it returns the url

test/unit/ingestors/material_csv_ingestor_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,23 @@ def run
222222
assert_not_equal url_spreadsheet, url_export_spreadsheet
223223
end
224224

225+
test 'read logs error when exception is raised' do
226+
source = @content_provider.sources.build(
227+
url: 'https://app.com/materials.csv',
228+
method: 'material_csv',
229+
enabled: true
230+
)
231+
232+
ingestor = Ingestors::MaterialCsvIngestor.new
233+
234+
# Stub a method that will raise an error
235+
ingestor.stub(:get_column, -> (*) { raise CSV::MalformedCSVError.new('test failure', 11) }) do
236+
ingestor.read(source.url)
237+
end
238+
239+
assert_equal ingestor.messages.last, 'parse table failed with: test failure in line 11.'
240+
end
241+
225242
private
226243

227244
def get_material(title, url, provider = nil)

0 commit comments

Comments
 (0)