trailblazer-macro 2.1.0.rc12 → 2.1.2
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/.travis.yml +1 -3
- data/CHANGES.md +22 -0
- data/LICENSE +9 -0
- data/lib/trailblazer/macro.rb +12 -13
- data/lib/trailblazer/macro/model.rb +17 -11
- data/lib/trailblazer/macro/policy.rb +3 -3
- data/lib/trailblazer/macro/pundit.rb +2 -2
- data/lib/trailblazer/macro/rescue.rb +1 -1
- data/lib/trailblazer/macro/version.rb +1 -1
- data/lib/trailblazer/macro/wrap.rb +3 -1
- data/test/docs/guard_test.rb +20 -17
- data/test/docs/model_test.rb +20 -0
- data/test/docs/nested_test.rb +110 -29
- data/test/docs/pundit_test.rb +7 -7
- data/test/docs/rescue_test.rb +1 -1
- data/test/docs/wrap_test.rb +216 -78
- data/test/operation/model_test.rb +12 -15
- data/test/operation/pundit_test.rb +22 -22
- data/test/test_helper.rb +4 -3
- data/trailblazer-macro.gemspec +5 -7
- metadata +34 -15
- data/LICENSE.txt +0 -27
data/test/docs/pundit_test.rb
CHANGED
|
@@ -36,11 +36,11 @@ class DocsPunditProcTest < Minitest::Spec
|
|
|
36
36
|
it do
|
|
37
37
|
#:pundit-result
|
|
38
38
|
result = Create.(params: {}, current_user: Module)
|
|
39
|
-
result["result.policy.default"].success? #=> true
|
|
40
|
-
result["result.policy.default"][
|
|
39
|
+
result[:"result.policy.default"].success? #=> true
|
|
40
|
+
result[:"result.policy.default"][:policy] #=> #<MyPolicy ...>
|
|
41
41
|
#:pundit-result end
|
|
42
|
-
result["result.policy.default"].success?.must_equal true
|
|
43
|
-
result["result.policy.default"][
|
|
42
|
+
result[:"result.policy.default"].success?.must_equal true
|
|
43
|
+
result[:"result.policy.default"][:policy].is_a?(MyPolicy).must_equal true
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
#---
|
|
@@ -82,7 +82,7 @@ class DocsPunditProcTest < Minitest::Spec
|
|
|
82
82
|
#:di-call
|
|
83
83
|
Create.(params: {},
|
|
84
84
|
current_user: Module,
|
|
85
|
-
"policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
|
|
85
|
+
:"policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
|
|
86
86
|
)
|
|
87
87
|
#:di-call end
|
|
88
88
|
result.inspect("").must_equal %{<Result:true [nil] >} }
|
|
@@ -104,9 +104,9 @@ class PunditWithNameTest < Minitest::Spec
|
|
|
104
104
|
it {
|
|
105
105
|
#:name-call
|
|
106
106
|
result = Create.(params: {}, current_user: Module)
|
|
107
|
-
result["result.policy.after_model"].success? #=> true
|
|
107
|
+
result[:"result.policy.after_model"].success? #=> true
|
|
108
108
|
#:name-call end
|
|
109
|
-
result["result.policy.after_model"].success?.must_equal true }
|
|
109
|
+
result[:"result.policy.after_model"].success?.must_equal true }
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
#---
|
data/test/docs/rescue_test.rb
CHANGED
|
@@ -23,7 +23,7 @@ class NestedRescueTest < Minitest::Spec
|
|
|
23
23
|
fail ->(options, **) { options["outer-err"] = true }, id: "nested/failure"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
it { Trailblazer::Developer.railway(NestedInsanity).must_match /\[>Rescue\(\
|
|
26
|
+
it { Trailblazer::Developer.railway(NestedInsanity).must_match /\[>Rescue\(.{8}\),>nested/ } # FIXME: better introspect tests for all id-generating macros.
|
|
27
27
|
it { NestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
|
|
28
28
|
it { NestedInsanity.( "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
|
|
29
29
|
it { NestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
|
data/test/docs/wrap_test.rb
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class DocsWrapTest < Minitest::Spec
|
|
4
|
-
module Memo
|
|
5
|
-
end
|
|
6
|
-
|
|
7
4
|
=begin
|
|
8
5
|
When success: return the block's returns
|
|
9
6
|
When raise: return {Railway.fail!}
|
|
@@ -11,11 +8,10 @@ When raise: return {Railway.fail!}
|
|
|
11
8
|
#:wrap-handler
|
|
12
9
|
class HandleUnsafeProcess
|
|
13
10
|
def self.call((ctx, flow_options), *, &block)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
11
|
+
yield # calls the wrapped steps
|
|
12
|
+
rescue
|
|
13
|
+
ctx[:exception] = $!.message
|
|
14
|
+
[ Trailblazer::Operation::Railway.fail!, [ctx, flow_options] ]
|
|
19
15
|
end
|
|
20
16
|
end
|
|
21
17
|
#:wrap-handler end
|
|
@@ -64,6 +60,11 @@ result.wtf? #=>
|
|
|
64
60
|
=end
|
|
65
61
|
end
|
|
66
62
|
|
|
63
|
+
=begin
|
|
64
|
+
Writing into ctx in a Wrap()
|
|
65
|
+
=end
|
|
66
|
+
it { Memo::Create.( { seq: [], rehash_raise: true } )[:exception].must_equal("nope!") }
|
|
67
|
+
|
|
67
68
|
=begin
|
|
68
69
|
When success: return the block's returns
|
|
69
70
|
When raise: return {Railway.fail!}, but wire Wrap() to {fail_fast: true}
|
|
@@ -74,13 +75,9 @@ When raise: return {Railway.fail!}, but wire Wrap() to {fail_fast: true}
|
|
|
74
75
|
class Memo::Create < Trailblazer::Operation
|
|
75
76
|
class HandleUnsafeProcess
|
|
76
77
|
def self.call((ctx), *, &block)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
puts $!
|
|
81
|
-
ctx[:exception] = $!.message
|
|
82
|
-
[ Trailblazer::Operation::Railway.fail!, [ctx, {}] ]
|
|
83
|
-
end
|
|
78
|
+
yield # calls the wrapped steps
|
|
79
|
+
rescue
|
|
80
|
+
[ Trailblazer::Operation::Railway.fail!, [ctx, {}] ]
|
|
84
81
|
end
|
|
85
82
|
end
|
|
86
83
|
|
|
@@ -112,11 +109,9 @@ When raise: return {Railway.fail_fast!} and configure Wrap() to {fast_track: t
|
|
|
112
109
|
#:fail-fast-handler
|
|
113
110
|
class HandleUnsafeProcess
|
|
114
111
|
def self.call((ctx), *, &block)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
[ Trailblazer::Operation::Railway.fail_fast!, [ctx, {}] ]
|
|
119
|
-
end
|
|
112
|
+
yield # calls the wrapped steps
|
|
113
|
+
rescue
|
|
114
|
+
[ Trailblazer::Operation::Railway.fail_fast!, [ctx, {}] ]
|
|
120
115
|
end
|
|
121
116
|
end
|
|
122
117
|
#:fail-fast-handler end
|
|
@@ -145,120 +140,176 @@ When raise: return {Railway.fail_fast!} and configure Wrap() to {fast_track: t
|
|
|
145
140
|
When success: return the block's returns
|
|
146
141
|
When raise: return {Railway.fail!} or {Railway.pass!}
|
|
147
142
|
=end
|
|
148
|
-
class
|
|
149
|
-
Memo
|
|
143
|
+
class WrapWithCustomEndsTest < Minitest::Spec
|
|
144
|
+
Memo = Module.new
|
|
150
145
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
146
|
+
#:custom-handler
|
|
147
|
+
class MyTransaction
|
|
148
|
+
MyFailSignal = Class.new(Trailblazer::Activity::Signal)
|
|
149
|
+
|
|
150
|
+
def self.call((ctx, flow_options), *, &block)
|
|
151
|
+
yield # calls the wrapped steps
|
|
152
|
+
rescue
|
|
153
|
+
MyFailSignal
|
|
159
154
|
end
|
|
160
155
|
end
|
|
156
|
+
#:custom-handler end
|
|
161
157
|
|
|
162
|
-
#:
|
|
163
|
-
class
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
#:custom
|
|
159
|
+
class Memo::Create < Trailblazer::Operation
|
|
160
|
+
step :find_model
|
|
161
|
+
step Wrap( MyTransaction ) {
|
|
162
|
+
step :update
|
|
163
|
+
step :rehash
|
|
164
|
+
},
|
|
165
|
+
Output(:success) => End(:transaction_worked),
|
|
166
|
+
Output(MyTransaction::MyFailSignal, :failure) => End(:transaction_failed)
|
|
167
|
+
step :notify
|
|
168
|
+
fail :log_error
|
|
169
|
+
#~methods
|
|
170
|
+
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
171
|
+
include Rehash
|
|
172
|
+
#~methods end
|
|
173
|
+
end
|
|
174
|
+
#:custom end
|
|
166
175
|
|
|
167
|
-
|
|
176
|
+
it do
|
|
177
|
+
result = Memo::Create.( { seq: [] } )
|
|
178
|
+
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash]] >}
|
|
179
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_worked>}
|
|
180
|
+
end
|
|
168
181
|
|
|
169
|
-
|
|
170
|
-
|
|
182
|
+
it do
|
|
183
|
+
result = Memo::Create.( { seq: [], rehash_raise: true } )
|
|
184
|
+
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash]] >}
|
|
185
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_failed>}
|
|
171
186
|
end
|
|
172
|
-
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
=begin
|
|
190
|
+
When success: return the block's returns
|
|
191
|
+
When raise: return {Railway.pass!} and go "successful"
|
|
192
|
+
=end
|
|
193
|
+
class WrapGoesIntoPassFromRescueTest < Minitest::Spec
|
|
194
|
+
Memo = Module.new
|
|
173
195
|
|
|
174
|
-
#:transaction
|
|
175
196
|
class Memo::Create < Trailblazer::Operation
|
|
197
|
+
class HandleUnsafeProcess
|
|
198
|
+
def self.call((ctx), *, &block)
|
|
199
|
+
yield # calls the wrapped steps
|
|
200
|
+
rescue
|
|
201
|
+
[ Trailblazer::Operation::Railway.pass!, [ctx, {}] ]
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
|
|
176
205
|
step :find_model
|
|
177
|
-
step Wrap(
|
|
206
|
+
step Wrap( HandleUnsafeProcess ) {
|
|
178
207
|
step :update
|
|
179
208
|
step :rehash
|
|
180
209
|
}
|
|
181
210
|
step :notify
|
|
182
211
|
fail :log_error
|
|
212
|
+
|
|
183
213
|
#~methods
|
|
184
214
|
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
185
215
|
include Rehash
|
|
186
216
|
#~methods end
|
|
187
217
|
end
|
|
188
|
-
#:transaction end
|
|
189
218
|
|
|
190
219
|
it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
|
|
191
|
-
it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:
|
|
220
|
+
it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
|
|
192
221
|
end
|
|
193
222
|
|
|
194
223
|
=begin
|
|
195
224
|
When success: return the block's returns
|
|
196
|
-
When raise: return {
|
|
225
|
+
When raise: return {true} and go "successful"
|
|
226
|
+
You can return boolean true in wrap.
|
|
197
227
|
=end
|
|
198
|
-
class
|
|
199
|
-
Memo
|
|
200
|
-
Sequel = WrapWithTransactionTest::Sequel
|
|
228
|
+
class WrapGoesIntoBooleanTrueFromRescueTest < Minitest::Spec
|
|
229
|
+
Memo = Module.new
|
|
201
230
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
231
|
+
class Memo::Create < Trailblazer::Operation
|
|
232
|
+
class HandleUnsafeProcess
|
|
233
|
+
def self.call((ctx), *, &block)
|
|
234
|
+
yield # calls the wrapped steps
|
|
235
|
+
rescue
|
|
236
|
+
true
|
|
237
|
+
end
|
|
238
|
+
end
|
|
205
239
|
|
|
206
|
-
|
|
207
|
-
|
|
240
|
+
step :find_model
|
|
241
|
+
step Wrap( HandleUnsafeProcess ) {
|
|
242
|
+
step :update
|
|
243
|
+
step :rehash
|
|
244
|
+
}
|
|
245
|
+
step :notify
|
|
246
|
+
fail :log_error
|
|
208
247
|
|
|
209
|
-
|
|
248
|
+
#~methods
|
|
249
|
+
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
250
|
+
include Rehash
|
|
251
|
+
#~methods end
|
|
252
|
+
end
|
|
210
253
|
|
|
211
|
-
|
|
212
|
-
|
|
254
|
+
it "translates true returned form a wrap to a signal with a `success` semantic" do
|
|
255
|
+
result = Memo::Create.( { seq: [], rehash_raise: true } )
|
|
256
|
+
result.inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >}
|
|
257
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
|
|
213
258
|
end
|
|
214
|
-
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
=begin
|
|
262
|
+
When success: return the block's returns
|
|
263
|
+
When raise: return {false} and go "failed"
|
|
264
|
+
You can return boolean false in wrap.
|
|
265
|
+
=end
|
|
266
|
+
class WrapGoesIntoBooleanFalseFromRescueTest < Minitest::Spec
|
|
267
|
+
Memo = Module.new
|
|
215
268
|
|
|
216
|
-
#:custom
|
|
217
269
|
class Memo::Create < Trailblazer::Operation
|
|
270
|
+
class HandleUnsafeProcess
|
|
271
|
+
def self.call((ctx), *, &block)
|
|
272
|
+
yield # calls the wrapped steps
|
|
273
|
+
rescue
|
|
274
|
+
false
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
218
278
|
step :find_model
|
|
219
|
-
step Wrap(
|
|
279
|
+
step Wrap( HandleUnsafeProcess ) {
|
|
220
280
|
step :update
|
|
221
281
|
step :rehash
|
|
222
|
-
}
|
|
223
|
-
Output(:success) => End(:transaction_worked),
|
|
224
|
-
Output(MyTransaction::MyFailSignal, :failure) => End(:transaction_failed)
|
|
282
|
+
}
|
|
225
283
|
step :notify
|
|
226
284
|
fail :log_error
|
|
285
|
+
|
|
227
286
|
#~methods
|
|
228
287
|
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
229
288
|
include Rehash
|
|
230
289
|
#~methods end
|
|
231
290
|
end
|
|
232
|
-
#:custom end
|
|
233
|
-
|
|
234
|
-
it do
|
|
235
|
-
result = Memo::Create.( { seq: [] } )
|
|
236
|
-
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash]] >}
|
|
237
|
-
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_worked>}
|
|
238
|
-
end
|
|
239
291
|
|
|
240
|
-
it do
|
|
292
|
+
it "translates false returned form a wrap to a signal with a `failure` semantic" do
|
|
241
293
|
result = Memo::Create.( { seq: [], rehash_raise: true } )
|
|
242
|
-
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash]] >}
|
|
243
|
-
result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:
|
|
294
|
+
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error]] >}
|
|
295
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
|
|
244
296
|
end
|
|
245
297
|
end
|
|
246
298
|
|
|
247
299
|
=begin
|
|
248
300
|
When success: return the block's returns
|
|
249
|
-
When raise: return {
|
|
301
|
+
When raise: return {nil} and go "failed"
|
|
302
|
+
You can return nil in wrap.
|
|
250
303
|
=end
|
|
251
|
-
class
|
|
304
|
+
class WrapGoesIntoNilFromRescueTest < Minitest::Spec
|
|
252
305
|
Memo = Module.new
|
|
253
306
|
|
|
254
307
|
class Memo::Create < Trailblazer::Operation
|
|
255
308
|
class HandleUnsafeProcess
|
|
256
309
|
def self.call((ctx), *, &block)
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
[ Trailblazer::Operation::Railway.pass!, [ctx, {}] ]
|
|
261
|
-
end
|
|
310
|
+
yield # calls the wrapped steps
|
|
311
|
+
rescue
|
|
312
|
+
nil
|
|
262
313
|
end
|
|
263
314
|
end
|
|
264
315
|
|
|
@@ -276,7 +327,94 @@ When raise: return {Railway.pass!} and go "successful"
|
|
|
276
327
|
#~methods end
|
|
277
328
|
end
|
|
278
329
|
|
|
330
|
+
it "translates nil returned form a wrap to a signal with a `failure` semantic" do
|
|
331
|
+
result = Memo::Create.( { seq: [], rehash_raise: true } )
|
|
332
|
+
result.inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error]] >}
|
|
333
|
+
result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
=begin
|
|
338
|
+
When success: return the block's returns
|
|
339
|
+
When raise: return {Railway.fail!}
|
|
340
|
+
This one is mostly to show how one could wrap steps in a transaction
|
|
341
|
+
=end
|
|
342
|
+
class WrapWithTransactionTest < Minitest::Spec
|
|
343
|
+
Memo = Module.new
|
|
344
|
+
|
|
345
|
+
module Sequel
|
|
346
|
+
def self.transaction
|
|
347
|
+
end_event, (ctx, flow_options) = yield
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
#:transaction-handler
|
|
352
|
+
class MyTransaction
|
|
353
|
+
def self.call((ctx, flow_options), *, &block)
|
|
354
|
+
Sequel.transaction { yield } # calls the wrapped steps
|
|
355
|
+
rescue
|
|
356
|
+
[ Trailblazer::Operation::Railway.fail!, [ctx, flow_options] ]
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
#:transaction-handler end
|
|
360
|
+
|
|
361
|
+
#:transaction
|
|
362
|
+
class Memo::Create < Trailblazer::Operation
|
|
363
|
+
step :find_model
|
|
364
|
+
step Wrap( MyTransaction ) {
|
|
365
|
+
step :update
|
|
366
|
+
step :rehash
|
|
367
|
+
}
|
|
368
|
+
step :notify
|
|
369
|
+
fail :log_error
|
|
370
|
+
#~methods
|
|
371
|
+
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
372
|
+
include Rehash
|
|
373
|
+
#~methods end
|
|
374
|
+
end
|
|
375
|
+
#:transaction end
|
|
376
|
+
|
|
279
377
|
it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
|
|
280
|
-
it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:
|
|
378
|
+
it { Memo::Create.( { seq: [], rehash_raise: true } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error]] >} }
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
=begin
|
|
382
|
+
When success: return {Railway.pass_fast!}
|
|
383
|
+
When failure: return {Railway.fail!}
|
|
384
|
+
This one is mostly to show how one could evaluate Wrap()'s return value based on Wrap() block's return
|
|
385
|
+
=end
|
|
386
|
+
class WrapWithBlockReturnSignatureCheckTest < Minitest::Spec
|
|
387
|
+
Memo = Module.new
|
|
388
|
+
|
|
389
|
+
#:handler-with-signature-evaluator
|
|
390
|
+
class HandleUnsafeProcess
|
|
391
|
+
def self.call((_ctx, _flow_options), *, &block)
|
|
392
|
+
signal, (ctx, flow_options) = yield
|
|
393
|
+
evaluated_signal = if signal.to_h[:semantic] == :success
|
|
394
|
+
Trailblazer::Operation::Railway.pass_fast!
|
|
395
|
+
else
|
|
396
|
+
Trailblazer::Operation::Railway.fail!
|
|
397
|
+
end
|
|
398
|
+
[ evaluated_signal, [ctx, flow_options] ]
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
#:handler-with-signature-evaluator end
|
|
402
|
+
|
|
403
|
+
#:transaction
|
|
404
|
+
class Memo::Create < Trailblazer::Operation
|
|
405
|
+
step :find_model
|
|
406
|
+
step Wrap( HandleUnsafeProcess ) {
|
|
407
|
+
step :update
|
|
408
|
+
}, fast_track: true # because Wrap can return pass_fast! now
|
|
409
|
+
step :notify
|
|
410
|
+
fail :log_error
|
|
411
|
+
#~methods
|
|
412
|
+
include T.def_steps(:find_model, :update, :notify, :log_error)
|
|
413
|
+
#~methods end
|
|
414
|
+
end
|
|
415
|
+
#:transaction end
|
|
416
|
+
|
|
417
|
+
it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update]] >} }
|
|
418
|
+
it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update, :log_error]] >} }
|
|
281
419
|
end
|
|
282
420
|
end
|
|
@@ -19,11 +19,8 @@ class ModelTest < Minitest::Spec
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
# :new new.
|
|
22
|
-
it
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
result = Create.(params: {})
|
|
26
|
-
|
|
22
|
+
it "initializes new model's instance" do
|
|
23
|
+
result = Create.()
|
|
27
24
|
result[:model].inspect.must_equal %{#<struct ModelTest::Song id=nil, title=nil>}
|
|
28
25
|
end
|
|
29
26
|
|
|
@@ -48,7 +45,7 @@ class ModelTest < Minitest::Spec
|
|
|
48
45
|
step Trailblazer::Operation::Model Song, :find_by
|
|
49
46
|
step :process
|
|
50
47
|
|
|
51
|
-
def process(options, **); options[
|
|
48
|
+
def process(options, **); options[:x] = true end
|
|
52
49
|
end
|
|
53
50
|
|
|
54
51
|
# :find_by, exceptionless.
|
|
@@ -57,36 +54,36 @@ class ModelTest < Minitest::Spec
|
|
|
57
54
|
step Trailblazer::Operation::Model( Song, :find_by, :title )
|
|
58
55
|
step :process
|
|
59
56
|
|
|
60
|
-
def process(options, **); options[
|
|
57
|
+
def process(options, **); options[:x] = true end
|
|
61
58
|
end
|
|
62
59
|
|
|
63
60
|
# can't find model.
|
|
64
61
|
#- result object, model
|
|
65
62
|
it do
|
|
66
|
-
Find.(params: {id: nil})["result.model"].failure?.must_equal true
|
|
67
|
-
Find.(params: {id: nil})["x"].must_be_nil
|
|
63
|
+
Find.(params: {id: nil})[:"result.model"].failure?.must_equal true
|
|
64
|
+
Find.(params: {id: nil})[:"x"].must_be_nil
|
|
68
65
|
Find.(params: {id: nil}).failure?.must_equal true
|
|
69
66
|
end
|
|
70
67
|
|
|
71
68
|
#- result object, model
|
|
72
69
|
it do
|
|
73
|
-
Find.(params: {id: 9})["result.model"].success?.must_equal true
|
|
74
|
-
Find.(params: {id: 9})["x"].must_equal true
|
|
70
|
+
Find.(params: {id: 9})[:"result.model"].success?.must_equal true
|
|
71
|
+
Find.(params: {id: 9})[:"x"].must_equal true
|
|
75
72
|
Find.(params: {id: 9})[:model].inspect.must_equal %{#<struct ModelTest::Song id=9, title=nil>}
|
|
76
73
|
end
|
|
77
74
|
|
|
78
75
|
# can't find model by title.
|
|
79
76
|
#- result object, model
|
|
80
77
|
it do
|
|
81
|
-
FindByKey.(params: {title: nil})["result.model"].failure?.must_equal true
|
|
82
|
-
FindByKey.(params: {title: nil})["x"].must_be_nil
|
|
78
|
+
FindByKey.(params: {title: nil})[:"result.model"].failure?.must_equal true
|
|
79
|
+
FindByKey.(params: {title: nil})[:"x"].must_be_nil
|
|
83
80
|
FindByKey.(params: {title: nil}).failure?.must_equal true
|
|
84
81
|
end
|
|
85
82
|
|
|
86
83
|
#- result object, model by title
|
|
87
84
|
it do
|
|
88
|
-
FindByKey.(params: {title: "Test"})["result.model"].success?.must_equal true
|
|
89
|
-
FindByKey.(params: {title: "Test"})["x"].must_equal true
|
|
85
|
+
FindByKey.(params: {title: "Test"})[:"result.model"].success?.must_equal true
|
|
86
|
+
FindByKey.(params: {title: "Test"})[:"x"].must_equal true
|
|
90
87
|
FindByKey.(params: {title: "Test"})[:model].inspect.must_equal %{#<struct ModelTest::Song id=2, title="Test">}
|
|
91
88
|
end
|
|
92
89
|
end
|