Sha256: 99129044fadacd6477e0b5f59bb31958cb905878514b544e1556a0f5056b7f13

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'helper'

class TestState < Test::Unit::TestCase
  def setup
    machine = Class.new do
      include Transitions
      state_machine do
      end
    end.get_state_machine
    state_name = :astate
    @options = { machine: machine, custom_key: :my_key }
    @state   = Transitions::State.new(state_name, @options)
  end

  def new_state_name
    Random.alphanumeric(16)
  end

  test 'sets the name' do
    assert_equal :astate, @state.name
  end

  test 'sets the display_name from name' do
    assert_equal 'Astate', @state.display_name
  end

  test 'sets the display_name from options' do
    assert_equal 'A State', Transitions::State.new(new_state_name, @options.merge(display: 'A State')).display_name
  end

  test 'sets the options and expose them as options' do
    @options.delete(:machine)
    state = Transitions::State.new new_state_name, @options
    assert_equal @options, state.options
  end

  test 'equals a symbol of the same name' do
    assert_equal @state, :astate
  end

  test 'equals a State of the same name' do
    assert_equal @state, @state
  end

  test 'should send a message to the record for an action if the action is present as a symbol' do
    state = Transitions::State.new new_state_name, @options.merge(entering: :foo)

    record = stub
    record.expects(:foo)

    state.call_action(:entering, record)
  end

  test 'should send a message to the record for an action if the action is present as a string' do
    state = Transitions::State.new new_state_name, @options.merge(entering: 'foo')

    record = stub
    record.expects(:foo)

    state.call_action(:entering, record)
  end

  test 'should call a proc, passing in the record for an action if the action is present' do
    state = Transitions::State.new new_state_name, @options.merge(entering: proc(&:foobar))

    record = stub
    record.expects(:foobar)

    state.call_action(:entering, record)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
transitions-1.0.0 test/state/test_state.rb
transitions-0.2.1 test/state/test_state.rb