|
| 1 | +require_relative '../test_case' |
| 2 | + |
| 3 | +require 'logger' |
| 4 | +require 'mocha/minitest' |
| 5 | +require 'stringio' |
| 6 | + |
| 7 | +class TestSubmissionProcessor < LinkedData::TestCase |
| 8 | + |
| 9 | + def self.before_suite |
| 10 | + LinkedData::TestCase.backend_4s_delete |
| 11 | + _count, _acronyms, onts = LinkedData::SampleData::Ontology.create_ontologies_and_submissions( |
| 12 | + ont_count: 1, submission_count: 1, acronym: 'PROCTEST', process_submission: false |
| 13 | + ) |
| 14 | + @@ont = onts.first |
| 15 | + end |
| 16 | + |
| 17 | + def self.after_suite |
| 18 | + @@ont&.delete |
| 19 | + LinkedData::TestCase.backend_4s_delete |
| 20 | + end |
| 21 | + |
| 22 | + # Regression test for the misleading log line: |
| 23 | + # "Email sending failed: undefined method `archived?' for nil:NilClass" |
| 24 | + # |
| 25 | + # When SubmissionMetadataExtractor#extract_metadata bails on an invalid submission it |
| 26 | + # returns nil, and OntologyProcessor#process_submission reassigns @submission to that |
| 27 | + # nil. Two invariants must hold: |
| 28 | + # 1. processing aborts with a clear StandardError (not a NoMethodError on nil), and |
| 29 | + # 2. notify_submission_processed (run from the ensure block) skips cleanly on a nil |
| 30 | + # submission instead of logging the misleading "Email sending failed" line above. |
| 31 | + def test_processor_aborts_cleanly_when_extract_metadata_returns_nil |
| 32 | + log_io = StringIO.new |
| 33 | + logger = Logger.new(log_io) |
| 34 | + |
| 35 | + submission = @@ont.latest_submission(status: :any) |
| 36 | + submission.bring_remaining |
| 37 | + |
| 38 | + # Simulate extract_metadata bailing on an invalid submission. |
| 39 | + submission.stubs(:extract_metadata).returns(nil) |
| 40 | + |
| 41 | + # Disable every other step so the test isolates the extract_metadata → notify path. |
| 42 | + options = { |
| 43 | + process_rdf: false, generate_missing_labels: false, generate_obsolete_classes: false, |
| 44 | + index_search: false, index_properties: false, index_all_data: false, |
| 45 | + run_metrics: false, diff: false, archive: false |
| 46 | + } |
| 47 | + |
| 48 | + error = assert_raises(StandardError) do |
| 49 | + submission.process_submission(logger, options) |
| 50 | + end |
| 51 | + |
| 52 | + refute_instance_of NoMethodError, error, |
| 53 | + 'processor crashed on a nil @submission instead of aborting cleanly' |
| 54 | + assert_match(/aborted/i, error.message, |
| 55 | + 'processor should abort with a clear message when extract_metadata returns nil') |
| 56 | + |
| 57 | + refute_match(/Email sending failed/, log_io.string, |
| 58 | + 'notify_submission_processed logged a misleading "Email sending failed" on a nil submission') |
| 59 | + end |
| 60 | +end |
0 commit comments