state_machine 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/CHANGELOG.rdoc +17 -0
  2. data/LICENSE +1 -1
  3. data/README.rdoc +54 -84
  4. data/Rakefile +1 -1
  5. data/examples/Car_state.png +0 -0
  6. data/examples/Vehicle_state.png +0 -0
  7. data/examples/auto_shop.rb +11 -0
  8. data/examples/car.rb +19 -0
  9. data/examples/traffic_light.rb +9 -0
  10. data/examples/vehicle.rb +35 -0
  11. data/lib/state_machine.rb +65 -52
  12. data/lib/state_machine/assertions.rb +1 -1
  13. data/lib/state_machine/callback.rb +13 -9
  14. data/lib/state_machine/eval_helpers.rb +4 -3
  15. data/lib/state_machine/event.rb +51 -33
  16. data/lib/state_machine/extensions.rb +2 -2
  17. data/lib/state_machine/guard.rb +47 -41
  18. data/lib/state_machine/integrations.rb +67 -0
  19. data/lib/state_machine/integrations/active_record.rb +62 -36
  20. data/lib/state_machine/integrations/active_record/observer.rb +41 -0
  21. data/lib/state_machine/integrations/data_mapper.rb +23 -37
  22. data/lib/state_machine/integrations/data_mapper/observer.rb +23 -9
  23. data/lib/state_machine/integrations/sequel.rb +23 -24
  24. data/lib/state_machine/machine.rb +380 -277
  25. data/lib/state_machine/node_collection.rb +142 -0
  26. data/lib/state_machine/state.rb +114 -69
  27. data/lib/state_machine/state_collection.rb +38 -0
  28. data/lib/state_machine/transition.rb +36 -17
  29. data/test/active_record.log +2940 -85664
  30. data/test/functional/state_machine_test.rb +49 -53
  31. data/test/sequel.log +747 -11990
  32. data/test/unit/assertions_test.rb +2 -1
  33. data/test/unit/callback_test.rb +14 -12
  34. data/test/unit/eval_helpers_test.rb +25 -6
  35. data/test/unit/event_test.rb +144 -124
  36. data/test/unit/guard_test.rb +118 -140
  37. data/test/unit/integrations/active_record_test.rb +102 -68
  38. data/test/unit/integrations/data_mapper_test.rb +48 -37
  39. data/test/unit/integrations/sequel_test.rb +34 -25
  40. data/test/unit/integrations_test.rb +42 -0
  41. data/test/unit/machine_test.rb +460 -531
  42. data/test/unit/node_collection_test.rb +208 -0
  43. data/test/unit/state_collection_test.rb +167 -0
  44. data/test/unit/state_machine_test.rb +1 -1
  45. data/test/unit/state_test.rb +223 -200
  46. data/test/unit/transition_test.rb +81 -46
  47. metadata +17 -3
  48. data/test/data_mapper.log +0 -30860
@@ -87,6 +87,7 @@ begin
87
87
  def setup
88
88
  @model = new_model
89
89
  @machine = StateMachine::Machine.new(@model)
90
+ @machine.state :parked, :idling, :first_gear
90
91
  end
91
92
 
92
93
  def test_should_create_singular_with_scope
@@ -94,10 +95,10 @@ begin
94
95
  end
95
96
 
96
97
  def test_should_only_include_records_with_state_in_singular_with_scope
97
- off = @model.create :state => 'off'
98
- on = @model.create :state => 'on'
98
+ parked = @model.create :state => 'parked'
99
+ idling = @model.create :state => 'idling'
99
100
 
100
- assert_equal [off], @model.with_state('off')
101
+ assert_equal [parked], @model.with_state(:parked)
101
102
  end
102
103
 
103
104
  def test_should_create_plural_with_scope
@@ -105,10 +106,10 @@ begin
105
106
  end
106
107
 
107
108
  def test_should_only_include_records_with_states_in_plural_with_scope
108
- off = @model.create :state => 'off'
109
- on = @model.create :state => 'on'
109
+ parked = @model.create :state => 'parked'
110
+ idling = @model.create :state => 'idling'
110
111
 
