Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/ingestors/material_csv_ingestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/unit/ingestors/material_csv_ingestor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ 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
def ingestor.get_column(*)
raise CSV::MalformedCSVError.new('test failure', 22)
end

ingestor.read(source.url)

Comment on lines +235 to +240
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better/safer to use minitest's stubbing:

ingestor.stub(:get_column, -> { raise CSV::MalformedCSVError.new('test failure', 22) }) do
  ingestor.read(source.url)
end

assert_includes ingestor.messages.last, 'parse table failed with: test failure'
end

private

def get_material(title, url, provider = nil)
Expand Down