class EventWithMatchingDisabledTransitionsTest
Public Instance Methods
invalidate(object, attribute, message, values = [])
click to toggle source
# File test/unit/event_test.rb, line 526 def invalidate(object, attribute, message, values = []) (object.errors ||= []) << generate_message(message, values) end
reset(object)
click to toggle source
# File test/unit/event_test.rb, line 530 def reset(object) object.errors = [] end
setup()
click to toggle source
# File test/unit/event_test.rb, line 522 def setup StateMachine::Integrations.const_set('Custom', Module.new do include StateMachine::Integrations::Base def invalidate(object, attribute, message, values = []) (object.errors ||= []) << generate_message(message, values) end def reset(object) object.errors = [] end end) @klass = Class.new do attr_accessor :errors end @machine = StateMachine::Machine.new(@klass, :integration => :custom) @machine.state :parked, :idling @machine.events << @event = StateMachine::Event.new(@machine, :ignite) @event.transition(:parked => :idling, :if => lambda {false}) @object = @klass.new @object.state = 'parked' end
teardown()
click to toggle source
# File test/unit/event_test.rb, line 627 def teardown StateMachine::Integrations.send(:remove_const, 'Custom') end
test_should_be_able_to_fire_with_disabled_guards()
click to toggle source
# File test/unit/event_test.rb, line 553 def test_should_be_able_to_fire_with_disabled_guards assert @event.can_fire?(@object, :guard => false) end
test_should_have_a_transition_with_disabled_guards()
click to toggle source
# File test/unit/event_test.rb, line 561 def test_should_have_a_transition_with_disabled_guards assert_not_nil @event.transition_for(@object, :guard => false) end
test_should_invalid_with_human_state_name_if_specified()
click to toggle source
# File test/unit/event_test.rb, line 585 def test_should_invalid_with_human_state_name_if_specified klass = Class.new do attr_accessor :errors end machine = StateMachine::Machine.new(klass, :integration => :custom, :messages => {:invalid_transition => 'cannot transition via "%s" from "%s"'}) parked, idling = machine.state :parked, :idling parked.human_name = 'stopped' machine.events << event = StateMachine::Event.new(machine, :ignite) event.transition(:parked => :idling, :if => lambda {false}) object = @klass.new object.state = 'parked' event.fire(object) assert_equal ['cannot transition via "ignite" from "stopped"'], object.errors end
test_should_invalidate_the_state()
click to toggle source
# File test/unit/event_test.rb, line 574 def test_should_invalidate_the_state @event.fire(@object) assert_equal ['cannot transition via "ignite"'], @object.errors end
test_should_invalidate_with_human_event_name()
click to toggle source
# File test/unit/event_test.rb, line 579 def test_should_invalidate_with_human_event_name @event.human_name = 'start' @event.fire(@object) assert_equal ['cannot transition via "start"'], @object.errors end
test_should_not_be_able_to_fire()
click to toggle source
# File test/unit/event_test.rb, line 549 def test_should_not_be_able_to_fire assert !@event.can_fire?(@object) end
test_should_not_change_the_current_state()
click to toggle source
# File test/unit/event_test.rb, line 569 def test_should_not_change_the_current_state @event.fire(@object) assert_equal 'parked', @object.state end
test_should_not_fire()
click to toggle source
# File test/unit/event_test.rb, line 565 def test_should_not_fire assert !@event.fire(@object) end
test_should_not_have_a_transition()
click to toggle source
# File test/unit/event_test.rb, line 557 def test_should_not_have_a_transition assert_nil @event.transition_for(@object) end
test_should_reset_existing_error()
click to toggle source
# File test/unit/event_test.rb, line 604 def test_should_reset_existing_error @object.errors = ['invalid'] @event.fire(@object) assert_equal ['cannot transition via "ignite"'], @object.errors end
test_should_run_failure_callbacks()
click to toggle source
# File test/unit/event_test.rb, line 611 def test_should_run_failure_callbacks callback_args = nil @machine.after_failure {|*args| callback_args = args} @event.fire(@object) object, transition = callback_args assert_equal @object, object assert_not_nil transition assert_equal @object, transition.object assert_equal @machine, transition.machine assert_equal :ignite, transition.event assert_equal :parked, transition.from_name assert_equal :parked, transition.to_name end