simple_state_machine 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +46 -0
- data/.gitignore +3 -0
- data/.travis.yml +17 -0
- data/Gemfile +7 -0
- data/README.rdoc +31 -29
- data/examples/conversation.rb +5 -5
- data/examples/lamp.rb +5 -5
- data/examples/relationship.rb +8 -8
- data/examples/traffic_light.rb +3 -3
- data/examples/user.rb +1 -0
- data/gemfiles/Gemfile.activerecord-5.2.x +9 -0
- data/gemfiles/Gemfile.activerecord-6.0.x +9 -0
- data/gemfiles/Gemfile.activerecord-6.1.x +8 -0
- data/gemfiles/Gemfile.activerecord-main.x +9 -0
- data/gemfiles/Gemfile.basic +6 -0
- data/lib/simple_state_machine/decorator/active_record.rb +12 -18
- data/lib/simple_state_machine/tools/graphviz.rb +6 -2
- data/lib/simple_state_machine/version.rb +1 -1
- data/lib/simple_state_machine.rb +5 -4
- data/lib/tasks/graphviz.rake +10 -0
- data/simple_state_machine.gemspec +14 -25
- data/spec/active_record_spec.rb +196 -199
- data/spec/decorator/default_spec.rb +28 -28
- data/spec/examples_spec.rb +13 -13
- data/spec/mountable_spec.rb +18 -16
- data/spec/simple_state_machine_spec.rb +71 -63
- data/spec/spec_helper.rb +16 -9
- data/spec/state_machine_definition_spec.rb +21 -21
- data/spec/state_machine_spec.rb +12 -12
- data/spec/tools/graphviz_spec.rb +3 -2
- data/spec/tools/inspector_spec.rb +3 -3
- metadata +36 -137
- data/autotest/discover.rb +0 -1
data/spec/active_record_spec.rb
CHANGED
@@ -1,253 +1,250 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
ActiveRecord
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
if defined? ActiveRecord
|
5
|
+
ActiveRecord::Base.logger = Logger.new "test.log"
|
6
|
+
ActiveRecord::Base.establish_connection('adapter' => RUBY_PLATFORM == 'java' ? 'jdbcsqlite3' : 'sqlite3', 'database' => ':memory:')
|
7
|
+
|
8
|
+
def setup_db
|
9
|
+
ActiveRecord::Schema.define(:version => 1) do
|
10
|
+
create_table :users do |t|
|
11
|
+
t.column :name, :string
|
12
|
+
t.column :state, :string
|
13
|
+
t.column :activation_code, :string
|
14
|
+
t.column :created_at, :datetime
|
15
|
+
t.column :updated_at, :datetime
|
16
|
+
end
|
17
|
+
create_table :tickets do |t|
|
18
|
+
t.column :ssm_state, :string
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def teardown_db
|
25
|
-
ActiveRecord::Base.connection.tables.each do |table|
|
26
|
-
ActiveRecord::Base.connection.drop_table(table)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Ticket < ActiveRecord::Base
|
31
|
-
extend SimpleStateMachine::ActiveRecord
|
32
22
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
def teardown_db
|
24
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
25
|
+
ActiveRecord::Base.connection.drop_table(table)
|
26
|
+
end
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
29
|
+
class Ticket < ActiveRecord::Base
|
30
|
+
extend SimpleStateMachine::ActiveRecord
|
41
31
|
|
42
|
-
|
32
|
+
state_machine_definition.state_method = :ssm_state
|
43
33
|
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
after_initialize :after_initialize
|
35
|
+
def after_initialize
|
36
|
+
self.ssm_state ||= 'open'
|
37
|
+
end
|
47
38
|
|
48
|
-
|
49
|
-
teardown_db
|
39
|
+
event :close, :open => :closed
|
50
40
|
end
|
51
41
|
|
52
|
-
|
53
|
-
User.new.should be_new
|
54
|
-
end
|
42
|
+
describe ActiveRecord do
|
55
43
|
|
56
|
-
|
44
|
+
before do
|
45
|
+
setup_db
|
46
|
+
end
|
57
47
|
|
58
|
-
|
59
|
-
|
60
|
-
user = User.create!(:name => 'name')
|
61
|
-
user.invite_and_save.should == true
|
62
|
-
User.find(user.id).should be_invited
|
63
|
-
User.find(user.id).activation_code.should_not be_nil
|
48
|
+
after do
|
49
|
+
teardown_db
|
64
50
|
end
|
65
51
|
|
66
|
-
it "
|
67
|
-
|
68
|
-
user_class.instance_eval { attr_protected :state }
|
69
|
-
user = user_class.create!(:name => 'name', :state => 'x')
|
70
|
-
user.should be_new
|
71
|
-
user.invite_and_save
|
72
|
-
user.reload.should be_invited
|
52
|
+
it "has a default state" do
|
53
|
+
expect(User.new).to be_new
|
73
54
|
end
|
74
55
|
|
75
56
|
it "persists transitions when using send and a symbol" do
|
76
57
|
user = User.create!(:name => 'name')
|
77
|
-
user.send(:invite_and_save).
|
78
|
-
User.find(user.id).
|
79
|
-
User.find(user.id).activation_code.
|
58
|
+
expect(user.send(:invite_and_save)).to eq(true)
|
59
|
+
expect(User.find(user.id)).to be_invited
|
60
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
80
61
|
end
|
81
62
|
|
82
|
-
|
83
|
-
user = User.create!(:name => 'name')
|
84
|
-
expect {
|
85
|
-
user.confirm_invitation_and_save 'abc'
|
86
|
-
}.to raise_error(SimpleStateMachine::IllegalStateTransitionError,
|
87
|
-
"You cannot 'confirm_invitation' when state is 'new'")
|
88
|
-
end
|
63
|
+
# TODO needs nesting/grouping, seems to have some duplication
|
89
64
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
65
|
+
describe "event_and_save" do
|
66
|
+
it "persists transitions" do
|
67
|
+
user = User.create!(:name => 'name')
|
68
|
+
expect(user.invite_and_save).to eq(true)
|
69
|
+
expect(User.find(user.id)).to be_invited
|
70
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
71
|
+
end
|
97
72
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
73
|
+
it "persists transitions when using send and a symbol" do
|
74
|
+
user = User.create!(:name => 'name')
|
75
|
+
expect(user.send(:invite_and_save)).to eq(true)
|
76
|
+
expect(User.find(user.id)).to be_invited
|
77
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
78
|
+
end
|
79
|
+
|
80
|
+
it "raises an error if an invalid state_transition is called" do
|
81
|
+
user = User.create!(:name => 'name')
|
82
|
+
expect {
|
83
|
+
user.confirm_invitation_and_save 'abc'
|
84
|
+
}.to raise_error(SimpleStateMachine::IllegalStateTransitionError,
|
85
|
+
"You cannot 'confirm_invitation' when state is 'new'")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "returns false and keeps state if record is invalid" do
|
89
|
+
user = User.new
|
90
|
+
expect(user).to be_new
|
91
|
+
expect(user).not_to be_valid
|
92
|
+
expect(user.invite_and_save).to eq(false)
|
93
|
+
expect(user).to be_new
|
94
|
+
end
|
95
|
+
|
96
|
+
it "returns false, keeps state and keeps errors if event adds errors" do
|
97
|
+
user = User.create!(:name => 'name')
|
98
|
+
user.invite_and_save!
|
99
|
+
expect(user).to be_invited
|
100
|
+
expect(user.confirm_invitation_and_save('x')).to eq(false)
|
101
|
+
expect(user).to be_invited
|
102
|
+
expect(Array(user.errors[:activation_code])).to eq(['is invalid'])
|
103
|
+
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
105
|
+
it "rollsback if an exception is raised" do
|
106
|
+
user_class = Class.new(User)
|
107
|
+
user_class.instance_eval do
|
108
|
+
define_method :invite_without_managed_state do
|
109
|
+
User.create!(:name => 'name2') #this shouldn't be persisted
|
110
|
+
User.create! #this should raise an error
|
111
|
+
end
|
113
112
|
end
|
113
|
+
expect(user_class.count).to eq(0)
|
114
|
+
user = user_class.create!(:name => 'name')
|
115
|
+
expect {
|
116
|
+
user.transaction { user.invite_and_save }
|
117
|
+
}.to raise_error(ActiveRecord::RecordInvalid,
|
118
|
+
"Validation failed: Name can't be blank")
|
119
|
+
expect(user_class.count).to eq(1)
|
120
|
+
expect(user_class.first.name).to eq('name')
|
121
|
+
expect(user_class.first).to be_new
|
122
|
+
end
|
123
|
+
|
124
|
+
it "raises an error if an invalid state_transition is called" do
|
125
|
+
user = User.create!(:name => 'name')
|
126
|
+
expect {
|
127
|
+
user.confirm_invitation_and_save! 'abc'
|
128
|
+
}.to raise_error(SimpleStateMachine::IllegalStateTransitionError,
|
129
|
+
"You cannot 'confirm_invitation' when state is 'new'")
|
114
130
|
end
|
115
|
-
user_class.count.should == 0
|
116
|
-
user = user_class.create!(:name => 'name')
|
117
|
-
expect {
|
118
|
-
user.transaction { user.invite_and_save }
|
119
|
-
}.to raise_error(ActiveRecord::RecordInvalid,
|
120
|
-
"Validation failed: Name can't be blank")
|
121
|
-
user_class.count.should == 1
|
122
|
-
user_class.first.name.should == 'name'
|
123
|
-
user_class.first.should be_new
|
124
131
|
end
|
125
|
-
end
|
126
132
|
|
127
|
-
|
133
|
+
describe "event_and_save!" do
|
128
134
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
+
it "persists transitions" do
|
136
|
+
user = User.create!(:name => 'name')
|
137
|
+
expect(user.invite_and_save!).to eq(true)
|
138
|
+
expect(User.find(user.id)).to be_invited
|
139
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
140
|
+
end
|
135
141
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
end
|
142
|
+
it "raises an error if an invalid state_transition is called" do
|
143
|
+
user = User.create!(:name => 'name')
|
144
|
+
expect {
|
145
|
+
user.confirm_invitation_and_save! 'abc'
|
146
|
+
}.to raise_error(SimpleStateMachine::IllegalStateTransitionError,
|
147
|
+
"You cannot 'confirm_invitation' when state is 'new'")
|
148
|
+
end
|
144
149
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
user.
|
149
|
-
|
150
|
-
|
151
|
-
|
150
|
+
it "raises a RecordInvalid and keeps state if record is invalid" do
|
151
|
+
user = User.new
|
152
|
+
expect(user).to be_new
|
153
|
+
expect(user).not_to be_valid
|
154
|
+
expect {
|
155
|
+
user.invite_and_save!
|
156
|
+
}.to raise_error(ActiveRecord::RecordInvalid,
|
157
|
+
"Validation failed: Name can't be blank")
|
158
|
+
expect(user).to be_new
|
159
|
+
end
|
152
160
|
|
153
|
-
|
154
|
-
|
155
|
-
user.should be_new
|
156
|
-
user.should_not be_valid
|
157
|
-
expect {
|
161
|
+
it "raises a RecordInvalid and keeps state if event adds errors" do
|
162
|
+
user = User.create!(:name => 'name')
|
158
163
|
user.invite_and_save!
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
user.invite_and_save!
|
167
|
-
user.should be_invited
|
168
|
-
expect {
|
169
|
-
user.confirm_invitation_and_save!('x')
|
170
|
-
}.to raise_error(ActiveRecord::RecordInvalid,
|
171
|
-
"Validation failed: Activation code is invalid")
|
172
|
-
user.should be_invited
|
173
|
-
end
|
164
|
+
expect(user).to be_invited
|
165
|
+
expect {
|
166
|
+
user.confirm_invitation_and_save!('x')
|
167
|
+
}.to raise_error(ActiveRecord::RecordInvalid,
|
168
|
+
"Validation failed: Activation code is invalid")
|
169
|
+
expect(user).to be_invited
|
170
|
+
end
|
174
171
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
172
|
+
it "rollsback if an exception is raised" do
|
173
|
+
user_class = Class.new(User)
|
174
|
+
user_class.instance_eval do
|
175
|
+
define_method :invite_without_managed_state do
|
176
|
+
User.create!(:name => 'name2') #this shouldn't be persisted
|
177
|
+
User.create! #this should raise an error
|
178
|
+
end
|
181
179
|
end
|
180
|
+
expect(user_class.count).to eq(0)
|
181
|
+
user = user_class.create!(:name => 'name')
|
182
|
+
expect {
|
183
|
+
user.transaction { user.invite_and_save! }
|
184
|
+
}.to raise_error(ActiveRecord::RecordInvalid,
|
185
|
+
"Validation failed: Name can't be blank")
|
186
|
+
expect(user_class.count).to eq(1)
|
187
|
+
expect(user_class.first.name).to eq('name')
|
188
|
+
expect(user_class.first).to be_new
|
182
189
|
end
|
183
|
-
|
184
|
-
user = user_class.create!(:name => 'name')
|
185
|
-
expect {
|
186
|
-
user.transaction { user.invite_and_save! }
|
187
|
-
}.to raise_error(ActiveRecord::RecordInvalid,
|
188
|
-
"Validation failed: Name can't be blank")
|
189
|
-
user_class.count.should == 1
|
190
|
-
user_class.first.name.should == 'name'
|
191
|
-
user_class.first.should be_new
|
190
|
+
|
192
191
|
end
|
193
192
|
|
194
|
-
|
193
|
+
describe "event" do
|
194
|
+
it "persists transitions" do
|
195
|
+
user = User.create!(:name => 'name')
|
196
|
+
expect(user.invite).to eq(true)
|
197
|
+
expect(User.find(user.id)).to be_invited
|
198
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
199
|
+
end
|
195
200
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
201
|
+
it "returns false, keeps state and keeps errors if event adds errors" do
|
202
|
+
user = User.create!(:name => 'name')
|
203
|
+
user.invite_and_save!
|
204
|
+
expect(user).to be_invited
|
205
|
+
expect(user.confirm_invitation('x')).to eq(false)
|
206
|
+
expect(user).to be_invited
|
207
|
+
expect(Array(user.errors[:activation_code])).to eq(['is invalid'])
|
208
|
+
end
|
203
209
|
|
204
|
-
it "returns false, keeps state and keeps errors if event adds errors" do
|
205
|
-
user = User.create!(:name => 'name')
|
206
|
-
user.invite_and_save!
|
207
|
-
user.should be_invited
|
208
|
-
user.confirm_invitation('x').should == false
|
209
|
-
user.should be_invited
|
210
|
-
user.errors.entries.should == [['activation_code', 'is invalid']]
|
211
210
|
end
|
212
211
|
|
213
|
-
|
212
|
+
describe "event!" do
|
214
213
|
|
215
|
-
|
214
|
+
it "persists transitions" do
|
215
|
+
user = User.create!(:name => 'name')
|
216
|
+
expect(user.invite!).to eq(true)
|
217
|
+
expect(User.find(user.id)).to be_invited
|
218
|
+
expect(User.find(user.id).activation_code).not_to be_nil
|
219
|
+
end
|
216
220
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
221
|
+
it "raises a RecordInvalid and keeps state if record is invalid" do
|
222
|
+
user = User.new
|
223
|
+
expect(user).to be_new
|
224
|
+
expect(user).not_to be_valid
|
225
|
+
expect { user.invite! }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Name can't be blank")
|
226
|
+
expect(user).to be_new
|
227
|
+
end
|
223
228
|
|
224
|
-
it "raises a RecordInvalid and keeps state if record is invalid" do
|
225
|
-
user = User.new
|
226
|
-
user.should be_new
|
227
|
-
user.should_not be_valid
|
228
|
-
expect { user.invite! }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Name can't be blank")
|
229
|
-
user.should be_new
|
230
229
|
end
|
231
230
|
|
232
|
-
|
231
|
+
describe 'custom state method' do
|
233
232
|
|
234
|
-
|
233
|
+
it "persists transitions" do
|
234
|
+
ticket = Ticket.create!
|
235
|
+
expect(ticket.ssm_state).to eq('open')
|
236
|
+
expect(ticket.close!).to eq(true)
|
237
|
+
expect(ticket.ssm_state).to eq('closed')
|
238
|
+
end
|
235
239
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
240
|
+
it "persists transitions with !" do
|
241
|
+
ticket = Ticket.create!
|
242
|
+
expect(ticket.ssm_state).to eq('open')
|
243
|
+
ticket.close!
|
244
|
+
expect(ticket.ssm_state).to eq('closed')
|
245
|
+
end
|
242
246
|
|
243
|
-
it "persists transitions with !" do
|
244
|
-
ticket = Ticket.create!
|
245
|
-
ticket.ssm_state.should == 'open'
|
246
|
-
ticket.close!
|
247
|
-
ticket.ssm_state.should == 'closed'
|
248
247
|
end
|
249
248
|
|
250
249
|
end
|
251
|
-
|
252
250
|
end
|
253
|
-
|
@@ -10,7 +10,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
10
10
|
@state_machine_definition ||= SimpleStateMachine::StateMachineDefinition.new
|
11
11
|
end
|
12
12
|
end
|
13
|
-
decorator =
|
13
|
+
decorator = described_class.new klass
|
14
14
|
decorator.decorate SimpleStateMachine::Transition.new(:event, :state1, :state2)
|
15
15
|
@instance = klass.new
|
16
16
|
@instance.state = 'state1'
|
@@ -18,26 +18,26 @@ describe SimpleStateMachine::Decorator::Default do
|
|
18
18
|
|
19
19
|
describe "#initialize" do
|
20
20
|
it "defines a state_machine method" do
|
21
|
-
@instance.state_machine.
|
21
|
+
expect(@instance.state_machine).to be_an(SimpleStateMachine::StateMachine)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "defines a state getter method" do
|
25
|
-
@instance.
|
25
|
+
expect(@instance).to respond_to(:state)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "defines a state setter method" do
|
29
|
-
@instance.
|
29
|
+
expect(@instance).to respond_to(:state=)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#decorate" do
|
34
34
|
it "defines state_helper_methods for both states" do
|
35
|
-
@instance.state1
|
36
|
-
@instance.state2
|
35
|
+
expect(@instance.state1?).to eq(true)
|
36
|
+
expect(@instance.state2?).to eq(false)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "defines an event method" do
|
40
|
-
@instance.
|
40
|
+
expect(@instance).to respond_to(:event)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -55,7 +55,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
55
55
|
def event() "predefined method" end
|
56
56
|
end
|
57
57
|
transition = SimpleStateMachine::Transition.new(:event, :state1, :state2)
|
58
|
-
decorator =
|
58
|
+
decorator = described_class.new klass
|
59
59
|
decorator.decorate transition
|
60
60
|
klass.state_machine_definition.transitions << transition
|
61
61
|
@instance = klass.new
|
@@ -64,26 +64,26 @@ describe SimpleStateMachine::Decorator::Default do
|
|
64
64
|
|
65
65
|
describe "#initialize" do
|
66
66
|
it "defines a state_machine method" do
|
67
|
-
@instance.state_machine.
|
67
|
+
expect(@instance.state_machine).to be_an(SimpleStateMachine::StateMachine)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "defines a state getter method" do
|
71
|
-
@instance.
|
71
|
+
expect(@instance).to respond_to(:state)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "defines a state setter method" do
|
75
|
-
@instance.
|
75
|
+
expect(@instance).to respond_to(:state=)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "#decorate" do
|
80
80
|
it "does not overwrite predefined state_helper_methods" do
|
81
|
-
@instance.state1
|
82
|
-
@instance.state2
|
81
|
+
expect(@instance.state1?).to eq("state1")
|
82
|
+
expect(@instance.state2?).to eq("state2")
|
83
83
|
end
|
84
84
|
|
85
85
|
it "does not overwrite predefined event method" do
|
86
|
-
@instance.event.
|
86
|
+
expect(@instance.event).to eq("predefined method")
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -102,7 +102,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
102
102
|
def event() "predefined method" end
|
103
103
|
end
|
104
104
|
transition = SimpleStateMachine::Transition.new(:event, :state1, :state2)
|
105
|
-
decorator =
|
105
|
+
decorator = described_class.new klass
|
106
106
|
decorator.decorate transition
|
107
107
|
klass.state_machine_definition.transitions << transition
|
108
108
|
@instance = klass.new
|
@@ -111,22 +111,22 @@ describe SimpleStateMachine::Decorator::Default do
|
|
111
111
|
|
112
112
|
describe "#initialize" do
|
113
113
|
it "defines a state_machine method" do
|
114
|
-
@instance.state_machine.
|
114
|
+
expect(@instance.state_machine).to be_an(SimpleStateMachine::StateMachine)
|
115
115
|
end
|
116
116
|
|
117
117
|
it "defines a state getter method" do
|
118
|
-
@instance.
|
118
|
+
expect(@instance).to respond_to(:state)
|
119
119
|
end
|
120
120
|
|
121
121
|
it "defines a state setter method" do
|
122
|
-
@instance.
|
122
|
+
expect(@instance).to respond_to(:state=)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
describe "#decorate" do
|
127
127
|
it "does not overwrite predefined protected state_helper_methods" do
|
128
|
-
@instance.send(:state1?).
|
129
|
-
@instance.send(:state2?).
|
128
|
+
expect(@instance.send(:state1?)).to eq("state1")
|
129
|
+
expect(@instance.send(:state2?)).to eq("state2")
|
130
130
|
end
|
131
131
|
|
132
132
|
it "keeps predefined protected state_helper_methods protected" do
|
@@ -135,7 +135,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "does not overwrite predefined protected event method" do
|
138
|
-
@instance.event.
|
138
|
+
expect(@instance.event).to eq("predefined method")
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
@@ -154,7 +154,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
154
154
|
def event() "predefined method" end
|
155
155
|
end
|
156
156
|
transition = SimpleStateMachine::Transition.new(:event, :state1, :state2)
|
157
|
-
decorator =
|
157
|
+
decorator = described_class.new klass
|
158
158
|
decorator.decorate transition
|
159
159
|
klass.state_machine_definition.transitions << transition
|
160
160
|
@instance = klass.new
|
@@ -163,22 +163,22 @@ describe SimpleStateMachine::Decorator::Default do
|
|
163
163
|
|
164
164
|
describe "#initialize" do
|
165
165
|
it "defines a state_machine method" do
|
166
|
-
@instance.state_machine.
|
166
|
+
expect(@instance.state_machine).to be_an(SimpleStateMachine::StateMachine)
|
167
167
|
end
|
168
168
|
|
169
169
|
it "defines a state getter method" do
|
170
|
-
@instance.
|
170
|
+
expect(@instance).to respond_to(:state)
|
171
171
|
end
|
172
172
|
|
173
173
|
it "defines a state setter method" do
|
174
|
-
@instance.
|
174
|
+
expect(@instance).to respond_to(:state=)
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
178
178
|
describe "#decorate" do
|
179
179
|
it "does not overwrite predefined private state_helper_methods" do
|
180
|
-
@instance.send(:state1?).
|
181
|
-
@instance.send(:state2?).
|
180
|
+
expect(@instance.send(:state1?)).to eq("state1")
|
181
|
+
expect(@instance.send(:state2?)).to eq("state2")
|
182
182
|
end
|
183
183
|
|
184
184
|
it "keeps predefined private state_helper_methods private" do
|
@@ -187,7 +187,7 @@ describe SimpleStateMachine::Decorator::Default do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "does not overwrite predefined protected event method" do
|
190
|
-
@instance.event.
|
190
|
+
expect(@instance.event).to eq("predefined method")
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|