class EventWithMatchingEnabledTransitionsTest

Public Instance Methods

invalidate(object, attribute, message, values = []) click to toggle source
# File test/unit/event_test.rb, line 637
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 641
def reset(object)
  object.errors = []
end
setup() click to toggle source
# File test/unit/event_test.rb, line 633
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)
  
  @object = @klass.new
  @object.state = 'parked'
end
teardown() click to toggle source
# File test/unit/event_test.rb, line 693
def teardown
  StateMachine::Integrations.send(:remove_const, 'Custom')
end
test_should_be_able_to_fire() click to toggle source
# File test/unit/event_test.rb, line 660
def test_should_be_able_to_fire
  assert @event.can_fire?(@object)
end
test_should_change_the_current_state() click to toggle source
# File test/unit/event_test.rb, line 676
def test_should_change_the_current_state
  @event.fire(@object)
  assert_equal 'idling', @object.state
end
test_should_fire() click to toggle source
# File test/unit/event_test.rb, line 672
def test_should_fire
  assert @event.fire(@object)
end
test_should_have_a_transition() click to toggle source
# File test/unit/event_test.rb, line 664
def test_should_have_a_transition
  transition = @event.transition_for(@object)
  assert_not_nil transition
  assert_equal 'parked', transition.from
  assert_equal 'idling', transition.to
  assert_equal :ignite, transition.event
end
test_should_not_invalidate_the_state() click to toggle source
# File test/unit/event_test.rb, line 688
def test_should_not_invalidate_the_state
  @event.fire(@object)
  assert_equal [], @object.errors
end
test_should_reset_existing_error() click to toggle source
# File test/unit/event_test.rb, line 681
def test_should_reset_existing_error
  @object.errors = ['invalid']
  
  @event.fire(@object)
  assert_equal [], @object.errors
end