trailblazer-macro 2.1.15 → 2.1.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,29 +29,29 @@ class DocsPunditProcTest < Minitest::Spec
29
29
  end
30
30
  #:pundit end
31
31
 
32
- it { Trailblazer::Developer.railway(Create).must_equal %{[>model.build,>policy.default.eval]} }
33
- it { Create.(params: {}, current_user: Module).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
34
- it { Create.(params: {} ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
32
+ it { assert_equal Trailblazer::Developer.railway(Create), %{[>model.build,>policy.default.eval]} }
33
+ it { assert_equal Create.(params: {}, current_user: Module).inspect(:model), %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
34
+ it { assert_equal Create.(params: {}).inspect(:model), %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
35
35
 
36
36
  it do
37
37
  #:pundit-result
38
- result = Create.(params: {}, current_user: Module)
39
- result[:"result.policy.default"].success? #=> true
40
- result[:"result.policy.default"][:policy] #=> #<MyPolicy ...>
38
+ result = Create.(params: {}, current_user: Module)
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"][:policy].is_a?(MyPolicy).must_equal true
42
+ assert_equal result[:"result.policy.default"].success?, true
43
+ assert_equal result[:"result.policy.default"][:policy].is_a?(MyPolicy), true
44
44
  end
45
45
 
46
46
  #---
47
47
  #- override
48
48
  class New < Create
49
- step Policy::Pundit( MyPolicy, :new? ), override: true
49
+ step Policy::Pundit( MyPolicy, :new? ), replace: :"policy.default.eval"
50
50
  end
51
51
 
52
- it { Trailblazer::Developer.railway(New).must_equal %{[>model.build,>policy.default.eval]} }
53
- it { New.(params: {}, current_user: Class ).inspect(:model).must_equal %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
54
- it { New.(params: {}, current_user: nil ).inspect(:model).must_equal %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
52
+ it { assert_equal Trailblazer::Developer.railway(New), %{[>model.build,>policy.default.eval]} }
53
+ it { assert_equal New.(params: {}, current_user: Class ).inspect(:model), %{<Result:true [#<struct DocsPunditProcTest::Song id=nil>] >} }
54
+ it { assert_equal New.(params: {}, current_user: nil ).inspect(:model), %{<Result:false [#<struct DocsPunditProcTest::Song id=nil>] >} }
55
55
 
56
56
  #---
57
57
  #- override with :name
@@ -64,10 +64,10 @@ class DocsPunditProcTest < Minitest::Spec
64
64
  step Policy::Pundit( MyPolicy, :new?, name: "first" ), override: true
65
65
  end
66
66
 
67
- it { Trailblazer::Developer.railway(Edit).must_equal %{[>policy.first.eval,>policy.second.eval]} }
68
- it { Edit.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:false [nil] >} }
69
- it { Trailblazer::Developer.railway(Update).must_equal %{[>policy.first.eval,>policy.second.eval]} }
70
- it { Update.(params: {}, current_user: Class).inspect(:model).must_equal %{<Result:true [nil] >} }
67
+ it { assert_equal Trailblazer::Developer.railway(Edit), %{[>policy.first.eval,>policy.second.eval]} }
68
+ it { assert_equal Edit.(params: {}, current_user: Class).inspect(:model), %{<Result:false [nil] >} }
69
+ it { assert_equal Trailblazer::Developer.railway(Update), %{[>policy.first.eval,>policy.second.eval]} }
70
+ it { assert_equal Update.(params: {}, current_user: Class).inspect(:model), %{<Result:true [nil] >} }
71
71
 
72
72
  #---
73
73
  # dependency injection
@@ -85,7 +85,7 @@ class DocsPunditProcTest < Minitest::Spec
85
85
  :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit.build(AnotherPolicy, :create?)
86
86
  )
87
87
  #:di-call end
88
- result.inspect("").must_equal %{<Result:true [nil] >} }
88
+ assert_equal result.inspect(""), %{<Result:true [nil] >} }
89
89
  end
90
90
 
91
91
  #-
@@ -106,7 +106,7 @@ class PunditWithNameTest < Minitest::Spec
106
106
  result = Create.(params: {}, current_user: Module)
107
107
  result[:"result.policy.after_model"].success? #=> true
108
108
  #:name-call end
109
- result[:"result.policy.after_model"].success?.must_equal true }
109
+ assert_equal result[:"result.policy.after_model"].success?, true }
110
110
  end
111
111
 
112
112
  #---
@@ -123,7 +123,7 @@ end
123
123
  # #:class-level end
124
124
 
125
125
  # it { Create.(); Create["result.policy"].must_be_nil }
126
- # it { Create.(params: {}, current_user: Module)["x"].must_equal true }
126
+ # it { Create.(params: {}, current_user: Module)["x"], true }
127
127
  # it { Create.(params: {} )["x"].must_be_nil }
128
128
  # end
129
129
 
@@ -23,18 +23,18 @@ 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\/.{1,3},>nested/ } # FIXME: better introspect tests for all id-generating macros.
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
- 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
- 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] >} }
26
+ it { assert_match /\[>Rescue\/.{1,3},>nested/, Trailblazer::Developer.railway(NestedInsanity) } # FIXME: better introspect tests for all id-generating macros.
27
+ it { assert_equal NestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
28
+ it { assert_equal NestedInsanity.( "raise-y" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, nil, nil, nil, nil, true, true] >} }
29
+ it { assert_equal NestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
30
30
 
31
31
  #-
32
32
  # inheritance
33
33
  class UbernestedInsanity < NestedInsanity
34
34
  end
35
35
 
36
- it { UbernestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err").must_equal %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
37
- it { UbernestedInsanity.( "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] >} }
36
+ it { assert_equal UbernestedInsanity.().inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:true [true, true, true, true, true, true, nil, nil] >} }
37
+ it { assert_equal UbernestedInsanity.( "raise-a" => true).inspect("a", "y", "z", "b", "c", "e", "inner-err", "outer-err"), %{<Result:false [true, true, true, true, nil, nil, nil, true] >} }
38
38
  end
39
39
 
40
40
  class RescueTest < Minitest::Spec
@@ -130,8 +130,8 @@ Rescue( SPECIFIC_EXCEPTION, handler: X )
130
130
  include Rehash
131
131
  end
132
132
 
133
- it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
134
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
133
+ it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class), %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
134
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class), %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
135
135
  end
136
136
 
137
137
  =begin
@@ -160,8 +160,8 @@ Rescue( handler: :instance_method )
160
160
  end
161
161
  #:rescue-method end
162
162
 
163
- it { Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
164
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class).must_equal %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
163
+ it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq, :exception_class), %{<Result:true [[:find_model, :update, :rehash, :notify], nil] >} }
164
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq, :exception_class), %{<Result:false [[:find_model, :update, :rehash, :log_error], RuntimeError] >} }
165
165
  end
166
166
 
167
167
  =begin
@@ -185,8 +185,8 @@ Rescue(), fast_track: true {}
185
185
  include T.def_steps(:find_model, :update, :notify, :log_error, :rehash)
186
186
  end
187
187
 
188
- it { Memo::Create.( { seq: [], } ).inspect(:seq).must_equal %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
189
- it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:find_model, :update]] >} }
188
+ it { assert_equal Memo::Create.( { seq: [], } ).inspect(:seq), %{<Result:true [[:find_model, :update, :rehash, :notify]] >} }
189
+ it { assert_equal Memo::Create.( { seq: [], update: false } ).inspect(:seq), %{<Result:false [[:find_model, :update]] >} }
190
190
  end
