From 10e7e324a9661afad126ed4f6b1e1292e1c03580 Mon Sep 17 00:00:00 2001 From: kennethrioja <59597207+kennethrioja@users.noreply.github.com> Date: Thu, 16 Oct 2025 11:56:48 +0200 Subject: [PATCH 1/2] fix(csv ingestor): `material.licence` when nil --- lib/ingestors/material_csv_ingestor.rb | 6 +++++- .../ingestors/material_csv_ingestor_test.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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..f86c8c7fe 100644 --- a/test/unit/ingestors/material_csv_ingestor_test.rb +++ b/test/unit/ingestors/material_csv_ingestor_test.rb @@ -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) + + assert_includes ingestor.messages.last, 'parse table failed with: test failure' + end + private def get_material(title, url, provider = nil) From c316e9db18b7bf2a473208a0c675d029ee1ac859 Mon Sep 17 00:00:00 2001 From: kennethrioja <59597207+kennethrioja@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:47:38 +0100 Subject: [PATCH 2/2] test(material_csv_ingestor): amended to use minitest's stubbing --- test/unit/ingestors/material_csv_ingestor_test.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/unit/ingestors/material_csv_ingestor_test.rb b/test/unit/ingestors/material_csv_ingestor_test.rb index f86c8c7fe..9cfe8f24d 100644 --- a/test/unit/ingestors/material_csv_ingestor_test.rb +++ b/test/unit/ingestors/material_csv_ingestor_test.rb @@ -232,13 +232,11 @@ def run ingestor = Ingestors::MaterialCsvIngestor.new # Stub a method that will raise an error - def ingestor.get_column(*) - raise CSV::MalformedCSVError.new('test failure', 22) + ingestor.stub(:get_column, -> (*) { raise CSV::MalformedCSVError.new('test failure', 11) }) do + ingestor.read(source.url) end - ingestor.read(source.url) - - assert_includes ingestor.messages.last, 'parse table failed with: test failure' + assert_equal ingestor.messages.last, 'parse table failed with: test failure in line 11.' end private