Sha256: d99bb56c1702396a90677459a56b6b2fab78713015f69afb05182dfb5ae751c2

Contents?: true

Size: 1.9 KB

Versions: 14

Compression:

Stored size: 1.9 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.new {|r| r.foobar})

    record = stub
    record.expects(:foobar)

    state.call_action(:entering, record)
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
transitions-0.2.0 test/state/test_state.rb
transitions-0.1.13 test/state/test_state.rb
transitions-0.1.12 test/state/test_state.rb
transitions-0.1.11 test/state/test_state.rb
transitions-0.1.10 test/state/test_state.rb
transitions-0.1.9 test/state/test_state.rb
transitions-0.1.8 test/state/test_state.rb
transitions-0.1.7 test/state/test_state.rb
transitions-0.1.6 test/state/test_state.rb
transitions-0.1.5 test/state/test_state.rb
transitions-0.1.4 test/state/test_state.rb
transitions-0.1.3 test/state/test_state.rb
transitions-0.1.2 test/state/test_state.rb
transitions-0.1.1 test/state/test_state.rb