Sha256: 1d6e0249e1a8e29f10495b39daab3d4e2d2321b43e163a85c002f4e58c754869

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

require "helper"

class StateTestSubject
  include Transitions

  state_machine do
  end
end

class TestState < Test::Unit::TestCase
  def setup
    @state_name = :astate
    @machine = StateTestSubject.state_machine
    @options = { :crazy_custom_key => "key", :machine => @machine }
  end

  def new_state(options={})
    Transitions::State.new(@state_name, @options.merge(options))
  end

  test "sets the name" do
    assert_equal :astate, new_state.name
  end

  test "sets the display_name from name" do
    assert_equal "Astate", new_state.display_name
  end

  test "sets the display_name from options" do
    assert_equal "A State", new_state(:display => "A State").display_name
  end

  test "sets the options and expose them as options" do
    @options.delete(:machine)
    assert_equal @options, new_state.options
  end

  test "equals a symbol of the same name" do
    assert_equal new_state, :astate
  end

  test "equals a State of the same name" do
    assert_equal new_state, new_state
  end

  test "should send a message to the record for an action if the action is present as a symbol" do
    state = new_state(: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 = new_state(: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 = new_state(:entering => Proc.new {|r| r.foobar})

    record = stub
    record.expects(:foobar)

    state.call_action(:entering, record)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
transitions-0.0.17 test/test_state.rb
transitions-0.0.16 test/test_state.rb
transitions-0.0.14 test/test_state.rb
transitions-0.0.13 test/test_state.rb
transitions-0.0.12 test/test_state.rb
transitions-0.0.11 test/test_state.rb
transitions-0.0.10 test/test_state.rb
transitions-0.0.9 test/test_state.rb
transitions-0.0.5 test/test_state.rb