111
- assert_equal [off, on], @model.with_states('off', 'on')
112
+ assert_equal [parked, idling], @model.with_states(:parked, :idling)
112
113
  end
113
114
 
114
115
  def test_should_create_singular_without_scope
@@ -116,10 +117,10 @@ begin
116
117
  end
117
118
 
118
119
  def test_should_only_include_records_without_state_in_singular_without_scope
119
- off = @model.create :state => 'off'
120
- on = @model.create :state => 'on'
120
+ parked = @model.create :state => 'parked'
121
+ idling = @model.create :state => 'idling'
121
122
 
122
- assert_equal [off], @model.without_state('on')
123
+ assert_equal [parked], @model.without_state(:idling)
123
124
  end
124
125
 
125
126
  def test_should_create_plural_without_scope
@@ -127,11 +128,18 @@ begin
127
128
  end
128
129
 
129
130
  def test_should_only_include_records_without_states_in_plural_without_scope
130
- off = @model.create :state => 'off'
131
- on = @model.create :state => 'on'
132
- error = @model.create :state => 'error'
131
+ parked = @model.create :state => 'parked'
132
+ idling = @model.create :state => 'idling'
133
+ first_gear = @model.create :state => 'first_gear'
133
134
 
134
- assert_equal [off, on], @model.without_states('error')
135
+ assert_equal [parked, idling], @model.without_states(:first_gear)
136
+ end
137
+
138
+ def test_should_allow_chaining_scopes
139
+ parked = @model.create :state => 'parked'
140
+ idling = @model.create :state => 'idling'
141
+
142
+ assert_equal [idling], @model.without_state(:parked).with_state(:idling)
135
143
  end
136
144
 
137
145
  def test_should_rollback_transaction_if_false
@@ -154,14 +162,29 @@ begin
154
162
 
155
163
  def test_should_not_override_the_column_reader
156
164
  record = @model.new
157
- record[:state] = 'off'
158
- assert_equal 'off', record.state
165
+ record[:state] = 'parked'
166
+ assert_equal 'parked', record.state
159
167
  end
160
168
 
161
169
  def test_should_not_override_the_column_writer
162
170
  record = @model.new
163
- record.state = 'off'
164
- assert_equal 'off', record[:state]
171
+ record.state = 'parked'
172
+ assert_equal 'parked', record[:state]
173
+ end
174
+ end
175
+
176
+ class MachineWithoutDatabaseTest < ActiveRecord::TestCase
177
+ def setup
178
+ @model = new_model(false) do
179
+ # Simulate the database not being available entirely
180
+ def self.connection
181
+ raise ActiveRecord::ConnectionNotEstablished
182
+ end
183
+ end
184
+ end
185
+
186
+ def test_should_allow_machine_creation
187
+ assert_nothing_raised { StateMachine::Machine.new(@model) }
165
188
  end
166
189
  end
167
190
 
@@ -181,20 +204,21 @@ begin
181
204
  class MachineWithInitialStateTest < ActiveRecord::TestCase
182
205
  def setup
183
206
  @model = new_model
184
- @machine = StateMachine::Machine.new(@model, :initial => 'off')
207
+ @machine = StateMachine::Machine.new(@model, :initial => :parked)
185
208
  @record = @model.new
186
209
  end
187
210
 
188
211
  def test_should_set_initial_state_on_created_object
189
- assert_equal 'off', @record.state
212
+ assert_equal 'parked', @record.state
190
213
  end
191
214
  end
192
215
 
193
216
  class MachineWithColumnStateAttributeTest < ActiveRecord::TestCase
194
217
  def setup
195
218
  @model = new_model
196
- @machine = StateMachine::Machine.new(@model, :initial => 'off')
197
- @machine.other_states('on')
219
+ @machine = StateMachine::Machine.new(@model, :initial => :parked)
220
+ @machine.other_states(:idling)
221
+
198
222
  @record = @model.new
199
223
  end
200
224
 
@@ -210,23 +234,23 @@ begin
210
234
  end
