dry-transaction 0.11.1 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +308 -0
  3. data/LICENSE +20 -0
  4. data/README.md +15 -43
  5. data/dry-transaction.gemspec +35 -0
  6. data/lib/dry-transaction.rb +2 -0
  7. data/lib/dry/transaction.rb +2 -0
  8. data/lib/dry/transaction/builder.rb +6 -4
  9. data/lib/dry/transaction/callable.rb +5 -0
  10. data/lib/dry/transaction/dsl.rb +9 -7
  11. data/lib/dry/transaction/errors.rb +2 -0
  12. data/lib/dry/transaction/instance_methods.rb +24 -20
  13. data/lib/dry/transaction/operation.rb +5 -3
  14. data/lib/dry/transaction/operation_resolver.rb +4 -2
  15. data/lib/dry/transaction/result_matcher.rb +7 -5
  16. data/lib/dry/transaction/stack.rb +2 -0
  17. data/lib/dry/transaction/step.rb +37 -24
  18. data/lib/dry/transaction/step_adapter.rb +6 -4
  19. data/lib/dry/transaction/step_adapters.rb +9 -7
  20. data/lib/dry/transaction/step_adapters/around.rb +4 -2
  21. data/lib/dry/transaction/step_adapters/check.rb +3 -1
  22. data/lib/dry/transaction/step_adapters/map.rb +2 -0
  23. data/lib/dry/transaction/step_adapters/raw.rb +5 -3
  24. data/lib/dry/transaction/step_adapters/tee.rb +2 -0
  25. data/lib/dry/transaction/step_adapters/try.rb +3 -1
  26. data/lib/dry/transaction/step_failure.rb +12 -0
  27. data/lib/dry/transaction/version.rb +3 -1
  28. metadata +14 -109
  29. data/Gemfile +0 -15
  30. data/Gemfile.lock +0 -97
  31. data/LICENSE.md +0 -9
  32. data/Rakefile +0 -6
  33. data/spec/examples.txt +0 -81
  34. data/spec/integration/around_spec.rb +0 -81
  35. data/spec/integration/custom_step_adapters_spec.rb +0 -41
  36. data/spec/integration/operation_spec.rb +0 -30
  37. data/spec/integration/passing_step_arguments_spec.rb +0 -51
  38. data/spec/integration/publishing_step_events_spec.rb +0 -119
  39. data/spec/integration/transaction_spec.rb +0 -483
  40. data/spec/integration/transaction_without_steps_spec.rb +0 -101
  41. data/spec/spec_helper.rb +0 -116
  42. data/spec/support/container.rb +0 -10
  43. data/spec/support/database.rb +0 -12
  44. data/spec/support/db_transactions.rb +0 -45
  45. data/spec/support/result_mixin.rb +0 -3
  46. data/spec/support/test_module_constants.rb +0 -11
  47. data/spec/unit/step_adapters/around_spec.rb +0 -46
  48. data/spec/unit/step_adapters/check_spec.rb +0 -43
  49. data/spec/unit/step_adapters/map_spec.rb +0 -16
  50. data/spec/unit/step_adapters/raw_spec.rb +0 -36
  51. data/spec/unit/step_adapters/tee_spec.rb +0 -17
  52. data/spec/unit/step_adapters/try_spec.rb +0 -89
  53. data/spec/unit/step_spec.rb +0 -131
@@ -1,4 +1,6 @@
1
- require "dry/transaction/errors"
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry/transaction/errors'
2
4
 
3
5
  module Dry
4
6
  module Transaction
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Transaction
3
5
  # A wrapper for storing together the step that failed
@@ -6,6 +8,16 @@ module Dry
6
8
  attr_reader :step
7
9
  attr_reader :value
8
10
 
11
+ # @api private
12
+ def self.call(step, value)
13
+ if self === value
14
+ value
15
+ else
16
+ yield
17
+ new(step, value)
18
+ end
19
+ end
20
+
9
21
  def initialize(step, value)
10
22
  @step = step
