trailblazer-operation 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -2
  3. data/CHANGES.md +10 -0
  4. data/lib/trailblazer/operation/class_dependencies.rb +1 -1
  5. data/lib/trailblazer/operation/public_call.rb +24 -14
  6. data/lib/trailblazer/operation/railway.rb +13 -7
  7. data/lib/trailblazer/operation/version.rb +1 -1
  8. data/lib/trailblazer/operation/wtf.rb +11 -0
  9. data/lib/trailblazer/operation.rb +2 -2
  10. data/test/call_test.rb +32 -10
  11. data/test/class_dependencies_test.rb +8 -4
  12. data/test/docs/autogenerated/activity_basics_test.rb +72 -0
  13. data/test/docs/autogenerated/composable_variable_mapping_test.rb +880 -0
  14. data/test/docs/autogenerated/fast_track_layout_test.rb +76 -0
  15. data/test/docs/autogenerated/mechanics_test.rb +382 -0
  16. data/test/docs/autogenerated/sequence_options_test.rb +202 -0
  17. data/test/docs/autogenerated/subprocess_test.rb +257 -0
  18. data/test/docs/autogenerated/wiring_api_test.rb +435 -0
  19. data/test/docs/developer_test.rb +27 -0
  20. data/test/docs/public_call_monkeypatching_test.rb +96 -0
  21. data/test/docs/result_test.rb +38 -0
  22. data/test/docs/step_dsl_test.rb +93 -0
  23. data/test/operation_test.rb +53 -13
  24. data/test/result_test.rb +1 -1
  25. data/test/test_helper.rb +17 -5
  26. data/test/trace_test.rb +3 -43
  27. data/trailblazer-operation.gemspec +2 -1
  28. metadata +42 -23
  29. data/lib/trailblazer/operation/trace.rb +0 -67
  30. data/test/callable_test.rb +0 -147
  31. data/test/docs/doormat_test.rb +0 -190
  32. data/test/docs/macaroni_test.rb +0 -31
  33. data/test/skill_test.rb +0 -66
  34. data/test/wire_test.rb +0 -113
  35. data/test/wiring/defaults_test.rb +0 -193
  36. data/test/wiring/subprocess_test.rb +0 -70
