0
@@ -4,34 +4,39 @@ class TransitionTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
ff', 'on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
n')
0
- def test_should_have_a_from_state
0
- assert_equal 'off', @transition.from_state
0
+ def test_should_not_have_any_from_states
0
+ assert @transition.from_states.empty?
0
- def test_should_have_a_to_state
0
- assert_equal 'on', @transition.to_state
0
+ def test_should_not_be_a_loopback_if_from_state_is_different
0
+ assert !@transition.loopback?('off')
0
- def test_should_not_be_a_loopback
0
- assert !@transition.loopback?
0
+ def test_should_have_a_to_state
0
+ assert_equal 'on', @transition.to_state
0
- def test_should_not_be_able_to_perform_if_record_state_is_not_from_state
0
- record = new_switch(:state => 'on')
0
- assert !@transition.can_perform_on?(record)
0
+ def test_should_be_loopback_if_from_state_is_same
0
+ assert @transition.loopback?('on')
0
- def test_should_be_able_to_perform_
if_record_state_is_from_state0
+ def test_should_be_able_to_perform_
on_all_states0
record = new_switch(:state => 'off')
0
assert @transition.can_perform_on?(record)
0
+ record = new_switch(:state => 'on')
0
+ assert @transition.can_perform_on?(record)
0
- def test_should_perform_for_
valid_from_state0
+ def test_should_perform_for_
all_states0
record = new_switch(:state => 'off')
0
assert @transition.perform(record)
0
+ record = new_switch(:state => 'on')
0
+ assert @transition.perform(record)
0
def test_should_not_raise_exception_if_not_valid_during_perform
0
@@ -63,58 +68,81 @@ class TransitionTest < Test::Unit::TestCase
0
-class TransitionWith
outFromStateTest < Test::Unit::TestCase
0
+class TransitionWith
LoopbackTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event,
nil, 'on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event,
'on', 'on')
0
- def test_should_not_have_a_from_state
0
- assert_nil @transition.from_state
0
+ def test_should_be_able_to_perform
0
+ record = new_switch(:state => 'on')
0
+ assert @transition.can_perform_on?(record)
0
- def test_should_be_able_to_perform_on_all_states
0
- record = new_switch(:state => 'off')
0
- assert @transition.can_perform_on?(record)
0
+ def test_should_perform_for_valid_from_state
0
record = new_switch(:state => 'on')
0
- assert @transition.
can_perform_on?(record)
0
+ assert @transition.
perform(record)
0
-class TransitionWith
LoopbackTest < Test::Unit::TestCase
0
+class TransitionWith
FromStateTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event, 'on', 'o
n')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event, 'on', 'o
ff')
0
def test_should_have_a_from_state
0
- assert_equal
'on', @transition.from_state0
+ assert_equal
['off'], @transition.from_states0
- def test_should_have_a_to_state
0
- assert_equal 'on', @transition.to_state
0
+ def test_should_not_be_able_to_perform_if_record_state_is_not_from_state
0
+ record = new_switch(:state => 'on')
0
+ assert !@transition.can_perform_on?(record)
0
- def test_should_be_a_loopback
0
- assert @transition.loopback?
0
+ def test_should_be_able_to_perform_if_record_state_is_from_state
0
+ record = new_switch(:state => 'off')
0
+ assert @transition.can_perform_on?(record)
0
- def test_should_
not_be_able_to_perform_if_record_state_is_not_from_state
0
+ def test_should_
perform_for_valid_from_state
0
record = new_switch(:state => 'off')
0
+ assert @transition.perform(record)
0
+class TransitionWithMultipleFromStatesTest < Test::Unit::TestCase
0
+ @machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
+ @event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event, 'on', 'off', 'on')
0
+ def test_should_have_multiple_from_states
0
+ assert_equal ['off', 'on'], @transition.from_states
0
+ def test_should_not_be_able_to_perform_if_record_state_is_not_from_state
0
+ record = new_switch(:state => 'unknown')
0
assert !@transition.can_perform_on?(record)
0
- def test_should_be_able_to_perform_if_record_is_in_from_state
0
+ def test_should_be_able_to_perform_if_record_state_is_any_from_state
0
+ record = new_switch(:state => 'off')
0
+ assert @transition.can_perform_on?(record)
0
record = new_switch(:state => 'on')
0
assert @transition.can_perform_on?(record)
0
- def test_should_perform_for_valid_from_state
0
- record = new_switch(:state => 'on')
0
+ def test_should_perform_for_any_valid_from_state
0
+ record = new_switch(:state => 'off')
0
assert @transition.perform(record)
0
+ record = new_switch(:state => 'on')
0
+ assert @transition.can_perform_on?(record)
0
@@ -122,7 +150,7 @@ class TransitionAfterBeingPerformedTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
ff', 'on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
n', 'off')
0
@record = create_switch(:state => 'off')
0
@transition.perform(@record)
0
@@ -162,7 +190,7 @@ class TransitionWithCallbacksTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
ff', 'on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event, 'o
n', 'off')
0
@record = create_switch(:state => 'off')
0
Switch.define_callbacks :before_exit_state_off, :before_enter_state_on, :after_exit_state_off, :after_enter_state_on
0
@@ -295,7 +323,7 @@ class TransitionWithoutFromStateAndCallbacksTest < Test::Unit::TestCase
0
@machine = PluginAWeek::StateMachine::Machine.new(Switch, 'state', :initial => 'off')
0
@event = PluginAWeek::StateMachine::Event.new(@machine, 'turn_on')
0
- @transition = PluginAWeek::StateMachine::Transition.new(@event,
nil, 'on')
0
+ @transition = PluginAWeek::StateMachine::Transition.new(@event,
'on')
0
@record = create_switch(:state => 'off')
0
Switch.define_callbacks :before_exit_state_off, :before_enter_state_on, :after_exit_state_off, :after_enter_state_on
Comments
No one has commented yet.