WIP: adding method to StandingOrderPlacementJob to send emails

This commit is contained in:
Rob Harrington
2016-11-16 12:23:11 +11:00
parent 5e0186fa1f
commit 3edfd07a40
2 changed files with 18 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ class StandingOrderPlacementJob
end
def process(order)
changes = cap_quantity_and_store_changes(order) unless order.completed?
until order.completed?
if order.errors.any?
Bugsnag.notify(RuntimeError.new("StandingOrderPlacementError"), {
@@ -32,6 +33,7 @@ class StandingOrderPlacementJob
order.next!
end
end
send_placement_email(order, changes)
end
def cap_quantity_and_store_changes(order)
@@ -43,4 +45,8 @@ class StandingOrderPlacementJob
{ line_item: line_item, quantity_was: quantity_was }
end
end
def send_placement_email(order, changes)
# Nothing yet
end
end

View File

@@ -56,19 +56,28 @@ describe StandingOrderPlacementJob do
end
end
describe "performing the job" do
let(:order) { standing_order1.orders.first }
describe "processing a standing order order" do
let(:changes) { double(:changes) }
before do
form = StandingOrderForm.new(standing_order1)
form.send(:initialise_orders!)
expect_any_instance_of(Spree::Payment).to_not receive(:process!)
allow(job).to receive(:cap_quantity_and_store_changes) { changes }
allow(job).to receive(:send_placement_email)
end
it "moves orders to completion, but does not process the payment" do
expect{job.perform}.to change{order.reload.completed_at}.from(nil)
order = standing_order1.orders.first
expect{job.send(:process, order)}.to change{order.reload.completed_at}.from(nil)
expect(order.completed_at).to be_within(5.seconds).of Time.now
expect(order.payments.first.state).to eq "checkout"
end
it "calls #send_placement_email with the order and any changes made" do
order = standing_order1.orders.first
job.send(:process, order)
expect(job).to have_received(:send_placement_email).with(order, changes).once
end
end
end