11
23
  @value = value
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  # Business transaction DSL.
3
5
  module Transaction
4
- VERSION = "0.11.1".freeze
6
+ VERSION = '0.13.1'.freeze
5
7
  end
6
8
  end
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.11.1
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-14 00:00:00.000000000 Z
11
+ date: 2021-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container
@@ -66,94 +66,17 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.4.0
69
- - !ruby/object:Gem::Dependency
70
- name: bundler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.15'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.15'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '11.2'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 11.2.2
93
- type: :development
94
- prerelease: false
95
- version_requirements: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '11.2'
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: 11.2.2
103
- - !ruby/object:Gem::Dependency
104
- name: rspec
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '3.3'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '3.3'
117
- - !ruby/object:Gem::Dependency
118
- name: simplecov
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: yard
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :development
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
- description:
69
+ description: Business Transaction Flow DSL
146
70
  email:
147
71
  - tim@icelab.com.au
148
72
  executables: []
149
73
  extensions: []
150
74
  extra_rdoc_files: []
151
75
  files:
152
- - Gemfile
153
- - Gemfile.lock
154
- - LICENSE.md
76
+ - CHANGELOG.md
77
+ - LICENSE
155
78
  - README.md
156
- - Rakefile
79
+ - dry-transaction.gemspec
157
80
  - lib/dry-transaction.rb
158
81
  - lib/dry/transaction.rb
159
82
  - lib/dry/transaction/builder.rb
@@ -176,31 +99,14 @@ files:
176
99
  - lib/dry/transaction/step_adapters/try.rb
177
100
  - lib/dry/transaction/step_failure.rb
178
101
  - lib/dry/transaction/version.rb
179
- - spec/examples.txt
180
- - spec/integration/around_spec.rb
181
- - spec/integration/custom_step_adapters_spec.rb
182
- - spec/integration/operation_spec.rb
183
- - spec/integration/passing_step_arguments_spec.rb
184
- - spec/integration/publishing_step_events_spec.rb
185
- - spec/integration/transaction_spec.rb
186
- - spec/integration/transaction_without_steps_spec.rb
187
- - spec/spec_helper.rb
188
- - spec/support/container.rb
189
- - spec/support/database.rb
190
- - spec/support/db_transactions.rb
191
- - spec/support/result_mixin.rb
192
- - spec/support/test_module_constants.rb
193
- - spec/unit/step_adapters/around_spec.rb
194
- - spec/unit/step_adapters/check_spec.rb
195
- - spec/unit/step_adapters/map_spec.rb
196
- - spec/unit/step_adapters/raw_spec.rb
197
- - spec/unit/step_adapters/tee_spec.rb
198
- - spec/unit/step_adapters/try_spec.rb
199
- - spec/unit/step_spec.rb
200
- homepage: https://github.com/dry-rb/dry-transaction
102
+ homepage: https://dry-rb.org/gems/dry-transaction
201
103
  licenses:
202
104
  - MIT
203
- metadata: {}
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
107
+ changelog_uri: https://github.com/dry-rb/dry-transaction/blob/master/CHANGELOG.md
108
+ source_code_uri: https://github.com/dry-rb/dry-transaction
109
+ bug_tracker_uri: https://github.com/dry-rb/dry-transaction/issues
204
110
  post_install_message:
205
111
  rdoc_options: []
206
112
  require_paths:
@@ -209,15 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
115
  requirements:
210
116
  - - ">="
211
117
  - !ruby/object:Gem::Version
212
- version: 2.2.0
118
+ version: 2.5.0
213
119
  required_rubygems_version: !ruby/object:Gem::Requirement
214
120
  requirements:
215
121
  - - ">="
216
122
  - !ruby/object:Gem::Version
217
123
  version: '0'
218
124
  requirements: []
219
- rubyforge_project:
220
- rubygems_version: 2.7.5
125
+ rubygems_version: 3.1.4
221
126
  signing_key:
222
127
  specification_version: 4
