mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Renaming cancelled_at column to canceled_at, for consistency
This commit is contained in:
@@ -8,18 +8,18 @@ class StandingOrderOrder < ActiveRecord::Base
|
||||
scope :not_closed, -> { joins(order: :order_cycle).merge(OrderCycle.not_closed) }
|
||||
|
||||
def state
|
||||
return 'canceled' if cancelled?
|
||||
return 'canceled' if canceled?
|
||||
order.state
|
||||
end
|
||||
|
||||
def cancelled?
|
||||
cancelled_at.present?
|
||||
def canceled?
|
||||
canceled_at.present?
|
||||
end
|
||||
|
||||
def cancel
|
||||
return false unless order.order_cycle.andand.orders_close_at.andand > Time.zone.now
|
||||
transaction do
|
||||
self.update_column(:cancelled_at, Time.zone.now)
|
||||
self.update_column(:canceled_at, Time.zone.now)
|
||||
order.send('cancel')
|
||||
true
|
||||
end
|
||||
@@ -28,7 +28,7 @@ class StandingOrderOrder < ActiveRecord::Base
|
||||
def resume
|
||||
return false unless order.order_cycle.orders_close_at > Time.zone.now
|
||||
transaction do
|
||||
self.update_column(:cancelled_at, nil)
|
||||
self.update_column(:canceled_at, nil)
|
||||
order.send('resume')
|
||||
true
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class RenameStandingOrderOrdersCancelledAt < ActiveRecord::Migration
|
||||
def change
|
||||
# No, I'm not illiterate. I just want to maintain consistency with
|
||||
# existing Spree column names that are spelt using US English
|
||||
rename_column :standing_order_orders, :cancelled_at, :canceled_at
|
||||
end
|
||||
end
|
||||
@@ -1079,7 +1079,7 @@ ActiveRecord::Schema.define(:version => 20170921065259) do
|
||||
create_table "standing_order_orders", :force => true do |t|
|
||||
t.integer "standing_order_id", :null => false
|
||||
t.integer "order_id", :null => false
|
||||
t.datetime "cancelled_at"
|
||||
t.datetime "canceled_at"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
@@ -45,7 +45,7 @@ describe Admin::StandingOrderOrdersController, type: :controller do
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['state']).to eq "canceled"
|
||||
expect(json_response['id']).to eq standing_order_order.id
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
end
|
||||
end
|
||||
|
||||
@@ -75,7 +75,7 @@ describe Admin::StandingOrderOrdersController, type: :controller do
|
||||
before do
|
||||
# Processing order to completion
|
||||
while !order.completed? do break unless order.next! end
|
||||
standing_order_order.update_attribute(:cancelled_at, Time.zone.now)
|
||||
standing_order_order.update_attribute(:canceled_at, Time.zone.now)
|
||||
order.cancel
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
end
|
||||
@@ -110,7 +110,7 @@ describe Admin::StandingOrderOrdersController, type: :controller do
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['state']).to eq "resumed"
|
||||
expect(json_response['id']).to eq standing_order_order.id
|
||||
expect(standing_order_order.reload.cancelled_at).to be nil
|
||||
expect(standing_order_order.reload.canceled_at).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ feature 'Standing Orders' do
|
||||
find("a.cancel-order").trigger('click')
|
||||
end
|
||||
expect(page).to have_content 'CANCELLED'
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
|
||||
# Resuming an order
|
||||
accept_alert 'Are you sure?' do
|
||||
@@ -94,7 +94,7 @@ feature 'Standing Orders' do
|
||||
end
|
||||
# Note: the order itself was not complete when 'cancelled', so state remained as cart
|
||||
expect(page).to have_content 'CART'
|
||||
expect(standing_order_order.reload.cancelled_at).to be nil
|
||||
expect(standing_order_order.reload.canceled_at).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ describe StandingOrderOrder, type: :model do
|
||||
context "and the order has already been completed" do
|
||||
let(:order) { create(:completed_order_with_totals, order_cycle: order_cycle) }
|
||||
|
||||
it "returns true and sets cancelled_at to the current time, and cancels the order" do
|
||||
it "returns true and sets canceled_at to the current time, and cancels the order" do
|
||||
expect(standing_order_order.cancel).to be true
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
expect(order.reload.state).to eq 'canceled'
|
||||
end
|
||||
end
|
||||
@@ -22,9 +22,9 @@ describe StandingOrderOrder, type: :model do
|
||||
context "and the order has not already been completed" do
|
||||
let(:order) { create(:order, order_cycle: order_cycle) }
|
||||
|
||||
it "returns true and sets cancelled at to the current time" do
|
||||
it "returns true and sets canceled_at to the current time" do
|
||||
expect(standing_order_order.cancel).to be true
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
expect(order.reload.state).to eq 'cart'
|
||||
end
|
||||
end
|
||||
@@ -37,7 +37,7 @@ describe StandingOrderOrder, type: :model do
|
||||
|
||||
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(standing_order_order.reload.canceled_at).to be nil
|
||||
expect(order.reload.state).to eq 'cart'
|
||||
end
|
||||
end
|
||||
@@ -47,7 +47,7 @@ describe StandingOrderOrder, type: :model do
|
||||
|
||||
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(standing_order_order.reload.canceled_at).to be nil
|
||||
expect(order.reload.state).to eq 'cart'
|
||||
end
|
||||
end
|
||||
@@ -63,7 +63,7 @@ describe StandingOrderOrder, type: :model do
|
||||
before do
|
||||
# Processing order to completion
|
||||
while !order.completed? do break unless order.next! end
|
||||
standing_order_order.update_attribute(:cancelled_at, Time.zone.now)
|
||||
standing_order_order.update_attribute(:canceled_at, Time.zone.now)
|
||||
end
|
||||
|
||||
context "when the order cycle for the order is not yet closed" do
|
||||
@@ -72,17 +72,17 @@ describe StandingOrderOrder, type: :model do
|
||||
context "and the order has already been cancelled" do
|
||||
before { order.cancel }
|
||||
|
||||
it "returns true, clears cancelled_at and resumes the order" do
|
||||
it "returns true, clears canceled_at and resumes the order" do
|
||||
expect(standing_order_order.resume).to be true
|
||||
expect(standing_order_order.reload.cancelled_at).to be nil
|
||||
expect(standing_order_order.reload.canceled_at).to be nil
|
||||
expect(order.reload.state).to eq 'resumed'
|
||||
end
|
||||
end
|
||||
|
||||
context "and the order has not been cancelled" do
|
||||
it "returns true and clears cancelled_at" do
|
||||
it "returns true and clears canceled_at" do
|
||||
expect(standing_order_order.resume).to be true
|
||||
expect(standing_order_order.reload.cancelled_at).to be nil
|
||||
expect(standing_order_order.reload.canceled_at).to be nil
|
||||
expect(order.reload.state).to eq 'complete'
|
||||
end
|
||||
end
|
||||
@@ -96,7 +96,7 @@ describe StandingOrderOrder, type: :model do
|
||||
|
||||
it "returns false and does nothing" do
|
||||
expect(standing_order_order.resume).to eq false
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
expect(order.reload.state).to eq 'canceled'
|
||||
end
|
||||
end
|
||||
@@ -104,7 +104,7 @@ describe StandingOrderOrder, type: :model do
|
||||
context "and the order has not been cancelled" do
|
||||
it "returns false and does nothing" do
|
||||
expect(standing_order_order.resume).to eq false
|
||||
expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now
|
||||
expect(standing_order_order.reload.canceled_at).to be_within(5.seconds).of Time.now
|
||||
expect(order.reload.state).to eq 'complete'
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user