stateful.rb 2.1.0 → 2.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +161 -0
- data/Gemfile +3 -0
- data/README.md +309 -0
- data/lib/Stateful/ActiveRecord/ClassMethods.rb +7 -65
- data/lib/Stateful/ClassMethods.rb +60 -0
- data/lib/Stateful/Poro/ClassMethods.rb +12 -70
- data/lib/Stateful/Sequel/ClassMethods.rb +59 -0
- data/lib/Stateful/Sequel.rb +30 -0
- data/lib/Stateful/VERSION.rb +1 -1
- data/lib/Stateful.rb +3 -0
- data/stateful.rb.gemspec +42 -0
- data/test/ActiveRecord/WithColumnName.rb +159 -0
- data/test/ActiveRecord/WithExplicitDeterministicEventOrdering.rb +159 -0
- data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrdering.rb +165 -0
- data/test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +163 -0
- data/test/ActiveRecord/WithExplicitNonDeterministicEventOrdering.rb +161 -0
- data/test/ActiveRecord/WithInitialStateBlock.rb +157 -0
- data/test/ActiveRecord/WithMultipleFinalStates.rb +188 -0
- data/test/ActiveRecord/WithMultipleStateMachines.rb +221 -0
- data/test/ActiveRecord/WithMultipleStateMachinesAndStatefulBlock.rb +223 -0
- data/test/ActiveRecord/WithPersistenceNonSpecificExtend.rb +159 -0
- data/test/ActiveRecord/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +161 -0
- data/test/ActiveRecord/WithPersistenceSpecificExtend.rb +159 -0
- data/test/ActiveRecord/WithPersistenceSpecificExtendAndStatefulBlock.rb +161 -0
- data/test/ActiveRecord/test_helper.rb +9 -0
- data/test/ActiveRecord.rb +5 -0
- data/test/Poro/WithExplicitDeterministicEventOrdering.rb +147 -0
- data/test/Poro/WithExplicitGlobalNonDeterministicEventOrdering.rb +153 -0
- data/test/Poro/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +151 -0
- data/test/Poro/WithExplicitNonDeterministicEventOrdering.rb +149 -0
- data/test/Poro/WithInitialStateBlock.rb +145 -0
- data/test/Poro/WithMultipleFinalStates.rb +176 -0
- data/test/Poro/WithMultipleStateMachines.rb +192 -0
- data/test/Poro/WithMultipleStateMachinesAndStatefulBlock.rb +194 -0
- data/test/Poro/WithPersistenceNonSpecificExtend.rb +147 -0
- data/test/Poro/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +149 -0
- data/test/Poro/WithPersistenceSpecificExtend.rb +147 -0
- data/test/Poro/WithPersistenceSpecificExtendAndStatefulBlock.rb +149 -0
- data/test/Poro/WithVariableName.rb +147 -0
- data/test/Poro.rb +5 -0
- data/test/Sequel/WithColumnName.rb +154 -0
- data/test/Sequel/WithExplicitDeterministicEventOrdering.rb +154 -0
- data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrdering.rb +160 -0
- data/test/Sequel/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb +158 -0
- data/test/Sequel/WithExplicitNonDeterministicEventOrdering.rb +156 -0
- data/test/Sequel/WithInitialStateBlock.rb +152 -0
- data/test/Sequel/WithMultipleFinalStates.rb +183 -0
- data/test/Sequel/WithMultipleStateMachines.rb +216 -0
- data/test/Sequel/WithMultipleStateMachinesAndStatefulBlock.rb +218 -0
- data/test/Sequel/WithPersistenceNonSpecificExtend.rb +154 -0
- data/test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb +156 -0
- data/test/Sequel/WithPersistenceSpecificExtend.rb +154 -0
- data/test/Sequel/WithPersistenceSpecificExtendAndStatefulBlock.rb +156 -0
- data/test/Sequel/test_helper.rb +5 -0
- data/test/Sequel.rb +5 -0
- data/test/Stateful.rb +15 -0
- metadata +69 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb
|
|
2
|
+
|
|
3
|
+
gem 'minitest'
|
|
4
|
+
gem 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
require 'minitest/autorun'
|
|
7
|
+
require 'minitest-spec-context'
|
|
8
|
+
|
|
9
|
+
require_relative './test_helper'
|
|
10
|
+
|
|
11
|
+
lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
|
12
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
13
|
+
|
|
14
|
+
require 'Stateful'
|
|
15
|
+
|
|
16
|
+
DB.create_table :sequel_machine1s do
|
|
17
|
+
primary_key :id
|
|
18
|
+
String :current_state
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class SequelMachine1 < Sequel::Model
|
|
22
|
+
extend Stateful
|
|
23
|
+
|
|
24
|
+
stateful do
|
|
25
|
+
initial_state :initial_state
|
|
26
|
+
|
|
27
|
+
state :initial_state do
|
|
28
|
+
on :an_event => :next_state
|
|
29
|
+
on :another_event => :final_state
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
state :next_state do
|
|
33
|
+
on :yet_another_event => :final_state
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
final_state :final_state
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe Stateful::Sequel do
|
|
41
|
+
let(:machine){SequelMachine1.create}
|
|
42
|
+
|
|
43
|
+
it "must have an initial state" do
|
|
44
|
+
_(machine.initial_state).wont_be_nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "must have a final state (if one has been specified)" do
|
|
48
|
+
if SequelMachine1.final_state?
|
|
49
|
+
_(machine.final_state).wont_be_nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "initial_state" do
|
|
54
|
+
it "must have an initial state before any events occur" do
|
|
55
|
+
_(machine.initial_state?).must_equal true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "must have an initial state consistent with what is given" do
|
|
59
|
+
_(machine.initial_state).must_equal SequelMachine1.stateful_state_machine.initial_state
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "must have an initial state with name as per the name given" do
|
|
63
|
+
_(machine.initial_state.name).must_equal :initial_state
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "must not be in the final state (assuming that initial and final are different states)" do
|
|
67
|
+
_(machine.final_state?).must_equal false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "must know what it's next state is given an event name" do
|
|
71
|
+
_(machine.next_state(:an_event)).must_equal SequelMachine1.stateful_state_machine.find(:next_state)
|
|
72
|
+
_(machine.next_state(:another_event)).must_equal SequelMachine1.stateful_state_machine.find(:final_state)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "must have an intial state which has as set of transitions to other states" do
|
|
76
|
+
_(machine.transitions.class).must_equal Array
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "must have two transitions to other states" do
|
|
80
|
+
_(machine.transitions.size).must_equal 2
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "must know what transitions are available" do
|
|
84
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "must be active" do
|
|
88
|
+
_(machine.active?).must_equal true
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "next_state" do
|
|
93
|
+
before do
|
|
94
|
+
machine.an_event
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "must not be in the initial state" do
|
|
98
|
+
_(machine.initial_state?).must_equal false
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "must not be in the final state" do
|
|
102
|
+
_(machine.final_state?).must_equal false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "must be in the next_state state" do
|
|
106
|
+
_(machine.current_state.name).must_equal :next_state
|
|
107
|
+
_(machine.next_state?).must_equal true
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "must have a set of transitions to other states" do
|
|
111
|
+
_(machine.transitions.class).must_equal Array
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "must have one transition to other states" do
|
|
115
|
+
_(machine.transitions.size).must_equal 1
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "must know what transitions are available" do
|
|
119
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "must be active" do
|
|
123
|
+
_(machine.active?).must_equal true
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context "final_state" do
|
|
128
|
+
before do
|
|
129
|
+
machine.another_event
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "must have a final state" do
|
|
133
|
+
_(machine.final_state?).must_equal true
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "must have a final state consistent with what is given" do
|
|
137
|
+
_(machine.final_state).must_equal SequelMachine1.stateful_state_machine.final_state
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "must have a state with name as per the name given" do
|
|
141
|
+
_(machine.current_state.name).must_equal :final_state
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "must not be in the initial state (assuming that initial and final are different states)" do
|
|
145
|
+
_(machine.initial_state?).must_equal false
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "must have no transitions" do
|
|
149
|
+
_(machine.transitions.empty?).must_equal true
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "must not be active" do
|
|
153
|
+
_(machine.active?).must_equal false
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# test/Sequel/WithPersistenceSpecificExtend.rb
|
|
2
|
+
|
|
3
|
+
gem 'minitest'
|
|
4
|
+
gem 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
require 'minitest/autorun'
|
|
7
|
+
require 'minitest-spec-context'
|
|
8
|
+
|
|
9
|
+
require_relative './test_helper'
|
|
10
|
+
|
|
11
|
+
lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
|
12
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
13
|
+
|
|
14
|
+
require 'Stateful/Sequel'
|
|
15
|
+
|
|
16
|
+
DB.create_table :sequel_machine2s do
|
|
17
|
+
primary_key :id
|
|
18
|
+
String :current_state
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class SequelMachine2 < Sequel::Model
|
|
22
|
+
extend Stateful::Sequel
|
|
23
|
+
|
|
24
|
+
initial_state :initial_state
|
|
25
|
+
|
|
26
|
+
state :initial_state do
|
|
27
|
+
on :an_event => :next_state
|
|
28
|
+
on :another_event => :final_state
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
state :next_state do
|
|
32
|
+
on :yet_another_event => :final_state
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
final_state :final_state
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe Stateful::Sequel do
|
|
39
|
+
let(:machine){SequelMachine2.create}
|
|
40
|
+
|
|
41
|
+
it "must have an initial state" do
|
|
42
|
+
_(machine.initial_state).wont_be_nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "must have a final state (if one has been specified)" do
|
|
46
|
+
if SequelMachine2.final_state?
|
|
47
|
+
_(machine.final_state).wont_be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "initial_state" do
|
|
52
|
+
it "must have an initial state before any events occur" do
|
|
53
|
+
_(machine.initial_state?).must_equal true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "must have an initial state consistent with what is given" do
|
|
57
|
+
_(machine.initial_state).must_equal SequelMachine2.stateful_state_machine.initial_state
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "must have an initial state with name as per the name given" do
|
|
61
|
+
_(machine.initial_state.name).must_equal :initial_state
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "must not be in the final state (assuming that initial and final are different states)" do
|
|
65
|
+
_(machine.final_state?).must_equal false
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "must know what it's next state is given an event name" do
|
|
69
|
+
_(machine.next_state(:an_event)).must_equal SequelMachine2.stateful_state_machine.find(:next_state)
|
|
70
|
+
_(machine.next_state(:another_event)).must_equal SequelMachine2.stateful_state_machine.find(:final_state)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "must have an intial state which has as set of transitions to other states" do
|
|
74
|
+
_(machine.transitions.class).must_equal Array
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "must have two transitions to other states" do
|
|
78
|
+
_(machine.transitions.size).must_equal 2
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "must know what transitions are available" do
|
|
82
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "must be active" do
|
|
86
|
+
_(machine.active?).must_equal true
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
context "next_state" do
|
|
91
|
+
before do
|
|
92
|
+
machine.an_event
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "must not be in the initial state" do
|
|
96
|
+
_(machine.initial_state?).must_equal false
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "must not be in the final state" do
|
|
100
|
+
_(machine.final_state?).must_equal false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "must be in the next_state state" do
|
|
104
|
+
_(machine.current_state.name).must_equal :next_state
|
|
105
|
+
_(machine.next_state?).must_equal true
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "must have a set of transitions to other states" do
|
|
109
|
+
_(machine.transitions.class).must_equal Array
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "must have one transition to other states" do
|
|
113
|
+
_(machine.transitions.size).must_equal 1
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it "must know what transitions are available" do
|
|
117
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it "must be active" do
|
|
121
|
+
_(machine.active?).must_equal true
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "final_state" do
|
|
126
|
+
before do
|
|
127
|
+
machine.another_event
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it "must have a final state" do
|
|
131
|
+
_(machine.final_state?).must_equal true
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "must have a final state consistent with what is given" do
|
|
135
|
+
_(machine.final_state).must_equal SequelMachine2.stateful_state_machine.final_state
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
it "must have a state with name as per the name given" do
|
|
139
|
+
_(machine.current_state.name).must_equal :final_state
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "must not be in the initial state (assuming that initial and final are different states)" do
|
|
143
|
+
_(machine.initial_state?).must_equal false
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "must have no transitions" do
|
|
147
|
+
_(machine.transitions.empty?).must_equal true
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
it "must not be active" do
|
|
151
|
+
_(machine.active?).must_equal false
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# test/Sequel/WithPersistenceSpecificExtendAndStatefulBlock.rb
|
|
2
|
+
|
|
3
|
+
gem 'minitest'
|
|
4
|
+
gem 'minitest-spec-context'
|
|
5
|
+
|
|
6
|
+
require 'minitest/autorun'
|
|
7
|
+
require 'minitest-spec-context'
|
|
8
|
+
|
|
9
|
+
require_relative './test_helper'
|
|
10
|
+
|
|
11
|
+
lib_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', 'lib'))
|
|
12
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
13
|
+
|
|
14
|
+
require 'Stateful/Sequel'
|
|
15
|
+
|
|
16
|
+
DB.create_table :sequel_machine3s do
|
|
17
|
+
primary_key :id
|
|
18
|
+
String :current_state
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class SequelMachine3 < Sequel::Model
|
|
22
|
+
extend Stateful::Sequel
|
|
23
|
+
|
|
24
|
+
stateful do
|
|
25
|
+
initial_state :initial_state
|
|
26
|
+
|
|
27
|
+
state :initial_state do
|
|
28
|
+
on :an_event => :next_state
|
|
29
|
+
on :another_event => :final_state
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
state :next_state do
|
|
33
|
+
on :yet_another_event => :final_state
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
final_state :final_state
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe Stateful::Sequel do
|
|
41
|
+
let(:machine){SequelMachine3.create}
|
|
42
|
+
|
|
43
|
+
it "must have an initial state" do
|
|
44
|
+
_(machine.initial_state).wont_be_nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "must have a final state (if one has been specified)" do
|
|
48
|
+
if SequelMachine3.final_state?
|
|
49
|
+
_(machine.final_state).wont_be_nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "initial_state" do
|
|
54
|
+
it "must have an initial state before any events occur" do
|
|
55
|
+
_(machine.initial_state?).must_equal true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "must have an initial state consistent with what is given" do
|
|
59
|
+
_(machine.initial_state).must_equal SequelMachine3.stateful_state_machine.initial_state
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "must have an initial state with name as per the name given" do
|
|
63
|
+
_(machine.initial_state.name).must_equal :initial_state
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "must not be in the final state (assuming that initial and final are different states)" do
|
|
67
|
+
_(machine.final_state?).must_equal false
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "must know what it's next state is given an event name" do
|
|
71
|
+
_(machine.next_state(:an_event)).must_equal SequelMachine3.stateful_state_machine.find(:next_state)
|
|
72
|
+
_(machine.next_state(:another_event)).must_equal SequelMachine3.stateful_state_machine.find(:final_state)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "must have an intial state which has as set of transitions to other states" do
|
|
76
|
+
_(machine.transitions.class).must_equal Array
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "must have two transitions to other states" do
|
|
80
|
+
_(machine.transitions.size).must_equal 2
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "must know what transitions are available" do
|
|
84
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:an_event, :next_state], [:another_event, :final_state]]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "must be active" do
|
|
88
|
+
_(machine.active?).must_equal true
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "next_state" do
|
|
93
|
+
before do
|
|
94
|
+
machine.an_event
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "must not be in the initial state" do
|
|
98
|
+
_(machine.initial_state?).must_equal false
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "must not be in the final state" do
|
|
102
|
+
_(machine.final_state?).must_equal false
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "must be in the next_state state" do
|
|
106
|
+
_(machine.current_state.name).must_equal :next_state
|
|
107
|
+
_(machine.next_state?).must_equal true
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "must have a set of transitions to other states" do
|
|
111
|
+
_(machine.transitions.class).must_equal Array
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "must have one transition to other states" do
|
|
115
|
+
_(machine.transitions.size).must_equal 1
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "must know what transitions are available" do
|
|
119
|
+
_(machine.transitions.collect{|t| [t.event_name, t.next_state_name]}).must_equal [[:yet_another_event, :final_state]]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "must be active" do
|
|
123
|
+
_(machine.active?).must_equal true
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context "final_state" do
|
|
128
|
+
before do
|
|
129
|
+
machine.another_event
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it "must have a final state" do
|
|
133
|
+
_(machine.final_state?).must_equal true
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it "must have a final state consistent with what is given" do
|
|
137
|
+
_(machine.final_state).must_equal SequelMachine3.stateful_state_machine.final_state
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "must have a state with name as per the name given" do
|
|
141
|
+
_(machine.current_state.name).must_equal :final_state
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "must not be in the initial state (assuming that initial and final are different states)" do
|
|
145
|
+
_(machine.initial_state?).must_equal false
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "must have no transitions" do
|
|
149
|
+
_(machine.transitions.empty?).must_equal true
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "must not be active" do
|
|
153
|
+
_(machine.active?).must_equal false
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
data/test/Sequel.rb
ADDED
data/test/Stateful.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# test/Stateful.rb
|
|
2
|
+
|
|
3
|
+
test_dir = File.dirname(File.expand_path(__FILE__))
|
|
4
|
+
|
|
5
|
+
lib_dir = File.expand_path(File.join(test_dir, '..', 'lib'))
|
|
6
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
7
|
+
|
|
8
|
+
active_record_specs = Dir[File.join(test_dir, 'ActiveRecord', '**', '*.rb')]
|
|
9
|
+
active_record_specs.each{|spec| require spec}
|
|
10
|
+
|
|
11
|
+
poro_specs = Dir[File.join(test_dir, 'Poro', '**', '*.rb')]
|
|
12
|
+
poro_specs.each{|spec| require spec}
|
|
13
|
+
|
|
14
|
+
sequel_specs = Dir[File.join(test_dir, 'Sequel', '**', '*.rb')]
|
|
15
|
+
sequel_specs.each{|spec| require spec}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stateful.rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
@@ -51,6 +51,20 @@ dependencies:
|
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: sequel
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
54
68
|
- !ruby/object:Gem::Dependency
|
|
55
69
|
name: sqlite3
|
|
56
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,12 +79,15 @@ dependencies:
|
|
|
65
79
|
- - ">="
|
|
66
80
|
- !ruby/object:Gem::Version
|
|
67
81
|
version: '0'
|
|
68
|
-
description: Easily add state to Poro and
|
|
82
|
+
description: Easily add state to Poro, ActiveRecord, and Sequel objects.
|
|
69
83
|
email: code@thoran.com
|
|
70
84
|
executables: []
|
|
71
85
|
extensions: []
|
|
72
86
|
extra_rdoc_files: []
|
|
73
87
|
files:
|
|
88
|
+
- CHANGELOG.md
|
|
89
|
+
- Gemfile
|
|
90
|
+
- README.md
|
|
74
91
|
- lib/Stateful.rb
|
|
75
92
|
- lib/Stateful/ActiveRecord.rb
|
|
76
93
|
- lib/Stateful/ActiveRecord/ClassMethods.rb
|
|
@@ -78,11 +95,59 @@ files:
|
|
|
78
95
|
- lib/Stateful/InstanceMethods.rb
|
|
79
96
|
- lib/Stateful/Poro.rb
|
|
80
97
|
- lib/Stateful/Poro/ClassMethods.rb
|
|
98
|
+
- lib/Stateful/Sequel.rb
|
|
99
|
+
- lib/Stateful/Sequel/ClassMethods.rb
|
|
81
100
|
- lib/Stateful/State.rb
|
|
82
101
|
- lib/Stateful/StateMachine.rb
|
|
83
102
|
- lib/Stateful/Transition.rb
|
|
84
103
|
- lib/Stateful/VERSION.rb
|
|
85
|
-
|
|
104
|
+
- stateful.rb.gemspec
|
|
105
|
+
- test/ActiveRecord.rb
|
|
106
|
+
- test/ActiveRecord/WithColumnName.rb
|
|
107
|
+
- test/ActiveRecord/WithExplicitDeterministicEventOrdering.rb
|
|
108
|
+
- test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrdering.rb
|
|
109
|
+
- test/ActiveRecord/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb
|
|
110
|
+
- test/ActiveRecord/WithExplicitNonDeterministicEventOrdering.rb
|
|
111
|
+
- test/ActiveRecord/WithInitialStateBlock.rb
|
|
112
|
+
- test/ActiveRecord/WithMultipleFinalStates.rb
|
|
113
|
+
- test/ActiveRecord/WithMultipleStateMachines.rb
|
|
114
|
+
- test/ActiveRecord/WithMultipleStateMachinesAndStatefulBlock.rb
|
|
115
|
+
- test/ActiveRecord/WithPersistenceNonSpecificExtend.rb
|
|
116
|
+
- test/ActiveRecord/WithPersistenceNonSpecificExtendAndStatefulBlock.rb
|
|
117
|
+
- test/ActiveRecord/WithPersistenceSpecificExtend.rb
|
|
118
|
+
- test/ActiveRecord/WithPersistenceSpecificExtendAndStatefulBlock.rb
|
|
119
|
+
- test/ActiveRecord/test_helper.rb
|
|
120
|
+
- test/Poro.rb
|
|
121
|
+
- test/Poro/WithExplicitDeterministicEventOrdering.rb
|
|
122
|
+
- test/Poro/WithExplicitGlobalNonDeterministicEventOrdering.rb
|
|
123
|
+
- test/Poro/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb
|
|
124
|
+
- test/Poro/WithExplicitNonDeterministicEventOrdering.rb
|
|
125
|
+
- test/Poro/WithInitialStateBlock.rb
|
|
126
|
+
- test/Poro/WithMultipleFinalStates.rb
|
|
127
|
+
- test/Poro/WithMultipleStateMachines.rb
|
|
128
|
+
- test/Poro/WithMultipleStateMachinesAndStatefulBlock.rb
|
|
129
|
+
- test/Poro/WithPersistenceNonSpecificExtend.rb
|
|
130
|
+
- test/Poro/WithPersistenceNonSpecificExtendAndStatefulBlock.rb
|
|
131
|
+
- test/Poro/WithPersistenceSpecificExtend.rb
|
|
132
|
+
- test/Poro/WithPersistenceSpecificExtendAndStatefulBlock.rb
|
|
133
|
+
- test/Poro/WithVariableName.rb
|
|
134
|
+
- test/Sequel.rb
|
|
135
|
+
- test/Sequel/WithColumnName.rb
|
|
136
|
+
- test/Sequel/WithExplicitDeterministicEventOrdering.rb
|
|
137
|
+
- test/Sequel/WithExplicitGlobalNonDeterministicEventOrdering.rb
|
|
138
|
+
- test/Sequel/WithExplicitGlobalNonDeterministicEventOrderingAndInitialStateBlock.rb
|
|
139
|
+
- test/Sequel/WithExplicitNonDeterministicEventOrdering.rb
|
|
140
|
+
- test/Sequel/WithInitialStateBlock.rb
|
|
141
|
+
- test/Sequel/WithMultipleFinalStates.rb
|
|
142
|
+
- test/Sequel/WithMultipleStateMachines.rb
|
|
143
|
+
- test/Sequel/WithMultipleStateMachinesAndStatefulBlock.rb
|
|
144
|
+
- test/Sequel/WithPersistenceNonSpecificExtend.rb
|
|
145
|
+
- test/Sequel/WithPersistenceNonSpecificExtendAndStatefulBlock.rb
|
|
146
|
+
- test/Sequel/WithPersistenceSpecificExtend.rb
|
|
147
|
+
- test/Sequel/WithPersistenceSpecificExtendAndStatefulBlock.rb
|
|
148
|
+
- test/Sequel/test_helper.rb
|
|
149
|
+
- test/Stateful.rb
|
|
150
|
+
homepage: http://github.com/thoran/stateful
|
|
86
151
|
licenses:
|
|
87
152
|
- MIT
|
|
88
153
|
metadata: {}
|
|
@@ -100,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
100
165
|
- !ruby/object:Gem::Version
|
|
101
166
|
version: '0'
|
|
102
167
|
requirements: []
|
|
103
|
-
rubygems_version: 4.0.
|
|
168
|
+
rubygems_version: 4.0.10
|
|
104
169
|
specification_version: 4
|
|
105
170
|
summary: A Ruby state machine.
|
|
106
171
|
test_files: []
|