211
235
 
212
236
  def test_should_return_false_for_predicate_if_does_not_match_current_value
213
- assert !@record.state?('on')
237
+ assert !@record.state?(:idling)
214
238
  end
215
239
 
216
240
  def test_should_return_true_for_predicate_if_matches_current_value
217
- assert @record.state?('off')
241
+ assert @record.state?(:parked)
218
242
  end
219
243
 
220
244
  def test_should_raise_exception_for_predicate_if_invalid_state_specified
221
- assert_raise(ArgumentError) { @record.state?('invalid') }
245
+ assert_raise(ArgumentError) { @record.state?(:invalid) }
222
246
  end
223
247
  end
224
248
 
225
249
  class MachineWithNonColumnStateAttributeTest < ActiveRecord::TestCase
226
250
  def setup
227
251
  @model = new_model
228
- @machine = StateMachine::Machine.new(@model, :status, :initial => 'off')
229
- @machine.other_states('on')
252
+ @machine = StateMachine::Machine.new(@model, :status, :initial => :parked)
253
+ @machine.other_states(:idling)
230
254
  @record = @model.new
231
255
  end
232
256
 
@@ -250,28 +274,30 @@ begin
250
274
  end
251
275
 
252
276
  def test_should_return_false_for_predicate_if_does_not_match_current_value
253
- assert !@record.status?('on')
277
+ assert !@record.status?(:idling)
254
278
  end
255
279
 
256
280
  def test_should_return_true_for_predicate_if_matches_current_value
257
- assert @record.status?('off')
281
+ assert @record.status?(:parked)
258
282
  end
259
283
 
260
284
  def test_should_raise_exception_for_predicate_if_invalid_state_specified
261
- assert_raise(ArgumentError) { @record.status?('invalid') }
285
+ assert_raise(ArgumentError) { @record.status?(:invalid) }
262
286
  end
263
287
 
264
288
  def test_should_set_initial_state_on_created_object
265
- assert_equal 'off', @record.status
289
+ assert_equal 'parked', @record.status
266
290
  end
267
291
  end
268
292
 
269
293
  class MachineWithCallbacksTest < ActiveRecord::TestCase
270
294
  def setup
271
295
  @model = new_model
272
- @machine = StateMachine::Machine.new(@model, :initial => 'off')
273
- @record = @model.new(:state => 'off')
274
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
296
+ @machine = StateMachine::Machine.new(@model, :initial => :parked)
297
+ @machine.other_states :idling
298
+
299
+ @record = @model.new(:state => 'parked')
300
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
275
301
  end
276
302
 
277
303
  def test_should_run_before_callbacks
@@ -339,20 +365,20 @@ begin
339
365
  end
340
366
 
341
367
  def test_should_include_transition_states_in_known_states
342
- @machine.before_transition :to => 'error', :do => lambda {}
368
+ @machine.before_transition :to => :first_gear, :do => lambda {}
343
369
 
344
- assert_equal %w(error off), @machine.states.keys.sort
370
+ assert_equal [:parked, :idling, :first_gear], @machine.states.map {|state| state.name}
345
371
  end
346
372
 
347
373
  def test_should_allow_symbolic_callbacks
348
374
  callback_args = nil
349
375
 
350
376
  klass = class << @record; self; end
351
- klass.send(:define_method, :after_turn_on) do |*args|
377
+ klass.send(:define_method, :after_ignite) do |*args|
352
378
  callback_args = args
353
379
  end
354
380
 
355
- @machine.before_transition(:after_turn_on)
381
+ @machine.before_transition(:after_ignite)
356
382
 
357
383
  @transition.perform
358
384
  assert_equal [@transition], callback_args
@@ -376,10 +402,12 @@ begin
376
402
 
377
403
  @model = new_model
378
404
  @machine = StateMachine::Machine.new(@model)
405
+ @machine.state :parked, :idling
379
406
  @machine.before_transition(lambda {@before_count += 1; false})
380
407
  @machine.before_transition(lambda {@before_count += 1})
