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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 297ac423123374945b62db51967e5a84ab01cadf
4
- data.tar.gz: 72b12c2f322edea6c349bedb12eb8f032a02badf
3
+ metadata.gz: 679662590f13d07a84ae193679d65f448ddb9e54
4
+ data.tar.gz: 5810baddf36d0bfd0691acdcb663c5b866f04576
5
5
  SHA512:
6
- metadata.gz: c935fb4f6c44ebdf251d519262d8276039cf1dbc565c35d16d80ab7915d4ffe4de7a9eb2189a20ca6af0061ce8c23a90abe3c20ff4cec06f9811c81a70a26c27
7
- data.tar.gz: 9eb6512ac995b4c5c7121f5c5d254f07fae98849c1bf9270ccd90e3eb46e00a933b409e9a0c75e9e29bcf9603b2904d9414e73f67a852cc65cb4308b219c7182
6
+ metadata.gz: 57726a7d740fa0e5983690fe21956303d2f4db5a62ba16f2c8aa334c7dd40b92aefccdc3e13df2f568eed5cf2ee7b4707d0ad78a771c20c89652f29f3fea1049
7
+ data.tar.gz: 3c9de9200a701e364c397279c3a277c5f575b725afa62c87b7102f6c31ae747b9b3f6f93b5798a99bd026062bb932aeac8ea78925d8147b678897fe0f8cd90b1
data/Gemfile CHANGED
@@ -6,6 +6,7 @@ group :test do
6
6
  gem "simplecov"
7
7
  gem "codeclimate-test-reporter"
8
8
  gem "byebug", platform: :mri
9
+ gem "dry-container"
9
10
  end
10
11
 
11
12
  group :tools do
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-transaction (0.10.1)
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) { ops_container and ops_container[step.operation_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
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  # Business transaction DSL.
3
3
  module Transaction
4
- VERSION = "0.10.1".freeze
4
+ VERSION = "0.10.2".freeze
5
5
  end
6
6
  end
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.00213 seconds |
4
- ./spec/integration/operation_spec.rb[1:1] | passed | 0.00313 seconds |
5
- ./spec/integration/operation_spec.rb[1:2] | passed | 0.00127 seconds |
6
- ./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.0008 seconds |
7
- ./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00036 seconds |
8
- ./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00197 seconds |
9
- ./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00074 seconds |
10
- ./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00065 seconds |
11
- ./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00072 seconds |
12
- ./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00062 seconds |
13
- ./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.00226 seconds |
14
- ./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00066 seconds |
15
- ./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00043 seconds |
16
- ./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00109 seconds |
17
- ./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00096 seconds |
18
- ./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00111 seconds |
19
- ./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00126 seconds |
20
- ./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00034 seconds |
21
- ./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00072 seconds |
22
- ./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00094 seconds |
23
- ./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00043 seconds |
24
- ./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.0007 seconds |
25
- ./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00061 seconds |
26
- ./spec/integration/transaction_spec.rb[1:7:2] | passed | 0.00096 seconds |
27
- ./spec/integration/transaction_spec.rb[1:7:3] | passed | 0.00097 seconds |
28
- ./spec/integration/transaction_spec.rb[1:7:4] | passed | 0.00093 seconds |
29
- ./spec/integration/transaction_spec.rb[1:7:5] | passed | 0.00053 seconds |
30
- ./spec/integration/transaction_spec.rb[1:7:6] | passed | 0.00073 seconds |
31
- ./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00086 seconds |
32
- ./spec/integration/transaction_spec.rb[1:8:2] | passed | 0.00074 seconds |
33
- ./spec/integration/transaction_spec.rb[1:8:3] | passed | 0.00072 seconds |
34
- ./spec/integration/transaction_spec.rb[1:8:4] | passed | 0.00032 seconds |
35
- ./spec/integration/transaction_spec.rb[1:8:5] | passed | 0.00044 seconds |
36
- ./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00096 seconds |
37
- ./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00013 seconds |
38
- ./spec/unit/step_adapters/map_spec.rb[1:1:2] | passed | 0.00026 seconds |
39
- ./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00204 seconds |
40
- ./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00019 seconds |
41
- ./spec/unit/step_adapters/raw_spec.rb[1:1:2:2] | passed | 0.00017 seconds |
42
- ./spec/unit/step_adapters/raw_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
43
- ./spec/unit/step_adapters/raw_spec.rb[1:1:3:2] | passed | 0.00015 seconds |
44
- ./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00194 seconds |
45
- ./spec/unit/step_adapters/tee_spec.rb[1:1:2] | passed | 0.00163 seconds |
46
- ./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00017 seconds |
47
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00013 seconds |
48
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00019 seconds |
49
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00014 seconds |
50
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00013 seconds |
51
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00014 seconds |
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.00026 seconds |
56
- ./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.01897 seconds |
57
- ./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00028 seconds |
58
- ./spec/unit/step_spec.rb[1:1:2:2] | passed | 0.0024 seconds |
59
- ./spec/unit/step_spec.rb[1:1:2:3] | passed | 0.00062 seconds |
60
- ./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.0001 seconds |
61
- ./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
62
- ./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00015 seconds |
63
- ./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00013 seconds |
64
- ./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00016 seconds |
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
- process: -> input { {name: input["name"], email: input["email"]} },
19
- verify: -> input { Right(input) },
20
- validate: -> input { input[:email].nil? ? raise(Test::NotValidError, "email required") : input },
21
- persist: -> input { Test::DB << input and true },
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
- module Test
67
- ContainerNames = {
68
- process_step: -> input { {name: input["name"], email: input["email"]} },
69
- verify_step: -> input { Dry::Monads.Right(input) },
70
- persist_step: -> input { Test::DB << input and true },
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::Container[:verify] = -> input { Left("raw failure") }
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::Container[:verify] = -> input { "failure" }
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.1
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-06-29 00:00:00.000000000 Z
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container