diff --git a/app/services/bulk_upload/processor.rb b/app/services/bulk_upload/processor.rb index 16d0a067d..711996fcf 100644 --- a/app/services/bulk_upload/processor.rb +++ b/app/services/bulk_upload/processor.rb @@ -6,6 +6,8 @@ class BulkUpload::Processor end def call + destroy_any_existing_errors_from_prior_run + download return send_failure_mail(errors: validator.errors.full_messages) if validator.invalid? @@ -46,6 +48,10 @@ class BulkUpload::Processor private + def destroy_any_existing_errors_from_prior_run + bulk_upload.bulk_upload_errors.destroy_all + end + def send_how_to_fix_upload_mail BulkUploadMailer .send_how_to_fix_upload_mail(bulk_upload:) diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 6c250bbb6..2314a325f 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -8,6 +8,16 @@ RSpec.describe BulkUpload::Processor do let(:owning_org) { create(:organisation, old_visible_id: 123) } describe "#call" do + context "when errors exist from prior job run" do + let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } + + it "destroys existing errors" do + processor.call + + expect { existing_error.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + end + context "when the bulk upload itself is not considered valid" do let(:mock_downloader) do instance_double(