191
191
 
192
192
  class RescueIDTest < Minitest::Spec
@@ -212,13 +212,13 @@ Rescue(), fast_track: true {}
212
212
  # assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each-1"])[0].id, "Each-1"
213
213
  # assert_equal Trailblazer::Developer::Introspect.find_path(activity, ["Each/composers_for_each"])[0].id, "Each/composers_for_each"
214
214
 
215
- assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[1].id
216
- assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[2].id
217
- assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[3].id
218
- assert_match "Rescue-1", Trailblazer::Activity::Introspect::Nodes(activity).values[4].id
219
- assert_match "Rescue-2", Trailblazer::Activity::Introspect::Nodes(activity).values[5].id
220
- assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[6].id
221
- assert_match /Rescue\/\d+/, Trailblazer::Activity::Introspect::Nodes(activity).values[7].id
215
+ assert_match (/Rescue\/\d+/), Trailblazer::Activity::Introspect::Nodes(activity).values[1].id
216
+ assert_match (/Rescue\/\d+/), Trailblazer::Activity::Introspect::Nodes(activity).values[2].id
217
+ assert_match (/Rescue\/\d+/), Trailblazer::Activity::Introspect::Nodes(activity).values[3].id
218
+ assert_equal "Rescue-1", Trailblazer::Activity::Introspect::Nodes(activity).values[4].id
219
+ assert_equal "Rescue-2", Trailblazer::Activity::Introspect::Nodes(activity).values[5].id
220
+ assert_match (/Rescue\/\d+/), Trailblazer::Activity::Introspect::Nodes(activity).values[6].id
221
+ assert_match (/Rescue\/\d+/), Trailblazer::Activity::Introspect::Nodes(activity).values[7].id
222
222
  end
