Convert OrderCycleNotificationJob to ActiveJob

This commit is contained in:
Matt-Yorkley
2020-11-06 02:08:37 +00:00
parent 9e334a4c1e
commit aaf7a90f8b
3 changed files with 4 additions and 4 deletions

View File

@@ -91,7 +91,7 @@ module Admin
# Send notifications to all producers who are part of the order cycle
def notify_producers
Delayed::Job.enqueue OrderCycleNotificationJob.new(params[:id].to_i)
OrderCycleNotificationJob.perform_later params[:id].to_i
redirect_to main_app.admin_order_cycles_path,
notice: I18n.t(:order_cycles_email_to_producers_notice)

View File

@@ -1,6 +1,6 @@
# Delivers an email with a report of the order cycle to each of its suppliers
OrderCycleNotificationJob = Struct.new(:order_cycle_id) do
def perform
class OrderCycleNotificationJob < ActiveJob::Base
def perform(order_cycle_id)
order_cycle = OrderCycle.find(order_cycle_id)
order_cycle.suppliers.each do |supplier|
ProducerMailer.order_cycle_report(supplier, order_cycle).deliver

View File

@@ -9,7 +9,7 @@ describe OrderCycleNotificationJob do
end
it 'sends a mail to each supplier' do
run_job OrderCycleNotificationJob.new(order_cycle.id)
OrderCycleNotificationJob.perform_now order_cycle.id
expect(ProducerMailer).to have_received(:order_cycle_report).twice
end
end