mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Process OC emails individually to avoid duplicates
Errors or delays can cause multiple duplicate emails to the same suppliers.
This commit is contained in:
@@ -5,7 +5,7 @@ class OrderCycleNotificationJob < ApplicationJob
|
||||
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_now
|
||||
ProducerMailer.order_cycle_report(supplier, order_cycle).deliver_later
|
||||
end
|
||||
order_cycle.update_columns mails_sent: true
|
||||
end
|
||||
|
||||
@@ -4,20 +4,18 @@ require 'spec_helper'
|
||||
|
||||
RSpec.describe OrderCycleNotificationJob do
|
||||
let(:order_cycle) { create(:order_cycle) }
|
||||
let(:mail) { double(:mail, deliver_now: true) }
|
||||
|
||||
before do
|
||||
allow(ProducerMailer).to receive(:order_cycle_report).twice.and_return(mail)
|
||||
end
|
||||
|
||||
it "sends a mail to each supplier" do
|
||||
OrderCycleNotificationJob.perform_now order_cycle.id
|
||||
expect(ProducerMailer).to have_received(:order_cycle_report).twice
|
||||
expect {
|
||||
OrderCycleNotificationJob.perform_now(order_cycle.id)
|
||||
}.to enqueue_mail(ProducerMailer, :order_cycle_report).twice
|
||||
end
|
||||
|
||||
it "records that mails have been sent for the order cycle" do
|
||||
expect do
|
||||
expect {
|
||||
OrderCycleNotificationJob.perform_now(order_cycle.id)
|
||||
end.to change{ order_cycle.reload.mails_sent? }.from(false).to(true)
|
||||
}.to change {
|
||||
order_cycle.reload.mails_sent?
|
||||
}.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user