381
- @record = @model.new(:state => 'off')
382
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
408
+
409
+ @record = @model.new(:state => 'parked')
410
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
383
411
  @result = @transition.perform
384
412
  end
385
413
 
@@ -388,7 +416,7 @@ begin
388
416
  end
389
417
 
390
418
  def test_should_not_change_current_state
391
- assert_equal 'off', @record.state
419
+ assert_equal 'parked', @record.state
392
420
  end
393
421
 
394
422
  def test_should_not_run_action
@@ -403,12 +431,13 @@ begin
403
431
  class MachineWithFailedActionTest < ActiveRecord::TestCase
404
432
  def setup
405
433
  @model = new_model do
406
- validates_inclusion_of :state, :in => %w(maybe)
434
+ validates_inclusion_of :state, :in => %w(first_gear)
407
435
  end
408
436
 
409
437
  @machine = StateMachine::Machine.new(@model)
410
- @record = @model.new(:state => 'off')
411
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
438
+ @machine.state :parked, :idling
439
+ @record = @model.new(:state => 'parked')
440
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
412
441
  @result = @transition.perform
413
442
  end
414
443
 
@@ -417,7 +446,7 @@ begin
417
446
  end
418
447
 
419
448
  def test_should_change_current_state
420
- assert_equal 'on', @record.state
449
+ assert_equal 'idling', @record.state
421
450
  end
422
451
 
423
452
  def test_should_not_save_record
@@ -431,10 +460,12 @@ begin
431
460
 
432
461
  @model = new_model
433
462
  @machine = StateMachine::Machine.new(@model)
463
+ @machine.state :parked, :idling
434
464
  @machine.after_transition(lambda {@after_count += 1; false})
435
465
  @machine.after_transition(lambda {@after_count += 1})
436
- @record = @model.new(:state => 'off')
437
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
466
+
467
+ @record = @model.new(:state => 'parked')
468
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
438
469
  @result = @transition.perform
439
470
  end
440
471
 
@@ -443,7 +474,7 @@ begin
443
474
  end
444
475
 
445
476
  def test_should_change_current_state
446
- assert_equal 'on', @record.state
477
+ assert_equal 'idling', @record.state
447
478
  end
448
479
 
449
480
  def test_should_save_record
@@ -459,13 +490,14 @@ begin
459
490
  def setup
460
491
  @model = new_model
461
492
  @machine = StateMachine::Machine.new(@model)
462
- @record = @model.new(:state => 'off')
463
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
493
+ @machine.state :parked, :idling
494
+ @record = @model.new(:state => 'parked')
495
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
464
496
  end
465
497
 
466
498
  def test_should_call_before_event_method
467
499
  observer = new_observer(@model) do
468
- def before_turn_on(*args)
500
+ def before_ignite(*args)
469
501
  notifications << args
470
502
  end
471
503
  end
@@ -489,7 +521,7 @@ begin
489
521
 
490
522
  def test_should_call_after_event_method
491
523
  observer = new_observer(@model) do
492
- def after_turn_on(*args)
524
+ def after_ignite(*args)
493
525
  notifications << args
494
526
  end
495
527
  end
@@ -513,8 +545,8 @@ begin
513
545
 
514
546
  def test_should_call_event_method_before_transition_method
515
547
  observer = new_observer(@model) do
516
- def before_turn_on(*args)
517
- notifications << :before_turn_on
548
+ def before_ignite(*args)
549
+ notifications << :before_ignite
518
550
  end
519
551
 
520
552
  def before_transition(*args)
@@ -524,12 +556,12 @@ begin
524
556
  instance = observer.instance
525
557
 
526
558
  @transition.perform
527
- assert_equal [:before_turn_on, :before_transition], instance.notifications
559
+ assert_equal [:before_ignite, :before_transition], instance.notifications
528
560
  end
529
561
 
530
562
  def test_should_call_methods_outside_the_context_of_the_record
531
563
  observer = new_observer(@model) do
532
- def before_turn_on(*args)
564
+ def before_ignite(*args)
533
565
  notifications << self
534
566
  end
535
567
  end
