dry-transaction 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -1
- data/lib/dry/transaction/operation_resolver.rb +3 -1
- data/lib/dry/transaction/version.rb +1 -1
- data/spec/examples.txt +60 -59
- data/spec/integration/transaction_spec.rb +84 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 679662590f13d07a84ae193679d65f448ddb9e54
|
4
|
+
data.tar.gz: 5810baddf36d0bfd0691acdcb663c5b866f04576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57726a7d740fa0e5983690fe21956303d2f4db5a62ba16f2c8aa334c7dd40b92aefccdc3e13df2f568eed5cf2ee7b4707d0ad78a771c20c89652f29f3fea1049
|
7
|
+
data.tar.gz: 3c9de9200a701e364c397279c3a277c5f575b725afa62c87b7102f6c31ae747b9b3f6f93b5798a99bd026062bb932aeac8ea78925d8147b678897fe0f8cd90b1
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dry-transaction (0.10.
|
4
|
+
dry-transaction (0.10.2)
|
5
5
|
dry-container (>= 0.2.8)
|
6
6
|
dry-matcher (>= 0.5.0)
|
7
7
|
dry-monads (>= 0.0.1)
|
@@ -78,6 +78,7 @@ DEPENDENCIES
|
|
78
78
|
bundler (~> 1.15)
|
79
79
|
byebug
|
80
80
|
codeclimate-test-reporter
|
81
|
+
dry-container
|
81
82
|
dry-transaction!
|
82
83
|
pry
|
83
84
|
rake (~> 11.2.2)
|
@@ -5,7 +5,9 @@ module Dry
|
|
5
5
|
module_exec(container) do |ops_container|
|
6
6
|
define_method :initialize do |**kwargs|
|
7
7
|
operation_kwargs = self.class.steps.select(&:operation_name).map { |step|
|
8
|
-
operation = kwargs.fetch(step.step_name) {
|
8
|
+
operation = kwargs.fetch(step.step_name) {
|
9
|
+
ops_container and ops_container.key?(step.operation_name) and ops_container[step.operation_name]
|
10
|
+
}
|
9
11
|
|
10
12
|
[step.step_name, operation]
|
11
13
|
}.to_h
|
data/spec/examples.txt
CHANGED
@@ -1,64 +1,65 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
-------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.
|
4
|
-
./spec/integration/operation_spec.rb[1:1] | passed | 0.
|
5
|
-
./spec/integration/operation_spec.rb[1:2] | passed | 0.
|
6
|
-
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.
|
7
|
-
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.
|
8
|
-
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.
|
9
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.
|
10
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.
|
11
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.
|
12
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.
|
13
|
-
./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.
|
14
|
-
./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.
|
15
|
-
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.
|
16
|
-
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.
|
17
|
-
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.
|
18
|
-
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.
|
19
|
-
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.
|
20
|
-
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.
|
21
|
-
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.
|
22
|
-
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.
|
23
|
-
./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.
|
24
|
-
./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.
|
25
|
-
./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.
|
26
|
-
./spec/integration/transaction_spec.rb[1:
|
27
|
-
./spec/integration/transaction_spec.rb[1:
|
28
|
-
./spec/integration/transaction_spec.rb[1:
|
29
|
-
./spec/integration/transaction_spec.rb[1:
|
30
|
-
./spec/integration/transaction_spec.rb[1:
|
31
|
-
./spec/integration/transaction_spec.rb[1:8:
|
32
|
-
./spec/integration/transaction_spec.rb[1:
|
33
|
-
./spec/integration/transaction_spec.rb[1:
|
34
|
-
./spec/integration/transaction_spec.rb[1:
|
35
|
-
./spec/integration/transaction_spec.rb[1:
|
36
|
-
./spec/integration/transaction_spec.rb[1:9:
|
37
|
-
./spec/
|
38
|
-
./spec/unit/step_adapters/map_spec.rb[1:1:
|
39
|
-
./spec/unit/step_adapters/
|
40
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:
|
41
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:2:
|
42
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:
|
43
|
-
./spec/unit/step_adapters/raw_spec.rb[1:1:3:
|
44
|
-
./spec/unit/step_adapters/
|
45
|
-
./spec/unit/step_adapters/tee_spec.rb[1:1:
|
46
|
-
./spec/unit/step_adapters/
|
47
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:
|
48
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:
|
49
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:
|
50
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:
|
51
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2
|
3
|
+
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.00042 seconds |
|
4
|
+
./spec/integration/operation_spec.rb[1:1] | passed | 0.00017 seconds |
|
5
|
+
./spec/integration/operation_spec.rb[1:2] | passed | 0.00014 seconds |
|
6
|
+
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00142 seconds |
|
7
|
+
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00248 seconds |
|
8
|
+
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.0003 seconds |
|
9
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00072 seconds |
|
10
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00067 seconds |
|
11
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00061 seconds |
|
12
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00057 seconds |
|
13
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.00084 seconds |
|
14
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00207 seconds |
|
15
|
+
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00115 seconds |
|
16
|
+
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00095 seconds |
|
17
|
+
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00098 seconds |
|
18
|
+
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00133 seconds |
|
19
|
+
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00104 seconds |
|
20
|
+
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00212 seconds |
|
21
|
+
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00048 seconds |
|
22
|
+
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00061 seconds |
|
23
|
+
./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00062 seconds |
|
24
|
+
./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.00283 seconds |
|
25
|
+
./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00051 seconds |
|
26
|
+
./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00307 seconds |
|
27
|
+
./spec/integration/transaction_spec.rb[1:8:2] | passed | 0.0007 seconds |
|
28
|
+
./spec/integration/transaction_spec.rb[1:8:3] | passed | 0.00173 seconds |
|
29
|
+
./spec/integration/transaction_spec.rb[1:8:4] | passed | 0.00162 seconds |
|
30
|
+
./spec/integration/transaction_spec.rb[1:8:5] | passed | 0.0006 seconds |
|
31
|
+
./spec/integration/transaction_spec.rb[1:8:6] | passed | 0.00052 seconds |
|
32
|
+
./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.0006 seconds |
|
33
|
+
./spec/integration/transaction_spec.rb[1:9:2] | passed | 0.00073 seconds |
|
34
|
+
./spec/integration/transaction_spec.rb[1:9:3] | passed | 0.00156 seconds |
|
35
|
+
./spec/integration/transaction_spec.rb[1:9:4] | passed | 0.00097 seconds |
|
36
|
+
./spec/integration/transaction_spec.rb[1:9:5] | passed | 0.00068 seconds |
|
37
|
+
./spec/integration/transaction_spec.rb[1:10:1] | passed | 0.00062 seconds |
|
38
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00056 seconds |
|
39
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:2] | passed | 0.001 seconds |
|
40
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
|
41
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
|
42
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:2] | passed | 0.00012 seconds |
|
43
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
|
44
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:3:2] | passed | 0.00011 seconds |
|
45
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00011 seconds |
|
46
|
+
./spec/unit/step_adapters/tee_spec.rb[1:1:2] | passed | 0.00009 seconds |
|
47
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00015 seconds |
|
48
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00012 seconds |
|
49
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00016 seconds |
|
50
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00013 seconds |
|
51
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00012 seconds |
|
52
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00011 seconds |
|
52
53
|
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2] | passed | 0.00012 seconds |
|
53
54
|
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:1] | passed | 0.00011 seconds |
|
54
55
|
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:3:2] | passed | 0.00012 seconds |
|
55
|
-
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.
|
56
|
-
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.
|
57
|
-
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.
|
58
|
-
./spec/unit/step_spec.rb[1:1:2:2] | passed | 0.
|
59
|
-
./spec/unit/step_spec.rb[1:1:2:3] | passed | 0.
|
60
|
-
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.
|
61
|
-
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.
|
62
|
-
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.
|
63
|
-
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.
|
64
|
-
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.
|
56
|
+
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.00024 seconds |
|
57
|
+
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.01629 seconds |
|
58
|
+
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00016 seconds |
|
59
|
+
./spec/unit/step_spec.rb[1:1:2:2] | passed | 0.00161 seconds |
|
60
|
+
./spec/unit/step_spec.rb[1:1:2:3] | passed | 0.00038 seconds |
|
61
|
+
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.00018 seconds |
|
62
|
+
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00011 seconds |
|
63
|
+
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00013 seconds |
|
64
|
+
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00012 seconds |
|
65
|
+
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00013 seconds |
|
@@ -1,28 +1,28 @@
|
|
1
1
|
RSpec.describe "Transactions" do
|
2
|
-
let(:transaction) {
|
3
|
-
Class.new do
|
4
|
-
include Dry::Transaction(container: Test::Container)
|
5
|
-
map :process
|
6
|
-
step :verify
|
7
|
-
try :validate, catch: Test::NotValidError
|
8
|
-
tee :persist
|
9
|
-
end.new(**dependencies)
|
10
|
-
}
|
11
|
-
|
12
2
|
let(:dependencies) { {} }
|
13
3
|
|
14
4
|
before do
|
15
5
|
Test::NotValidError = Class.new(StandardError)
|
16
6
|
Test::DB = []
|
17
|
-
Test::Container
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
7
|
+
class Test::Container
|
8
|
+
extend Dry::Container::Mixin
|
9
|
+
register :process, -> input { {name: input["name"], email: input["email"]} }
|
10
|
+
register :verify, -> input { Dry::Monads::Right(input) }
|
11
|
+
register :validate, -> input { input[:email].nil? ? raise(Test::NotValidError, "email required") : input }
|
12
|
+
register :persist, -> input { Test::DB << input and true }
|
13
|
+
end
|
23
14
|
end
|
24
15
|
|
25
16
|
context "successful" do
|
17
|
+
let(:transaction) {
|
18
|
+
Class.new do
|
19
|
+
include Dry::Transaction(container: Test::Container)
|
20
|
+
map :process
|
21
|
+
step :verify
|
22
|
+
try :validate, catch: Test::NotValidError
|
23
|
+
tee :persist
|
24
|
+
end.new(**dependencies)
|
25
|
+
}
|
26
26
|
let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
|
27
27
|
|
28
28
|
it "calls the operations" do
|
@@ -63,12 +63,11 @@ RSpec.describe "Transactions" do
|
|
63
63
|
|
64
64
|
context "different step names" do
|
65
65
|
before do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
66
|
+
class Test::ContainerNames
|
67
|
+
extend Dry::Container::Mixin
|
68
|
+
register :process_step, -> input { {name: input["name"], email: input["email"]} }
|
69
|
+
register :verify_step, -> input { Dry::Monads::Right(input) }
|
70
|
+
register :persist_step, -> input { Test::DB << input and true }
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
@@ -156,6 +155,29 @@ RSpec.describe "Transactions" do
|
|
156
155
|
end
|
157
156
|
end
|
158
157
|
|
158
|
+
context "local step definition not in container" do
|
159
|
+
let(:transaction) do
|
160
|
+
Class.new do
|
161
|
+
include Dry::Transaction(container: Test::Container)
|
162
|
+
|
163
|
+
map :process, with: :process
|
164
|
+
step :verify_only_local
|
165
|
+
tee :persist, with: :persist
|
166
|
+
|
167
|
+
def verify_only_local(input)
|
168
|
+
Right(input.keys)
|
169
|
+
end
|
170
|
+
end.new
|
171
|
+
end
|
172
|
+
|
173
|
+
it "execute step only defined as local method" do
|
174
|
+
transaction.call("name" => "Jane", "email" => "jane@doe.com")
|
175
|
+
|
176
|
+
expect(Test::DB).to include([:name, :email])
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
159
181
|
context "all steps are local methods" do
|
160
182
|
let(:transaction) do
|
161
183
|
Class.new do
|
@@ -186,6 +208,15 @@ RSpec.describe "Transactions" do
|
|
186
208
|
end
|
187
209
|
|
188
210
|
context "failed in a try step" do
|
211
|
+
let(:transaction) {
|
212
|
+
Class.new do
|
213
|
+
include Dry::Transaction(container: Test::Container)
|
214
|
+
map :process
|
215
|
+
step :verify
|
216
|
+
try :validate, catch: Test::NotValidError
|
217
|
+
tee :persist
|
218
|
+
end.new(**dependencies)
|
219
|
+
}
|
189
220
|
let(:input) { {"name" => "Jane"} }
|
190
221
|
|
191
222
|
it "does not run subsequent operations" do
|
@@ -252,9 +283,24 @@ RSpec.describe "Transactions" do
|
|
252
283
|
let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
|
253
284
|
|
254
285
|
before do
|
255
|
-
Test::
|
286
|
+
class Test::ContainerRaw
|
287
|
+
extend Dry::Container::Mixin
|
288
|
+
register :process_step, -> input { {name: input["name"], email: input["email"]} }
|
289
|
+
register :verify_step, -> input { Dry::Monads::Left("raw failure") }
|
290
|
+
register :persist_step, -> input { Test::DB << input and true }
|
291
|
+
end
|
256
292
|
end
|
257
293
|
|
294
|
+
let(:transaction) {
|
295
|
+
Class.new do
|
296
|
+
include Dry::Transaction(container: Test::ContainerRaw)
|
297
|
+
|
298
|
+
map :process, with: :process_step
|
299
|
+
step :verify, with: :verify_step
|
300
|
+
tee :persist, with: :persist_step
|
301
|
+
end.new(**dependencies)
|
302
|
+
}
|
303
|
+
|
258
304
|
it "does not run subsequent operations" do
|
259
305
|
transaction.call(input)
|
260
306
|
expect(Test::DB).to be_empty
|
@@ -284,8 +330,22 @@ RSpec.describe "Transactions" do
|
|
284
330
|
context "non-confirming raw step result" do
|
285
331
|
let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
|
286
332
|
|
333
|
+
let(:transaction) {
|
334
|
+
Class.new do
|
335
|
+
include Dry::Transaction(container: Test::ContainerRaw)
|
336
|
+
map :process
|
337
|
+
step :verify
|
338
|
+
tee :persist
|
339
|
+
end.new(**dependencies)
|
340
|
+
}
|
341
|
+
|
287
342
|
before do
|
288
|
-
Test::
|
343
|
+
class Test::ContainerRaw
|
344
|
+
extend Dry::Container::Mixin
|
345
|
+
register :process, -> input { {name: input["name"], email: input["email"]} }
|
346
|
+
register :verify, -> input { "failure" }
|
347
|
+
register :persist, -> input { Test::DB << input and true }
|
348
|
+
end
|
289
349
|
end
|
290
350
|
|
291
351
|
it "raises an exception" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Riley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|