223
223
  end
224
224
 
@@ -239,6 +239,7 @@ Rescue(), fast_track: true {}
239
239
  ctx = {validate: false}
240
240
 
241
241
  output, _ = trace activity, ctx
242
+
242
243
  assert_equal output, %(TOP
243
244
  |-- Start.default
244
245
  |-- Rescue/1
@@ -204,8 +204,8 @@ When raise: return {Railway.fail!}, but wire Wrap() to {fail_fast: true}
204
204
  #~methods end
205
205
  end
206
206
 
207
- it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
208
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
207
+ it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} }
208
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} }
209
209
  end
210
210
 
211
211
  =begin
@@ -241,8 +241,8 @@ When raise: return {Railway.fail_fast!} and configure Wrap() to {fast_track: t
241
241
  end
242
242
  #:fail-fast end
243
243
 
244
- it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
245
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >} }
244
+ it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} }
245
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >} }
246
246
  end
247
247
 
248
248
  =begin
@@ -284,14 +284,16 @@ When raise: return {Railway.fail!} or {Railway.pass!}
284
284
 
285
285
  it do
286
286
  result = Memo::Create.( { seq: [] } )
287
- result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >}
288
- result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_worked>}
287
+
288
+ assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >}
289
+ assert_equal result.event.inspect, %{#<Trailblazer::Activity::End semantic=:transaction_worked>}
289
290
  end
290
291
 
291
292
  it do
292
293
  result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
293
- result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash]] >}
294
- result.event.inspect.must_equal %{#<Trailblazer::Activity::End semantic=:transaction_failed>}
294
+
295
+ assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash]] >}
296
+ assert_equal result.event.inspect, %{#<Trailblazer::Activity::End semantic=:transaction_failed>}
295
297
  end
296
298
  end
297
299
 
@@ -325,8 +327,8 @@ When raise: return {Railway.pass!} and go "successful"
325
327
  #~methods end
326
328
  end
327
329
 
328
- it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
329
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
330
+ it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} }
331
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} }
330
332
  end
331
333
 
332
334
  =begin
@@ -362,8 +364,9 @@ You can return boolean true in wrap.
362
364
 
363
365
  it "translates true returned form a wrap to a signal with a `success` semantic" do
364
366
  result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
365
- result.inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >}
366
- result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
367
+
368
+ assert_equal result.inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >}
369
+ assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Success semantic=:success>}
367
370
  end
368
371
  end
369
372
 
@@ -400,8 +403,9 @@ You can return boolean false in wrap.
400
403
 
401
404
  it "translates false returned form a wrap to a signal with a `failure` semantic" do
402
405
  result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
403
- result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >}
404
- result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
406
+
407
+ assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >}
408
+ assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
405
409
  end
406
410
  end
407
411
 
@@ -438,8 +442,9 @@ You can return nil in wrap.
438
442
 
439
443
  it "translates nil returned form a wrap to a signal with a `failure` semantic" do
440
444
  result = Memo::Create.( { seq: [], rehash_raise: RuntimeError } )
441
- result.inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >}
442
- result.event.inspect.must_equal %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
445
+
446
+ assert_equal result.inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >}
447
+ assert_equal result.event.inspect, %{#<Trailblazer::Activity::Railway::End::Failure semantic=:failure>}
443
448
  end
444
449
  end
445
450
 
@@ -453,7 +458,7 @@ This one is mostly to show how one could wrap steps in a transaction
453
458
 
454
459
  module Sequel
455
460
  def self.transaction
456
- end_event, (ctx, flow_options) = yield
461
+ _end_event, (_ctx, _flow_options) = yield
457
462
  end
458
463
  end
459
464
 
@@ -483,8 +488,8 @@ This one is mostly to show how one could wrap steps in a transaction
483
488
  end
484
489
  #:transaction end
485
490
 
486
- it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update, :rehash, :notify]] >} }
487
- it { Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :rehash, :log_error]] >} }
491
+ it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update, :rehash, :notify]] >} }
492
+ it { assert_equal Memo::Create.( { seq: [], rehash_raise: RuntimeError } ).inspect(:seq), %{<Result:false [[:model, :update, :rehash, :log_error]] >} }
488
493
  end
489
494
 
490
495
  =begin
@@ -523,8 +528,8 @@ This one is mostly to show how one could evaluate Wrap()'s return value based on
523
528
  end
