trailblazer-operation 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +223 -0
- data/.travis.yml +6 -7
- data/CHANGES.md +16 -12
- data/Gemfile +5 -3
- data/README.md +13 -2
- data/Rakefile +2 -2
- data/lib/trailblazer/operation.rb +52 -67
- data/lib/trailblazer/operation/class_dependencies.rb +1 -1
- data/lib/trailblazer/operation/container.rb +14 -0
- data/lib/trailblazer/operation/deprecated_macro.rb +2 -2
- data/lib/trailblazer/operation/public_call.rb +23 -20
- data/lib/trailblazer/operation/railway.rb +2 -3
- data/lib/trailblazer/operation/railway/macaroni.rb +2 -2
- data/lib/trailblazer/operation/result.rb +14 -1
- data/lib/trailblazer/operation/trace.rb +9 -12
- data/lib/trailblazer/operation/version.rb +4 -2
- data/test/benchmark/skill_resolver_benchmark.rb +8 -9
- data/test/call_test.rb +57 -31
- data/test/callable_test.rb +147 -147
- data/test/class_dependencies_test.rb +6 -7
- data/test/docs/doormat_test.rb +13 -12
- data/test/docs/macaroni_test.rb +7 -9
- data/test/docs/operation_test.rb +69 -4
- data/test/docs/wiring_test.rb +85 -153
- data/test/dry_container_test.rb +4 -3
- data/test/fast_track_test.rb +24 -44
- data/test/inheritance_test.rb +13 -12
- data/test/introspect_test.rb +6 -6
- data/test/operation_test.rb +17 -25
- data/test/result_test.rb +4 -4
- data/test/ruby-2.0.0/operation_test.rb +9 -9
- data/test/ruby-2.0.0/step_test.rb +17 -16
- data/test/step_test.rb +55 -50
- data/test/test_helper.rb +7 -13
- data/test/trace_test.rb +27 -27
- data/test/wiring/defaults_test.rb +29 -33
- data/trailblazer-operation.gemspec +9 -7
- metadata +46 -27
- data/lib/trailblazer/operation/heritage.rb +0 -30
- data/lib/trailblazer/operation/inject.rb +0 -36
- data/lib/trailblazer/operation/inspect.rb +0 -79
- data/lib/trailblazer/operation/railway/fast_track.rb +0 -13
- data/lib/trailblazer/operation/railway/normalizer.rb +0 -58
- data/lib/trailblazer/operation/railway/task_builder.rb +0 -37
- data/test/inspect_test.rb +0 -43
- data/test/macro_test.rb +0 -60
- data/test/task_wrap_test.rb +0 -97
@@ -1,16 +1,15 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class ClassDependenciesTest < Minitest::Spec
|
4
|
-
|
5
4
|
#- Operation[] and Operation[]=
|
6
5
|
|
7
|
-
class Index < Trailblazer::Operation
|
8
|
-
|
6
|
+
# class Index < Trailblazer::Operation
|
7
|
+
# extend ClassDependencies
|
9
8
|
|
10
|
-
|
9
|
+
# self["model.class"] = Module
|
11
10
|
|
12
|
-
|
13
|
-
end
|
11
|
+
# step ->(options, **) { options["a"] = options["model.class"] }
|
12
|
+
# end
|
14
13
|
|
15
|
-
it { Index.({}).inspect("a", "model.class").must_equal %{<Result:true [Module, Module] >} }
|
14
|
+
it { skip "https://trello.com/c/t8bUJlqb/25-op-class-dependencies"; Index.({}).inspect("a", "model.class").must_equal %{<Result:true [Module, Module] >} }
|
16
15
|
end
|
data/test/docs/doormat_test.rb
CHANGED
@@ -5,7 +5,7 @@ class TemplateWithGroupTest < Minitest::Spec
|
|
5
5
|
|
6
6
|
#:template
|
7
7
|
class Memo::Operation < Trailblazer::Operation
|
8
|
-
step :log_call,
|
8
|
+
step :log_call, group: :start
|
9
9
|
step :log_success, group: :end, before: "End.success"
|
10
10
|
fail :log_errors, group: :end, before: "End.failure"
|
11
11
|
#~tmethods
|
@@ -49,8 +49,10 @@ class TemplateWithGroupTest < Minitest::Spec
|
|
49
49
|
#:template-user end
|
50
50
|
|
51
51
|
# it { pp F['__sequence__'].to_a }
|
52
|
-
it {
|
53
|
-
|
52
|
+
it {
|
53
|
+
skip
|
54
|
+
Memo::Create.(params: {}, "b_return" => false).inspect("row").must_equal %{<Result:true [[:a, :l, :b, :c, :z]] >}
|
55
|
+
}
|
54
56
|
end
|
55
57
|
|
56
58
|
class DoormatWithGroupTest < Minitest::Spec
|
@@ -59,12 +61,12 @@ class DoormatWithGroupTest < Minitest::Spec
|
|
59
61
|
#:doormat-group
|
60
62
|
class Memo::Create < Trailblazer::Operation
|
61
63
|
step :create_model
|
62
|
-
step :log_success,
|
64
|
+
step :log_success, group: :end, before: "End.success"
|
63
65
|
|
64
66
|
step :validate
|
65
67
|
step :save
|
66
68
|
|
67
|
-
fail :log_errors,
|
69
|
+
fail :log_errors, group: :end, before: "End.failure"
|
68
70
|
#~methods
|
69
71
|
def create_model(options, **)
|
70
72
|
options["row"] = [:a]
|
@@ -93,8 +95,10 @@ class DoormatWithGroupTest < Minitest::Spec
|
|
93
95
|
#:doormat-group end
|
94
96
|
|
95
97
|
# it { pp F['__sequence__'].to_a }
|
96
|
-
it {
|
97
|
-
|
98
|
+
it {
|
99
|
+
skip
|
100
|
+
Memo::Create.(params: {}, "b_return" => false).inspect("row").must_equal %{<Result:true [[:a, :b, :c, :z]] >}
|
101
|
+
}
|
98
102
|
end
|
99
103
|
|
100
104
|
class DoormatStepDocsTest < Minitest::Spec
|
@@ -137,8 +141,7 @@ class DoormatStepDocsTest < Minitest::Spec
|
|
137
141
|
#:doormat-before end
|
138
142
|
|
139
143
|
# it { pp F['__sequence__'].to_a }
|
140
|
-
it { Memo::Create.(params: {}, "b_return" => false,
|
141
|
-
).inspect("row").must_equal %{<Result:true [[:a, :b, :c, :z]] >} }
|
144
|
+
it { Memo::Create.(params: {}, "b_return" => false).inspect("row").must_equal %{<Result:true [[:a, :b, :c, :z]] >} }
|
142
145
|
end
|
143
146
|
|
144
147
|
class DoormatInheritanceTest < Minitest::Spec
|
@@ -183,7 +186,5 @@ class DoormatInheritanceTest < Minitest::Spec
|
|
183
186
|
#:doormat-before-inheritance-sub end
|
184
187
|
|
185
188
|
# it { pp F['__sequence__'].to_a }
|
186
|
-
it { Create.(
|
187
|
-
).inspect("row").must_equal %{<Result:true [[:a, :b, :c, :z]] >} }
|
189
|
+
it { Create.("b_return" => false).inspect("row").must_equal %{<Result:true [[:a, :b, :c, :z]] >} }
|
188
190
|
end
|
189
|
-
|
data/test/docs/macaroni_test.rb
CHANGED
@@ -8,19 +8,17 @@ class MacaroniTaskBuilderTest < Minitest::Spec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
#:create
|
11
|
-
class Memo::Create < Trailblazer::Operation
|
11
|
+
class Memo::Create < Trailblazer::Operation(step_interface_builder: Trailblazer::Operation::Railway::KwSignature)
|
12
12
|
#~ign
|
13
|
-
|
14
|
-
|
15
|
-
step :create_model, normalizer: Normalizer
|
16
|
-
step :save, normalizer: Normalizer
|
13
|
+
step :create_model
|
14
|
+
step :save
|
17
15
|
#~ign end
|
18
16
|
#~methods
|
19
|
-
def create_model(
|
20
|
-
options[:model] = Memo.new(
|
17
|
+
def create_model(params:, options:, **)
|
18
|
+
options[:model] = Memo.new(title: params[:title])
|
21
19
|
end
|
22
20
|
|
23
|
-
def save(
|
21
|
+
def save(model:, **)
|
24
22
|
model.save
|
25
23
|
end
|
26
24
|
#~methods end
|
@@ -28,6 +26,6 @@ class MacaroniTaskBuilderTest < Minitest::Spec
|
|
28
26
|
#:create end
|
29
27
|
|
30
28
|
it "allows optional macaroni call style" do
|
31
|
-
Memo::Create.(
|
29
|
+
Memo::Create.(params: {title: "Wow!"}).inspect(:model).must_equal %{<Result:true [#<struct MacaroniTaskBuilderTest::Memo title=\"!woW\">] >}
|
32
30
|
end
|
33
31
|
end
|
data/test/docs/operation_test.rb
CHANGED
@@ -1,23 +1,88 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class DocsActivityTest < Minitest::Spec
|
4
|
-
Memo = Struct.new(:
|
4
|
+
Memo = Struct.new(:text)
|
5
5
|
|
6
|
+
#:memo
|
6
7
|
class Memo::Create < Trailblazer::Operation
|
7
8
|
step :create_model
|
9
|
+
|
8
10
|
def create_model(ctx, params:, **)
|
9
|
-
ctx[:model] = Memo.new(params[:
|
11
|
+
ctx[:model] = Memo.new(params[:text])
|
10
12
|
end
|
11
13
|
end
|
14
|
+
#:memo end
|
15
|
+
|
16
|
+
it "what" do
|
17
|
+
#:call-circuit
|
18
|
+
ctx = {params: {text: "Enjoy an IPA"}}
|
19
|
+
signal, (ctx, _) = Memo::Create.([ctx, {}], {})
|
20
|
+
|
21
|
+
puts signal #=> #<Trailblazer::Activity::Railway::End::Success semantic=:success>
|
22
|
+
#:call-circuit end
|
23
|
+
|
24
|
+
signal.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
25
|
+
end
|
12
26
|
|
13
27
|
#:describe
|
14
28
|
describe Memo::Create do
|
15
29
|
it "creates a sane Memo instance" do
|
16
|
-
|
30
|
+
#:call-public
|
31
|
+
result = Memo::Create.(params: {text: "Enjoy an IPA"})
|
32
|
+
|
33
|
+
puts result.success? #=> true
|
34
|
+
|
35
|
+
model = result[:model]
|
36
|
+
puts model.text #=> "Enjoy an IPA"
|
37
|
+
#:call-public end
|
17
38
|
|
18
39
|
result.success?.must_equal true
|
19
|
-
result[:model].
|
40
|
+
result[:model].text.must_equal "Enjoy an IPA"
|
20
41
|
end
|
21
42
|
end
|
22
43
|
#:describe end
|
44
|
+
|
45
|
+
it do
|
46
|
+
module J
|
47
|
+
Memo = Struct.new(:id)
|
48
|
+
|
49
|
+
#:op
|
50
|
+
class Create < Trailblazer::Operation
|
51
|
+
#~flow
|
52
|
+
step :validate, fast_track: true
|
53
|
+
fail :log_error
|
54
|
+
step :create
|
55
|
+
#~flow end
|
56
|
+
|
57
|
+
#~mod
|
58
|
+
def create(ctx, **)
|
59
|
+
ctx[:model] = Memo.new
|
60
|
+
end
|
61
|
+
#~rest
|
62
|
+
def validate(ctx, params:, **)
|
63
|
+
ctx[:input] # true/false
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def log_error(ctx, params:, **)
|
68
|
+
logger.error("wrong params: #{params.inspect}")
|
69
|
+
true
|
70
|
+
end
|
71
|
+
#~rest
|
72
|
+
#~mod end
|
73
|
+
end
|
74
|
+
#:op end
|
75
|
+
end
|
76
|
+
|
77
|
+
ctx = {params: {text: "Hydrate!"}}
|
78
|
+
result = J::Create.(ctx)
|
79
|
+
|
80
|
+
result.success?.must_equal true
|
81
|
+
# ctx.inspect.must_equal %{{:params=>{:text=>\"Hydrate!\"}, :create=>true}}
|
82
|
+
|
83
|
+
#:op-result
|
84
|
+
result.success? #=> true
|
85
|
+
result[:model] #=> #<Memo ..>
|
86
|
+
#:op-result end
|
87
|
+
end
|
23
88
|
end
|
data/test/docs/wiring_test.rb
CHANGED
@@ -2,7 +2,7 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class WiringDocsTest < Minitest::Spec
|
4
4
|
class Memo
|
5
|
-
def initialize(
|
5
|
+
def initialize(_options = {})
|
6
6
|
@options
|
7
7
|
end
|
8
8
|
|
@@ -16,6 +16,8 @@ class WiringDocsTest < Minitest::Spec
|
|
16
16
|
# _"Everything's a memo."_
|
17
17
|
|
18
18
|
module Step
|
19
|
+
Memo = Class.new(WiringDocsTest::Memo)
|
20
|
+
|
19
21
|
#:memo-op
|
20
22
|
class Memo::Create < Trailblazer::Operation
|
21
23
|
step :create_model
|
@@ -28,34 +30,41 @@ class WiringDocsTest < Minitest::Spec
|
|
28
30
|
#~memo-methods
|
29
31
|
def create_model(options, **)
|
30
32
|
end
|
33
|
+
|
31
34
|
def validate(options, **)
|
32
35
|
end
|
36
|
+
|
33
37
|
def assign_errors(options, **)
|
34
38
|
end
|
39
|
+
|
35
40
|
def index(options, **)
|
36
41
|
end
|
42
|
+
|
37
43
|
def uuid(options, **)
|
38
44
|
end
|
45
|
+
|
39
46
|
def save(options, **)
|
40
47
|
end
|
48
|
+
|
41
49
|
def log_errors(options, **)
|
42
50
|
end
|
43
51
|
#~memo-methods end
|
44
52
|
end
|
45
53
|
#:memo-op end
|
46
|
-
|
47
54
|
end
|
48
55
|
|
49
56
|
it do
|
50
|
-
|
57
|
+
Step::Memo::Create.(text: "Punk is not dead.")
|
51
58
|
end
|
52
59
|
|
53
60
|
|
54
61
|
module PassFast
|
62
|
+
Memo = Class.new(WiringDocsTest::Memo)
|
63
|
+
|
55
64
|
#:pf-op
|
56
65
|
class Memo::Create < Trailblazer::Operation
|
57
66
|
step :create_model
|
58
|
-
step :validate,
|
67
|
+
step :validate, pass_fast: true
|
59
68
|
fail :assign_errors
|
60
69
|
step :index
|
61
70
|
pass :uuid
|
@@ -64,25 +73,32 @@ class WiringDocsTest < Minitest::Spec
|
|
64
73
|
#~pf-methods
|
65
74
|
def create_model(options, **)
|
66
75
|
end
|
76
|
+
|
67
77
|
def validate(options, **)
|
68
78
|
end
|
79
|
+
|
69
80
|
def assign_errors(options, **)
|
70
81
|
end
|
82
|
+
|
71
83
|
def index(options, **)
|
72
84
|
end
|
85
|
+
|
73
86
|
def uuid(options, **)
|
74
87
|
end
|
88
|
+
|
75
89
|
def save(options, **)
|
76
90
|
end
|
91
|
+
|
77
92
|
def log_errors(options, **)
|
78
93
|
end
|
79
94
|
#~pf-methods end
|
80
95
|
end
|
81
96
|
#:pf-op end
|
82
|
-
|
83
97
|
end
|
84
98
|
|
85
99
|
module FailFast
|
100
|
+
Memo = Class.new(WiringDocsTest::Memo)
|
101
|
+
|
86
102
|
#:ff-op
|
87
103
|
class Memo::Create < Trailblazer::Operation
|
88
104
|
step :create_model
|
@@ -95,25 +111,33 @@ class WiringDocsTest < Minitest::Spec
|
|
95
111
|
#~ff-methods
|
96
112
|
def create_model(options, **)
|
97
113
|
end
|
114
|
+
|
98
115
|
def validate(options, **)
|
99
116
|
end
|
117
|
+
|
100
118
|
def assign_errors(options, **)
|
101
119
|
end
|
120
|
+
|
102
121
|
def index(options, **)
|
103
122
|
end
|
123
|
+
|
104
124
|
def uuid(options, **)
|
105
125
|
end
|
126
|
+
|
106
127
|
def save(options, **)
|
107
128
|
end
|
129
|
+
|
108
130
|
def log_errors(options, **)
|
109
131
|
end
|
110
132
|
#~ff-methods end
|
111
133
|
end
|
112
134
|
#:ff-op end
|
113
|
-
|
114
135
|
end
|
115
136
|
|
137
|
+
#rubocop:disable Lint/DuplicateMethods
|
116
138
|
module FailFast
|
139
|
+
Memo = Class.new(WiringDocsTest::Memo)
|
140
|
+
|
117
141
|
#:ff-step-op
|
118
142
|
class Memo::Create < Trailblazer::Operation
|
119
143
|
step :create_model
|
@@ -126,32 +150,39 @@ class WiringDocsTest < Minitest::Spec
|
|
126
150
|
#~ff-step-methods
|
127
151
|
def create_model(options, **)
|
128
152
|
end
|
153
|
+
|
129
154
|
def validate(options, **)
|
130
155
|
end
|
156
|
+
|
131
157
|
def assign_errors(options, **)
|
132
158
|
end
|
159
|
+
|
133
160
|
def index(options, **)
|
134
161
|
end
|
162
|
+
|
135
163
|
def uuid(options, **)
|
136
164
|
end
|
165
|
+
|
137
166
|
def save(options, **)
|
138
167
|
end
|
168
|
+
|
139
169
|
def log_errors(options, **)
|
140
170
|
end
|
141
171
|
#~ff-step-methods end
|
142
172
|
end
|
143
173
|
#:ff-step-op end
|
144
174
|
end
|
175
|
+
#rubocop:enable Lint/DuplicateMethods
|
145
176
|
|
146
177
|
=begin
|
147
178
|
describe all options :pass_fast, :fast_track and emiting signals directly, like Left.
|
148
179
|
=end
|
149
180
|
module FastTrack
|
150
|
-
|
181
|
+
Memo = Class.new(WiringDocsTest::Memo)
|
151
182
|
|
152
183
|
#:ft-step-op
|
153
184
|
class Memo::Create < Trailblazer::Operation
|
154
|
-
step :create_model,
|
185
|
+
step :create_model, fast_track: true
|
155
186
|
step :validate
|
156
187
|
fail :assign_errors, fast_track: true
|
157
188
|
step :index
|
@@ -160,34 +191,40 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
160
191
|
fail :log_errors
|
161
192
|
#~ft-step-methods
|
162
193
|
#:ft-create
|
163
|
-
def create_model(options, create_empty_model:false, **)
|
194
|
+
def create_model(options, create_empty_model: false, **)
|
164
195
|
options[:model] = Memo.new
|
165
196
|
create_empty_model ? Railway.pass_fast! : true
|
166
197
|
end
|
198
|
+
|
167
199
|
#:ft-create end
|
168
200
|
#:signal-validate
|
169
|
-
def validate(
|
201
|
+
def validate(_options, params: {}, **)
|
170
202
|
if params[:text].nil?
|
171
203
|
Trailblazer::Activity::Left #=> left track, failure
|
172
204
|
else
|
173
205
|
Trailblazer::Activity::Right #=> right track, success
|
174
206
|
end
|
175
207
|
end
|
208
|
+
|
176
209
|
#:signal-validate end
|
177
210
|
def assign_errors(options, model:, **)
|
178
211
|
options[:errors] = "Something went wrong!"
|
179
212
|
|
180
213
|
model.id.nil? ? Railway.fail_fast! : false
|
181
214
|
end
|
182
|
-
|
215
|
+
|
216
|
+
def index(_options, *)
|
183
217
|
true
|
184
218
|
end
|
185
|
-
|
219
|
+
|
220
|
+
def uuid(_options, **)
|
186
221
|
true
|
187
222
|
end
|
188
|
-
|
223
|
+
|
224
|
+
def save(_options, model:, **)
|
189
225
|
model.id = 1
|
190
226
|
end
|
227
|
+
|
191
228
|
def log_errors(options, **)
|
192
229
|
end
|
193
230
|
#~ft-step-methods end
|
@@ -196,7 +233,7 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
196
233
|
|
197
234
|
class Memo::Create2 < Memo::Create
|
198
235
|
#:signalhelper-validate
|
199
|
-
def validate(
|
236
|
+
def validate(_options, params: {}, **)
|
200
237
|
if params[:text].nil?
|
201
238
|
Railway.fail! #=> left track, failure
|
202
239
|
else
|
@@ -210,7 +247,7 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
210
247
|
it "runs #create_model, only" do
|
211
248
|
Memo = FastTrack::Memo
|
212
249
|
#:ft-call
|
213
|
-
result = Memo::Create.(
|
250
|
+
result = Memo::Create.(create_empty_model: true)
|
214
251
|
puts result.success? #=> true
|
215
252
|
puts result[:model].inspect #=> #<Memo text=nil>
|
216
253
|
#:ft-call end
|
@@ -222,7 +259,7 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
222
259
|
it "fast-tracks in #assign_errors" do
|
223
260
|
Memo = FastTrack::Memo
|
224
261
|
#:ft-call-err
|
225
|
-
result = Memo::Create.(
|
262
|
+
result = Memo::Create.({})
|
226
263
|
puts result.success? #=> false
|
227
264
|
puts result[:model].inspect #=> #<Memo text=nil>
|
228
265
|
puts result[:errors].inspect #=> "Something went wrong!"
|
@@ -235,7 +272,7 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
235
272
|
|
236
273
|
it "goes till #save by emitting signals directly" do
|
237
274
|
Memo = FastTrack::Memo
|
238
|
-
result = Memo::Create.(
|
275
|
+
result = Memo::Create.(params: {text: "Punk is not dead!"})
|
239
276
|
result.success?.must_equal true
|
240
277
|
result[:model].id.must_equal 1
|
241
278
|
result[:errors].must_be_nil
|
@@ -243,124 +280,13 @@ describe all options :pass_fast, :fast_track and emiting signals directly, like
|
|
243
280
|
|
244
281
|
it "goes till #save by using signal helper" do
|
245
282
|
Memo = FastTrack::Memo
|
246
|
-
result = Memo::Create2.(
|
283
|
+
result = Memo::Create2.(params: {text: "Punk is not dead!"})
|
247
284
|
result.success?.must_equal true
|
248
285
|
result[:model].id.must_equal 1
|
249
286
|
result[:errors].must_be_nil
|
250
287
|
end
|
251
288
|
end
|
252
289
|
|
253
|
-
=begin
|
254
|
-
:before, :after, :replace, :delete, :group, :id
|
255
|
-
=end
|
256
|
-
class WiringsDocSeqOptionsTest < Minitest::Spec
|
257
|
-
module Id
|
258
|
-
class Memo < WiringDocsTest::Memo; end
|
259
|
-
|
260
|
-
#:id
|
261
|
-
class Memo::Create < Trailblazer::Operation
|
262
|
-
step :create_model, id: "create_memo"
|
263
|
-
step :validate, id: "validate_params"
|
264
|
-
step :save
|
265
|
-
#~id-methods
|
266
|
-
def create_model(options, **)
|
267
|
-
end
|
268
|
-
def validate(options, **)
|
269
|
-
end
|
270
|
-
def save(options, **)
|
271
|
-
end
|
272
|
-
#~id-methods end
|
273
|
-
end
|
274
|
-
#:id end
|
275
|
-
|
276
|
-
#:delete
|
277
|
-
class Memo::Create::Admin < Memo::Create
|
278
|
-
step nil, delete: "validate_params", id: ""
|
279
|
-
end
|
280
|
-
#:delete end
|
281
|
-
|
282
|
-
#:before
|
283
|
-
class Memo::Create::Authorized < Memo::Create
|
284
|
-
step :policy, before: "create_memo"
|
285
|
-
#~before-methods
|
286
|
-
def policy(options, **)
|
287
|
-
end
|
288
|
-
#~before-methods end
|
289
|
-
end
|
290
|
-
#:before end
|
291
|
-
|
292
|
-
#:after
|
293
|
-
class Memo::Create::Logging < Memo::Create
|
294
|
-
step :logger, after: "validate_params"
|
295
|
-
#~after-methods
|
296
|
-
def logger(options, **)
|
297
|
-
end
|
298
|
-
#~after-methods end
|
299
|
-
end
|
300
|
-
#:after end
|
301
|
-
|
302
|
-
#:replace
|
303
|
-
class Memo::Update < Memo::Create
|
304
|
-
step :find_model, replace: "create_memo", id: "update_memo"
|
305
|
-
#~replace-methods
|
306
|
-
def find_model(options, **)
|
307
|
-
end
|
308
|
-
#~replace-methods end
|
309
|
-
end
|
310
|
-
#:replace end
|
311
|
-
end
|
312
|
-
|
313
|
-
it ":id shows up in introspect" do
|
314
|
-
Memo = Id::Memo
|
315
|
-
#:id-inspect
|
316
|
-
Trailblazer::Operation.introspect( Memo::Create )
|
317
|
-
#=> [>create_memo,>validate_params,>save]
|
318
|
-
#:id-inspect end
|
319
|
-
|
320
|
-
Trailblazer::Operation.introspect( Memo::Create ).must_equal %{[>create_memo,>validate_params,>save]}
|
321
|
-
end
|
322
|
-
|
323
|
-
it ":delete removes step" do
|
324
|
-
Memo = Id::Memo
|
325
|
-
#:delete-inspect
|
326
|
-
Trailblazer::Operation.introspect( Memo::Create::Admin )
|
327
|
-
#=> [>create_model,>save]
|
328
|
-
#:delete-inspect end
|
329
|
-
|
330
|
-
Trailblazer::Operation.introspect( Memo::Create::Admin ).must_equal %{[>create_memo,>save]}
|
331
|
-
end
|
332
|
-
|
333
|
-
it ":before inserts" do
|
334
|
-
Memo = Id::Memo
|
335
|
-
#:before-inspect
|
336
|
-
Trailblazer::Operation.introspect( Memo::Create::Authorized )
|
337
|
-
#=> [>create_model,>save]
|
338
|
-
#:before-inspect end
|
339
|
-
|
340
|
-
Trailblazer::Operation.introspect( Memo::Create::Authorized ).must_equal %{[>policy,>create_memo,>validate_params,>save]}
|
341
|
-
end
|
342
|
-
|
343
|
-
it ":after inserts" do
|
344
|
-
Memo = Id::Memo
|
345
|
-
#:after-inspect
|
346
|
-
Trailblazer::Operation.introspect( Memo::Create::Logging )
|
347
|
-
#=> [>create_memo,>validate_params,>logger,>save]
|
348
|
-
#:after-inspect end
|
349
|
-
|
350
|
-
Trailblazer::Operation.introspect( Memo::Create::Logging ).must_equal %{[>create_memo,>validate_params,>logger,>save]}
|
351
|
-
end
|
352
|
-
|
353
|
-
it ":replace inserts" do
|
354
|
-
Memo = Id::Memo
|
355
|
-
#:replace-inspect
|
356
|
-
Trailblazer::Operation.introspect( Memo::Update )
|
357
|
-
#=> [>update_memo,>validate_params,>save]
|
358
|
-
#:replace-inspect end
|
359
|
-
|
360
|
-
Trailblazer::Operation.introspect( Memo::Update ).must_equal %{[>update_memo,>validate_params,>save]}
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
290
|
# @see https://github.com/trailblazer/trailblazer/issues/190#issuecomment-326992255
|
365
291
|
class WiringsDocRecoverTest < Minitest::Spec
|
366
292
|
Memo = WiringDocsTest::Memo
|
@@ -396,27 +322,27 @@ class WiringsDocRecoverTest < Minitest::Spec
|
|
396
322
|
let(:my_image) { "beautiful landscape" }
|
397
323
|
|
398
324
|
it "works for S3" do
|
399
|
-
result = Memo::Upload.(
|
325
|
+
result = Memo::Upload.(image: my_image, s3: true)
|
400
326
|
|
401
|
-
[
|
327
|
+
[result.success?, result[:s3], result[:azure], result[:b2], result[:problem]].must_equal [true, true, nil, nil, nil]
|
402
328
|
end
|
403
329
|
|
404
330
|
it "works for Azure" do
|
405
|
-
result = Memo::Upload.(
|
331
|
+
result = Memo::Upload.(image: my_image, azure: true, s3: false)
|
406
332
|
|
407
|
-
[
|
333
|
+
[result.success?, result[:s3], result[:azure], result[:b2], result[:problem]].must_equal [true, false, true, nil, nil]
|
408
334
|
end
|
409
335
|
|
410
336
|
it "works for B2" do
|
411
|
-
result = Memo::Upload.(
|
337
|
+
result = Memo::Upload.(image: my_image, b2: true, azure: false, s3: false)
|
412
338
|
|
413
|
-
[
|
339
|
+
[result.success?, result[:s3], result[:azure], result[:b2], result[:problem]].must_equal [true, false, false, true, nil]
|
414
340
|
end
|
415
341
|
|
416
342
|
it "fails for all" do
|
417
|
-
result = Memo::Upload.(
|
343
|
+
result = Memo::Upload.(image: my_image, b2: false, azure: false, s3: false)
|
418
344
|
|
419
|
-
[
|
345
|
+
[result.success?, result[:s3], result[:azure], result[:b2], result[:problem]].must_equal [false, false, false, false, "All uploads failed."]
|
420
346
|
end
|
421
347
|
end
|
422
348
|
|
@@ -425,11 +351,11 @@ class WiringsDocCustomConnectionTest < Minitest::Spec
|
|
425
351
|
|
426
352
|
#:target-id
|
427
353
|
class Memo::Upload < Trailblazer::Operation
|
428
|
-
step :new?, Output(:failure) =>
|
354
|
+
step :new?, Output(:failure) => Id(:index)
|
429
355
|
step :upload
|
430
356
|
step :validate
|
431
357
|
fail :validation_error
|
432
|
-
step :index, id:
|
358
|
+
step :index, id: :index
|
433
359
|
#~target-id-methods
|
434
360
|
def new?(options, is_new:, **)
|
435
361
|
options[:new?] = is_new
|
@@ -439,7 +365,7 @@ class WiringsDocCustomConnectionTest < Minitest::Spec
|
|
439
365
|
options[:upload] = true
|
440
366
|
end
|
441
367
|
|
442
|
-
def validate(options, validate:true, **)
|
368
|
+
def validate(options, validate: true, **)
|
443
369
|
options[:validate] = validate
|
444
370
|
end
|
445
371
|
|
@@ -457,17 +383,17 @@ class WiringsDocCustomConnectionTest < Minitest::Spec
|
|
457
383
|
let(:my_image) { "beautiful landscape" }
|
458
384
|
|
459
385
|
it "works with new image" do
|
460
|
-
result = Memo::Upload.(
|
386
|
+
result = Memo::Upload.(image: my_image, is_new: true)
|
461
387
|
result.inspect(:new?, :upload, :validate, :validation_error, :index).must_equal %{<Result:true [true, true, true, nil, true] >}
|
462
388
|
end
|
463
389
|
|
464
390
|
it "skips everything but index for existing image" do
|
465
|
-
result = Memo::Upload.(
|
391
|
+
result = Memo::Upload.(image: my_image, is_new: false)
|
466
392
|
result.inspect(:new?, :upload, :validate, :validation_error, :index).must_equal %{<Result:true [false, nil, nil, nil, true] >}
|
467
393
|
end
|
468
394
|
|
469
395
|
it "fails in validation" do
|
470
|
-
result = Memo::Upload.(
|
396
|
+
result = Memo::Upload.(image: my_image, is_new: true, validate: false)
|
471
397
|
result.inspect(:new?, :upload, :validate, :validation_error, :index).must_equal %{<Result:false [true, true, false, true, nil] >}
|
472
398
|
end
|
473
399
|
end
|
@@ -479,22 +405,25 @@ class WiringsDocDeciderTest < Minitest::Spec
|
|
479
405
|
class Memo::Upsert < Trailblazer::Operation
|
480
406
|
step :find_model, Output(:failure) => Track(:create_route)
|
481
407
|
step :update
|
482
|
-
step :create, magnetic_to:
|
408
|
+
step :create, magnetic_to: :create_route
|
483
409
|
step :save
|
484
410
|
#~methods
|
485
|
-
def find_model(options, id:nil, **)
|
411
|
+
def find_model(options, id: nil, **)
|
486
412
|
options[:model] = Memo.find(id)
|
487
413
|
end
|
488
414
|
|
489
|
-
def find_model(options, id:, **)
|
415
|
+
def find_model(options, id:, **) #rubocop:disable Lint/DuplicateMethods
|
490
416
|
options[:find_model] = id
|
491
417
|
end
|
418
|
+
|
492
419
|
def update(options, **)
|
493
420
|
options[:update] = true
|
494
421
|
end
|
422
|
+
|
495
423
|
def create(options, **)
|
496
424
|
options[:create] = true
|
497
425
|
end
|
426
|
+
|
498
427
|
def save(options, **)
|
499
428
|
options[:save] = true
|
500
429
|
end
|
@@ -503,11 +432,11 @@ class WiringsDocDeciderTest < Minitest::Spec
|
|
503
432
|
#:decider end
|
504
433
|
|
505
434
|
it "goes the create route" do
|
506
|
-
Memo::Upsert.(
|
435
|
+
Memo::Upsert.(id: false).inspect(:find_model, :update, :create, :save).must_equal %{<Result:true [false, nil, true, true] >}
|
507
436
|
end
|
508
437
|
|
509
438
|
it "goes the update route" do
|
510
|
-
Memo::Upsert.(
|
439
|
+
Memo::Upsert.(id: true).inspect(:find_model, :update, :create, :save).must_equal %{<Result:true [true, true, nil, true] >}
|
511
440
|
end
|
512
441
|
end
|
513
442
|
|
@@ -521,19 +450,22 @@ class WiringsDocEndTest < Minitest::Spec
|
|
521
450
|
fail :db_error
|
522
451
|
step :save
|
523
452
|
#~methods
|
524
|
-
def find_model(options, id:nil, **)
|
453
|
+
def find_model(options, id: nil, **)
|
525
454
|
options[:model] = Memo.find(id)
|
526
455
|
end
|
527
456
|
|
528
|
-
def find_model(options, id:, **)
|
457
|
+
def find_model(options, id:, **) #rubocop:disable Lint/DuplicateMethods
|
529
458
|
options[:find_model] = id
|
530
459
|
end
|
460
|
+
|
531
461
|
def update(options, update: true, **)
|
532
462
|
options[:update] = update
|
533
463
|
end
|
464
|
+
|
534
465
|
def db_error(options, **)
|
535
466
|
options[:db_error] = 1
|
536
467
|
end
|
468
|
+
|
537
469
|
def save(options, **)
|
538
470
|
options[:save] = true
|
539
471
|
end
|
@@ -542,17 +474,17 @@ class WiringsDocEndTest < Minitest::Spec
|
|
542
474
|
#:end end
|
543
475
|
|
544
476
|
it "goes success path" do
|
545
|
-
Memo::Update.(
|
477
|
+
Memo::Update.(id: true).inspect(:find_model, :update, :save, :db_error).must_equal %{<Result:true [true, true, true, nil] >}
|
546
478
|
end
|
547
479
|
|
548
480
|
it "errors out on End.model_not_found" do
|
549
|
-
result = Memo::Update.(
|
481
|
+
result = Memo::Update.(id: false)
|
550
482
|
result.inspect(:find_model, :update, :save, :db_error).must_equal %{<Result:false [false, nil, nil, nil] >}
|
551
483
|
result.event.to_h.must_equal(semantic: :model_not_found)
|
552
484
|
end
|
553
485
|
|
554
486
|
it "takes normal error track" do
|
555
|
-
result = Memo::Update.(
|
487
|
+
result = Memo::Update.(id: true, update: false)
|
556
488
|
result.inspect(:find_model, :update, :save, :db_error).must_equal %{<Result:false [true, false, nil, 1] >}
|
557
489
|
result.event.to_h.must_equal(semantic: :failure)
|
558
490
|
end
|