From 2bceb3389cdd5333c9477cc77a7e10ba575f905c Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 13:20:56 -0600 Subject: [PATCH] Add ExportSupporterNotesFailedJob --- app/jobs/export_supporter_notes_failed_job.rb | 7 +++++++ lib/export/export_supporter_notes.rb | 2 +- .../export_supporter_notes_failed_job.rb | 16 ---------------- spec/lib/export/export_supporter_notes_spec.rb | 3 ++- .../export_supporter_notes_failed_spec.rb | 16 ---------------- 5 files changed, 10 insertions(+), 34 deletions(-) create mode 100644 app/jobs/export_supporter_notes_failed_job.rb delete mode 100644 lib/job_types/export_supporter_notes_failed_job.rb delete mode 100644 spec/lib/job_types/export_supporter_notes_failed_spec.rb diff --git a/app/jobs/export_supporter_notes_failed_job.rb b/app/jobs/export_supporter_notes_failed_job.rb new file mode 100644 index 00000000..d43fae66 --- /dev/null +++ b/app/jobs/export_supporter_notes_failed_job.rb @@ -0,0 +1,7 @@ +class ExportSupporterNotesFailedJob < ApplicationJob + queue_as :default + + def perform(export) + ExportMailer.export_supporter_notes_failed_notification(export).deliver_now + end +end diff --git a/lib/export/export_supporter_notes.rb b/lib/export/export_supporter_notes.rb index 12efa5e6..02c52c14 100644 --- a/lib/export/export_supporter_notes.rb +++ b/lib/export/export_supporter_notes.rb @@ -67,7 +67,7 @@ module ExportSupporterNotes export.ended = Time.now export.save! if user - EmailJobQueue.queue(JobTypes::ExportSupporterNotesFailedJob, export) + ExportSupporterNotesFailedJob.perform_later export end raise e end diff --git a/lib/job_types/export_supporter_notes_failed_job.rb b/lib/job_types/export_supporter_notes_failed_job.rb deleted file mode 100644 index 1579836b..00000000 --- a/lib/job_types/export_supporter_notes_failed_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -module JobTypes - class ExportSupporterNotesFailedJob < EmailJob - attr_reader :export - - def initialize(export) - @export = export - end - - def perform - ExportMailer.export_supporter_notes_failed_notification(@export).deliver - end - end -end diff --git a/spec/lib/export/export_supporter_notes_spec.rb b/spec/lib/export/export_supporter_notes_spec.rb index 2d053ae7..9b3c5358 100644 --- a/spec/lib/export/export_supporter_notes_spec.rb +++ b/spec/lib/export/export_supporter_notes_spec.rb @@ -182,9 +182,9 @@ describe ExportSupporterNotes do it 'handles exception in upload properly' do Timecop.freeze(2020, 4, 5) do @export = force_create(:export, user: user) - expect_email_queued.with(JobTypes::ExportSupporterNotesFailedJob, @export) CHUNKED_UPLOADER.raise_error Timecop.freeze(2020, 4, 6) do + expect { expect { ExportSupporterNotes.run_export(nonprofit.id, {}.to_json, user.id, @export.id) }.to(raise_error do |error| expect(error).to be_a StandardError expect(error.message).to eq TestChunkedUploader::TEST_ERROR_MESSAGE @@ -195,6 +195,7 @@ describe ExportSupporterNotes do expect(@export.ended).to eq Time.now expect(@export.updated_at).to eq Time.now end) + }.to have_enqueued_job(ExportSupporterNotesFailedJob).with(@export) end end end diff --git a/spec/lib/job_types/export_supporter_notes_failed_spec.rb b/spec/lib/job_types/export_supporter_notes_failed_spec.rb deleted file mode 100644 index fb0f4da3..00000000 --- a/spec/lib/job_types/export_supporter_notes_failed_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -require 'rails_helper.rb' - -describe JobTypes::ExportSupporterNotesFailedJob do - describe '.perform' do - it 'calls the correct active mailer' do - input = 1 - expect(ExportMailer).to receive(:export_supporter_notes_failed_notification).with(input).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::ExportSupporterNotesFailedJob.new(1) - job.perform - end - end -end