524
529
  #:transaction end
525
530
 
526
- it { Memo::Create.( { seq: [] } ).inspect(:seq).must_equal %{<Result:true [[:model, :update]] >} }
527
- it { Memo::Create.( { seq: [], update: false } ).inspect(:seq).must_equal %{<Result:false [[:model, :update, :log_error]] >} }
531
+ it { assert_equal Memo::Create.( { seq: [] } ).inspect(:seq), %{<Result:true [[:model, :update]] >} }
532
+ it { assert_equal Memo::Create.( { seq: [], update: false } ).inspect(:seq), %{<Result:false [[:model, :update, :log_error]] >} }
528
533
  end
529
534
 
530
535
 
@@ -661,6 +666,19 @@ class WrapUnitTest < Minitest::Spec
661
666
 
662
667
  #@ the patched version only runs {mock_validation}.
663
668
  assert_invoke patched_activity, seq: %{[:mock_validation]}
669
+
670
+ # Patch Wrap/Subprocess/step, put step after {validate}
671
+ patched_activity = Trailblazer::Activity::DSL::Linear::Patch.call(
672
+ activity,
673
+ ["Wrap/WrapUnitTest::HandleUnsafeProcess", :validation],
674
+ -> { step mock_validation }
675
+ )
676
+
677
+ #@ the original activity with Wrap is unchanged.
678
+ assert_invoke activity, seq: %{[:validate]}
679
+
680
+ #@ the patched version only runs {mock_validation}.
681
+ assert_invoke patched_activity, seq: %{[:validate, :mock_validation]}
664
682
  end
665
683
  end
666
684
 
@@ -30,12 +30,12 @@ class IntegrationTest < Minitest::Spec
30
30
  end
31
31
 
32
32
  class SongSpecialCreate < Trailblazer::Operation
33
- step Nested(ArtistCreate)
34
- step Nested(SongCreate)
33
+ step Subprocess(ArtistCreate)
34
+ step Subprocess(SongCreate)
35
35
  end
36
36
 
37
37
  it "create Artist and Song" do
38
- result = SongSpecialCreate.trace(
38
+ result = SongSpecialCreate.wtf?(
39
39
  params: {
40
40
  artist: {
41
41
  name: "My Artist"
@@ -46,10 +46,8 @@ class IntegrationTest < Minitest::Spec
46
46
  }
47
47
  )
48
48
 
49
- puts result.wtf?
50
-
51
49
  # this should return song
52
- result[:model].name.must_match "My Song"
53
- result[:model].artist_name.must_match "My Artist"
50
+ assert_equal result[:model].name, "My Song"
51
+ assert_equal result[:model].artist_name, "My Artist"
54
52
  end
55
53
  end
@@ -27,23 +27,24 @@ class PolicyTest < Minitest::Spec
27
27
  # successful.
28
28
  it do
29
29
  result = Create.(params: {}, current_user: Module)
30
- result[:process].must_equal true
30
+
31
+ assert_equal result[:process], true
31
32
  #- result object, policy
32
- result[:"result.policy.default"].success?.must_equal true
33
- result[:"result.policy.default"][:message].must_be_nil
33
+ assert_equal result[:"result.policy.default"].success?, true
34
+ assert_nil result[:"result.policy.default"][:message]
34
35
  # result[:valid].must_be_nil
35
- result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:nil>}
36
+ assert_equal result[:"policy.default"].inspect, %{<Auth: user:Module, model:nil>}
36
37
  end
37
38
  # breach.
38
39
  it do
39
40
  result = Create.(params: {}, current_user: nil)
40
- result[:process].must_be_nil
41
+ assert_nil result[:process]
41
42
  #- result object, policy
42
- result[:"result.policy.default"].success?.must_equal false
43
- result[:"result.policy.default"][:message].must_equal "Breach"
43
+ assert_equal result[:"result.policy.default"].success?, false
44
+ assert_equal result[:"result.policy.default"][:message], "Breach"
44
45
  end
45
- # inject different policy.Condition it { Create.(params: {}, current_user: Object, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))["process"].must_equal true }
46
- it { Create.(params: {}, current_user: Module, :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))[:process].must_be_nil }
46
+ # inject different policy.Condition it { Create.(params: {}, current_user: Object, "policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))["process"], true }
47
+ it { assert_nil Create.(params: {}, current_user: Module, :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_object?))[:process] }
47
48
 
48
49
 
49
50
  #---
@@ -52,23 +53,25 @@ class PolicyTest < Minitest::Spec
52
53
  step Model( Song, :new ), before: :"policy.default.eval"
