Sha256: c6f007b7ced67ada955326c440ccf9f21ad9f98e8156a161cf8822346c7cbdb1

Contents?: true

Size: 1.28 KB

Versions: 9

Compression:

Stored size: 1.28 KB

Contents

require_relative '../../test_helper'

class InvalidTransitionWithIntegrationTest < StateMachinesTest
  module Custom
    include StateMachines::Integrations::Base

    def errors_for(object)
      object.errors
    end
  end

  def setup
    StateMachines::Integrations.register(InvalidTransitionWithIntegrationTest::Custom)

    @klass = Class.new do
      attr_accessor :errors
    end
    @machine = StateMachines::Machine.new(@klass, integration: :custom)
    @machine.state :parked
    @machine.event :ignite

    @object = @klass.new
    @object.state = 'parked'
  end

  def fix_test
    skip
  end

  def test_should_generate_a_message_without_reasons_if_empty
    @object.errors = ''
    invalid_transition = StateMachines::InvalidTransition.new(@object, @machine, :ignite)
    assert_equal 'Cannot transition state via :ignite from :parked', invalid_transition.message
  end

  def test_should_generate_a_message_with_error_reasons_if_errors_found
    @object.errors = 'Id is invalid, Name is invalid'
    invalid_transition = StateMachines::InvalidTransition.new(@object, @machine, :ignite)
    assert_equal 'Cannot transition state via :ignite from :parked (Reason(s): Id is invalid, Name is invalid)', invalid_transition.message
  end

  def teardown
    StateMachines::Integrations.reset
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
state_machines-0.5.0 test/unit/invalid_transition/invalid_transition_with_integration_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/invalid_transition/invalid_transition_with_integration_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/invalid_transition/invalid_transition_with_integration_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/invalid_transition/invalid_transition_with_integration_test.rb
state_machines-0.4.0 test/unit/invalid_transition/invalid_transition_with_integration_test.rb
state_machines-0.3.0 test/unit/invalid_transition/invalid_transition_with_integration_test.rb
state_machines-0.2.2 test/unit/invalid_transition/invalid_transition_with_integration_test.rb
state_machines-0.2.1 test/unit/invalid_transition/invalid_transition_with_integration_test.rb
state_machines-0.2.0 test/unit/invalid_transition/invalid_transition_with_integration_test.rb