@@ -543,14 +575,15 @@ begin
543
575
  class MachineWithNamespacedObserversTest < ActiveRecord::TestCase
544
576
  def setup
545
577
  @model = new_model
546
- @machine = StateMachine::Machine.new(@model, :namespace => 'switch')
547
- @record = @model.new(:state => 'off')
548
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
578
+ @machine = StateMachine::Machine.new(@model, :namespace => 'car')
579
+ @machine.state :parked, :idling
580
+ @record = @model.new(:state => 'parked')
581
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
549
582
  end
550
583
 
551
584
  def test_should_call_namespaced_before_event_method
552
585
  observer = new_observer(@model) do
553
- def before_turn_on_switch(*args)
586
+ def before_ignite_car(*args)
554
587
  notifications << args
555
588
  end
556
589
  end
@@ -562,7 +595,7 @@ begin
562
595
 
563
596
  def test_should_call_namespaced_after_event_method
564
597
  observer = new_observer(@model) do
565
- def after_turn_on_switch(*args)
598
+ def after_ignite_car(*args)
566
599
  notifications << args
567
600
  end
568
601
  end
@@ -577,8 +610,9 @@ begin
577
610
  def setup
578
611
  @model = new_model
579
612
  @machine = StateMachine::Machine.new(@model)
580
- @record = @model.new(:state => 'off')
581
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
613
+ @machine.state :parked, :idling
614
+ @record = @model.new(:state => 'parked')
615
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
582
616
 
583
617
  @notifications = []
584
618
 
@@ -588,16 +622,16 @@ begin
588
622
 
589
623
  # Create observer callbacks
590
624
  observer = new_observer(@model) do
591
- def before_turn_on(*args)
592
- notifications << :observer_before_turn_on
625
+ def before_ignite(*args)
626
+ notifications << :observer_before_ignite
593
627
  end
594
628
 
595
629
  def before_transition(*args)
596
630
  notifications << :observer_before_transition
597
631
  end
598
632
 
599
- def after_turn_on(*args)
600
- notifications << :observer_after_turn_on
633
+ def after_ignite(*args)
634
+ notifications << :observer_after_ignite
601
635
  end
602
636
 
603
637
  def after_transition(*args)
@@ -613,10 +647,10 @@ begin
613
647
  def test_should_invoke_callbacks_in_specific_order
614
648
  expected = [
615
649
  :callback_before_transition,
616
- :observer_before_turn_on,
650
+ :observer_before_ignite,
617
651
  :observer_before_transition,
618
652
  :callback_after_transition,
619
- :observer_after_turn_on,
653
+ :observer_after_ignite,
620
654
  :observer_after_transition
621
655
  ]
622
656
 
@@ -7,7 +7,7 @@ begin
7
7
 
8
8
  # Establish database connection
9
9
  DataMapper.setup(:default, 'sqlite3::memory:')
10
- DataObjects::Sqlite3.logger = DataObjects::Logger.new("#{File.dirname(__FILE__)}/../../data_mapper.log", 0)
10
+ DataObjects::Sqlite3.logger = DataObjects::Logger.new("#{File.dirname(__FILE__)}/../../data_mapper.log", :info)
11
11
 
12
12
  module DataMapperTest
13
13
  class BaseTestCase < Test::Unit::TestCase
@@ -68,6 +68,7 @@ begin
68
68
  def setup
69
69
  @resource = new_resource
70
70
  @machine = StateMachine::Machine.new(@resource)
71
+ @machine.state :parked, :idling, :first_gear
71
72
  end
72
73
 
73
74
  def test_should_create_singular_with_scope
@@ -75,10 +76,10 @@ begin
75
76
  end
76
77
 
77
78
  def test_should_only_include_records_with_state_in_singular_with_scope
78
- off = @resource.create :state => 'off'
79
- on = @resource.create :state => 'on'
79
+ parked = @resource.create :state => 'parked'
80
+ idling = @resource.create :state => 'idling'
80
81
 
81
- assert_equal [off], @resource.with_state('off')
82
+ assert_equal [parked], @resource.with_state(:parked)
82
83
  end
