diff --git a/api/app/controllers/spree/api/checkouts_controller.rb b/api/app/controllers/spree/api/checkouts_controller.rb index af51911573b..40c5c431732 100644 --- a/api/app/controllers/spree/api/checkouts_controller.rb +++ b/api/app/controllers/spree/api/checkouts_controller.rb @@ -19,7 +19,7 @@ def next authorize! :update, @order, order_token @order.next! respond_with(@order, default_template: 'spree/api/orders/show', status: 200) - rescue StateMachine::InvalidTransition + rescue StateMachines::InvalidTransition respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422) end diff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rb index 3d58449c9bb..7801b7bcb5f 100644 --- a/api/spec/spec_helper.rb +++ b/api/spec/spec_helper.rb @@ -20,21 +20,6 @@ puts "Could not load dummy application. Please ensure you have run `bundle exec rake test_app`" exit end -# -# STATE MACHINE GEM HACK -# Rails 4.1.0.rc1 and StateMachine don't play nice -# https://github.com/pluginaweek/state_machine/issues/295 -require 'state_machine' -require 'state_machine/version' - -unless StateMachine::VERSION == '1.2.0' - # If you see this message, please test removing this file - # If it's still required, please bump up the version above - puts "StateMachine Hack says: Please remove me, StateMachine version has changed #{__FILE__} #{__LINE__} " -end -module StateMachine::Integrations::ActiveModel - public :around_validation -end diff --git a/core/app/models/spree/inventory_unit.rb b/core/app/models/spree/inventory_unit.rb index ef962ac004b..c036b18e030 100644 --- a/core/app/models/spree/inventory_unit.rb +++ b/core/app/models/spree/inventory_unit.rb @@ -17,6 +17,7 @@ class InventoryUnit < ActiveRecord::Base end # state machine (see http://github.com/pluginaweek/state_machine/tree/master for details) + # comment updated 08/2017: see https://github.com/state-machines/state_machines state_machine initial: :on_hand do event :fill_backorder do transition to: :on_hand, from: :backordered diff --git a/core/app/models/spree/order/checkout.rb b/core/app/models/spree/order/checkout.rb index 22e535240d2..366243e71eb 100644 --- a/core/app/models/spree/order/checkout.rb +++ b/core/app/models/spree/order/checkout.rb @@ -34,7 +34,7 @@ def self.define_state_machine! 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/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb index b317737b747..78b5d7bd81a 100644 --- a/core/app/models/spree/payment.rb +++ b/core/app/models/spree/payment.rb @@ -48,6 +48,7 @@ def persist_invalid end # order state machine (see http://github.com/pluginaweek/state_machine/tree/master for details) + # comment updated 08/2017: see https://github.com/state-machines/state_machines state_machine initial: :checkout do # With card payments, happens before purchase or authorization happens event :started_processing do diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb index 3455c47ee23..ea8a20af1ba 100644 --- a/core/app/models/spree/shipment.rb +++ b/core/app/models/spree/shipment.rb @@ -30,6 +30,7 @@ class Shipment < ActiveRecord::Base scope :trackable, -> { where("tracking IS NOT NULL AND tracking != ''") } # shipment state machine (see http://github.com/pluginaweek/state_machine/tree/master for details) + # comment updated 08/2017: see https://github.com/state-machines/state_machines state_machine initial: :pending, use_transactions: false do event :ready do transition from: :pending, to: :ready, if: lambda { |shipment| @@ -153,7 +154,7 @@ def discounted_cost alias discounted_amount discounted_cost # Only one of either included_tax_total or additional_tax_total is set - # This method returns the total of the two. Saves having to check if + # This method returns the total of the two. Saves having to check if # tax is included or additional. def tax_total included_tax_total + additional_tax_total diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb index ae50f99a95a..2467422b7a2 100644 --- a/core/lib/spree/core.rb +++ b/core/lib/spree/core.rb @@ -9,7 +9,7 @@ require 'paperclip' require 'paranoia' require 'ransack' -require 'state_machine' +require 'state_machines-activerecord' require 'friendly_id' require 'font-awesome-rails' require 'responders' diff --git a/core/spec/models/spree/order/checkout_spec.rb b/core/spec/models/spree/order/checkout_spec.rb index 1aafee0e680..07780111920 100644 --- a/core/spec/models/spree/order/checkout_spec.rb +++ b/core/spec/models/spree/order/checkout_spec.rb @@ -99,7 +99,7 @@ def assert_state_changed(order, from, to) it "cannot transition to address without any line items" do order.line_items.should be_blank - lambda { order.next! }.should raise_error(StateMachine::InvalidTransition, /#{Spree.t(:there_are_no_items_for_this_order)}/) + lambda { order.next! }.should raise_error(StateMachines::InvalidTransition, /#{Spree.t(:there_are_no_items_for_this_order)}/) end context "from address" do @@ -137,7 +137,7 @@ def assert_state_changed(order, from, to) context "if there are no shipping rates for any shipment" do specify do transition = lambda { order.next! } - transition.should raise_error(StateMachine::InvalidTransition, /#{Spree.t(:items_cannot_be_shipped)}/) + transition.should raise_error(StateMachines::InvalidTransition, /#{Spree.t(:items_cannot_be_shipped)}/) end end end diff --git a/core/spec/spec_helper.rb b/core/spec/spec_helper.rb index 3ebd2f5a7e4..12b2f2e1856 100644 --- a/core/spec/spec_helper.rb +++ b/core/spec/spec_helper.rb @@ -15,24 +15,9 @@ # from the project root directory. ENV["RAILS_ENV"] ||= 'test' -# STATE MACHINE GEM HACK -# Rails 4.1.0.rc1 and StateMachine don't play nice -# https://github.com/pluginaweek/state_machine/issues/295 -require 'state_machine' -require 'state_machine/version' - -unless StateMachine::VERSION == '1.2.0' - # If you see this message, please test removing this file - # If it's still required, please bump up the version above - puts "StateMachine Hack says: Please remove me, StateMachine version has changed #{__FILE__} #{__LINE__} " -end require 'byebug' -module StateMachine::Integrations::ActiveModel - public :around_validation -end - begin require File.expand_path("../dummy/config/environment", __FILE__) rescue LoadError diff --git a/core/spree_core.gemspec b/core/spree_core.gemspec index 198e3c2f32f..1f8e56588a4 100644 --- a/core/spree_core.gemspec +++ b/core/spree_core.gemspec @@ -37,7 +37,7 @@ Gem::Specification.new do |s| s.add_dependency 'rails', '~> 4.2.9' s.add_dependency 'ransack', '~> 1.4.1' s.add_dependency 'responders', '~> 2.3.0' - s.add_dependency 'state_machine', '1.2.0' + s.add_dependency 'state_machines-activerecord', '~> 0.5.0' s.add_dependency 'stringex', '~> 1.5.1' s.add_dependency 'truncate_html', '0.9.2' s.add_development_dependency 'byebug'