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:
Rob Harrington
2017-11-24 13:38:37 +11:00
parent ef6c9ec0f0
commit 818af47613
2 changed files with 3 additions and 2 deletions

View File

@@ -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)

View File

@@ -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