From 3edfd07a401eb961fa5b519fb83686fdc0a85ac5 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 16 Nov 2016 12:23:11 +1100 Subject: [PATCH] WIP: adding method to StandingOrderPlacementJob to send emails --- app/jobs/standing_order_placement_job.rb | 6 ++++++ spec/jobs/standing_order_placement_job_spec.rb | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/jobs/standing_order_placement_job.rb b/app/jobs/standing_order_placement_job.rb index e9367556d2..7b5eea1b15 100644 --- a/app/jobs/standing_order_placement_job.rb +++ b/app/jobs/standing_order_placement_job.rb @@ -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 diff --git a/spec/jobs/standing_order_placement_job_spec.rb b/spec/jobs/standing_order_placement_job_spec.rb index e1121bcca7..87275cc79a 100644 --- a/spec/jobs/standing_order_placement_job_spec.rb +++ b/spec/jobs/standing_order_placement_job_spec.rb @@ -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