class TransitionWithAfterCallbacksSkippedTest
Public Instance Methods
setup()
click to toggle source
# File test/unit/transition_test.rb, line 1193 def setup @klass = Class.new @machine = StateMachine::Machine.new(@klass) @machine.state :parked, :idling @machine.event :ignite @object = @klass.new @object.state = 'parked' @transition = StateMachine::Transition.new(@object, @machine, :ignite, :parked, :idling) end
test_should_continue_around_transition_execution_on_second_call()
click to toggle source
# File test/unit/transition_test.rb, line 1233 def test_should_continue_around_transition_execution_on_second_call @callbacks = [] @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1} @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2} @machine.after_transition {@callbacks << :after} assert_equal true, @transition.run_callbacks(:after => false) assert_equal [:before_around_1, :before_around_2], @callbacks assert_equal true, @transition.run_callbacks assert_equal [:before_around_1, :before_around_2, :after_around_2, :after_around_1, :after], @callbacks end
test_should_have_access_to_result_after_continued()
click to toggle source
# File test/unit/transition_test.rb, line 1285 def test_should_have_access_to_result_after_continued @machine.around_transition {|block| @around_before_result = @transition.result; block.call; @around_after_result = @transition.result} @machine.after_transition {@after_result = @transition.result} @transition.run_callbacks(:after => false) @transition.run_callbacks {{:result => 1}} assert_nil @around_before_result assert_equal 1, @around_after_result assert_equal 1, @after_result end
test_should_not_be_able_to_continue_again_after_halted()
click to toggle source
# File test/unit/transition_test.rb, line 1272 def test_should_not_be_able_to_continue_again_after_halted @count = 0 @machine.around_transition {|block| block.call; @count += 1; throw :halt} @machine.after_transition {@count += 1} @transition.run_callbacks(:after => false) 2.times do assert_equal true, @transition.run_callbacks assert_equal 1, @count end end
test_should_not_be_able_to_continue_twice()
click to toggle source
# File test/unit/transition_test.rb, line 1259 def test_should_not_be_able_to_continue_twice @count = 0 @machine.around_transition {|block| block.call; @count += 1} @machine.after_transition {@count += 1} @transition.run_callbacks(:after => false) 2.times do assert_equal true, @transition.run_callbacks assert_equal 2, @count end end
test_should_not_run_after_callbacks()
click to toggle source
# File test/unit/transition_test.rb, line 1219 def test_should_not_run_after_callbacks @machine.after_transition {@run = true} assert_equal true, @transition.run_callbacks(:after => false) assert !@run end
test_should_not_run_around_callbacks_after_yield()
click to toggle source
# File test/unit/transition_test.rb, line 1226 def test_should_not_run_around_callbacks_after_yield @machine.around_transition {|block| block.call; @run = true} assert_equal true, @transition.run_callbacks(:after => false) assert !@run end
test_should_not_run_further_callbacks_if_halted_during_continue_around_transition()
click to toggle source
# File test/unit/transition_test.rb, line 1246 def test_should_not_run_further_callbacks_if_halted_during_continue_around_transition @callbacks = [] @machine.around_transition {|block| @callbacks << :before_around_1; block.call; @callbacks << :after_around_1} @machine.around_transition {|block| @callbacks << :before_around_2; block.call; @callbacks << :after_around_2; throw :halt} @machine.after_transition {@callbacks << :after} assert_equal true, @transition.run_callbacks(:after => false) assert_equal [:before_around_1, :before_around_2], @callbacks assert_equal true, @transition.run_callbacks assert_equal [:before_around_1, :before_around_2, :after_around_2], @callbacks end
test_should_raise_exceptions_during_around_callbacks_after_yield_in_second_execution()
click to toggle source
# File test/unit/transition_test.rb, line 1297 def test_should_raise_exceptions_during_around_callbacks_after_yield_in_second_execution @machine.around_transition {|block| block.call; raise ArgumentError} assert_nothing_raised { @transition.run_callbacks(:after => false) } assert_raise(ArgumentError) { @transition.run_callbacks } end
test_should_run_around_callbacks_before_yield()
click to toggle source
# File test/unit/transition_test.rb, line 1212 def test_should_run_around_callbacks_before_yield @machine.around_transition {|block| @run = true; block.call} assert_equal true, @transition.run_callbacks(:after => false) assert @run end
test_should_run_before_callbacks()
click to toggle source
# File test/unit/transition_test.rb, line 1205 def test_should_run_before_callbacks @machine.before_transition {@run = true} assert_equal true, @transition.run_callbacks(:after => false) assert @run end