flow 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/flow.rb +1 -3
- data/lib/flow/flow/core.rb +4 -2
- data/lib/flow/spec_helper.rb +5 -4
- data/lib/flow/{custom_matchers.rb → spec_helper/custom_matchers.rb} +0 -0
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/define_failure.rb +0 -0
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/define_output.rb +0 -0
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/handle_error.rb +0 -0
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/have_on_state.rb +17 -15
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/use_operations.rb +0 -0
- data/lib/flow/{custom_matchers → spec_helper/custom_matchers}/wrap_in_transaction.rb +0 -0
- data/lib/flow/{rspec_configuration.rb → spec_helper/rspec_configuration.rb} +1 -1
- data/lib/flow/spec_helper/shared_contexts.rb +3 -0
- data/lib/flow/spec_helper/shared_contexts/with_failing_operation.rb +43 -0
- data/lib/flow/{shoulda_matcher_helper.rb → spec_helper/shoulda_matcher_helper.rb} +0 -0
- data/lib/flow/state_base.rb +1 -1
- data/lib/flow/version.rb +1 -1
- metadata +44 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb7054475f94b6d73503adf9168e31222098af20a36c048cdf72b68b3e0a7a5
|
4
|
+
data.tar.gz: 3a6feb462916f4d24dd180d88e63527ad1e18a4d99e8cbb5ecae664d919e744a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 467c98e3ab094d2af99c8c27b72cd493c4efb70bec3980c8dbe6c37d3f6101b829ded1fd80445adf4cbd83195d6143c97c4be3ddf1d1f9c87a19ab875aea07da
|
7
|
+
data.tar.gz: 2bcb846816f4f3ad8599dd14970e7ffe6e5d8d0bae9b171ca6b763a6940be1105331bab14e9391c2e2d2dd5b2468cb15d15a1797351259f06af57fc09e3fa133
|
data/README.md
CHANGED
@@ -131,6 +131,14 @@ class ExampleFlow < ApplicationState
|
|
131
131
|
end
|
132
132
|
```
|
133
133
|
|
134
|
+
If you _already have_ an instance of a state class that you want to execute a Flow on, you can simply pass it directly to trigger:
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
state_instance = ExampleState.new(...)
|
138
|
+
|
139
|
+
CalculateTimetablesFlow.trigger(state_instance)
|
140
|
+
```
|
141
|
+
|
134
142
|
### Operations
|
135
143
|
|
136
144
|
An **Operation** is a service object which is executed with a **State**.
|
@@ -299,7 +307,7 @@ If the default value is static, it can be specified in the class definition.
|
|
299
307
|
|
300
308
|
If the default value is dynamic, you may provide a block to compute the default value.
|
301
309
|
|
302
|
-
⚠️ **Heads Up**: The default value blocks **DO NOT** provide access to the state or
|
310
|
+
⚠️ **Heads Up**: The default value blocks **DO NOT** provide access to the state or its other variables!
|
303
311
|
|
304
312
|
```ruby
|
305
313
|
class ExampleFlow < ApplicationFlow; end
|
data/lib/flow.rb
CHANGED
data/lib/flow/flow/core.rb
CHANGED
@@ -18,8 +18,10 @@ module Flow
|
|
18
18
|
attr_reader :state
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(**
|
22
|
-
run_callbacks(:initialize)
|
21
|
+
def initialize(state_instance = nil, **options)
|
22
|
+
run_callbacks(:initialize) do
|
23
|
+
@state = state_instance || state_class.new(**options)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
data/lib/flow/spec_helper.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "spicerack/spec_helper"
|
4
4
|
|
5
|
-
require_relative "custom_matchers"
|
6
|
-
require_relative "
|
7
|
-
require_relative "
|
5
|
+
require_relative "spec_helper/custom_matchers"
|
6
|
+
require_relative "spec_helper/shared_contexts"
|
7
|
+
require_relative "spec_helper/shoulda_matcher_helper"
|
8
|
+
require_relative "spec_helper/rspec_configuration"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -29,26 +29,28 @@
|
|
29
29
|
# it { is_expected.to have_on_state foo: "some data", bar: "some other data" }
|
30
30
|
# end
|
31
31
|
|
32
|
-
module
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
module Flow
|
33
|
+
module CustomMatchers
|
34
|
+
def have_on_state(expectations)
|
35
|
+
HaveOnState.new(expectations)
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
class HaveOnState
|
39
|
+
include RSpec::Matchers
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def initialize(state_expectations)
|
42
|
+
@state_expectations = state_expectations
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def matches?(object)
|
46
|
+
@state_expectations.all? do |key, value|
|
47
|
+
expect(object.state.public_send(key)).to match value
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
def description
|
52
|
+
"have the expected data on state"
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Stubs a given flow to always fail when triggered.
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# describe SomeFlow do
|
7
|
+
# let(:flow) { described_class.new }
|
8
|
+
# let(:failing_flow_class) { described_class }
|
9
|
+
#
|
10
|
+
# include_context "with failing operation"
|
11
|
+
#
|
12
|
+
# before { flow.trigger }
|
13
|
+
#
|
14
|
+
# it "is failed" do
|
15
|
+
# expect(flow).to be_failed
|
16
|
+
# expect(flow.failed_operation.operation_failure.problem).to eq failing_problem
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Requires let variables to be defined in the inclusion context:
|
21
|
+
# * failing_flow_class
|
22
|
+
#
|
23
|
+
# Defines the following variable:
|
24
|
+
# * failure_problem
|
25
|
+
RSpec.shared_context "with failing operation" do
|
26
|
+
let(:failure_problem) { Faker::Lorem.words.join("-").parameterize.underscore }
|
27
|
+
let(:failing_operation) do
|
28
|
+
Class.new(Flow::OperationBase).tap do |klass|
|
29
|
+
klass.instance_exec(self) do |spec_context|
|
30
|
+
failure spec_context.failure_problem
|
31
|
+
|
32
|
+
define_method :behavior do
|
33
|
+
instance_eval("#{spec_context.failure_problem}_failure!")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(failing_flow_class).to receive(:_operations).and_return([ failing_operation ])
|
41
|
+
stub_const("FailingOperation", failing_operation)
|
42
|
+
end
|
43
|
+
end
|
File without changes
|
data/lib/flow/state_base.rb
CHANGED
data/lib/flow/version.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Garside
|
8
8
|
- Allen Rettberg
|
9
9
|
- Jordan Minneti
|
10
10
|
- Vinod Lala
|
11
|
+
- Andrew Cross
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date: 2019-
|
15
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: activemodel
|
@@ -59,16 +60,22 @@ dependencies:
|
|
59
60
|
name: spicerack
|
60
61
|
requirement: !ruby/object:Gem::Requirement
|
61
62
|
requirements:
|
62
|
-
- - "
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.13.3
|
66
|
+
- - "<"
|
63
67
|
- !ruby/object:Gem::Version
|
64
|
-
version: 0
|
68
|
+
version: '1.0'
|
65
69
|
type: :runtime
|
66
70
|
prerelease: false
|
67
71
|
version_requirements: !ruby/object:Gem::Requirement
|
68
72
|
requirements:
|
69
|
-
- - "
|
73
|
+
- - ">="
|
70
74
|
- !ruby/object:Gem::Version
|
71
|
-
version: 0.
|
75
|
+
version: 0.13.3
|
76
|
+
- - "<"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.0'
|
72
79
|
- !ruby/object:Gem::Dependency
|
73
80
|
name: bundler
|
74
81
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,30 +178,42 @@ dependencies:
|
|
171
178
|
name: rspice
|
172
179
|
requirement: !ruby/object:Gem::Requirement
|
173
180
|
requirements:
|
174
|
-
- - "
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: 0.13.3
|
184
|
+
- - "<"
|
175
185
|
- !ruby/object:Gem::Version
|
176
|
-
version: 0
|
186
|
+
version: '1.0'
|
177
187
|
type: :development
|
178
188
|
prerelease: false
|
179
189
|
version_requirements: !ruby/object:Gem::Requirement
|
180
190
|
requirements:
|
181
|
-
- - "
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: 0.13.3
|
194
|
+
- - "<"
|
182
195
|
- !ruby/object:Gem::Version
|
183
|
-
version: 0
|
196
|
+
version: '1.0'
|
184
197
|
- !ruby/object:Gem::Dependency
|
185
198
|
name: spicerack-styleguide
|
186
199
|
requirement: !ruby/object:Gem::Requirement
|
187
200
|
requirements:
|
188
|
-
- - "
|
201
|
+
- - ">="
|
189
202
|
- !ruby/object:Gem::Version
|
190
|
-
version: 0.
|
203
|
+
version: 0.13.3
|
204
|
+
- - "<"
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '1.0'
|
191
207
|
type: :development
|
192
208
|
prerelease: false
|
193
209
|
version_requirements: !ruby/object:Gem::Requirement
|
194
210
|
requirements:
|
195
|
-
- - "
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: 0.13.3
|
214
|
+
- - "<"
|
196
215
|
- !ruby/object:Gem::Version
|
197
|
-
version: 0
|
216
|
+
version: '1.0'
|
198
217
|
- !ruby/object:Gem::Dependency
|
199
218
|
name: shoulda-matchers
|
200
219
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,13 +240,6 @@ files:
|
|
221
240
|
- README.md
|
222
241
|
- lib/flow.rb
|
223
242
|
- lib/flow/concerns/transaction_wrapper.rb
|
224
|
-
- lib/flow/custom_matchers.rb
|
225
|
-
- lib/flow/custom_matchers/define_failure.rb
|
226
|
-
- lib/flow/custom_matchers/define_output.rb
|
227
|
-
- lib/flow/custom_matchers/handle_error.rb
|
228
|
-
- lib/flow/custom_matchers/have_on_state.rb
|
229
|
-
- lib/flow/custom_matchers/use_operations.rb
|
230
|
-
- lib/flow/custom_matchers/wrap_in_transaction.rb
|
231
243
|
- lib/flow/flow/callbacks.rb
|
232
244
|
- lib/flow/flow/core.rb
|
233
245
|
- lib/flow/flow/errors/state_invalid.rb
|
@@ -248,9 +260,18 @@ files:
|
|
248
260
|
- lib/flow/operation/status.rb
|
249
261
|
- lib/flow/operation/transactions.rb
|
250
262
|
- lib/flow/operation_base.rb
|
251
|
-
- lib/flow/rspec_configuration.rb
|
252
|
-
- lib/flow/shoulda_matcher_helper.rb
|
253
263
|
- lib/flow/spec_helper.rb
|
264
|
+
- lib/flow/spec_helper/custom_matchers.rb
|
265
|
+
- lib/flow/spec_helper/custom_matchers/define_failure.rb
|
266
|
+
- lib/flow/spec_helper/custom_matchers/define_output.rb
|
267
|
+
- lib/flow/spec_helper/custom_matchers/handle_error.rb
|
268
|
+
- lib/flow/spec_helper/custom_matchers/have_on_state.rb
|
269
|
+
- lib/flow/spec_helper/custom_matchers/use_operations.rb
|
270
|
+
- lib/flow/spec_helper/custom_matchers/wrap_in_transaction.rb
|
271
|
+
- lib/flow/spec_helper/rspec_configuration.rb
|
272
|
+
- lib/flow/spec_helper/shared_contexts.rb
|
273
|
+
- lib/flow/spec_helper/shared_contexts/with_failing_operation.rb
|
274
|
+
- lib/flow/spec_helper/shoulda_matcher_helper.rb
|
254
275
|
- lib/flow/state/errors/not_validated.rb
|
255
276
|
- lib/flow/state/output.rb
|
256
277
|
- lib/flow/state/status.rb
|