diff --git a/app/jobs/payment_export_create_job.rb b/app/jobs/payment_export_create_job.rb new file mode 100644 index 00000000..eb55e566 --- /dev/null +++ b/app/jobs/payment_export_create_job.rb @@ -0,0 +1,7 @@ +class PaymentExportCreateJob < ApplicationJob + queue_as :default + + def perform(npo_id, params, user_id, export_id) + ExportPayments.run_export(npo_id, params, user_id, export_id) + end +end diff --git a/lib/export/export_payments.rb b/lib/export/export_payments.rb index fd1f0f60..00f52b63 100644 --- a/lib/export/export_payments.rb +++ b/lib/export/export_payments.rb @@ -20,7 +20,7 @@ module ExportPayments e = Export.create(nonprofit: npo, user: user, status: :queued, export_type: 'ExportPayments', parameters: params.to_json) - DelayedJobHelper.enqueue_job(ExportPayments, :run_export, [npo_id, params.to_json, user_id, e.id]) + PaymentExportCreateJob.perform_later(npo_id, params.to_json, user_id, e.id) end def self.run_export(npo_id, params, user_id, export_id) diff --git a/spec/lib/export/export_payments_spec.rb b/spec/lib/export/export_payments_spec.rb index 22f456d6..2f8d88d0 100644 --- a/spec/lib/export/export_payments_spec.rb +++ b/spec/lib/export/export_payments_spec.rb @@ -60,16 +60,11 @@ describe ExportPayments do it 'creates an export object and schedules job' do Timecop.freeze(2020, 4, 5) do - stub_const('DelayedJobHelper', double('delayed')) params = { param1: 'pp' }.with_indifferent_access - - expect(Export).to receive(:create).and_wrap_original { |m, *args| - e = m.call(*args) # get original create - expect(DelayedJobHelper).to receive(:enqueue_job).with(ExportPayments, :run_export, [nonprofit.id, params.to_json, user.id, e.id]) # add the enqueue - e - } - - ExportPayments.initiate_export(nonprofit.id, params, user.id) + expect{ + ExportPayments.initiate_export(nonprofit.id, params, user.id) + }.to have_enqueued_job(PaymentExportCreateJob) + export = Export.first expected_export = { id: export.id, user_id: user.id,