From 50ffd7ca01f60572d367c0a4941089acf4453950 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 2 Mar 2018 10:48:22 +1100 Subject: [PATCH] Clear adjustments on subs orders when no items are able to be fulfilled This prevents shipping and payment fees from being displayed in the notification email --- app/jobs/subscription_placement_job.rb | 1 + spec/jobs/subscription_placement_job_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index 91d395157f..b3d0f7fd83 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -34,6 +34,7 @@ class SubscriptionPlacementJob changes = cap_quantity_and_store_changes(order) if order.line_items.where('quantity > 0').empty? + order.adjustments.destroy_all return send_empty_email(order, changes) end diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index d1f6e1dfd9..afa0e18f86 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -147,8 +147,9 @@ describe SubscriptionPlacementJob do allow(job).to receive(:unavailable_stock_lines_for) { order.line_items } end - it "does not place the order, sends an empty_order email" do + it "does not place the order, clears, all adjustments, and sends an empty_order email" do expect{ job.send(:process, order) }.to_not change{ order.reload.completed_at }.from(nil) + expect(order.reload.adjustments).to be_empty expect(job).to_not have_received(:send_placement_email) expect(job).to have_received(:send_empty_email) end