aasm 3.0.26 → 3.1.1
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/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +13 -1
- data/README.md +56 -4
- data/aasm.gemspec +1 -1
- data/lib/aasm/base.rb +21 -15
- data/lib/aasm/event.rb +15 -4
- data/lib/aasm/instance_base.rb +2 -0
- data/lib/aasm/localizer.rb +1 -1
- data/lib/aasm/persistence/active_record_persistence.rb +17 -1
- data/lib/aasm/transition.rb +13 -6
- data/lib/aasm/version.rb +1 -1
- data/spec/models/guardian.rb +48 -0
- data/spec/unit/api_spec.rb +12 -12
- data/spec/unit/callbacks_spec.rb +25 -25
- data/spec/unit/complex_example_spec.rb +15 -15
- data/spec/unit/event_spec.rb +44 -44
- data/spec/unit/guard_spec.rb +60 -0
- data/spec/unit/initial_state_spec.rb +3 -3
- data/spec/unit/inspection_spec.rb +36 -36
- data/spec/unit/localizer_spec.rb +12 -12
- data/spec/unit/new_dsl_spec.rb +2 -2
- data/spec/unit/persistence/active_record_persistence_spec.rb +107 -67
- data/spec/unit/persistence/mongoid_persistance_spec.rb +24 -24
- data/spec/unit/simple_example_spec.rb +20 -20
- data/spec/unit/state_spec.rb +16 -16
- data/spec/unit/subclassing_spec.rb +6 -6
- data/spec/unit/transition_spec.rb +55 -40
- metadata +9 -5
|
@@ -4,46 +4,46 @@ describe 'transitions' do
|
|
|
4
4
|
|
|
5
5
|
it 'should raise an exception when whiny' do
|
|
6
6
|
process = ProcessWithNewDsl.new
|
|
7
|
-
|
|
8
|
-
process.
|
|
7
|
+
expect { process.stop! }.to raise_error(AASM::InvalidTransition)
|
|
8
|
+
expect(process).to be_sleeping
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it 'should not raise an exception when not whiny' do
|
|
12
12
|
silencer = Silencer.new
|
|
13
|
-
silencer.smile
|
|
14
|
-
silencer.
|
|
13
|
+
expect(silencer.smile!).to be_false
|
|
14
|
+
expect(silencer).to be_silent
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it 'should not raise an exception when superclass not whiny' do
|
|
18
18
|
sub = SubClassing.new
|
|
19
|
-
sub.smile
|
|
20
|
-
sub.
|
|
19
|
+
expect(sub.smile!).to be_false
|
|
20
|
+
expect(sub).to be_silent
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it 'should not raise an exception when from is nil even if whiny' do
|
|
24
24
|
silencer = Silencer.new
|
|
25
|
-
silencer.smile_any
|
|
26
|
-
silencer.
|
|
25
|
+
expect(silencer.smile_any!).to be_true
|
|
26
|
+
expect(silencer).to be_smiling
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it 'should call the block when success' do
|
|
30
30
|
silencer = Silencer.new
|
|
31
31
|
success = false
|
|
32
|
-
|
|
32
|
+
expect {
|
|
33
33
|
silencer.smile_any! do
|
|
34
34
|
success = true
|
|
35
35
|
end
|
|
36
|
-
}.
|
|
36
|
+
}.to change { success }.to(true)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it 'should not call the block when failure' do
|
|
40
40
|
silencer = Silencer.new
|
|
41
41
|
success = false
|
|
42
|
-
|
|
42
|
+
expect {
|
|
43
43
|
silencer.smile! do
|
|
44
44
|
success = true
|
|
45
45
|
end
|
|
46
|
-
}.
|
|
46
|
+
}.not_to change { success }.to(true)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
end
|
|
@@ -56,9 +56,9 @@ describe AASM::Transition do
|
|
|
56
56
|
opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
|
|
57
57
|
st = AASM::Transition.new(opts)
|
|
58
58
|
|
|
59
|
-
st.from.
|
|
60
|
-
st.to.
|
|
61
|
-
st.opts.
|
|
59
|
+
expect(st.from).to eq(opts[:from])
|
|
60
|
+
expect(st.to).to eq(opts[:to])
|
|
61
|
+
expect(st.opts).to eq(opts)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
it 'should pass equality check if from and to are the same' do
|
|
@@ -66,10 +66,10 @@ describe AASM::Transition do
|
|
|
66
66
|
st = AASM::Transition.new(opts)
|
|
67
67
|
|
|
68
68
|
obj = double('object')
|
|
69
|
-
obj.
|
|
70
|
-
obj.
|
|
69
|
+
allow(obj).to receive(:from).and_return(opts[:from])
|
|
70
|
+
allow(obj).to receive(:to).and_return(opts[:to])
|
|
71
71
|
|
|
72
|
-
st.
|
|
72
|
+
expect(st).to eq(obj)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it 'should fail equality check if from are not the same' do
|
|
@@ -77,10 +77,10 @@ describe AASM::Transition do
|
|
|
77
77
|
st = AASM::Transition.new(opts)
|
|
78
78
|
|
|
79
79
|
obj = double('object')
|
|
80
|
-
obj.
|
|
81
|
-
obj.
|
|
80
|
+
allow(obj).to receive(:from).and_return('blah')
|
|
81
|
+
allow(obj).to receive(:to).and_return(opts[:to])
|
|
82
82
|
|
|
83
|
-
st.
|
|
83
|
+
expect(st).not_to eq(obj)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
it 'should fail equality check if to are not the same' do
|
|
@@ -88,10 +88,10 @@ describe AASM::Transition do
|
|
|
88
88
|
st = AASM::Transition.new(opts)
|
|
89
89
|
|
|
90
90
|
obj = double('object')
|
|
91
|
-
obj.
|
|
92
|
-
obj.
|
|
91
|
+
allow(obj).to receive(:from).and_return(opts[:from])
|
|
92
|
+
allow(obj).to receive(:to).and_return('blah')
|
|
93
93
|
|
|
94
|
-
st.
|
|
94
|
+
expect(st).not_to eq(obj)
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -100,7 +100,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
|
100
100
|
opts = {:from => 'foo', :to => 'bar'}
|
|
101
101
|
st = AASM::Transition.new(opts)
|
|
102
102
|
|
|
103
|
-
st.perform(nil).
|
|
103
|
+
expect(st.perform(nil)).to be_true
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
it 'should call the method on the object if guard is a symbol' do
|
|
@@ -108,7 +108,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
|
108
108
|
st = AASM::Transition.new(opts)
|
|
109
109
|
|
|
110
110
|
obj = double('object')
|
|
111
|
-
obj.
|
|
111
|
+
expect(obj).to receive(:test)
|
|
112
112
|
|
|
113
113
|
st.perform(obj)
|
|
114
114
|
end
|
|
@@ -118,7 +118,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
|
118
118
|
st = AASM::Transition.new(opts)
|
|
119
119
|
|
|
120
120
|
obj = double('object')
|
|
121
|
-
obj.
|
|
121
|
+
expect(obj).to receive(:test)
|
|
122
122
|
|
|
123
123
|
st.perform(obj)
|
|
124
124
|
end
|
|
@@ -128,7 +128,7 @@ describe AASM::Transition, '- when performing guard checks' do
|
|
|
128
128
|
st = AASM::Transition.new(opts)
|
|
129
129
|
|
|
130
130
|
obj = double('object')
|
|
131
|
-
obj.
|
|
131
|
+
expect(obj).to receive(:test)
|
|
132
132
|
|
|
133
133
|
st.perform(obj)
|
|
134
134
|
end
|
|
@@ -139,9 +139,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|
|
139
139
|
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {|o| o.test}}
|
|
140
140
|
st = AASM::Transition.new(opts)
|
|
141
141
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
142
|
-
obj = double('object')
|
|
142
|
+
obj = double('object', :aasm => 'aasm')
|
|
143
143
|
|
|
144
|
-
opts[:on_transition].
|
|
144
|
+
expect(opts[:on_transition]).to receive(:call).with(any_args)
|
|
145
145
|
|
|
146
146
|
st.execute(obj, args)
|
|
147
147
|
end
|
|
@@ -150,9 +150,9 @@ describe AASM::Transition, '- when executing the transition with a Proc' do
|
|
|
150
150
|
opts = {:from => 'foo', :to => 'bar', :on_transition => Proc.new {||}}
|
|
151
151
|
st = AASM::Transition.new(opts)
|
|
152
152
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
153
|
-
obj = double('object')
|
|
153
|
+
obj = double('object', :aasm => 'aasm')
|
|
154
154
|
|
|
155
|
-
opts[:on_transition].
|
|
155
|
+
expect(opts[:on_transition]).to receive(:call).with(no_args)
|
|
156
156
|
|
|
157
157
|
st.execute(obj, args)
|
|
158
158
|
end
|
|
@@ -163,9 +163,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
|
163
163
|
opts = {:from => 'foo', :to => 'bar', :on_transition => 'test'}
|
|
164
164
|
st = AASM::Transition.new(opts)
|
|
165
165
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
166
|
-
obj = double('object')
|
|
166
|
+
obj = double('object', :aasm => 'aasm')
|
|
167
167
|
|
|
168
|
-
obj.
|
|
168
|
+
expect(obj).to receive(:test)
|
|
169
169
|
|
|
170
170
|
st.execute(obj, args)
|
|
171
171
|
end
|
|
@@ -174,9 +174,9 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
|
174
174
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
|
175
175
|
st = AASM::Transition.new(opts)
|
|
176
176
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
177
|
-
obj = double('object')
|
|
177
|
+
obj = double('object', :aasm => 'aasm')
|
|
178
178
|
|
|
179
|
-
obj.
|
|
179
|
+
expect(obj).to receive(:test)
|
|
180
180
|
|
|
181
181
|
st.execute(obj, args)
|
|
182
182
|
end
|
|
@@ -185,7 +185,7 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
|
185
185
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
|
186
186
|
st = AASM::Transition.new(opts)
|
|
187
187
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
188
|
-
obj = double('object')
|
|
188
|
+
obj = double('object', :aasm => 'aasm')
|
|
189
189
|
|
|
190
190
|
def obj.test(args)
|
|
191
191
|
"arg1: #{args[:arg1]} arg2: #{args[:arg2]}"
|
|
@@ -193,14 +193,14 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
|
193
193
|
|
|
194
194
|
return_value = st.execute(obj, args)
|
|
195
195
|
|
|
196
|
-
return_value.
|
|
196
|
+
expect(return_value).to eq('arg1: 1 arg2: 2')
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
it 'should NOT pass args if the target method does NOT accept them' do
|
|
200
200
|
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
|
201
201
|
st = AASM::Transition.new(opts)
|
|
202
202
|
args = {:arg1 => '1', :arg2 => '2'}
|
|
203
|
-
obj = double('object')
|
|
203
|
+
obj = double('object', :aasm => 'aasm')
|
|
204
204
|
|
|
205
205
|
def obj.test
|
|
206
206
|
'success'
|
|
@@ -208,7 +208,22 @@ describe AASM::Transition, '- when executing the transition with an :on_transtio
|
|
|
208
208
|
|
|
209
209
|
return_value = st.execute(obj, args)
|
|
210
210
|
|
|
211
|
-
return_value.
|
|
211
|
+
expect(return_value).to eq('success')
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'should allow accessing the from_state and the to_state' do
|
|
215
|
+
opts = {:from => 'foo', :to => 'bar', :on_transition => :test}
|
|
216
|
+
st = AASM::Transition.new(opts)
|
|
217
|
+
args = {:arg1 => '1', :arg2 => '2'}
|
|
218
|
+
obj = double('object', :aasm => AASM::InstanceBase.new('object'))
|
|
219
|
+
|
|
220
|
+
def obj.test(args)
|
|
221
|
+
"from: #{aasm.from_state} to: #{aasm.to_state}"
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
return_value = st.execute(obj, args)
|
|
225
|
+
|
|
226
|
+
expect(return_value).to eq('from: foo to: bar')
|
|
212
227
|
end
|
|
213
228
|
|
|
214
229
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aasm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Scott Barron
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2014-01
|
|
14
|
+
date: 2014-03-01 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: rake
|
|
@@ -45,14 +45,14 @@ dependencies:
|
|
|
45
45
|
name: rspec
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
|
48
|
-
- - "
|
|
48
|
+
- - ">="
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
50
|
version: '2.14'
|
|
51
51
|
type: :development
|
|
52
52
|
prerelease: false
|
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
54
54
|
requirements:
|
|
55
|
-
- - "
|
|
55
|
+
- - ">="
|
|
56
56
|
- !ruby/object:Gem::Version
|
|
57
57
|
version: '2.14'
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
@@ -145,6 +145,7 @@ files:
|
|
|
145
145
|
- spec/models/conversation.rb
|
|
146
146
|
- spec/models/father.rb
|
|
147
147
|
- spec/models/foo.rb
|
|
148
|
+
- spec/models/guardian.rb
|
|
148
149
|
- spec/models/invalid_persistor.rb
|
|
149
150
|
- spec/models/mongoid/no_scope_mongoid.rb
|
|
150
151
|
- spec/models/mongoid/simple_mongoid.rb
|
|
@@ -165,6 +166,7 @@ files:
|
|
|
165
166
|
- spec/unit/callbacks_spec.rb
|
|
166
167
|
- spec/unit/complex_example_spec.rb
|
|
167
168
|
- spec/unit/event_spec.rb
|
|
169
|
+
- spec/unit/guard_spec.rb
|
|
168
170
|
- spec/unit/initial_state_spec.rb
|
|
169
171
|
- spec/unit/inspection_spec.rb
|
|
170
172
|
- spec/unit/localizer_spec.rb
|
|
@@ -196,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
196
198
|
version: '0'
|
|
197
199
|
requirements: []
|
|
198
200
|
rubyforge_project:
|
|
199
|
-
rubygems_version: 2.
|
|
201
|
+
rubygems_version: 2.2.2
|
|
200
202
|
signing_key:
|
|
201
203
|
specification_version: 4
|
|
202
204
|
summary: State machine mixin for Ruby objects
|
|
@@ -213,6 +215,7 @@ test_files:
|
|
|
213
215
|
- spec/models/conversation.rb
|
|
214
216
|
- spec/models/father.rb
|
|
215
217
|
- spec/models/foo.rb
|
|
218
|
+
- spec/models/guardian.rb
|
|
216
219
|
- spec/models/invalid_persistor.rb
|
|
217
220
|
- spec/models/mongoid/no_scope_mongoid.rb
|
|
218
221
|
- spec/models/mongoid/simple_mongoid.rb
|
|
@@ -233,6 +236,7 @@ test_files:
|
|
|
233
236
|
- spec/unit/callbacks_spec.rb
|
|
234
237
|
- spec/unit/complex_example_spec.rb
|
|
235
238
|
- spec/unit/event_spec.rb
|
|
239
|
+
- spec/unit/guard_spec.rb
|
|
236
240
|
- spec/unit/initial_state_spec.rb
|
|
237
241
|
- spec/unit/inspection_spec.rb
|
|
238
242
|
- spec/unit/localizer_spec.rb
|