From 91908a0e4c3e4c2810a0e6c88942ad54930e2bdb Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 4 Nov 2020 10:24:19 +0000 Subject: [PATCH] Switch from state_machine to state_machines gem The old version is completely unmaintained and does not work with Rails 4.2 --- Gemfile | 2 +- Gemfile.lock | 10 ++++++++-- app/models/spree/order/checkout.rb | 2 +- config/initializers/state_machine_patch.rb | 11 ----------- lib/spree/core.rb | 2 +- spec/models/spree/order/checkout_spec.rb | 6 +++--- spec/models/spree/order_spec.rb | 2 +- spec/services/order_checkout_restart_spec.rb | 2 +- spec/services/order_workflow_spec.rb | 2 +- 9 files changed, 17 insertions(+), 22 deletions(-) delete mode 100644 config/initializers/state_machine_patch.rb diff --git a/Gemfile b/Gemfile index 02318308f9..59b5dcf62a 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ gem 'json' gem 'money', '< 6.1.0' gem 'paranoia', '~> 2.0' gem 'ransack', '~> 1.8.10' -gem 'state_machine', '1.2.0' +gem 'state_machines-activerecord' gem 'stringex', '~> 1.5.1' gem 'spree_i18n', github: 'openfoodfoundation/spree_i18n', branch: '1-3-stable' diff --git a/Gemfile.lock b/Gemfile.lock index 2a4e82502f..05ead18e7f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -667,7 +667,13 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - state_machine (1.2.0) + state_machines (0.5.0) + state_machines-activemodel (0.7.1) + activemodel (>= 4.1) + state_machines (>= 0.5.0) + state_machines-activerecord (0.6.0) + activerecord (>= 4.1) + state_machines-activemodel (>= 0.5.0) stringex (1.5.1) stripe (5.28.0) temple (0.8.2) @@ -818,7 +824,7 @@ DEPENDENCIES spree_paypal_express! spring spring-commands-rspec - state_machine (= 1.2.0) + state_machines-activerecord stringex (~> 1.5.1) stripe test-prof diff --git a/app/models/spree/order/checkout.rb b/app/models/spree/order/checkout.rb index 82efef81e7..39992a5701 100644 --- a/app/models/spree/order/checkout.rb +++ b/app/models/spree/order/checkout.rb @@ -34,7 +34,7 @@ module Spree klass = self # To avoid a ton of warnings when the state machine is re-defined - StateMachine::Machine.ignore_method_conflicts = true + StateMachines::Machine.ignore_method_conflicts = true # To avoid multiple occurrences of the same transition being defined # On first definition, state_machines will not be defined state_machines.clear if respond_to?(:state_machines) diff --git a/config/initializers/state_machine_patch.rb b/config/initializers/state_machine_patch.rb deleted file mode 100644 index 76e984526a..0000000000 --- a/config/initializers/state_machine_patch.rb +++ /dev/null @@ -1,11 +0,0 @@ -module StateMachine - module Integrations - module ActiveModel - public :around_validation - end - - module ActiveRecord - public :around_save - end - end -end diff --git a/lib/spree/core.rb b/lib/spree/core.rb index e3ef713db7..cdf1ff4b2a 100644 --- a/lib/spree/core.rb +++ b/lib/spree/core.rb @@ -10,7 +10,7 @@ require 'mail' require 'paperclip' require 'paranoia' require 'ransack' -require 'state_machine' +require 'state_machines' module Spree mattr_accessor :user_class diff --git a/spec/models/spree/order/checkout_spec.rb b/spec/models/spree/order/checkout_spec.rb index 3fadb6b8e0..27a35c8023 100644 --- a/spec/models/spree/order/checkout_spec.rb +++ b/spec/models/spree/order/checkout_spec.rb @@ -59,7 +59,7 @@ describe Spree::Order::Checkout do it "cannot transition to address without any line items" do expect(order.line_items).to be_blank - expect(lambda { order.next! }).to raise_error(StateMachine::InvalidTransition, + expect(lambda { order.next! }).to raise_error(StateMachines::InvalidTransition, /#{Spree.t(:there_are_no_items_for_this_order)}/) end @@ -82,7 +82,7 @@ describe Spree::Order::Checkout do context "if there are no shipping rates for any shipment" do specify do transition = lambda { order.next! } - expect(transition).to raise_error(StateMachine::InvalidTransition, + expect(transition).to raise_error(StateMachines::InvalidTransition, /#{Spree.t(:items_cannot_be_shipped)}/) end end @@ -167,7 +167,7 @@ describe Spree::Order::Checkout do it 'raises' do expect { order.restart_checkout! } .to raise_error( - StateMachine::InvalidTransition, + StateMachines::InvalidTransition, /Cannot transition state via :restart_checkout/ ) end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 17c0d6e18f..958ece8e52 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -1321,7 +1321,7 @@ describe Spree::Order do it 'raises' do expect { order.restart_checkout! } - .to raise_error(StateMachine::InvalidTransition) + .to raise_error(StateMachines::InvalidTransition) end end diff --git a/spec/services/order_checkout_restart_spec.rb b/spec/services/order_checkout_restart_spec.rb index f74a427c02..a5b7258e74 100644 --- a/spec/services/order_checkout_restart_spec.rb +++ b/spec/services/order_checkout_restart_spec.rb @@ -49,7 +49,7 @@ describe OrderCheckoutRestart do it "does not reset the order state nor clears incomplete shipments and payments" do expect do OrderCheckoutRestart.new(order).call - end.to raise_error(StateMachine::InvalidTransition) + end.to raise_error(StateMachines::InvalidTransition) expect(order.state).to eq 'payment' expect(order.shipments.count).to eq 1 diff --git a/spec/services/order_workflow_spec.rb b/spec/services/order_workflow_spec.rb index 5b2b6f0bf5..bed3a7b0c9 100644 --- a/spec/services/order_workflow_spec.rb +++ b/spec/services/order_workflow_spec.rb @@ -49,7 +49,7 @@ describe OrderWorkflow do end it "raises error" do - expect { service.complete! }.to raise_error(StateMachine::InvalidTransition) + expect { service.complete! }.to raise_error(StateMachines::InvalidTransition) end end end