223
128
  summary: Business Transaction Flow DSL
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem "simplecov"
7
- gem "codeclimate-test-reporter"
8
- gem "pry-byebug", platform: :mri
9
- gem "dry-container"
10
- end
11
-
12
- group :tools do
13
- gem "pry"
14
- gem "rubocop"
15
- end
@@ -1,97 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- dry-transaction (0.11.1)
5
- dry-container (>= 0.2.8)
6
- dry-events (>= 0.1.0)
7
- dry-matcher (>= 0.7.0)
8
- dry-monads (>= 0.4.0)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- ast (2.3.0)
14
- byebug (9.1.0)
15
- codeclimate-test-reporter (0.5.0)
16
- simplecov (>= 0.7.1, < 1.0.0)
17
- coderay (1.1.1)
18
- concurrent-ruby (1.0.5)
19
- diff-lcs (1.2.5)
20
- docile (1.1.5)
21
- dry-configurable (0.7.0)
22
- concurrent-ruby (~> 1.0)
23
- dry-container (0.6.0)
24
- concurrent-ruby (~> 1.0)
25
- dry-configurable (~> 0.1, >= 0.1.3)
26
- dry-core (0.4.4)
27
- concurrent-ruby (~> 1.0)
28
- dry-equalizer (0.2.0)
29
- dry-events (0.1.0)
30
- concurrent-ruby (~> 1.0)
31
- dry-core (~> 0.4)
32
- dry-equalizer (~> 0.2)
33
- dry-matcher (0.7.0)
34
- dry-monads (0.4.0)
35
- dry-core (~> 0.3, >= 0.3.3)
36
- dry-equalizer
37
- json (1.8.6)
38
- method_source (0.8.2)
39
- parser (2.3.1.4)
40
- ast (~> 2.2)
41
- powerpack (0.1.1)
42
- pry (0.10.3)
43
- coderay (~> 1.1.0)
44
- method_source (~> 0.8.1)
45
- slop (~> 3.4)
46
- pry-byebug (3.5.0)
47
- byebug (~> 9.1)
48
- pry (~> 0.10)
49
- rainbow (2.1.0)
50
- rake (11.2.2)
51
- rspec (3.3.0)
52
- rspec-core (~> 3.3.0)
53
- rspec-expectations (~> 3.3.0)
54
- rspec-mocks (~> 3.3.0)
55
- rspec-core (3.3.2)
56
- rspec-support (~> 3.3.0)
57
- rspec-expectations (3.3.1)
58
- diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.3.0)
60
- rspec-mocks (3.3.2)
61
- diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.3.0)
63
- rspec-support (3.3.0)
64
- rubocop (0.43.0)
65
- parser (>= 2.3.1.1, < 3.0)
66
- powerpack (~> 0.1)
67
- rainbow (>= 1.99.1, < 3.0)
68
- ruby-progressbar (~> 1.7)
69
- unicode-display_width (~> 1.0, >= 1.0.1)
70
- ruby-progressbar (1.8.1)
71
- simplecov (0.10.0)
72
- docile (~> 1.1.0)
73
- json (~> 1.8)
74
- simplecov-html (~> 0.10.0)
75
- simplecov-html (0.10.0)
76
- slop (3.6.0)
77
- unicode-display_width (1.1.1)
78
- yard (0.8.7.6)
79
-
80
- PLATFORMS
81
- ruby
82
-
83
- DEPENDENCIES
84
- bundler (~> 1.15)
85
- codeclimate-test-reporter
86
- dry-container
87
- dry-transaction!
88
- pry
89
- pry-byebug
90
- rake (~> 11.2, >= 11.2.2)
91
- rspec (~> 3.3)
92
- rubocop
93
- simplecov
94
- yard
95
-
96
- BUNDLED WITH
97
- 1.16.1
data/LICENSE.md DELETED
@@ -1,9 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2015-2016 [Icelab](http://icelab.com.au/).
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- require "rspec/core/rake_task"
4
- RSpec::Core::RakeTask.new
5
-
6
- task default: :spec
@@ -1,81 +0,0 @@
1
- example_id | status | run_time |
2
- ----------------------------------------------------------- | ------ | --------------- |
3
- ./spec/integration/around_spec.rb[1:1] | passed | 0.00176 seconds |
4
- ./spec/integration/around_spec.rb[1:2] | passed | 0.00362 seconds |
5
- ./spec/integration/around_spec.rb[1:3] | passed | 0.00089 seconds |
6
- ./spec/integration/around_spec.rb[1:4] | passed | 0.00249 seconds |
7
- ./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.00198 seconds |
8
- ./spec/integration/operation_spec.rb[1:1] | passed | 0.00012 seconds |
9
- ./spec/integration/operation_spec.rb[1:2] | passed | 0.00094 seconds |
10
- ./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00085 seconds |
11
- ./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00061 seconds |
12
- ./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00039 seconds |
13
- ./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00243 seconds |
14
- ./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00068 seconds |
15
- ./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00058 seconds |
16
- ./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00056 seconds |
17
- ./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.0007 seconds |
18
- ./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00077 seconds |
19
- ./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.0006 seconds |
20
- ./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00058 seconds |
21
- ./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00083 seconds |
22
- ./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00062 seconds |
23
- ./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00056 seconds |
24
- ./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00059 seconds |
25
- ./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00098 seconds |
26
- ./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00084 seconds |
27
- ./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00057 seconds |
28
- ./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.00054 seconds |
29
- ./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00086 seconds |
30
- ./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00084 seconds |
31
- ./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00075 seconds |
32
- ./spec/integration/transaction_spec.rb[1:9:2] | passed | 0.00064 seconds |
33
- ./spec/integration/transaction_spec.rb[1:9:3] | passed | 0.00079 seconds |
34
- ./spec/integration/transaction_spec.rb[1:9:4] | passed | 0.00101 seconds |
35
- ./spec/integration/transaction_spec.rb[1:9:5] | passed | 0.00089 seconds |
36
- ./spec/integration/transaction_spec.rb[1:9:6] | passed | 0.00094 seconds |
37
- ./spec/integration/transaction_spec.rb[1:10:1] | passed | 0.00061 seconds |
38
- ./spec/integration/transaction_spec.rb[1:10:2] | passed | 0.00056 seconds |
39
- ./spec/integration/transaction_spec.rb[1:10:3] | passed | 0.0006 seconds |
40
- ./spec/integration/transaction_spec.rb[1:10:4] | passed | 0.00055 seconds |
41
- ./spec/integration/transaction_spec.rb[1:10:5] | passed | 0.00061 seconds |
42
- ./spec/integration/transaction_spec.rb[1:11:1] | passed | 0.00085 seconds |
43
- ./spec/integration/transaction_spec.rb[1:12:1] | passed | 0.00046 seconds |
44
- ./spec/integration/transaction_spec.rb[1:13:1:1:1] | passed | 0.00066 seconds |
45
- ./spec/integration/transaction_spec.rb[1:13:2:1:1] | passed | 0.00064 seconds |
46
- ./spec/integration/transaction_spec.rb[1:13:2:2:1] | passed | 0.00048 seconds |
47
- ./spec/integration/transaction_without_steps_spec.rb[1:1:1] | passed | 0.00268 seconds |
48
- ./spec/integration/transaction_without_steps_spec.rb[1:1:2] | passed | 0.00095 seconds |
49
- ./spec/integration/transaction_without_steps_spec.rb[1:1:3] | passed | 0.00087 seconds |
50
- ./spec/integration/transaction_without_steps_spec.rb[1:1:4] | passed | 0.0008 seconds |
51
- ./spec/integration/transaction_without_steps_spec.rb[1:2:1] | passed | 0.00082 seconds |
52
- ./spec/integration/transaction_without_steps_spec.rb[1:3:1] | passed | 0.00103 seconds |
53
- ./spec/unit/step_adapters/around_spec.rb[1:1:1:1] | passed | 0.00024 seconds |
54
- ./spec/unit/step_adapters/around_spec.rb[1:1:2:1] | passed | 0.00019 seconds |
55
- ./spec/unit/step_adapters/around_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
56
- ./spec/unit/step_adapters/check_spec.rb[1:1:1] | passed | 0.00009 seconds |
57
- ./spec/unit/step_adapters/check_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
58
- ./spec/unit/step_adapters/check_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
59
- ./spec/unit/step_adapters/check_spec.rb[1:1:4:1] | passed | 0.0001 seconds |
60
- ./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.0001 seconds |
61
- ./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
62
- ./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
63
- ./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.0001 seconds |
64
- ./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.0002 seconds |
65
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00013 seconds |
66
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00016 seconds |
67
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00012 seconds |
68
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00015 seconds |
69
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00018 seconds |
70
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2:1] | passed | 0.00011 seconds |
71
- ./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.0002 seconds |
72
- ./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.00054 seconds |
73
- ./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00033 seconds |
74
- ./spec/unit/step_spec.rb[1:1:3:1] | passed | 0.00018 seconds |
75
- ./spec/unit/step_spec.rb[1:1:3:2] | passed | 0.00251 seconds |
76
- ./spec/unit/step_spec.rb[1:1:3:3] | passed | 0.0125 seconds |
77
- ./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.00011 seconds |
78
- ./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00011 seconds |
79
- ./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00014 seconds |
80
- ./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00011 seconds |
81
- ./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00015 seconds |
@@ -1,81 +0,0 @@
1
- RSpec.describe "around steps" do
2
- include_context "db transactions"
3
-
4
- include Dry::Monads::Result::Mixin
5
-
6
- before do
7
- container.instance_exec do
8
- register :validate, -> input { Success(input) }
9
-
10
- register :persist_user do |user:, **other|
11
- self[:database] << [:user, user]
12
- Success(other)
13
- end
14
-
15
- register :persist_account do |account: |
16
- self[:database] << [:account, account]
17
- Success(true)
18
- end
19
- end
20
- end
21
-
22
- let(:transaction) do
23
- Class.new do
24
- include Dry::Transaction(container: Test::Container)
25
-
26
- step :validate
27
- around :transaction
28
- step :persist_user
29
- step :persist_account
30
- step :finalize
31
- end
32
- end
33
-
34
- let(:input) { { user: { name: "Jane" }, account: { balance: 0 } } }
35
-
36
- it "starts a transaction" do
37
- called = false
38
-
39
- finalize = -> x do
40
- called = true
41
- expect(database).to(be_in_transaction)
42
- Success(x)
43
- end
44
-
45
- result = transaction.new(finalize: finalize).call(input)
46
- expect(called).to be true
47
- expect(result).to eql(Success(true))
48
- end
49
-
50
- it "commits transactions" do
51
- transaction.new(finalize: -> x { Success(x) }).call(input)
52
-
53
- expect(database).to be_committed
54
- expect(database).not_to be_rolled_back
55
- expect(database).not_to be_in_transaction
56
- expect(database).to eql([[:user, name: "Jane"],
57
- [:account, balance: 0]])
58
- end
59
-
60
- it "rolls back transactions on failure" do
61
- transaction.new(finalize: -> x { Failure(x) }).call(input)
62
-
63
- expect(database).to be_rolled_back
64
- expect(database).not_to be_in_transaction
65
- expect(database).not_to be_committed
66
- expect(database).to be_empty
67
- end
68
-
69
- it "rolls back transaction on exception" do
70
- uncaught = Class.new(StandardError)
71
-
72
- expect {
73
- transaction.new(finalize: -> x { raise uncaught }).call(input)
74
- }.to raise_error(uncaught)
75
-
76
- expect(database).to be_rolled_back
77
- expect(database).not_to be_in_transaction
78
- expect(database).not_to be_committed
79
- expect(database).to be_empty
80
- end
81
- end