end_state 0.4.0 → 0.9.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/README.md +17 -17
- data/examples/example1.rb +2 -2
- data/examples/machine_spec.rb +4 -4
- data/lib/end_state/{finalizer.rb → concluder.rb} +5 -1
- data/lib/end_state/{finalizers → concluders}/persistence.rb +6 -2
- data/lib/end_state/concluders.rb +1 -0
- data/lib/end_state/errors.rb +5 -1
- data/lib/end_state/state_machine.rb +3 -3
- data/lib/end_state/transition.rb +19 -13
- data/lib/end_state/version.rb +1 -1
- data/lib/end_state.rb +2 -2
- data/lib/end_state_matchers.rb +17 -11
- data/spec/end_state/{finalizer_spec.rb → concluder_spec.rb} +4 -4
- data/spec/end_state/{finalizers → concluders}/persistence_spec.rb +6 -6
- data/spec/end_state/state_machine_spec.rb +17 -17
- data/spec/end_state/transition_spec.rb +21 -21
- metadata +9 -9
- data/lib/end_state/finalizers.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51e9a6a8a317af60132c723aabd5a615ec93f4e3
|
4
|
+
data.tar.gz: 96a3350ec5237b631314c8b5ab574598eb47b219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29e1d05f5fe9da4df8f33783fde04cb1fd9b0f458ee79cfa9d0c728c003e29d62526259fc01b5e0240613583248f4987f9f3883d154957d39477ee2ed895a1e9
|
7
|
+
data.tar.gz: 1c82abe3ebcd9475e20865a77559a596d8bbfd718717a011cfa14d8d1938417ebdc57e6faa420a2fc3cb0fa54ad7484cfbad33bc84dfcde47c092bc29f53db5d
|
data/README.md
CHANGED
@@ -118,9 +118,9 @@ class Machine < EndState::StateMachine
|
|
118
118
|
end
|
119
119
|
```
|
120
120
|
|
121
|
-
##
|
121
|
+
## Concluders
|
122
122
|
|
123
|
-
|
123
|
+
Concluders can be created by subclassing `EndState::Concluder`. Your class will be provided access to:
|
124
124
|
|
125
125
|
* `object` - The wrapped object that has been transitioned.
|
126
126
|
* `state` - The previous state.
|
@@ -128,8 +128,8 @@ Finalizers can be created by subclassing `EndState::Finalizer`. Your class will
|
|
128
128
|
|
129
129
|
Your class should implement the `call` method which should return true or false as to whether it was successful or not.
|
130
130
|
|
131
|
-
If your
|
132
|
-
will be rolled back. The roll back is performed by calling `rollback` on the
|
131
|
+
If your concluder returns false, the transition will be "rolled back" and the failing transition, as well as all previous transitions
|
132
|
+
will be rolled back. The roll back is performed by calling `rollback` on the concluder. During the roll back the concluder will be
|
133
133
|
set up a little differently and you have access to:
|
134
134
|
|
135
135
|
* `object` - The wrapped object that has been rolled back.
|
@@ -137,15 +137,15 @@ set up a little differently and you have access to:
|
|
137
137
|
* `params` - A hash of params passed when calling transition on the machine.
|
138
138
|
|
139
139
|
The wrapped object has an array `failure_messages` available for tracking reasons for invalid transitions. You may shovel
|
140
|
-
a reason (string) into this if you want to provide information on why your
|
141
|
-
the `
|
140
|
+
a reason (string) into this if you want to provide information on why your concluder failed. You can also use the helper method in
|
141
|
+
the `Concluder` class called `add_error` which takes a string.
|
142
142
|
|
143
143
|
The wrapped object has an array `success_messages` available for tracking reasons for valid transitions. You may shovel
|
144
|
-
a reason (string) into this if you want to provide information on why your
|
145
|
-
the `
|
144
|
+
a reason (string) into this if you want to provide information on why your concluder succeeded. You can also use the helper method in
|
145
|
+
the `Concluder` class called `add_success` which takes a string.
|
146
146
|
|
147
147
|
```ruby
|
148
|
-
class WrapUp < EndState::
|
148
|
+
class WrapUp < EndState::Concluder
|
149
149
|
def call
|
150
150
|
# Some important processing
|
151
151
|
true
|
@@ -157,17 +157,17 @@ class WrapUp < EndState::Finalizer
|
|
157
157
|
end
|
158
158
|
```
|
159
159
|
|
160
|
-
A
|
160
|
+
A concluder can be added to the transition definition:
|
161
161
|
|
162
162
|
```ruby
|
163
163
|
class Machine < EndState::StateMachine
|
164
164
|
transition a: :b do |t|
|
165
|
-
t.
|
165
|
+
t.concluder WrapUp
|
166
166
|
end
|
167
167
|
end
|
168
168
|
```
|
169
169
|
|
170
|
-
Since it is a common use case, a
|
170
|
+
Since it is a common use case, a concluder is included which will call `save` on the wrapped object if it responds to `save`.
|
171
171
|
You can use this with a convience method in your transition definition:
|
172
172
|
|
173
173
|
```ruby
|
@@ -252,10 +252,10 @@ end
|
|
252
252
|
## Exceptions for failing Transitions
|
253
253
|
|
254
254
|
By default `transition` will only raise an error, `EndState::UnknownState`, if called with a state that doesn't exist.
|
255
|
-
All other failures, such as missing transition, guard failure, or
|
255
|
+
All other failures, such as missing transition, guard failure, or concluder failure will silently just return `false` and not
|
256
256
|
transition to the new state.
|
257
257
|
|
258
|
-
You also have the option to use `transition!` which will instead raise an error for failures. If your guards and/or
|
258
|
+
You also have the option to use `transition!` which will instead raise an error for failures. If your guards and/or concluders
|
259
259
|
add to the `failure_messages` array then they will be included in the error message.
|
260
260
|
|
261
261
|
Additionally, if you would like to treat all transitions as hard and raise an error you can set that in the machine definition.
|
@@ -292,10 +292,10 @@ In the spec for your state machine:
|
|
292
292
|
```ruby
|
293
293
|
describe Machine do
|
294
294
|
specify { expect(Machine).to have_transition(a: :b).with_guard(MyGuard) }
|
295
|
-
specify { expect(Machine).to have_transition(a: :b).
|
296
|
-
specify { expect(Machine).to have_transition(a: :b).with_guard(MyGuard).
|
295
|
+
specify { expect(Machine).to have_transition(a: :b).with_concluder(MyConcluder) }
|
296
|
+
specify { expect(Machine).to have_transition(a: :b).with_guard(MyGuard).with_concluder(MyConcluder) }
|
297
297
|
specify { expect(Machine).to have_transition(a: :b).with_guards(MyGuard, AnotherGuard) }
|
298
|
-
specify { expect(Machine).to have_transition(a: :b).
|
298
|
+
specify { expect(Machine).to have_transition(a: :b).with_concluders(MyConcluder, AnotherConcluder) }
|
299
299
|
specify { expect(Machine).not_to have_transition(a: :c) }
|
300
300
|
end
|
301
301
|
```
|
data/examples/example1.rb
CHANGED
@@ -7,7 +7,7 @@ class Easy < EndState::Guard
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
class NoOp < EndState::
|
10
|
+
class NoOp < EndState::Concluder
|
11
11
|
def call
|
12
12
|
true
|
13
13
|
end
|
@@ -35,7 +35,7 @@ class Machine < EndState::StateMachine
|
|
35
35
|
end
|
36
36
|
|
37
37
|
transition [:b, :c] => :a do |t|
|
38
|
-
t.
|
38
|
+
t.concluder NoOp, not_very_important_param: 'Ignore me'
|
39
39
|
t.persistence_on
|
40
40
|
end
|
41
41
|
end
|
data/examples/machine_spec.rb
CHANGED
@@ -8,7 +8,7 @@ class Easy < EndState::Guard
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
class NoOp < EndState::
|
11
|
+
class NoOp < EndState::Concluder
|
12
12
|
def call
|
13
13
|
true
|
14
14
|
end
|
@@ -17,12 +17,12 @@ end
|
|
17
17
|
class Machine < EndState::StateMachine
|
18
18
|
transition a: :b do |t|
|
19
19
|
t.guard Easy
|
20
|
-
t.
|
20
|
+
t.concluder NoOp
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe Machine do
|
25
|
-
specify { expect(Machine).to have_transition(a: :b).with_guard(Easy).
|
26
|
-
specify { expect(Machine).to have_transition(a: :b).with_guards(Easy, Easy).
|
25
|
+
specify { expect(Machine).to have_transition(a: :b).with_guard(Easy).with_concluder(NoOp) }
|
26
|
+
specify { expect(Machine).to have_transition(a: :b).with_guards(Easy, Easy).with_concluders(NoOp, NoOp) }
|
27
27
|
specify { expect(Machine).not_to have_transition(a: :c) }
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module EndState
|
2
|
-
class
|
2
|
+
class Concluder
|
3
3
|
include Messages
|
4
4
|
attr_reader :object, :state, :params
|
5
5
|
|
@@ -17,4 +17,8 @@ module EndState
|
|
17
17
|
true
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
# Backward compatibility
|
22
|
+
# Finalizer is deprecated
|
23
|
+
Finalizer = Concluder
|
20
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module EndState
|
2
|
-
module
|
3
|
-
class Persistence < EndState::
|
2
|
+
module Concluders
|
3
|
+
class Persistence < EndState::Concluder
|
4
4
|
def call
|
5
5
|
return false unless object.respond_to? :save
|
6
6
|
!!(object.save)
|
@@ -12,4 +12,8 @@ module EndState
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
# Backward compatibility
|
17
|
+
# Finalizer is deprecated
|
18
|
+
Finalizers = Concluders
|
15
19
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'end_state/concluders/persistence'
|
data/lib/end_state/errors.rb
CHANGED
@@ -4,5 +4,9 @@ module EndState
|
|
4
4
|
class UnknownTransition < Error; end
|
5
5
|
class InvalidEvent < Error; end
|
6
6
|
class GuardFailed < Error; end
|
7
|
-
class
|
7
|
+
class ConcluderFailed < Error; end
|
8
|
+
|
9
|
+
# Backward compatibility
|
10
|
+
# Finalizer is deprecated
|
11
|
+
FinalizerFailed = ConcluderFailed
|
8
12
|
end
|
@@ -94,7 +94,7 @@ module EndState
|
|
94
94
|
return block_transistion(transition, state, mode) unless transition
|
95
95
|
return guard_failed(state, mode) unless transition.allowed?(self, params)
|
96
96
|
return false unless transition.action.new(self, state).call
|
97
|
-
return
|
97
|
+
return conclude_failed(state, mode) unless transition.conclude(self, previous_state, params)
|
98
98
|
true
|
99
99
|
end
|
100
100
|
|
@@ -152,9 +152,9 @@ module EndState
|
|
152
152
|
fail GuardFailed, "The transition to #{state} was blocked: #{failure_messages.join(', ')}"
|
153
153
|
end
|
154
154
|
|
155
|
-
def
|
155
|
+
def conclude_failed(state, mode)
|
156
156
|
return false unless mode == :hard
|
157
|
-
fail
|
157
|
+
fail ConcluderFailed, "The transition to #{state} was rolled back: #{failure_messages.join(', ')}"
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
data/lib/end_state/transition.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module EndState
|
2
2
|
class Transition
|
3
3
|
attr_reader :state, :blocked_event_message
|
4
|
-
attr_accessor :action, :guards, :
|
4
|
+
attr_accessor :action, :guards, :concluders
|
5
5
|
|
6
6
|
def initialize(state)
|
7
7
|
@state = state
|
8
8
|
@action = Action
|
9
9
|
@guards = []
|
10
|
-
@
|
10
|
+
@concluders = []
|
11
11
|
end
|
12
12
|
|
13
13
|
def allowed?(object, params={})
|
@@ -18,10 +18,10 @@ module EndState
|
|
18
18
|
guards.all? { |guard| guard.new(object, state, params).will_allow? }
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
return rollback(
|
21
|
+
def conclude(object, previous_state, params={})
|
22
|
+
concluders.each_with_object([]) do |concluder, concluded|
|
23
|
+
concluded << concluder
|
24
|
+
return rollback(concluded, object, previous_state, params) unless run_concluder(concluder, object, state, params)
|
25
25
|
end
|
26
26
|
true
|
27
27
|
end
|
@@ -34,28 +34,34 @@ module EndState
|
|
34
34
|
guards << guard
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def concluder(concluder)
|
38
|
+
concluders << concluder
|
39
39
|
end
|
40
40
|
|
41
41
|
def persistence_on
|
42
|
-
|
42
|
+
concluder Concluders::Persistence
|
43
43
|
end
|
44
44
|
|
45
45
|
def blocked(message)
|
46
46
|
@blocked_event_message = message
|
47
47
|
end
|
48
48
|
|
49
|
+
# Backward compatibility
|
50
|
+
# Finalizer is deprecated
|
51
|
+
alias_method :finalizers, :concluders
|
52
|
+
alias_method :finalize, :conclude
|
53
|
+
alias_method :finalizer, :concluder
|
54
|
+
|
49
55
|
private
|
50
56
|
|
51
|
-
def rollback(
|
57
|
+
def rollback(concluded, object, previous_state, params)
|
52
58
|
action.new(object, previous_state).rollback
|
53
|
-
|
59
|
+
concluded.reverse.each { |concluder| concluder.new(object, state, params).rollback }
|
54
60
|
false
|
55
61
|
end
|
56
62
|
|
57
|
-
def
|
58
|
-
|
63
|
+
def run_concluder(concluder, object, state, params)
|
64
|
+
concluder.new(object, state, params).call
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
data/lib/end_state/version.rb
CHANGED
data/lib/end_state.rb
CHANGED
@@ -3,8 +3,8 @@ require 'end_state/version'
|
|
3
3
|
require 'end_state/errors'
|
4
4
|
require 'end_state/messages'
|
5
5
|
require 'end_state/guard'
|
6
|
-
require 'end_state/
|
7
|
-
require 'end_state/
|
6
|
+
require 'end_state/concluder'
|
7
|
+
require 'end_state/concluders'
|
8
8
|
require 'end_state/transition'
|
9
9
|
require 'end_state/action'
|
10
10
|
require 'end_state/state_machine'
|
data/lib/end_state_matchers.rb
CHANGED
@@ -4,13 +4,13 @@ module EndStateMatchers
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class TransitionMatcher
|
7
|
-
attr_reader :transition, :machine, :failure_messages, :guards, :
|
7
|
+
attr_reader :transition, :machine, :failure_messages, :guards, :concluders
|
8
8
|
|
9
9
|
def initialize(transition)
|
10
10
|
@transition = transition
|
11
11
|
@failure_messages = []
|
12
12
|
@guards = []
|
13
|
-
@
|
13
|
+
@concluders = []
|
14
14
|
end
|
15
15
|
|
16
16
|
def matches?(actual)
|
@@ -36,23 +36,29 @@ module EndStateMatchers
|
|
36
36
|
self
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
@
|
39
|
+
def with_concluder(concluder)
|
40
|
+
@concluders << concluder
|
41
41
|
self
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
@
|
44
|
+
def with_concluders(*concluders)
|
45
|
+
@concluders += Array(concluders)
|
46
46
|
self
|
47
47
|
end
|
48
48
|
|
49
|
+
# Backward compatibility
|
50
|
+
# Finalizer is deprecated
|
51
|
+
alias_method :with_finalizer, :with_concluder
|
52
|
+
alias_method :with_finalizers, :with_concluders
|
53
|
+
alias_method :finalizers, :concluders
|
54
|
+
|
49
55
|
private
|
50
56
|
|
51
57
|
def verify
|
52
58
|
result = true
|
53
59
|
if machine.transitions.keys.include? transition
|
54
60
|
result = (result && verify_guards) if guards.any?
|
55
|
-
result = (result &&
|
61
|
+
result = (result && verify_concluders) if concluders.any?
|
56
62
|
result
|
57
63
|
else
|
58
64
|
failure_messages << "expected that #{machine.name} would have transition :#{transition.keys.first} => :#{transition.values.first}"
|
@@ -71,11 +77,11 @@ module EndStateMatchers
|
|
71
77
|
result
|
72
78
|
end
|
73
79
|
|
74
|
-
def
|
80
|
+
def verify_concluders
|
75
81
|
result = true
|
76
|
-
|
77
|
-
unless machine.transitions[transition].
|
78
|
-
failure_messages << "expected that transition :#{transition.keys.first} => :#{transition.values.first} would have
|
82
|
+
concluders.each do |concluder|
|
83
|
+
unless machine.transitions[transition].concluders.any? { |f| f == concluder }
|
84
|
+
failure_messages << "expected that transition :#{transition.keys.first} => :#{transition.values.first} would have concluder #{concluder.name}"
|
79
85
|
result = false
|
80
86
|
end
|
81
87
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module EndState
|
4
|
-
describe
|
5
|
-
subject(:
|
4
|
+
describe Concluder do
|
5
|
+
subject(:concluder) { Concluder.new(object, state, params) }
|
6
6
|
let(:object) { Struct.new('Machine', :failure_messages, :success_messages, :state, :store_states_as_strings).new }
|
7
7
|
let(:state) { :a }
|
8
8
|
let(:params) { {} }
|
@@ -13,14 +13,14 @@ module EndState
|
|
13
13
|
|
14
14
|
describe '#add_error' do
|
15
15
|
it 'adds an error' do
|
16
|
-
|
16
|
+
concluder.add_error('error')
|
17
17
|
expect(object.failure_messages).to eq ['error']
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#add_success' do
|
22
22
|
it 'adds an success' do
|
23
|
-
|
23
|
+
concluder.add_error('success')
|
24
24
|
expect(object.failure_messages).to eq ['success']
|
25
25
|
end
|
26
26
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module EndState
|
4
|
-
module
|
4
|
+
module Concluders
|
5
5
|
describe Persistence do
|
6
|
-
subject(:
|
6
|
+
subject(:concluder) { Persistence.new(object, state, params) }
|
7
7
|
let(:object) { double :object, save: nil }
|
8
8
|
let(:state) { :b }
|
9
9
|
let(:params) { {} }
|
10
10
|
|
11
11
|
describe '#call' do
|
12
12
|
it 'calls save on the object' do
|
13
|
-
|
13
|
+
concluder.call
|
14
14
|
expect(object).to have_received(:save)
|
15
15
|
end
|
16
16
|
|
@@ -18,14 +18,14 @@ module EndState
|
|
18
18
|
let(:object) { Object.new }
|
19
19
|
|
20
20
|
it 'returns false' do
|
21
|
-
expect(
|
21
|
+
expect(concluder.call).to be_false
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe '#rollback' do
|
27
27
|
it 'calls save on the object' do
|
28
|
-
|
28
|
+
concluder.rollback
|
29
29
|
expect(object).to have_received(:save)
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ module EndState
|
|
33
33
|
let(:object) { Object.new }
|
34
34
|
|
35
35
|
it 'returns true' do
|
36
|
-
expect(
|
36
|
+
expect(concluder.rollback).to be_true
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -311,18 +311,18 @@ module EndState
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
|
-
context 'and a
|
315
|
-
let(:
|
316
|
-
let(:
|
314
|
+
context 'and a concluder is configured' do
|
315
|
+
let(:concluder) { double :concluder, new: concluder_instance }
|
316
|
+
let(:concluder_instance) { double :concluder_instance, call: nil, rollback: nil }
|
317
317
|
before do
|
318
318
|
StateMachine.transition a: :b do |transition|
|
319
|
-
transition.
|
319
|
+
transition.concluder concluder
|
320
320
|
end
|
321
321
|
end
|
322
322
|
|
323
|
-
context 'and the
|
323
|
+
context 'and the concluder is successful' do
|
324
324
|
before do
|
325
|
-
|
325
|
+
concluder_instance.stub(:call).and_return(true)
|
326
326
|
end
|
327
327
|
|
328
328
|
it 'transitions the state' do
|
@@ -331,9 +331,9 @@ module EndState
|
|
331
331
|
end
|
332
332
|
end
|
333
333
|
|
334
|
-
context 'and the
|
334
|
+
context 'and the concluder fails' do
|
335
335
|
before do
|
336
|
-
|
336
|
+
concluder_instance.stub(:call).and_return(false)
|
337
337
|
end
|
338
338
|
|
339
339
|
it 'does not transition the state' do
|
@@ -405,18 +405,18 @@ module EndState
|
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
408
|
-
context 'and a
|
409
|
-
let(:
|
410
|
-
let(:
|
408
|
+
context 'and a concluder is configured' do
|
409
|
+
let(:concluder) { double :concluder, new: concluder_instance }
|
410
|
+
let(:concluder_instance) { double :concluder_instance, call: nil, rollback: nil }
|
411
411
|
before do
|
412
412
|
StateMachine.transition a: :b do |transition|
|
413
|
-
transition.
|
413
|
+
transition.concluder concluder
|
414
414
|
end
|
415
415
|
end
|
416
416
|
|
417
|
-
context 'and the
|
417
|
+
context 'and the concluder is successful' do
|
418
418
|
before do
|
419
|
-
|
419
|
+
concluder_instance.stub(:call).and_return(true)
|
420
420
|
end
|
421
421
|
|
422
422
|
it 'transitions the state' do
|
@@ -425,13 +425,13 @@ module EndState
|
|
425
425
|
end
|
426
426
|
end
|
427
427
|
|
428
|
-
context 'and the
|
428
|
+
context 'and the concluder fails' do
|
429
429
|
before do
|
430
|
-
|
430
|
+
concluder_instance.stub(:call).and_return(false)
|
431
431
|
end
|
432
432
|
|
433
433
|
it 'does not transition the state' do
|
434
|
-
expect { machine.transition! :b }.to raise_error(
|
434
|
+
expect { machine.transition! :b }.to raise_error(ConcluderFailed)
|
435
435
|
expect(object.state).to eq :a
|
436
436
|
end
|
437
437
|
end
|
@@ -82,50 +82,50 @@ module EndState
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe '#
|
86
|
-
let(:
|
85
|
+
describe '#concluder' do
|
86
|
+
let(:concluder) { double :concluder }
|
87
87
|
|
88
|
-
it 'adds a
|
89
|
-
expect { transition.
|
88
|
+
it 'adds a concluder' do
|
89
|
+
expect { transition.concluder concluder }.to change(transition.concluders, :count).by(1)
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
describe '#persistence_on' do
|
94
|
-
it 'adds a Persistence
|
95
|
-
expect { transition.persistence_on }.to change(transition.
|
94
|
+
it 'adds a Persistence concluder' do
|
95
|
+
expect { transition.persistence_on }.to change(transition.concluders, :count).by(1)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
describe '#
|
100
|
-
let(:
|
101
|
-
let(:
|
99
|
+
describe '#conclude' do
|
100
|
+
let(:concluder) { double :concluder, new: concluder_instance }
|
101
|
+
let(:concluder_instance) { double :concluder_instance, call: nil, rollback: nil }
|
102
102
|
let(:object) { OpenStruct.new(state: :b) }
|
103
103
|
before do
|
104
104
|
object.stub_chain(:class, :store_states_as_strings).and_return(false)
|
105
|
-
transition.
|
105
|
+
transition.concluders << concluder
|
106
106
|
end
|
107
107
|
|
108
|
-
context 'when all
|
109
|
-
before {
|
108
|
+
context 'when all concluders succeed' do
|
109
|
+
before { concluder_instance.stub(:call).and_return(true) }
|
110
110
|
|
111
|
-
specify { expect(transition.
|
111
|
+
specify { expect(transition.conclude object, :a).to be_true }
|
112
112
|
end
|
113
113
|
|
114
|
-
context 'when not all
|
115
|
-
before {
|
114
|
+
context 'when not all concluders succeed' do
|
115
|
+
before { concluder_instance.stub(:call).and_return(false) }
|
116
116
|
|
117
|
-
specify { expect(transition.
|
117
|
+
specify { expect(transition.conclude object, :a).to be_false }
|
118
118
|
|
119
119
|
it 'rolls them back' do
|
120
|
-
transition.
|
121
|
-
expect(
|
120
|
+
transition.conclude object, :a
|
121
|
+
expect(concluder_instance).to have_received(:rollback)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
context 'when params are provided' do
|
126
|
-
it 'creates a
|
127
|
-
transition.
|
128
|
-
expect(
|
126
|
+
it 'creates a concluder with the params' do
|
127
|
+
transition.conclude object, :b, { foo: 'bar' }
|
128
|
+
expect(concluder).to have_received(:new).twice.with(object, :a, { foo: 'bar'} )
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: end_state
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexpeachey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,10 +87,10 @@ files:
|
|
87
87
|
- examples/machine_spec.rb
|
88
88
|
- lib/end_state.rb
|
89
89
|
- lib/end_state/action.rb
|
90
|
+
- lib/end_state/concluder.rb
|
91
|
+
- lib/end_state/concluders.rb
|
92
|
+
- lib/end_state/concluders/persistence.rb
|
90
93
|
- lib/end_state/errors.rb
|
91
|
-
- lib/end_state/finalizer.rb
|
92
|
-
- lib/end_state/finalizers.rb
|
93
|
-
- lib/end_state/finalizers/persistence.rb
|
94
94
|
- lib/end_state/graph.rb
|
95
95
|
- lib/end_state/guard.rb
|
96
96
|
- lib/end_state/messages.rb
|
@@ -100,8 +100,8 @@ files:
|
|
100
100
|
- lib/end_state_matchers.rb
|
101
101
|
- lib/tasks/end_state.rake
|
102
102
|
- spec/end_state/action_spec.rb
|
103
|
-
- spec/end_state/
|
104
|
-
- spec/end_state/
|
103
|
+
- spec/end_state/concluder_spec.rb
|
104
|
+
- spec/end_state/concluders/persistence_spec.rb
|
105
105
|
- spec/end_state/guard_spec.rb
|
106
106
|
- spec/end_state/state_machine_spec.rb
|
107
107
|
- spec/end_state/transition_spec.rb
|
@@ -133,8 +133,8 @@ specification_version: 4
|
|
133
133
|
summary: A State Machine implementation
|
134
134
|
test_files:
|
135
135
|
- spec/end_state/action_spec.rb
|
136
|
-
- spec/end_state/
|
137
|
-
- spec/end_state/
|
136
|
+
- spec/end_state/concluder_spec.rb
|
137
|
+
- spec/end_state/concluders/persistence_spec.rb
|
138
138
|
- spec/end_state/guard_spec.rb
|
139
139
|
- spec/end_state/state_machine_spec.rb
|
140
140
|
- spec/end_state/transition_spec.rb
|
data/lib/end_state/finalizers.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'end_state/finalizers/persistence'
|