class MachineCollectionStateInitializationTest

Public Class Methods

new() click to toggle source
# File test/unit/machine_collection_test.rb, line 25
def initialize
end

Public Instance Methods

setup() click to toggle source
# File test/unit/machine_collection_test.rb, line 14
def setup
  @machines = StateMachine::MachineCollection.new
  
  @klass = Class.new
  
  @machines[:state] = StateMachine::Machine.new(@klass, :state, :initial => :parked)
  @machines[:alarm_state] = StateMachine::Machine.new(@klass, :alarm_state, :initial => lambda {|object| :active})
  @machines[:alarm_state].state :active, :value => lambda {'active'}
  
  # Prevent the auto-initialization hook from firing
  @klass.class_eval do
    def initialize
    end
  end
  
  @object = @klass.new
  @object.state = nil
  @object.alarm_state = nil
end
test_should_initialize_all_states_without_block() click to toggle source
# File test/unit/machine_collection_test.rb, line 57
def test_should_initialize_all_states_without_block
  @machines.initialize_states(@object)
  
  assert_equal 'parked', @object.state
  assert_equal 'active', @object.alarm_state
end
test_should_initialize_existing_dynamic_states_if_forced() click to toggle source
# File test/unit/machine_collection_test.rb, line 100
def test_should_initialize_existing_dynamic_states_if_forced
  @object.alarm_state = 'inactive'
  @machines.initialize_states(@object, :dynamic => :force)
  assert_equal 'active', @object.alarm_state
end
test_should_initialize_existing_static_states_by_default() click to toggle source
# File test/unit/machine_collection_test.rb, line 70
def test_should_initialize_existing_static_states_by_default
  @object.state = 'idling'
  @machines.initialize_states(@object)
  assert_equal 'parked', @object.state
end
test_should_initialize_existing_static_states_if_forced() click to toggle source
# File test/unit/machine_collection_test.rb, line 76
def test_should_initialize_existing_static_states_if_forced
  @object.state = 'idling'
  @machines.initialize_states(@object, :static => :force)
  assert_equal 'parked', @object.state
end
test_should_not_initialize_existing_dynamic_states_by_default() click to toggle source
# File test/unit/machine_collection_test.rb, line 94
def test_should_not_initialize_existing_dynamic_states_by_default
  @object.alarm_state = 'inactive'
  @machines.initialize_states(@object)
  assert_equal 'inactive', @object.alarm_state
end
test_should_not_initialize_existing_dynamic_states_if_not_forced() click to toggle source
# File test/unit/machine_collection_test.rb, line 106
def test_should_not_initialize_existing_dynamic_states_if_not_forced
  @object.alarm_state = 'inactive'
  @machines.initialize_states(@object, :dynamic => true)
  assert_equal 'inactive', @object.alarm_state
end
test_should_not_initialize_existing_static_states_if_not_forced() click to toggle source
# File test/unit/machine_collection_test.rb, line 82
def test_should_not_initialize_existing_static_states_if_not_forced
  @object.state = 'idling'
  @machines.initialize_states(@object, :static => true)
  assert_equal 'idling', @object.state
end
test_should_only_initialize_dynamic_states_after_block() click to toggle source
# File test/unit/machine_collection_test.rb, line 48
def test_should_only_initialize_dynamic_states_after_block
  @machines.initialize_states(@object) do
    @alarm_state_in_block = @object.alarm_state
  end
  
  assert_nil @alarm_state_in_block
  assert_equal 'active', @object.alarm_state
end
test_should_only_initialize_static_states_prior_to_block() click to toggle source
# File test/unit/machine_collection_test.rb, line 38
def test_should_only_initialize_static_states_prior_to_block
  @machines.initialize_states(@object) do
    @state_in_block = @object.state
    @alarm_state_in_block = @object.alarm_state
  end
  
  assert_equal 'parked', @state_in_block
  assert_nil @alarm_state_in_block
end
test_should_raise_exception_if_invalid_option_specified() click to toggle source
# File test/unit/machine_collection_test.rb, line 34
def test_should_raise_exception_if_invalid_option_specified
  assert_raise(ArgumentError) {@machines.initialize_states(@object, :invalid => true)}
end
test_should_skip_dynamic_states_if_disabled() click to toggle source
# File test/unit/machine_collection_test.rb, line 88
def test_should_skip_dynamic_states_if_disabled
  @machines.initialize_states(@object, :dynamic => false)
  assert_equal 'parked', @object.state
  assert_nil @object.alarm_state
end
test_should_skip_static_states_if_disabled() click to toggle source
# File test/unit/machine_collection_test.rb, line 64
def test_should_skip_static_states_if_disabled
  @machines.initialize_states(@object, :static => false)
  assert_nil @object.state
  assert_equal 'active', @object.alarm_state
end