Sha256: b2f158cf46957c4573558cae49cab32a596170aed1de4c4949b5cba2c0314a3d

Contents?: true

Size: 1.63 KB

Versions: 14

Compression:

Stored size: 1.63 KB

Contents

require_relative '../../test_helper'

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

    @callbacks = []

    @machine = StateMachines::Machine.new(@klass, initial: :parked)
    @machine.state :idling
    @machine.event :ignite
    @machine.around_transition { |block| @callbacks << :around_before; block.call; @callbacks << :around_after }

    @object = @klass.new

    @transitions = StateMachines::TransitionCollection.new([
      @transition = StateMachines::Transition.new(@object, @machine, :ignite, :parked, :idling)
    ], after: false)
    @result = @transitions.perform
  end

  def test_should_raise_exception
    skip('Not supported') if StateMachines::Transition.pause_supported?
    assert_raises(ArgumentError) { @transitions.perform }
  end

  def test_should_succeed
    skip unless StateMachines::Transition.pause_supported?

    assert_equal true, @result
  end

  def test_should_not_run_around_callbacks_after_yield
    skip unless StateMachines::Transition.pause_supported?

    refute @callbacks.include?(:around_after)
  end

  def test_should_run_around_callbacks_after_yield_on_subsequent_perform
    skip unless StateMachines::Transition.pause_supported?

    StateMachines::TransitionCollection.new([@transition]).perform
    assert @callbacks.include?(:around_after)
  end

  def test_should_not_rerun_around_callbacks_before_yield_on_subsequent_perform
    skip unless StateMachines::Transition.pause_supported?

    @callbacks = []
    StateMachines::TransitionCollection.new([@transition]).perform
    refute @callbacks.include?(:around_before)
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

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