53
54
  end
54
55
 
55
- it { Trailblazer::Developer.railway(Show).must_equal %{[>model.build,>policy.default.eval,>process]} }
56
+ it { assert_equal Trailblazer::Developer.railway(Show), %{[>model.build,>policy.default.eval,>process]} }
56
57
 
57
58
  # invalid because user AND model.
58
59
  it do
59
60
  result = Show.(params: {}, current_user: Module)
60
- result[:process].must_be_nil
61
- result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
62
- # result["policy"].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
61
+ assert_nil result[:process]
62
+
63
+ assert_equal result[:model].inspect, %{#<struct PolicyTest::Song id=nil>}
64
+ # result["policy"].inspect, %{#<struct PolicyTest::Song id=nil>}
63
65
  end
64
66
 
65
67
  # valid because new policy.
66
68
  it do
67
69
  # puts Show["pipetree"].inspect
68
70
  result = Show.(params: {}, current_user: Module, :"policy.default.eval" => Trailblazer::Operation::Policy::Pundit::Condition.new(Auth, :user_and_model?))
69
- result[:process].must_equal true
70
- result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=nil>}
71
- result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=nil>>}
71
+
72
+ assert_equal result[:process], true
73
+ assert_equal result[:model].inspect, %{#<struct PolicyTest::Song id=nil>}
74
+ assert_equal result[:"policy.default"].inspect, %{<Auth: user:Module, model:#<struct PolicyTest::Song id=nil>>}
72
75
  end
73
76
 
74
77
  ##--
@@ -86,20 +89,23 @@ class PolicyTest < Minitest::Spec
86
89
  # successful.
87
90
  it do
88
91
  result = Edit.(params: { id: 1 }, current_user: Module)
89
- result[:process].must_equal true
90
- result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=1>}
91
- result[:"result.policy.default"].success?.must_equal true
92
- result[:"result.policy.default"][:message].must_be_nil
92
+
93
+ assert_equal result[:process], true
94
+ assert_equal result[:model].inspect, %{#<struct PolicyTest::Song id=1>}
95
+ assert_equal result[:"result.policy.default"].success?, true
96
+ assert_nil result[:"result.policy.default"][:message]
93
97
  # result[:valid].must_be_nil
94
- result[:"policy.default"].inspect.must_equal %{<Auth: user:Module, model:#<struct PolicyTest::Song id=1>>}
98
+ assert_equal result[:"policy.default"].inspect, %{<Auth: user:Module, model:#<struct PolicyTest::Song id=1>>}
95
99
  end
96
100
 
97
101
  # breach.
98
102
  it do
99
103
  result = Edit.(params: { id: 4 }, current_user: nil)
100
- result[:model].inspect.must_equal %{#<struct PolicyTest::Song id=4>}
101
- result[:process].must_be_nil
102
- result[:"result.policy.default"].success?.must_equal false
103
- result[:"result.policy.default"][:message].must_equal "Breach"
104
+
105
+ assert_equal result[:model].inspect, %{#<struct PolicyTest::Song id=4>}
106
+ assert_nil result[:process]
107
+
108
+ assert_equal result[:"result.policy.default"].success?, false
109
+ assert_equal result[:"result.policy.default"][:message], "Breach"
104
110
  end
105
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trailblazer-macro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.15
4
+ version: 2.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-14 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -111,6 +111,7 @@ files:
111
111
  - lib/trailblazer/macro/each.rb
112
112
  - lib/trailblazer/macro/guard.rb
113
113
  - lib/trailblazer/macro/model.rb
114
+ - lib/trailblazer/macro/model/find.rb
114
115
  - lib/trailblazer/macro/nested.rb
115
116
  - lib/trailblazer/macro/policy.rb
116
117
  - lib/trailblazer/macro/pundit.rb
@@ -123,6 +124,7 @@ files:
123
124
  - test/docs/each_test.rb
124
125
  - test/docs/guard_test.rb
125
126
  - test/docs/macro_test.rb
127
+ - test/docs/model/find_test.rb
126
128
  - test/docs/model_test.rb
127
129
  - test/docs/nested_static_test.rb
128
130
  - test/docs/pundit_test.rb
@@ -161,6 +163,7 @@ test_files:
161
163
  - test/docs/each_test.rb
162
164
  - test/docs/guard_test.rb
163
165
  - test/docs/macro_test.rb
166
+ - test/docs/model/find_test.rb
164
167
  - test/docs/model_test.rb
165
168
  - test/docs/nested_static_test.rb
166
169
  - test/docs/pundit_test.rb