state_machine 0.6.1 → 0.6.2
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.
- data/CHANGELOG.rdoc +4 -0
- data/Rakefile +1 -1
- data/lib/state_machine/event.rb +19 -22
- data/lib/state_machine/integrations/active_record.rb +2 -0
- data/lib/state_machine/machine.rb +108 -24
- data/lib/state_machine/state.rb +3 -6
- data/test/active_record.log +12079 -0
- data/test/functional/state_machine_test.rb +4 -0
- data/test/sequel.log +2681 -0
- data/test/unit/event_test.rb +71 -0
- data/test/unit/machine_test.rb +166 -73
- data/test/unit/state_test.rb +15 -5
- metadata +2 -2
data/test/unit/event_test.rb
CHANGED
|
@@ -78,6 +78,77 @@ class EventTest < Test::Unit::TestCase
|
|
|
78
78
|
end
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
class EventWithConflictingHelpersTest < Test::Unit::TestCase
|
|
82
|
+
def setup
|
|
83
|
+
@klass = Class.new do
|
|
84
|
+
def can_ignite?
|
|
85
|
+
0
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def next_ignite_transition
|
|
89
|
+
0
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def ignite
|
|
93
|
+
0
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def ignite!
|
|
97
|
+
0
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
@machine = StateMachine::Machine.new(@klass)
|
|
101
|
+
@state = StateMachine::Event.new(@machine, :ignite)
|
|
102
|
+
@object = @klass.new
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_should_not_redefine_predicate
|
|
106
|
+
assert_equal 0, @object.can_ignite?
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_should_not_redefine_transition_accessor
|
|
110
|
+
assert_equal 0, @object.next_ignite_transition
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_should_not_redefine_action
|
|
114
|
+
assert_equal 0, @object.ignite
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def test_should_not_redefine_bang_action
|
|
118
|
+
assert_equal 0, @object.ignite!
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_should_allow_super_chaining
|
|
122
|
+
@klass.class_eval do
|
|
123
|
+
def can_ignite?
|
|
124
|
+
super ? 1 : 0
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def next_ignite_transition
|
|
128
|
+
super ? 1 : 0
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def ignite
|
|
132
|
+
super ? 1 : 0
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def ignite!
|
|
136
|
+
begin
|
|
137
|
+
super
|
|
138
|
+
1
|
|
139
|
+
rescue Exception => ex
|
|
140
|
+
0
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
assert_equal 0, @object.can_ignite?
|
|
146
|
+
assert_equal 0, @object.next_ignite_transition
|
|
147
|
+
assert_equal 0, @object.ignite
|
|
148
|
+
assert_equal 0, @object.ignite!
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
81
152
|
class EventWithNamespaceTest < Test::Unit::TestCase
|
|
82
153
|
def setup
|
|
83
154
|
@klass = Class.new
|
data/test/unit/machine_test.rb
CHANGED
|
@@ -536,96 +536,102 @@ class MachineAfterChangingInitialState < Test::Unit::TestCase
|
|
|
536
536
|
end
|
|
537
537
|
end
|
|
538
538
|
|
|
539
|
-
class
|
|
539
|
+
class MachineWithInstanceHelpersTest < Test::Unit::TestCase
|
|
540
540
|
def setup
|
|
541
|
-
@klass = Class.new
|
|
542
|
-
attr_accessor :status
|
|
543
|
-
|
|
544
|
-
def state
|
|
545
|
-
status
|
|
546
|
-
end
|
|
547
|
-
|
|
548
|
-
def state=(value)
|
|
549
|
-
self.status = value
|
|
550
|
-
end
|
|
551
|
-
|
|
552
|
-
def state?
|
|
553
|
-
true
|
|
554
|
-
end
|
|
555
|
-
|
|
556
|
-
def state_name
|
|
557
|
-
:parked
|
|
558
|
-
end
|
|
559
|
-
end
|
|
541
|
+
@klass = Class.new
|
|
560
542
|
@machine = StateMachine::Machine.new(@klass)
|
|
561
543
|
@object = @klass.new
|
|
562
544
|
end
|
|
563
545
|
|
|
564
|
-
def
|
|
565
|
-
@
|
|
546
|
+
def test_should_not_redefine_existing_public_methods
|
|
547
|
+
@klass.class_eval do
|
|
548
|
+
def state
|
|
549
|
+
'parked'
|
|
550
|
+
end
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
@machine.define_instance_method(:state) {}
|
|
566
554
|
assert_equal 'parked', @object.state
|
|
567
555
|
end
|
|
568
556
|
|
|
569
|
-
def
|
|
570
|
-
@
|
|
571
|
-
|
|
557
|
+
def test_should_not_redefine_existing_protected_methods
|
|
558
|
+
@klass.class_eval do
|
|
559
|
+
protected
|
|
560
|
+
def state
|
|
561
|
+
'parked'
|
|
562
|
+
end
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
@machine.define_instance_method(:state) {}
|
|
566
|
+
assert_equal 'parked', @object.send(:state)
|
|
572
567
|
end
|
|
573
568
|
|
|
574
|
-
def
|
|
575
|
-
|
|
569
|
+
def test_should_not_redefine_existing_private_methods
|
|
570
|
+
@klass.class_eval do
|
|
571
|
+
private
|
|
572
|
+
def state
|
|
573
|
+
'parked'
|
|
574
|
+
end
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
@machine.define_instance_method(:state) {}
|
|
578
|
+
assert_equal 'parked', @object.send(:state)
|
|
576
579
|
end
|
|
577
580
|
|
|
578
|
-
def
|
|
579
|
-
|
|
581
|
+
def test_should_define_nonexistent_methods
|
|
582
|
+
@machine.define_instance_method(:state) {'parked'}
|
|
583
|
+
assert_equal 'parked', @object.state
|
|
580
584
|
end
|
|
581
585
|
end
|
|
582
586
|
|
|
583
|
-
class
|
|
587
|
+
class MachineWithClassHelpersTest < Test::Unit::TestCase
|
|
584
588
|
def setup
|
|
585
|
-
@klass = Class.new
|
|
586
|
-
attr_accessor :status
|
|
587
|
-
|
|
588
|
-
private
|
|
589
|
-
def state
|
|
590
|
-
status
|
|
591
|
-
end
|
|
592
|
-
|
|
593
|
-
def state=(value)
|
|
594
|
-
self.status = value
|
|
595
|
-
end
|
|
596
|
-
|
|
597
|
-
def state?
|
|
598
|
-
true
|
|
599
|
-
end
|
|
600
|
-
|
|
601
|
-
def state_name
|
|
602
|
-
:parked
|
|
603
|
-
end
|
|
604
|
-
end
|
|
589
|
+
@klass = Class.new
|
|
605
590
|
@machine = StateMachine::Machine.new(@klass)
|
|
606
|
-
@object = @klass.new
|
|
607
591
|
end
|
|
608
592
|
|
|
609
|
-
def
|
|
610
|
-
|
|
611
|
-
|
|
593
|
+
def test_should_not_redefine_existing_public_methods
|
|
594
|
+
class << @klass
|
|
595
|
+
def states
|
|
596
|
+
[]
|
|
597
|
+
end
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
@machine.define_class_method(:states) {}
|
|
601
|
+
assert_equal [], @klass.states
|
|
612
602
|
end
|
|
613
603
|
|
|
614
|
-
def
|
|
615
|
-
@
|
|
616
|
-
|
|
604
|
+
def test_should_not_redefine_existing_protected_methods
|
|
605
|
+
class << @klass
|
|
606
|
+
protected
|
|
607
|
+
def states
|
|
608
|
+
[]
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
|
|
612
|
+
@machine.define_class_method(:states) {}
|
|
613
|
+
assert_equal [], @klass.send(:states)
|
|
617
614
|
end
|
|
618
615
|
|
|
619
|
-
def
|
|
620
|
-
|
|
616
|
+
def test_should_not_redefine_existing_private_methods
|
|
617
|
+
class << @klass
|
|
618
|
+
private
|
|
619
|
+
def states
|
|
620
|
+
[]
|
|
621
|
+
end
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
@machine.define_class_method(:states) {}
|
|
625
|
+
assert_equal [], @klass.send(:states)
|
|
621
626
|
end
|
|
622
627
|
|
|
623
|
-
def
|
|
624
|
-
|
|
628
|
+
def test_should_define_nonexistent_methods
|
|
629
|
+
@machine.define_class_method(:states) {[]}
|
|
630
|
+
assert_equal [], @klass.states
|
|
625
631
|
end
|
|
626
632
|
end
|
|
627
633
|
|
|
628
|
-
class
|
|
634
|
+
class MachineWithConflictingHelpersTest < Test::Unit::TestCase
|
|
629
635
|
def setup
|
|
630
636
|
@klass = Class.new do
|
|
631
637
|
def self.with_state
|
|
@@ -643,37 +649,124 @@ class MachineWithConflictingScopesTest < Test::Unit::TestCase
|
|
|
643
649
|
def self.without_states
|
|
644
650
|
:without_states
|
|
645
651
|
end
|
|
652
|
+
|
|
653
|
+
attr_accessor :status
|
|
654
|
+
|
|
655
|
+
def state
|
|
656
|
+
'parked'
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
def state=(value)
|
|
660
|
+
self.status = value
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
def state?
|
|
664
|
+
true
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
def state_name
|
|
668
|
+
:parked
|
|
669
|
+
end
|
|
646
670
|
end
|
|
647
671
|
|
|
648
|
-
|
|
649
|
-
def
|
|
650
|
-
|
|
672
|
+
StateMachine::Integrations.const_set('Custom', Module.new do
|
|
673
|
+
def create_with_scope(name)
|
|
674
|
+
lambda {|klass, values| []}
|
|
651
675
|
end
|
|
652
676
|
|
|
653
|
-
def
|
|
654
|
-
|
|
677
|
+
def create_without_scope(name)
|
|
678
|
+
lambda {|klass, values| []}
|
|
655
679
|
end
|
|
656
|
-
end
|
|
657
|
-
|
|
680
|
+
end)
|
|
681
|
+
|
|
658
682
|
@machine = StateMachine::Machine.new(@klass, :integration => :custom)
|
|
683
|
+
@machine.state :parked, :idling
|
|
684
|
+
@object = @klass.new
|
|
659
685
|
end
|
|
660
686
|
|
|
661
|
-
def
|
|
687
|
+
def test_should_not_redefine_singular_with_scope
|
|
662
688
|
assert_equal :with_state, @klass.with_state
|
|
663
689
|
end
|
|
664
690
|
|
|
665
|
-
def
|
|
691
|
+
def test_should_not_redefine_plural_with_scope
|
|
666
692
|
assert_equal :with_states, @klass.with_states
|
|
667
693
|
end
|
|
668
694
|
|
|
669
|
-
def
|
|
695
|
+
def test_should_not_redefine_singular_without_scope
|
|
670
696
|
assert_equal :without_state, @klass.without_state
|
|
671
697
|
end
|
|
672
698
|
|
|
673
|
-
def
|
|
699
|
+
def test_should_not_redefine_plural_without_scope
|
|
674
700
|
assert_equal :without_states, @klass.without_states
|
|
675
701
|
end
|
|
676
702
|
|
|
703
|
+
def test_should_not_redefine_attribute_writer
|
|
704
|
+
assert_equal 'parked', @object.state
|
|
705
|
+
end
|
|
706
|
+
|
|
707
|
+
def test_should_not_redefine_attribute_writer
|
|
708
|
+
@object.state = 'parked'
|
|
709
|
+
assert_equal 'parked', @object.status
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
def test_should_not_define_attribute_predicate
|
|
713
|
+
assert @object.state?
|
|
714
|
+
end
|
|
715
|
+
|
|
716
|
+
def test_should_not_redefine_attribute_name_reader
|
|
717
|
+
assert_equal :parked, @object.state_name
|
|
718
|
+
end
|
|
719
|
+
|
|
720
|
+
def test_should_allow_super_chaining
|
|
721
|
+
@klass.class_eval do
|
|
722
|
+
def self.with_state(*states)
|
|
723
|
+
super == []
|
|
724
|
+
end
|
|
725
|
+
|
|
726
|
+
def self.with_states(*states)
|
|
727
|
+
super == []
|
|
728
|
+
end
|
|
729
|
+
|
|
730
|
+
def self.without_state(*states)
|
|
731
|
+
super == []
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
def self.without_states(*states)
|
|
735
|
+
super == []
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
attr_accessor :status
|
|
739
|
+
|
|
740
|
+
def state
|
|
741
|
+
super || 'parked'
|
|
742
|
+
end
|
|
743
|
+
|
|
744
|
+
def state=(value)
|
|
745
|
+
super
|
|
746
|
+
self.status = value
|
|
747
|
+
end
|
|
748
|
+
|
|
749
|
+
def state?(state)
|
|
750
|
+
super ? 1 : 0
|
|
751
|
+
end
|
|
752
|
+
|
|
753
|
+
def state_name
|
|
754
|
+
super == :parked ? 1 : 0
|
|
755
|
+
end
|
|
756
|
+
end
|
|
757
|
+
|
|
758
|
+
assert_equal true, @klass.with_state
|
|
759
|
+
assert_equal true, @klass.with_states
|
|
760
|
+
assert_equal true, @klass.without_state
|
|
761
|
+
assert_equal true, @klass.without_states
|
|
762
|
+
|
|
763
|
+
assert_equal 'parked', @object.state
|
|
764
|
+
@object.state = 'idling'
|
|
765
|
+
assert_equal 'idling', @object.status
|
|
766
|
+
assert_equal 0, @object.state?(:parked)
|
|
767
|
+
assert_equal 0, @object.state_name
|
|
768
|
+
end
|
|
769
|
+
|
|
677
770
|
def teardown
|
|
678
771
|
StateMachine::Integrations.send(:remove_const, 'Custom')
|
|
679
772
|
end
|
data/test/unit/state_test.rb
CHANGED
|
@@ -272,20 +272,30 @@ class StateNotInitialTest < Test::Unit::TestCase
|
|
|
272
272
|
end
|
|
273
273
|
end
|
|
274
274
|
|
|
275
|
-
class
|
|
275
|
+
class StateWithConflictingHelpersTest < Test::Unit::TestCase
|
|
276
276
|
def setup
|
|
277
277
|
@klass = Class.new do
|
|
278
278
|
def parked?
|
|
279
|
-
|
|
279
|
+
0
|
|
280
280
|
end
|
|
281
281
|
end
|
|
282
282
|
@machine = StateMachine::Machine.new(@klass)
|
|
283
|
-
@state
|
|
283
|
+
@machine.state :parked
|
|
284
284
|
@object = @klass.new
|
|
285
285
|
end
|
|
286
286
|
|
|
287
|
-
def
|
|
288
|
-
assert_equal
|
|
287
|
+
def test_should_not_redefine_state_predicate
|
|
288
|
+
assert_equal 0, @object.parked?
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def test_should_allow_super_chaining
|
|
292
|
+
@klass.class_eval do
|
|
293
|
+
def parked?
|
|
294
|
+
super ? 1 : 0
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
assert_equal 0, @object.parked?
|
|
289
299
|
end
|
|
290
300
|
end
|
|
291
301
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: state_machine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Pfeifer
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-03-07
|
|
12
|
+
date: 2009-03-07 23:00:00 -05:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|