Sha256: 2b8b547995f83bf0ea3d16ca592ad9e99d095a7b891da20d98fad5fb39663303

Contents?: true

Size: 1.59 KB

Versions: 14

Compression:

Stored size: 1.59 KB

Contents

require_relative '../../test_helper'

class TransitionCollectionWithActionErrorTest < StateMachinesTest
  def setup
    @klass = Class.new do
      def save
        fail ArgumentError
      end
    end
    @before_count = 0
    @around_before_count = 0
    @after_count = 0
    @around_after_count = 0
    @failure_count = 0

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

    @machine.before_transition { @before_count += 1 }
    @machine.after_transition { @after_count += 1 }
    @machine.around_transition { |block| @around_before_count += 1; block.call; @around_after_count += 1 }
    @machine.after_failure { @failure_count += 1 }

    @object = @klass.new

    @transitions = StateMachines::TransitionCollection.new([
      StateMachines::Transition.new(@object, @machine, :ignite, :parked, :idling)
    ])

    @raised = true
    begin
      @transitions.perform
      @raised = false
    rescue ArgumentError
    end
  end

  def test_should_not_catch_exception
    assert @raised
  end

  def test_should_not_persist_state
    assert_equal 'parked', @object.state
  end

  def test_should_run_before_callbacks
    assert_equal 1, @before_count
  end

  def test_should_run_around_callbacks_before_yield
    assert_equal 1, @around_before_count
  end

  def test_should_not_run_after_callbacks
    assert_equal 0, @after_count
  end

  def test_should_not_run_around_callbacks_after_yield
    assert_equal 0, @around_after_count
  end

  def test_should_not_run_failure_callbacks
    assert_equal 0, @failure_count
  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_action_error_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/transition_collection/transition_collection_with_action_error_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/transition_collection/transition_collection_with_action_error_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.4.0 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.3.0 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.2.2 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.2.1 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.2.0 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.1.4 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.1.3 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.1.2 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.1.1 test/unit/transition_collection/transition_collection_with_action_error_test.rb
state_machines-0.1.0 test/unit/transition_collection/transition_collection_with_action_error_test.rb