Class: MachineCollectionStateInitializationTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- MachineCollectionStateInitializationTest
- Defined in:
- lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_should_not_set_states_if_ignored ⇒ Object
- #test_should_not_set_states_if_not_empty ⇒ Object
- #test_should_only_initialize_dynamic_states_if_dynamic_enabled ⇒ Object
- #test_should_only_initialize_static_states_if_dynamic_disabled ⇒ Object
- #test_should_set_states_if_empty ⇒ Object
- #test_should_set_states_if_nil ⇒ Object
- #test_should_set_states_if_not_ignored_and_empty ⇒ Object
- #test_should_set_states_if_not_ignored_and_nil ⇒ Object
- #test_should_set_states_if_not_ignored_and_not_empty ⇒ Object
Instance Method Details
#setup ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/branston/vendor/plugins/state_machine/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_not_set_states_if_ignored ⇒ Object
73 74 75 76 77 78 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 73 def test_should_not_set_states_if_ignored @machines.initialize_states(@object, :ignore => [:state, :alarm_state]) assert_nil @object.state assert_nil @object.alarm_state end |
#test_should_not_set_states_if_not_empty ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 50 def test_should_not_set_states_if_not_empty @object.state = 'idling' @object.alarm_state = 'off' @machines.initialize_states(@object) assert_equal 'idling', @object.state assert_equal 'off', @object.alarm_state end |
#test_should_only_initialize_dynamic_states_if_dynamic_enabled ⇒ Object
66 67 68 69 70 71 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 66 def test_should_only_initialize_dynamic_states_if_dynamic_enabled @machines.initialize_states(@object, :dynamic => true) assert_nil @object.state assert_equal 'active', @object.alarm_state end |
#test_should_only_initialize_static_states_if_dynamic_disabled ⇒ Object
59 60 61 62 63 64 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 59 def test_should_only_initialize_static_states_if_dynamic_disabled @machines.initialize_states(@object, :dynamic => false) assert_equal 'parked', @object.state assert_nil @object.alarm_state end |
#test_should_set_states_if_empty ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 41 def test_should_set_states_if_empty @object.state = '' @object.alarm_state = '' @machines.initialize_states(@object) assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end |
#test_should_set_states_if_nil ⇒ Object
34 35 36 37 38 39 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 34 def test_should_set_states_if_nil @machines.initialize_states(@object) assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end |
#test_should_set_states_if_not_ignored_and_empty ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 87 def test_should_set_states_if_not_ignored_and_empty @object.state = '' @object.alarm_state = '' @machines.initialize_states(@object, :ignore => []) assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end |
#test_should_set_states_if_not_ignored_and_nil ⇒ Object
80 81 82 83 84 85 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 80 def test_should_set_states_if_not_ignored_and_nil @machines.initialize_states(@object, :ignore => []) assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end |
#test_should_set_states_if_not_ignored_and_not_empty ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/branston/vendor/plugins/state_machine/test/unit/machine_collection_test.rb', line 96 def test_should_set_states_if_not_ignored_and_not_empty @object.state = 'idling' @object.alarm_state = 'inactive' @machines.initialize_states(@object, :ignore => []) assert_equal 'parked', @object.state assert_equal 'active', @object.alarm_state end |