Skip to content

Commit

Permalink
Merge pull request #34 from Fullscript/state-machines-activerecord-ra…
Browse files Browse the repository at this point in the history
…ils42

gem change: state_machine
  • Loading branch information
glongman authored Aug 8, 2017
2 parents 747817e + b4cd830 commit b1d3c48
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/checkouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 0 additions & 15 deletions api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/inventory_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions core/app/models/spree/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions core/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/spree_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b1d3c48

Please sign in to comment.