From ad2b701f697a75c958428f51b2b4f59c0d6ba6ab Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Thu, 7 Nov 2019 13:17:06 -0600 Subject: [PATCH] Add ExportSupporterNotesCompletedJob --- app/jobs/export_supporter_notes_completed_job.rb | 7 +++++++ lib/export/export_supporter_notes.rb | 3 +-- .../export_supporter_notes_completed_job.rb | 16 ---------------- spec/lib/export/export_supporter_notes_spec.rb | 2 ++ .../export_supporter_notes_completed_spec.rb | 16 ---------------- 5 files changed, 10 insertions(+), 34 deletions(-) create mode 100644 app/jobs/export_supporter_notes_completed_job.rb delete mode 100644 lib/job_types/export_supporter_notes_completed_job.rb delete mode 100644 spec/lib/job_types/export_supporter_notes_completed_spec.rb diff --git a/app/jobs/export_supporter_notes_completed_job.rb b/app/jobs/export_supporter_notes_completed_job.rb new file mode 100644 index 00000000..3aa17c00 --- /dev/null +++ b/app/jobs/export_supporter_notes_completed_job.rb @@ -0,0 +1,7 @@ +class ExportSupporterNotesCompletedJob < ApplicationJob + queue_as :default + + def perform(export) + ExportMailer.export_supporter_notes_completed_notification(export).deliver_now + end +end diff --git a/lib/export/export_supporter_notes.rb b/lib/export/export_supporter_notes.rb index 52b3af11..12efa5e6 100644 --- a/lib/export/export_supporter_notes.rb +++ b/lib/export/export_supporter_notes.rb @@ -59,8 +59,7 @@ module ExportSupporterNotes export.status = :completed export.ended = Time.now export.save! - - EmailJobQueue.queue(JobTypes::ExportSupporterNotesCompletedJob, export) + ExportSupporterNotesCompletedJob.perform_later(export) rescue StandardError => e if export export.status = :failed diff --git a/lib/job_types/export_supporter_notes_completed_job.rb b/lib/job_types/export_supporter_notes_completed_job.rb deleted file mode 100644 index 10542128..00000000 --- a/lib/job_types/export_supporter_notes_completed_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 ExportSupporterNotesCompletedJob < EmailJob - attr_reader :export - - def initialize(export) - @export = export - end - - def perform - ExportMailer.export_supporter_notes_completed_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 f0a52b27..2d053ae7 100644 --- a/spec/lib/export/export_supporter_notes_spec.rb +++ b/spec/lib/export/export_supporter_notes_spec.rb @@ -204,7 +204,9 @@ describe ExportSupporterNotes do @export = create(:export, user: user, created_at: Time.now, updated_at: Time.now) expect_email_queued.with(JobTypes::ExportSupporterNotesCompletedJob, @export) Timecop.freeze(2020, 4, 6, 1, 2, 3) do + expect { ExportSupporterNotes.run_export(nonprofit.id, { root_url: 'https://localhost:8080/' }.to_json, user.id, @export.id) + }.to have_enqueued_job(ExportSupporterNotesCompletedJob).with(@export) @export.reload diff --git a/spec/lib/job_types/export_supporter_notes_completed_spec.rb b/spec/lib/job_types/export_supporter_notes_completed_spec.rb deleted file mode 100644 index eac5977f..00000000 --- a/spec/lib/job_types/export_supporter_notes_completed_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::ExportSupporterNotesCompletedJob do - describe '.perform' do - it 'calls the correct active mailer' do - input = 1 - expect(ExportMailer).to receive(:export_supporter_notes_completed_notification).with(input).and_wrap_original { |_m, *_args| mailer = double('object'); expect(mailer).to receive(:deliver).and_return(nil); mailer } - - job = JobTypes::ExportSupporterNotesCompletedJob.new(1) - job.perform - end - end -end