dry-transaction 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/dry/transaction/step_adapters/check.rb +1 -1
- data/lib/dry/transaction/version.rb +1 -1
- data/spec/examples.txt +76 -74
- data/spec/integration/auto_injection_spec.rb +32 -0
- data/spec/integration/transaction_spec.rb +83 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276cf0f224a91609346da41546c856d66b812f170e1cefdf955b47bbcd026be4
|
4
|
+
data.tar.gz: 0c221a299d6fbd3827444f1dae381ba939660562c9c7faad3e8f1c413ea8f8d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60e0c3811eaa55ba407af65b383801e7a51ca27cae32bd8957fdb43b96896b8ff6020c60a49e4cbc6f7121655ae14d61269573226ad64cf24e6e828b9245be4b
|
7
|
+
data.tar.gz: 3ca91483d02fde42afac52df0dcf22aeef1b11d6325f923f7267de7c238df6b66070850582c865a4229449d2f7341b6a38dfe8c7d9f277b796523147f78f7b80
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dry-transaction (0.11.
|
4
|
+
dry-transaction (0.11.2)
|
5
5
|
dry-container (>= 0.2.8)
|
6
6
|
dry-events (>= 0.1.0)
|
7
7
|
dry-matcher (>= 0.7.0)
|
@@ -23,7 +23,7 @@ GEM
|
|
23
23
|
dry-container (0.6.0)
|
24
24
|
concurrent-ruby (~> 1.0)
|
25
25
|
dry-configurable (~> 0.1, >= 0.1.3)
|
26
|
-
dry-core (0.4.
|
26
|
+
dry-core (0.4.5)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
28
|
dry-equalizer (0.2.0)
|
29
29
|
dry-events (0.1.0)
|
data/spec/examples.txt
CHANGED
@@ -1,81 +1,83 @@
|
|
1
1
|
example_id | status | run_time |
|
2
2
|
----------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/integration/around_spec.rb[1:1] | passed | 0.
|
4
|
-
./spec/integration/around_spec.rb[1:2] | passed | 0.
|
5
|
-
./spec/integration/around_spec.rb[1:3] | passed | 0.
|
6
|
-
./spec/integration/around_spec.rb[1:4] | passed | 0.
|
7
|
-
./spec/integration/
|
8
|
-
./spec/integration/
|
9
|
-
./spec/integration/operation_spec.rb[1:
|
10
|
-
./spec/integration/
|
11
|
-
./spec/integration/passing_step_arguments_spec.rb[1:
|
12
|
-
./spec/integration/passing_step_arguments_spec.rb[1:
|
13
|
-
./spec/integration/
|
14
|
-
./spec/integration/publishing_step_events_spec.rb[1:1:
|
15
|
-
./spec/integration/publishing_step_events_spec.rb[1:2
|
16
|
-
./spec/integration/publishing_step_events_spec.rb[1:2:
|
17
|
-
./spec/integration/publishing_step_events_spec.rb[1:
|
18
|
-
./spec/integration/publishing_step_events_spec.rb[1:3:
|
19
|
-
./spec/integration/
|
20
|
-
./spec/integration/transaction_spec.rb[1:1:
|
21
|
-
./spec/integration/transaction_spec.rb[1:1:
|
22
|
-
./spec/integration/transaction_spec.rb[1:1:
|
23
|
-
./spec/integration/transaction_spec.rb[1:1:
|
24
|
-
./spec/integration/transaction_spec.rb[1:
|
25
|
-
./spec/integration/transaction_spec.rb[1:
|
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:
|
32
|
-
./spec/integration/transaction_spec.rb[1:9:
|
33
|
-
./spec/integration/transaction_spec.rb[1:9:
|
34
|
-
./spec/integration/transaction_spec.rb[1:9:
|
35
|
-
./spec/integration/transaction_spec.rb[1:9:
|
36
|
-
./spec/integration/transaction_spec.rb[1:9:
|
37
|
-
./spec/integration/transaction_spec.rb[1:
|
38
|
-
./spec/integration/transaction_spec.rb[1:10:
|
39
|
-
./spec/integration/transaction_spec.rb[1:10:
|
40
|
-
./spec/integration/transaction_spec.rb[1:10:
|
41
|
-
./spec/integration/transaction_spec.rb[1:10:
|
42
|
-
./spec/integration/transaction_spec.rb[1:
|
43
|
-
./spec/integration/transaction_spec.rb[1:
|
44
|
-
./spec/integration/transaction_spec.rb[1:
|
45
|
-
./spec/integration/transaction_spec.rb[1:13:
|
46
|
-
./spec/integration/transaction_spec.rb[1:13:2:
|
47
|
-
./spec/integration/
|
48
|
-
./spec/integration/transaction_without_steps_spec.rb[1:1:
|
49
|
-
./spec/integration/transaction_without_steps_spec.rb[1:1:
|
50
|
-
./spec/integration/transaction_without_steps_spec.rb[1:1:
|
51
|
-
./spec/integration/transaction_without_steps_spec.rb[1:
|
52
|
-
./spec/integration/transaction_without_steps_spec.rb[1:
|
53
|
-
./spec/
|
54
|
-
./spec/
|
3
|
+
./spec/integration/around_spec.rb[1:1] | passed | 0.00079 seconds |
|
4
|
+
./spec/integration/around_spec.rb[1:2] | passed | 0.00071 seconds |
|
5
|
+
./spec/integration/around_spec.rb[1:3] | passed | 0.00082 seconds |
|
6
|
+
./spec/integration/around_spec.rb[1:4] | passed | 0.00085 seconds |
|
7
|
+
./spec/integration/auto_injection_spec.rb[1:1] | failed | 0.001 seconds |
|
8
|
+
./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.0007 seconds |
|
9
|
+
./spec/integration/operation_spec.rb[1:1] | passed | 0.00245 seconds |
|
10
|
+
./spec/integration/operation_spec.rb[1:2] | passed | 0.0011 seconds |
|
11
|
+
./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00056 seconds |
|
12
|
+
./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00048 seconds |
|
13
|
+
./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00037 seconds |
|
14
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00054 seconds |
|
15
|
+
./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00055 seconds |
|
16
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00059 seconds |
|
17
|
+
./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.0006 seconds |
|
18
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.0009 seconds |
|
19
|
+
./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00105 seconds |
|
20
|
+
./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00063 seconds |
|
21
|
+
./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.00066 seconds |
|
22
|
+
./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00093 seconds |
|
23
|
+
./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00068 seconds |
|
24
|
+
./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00066 seconds |
|
25
|
+
./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00066 seconds |
|
26
|
+
./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00243 seconds |
|
27
|
+
./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00065 seconds |
|
28
|
+
./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00058 seconds |
|
29
|
+
./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.00071 seconds |
|
30
|
+
./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00055 seconds |
|
31
|
+
./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00052 seconds |
|
32
|
+
./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00081 seconds |
|
33
|
+
./spec/integration/transaction_spec.rb[1:9:2] | passed | 0.00074 seconds |
|
34
|
+
./spec/integration/transaction_spec.rb[1:9:3] | passed | 0.00083 seconds |
|
35
|
+
./spec/integration/transaction_spec.rb[1:9:4] | passed | 0.00082 seconds |
|
36
|
+
./spec/integration/transaction_spec.rb[1:9:5] | passed | 0.00066 seconds |
|
37
|
+
./spec/integration/transaction_spec.rb[1:9:6] | passed | 0.00069 seconds |
|
38
|
+
./spec/integration/transaction_spec.rb[1:10:1] | passed | 0.00078 seconds |
|
39
|
+
./spec/integration/transaction_spec.rb[1:10:2] | passed | 0.00087 seconds |
|
40
|
+
./spec/integration/transaction_spec.rb[1:10:3] | passed | 0.00076 seconds |
|
41
|
+
./spec/integration/transaction_spec.rb[1:10:4] | passed | 0.00096 seconds |
|
42
|
+
./spec/integration/transaction_spec.rb[1:10:5] | passed | 0.00076 seconds |
|
43
|
+
./spec/integration/transaction_spec.rb[1:11:1] | passed | 0.00074 seconds |
|
44
|
+
./spec/integration/transaction_spec.rb[1:12:1] | passed | 0.00056 seconds |
|
45
|
+
./spec/integration/transaction_spec.rb[1:13:1:1:1] | passed | 0.00043 seconds |
|
46
|
+
./spec/integration/transaction_spec.rb[1:13:2:1:1] | passed | 0.00038 seconds |
|
47
|
+
./spec/integration/transaction_spec.rb[1:13:2:2:1] | passed | 0.00047 seconds |
|
48
|
+
./spec/integration/transaction_without_steps_spec.rb[1:1:1] | passed | 0.00205 seconds |
|
49
|
+
./spec/integration/transaction_without_steps_spec.rb[1:1:2] | passed | 0.00177 seconds |
|
50
|
+
./spec/integration/transaction_without_steps_spec.rb[1:1:3] | passed | 0.00076 seconds |
|
51
|
+
./spec/integration/transaction_without_steps_spec.rb[1:1:4] | passed | 0.00059 seconds |
|
52
|
+
./spec/integration/transaction_without_steps_spec.rb[1:2:1] | passed | 0.00088 seconds |
|
53
|
+
./spec/integration/transaction_without_steps_spec.rb[1:3:1] | passed | 0.00061 seconds |
|
54
|
+
./spec/integration/user_class_hierarchy_spec.rb[1:1:1] | passed | 0.00192 seconds |
|
55
|
+
./spec/unit/step_adapters/around_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
|
56
|
+
./spec/unit/step_adapters/around_spec.rb[1:1:2:1] | passed | 0.00016 seconds |
|
55
57
|
./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.
|
58
|
+
./spec/unit/step_adapters/check_spec.rb[1:1:1] | passed | 0.00063 seconds |
|
57
59
|
./spec/unit/step_adapters/check_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
|
58
60
|
./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.
|
60
|
-
./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.
|
61
|
+
./spec/unit/step_adapters/check_spec.rb[1:1:4:1] | passed | 0.00011 seconds |
|
62
|
+
./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00009 seconds |
|
61
63
|
./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.
|
64
|
+
./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00015 seconds |
|
63
65
|
./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.
|
65
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.
|
66
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.
|
67
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.
|
68
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.
|
69
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.
|
70
|
-
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2:1] | passed | 0.
|
71
|
-
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.
|
72
|
-
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.
|
73
|
-
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.
|
74
|
-
./spec/unit/step_spec.rb[1:1:3:1] | passed | 0.
|
75
|
-
./spec/unit/step_spec.rb[1:1:3:2] | passed | 0.
|
76
|
-
./spec/unit/step_spec.rb[1:1:3:3] | passed | 0.
|
77
|
-
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.
|
78
|
-
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.
|
79
|
-
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.
|
80
|
-
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.
|
81
|
-
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.
|
66
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.0017 seconds |
|
67
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00012 seconds |
|
68
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00013 seconds |
|
69
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00015 seconds |
|
70
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00011 seconds |
|
71
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.0001 seconds |
|
72
|
+
./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2:1] | passed | 0.0001 seconds |
|
73
|
+
./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.00022 seconds |
|
74
|
+
./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.00044 seconds |
|
75
|
+
./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00239 seconds |
|
76
|
+
./spec/unit/step_spec.rb[1:1:3:1] | passed | 0.00026 seconds |
|
77
|
+
./spec/unit/step_spec.rb[1:1:3:2] | passed | 0.00177 seconds |
|
78
|
+
./spec/unit/step_spec.rb[1:1:3:3] | passed | 0.01264 seconds |
|
79
|
+
./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.00009 seconds |
|
80
|
+
./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
|
81
|
+
./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00016 seconds |
|
82
|
+
./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00014 seconds |
|
83
|
+
./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00012 seconds |
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "dry-monads"
|
2
|
+
require "dry-auto_inject"
|
3
|
+
|
4
|
+
RSpec.describe "Using dry-auto_inject" do
|
5
|
+
let(:transaction) {
|
6
|
+
Class.new do
|
7
|
+
include Dry::Transaction(container: Test::Container)
|
8
|
+
include Test::Inject[:extract_email]
|
9
|
+
|
10
|
+
step :symbolize
|
11
|
+
|
12
|
+
def call(input)
|
13
|
+
super(input).bind(extract_email)
|
14
|
+
end
|
15
|
+
end.new
|
16
|
+
}
|
17
|
+
|
18
|
+
before do
|
19
|
+
module Test
|
20
|
+
Container = {
|
21
|
+
symbolize: -> input { Dry::Monads::Right(name: input["name"], email: input["email"]) },
|
22
|
+
extract_email: -> input { Dry::Monads::Right(email: input[:email]) },
|
23
|
+
}
|
24
|
+
|
25
|
+
Inject = Dry::AutoInject(container: Container)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "support auto-injection of dependencies alongside step operations" do
|
30
|
+
expect(transaction.("name" => "Jane", "email" => "jane@example.com").value).to eq(email: "jane@example.com")
|
31
|
+
end
|
32
|
+
end
|
@@ -159,6 +159,89 @@ RSpec.describe "Transactions" do
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
162
|
+
context "operation injection of step only defined in the transaction class not in the container" do
|
163
|
+
let(:transaction) do
|
164
|
+
Class.new do
|
165
|
+
include Dry::Transaction
|
166
|
+
|
167
|
+
step :process
|
168
|
+
|
169
|
+
def process(input)
|
170
|
+
new_input = input << :world
|
171
|
+
super(new_input)
|
172
|
+
end
|
173
|
+
end.new(**dependencies)
|
174
|
+
end
|
175
|
+
|
176
|
+
let(:dependencies) do
|
177
|
+
{process: -> input { Failure(input)} }
|
178
|
+
end
|
179
|
+
|
180
|
+
it "execute the transaction and execute the injected operation" do
|
181
|
+
result = transaction.call([:hello])
|
182
|
+
|
183
|
+
expect(result).to eq (Failure([:hello, :world]))
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "operation injection of step without container and no transaction instance methods" do
|
188
|
+
let(:transaction) do
|
189
|
+
Class.new do
|
190
|
+
include Dry::Transaction
|
191
|
+
|
192
|
+
map :process
|
193
|
+
step :verify
|
194
|
+
try :validate, catch: Test::NotValidError
|
195
|
+
tee :persist
|
196
|
+
|
197
|
+
end.new(**dependencies)
|
198
|
+
end
|
199
|
+
|
200
|
+
let(:dependencies) do
|
201
|
+
{
|
202
|
+
process: -> input { {name: input["name"], email: input["email"]} },
|
203
|
+
verify: -> input { Success(input) },
|
204
|
+
validate: -> input { input[:email].nil? ? raise(Test::NotValidError, "email required") : input },
|
205
|
+
persist: -> input { database << input and true }
|
206
|
+
}
|
207
|
+
end
|
208
|
+
|
209
|
+
let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
|
210
|
+
|
211
|
+
it "calls the injected operations" do
|
212
|
+
transaction.call(input)
|
213
|
+
expect(database).to include(name: "Jane", email: "jane@doe.com")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "operation injection of step without container and no transaction instance methods but missing an injected operation" do
|
218
|
+
let(:transaction) do
|
219
|
+
Class.new do
|
220
|
+
include Dry::Transaction
|
221
|
+
|
222
|
+
map :process
|
223
|
+
step :verify
|
224
|
+
try :validate, catch: Test::NotValidError
|
225
|
+
tee :persist
|
226
|
+
|
227
|
+
end.new(**dependencies)
|
228
|
+
end
|
229
|
+
|
230
|
+
let(:dependencies) do
|
231
|
+
{
|
232
|
+
process: -> input { {name: input["name"], email: input["email"]} },
|
233
|
+
verify: -> input { Success(input) },
|
234
|
+
validate: -> input { input[:email].nil? ? raise(Test::NotValidError, "email required") : input }
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
|
239
|
+
|
240
|
+
it "raises an exception" do
|
241
|
+
expect { transaction }.to raise_error(Dry::Transaction::MissingStepError)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
162
245
|
context "local step definition" do
|
163
246
|
let(:transaction) do
|
164
247
|
Class.new 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.11.
|
4
|
+
version: 0.11.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: 2018-
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/dry/transaction/version.rb
|
179
179
|
- spec/examples.txt
|
180
180
|
- spec/integration/around_spec.rb
|
181
|
+
- spec/integration/auto_injection_spec.rb
|
181
182
|
- spec/integration/custom_step_adapters_spec.rb
|
182
183
|
- spec/integration/operation_spec.rb
|
183
184
|
- spec/integration/passing_step_arguments_spec.rb
|