From 736de4826ff536003fe9416e37aa177b213e1b63 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 7 Dec 2016 15:14:07 +1100 Subject: [PATCH] Renaming cancelled_at column to canceled_at, for consistency --- app/models/standing_order_order.rb | 10 +++---- ...name_standing_order_orders_cancelled_at.rb | 7 +++++ db/schema.rb | 2 +- .../standing_order_orders_controller_spec.rb | 6 ++--- spec/features/admin/standing_orders_spec.rb | 4 +-- spec/models/standing_order_order_spec.rb | 26 +++++++++---------- 6 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20161207040232_rename_standing_order_orders_cancelled_at.rb diff --git a/app/models/standing_order_order.rb b/app/models/standing_order_order.rb index 5c2a7ffaec..34ed02c0db 100644 --- a/app/models/standing_order_order.rb +++ b/app/models/standing_order_order.rb @@ -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 diff --git a/db/migrate/20161207040232_rename_standing_order_orders_cancelled_at.rb b/db/migrate/20161207040232_rename_standing_order_orders_cancelled_at.rb new file mode 100644 index 0000000000..6d2c3d0c3f --- /dev/null +++ b/db/migrate/20161207040232_rename_standing_order_orders_cancelled_at.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index a43d2465e0..a15b274457 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/controllers/admin/standing_order_orders_controller_spec.rb b/spec/controllers/admin/standing_order_orders_controller_spec.rb index 20792bd824..68ddbd2ca6 100644 --- a/spec/controllers/admin/standing_order_orders_controller_spec.rb +++ b/spec/controllers/admin/standing_order_orders_controller_spec.rb @@ -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 diff --git a/spec/features/admin/standing_orders_spec.rb b/spec/features/admin/standing_orders_spec.rb index 0f9654375d..e737a9443a 100644 --- a/spec/features/admin/standing_orders_spec.rb +++ b/spec/features/admin/standing_orders_spec.rb @@ -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 diff --git a/spec/models/standing_order_order_spec.rb b/spec/models/standing_order_order_spec.rb index 88326ef07a..4116a1734b 100644 --- a/spec/models/standing_order_order_spec.rb +++ b/spec/models/standing_order_order_spec.rb @@ -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