@@ -0,0 +1,257 @@
1
+ # THIS FILE IS AUTOGENERATED FROM trailblazer-activity-dsl-linear/test/docs/subprocess_test.rb
2
+ require "test_helper"
3
+
4
+ class SubprocessDocsTest < Minitest::Spec
5
+ Memo = Class.new
6
+ #:nested
7
+ module Memo::Operation
8
+ class Validate < Trailblazer::Operation
9
+ step :check_params
10
+ step :text_present?
11
+ #~meths
12
+ include T.def_steps(:check_params, :text_present?)
13
+ #~meths end
14
+ end
15
+ end
16
+ #:nested end
17
+
18
+ #:container
19
+ module Memo::Operation
20
+ class Create < Trailblazer::Operation
21
+ step Subprocess(Validate)
22
+ step :save
23
+ left :handle_errors
24
+ step :notify
25
+ #~meths
26
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
27
+ #~meths end
28
+ end
29
+ end
30
+ #:container end
31
+
32
+ it "what" do
33
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :notify]"
34
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :handle_errors]", save: false, terminus: :failure
35
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :handle_errors]", text_present?: false, terminus: :failure
36
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :handle_errors]", check_params: false, terminus: :failure
37
+ end
38
+ end
39
+
40
+ class Output_SubprocessDocsTest < Minitest::Spec
41
+ Memo = Class.new
42
+
43
+ module Memo::Operation
44
+ class Validate < Trailblazer::Operation
45
+ step :check_params
46
+ step :text_present?
47
+ #~meths
48
+ include T.def_steps(:check_params, :text_present?)
49
+ #~meths end
50
+ end
51
+ end
52
+
53
+ #:container-output
54
+ module Memo::Operation
55
+ class Create < Trailblazer::Operation
56
+ step Subprocess(Validate),
57
+ Output(:failure) => Id(:notify)
58
+ step :save
59
+ left :handle_errors
60
+ step :notify
61
+ #~meths
62
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
63
+ #~meths end
64
+ end
65
+ end
66
+ #:container-output end
67
+
68
+ it "what" do
69
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :notify]"
70
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :handle_errors]", save: false, terminus: :failure
71
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :notify]", text_present?: false
72
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :notify]", check_params: false
73
+ end
74
+ end
75
+
76
+ class SubprocessDocsTest < Minitest::Spec
77
+ Memo = Class.new
78
+ #:nested-terminus
79
+ module Memo::Operation
80
+ class Validate < Trailblazer::Operation
81
+ step :check_params,
82
+ Output(:failure) => End(:invalid)
83
+ step :text_present?
84
+ #~meths
85
+ include T.def_steps(:check_params, :text_present?)
86
+ #~meths end
87
+ end
88
+ end
89
+ #:nested-terminus end
90
+
91
+ #:container-terminus
92
+ module Memo::Operation
93
+ class Create < Trailblazer::Operation
94
+ step Subprocess(Validate),
95
+ Output(:invalid) => Track(:failure)
96
+ step :save
97
+ left :handle_errors
98
+ step :notify
99
+ #~meths
100
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
101
+ #~meths end
102
+ end
103
+ end
104
+ #:container-terminus end
105
+
106
+ it "what" do
107
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :notify]"
108
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :handle_errors]", save: false, terminus: :failure
109
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :handle_errors]", text_present?: false, terminus: :failure
110
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :handle_errors]", check_params: false, terminus: :failure
111
+ end
112
+ end
113
+
114
+ #~ignore end
115
+
116
+ class Strict_SubprocessDocsTest < Minitest::Spec
117
+ Memo = Class.new
118
+
119
+ module Memo::Operation
120
+ class Validate < Trailblazer::Operation
121
+ step :check_params,
122
+ Output(:failure) => End(:invalid)
123
+ step :text_present?
124
+ #~meths
125
+ include T.def_steps(:check_params, :text_present?)
126
+ #~meths end
127
+ end
128
+ end
129
+
130
+ module Memo::Operation
131
+ class Create < Trailblazer::Operation
132
+ step Subprocess(Validate, strict: true) # no wiring of {:invalid} terminus.
133
+ step :save
134
+ left :handle_errors
135
+ step :notify
136
+ #~meths
137
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
138
+ #~meths end
139
+ end
140
+ end
141
+
142
+ it "raises {IllegalSignalError} at runtime when not connected" do
143
+ skip "see https://github.com/trailblazer/trailblazer-activity-dsl-linear/issues/59"
144
+
145
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :notify]"
146
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :save, :handle_errors]", save: false, terminus: :failure
147
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :text_present?, :handle_errors]", text_present?: false, terminus: :failure
148
+ # exception = assert_raises Trailblazer::Operation::Circuit::IllegalSignalError do
149
+ assert_invoke Memo::Operation::Create, seq: "[:check_params, :handle_errors]", check_params: false, terminus: :failure
150
+ # end
151
+
152
+ # assert_equal exception.message.split("\n")[1][0..82], %(\e[31mUnrecognized Signal `#<Trailblazer::Operation::End semantic=:invalid>` returned)
153
+ end
154
+ end
155
+
156
+ class FixmeSubprocess_FailFast_DocsTest < Minitest::Spec
157
+ Memo = Class.new
158
+ module Memo::Operation
159
+ class Create < Trailblazer::Operation
160
+ step :validate,
161
+ fail_fast: true
162
+ step :save
163
+ #~meths
164
+ include T.def_steps(:validate, :save)
165
+ #~meths end
166
+ end
167
+ end
168
+
169
+ it do
170
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save]"
171
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", terminus: :fail_fast, validate: false
172
+ end
173
+ end
174
+
175
+ class Subprocess_FailFast_DocsTest < Minitest::Spec
176
+ Memo = Struct.new(:id)
177
+
178
+ module Memo::Operation
179
+ class Validate < Trailblazer::Operation # Validate is a {Railway}
180
+ step :validate
181
+ include T.def_steps(:validate)
182
+ end
183
+ end
184
+
185
+ module Memo::Operation
186
+ class Create < Trailblazer::Operation
187
+ step Subprocess(Validate), fail_fast: true
188
+ step :save
189
+ #~meths
190
+ include T.def_steps(:save)
191
+ #~meths end
192
+ end
193
+ end
194
+
195
+ it do
196
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save]"
197
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", terminus: :fail_fast, validate: false
198
+ end
199
+ end
200
+
201
+ class Subprocess_PassFast_DocsTest < Minitest::Spec
202
+ Memo = Struct.new(:id)
203
+
204
+ module Memo::Operation
205
+ class Validate < Trailblazer::Operation
206
+ step :validate
207
+ include T.def_steps(:validate)
208
+ end
209
+ end
210
+
211
+ module Memo::Operation
212
+ class Create < Trailblazer::Operation
213
+ step Subprocess(Validate), pass_fast: true
214
+ step :save
215
+ #~meths
216
+ include T.def_steps(:save)
217
+ #~meths end
218
+ end
219
+ end
220
+
221
+ it do
222
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", terminus: :pass_fast
223
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", terminus: :failure, validate: false
224
+ end
225
+ end
226
+
227
+ class Subprocess_FastTrack_DocsTest < Minitest::Spec
228
+ Memo = Struct.new(:id)
229
+
230
+ module Memo::Operation
231
+ class Validate < Trailblazer::Operation
232
+ step :validate, fast_track: true
233
+ include T.def_steps(:validate)
234
+ end
235
+ end
236
+
237
+ #:subprocess-fast-track
238
+ module Memo::Operation
239
+ class Create < Trailblazer::Operation
240
+ step Subprocess(Validate), fast_track: true
241
+ step :save
242
+ left :handle_errors
243
+ step :notify
244
+ #~meths
245
+ include T.def_steps(:save, :handle_errors, :notify)
246
+ #~meths end
247
+ end
248
+ end
249
+ #:subprocess-fast-track end
250
+
251
+ it do
252
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]" # validate returns {true}.
253
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :handle_errors]", validate: false, terminus: :failure # validate returns {false}.
254
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", validate: Trailblazer::Activity::FastTrack::PassFast, terminus: :pass_fast # validate returns {pass_fast!}.
255
+ assert_invoke Memo::Operation::Create, seq: "[:validate]", validate: Trailblazer::Activity::FastTrack::FailFast, terminus: :fail_fast # validate returns {fail_fast!}.
256
+ end
257
+ end
@@ -0,0 +1,435 @@
1
+ # THIS FILE IS AUTOGENERATED FROM trailblazer-activity-dsl-linear/test/docs/wiring_api_test.rb
2
+ require "test_helper"
3
+
4
+ #@ original Memo::Operation::Create
5
+ class Vanilla_WiringApiDocsTest < Minitest::Spec
6
+ Memo = Class.new
7
+ module Memo::Operation
8
+ class Create < Trailblazer::Operation
9
+ step :validate
10
+ step :save
11
+ left :handle_errors
12
+ step :notify
13
+ #~meths
14
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
15
+ end
16
+ end
17
+
18
+ it "what" do
19
+ =begin
20
+ #:render
21
+ puts Trailblazer::Developer.render(Memo::Operation::Create)
22
+
23
+ #<Start/:default>
24
+ {Trailblazer::Operation::Right} => #<Trailblazer::Operation::TaskBuilder::Task user_proc=validate>
25
+ #<Trailblazer::Operation::TaskBuilder::Task user_proc=validate>
26
+ {Trailblazer::Operation::Left} => #<Trailblazer::Operation::TaskBuilder::Task user_proc=handle_errors>
27
+ {Trailblazer::Operation::Right} => #<Trailblazer::Operation::TaskBuilder::Task user_proc=save>
28
+ #<Trailblazer::Operation::TaskBuilder::Task user_proc=save>
29
+ {Trailblazer::Operation::Left} => #<Trailblazer::Operation::TaskBuilder::Task user_proc=handle_errors>
30
+ {Trailblazer::Operation::Right} => #<Trailblazer::Operation::TaskBuilder::Task user_proc=notify>
31
+ #<Trailblazer::Operation::TaskBuilder::Task user_proc=handle_errors>
32
+ {Trailblazer::Operation::Left} => #<End/:failure>
33
+ {Trailblazer::Operation::Right} => #<End/:failure>
34
+ #<Trailblazer::Operation::TaskBuilder::Task user_proc=notify>
35
+ {Trailblazer::Operation::Left} => #<End/:failure>
36
+ {Trailblazer::Operation::Right} => #<End/:success>
37
+ #<End/:success>
38
+
39
+ #<End/:failure>
40
+ #:render end
41
+ =end
42
+ end
43
+ end
44
+
45
+ #@ Output => End
46
+ class Output_WiringApiDocsTest < Minitest::Spec
47
+ Memo = Class.new
48
+ module Memo::Operation
49
+ class Create < Trailblazer::Operation
50
+ step :validate
51
+ step :save,
52
+ Output(:failure) => End(:db_error)
53
+ left :handle_errors
54
+ step :notify
55
+ #~meths
56
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
57
+ end
58
+ end
59
+
60
+ it "what" do
61
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
62
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save]", save: false, terminus: :db_error
63
+ end
64
+ end
65
+
66
+ #@ failure/Output => End
67
+ class OutputOnLeft_WiringApiDocsTest < Minitest::Spec
68
+ Memo = Class.new
69
+ #:left
70
+ module Memo::Operation
71
+ class Create < Trailblazer::Operation
72
+ step :validate
73
+ step :save
74
+ left :handle_errors,
75
+ Output(:success) => Track(:success)
76
+ step :notify
77
+ #~meths
78
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
79
+ #~meths end
80
+ end
81
+ end
82
+ #:left end
83
+
84
+ it "what" do
85
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
86
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :handle_errors, :notify]", save: false
87
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :handle_errors]", save: false, handle_errors: false, terminus: :failure
88
+ end
89
+ end
90
+
91
+ #@ Output => Track
92
+ class OutputToSuccess_WiringApiDocsTest < Minitest::Spec
93
+ Memo = Class.new
94
+ #:output-track
95
+ module Memo::Operation
96
+ class Create < Trailblazer::Operation
97
+ step :validate
98
+ step :save,
99
+ Output(:failure) => Track(:success)
100
+ left :handle_errors
101
+ step :notify
102
+ #~meths
103
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
104
+ #~meths end
105
+ end
106
+ end
107
+ #:output-track end
108
+
109
+ it "what" do
110
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
111
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]", save: false
112
+ end
113
+ end
114
+
115
+ #@ Output => Id
116
+ class OutputToId_WiringApiDocsTest < Minitest::Spec
117
+ Memo = Class.new
118
+ #:output-id
119
+ module Memo::Operation
120
+ class Create < Trailblazer::Operation
121
+ step :validate,
122
+ Output(:failure) => Id(:notify)
123
+ step :save
124
+ left :handle_errors
125
+ step :notify
126
+ #~meths
127
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
128
+ #~meths end
129
+ end
130
+ end
131
+ #:output-id end
132
+
133
+ it "what" do
134
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
135
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :notify]", validate: false
136
+ end
137
+ end
138
+
139
+ #@ Output(semantic, Signal) => Track
140
+ class ExplicitOutput_WiringApiDocsTest < Minitest::Spec
141
+ Memo = Struct.new(:save_result) do
142
+ def save; self.save_result; end
143
+ end
144
+
145
+ #:output-explicit
146
+ module Memo::Operation
147
+ class Create < Trailblazer::Operation
148
+ class DbError < Trailblazer::Activity::Signal; end
149
+
150
+ step :validate
151
+ step :save,
152
+ Output(DbError, :database_error) => Track(:failure)
153
+ left :handle_errors
154
+ step :notify
155
+ #~meths
156
+ include T.def_steps(:validate, :handle_errors, :notify)
157
+ def save(ctx, model:, **)
158
+ #~code
159
+ database_broken = ctx[:database_broken]
160
+ #~code end
161
+ return DbError if database_broken
162
+
163
+ model.save
164
+ end
165
+ #~meths end
166
+ end
167
+ end
168
+ #:output-explicit end
169
+
170
+ it "what" do
171
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :handle_errors]", validate: false, terminus: :failure
172
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :notify]", model: Memo.new(true)
173
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :handle_errors]", model: Memo.new(false), terminus: :failure
174
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :handle_errors]", model: Memo.new(true), database_broken: true, terminus: :failure
175
+ end
176
+ end
177
+
178
+ #@ Output => End
179
+ class OutputToEnd_WiringApiDocsTest < Minitest::Spec
180
+ Memo = Class.new
181
+ #:output-end
182
+ module Memo::Operation
183
+ class Create < Trailblazer::Operation
184
+ step :validate
185
+ step :save,
186
+ Output(:failure) => End(:db_error)
187
+ left :handle_errors
188
+ step :notify
189
+ #~meths
190
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
191
+ #~meths end
192
+ end
193
+ end
194
+ #:output-end end
195
+
196
+ it "what" do
197
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
198
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save]", save: false, terminus: :db_error
199
+ end
200
+ end
201
+
202
+ #@ #terminus
203
+ class Terminus_WiringApiDocsTest < Minitest::Spec
204
+ Memo = Class.new
205
+ #:terminus
206
+ module Memo::Operation
207
+ class CRUD < Trailblazer::Operation
208
+ step :validate
209
+ step :save
210
+ terminus :db_error
211
+ #~meths
212
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
213
+ #~meths end
214
+ end
215
+ end
216
+ #:terminus end
217
+
218
+ #:terminus-sub
219
+ module Memo::Operation
220
+ class Create < CRUD
221
+ step :notify,
222
+ Output(:failure) => End(:db_error)
223
+ #~meths
224
+ include T.def_steps(:validate, :save, :handle_errors, :notify)
225
+ #~meths end
226
+ end
227
+ end
228
+ #:terminus-sub end
229
+
230
+ it "what" do
231
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]"
232
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save]", save: false, terminus: :failure
233
+ assert_invoke Memo::Operation::Create, seq: "[:validate, :save, :notify]", notify: false, terminus: :db_error
234
+ end
235
+ end
236
+
237
+ #@ Track()
238
+ class Track_WiringApiDocsTest < Minitest::Spec
239
+ Memo = Class.new
240
+ #:custom-track
241
+ module Memo::Operation
242
+ class Charge < Trailblazer::Operation
243
+ terminus :paypal # add a custom terminus (if you need it)
244
+ step :validate
245
+ step :find_provider,
246
+ Output(:failure) => Track(:paypal)
247
+ step :charge_paypal,
248
+ magnetic_to: :paypal, Output(:success) => Track(:paypal)
249
+ step :charge_default
250
+ #~meths
251
+ include T.def_steps(:validate, :find_provider, :charge_paypal, :charge_default)
252
+ #~meths end
253
+ end
254
+ end
255
+ #:custom-track end
256
+
257
+ it "what" do
258
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_default]"
259
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, terminus: :paypal
260
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, charge_paypal: false, terminus: :failure
261
+ end
262
+ end
263
+
264
+ #@ Path()
265
+ class Path_WiringApiDocsTest < Minitest::Spec
266
+ Memo = Class.new
267
+ #:path-helper
268
+ module Memo::Operation
269
+ class Charge < Trailblazer::Operation
270
+ step :validate
271
+ step :find_provider,
272
+ Output(:failure) => Path(terminus: :paypal) do
273
+ # step :authorize # you can have multiple steps on a path.
274
+ step :charge_paypal
275
+ end
276
+ step :charge_default
277
+ #~meths
278
+ include T.def_steps(:validate, :find_provider, :charge_paypal, :charge_default)
279
+ #~meths end
280
+ end
281
+ end
282
+ #:path-helper end
283
+
284
+ it "what" do
285
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_default]"
286
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, terminus: :paypal
287
+ # TODO: this doesn't add a {failure} output.
288
+ # assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, charge_paypal: false, terminus: :failure
289
+ end
290
+ end
291
+
292
+ #@ Path() with error handling: Output()
293
+ # class Path_WiringApiDocsTest < Minitest::Spec
294
+ # Memo = Class.new
295
+ # #:path-helper-failure
296
+ # module Memo::Operation
297
+ # class Charge < Trailblazer::Operation
298
+ # step :validate
299
+ # step :find_provider,
300
+ # Output(:failure) => Path(terminus: :paypal) do
301
+ # step :charge_paypal, Output(:failure) => Track(:failure) # route to the "global" failure track.
302
+ # end
303
+ # step :charge_default
304
+
305
+ # #~meths
306
+ # include T.def_steps(:validate, :find_provider, :charge_paypal, :charge_default)
307
+ # #~meths end
308
+ # end
309
+ # end
310
+ # #:path-helper-failure end
311
+
312
+ # it "what" do
313
+ # assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_default]"
314
+ # assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, terminus: :paypal
315
+ # assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, charge_paypal: false, terminus: :failure
316
+ # end
317
+ # end
318
+
319
+ #@ Path(:connect_to)
320
+ class PathConnectTo_WiringApiDocsTest < Minitest::Spec
321
+ Memo = Class.new
322
+ #:path-helper-connect-to
323
+ module Memo::Operation
324
+ class Charge < Trailblazer::Operation
325
+ step :validate
326
+ step :find_provider,
327
+ Output(:failure) => Path(connect_to: Id(:finalize)) do
328
+ # step :authorize # you can have multiple steps on a path.
329
+ step :charge_paypal
330
+ end
331
+ step :charge_default
332
+ step :finalize
333
+ #~meths
334
+ include T.def_steps(:validate, :find_provider, :charge_paypal, :charge_default, :finalize)
335
+ #~meths end
336
+ end
337
+ end
338
+ #:path-helper-connect-to end
339
+
340
+ it "what" do
341
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_default, :finalize]"
342
+ assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal, :finalize]", find_provider: false
343
+ # TODO: this doesn't add a {failure} output.
344
+ # assert_invoke Memo::Operation::Charge, seq: "[:validate, :find_provider, :charge_paypal]", find_provider: false, charge_paypal: false, terminus: :failure
345
+ end
346
+ end
347
+
348
+ class WiringApiDocsTest < Minitest::Spec
349
+ # {#terminus} 1.0
350
+ module A
351
+ class Payment
352
+ module Operation
353
+ end
354
+ end
355
+
356
+ #:terminus-
357
+ module Payment::Operation
358
+ class Create < Trailblazer::Operation
359
+ step :find_provider
360
+
361
+ terminus :provider_invalid # , id: "End.provider_invalid", magnetic_to: :provider_invalid
362
+ #~meths
363
+ include T.def_steps(:find_provider)
364
+ #~meths end
365
+ end
366
+ end
367
+ #:terminus- end
368
+ # @diagram wiring-terminus
369
+ end
370
+
371
+ #@ we cannot route to {End.provider_invalid}
372
+ it { assert_invoke A::Payment::Operation::Create, seq: "[:find_provider]" }
373
+ it { assert_invoke A::Payment::Operation::Create, find_provider: false, seq: "[:find_provider]", terminus: :failure }
374
+
375
+ # {#terminus} 1.1
376
+ module B
377
+ class Payment
378
+ module Operation
379
+ end
380
+ end
381
+
382
+ #:terminus-track
383
+ module Payment::Operation
384
+ class Create < Trailblazer::Operation
385
+ step :find_provider,
386
+ # connect {failure} to the next element that is magnetic_to {:provider_invalid}.
387
+ Output(:failure) => Track(:provider_invalid)
388
+
389
+ terminus :provider_invalid
390
+ #~meths
391
+ include T.def_steps(:find_provider)
392
+ #~meths end
393
+ end
394
+ end
395
+ #:terminus-track end
396
+ end
397
+
398
+ #@ failure routes to {End.provider_invalid}
399
+ it { assert_invoke B::Payment::Operation::Create, seq: "[:find_provider]" }
400
+ it { assert_invoke B::Payment::Operation::Create, find_provider: false, seq: "[:find_provider]", terminus: :provider_invalid }
401
+
402
+ it do
403
+ result = B::Payment::Operation::Create.(find_provider: false, seq: [])
404
+ assert_equal result.event.to_h[:semantic], :provider_invalid
405
+ =begin
406
+ #:terminus-invalid
407
+ result = Payment::Operation::Create.(provider: "bla-unknown")
408
+ puts signal.to_h[:semantic] #=> :provider_invalid
409
+ #:terminus-invalid end
410
+ =end
411
+
412
+ end
413
+ end
414
+
415
+ #@ :magnetic_to
416
+ module A
417
+ class MagneticTo_DocsTest < Minitest::Spec
418
+ Memo = Class.new
419
+ #:magnetic_to
420
+ module Memo::Operation
421
+ class Create < Trailblazer::Operation
422
+ step :validate
423
+ step :payment_provider, Output(:failure) => Track(:paypal)
424
+ step :charge_paypal, magnetic_to: :paypal
425
+ step :save
426
+ end
427
+ end
428
+ #:magnetic_to end
429
+
430
+ it "what" do
431
+ #~ignore end
432
+ end
433
+
434
+ end
435
+ end