From 076a05f8a913ee76663ea6fa78d1a68014fcb2ce Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 7 Dec 2016 11:24:27 +1100 Subject: [PATCH] Adding spec for case when standing_order_orders aren't linked to an order cycle This should never happen, but came up in specs --- app/models/standing_order_order.rb | 4 ++-- spec/models/standing_order_order_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/standing_order_order.rb b/app/models/standing_order_order.rb index 832fbe08bc..5c2a7ffaec 100644 --- a/app/models/standing_order_order.rb +++ b/app/models/standing_order_order.rb @@ -17,10 +17,10 @@ class StandingOrderOrder < ActiveRecord::Base end def cancel - return false unless order.order_cycle.orders_close_at > Time.zone.now + return false unless order.order_cycle.andand.orders_close_at.andand > Time.zone.now transaction do self.update_column(:cancelled_at, Time.zone.now) - order.send('cancel') if order.complete? + order.send('cancel') true end end diff --git a/spec/models/standing_order_order_spec.rb b/spec/models/standing_order_order_spec.rb index 1ebf41e581..88326ef07a 100644 --- a/spec/models/standing_order_order_spec.rb +++ b/spec/models/standing_order_order_spec.rb @@ -36,7 +36,17 @@ describe StandingOrderOrder, type: :model do before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } it "returns false and does nothing" do - expect(standing_order_order.cancel).to eq false + expect(standing_order_order.cancel).to be false + expect(standing_order_order.reload.cancelled_at).to be nil + expect(order.reload.state).to eq 'cart' + end + end + + context "when the order cycle for the order does not exist" do + let(:order) { create(:order) } + + it "returns false and does nothing" do + expect(standing_order_order.cancel).to be false expect(standing_order_order.reload.cancelled_at).to be nil expect(order.reload.state).to eq 'cart' end