83
84
 
84
85
  def test_should_create_plural_with_scope
@@ -86,10 +87,10 @@ begin
86
87
  end
87
88
 
88
89
  def test_should_only_include_records_with_states_in_plural_with_scope
89
- off = @resource.create :state => 'off'
90
- on = @resource.create :state => 'on'
90
+ parked = @resource.create :state => 'parked'
91
+ idling = @resource.create :state => 'idling'
91
92
 
92
- assert_equal [off, on], @resource.with_states('off', 'on')
93
+ assert_equal [parked, idling], @resource.with_states(:parked, :idling)
93
94
  end
94
95
 
95
96
  def test_should_create_singular_without_scope
@@ -97,10 +98,10 @@ begin
97
98
  end
98
99
 
99
100
  def test_should_only_include_records_without_state_in_singular_without_scope
100
- off = @resource.create :state => 'off'
101
- on = @resource.create :state => 'on'
101
+ parked = @resource.create :state => 'parked'
102
+ idling = @resource.create :state => 'idling'
102
103
 
103
- assert_equal [off], @resource.without_state('on')
104
+ assert_equal [parked], @resource.without_state(:idling)
104
105
  end
105
106
 
106
107
  def test_should_create_plural_without_scope
@@ -108,11 +109,18 @@ begin
108
109
  end
109
110
 
110
111
  def test_should_only_include_records_without_states_in_plural_without_scope
111
- off = @resource.create :state => 'off'
112
- on = @resource.create :state => 'on'
113
- error = @resource.create :state => 'error'
112
+ parked = @resource.create :state => 'parked'
113
+ idling = @resource.create :state => 'idling'
114
+ first_gear = @resource.create :state => 'first_gear'
114
115
 
115
- assert_equal [off, on], @resource.without_states('error')
116
+ assert_equal [parked, idling], @resource.without_states(:first_gear)
117
+ end
118
+
119
+ def test_should_allow_chaining_scopes
120
+ parked = @resource.create :state => 'parked'
121
+ idling = @resource.create :state => 'idling'
122
+
123
+ assert_equal [idling], @resource.without_state(:parked).with_state(:idling)
116
124
  end
117
125
 
118
126
  def test_should_rollback_transaction_if_false
@@ -135,14 +143,14 @@ begin
135
143
 
136
144
  def test_should_not_override_the_column_reader
137
145
  record = @resource.new
138
- record.attribute_set(:state, 'off')
139
- assert_equal 'off', record.state
146
+ record.attribute_set(:state, 'parked')
147
+ assert_equal 'parked', record.state
140
148
  end
141
149
 
142
150
  def test_should_not_override_the_column_writer
143
151
  record = @resource.new
144
- record.state = 'off'
145
- assert_equal 'off', record.attribute_get(:state)
152
+ record.state = 'parked'
153
+ assert_equal 'parked', record.attribute_get(:state)
146
154
  end
147
155
  end
148
156
 
@@ -159,19 +167,19 @@ begin
159
167
  class MachineWithInitialStateTest < BaseTestCase
160
168
  def setup
161
169
  @resource = new_resource
162
- @machine = StateMachine::Machine.new(@resource, :initial => 'off')
170
+ @machine = StateMachine::Machine.new(@resource, :initial => 'parked')
163
171
  @record = @resource.new
164
172
  end
165
173
 
166
174
  def test_should_set_initial_state_on_created_object
167
- assert_equal 'off', @record.state
175
+ assert_equal 'parked', @record.state
168
176
  end
169
177
  end
170
178
 
171
179
  class MachineWithNonColumnStateAttributeTest < BaseTestCase
172
180
  def setup
173
181
  @resource = new_resource
174
- @machine = StateMachine::Machine.new(@resource, :status, :initial => 'off')
182
+ @machine = StateMachine::Machine.new(@resource, :status, :initial => 'parked')
175
183
  @record = @resource.new
176
184
  end
177
185
 
@@ -184,7 +192,7 @@ begin
184
192
  end
185
193
 
