mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
Move rescue clause to process method
This prevents a placement email from being sent unless the order is processed successfully
This commit is contained in:
@@ -41,6 +41,8 @@ class StandingOrderPlacementJob
|
||||
|
||||
move_to_completion(order)
|
||||
send_placement_email(order, changes)
|
||||
rescue StateMachine::InvalidTransition
|
||||
record_failure(order)
|
||||
end
|
||||
|
||||
def cap_quantity_and_store_changes(order)
|
||||
@@ -58,8 +60,6 @@ class StandingOrderPlacementJob
|
||||
|
||||
def move_to_completion(order)
|
||||
until order.completed? do order.next! end
|
||||
rescue StateMachine::InvalidTransition
|
||||
record_failure(order)
|
||||
end
|
||||
|
||||
def unavailable_stock_lines_for(order)
|
||||
|
||||
@@ -172,6 +172,7 @@ describe StandingOrderPlacementJob do
|
||||
before { allow(order).to receive(:next) { false } }
|
||||
|
||||
it "records a failure and does not attempt to send an email" do
|
||||
expect(job).to_not receive(:send_placement_email)
|
||||
expect(job).to receive(:record_failure).once
|
||||
job.send(:process, order)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user