File: machine_test.rb

package info (click to toggle)
rails 2.3.5-1.2%2Bsqueeze8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 18,248 kB
  • ctags: 20,944
  • sloc: ruby: 122,413; makefile: 72; sql: 43; sh: 1
file content (43 lines) | stat: -rw-r--r-- 1,047 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'test_helper'

class MachineTestSubject
  include ActiveModel::StateMachine

  state_machine do
    state :open
    state :closed
  end

  state_machine :initial => :foo do
    event :shutdown do
      transitions :from => :open, :to => :closed
    end

    event :timeout do
      transitions :from => :open, :to => :closed
    end
  end

  state_machine :extra, :initial => :bar do
  end
end

class StateMachineMachineTest < ActiveModel::TestCase
  test "allows reuse of existing machines" do
    assert_equal 2, MachineTestSubject.state_machines.size
  end

  test "sets #initial_state from :initial option" do
    assert_equal :bar, MachineTestSubject.state_machine(:extra).initial_state
  end

  test "accesses non-default state machine" do
    assert_kind_of ActiveModel::StateMachine::Machine, MachineTestSubject.state_machine(:extra)
  end

  test "finds events for given state" do
    events = MachineTestSubject.state_machine.events_for(:open)
    assert events.include?(:shutdown)
    assert events.include?(:timeout)
  end
end