186
194
  def test_should_set_initial_state_on_created_object
187
- assert_equal 'off', @record.status
195
+ assert_equal 'parked', @record.status
188
196
  end
189
197
  end
190
198
 
@@ -192,8 +200,9 @@ begin
192
200
  def setup
193
201
  @resource = new_resource
194
202
  @machine = StateMachine::Machine.new(@resource)
195
- @record = @resource.new(:state => 'off')
196
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
203
+ @machine.state :parked, :idling
204
+ @record = @resource.new(:state => 'parked')
205
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
197
206
  end
198
207
 
199
208
  def test_should_run_before_callbacks
@@ -256,11 +265,11 @@ begin
256
265
  callback_args = nil
257
266
 
258
267
  klass = class << @record; self; end
259
- klass.send(:define_method, :after_turn_on) do |*args|
268
+ klass.send(:define_method, :after_ignite) do |*args|
260
269
  callback_args = args
261
270
  end
262
271
 
263
- @machine.before_transition(:after_turn_on)
272
+ @machine.before_transition(:after_ignite)
264
273
 
265
274
  @transition.perform
266
275
  assert_equal [@transition], callback_args
@@ -285,15 +294,16 @@ begin
285
294
  def setup
286
295
  @resource = new_resource
287
296
  @machine = StateMachine::Machine.new(@resource)
288
- @record = @resource.new(:state => 'off')
289
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
297
+ @machine.state :parked, :idling
298
+ @record = @resource.new(:state => 'parked')
299
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
290
300
  end
291
301
 
292
302
  def test_should_call_before_transition_callback_if_requirements_match
293
303
  called = false
294
304
 
295
305
  observer = new_observer(@resource) do
296
- before_transition :from => 'off' do
306
+ before_transition :from => :parked do
297
307
  called = true
298
308
  end
299
309
  end
@@ -306,7 +316,7 @@ begin
306
316
  called = false
307
317
 
308
318
  observer = new_observer(@resource) do
309
- before_transition :from => 'on' do
319
+ before_transition :from => :idling do
310
320
  called = true
311
321
  end
312
322
  end
@@ -322,11 +332,11 @@ begin
322
332
  called_status = false
323
333
 
324
334
  observer = new_observer(@resource) do
325
- before_transition :state, :from => 'off' do
335
+ before_transition :state, :from => :parked do
326
336
  called_state = true
327
337
  end
328
338
 
329
- before_transition :status, :from => 'off' do
339
+ before_transition :status, :from => :parked do
330
340
  called_status = true
331
341
  end
332
342
  end
@@ -354,7 +364,7 @@ begin
354
364
  called = false
355
365
 
356
366
  observer = new_observer(@resource) do
357
- after_transition :from => 'off' do
367
+ after_transition :from => :parked do
358
368
  called = true
359
369
  end
360
370
  end
@@ -367,7 +377,7 @@ begin
367
377
  called = false
368
378
 
369
379
  observer = new_observer(@resource) do
370
- after_transition :from => 'on' do
380
+ after_transition :from => :idling do
371
381
  called = true
372
382
  end
373
383
  end
@@ -394,8 +404,9 @@ begin
394
404
  def setup
395
405
  @resource = new_resource
396
406
  @machine = StateMachine::Machine.new(@resource)
397
- @record = @resource.new(:state => 'off')
398
- @transition = StateMachine::Transition.new(@record, @machine, 'turn_on', 'off', 'on')
407
+ @machine.state :parked, :idling
408
+ @record = @resource.new(:state => 'parked')
409
+ @transition = StateMachine::Transition.new(@record, @machine, :ignite, :parked, :idling)
399
410
 
400
411
  @notifications = notifications = []
401
412
 
@@ -432,5 +443,5 @@ begin
432
443
  end
433
444
  end
434
445
  rescue LoadError
435
- $stderr.puts 'Skipping DataMapper Core tests. `gem install dm-core` and try again.'
446
+ $stderr.puts 'Skipping DataMapper tests. `gem install dm-core rspec hoe launchy do_sqlite3` and try again.'
436
447
  end