Sha256: d34d09011512929bdc260d60fecd4eb70e6c431689c995f2920c764779d168b8

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

require_relative '../../test_helper'

class TransitionWithMultipleFailureCallbacksTest < StateMachinesTest
  def setup
    @klass = Class.new

    @machine = StateMachines::Machine.new(@klass)
    @machine.state :parked, :idling
    @machine.event :ignite

    @object = @klass.new
    @object.state = 'parked'
    @transition = StateMachines::Transition.new(@object, @machine, :ignite, :parked, :idling)
  end

  def test_should_run_in_the_order_they_were_defined
    @callbacks = []
    @machine.after_failure { @callbacks << 1 }
    @machine.after_failure { @callbacks << 2 }
    @transition.run_callbacks { { success: false } }

    assert_equal [1, 2], @callbacks
  end

  def test_should_not_run_further_callbacks_if_halted
    @callbacks = []
    @machine.after_failure { @callbacks << 1; throw :halt }
    @machine.after_failure { @callbacks << 2 }

    assert_equal true, @transition.run_callbacks { { success: false } }
    assert_equal [1], @callbacks
  end

  def test_should_fail_if_any_callback_halted
    @machine.after_failure { true }
    @machine.after_failure { throw :halt }

    assert_equal true, @transition.run_callbacks { { success: false } }
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
state_machines-0.5.0 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.4.0 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.3.0 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.2.2 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.2.1 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.2.0 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.1.4 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.1.3 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.1.2 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.1.1 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb
state_machines-0.1.0 test/unit/transition/transition_with_multiple_failure_callbacks_test.rb