class TransitionCollectionWithBlockTest

Public Instance Methods

save() click to toggle source
# File test/unit/transition_collection_test.rb, line 717
def save
  (@actions ||= []) << :save
end
setup() click to toggle source
# File test/unit/transition_collection_test.rb, line 713
def setup
  @klass = Class.new do
    attr_reader :actions
    
    def save
      (@actions ||= []) << :save
    end
  end
  
  @state = StateMachine::Machine.new(@klass, :state, :initial => :parked, :action => :save)
  @state.state  :idling
  @state.event :ignite
  
  @status = StateMachine::Machine.new(@klass, :status, :initial => :first_gear, :action => :save)
  @status.state :second_gear
  @status.event :shift_up
  
  @object = @klass.new
  @transitions = StateMachine::TransitionCollection.new([
    @state_transition = StateMachine::Transition.new(@object, @state, :ignite, :parked, :idling),
    @status_transition = StateMachine::Transition.new(@object, @status, :shift_up, :first_gear, :second_gear)
  ])
  @result = @transitions.perform { 1 }
end
test_should_not_run_machine_actions() click to toggle source
# File test/unit/transition_collection_test.rb, line 747
def test_should_not_run_machine_actions
  assert_nil @object.actions
end
test_should_persist_states() click to toggle source
# File test/unit/transition_collection_test.rb, line 742
def test_should_persist_states
  assert_equal 'idling', @object.state
  assert_equal 'second_gear', @object.status
end
test_should_succeed() click to toggle source
# File test/unit/transition_collection_test.rb, line 738
def test_should_succeed
  assert_equal 1, @result
end
test_should_use_result_as_transition_result() click to toggle source
# File test/unit/transition_collection_test.rb, line 751
def test_should_use_result_as_transition_result
  assert_equal 1, @state_transition.result
  assert_equal 1, @status_transition.result
end