trailblazer-operation 0.4.1 → 0.5.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 +2 -14
- data/Gemfile +4 -2
- data/README.md +13 -2
- data/Rakefile +2 -2
- data/lib/trailblazer/operation.rb +53 -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/inspect.rb +17 -27
- data/lib/trailblazer/operation/public_call.rb +16 -18
- 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 +5 -8
- data/lib/trailblazer/operation/version.rb +4 -2
- data/test/benchmark/skill_resolver_benchmark.rb +8 -9
- data/test/call_test.rb +56 -30
- 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 +98 -53
- 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/inspect_test.rb +6 -7
- 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 +47 -42
- data/test/test_helper.rb +6 -13
- data/test/trace_test.rb +26 -26
- data/test/wiring/defaults_test.rb +29 -33
- data/trailblazer-operation.gemspec +7 -6
- metadata +26 -18
- data/lib/trailblazer/operation/heritage.rb +0 -30
- data/lib/trailblazer/operation/inject.rb +0 -36
- 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/macro_test.rb +0 -60
- data/test/task_wrap_test.rb +0 -97
data/test/dry_container_test.rb
CHANGED
@@ -9,6 +9,7 @@ class DryContainerTest < Minitest::Spec
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class Create < Trailblazer::Operation
|
12
|
+
extend Trailblazer::Operation::Container
|
12
13
|
end
|
13
14
|
|
14
15
|
it "allows 2.2 call style" do
|
@@ -18,7 +19,7 @@ class DryContainerTest < Minitest::Spec
|
|
18
19
|
it { Create.({}, {}, my_container)["user_repository"].must_equal Object }
|
19
20
|
it { Create.({}, {}, my_container)["contract.create"].must_equal Array }
|
20
21
|
# also allows our own options PLUS containers.
|
21
|
-
it { Create.({}, {
|
22
|
-
it { Create.({}, {
|
23
|
-
it { Create.({}, {
|
22
|
+
it { Create.({}, {"model" => String}, my_container)["model"].must_equal String }
|
23
|
+
it { Create.({}, {"model" => String}, my_container)["user_repository"].must_equal Object }
|
24
|
+
it { Create.({}, {"user_repository" => Integer}, my_container)["user_repository"].must_equal Integer }
|
24
25
|
end
|
data/test/fast_track_test.rb
CHANGED
@@ -1,42 +1,25 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class FastTrackTest < Minitest::Spec
|
4
|
-
# #failure fails fast.
|
5
|
-
# class Create < Trailblazer::Operation
|
6
|
-
# step ->(options, *) { options["x"] = options["dont_fail"] }
|
7
|
-
# failure ->(options, *) { options["a"] = true; options["fail_fast"] }, fail_fast: true
|
8
|
-
# failure ->(options, *) { options["b"] = true }
|
9
|
-
# step ->(options, *) { options["y"] = true }
|
10
|
-
# end
|
11
|
-
|
12
|
-
# puts Create["pipetree"].inspect
|
13
|
-
|
14
|
-
# require "trailblazer/diagram/bpmn"
|
15
|
-
# puts Trailblazer::Diagram::BPMN.to_xml(Create["pipetree"])
|
16
|
-
|
17
|
-
# it { Create.("fail_fast" => true, "dont_fail" => true ).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, nil, nil, true] >} }
|
18
|
-
# it { Create.("fail_fast" => true ).inspect("x", "a", "b", "y").must_equal %{<Result:false [nil, true, nil, nil] >} }
|
19
|
-
# it { Create.("fail_fast" => false ).inspect("x", "a", "b", "y").must_equal %{<Result:false [nil, true, nil, nil] >} }
|
20
|
-
|
21
4
|
# #success passes fast.
|
22
5
|
class Retrieve < Trailblazer::Operation
|
23
6
|
pass ->(options, **) { options["x"] = options["dont_fail"] }, pass_fast: true
|
24
7
|
fail ->(options, **) { options["b"] = true }
|
25
8
|
step ->(options, **) { options["y"] = true }
|
26
9
|
end
|
27
|
-
it { Retrieve.("dont_fail" => true
|
28
|
-
it { Retrieve.("dont_fail" => false
|
10
|
+
it { Retrieve.("dont_fail" => true).inspect("x", "b", "y").must_equal %{<Result:true [true, nil, nil] >} }
|
11
|
+
it { Retrieve.("dont_fail" => false).inspect("x", "b", "y").must_equal %{<Result:true [false, nil, nil] >} }
|
29
12
|
|
30
13
|
# #step fails fast if option set and returns false.
|
31
14
|
class Update < Trailblazer::Operation
|
32
15
|
step ->(options, *) { options["x"] = true }
|
33
16
|
step ->(options, *) { options["a"] = options["dont_fail"] }, fail_fast: true # only on false.
|
34
|
-
|
17
|
+
fail ->(options, *) { options["b"] = true }
|
35
18
|
step ->(options, *) { options["y"] = true }
|
36
19
|
end
|
37
20
|
|
38
21
|
it { Update.("dont_fail" => true).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, true, nil, true] >} }
|
39
|
-
it { Update.({}
|
22
|
+
it { Update.({}).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, nil, nil] >} }
|
40
23
|
|
41
24
|
# #step passes fast if option set and returns true.
|
42
25
|
class Delete < Trailblazer::Operation
|
@@ -47,14 +30,14 @@ class FastTrackTest < Minitest::Spec
|
|
47
30
|
end
|
48
31
|
|
49
32
|
it { Delete.("dont_fail" => true).inspect("x", "a", "b", "y").must_equal %{<Result:true [true, true, nil, nil] >} }
|
50
|
-
it { Delete.({}
|
33
|
+
it { Delete.({}).inspect("x", "a", "b", "y").must_equal %{<Result:false [true, nil, true, nil] >} }
|
51
34
|
end
|
52
35
|
|
53
36
|
class FailBangTest < Minitest::Spec
|
54
37
|
class Create < Trailblazer::Operation
|
55
38
|
step ->(options, *) { options["x"] = true; Railway.fail! }
|
56
39
|
step ->(options, *) { options["y"] = true }
|
57
|
-
|
40
|
+
fail ->(options, *) { options["a"] = true }
|
58
41
|
end
|
59
42
|
|
60
43
|
it { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, true] >} }
|
@@ -64,7 +47,7 @@ class PassBangTest < Minitest::Spec
|
|
64
47
|
class Create < Trailblazer::Operation
|
65
48
|
step ->(options, *) { options["x"] = true; Railway.pass! }
|
66
49
|
step ->(options, *) { options["y"] = true }
|
67
|
-
|
50
|
+
fail ->(options, *) { options["a"] = true }
|
68
51
|
end
|
69
52
|
|
70
53
|
it { Create.().inspect("x", "y", "a").must_equal %{<Result:true [true, true, nil] >} }
|
@@ -74,16 +57,16 @@ class FailFastBangTest < Minitest::Spec
|
|
74
57
|
class Create < Trailblazer::Operation
|
75
58
|
step ->(options, *) { options["x"] = true; Railway.fail_fast! }
|
76
59
|
step ->(options, *) { options["y"] = true }
|
77
|
-
|
60
|
+
fail ->(options, *) { options["a"] = true }
|
78
61
|
end
|
79
62
|
|
80
63
|
# without proper configuration, emitting a FastTrack signal is illegal.
|
81
|
-
it { assert_raises(Trailblazer::Circuit::IllegalSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
|
64
|
+
it { assert_raises(Trailblazer::Activity::Circuit::IllegalSignalError) { Create.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} } }
|
82
65
|
|
83
66
|
class Update < Trailblazer::Operation
|
84
67
|
step ->(options, *) { options["x"] = true; Railway.fail_fast! }, fast_track: true
|
85
68
|
step ->(options, *) { options["y"] = true }
|
86
|
-
|
69
|
+
fail ->(options, *) { options["a"] = true }
|
87
70
|
end
|
88
71
|
|
89
72
|
it { Update.().inspect("x", "y", "a").must_equal %{<Result:false [true, nil, nil] >} }
|
@@ -93,7 +76,7 @@ class PassFastBangTest < Minitest::Spec
|
|
93
76
|
class Create < Trailblazer::Operation
|
94
77
|
step ->(options, *) { options["x"] = true; Railway.pass_fast! }, fast_track: true
|
95
78
|
step ->(options, *) { options["y"] = true }
|
96
|
-
|
79
|
+
fail ->(options, *) { options["a"] = true }
|
97
80
|
end
|
98
81
|
|
99
82
|
it { Create.().inspect("x", "y", "a").must_equal %{<Result:true [true, nil, nil] >} }
|
@@ -103,7 +86,7 @@ end
|
|
103
86
|
class NestedFastTrackTest < Minitest::Spec
|
104
87
|
#- The ::step DSL method automatically connects the nested's End.fail_fast/End.pass_fast to Update's End.fail_fast/End.pass_fast.
|
105
88
|
#
|
106
|
-
# Edit has fast-tracked steps, so it has outputs :success/:
|
89
|
+
# Edit has fast-tracked steps, so it has outputs :success/:fail/:pass_fast/:fail_fast.
|
107
90
|
class Edit < Trailblazer::Operation
|
108
91
|
step :a, fast_track: true # task is connected to End.pass_fast and End.fail_fast.
|
109
92
|
|
@@ -115,7 +98,7 @@ class NestedFastTrackTest < Minitest::Spec
|
|
115
98
|
|
116
99
|
module Steps
|
117
100
|
def b(options, a:, **)
|
118
|
-
options["b"] = a+1
|
101
|
+
options["b"] = a + 1
|
119
102
|
end
|
120
103
|
|
121
104
|
def f(options, **)
|
@@ -126,9 +109,7 @@ class NestedFastTrackTest < Minitest::Spec
|
|
126
109
|
describe "Nested, fast_track: true and all its outputs given" do
|
127
110
|
let(:update) do
|
128
111
|
Class.new(Trailblazer::Operation) do
|
129
|
-
step
|
130
|
-
outputs: Edit.outputs ,
|
131
|
-
fast_track: true
|
112
|
+
step Subprocess(Edit), fast_track: true
|
132
113
|
step :b
|
133
114
|
fail :f
|
134
115
|
|
@@ -138,7 +119,7 @@ class NestedFastTrackTest < Minitest::Spec
|
|
138
119
|
|
139
120
|
# Edit returns End.success
|
140
121
|
it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
|
141
|
-
# Edit returns End.
|
122
|
+
# Edit returns End.fail
|
142
123
|
it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
|
143
124
|
# Edit returns End.pass_fast
|
144
125
|
it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, nil, nil] >} }
|
@@ -151,8 +132,7 @@ class NestedFastTrackTest < Minitest::Spec
|
|
151
132
|
Class.new(Trailblazer::Operation) do
|
152
133
|
include Steps
|
153
134
|
|
154
|
-
step
|
155
|
-
outputs: Edit.outputs # all outputs given means it "works"
|
135
|
+
step Subprocess(Edit), Output(:pass_fast) => Track(:pass_fast), Output(:fail_fast) => Track(:fail_fast)
|
156
136
|
step :b
|
157
137
|
fail :f
|
158
138
|
end
|
@@ -160,7 +140,7 @@ class NestedFastTrackTest < Minitest::Spec
|
|
160
140
|
|
161
141
|
# Edit returns End.success
|
162
142
|
it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
|
163
|
-
# Edit returns End.
|
143
|
+
# Edit returns End.fail
|
164
144
|
it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
|
165
145
|
# Edit returns End.pass_fast
|
166
146
|
it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, nil, nil] >} }
|
@@ -173,9 +153,10 @@ class NestedFastTrackTest < Minitest::Spec
|
|
173
153
|
Class.new(Trailblazer::Operation) do
|
174
154
|
include Steps
|
175
155
|
|
176
|
-
step
|
177
|
-
|
178
|
-
|
156
|
+
step Subprocess(Edit),
|
157
|
+
# manually rewire the fast-track outputs to "conventional" railway ends.
|
158
|
+
Output(:pass_fast) => Track(:success),
|
159
|
+
Output(:fail_fast) => Track(:failure)
|
179
160
|
|
180
161
|
step :b
|
181
162
|
fail :f
|
@@ -183,15 +164,14 @@ class NestedFastTrackTest < Minitest::Spec
|
|
183
164
|
end
|
184
165
|
|
185
166
|
# it { puts Trailblazer::Activity::Introspect.Cct(update.instance_variable_get(:@process)) }
|
186
|
-
it { update.to_h
|
167
|
+
it { update.to_h }
|
187
168
|
# Edit returns End.success
|
188
169
|
it { update.(edit_return: true).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
|
189
|
-
# Edit returns End.
|
170
|
+
# Edit returns End.fail
|
190
171
|
it { update.(edit_return: false).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
|
191
172
|
# Edit returns End.pass_fast, but behaves like :success.
|
192
173
|
it { update.(edit_return: Trailblazer::Operation::Railway.pass_fast!).inspect("a", "b", "f").must_equal %{<Result:true [1, 2, nil] >} }
|
193
|
-
# Edit returns End.fail_fast, but behaves like :
|
174
|
+
# Edit returns End.fail_fast, but behaves like :fail.
|
194
175
|
it { update.(edit_return: Trailblazer::Operation::Railway.fail_fast!).inspect("a", "b", "f").must_equal %{<Result:false [1, nil, 3] >} }
|
195
176
|
end
|
196
177
|
end
|
197
|
-
|
data/test/inheritance_test.rb
CHANGED
@@ -5,22 +5,23 @@ class InheritanceTest < Minitest::Spec
|
|
5
5
|
def self.find_by(options); options[:id].nil? ? nil : new(options[:id]) end
|
6
6
|
end
|
7
7
|
|
8
|
-
class Create < Trailblazer::Operation
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
# class Create < Trailblazer::Operation
|
9
|
+
# self["a"] = "A"
|
10
|
+
# self["b"] = "B"
|
11
|
+
# self["c"] = "D"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
13
|
+
# def self.class(*skills)
|
14
|
+
# Class.new(Trailblazer::Operation). tap do |klass|
|
15
|
+
# skills.each { |skill| klass.heritage.record(:[]=, skill, self[skill]) }
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
# end
|
19
19
|
|
20
|
-
class Update < Create.class("a", "b")
|
21
|
-
end
|
20
|
+
# class Update < Create.class("a", "b")
|
21
|
+
# end
|
22
22
|
|
23
23
|
it do
|
24
|
+
skip "https://trello.com/c/t8bUJlqb/25-op-class-dependencies"
|
24
25
|
Update["a"].must_equal "A"
|
25
26
|
Update["b"].must_equal "B"
|
26
27
|
Update["c"].must_be_nil
|
data/test/inspect_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
-
|
4
3
|
class InspectTest < Minitest::Spec
|
5
4
|
# Test: #to_table
|
6
5
|
class Create < Trailblazer::Operation
|
@@ -23,12 +22,12 @@ class InspectTest < Minitest::Spec
|
|
23
22
|
|
24
23
|
it do
|
25
24
|
Trailblazer::Operation::Inspect.call(Create, style: :rows).must_equal %{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
1 ==============================>decide!
|
26
|
+
2 ===========================>>wasnt_ok!
|
27
|
+
3 =============================>>was_ok!
|
28
|
+
4 <<return_true!========================
|
29
|
+
5 <<return_false!=======================
|
30
|
+
6 ============================>finalize!}
|
32
31
|
end
|
33
32
|
|
34
33
|
describe "step with only one output (happens with Nested)" do
|
data/test/introspect_test.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class IntrospectTest < Minitest::Spec
|
4
|
-
A = ->(*args) { [
|
5
|
-
B = ->(*args) { [
|
6
|
-
C = ->(*args) { [
|
7
|
-
D = ->(*args) { [
|
4
|
+
A = ->(*args) { [Activity::Right, *args] }
|
5
|
+
B = ->(*args) { [Activity::Right, *args] }
|
6
|
+
C = ->(*args) { [Activity::Right, *args] }
|
7
|
+
D = ->(*args) { [Activity::Right, *args] }
|
8
8
|
|
9
9
|
let(:activity) do
|
10
10
|
nested = bc
|
@@ -26,7 +26,7 @@ class IntrospectTest < Minitest::Spec
|
|
26
26
|
describe "#collect" do
|
27
27
|
it "iterates over each task element in the top activity" do
|
28
28
|
skip
|
29
|
-
all_tasks = Activity::Introspect.collect(activity) do |task,
|
29
|
+
all_tasks = Activity::Introspect.collect(activity) do |task, _connections|
|
30
30
|
task
|
31
31
|
end
|
32
32
|
|
@@ -39,7 +39,7 @@ class IntrospectTest < Minitest::Spec
|
|
39
39
|
|
40
40
|
it "iterates over all task elements recursively" do
|
41
41
|
skip
|
42
|
-
all_tasks = Activity::Introspect.collect(activity, recursive: true) do |task,
|
42
|
+
all_tasks = Activity::Introspect.collect(activity, recursive: true) do |task, _connections|
|
43
43
|
task
|
44
44
|
end
|
45
45
|
|
data/test/operation_test.rb
CHANGED
@@ -13,7 +13,14 @@ class DeclarativeApiTest < Minitest::Spec
|
|
13
13
|
fail :return_true!
|
14
14
|
fail :return_false!
|
15
15
|
|
16
|
-
|
16
|
+
step :bla, input: ->(ctx, *) { {id: ctx.inspect} }, output: ->(scope, ctx) { ctx["hello"] = scope["1"]; ctx }
|
17
|
+
|
18
|
+
def bla(ctx, id:1, **)
|
19
|
+
puts id
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def decide!(options, decide: raise, **)
|
17
24
|
options["a"] = true
|
18
25
|
decide
|
19
26
|
end
|
@@ -26,18 +33,19 @@ class DeclarativeApiTest < Minitest::Spec
|
|
26
33
|
options["x"] = true
|
27
34
|
end
|
28
35
|
|
29
|
-
def return_true!
|
36
|
+
def return_true!(options, **); options["b"] = true end
|
37
|
+
|
30
38
|
def return_false!(options, **); options["c"] = false end
|
31
39
|
end
|
32
40
|
|
33
41
|
it { Create.(decide: true).inspect("a", "x", "y", "b", "c").must_equal %{<Result:true [true, true, false, nil, nil] >} }
|
34
42
|
it { Create.(decide: false).inspect("a", "x", "y", "b", "c").must_equal %{<Result:false [true, nil, nil, true, false] >} }
|
35
|
-
|
43
|
+
it { Create.(decide: nil).keys.must_equal(%i(decide a b c)) }
|
44
|
+
it { Create.(decide: nil).to_hash.must_equal(decide: nil, a: true, b: true, c: false) }
|
36
45
|
#---
|
37
46
|
#- trace
|
38
47
|
|
39
48
|
it do
|
40
|
-
|
41
49
|
end
|
42
50
|
|
43
51
|
#---
|
@@ -46,14 +54,16 @@ class DeclarativeApiTest < Minitest::Spec
|
|
46
54
|
end
|
47
55
|
|
48
56
|
it { Noop.().inspect("params").must_equal %{<Result:true [nil] >} }
|
57
|
+
it { Noop.().keys.must_equal([]) }
|
58
|
+
it { Noop.().to_hash.must_equal({}) }
|
49
59
|
|
50
60
|
#---
|
51
61
|
#- pass
|
52
62
|
#- fail
|
53
63
|
class Update < Trailblazer::Operation
|
54
|
-
pass ->(options, **)
|
55
|
-
step ->(options, params:raise, **) { options["b"] = params[:decide] }
|
56
|
-
fail ->(options, **)
|
64
|
+
pass ->(options, **) { options["a"] = false }
|
65
|
+
step ->(options, params: raise, **) { options["b"] = params[:decide] }
|
66
|
+
fail ->(options, **) { options["c"] = true }
|
57
67
|
end
|
58
68
|
|
59
69
|
it { Update.("params" => {decide: true}).inspect("a", "b", "c").must_equal %{<Result:true [false, true, nil] >} }
|
@@ -73,22 +83,4 @@ class DeclarativeApiTest < Minitest::Spec
|
|
73
83
|
Upsert.("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, nil] >}
|
74
84
|
Unset. ("params" => {decide: true}).inspect("a", "b", "c", "d", "e").must_equal %{<Result:true [false, true, nil, 1, 2] >}
|
75
85
|
end
|
76
|
-
|
77
|
-
describe "Activity::Interface" do
|
78
|
-
class Edit < Trailblazer::Operation
|
79
|
-
step :a
|
80
|
-
step :b, fast_track: true
|
81
|
-
end
|
82
|
-
|
83
|
-
it "provides #outputs" do
|
84
|
-
Activity::Introspect.Outputs(Edit.outputs).must_equal %{success=> (#<Trailblazer::Operation::Railway::End::Success semantic=:success>, success)
|
85
|
-
failure=> (#<Trailblazer::Operation::Railway::End::Failure semantic=:failure>, failure)
|
86
|
-
pass_fast=> (#<Trailblazer::Operation::Railway::End::PassFast semantic=:pass_fast>, pass_fast)
|
87
|
-
fail_fast=> (#<Trailblazer::Operation::Railway::End::FailFast semantic=:fail_fast>, fail_fast)}
|
88
|
-
end
|
89
|
-
|
90
|
-
it "is an Interface" do
|
91
|
-
Edit.is_a?( Activity::Interface ).must_equal true
|
92
|
-
end
|
93
|
-
end
|
94
86
|
end
|
data/test/result_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
require "test_helper"
|
2
2
|
|
3
3
|
class RailwayResultTest < Minitest::Spec
|
4
4
|
Result = Trailblazer::Operation::Railway::Result
|
5
5
|
Success = Trailblazer::Operation::Railway::End::Success
|
6
6
|
|
7
7
|
let(:event) { Success.new(semantic: nil) }
|
8
|
-
let
|
8
|
+
let(:success) { Result.new(true, {"x" => String}, event) }
|
9
9
|
|
10
10
|
it { success.success?.must_equal true }
|
11
11
|
it { success.failure?.must_equal false }
|
@@ -20,10 +20,10 @@ class RailwayResultTest < Minitest::Spec
|
|
20
20
|
#---
|
21
21
|
# inspect
|
22
22
|
it { success.inspect.must_equal %{<Result:true {\"x\"=>String} >} }
|
23
|
-
it { Result.new(true, {
|
23
|
+
it { Result.new(true, {"x" => true, "y" => 1, "z" => 2}, event).inspect("z", "y").must_equal %{<Result:true [2, 1] >} }
|
24
24
|
|
25
25
|
class Create < Trailblazer::Operation
|
26
|
-
|
26
|
+
pass :call
|
27
27
|
|
28
28
|
def call(options, **)
|
29
29
|
options[:message] = "Result objects are actually quite handy!"
|
@@ -13,21 +13,22 @@ class DeclarativeApiTest < Minitest::Spec
|
|
13
13
|
failure :return_true!
|
14
14
|
failure :return_false!
|
15
15
|
|
16
|
-
def decide!(options, decide:raise, **
|
16
|
+
def decide!(options, decide: raise, **_o)
|
17
17
|
options["a"] = true
|
18
18
|
decide
|
19
19
|
end
|
20
20
|
|
21
|
-
def wasnt_ok!(options, **
|
21
|
+
def wasnt_ok!(options, **_o)
|
22
22
|
options["y"] = false
|
23
23
|
end
|
24
24
|
|
25
|
-
def was_ok!(options, **
|
25
|
+
def was_ok!(options, **_o)
|
26
26
|
options["x"] = true
|
27
27
|
end
|
28
28
|
|
29
|
-
def return_true!
|
30
|
-
|
29
|
+
def return_true!(options, **_o); options["b"] = true end
|
30
|
+
|
31
|
+
def return_false!(options, **_o); options["c"] = false end
|
31
32
|
end
|
32
33
|
|
33
34
|
it { Create.({}, decide: true).inspect("a", "x", "y", "b", "c").must_equal %{<Result:true [true, true, false, nil, nil] >} }
|
@@ -37,7 +38,6 @@ class DeclarativeApiTest < Minitest::Spec
|
|
37
38
|
#- trace
|
38
39
|
|
39
40
|
it do
|
40
|
-
|
41
41
|
end
|
42
42
|
|
43
43
|
#---
|
@@ -51,9 +51,9 @@ class DeclarativeApiTest < Minitest::Spec
|
|
51
51
|
#- pass
|
52
52
|
#- fail
|
53
53
|
class Update < Trailblazer::Operation
|
54
|
-
pass ->(options, **
|
55
|
-
step ->(options, params:raise, **
|
56
|
-
fail ->(options, **
|
54
|
+
pass ->(options, **_o) { options["a"] = false }
|
55
|
+
step ->(options, params: raise, **_o) { options["b"] = params[:decide] }
|
56
|
+
fail ->(options, **_o) { options["c"] = true }
|
57
57
|
end
|
58
58
|
|
59
59
|
it { Update.(decide: true).inspect("a", "b", "c").must_equal %{<Result:true [false, true, nil] >} }
|