Sha256: ec293c06683e70f21a129c3911d0eae795e092841b56e0417ba4c6ff053bb01c

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

require_relative '../../test_helper'

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

    def invalidate(object, _attribute, message, values = [])
      object.error = generate_message(message, values)
    end
  end

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

    @klass = Class.new do
      attr_accessor :error
    end

    @machine = StateMachines::Machine.new(@klass, integration: :custom, messages: {invalid_transition: 'cannot %s'})
    @machine.state :parked

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

  def test_generate_custom_message
    assert_equal 'cannot park', @machine.generate_message(:invalid_transition, [[:event, :park]])
  end

  def test_use_custom_message
    @machine.invalidate(@object, :state, :invalid_transition, [[:event, 'park']])
    assert_equal 'cannot park', @object.error
  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/machine/machine_with_custom_invalidation_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_with_custom_invalidation_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_with_custom_invalidation_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/state_machines-0.2.2/test/unit/machine/machine_with_custom_invalidation_test.rb
state_machines-0.4.0 test/unit/machine/machine_with_custom_invalidation_test.rb
state_machines-0.3.0 test/unit/machine/machine_with_custom_invalidation_test.rb
state_machines-0.2.2 test/unit/machine/machine_with_custom_invalidation_test.rb
state_machines-0.2.1 test/unit/machine/machine_with_custom_invalidation_test.rb
state_machines-0.2.0 test/unit/machine/machine_with_custom_invalidation_test.rb