Adding spec for case when standing_order_orders aren't linked to an order cycle

This should never happen, but came up in specs
This commit is contained in:
Rob Harrington
2016-12-07 11:24:27 +11:00
parent 284103b6b6
commit 076a05f8a9
2 changed files with 13 additions and 3 deletions

View File

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

View File

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