diff --git a/app/jobs/export_supporters_completed_job.rb b/app/jobs/export_supporters_completed_job.rb new file mode 100644 index 00000000..b2c1a19d --- /dev/null +++ b/app/jobs/export_supporters_completed_job.rb @@ -0,0 +1,7 @@ +class ExportSupportersCompletedJob < ApplicationJob + queue_as :default + + def perform(export) + ExportMailer.export_supporters_completed_notification(export).deliver_now + end +end diff --git a/lib/export/export_supporters.rb b/lib/export/export_supporters.rb index 51e4a4cb..211d8324 100644 --- a/lib/export/export_supporters.rb +++ b/lib/export/export_supporters.rb @@ -58,7 +58,7 @@ module ExportSupporters export.ended = Time.now export.save! - EmailJobQueue.queue(JobTypes::ExportSupportersCompletedJob, export) + ExportSupportersCompletedJob.perform_later export rescue StandardError => e if export export.status = :failed diff --git a/spec/lib/export/export_supporters_spec.rb b/spec/lib/export/export_supporters_spec.rb index d054b634..95f74f8b 100644 --- a/spec/lib/export/export_supporters_spec.rb +++ b/spec/lib/export/export_supporters_spec.rb @@ -172,7 +172,9 @@ describe ExportSupporters do @export = create(:export, user: @user, created_at: Time.now, updated_at: Time.now) expect_email_queued.with(JobTypes::ExportSupportersCompletedJob, @export) Timecop.freeze(2020, 4, 6, 1, 2, 3) do - ExportSupporters.run_export(@nonprofit.id, { root_url: 'https://localhost:8080/' }.to_json, @user.id, @export.id) + expect { + ExportSupporters.run_export(@nonprofit.id, { root_url: 'https://localhost:8080/' }.to_json, @user.id, @export.id) + }.to have_enqueued_job(ExportSupportersCompletedJob).with(@export) @export.reload diff --git a/spec/lib/job_types/export_supporters_completed_job_spec.rb b/spec/lib/job_types/export_supporters_completed_job_spec.rb deleted file mode 100644 index 717cc1ff..00000000 --- a/spec/lib/job_types/export_supporters_completed_job_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper.rb' - -describe JobTypes::ExportSupportersCompletedJob do - describe '.perform' do - it 'calls the correct active mailer' do - input = 1 - expect(ExportMailer).to receive(:export_supporters_completed_notification).with(input).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::ExportSupportersCompletedJob.new(input) - job.perform - end - end -end