dry-transaction 0.12.1 → 0.13.0

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
  SHA256:
3
- metadata.gz: b7411e4fbbd3d2e8d7759a51edc217763e2e0de002d42cced4ba43625d1818e8
4
- data.tar.gz: 7fd3abc78aad520b6a980853a13727c26de21021bad9c6db824c8e287ec85ec2
3
+ metadata.gz: 901e6ca3954acdc46da017a77ceb17014e0c5728d216fbf80b97995d9be03164
4
+ data.tar.gz: 501e37cccc173d5be0f654f5e4606c9d2db4e4737c0e004c569bab1bbadd04bd
5
5
  SHA512:
6
- metadata.gz: 2876c89f0b31df3734314c3e6ce1541cb451ae54d891296d4546ae16dcd0e7fcd8b971dab31cc779a47406847b238c4fbfe6ca76a10eadf638e0005526c63b93
7
- data.tar.gz: 64d23944e110e9a42f43c0f1c686be199fe53ea5dcaae8a9e984fbab29eda35c9badbc85edf15c694a8bdd4669db10460edc2fab9201c9a0b194bd2dc8800efc
6
+ metadata.gz: bcad8d5346e432e465310eeba9d79c32c2d2df024baf8d752ef5d2ad054685652f1851e3e55ec42d3937563dbaec2b93acd4f6a93e5e40d6cadee66332c6f80d
7
+ data.tar.gz: 6ff93e764b43ff80a578c2bb775a9a2d1db41a86b617ad2e62ffbcddef4bde69ba95bb8387824a2c96150d4729f0b7c80ab5464e87b4b29f2717ed05d383c246
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-transaction (0.12.1)
4
+ dry-transaction (0.13.0)
5
5
  dry-container (>= 0.2.8)
6
6
  dry-events (>= 0.1.0)
7
7
  dry-matcher (>= 0.7.0)
@@ -24,16 +24,16 @@ module Dry
24
24
 
25
25
  def define_dsl
26
26
  module_exec(@step_adapters) do |step_adapters|
27
- step_adapters.keys.each do |adapter_name|
27
+ step_adapters.each do |adapter_name, adapter|
28
28
  define_method(adapter_name) do |step_name, with: nil, **options|
29
- operation_name = with || step_name
29
+ operation_name = with
30
30
 
31
31
  steps << Step.new(
32
- step_adapters[adapter_name],
33
- step_name,
34
- operation_name,
35
- nil, # operations are resolved only when transactions are instantiated
36
- options,
32
+ adapter: adapter,
33
+ name: step_name,
34
+ operation_name: operation_name,
35
+ operation: nil, # operations are resolved only when transactions are instantiated
36
+ options: options,
37
37
  )
38
38
  end
39
39
  end
@@ -42,7 +42,7 @@ module Dry
42
42
 
43
43
  if listeners.is_a?(Hash)
44
44
  listeners.each do |step_name, listener|
45
- steps.detect { |step| step.step_name == step_name }.subscribe(listener)
45
+ steps.detect { |step| step.name == step_name }.subscribe(listener)
46
46
  end
47
47
  else
48
48
  steps.each do |step|
@@ -55,8 +55,8 @@ module Dry
55
55
  assert_valid_step_args(step_args)
56
56
 
57
57
  new_steps = steps.map { |step|
58
- if step_args[step.step_name]
59
- step.with(call_args: step_args[step.step_name])
58
+ if step_args[step.name]
59
+ step.with(call_args: step_args[step.name])
60
60
  else
61
61
  step
62
62
  end
@@ -68,34 +68,36 @@ module Dry
68
68
  private
69
69
 
70
70
  def respond_to_missing?(name, _include_private = false)
71
- steps.any? { |step| step.step_name == name }
71
+ steps.any? { |step| step.name == name }
72
72
  end
73
73
 
74
74
  def method_missing(name, *args, &block)
75
- step = steps.detect { |s| s.step_name == name }
75
+ step = steps.detect { |s| s.name == name }
76
76
  super unless step
77
77
 
78
- operation = operations[step.step_name]
79
- raise NotImplementedError, "no operation +#{step.operation_name}+ defined for step +#{step.step_name}+" unless operation
78
+ operation = operations[step.name]
79
+ raise NotImplementedError, "no operation +#{step.operation_name}+ defined for step +#{step.name}+" unless operation
80
80
 
81
81
  operation.(*args, &block)
82
82
  end
83
83
 
84
84
  def resolve_operation(step, **operations)
85
- if methods.include?(step.step_name) || private_methods.include?(step.step_name)
86
- method(step.step_name)
87
- elsif operations[step.step_name].nil?
88
- raise MissingStepError.new(step.step_name)
89
- elsif operations[step.step_name].respond_to?(:call)
90
- operations[step.step_name]
85
+ if step.internal? && operations[step.name]
86
+ operations[step.name]
87
+ elsif methods.include?(step.name) || private_methods.include?(step.name)
88
+ method(step.name)
89
+ elsif operations[step.name].respond_to?(:call)
90
+ operations[step.name]
91
+ elsif operations[step.name]
92
+ raise InvalidStepError.new(step.name)
91
93
  else
92
- raise InvalidStepError.new(step.step_name)
94
+ raise MissingStepError.new(step.name)
93
95
  end
94
96
  end
95
97
 
96
98
  def assert_valid_step_args(step_args)
97
99
  step_args.each_key do |step_name|
98
- unless steps.any? { |step| step.step_name == step_name }
100
+ unless steps.any? { |step| step.name == step_name }
99
101
  raise ArgumentError, "+#{step_name}+ is not a valid step name"
100
102
  end
101
103
  end
@@ -107,7 +109,7 @@ module Dry
107
109
  num_args_supplied = step.call_args.length + 1 # add 1 for main `input`
108
110
 
109
111
  if num_args_required > num_args_supplied
110
- raise ArgumentError, "not enough arguments supplied for step +#{step.step_name}+"
112
+ raise ArgumentError, "not enough arguments supplied for step +#{step.name}+"
111
113
  end
112
114
  end
113
115
  end
@@ -5,7 +5,7 @@ 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.name) {
9
9
  if ops_container && ops_container.key?(step.operation_name)
10
10
  ops_container[step.operation_name]
11
11
  else
@@ -13,7 +13,7 @@ module Dry
13
13
  end
14
14
  }
15
15
 
16
- [step.step_name, operation]
16
+ [step.name, operation]
17
17
  }.to_h
18
18
 
19
19
  super(**kwargs, **operation_kwargs)
@@ -10,7 +10,7 @@ module Dry
10
10
  failure: Dry::Matcher::Case.new(
11
11
  match: -> result, step_name = nil {
12
12
  if step_name
13
- result.failure? && result.failure.step.step_name == step_name
13
+ result.failure? && result.failure.step.name == step_name
14
14
  else
15
15
  result.failure?
16
16
  end
@@ -17,14 +17,14 @@ module Dry
17
17
  register_event(:step_succeeded)
18
18
  register_event(:step_failed)
19
19
 
20
- attr_reader :step_adapter
21
- attr_reader :step_name
20
+ attr_reader :adapter
21
+ attr_reader :name
22
22
  attr_reader :operation_name
23
23
  attr_reader :call_args
24
24
 
25
- def initialize(step_adapter, step_name, operation_name, operation, options, call_args = [])
26
- @step_adapter = StepAdapter[step_adapter, operation, **options, step_name: step_name, operation_name: operation_name]
27
- @step_name = step_name
25
+ def initialize(adapter:, name:, operation_name:, operation: nil, options:, call_args: [])
26
+ @adapter = StepAdapter[adapter, operation, **options, step_name: name, operation_name: operation_name]
27
+ @name = name
28
28
  @operation_name = operation_name
29
29
  @call_args = call_args
30
30
  end
@@ -32,50 +32,58 @@ module Dry
32
32
  def with(operation: UNDEFINED, call_args: UNDEFINED)
33
33
  return self if operation == UNDEFINED && call_args == UNDEFINED
34
34
 
35
- new_operation = operation == UNDEFINED ? step_adapter.operation : operation
35
+ new_operation = operation == UNDEFINED ? adapter.operation : operation
36
36
  new_call_args = call_args == UNDEFINED ? self.call_args : Array(call_args)
37
37
 
38
38
  self.class.new(
39
- step_adapter,
40
- step_name,
41
- operation_name,
42
- new_operation,
43
- step_adapter.options,
44
- new_call_args
39
+ adapter: adapter,
40
+ name: name,
41
+ operation_name: operation_name,
42
+ operation: new_operation,
43
+ options: adapter.options,
44
+ call_args: new_call_args,
45
45
  )
46
46
  end
47
47
 
48
48
  def call(input, continue = RETURN)
49
49
  args = [input, *call_args]
50
50
 
51
- if step_adapter.yields?
52
- with_broadcast(args) { step_adapter.(args, &continue) }
51
+ if adapter.yields?
52
+ with_broadcast(args) { adapter.(args, &continue) }
53
53
  else
54
- continue.(with_broadcast(args) { step_adapter.(args) })
54
+ continue.(with_broadcast(args) { adapter.(args) })
55
55
  end
56
56
  end
57
57
 
58
58
  def with_broadcast(args)
59
- publish(:step, step_name: step_name, args: args)
59
+ publish(:step, step_name: name, args: args)
60
60
 
61
61
  yield.fmap { |value|
62
- publish(:step_succeeded, step_name: step_name, args: args, value: value)
62
+ publish(:step_succeeded, step_name: name, args: args, value: value)
63
63
  value
64
64
  }.or { |value|
65
65
  Failure(
66
66
  StepFailure.(self, value) {
67
- publish(:step_failed, step_name: step_name, args: args, value: value)
67
+ publish(:step_failed, step_name: name, args: args, value: value)
68
68
  }
69
69
  )
70
70
  }
71
71
  end
72
72
 
73
+ def internal?
74
+ !external?
75
+ end
76
+
77
+ def external?
78
+ !!operation_name
79
+ end
80
+
73
81
  def arity
74
- step_adapter.operation.arity
82
+ adapter.operation.arity
75
83
  end
76
84
 
77
85
  def operation
78
- step_adapter.operation
86
+ adapter.operation
79
87
  end
80
88
  end
81
89
  end
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  # Business transaction DSL.
3
3
  module Transaction
4
- VERSION = "0.12.1".freeze
4
+ VERSION = "0.13.0".freeze
5
5
  end
6
6
  end
@@ -1,87 +1,88 @@
1
1
  example_id | status | run_time |
2
2
  ----------------------------------------------------------- | ------ | --------------- |
3
- ./spec/integration/around_spec.rb[1:1] | passed | 0.00221 seconds |
4
- ./spec/integration/around_spec.rb[1:2] | passed | 0.00168 seconds |
5
- ./spec/integration/around_spec.rb[1:3] | passed | 0.00085 seconds |
6
- ./spec/integration/around_spec.rb[1:4] | passed | 0.00301 seconds |
7
- ./spec/integration/around_spec.rb[1:5] | passed | 0.00093 seconds |
8
- ./spec/integration/around_spec.rb[1:6:1] | passed | 0.00078 seconds |
3
+ ./spec/integration/around_spec.rb[1:1] | passed | 0.00234 seconds |
4
+ ./spec/integration/around_spec.rb[1:2] | passed | 0.00095 seconds |
5
+ ./spec/integration/around_spec.rb[1:3] | passed | 0.00149 seconds |
6
+ ./spec/integration/around_spec.rb[1:4] | passed | 0.00118 seconds |
7
+ ./spec/integration/around_spec.rb[1:5] | passed | 0.00104 seconds |
8
+ ./spec/integration/around_spec.rb[1:6:1] | passed | 0.00096 seconds |
9
9
  ./spec/integration/auto_injection_spec.rb[1:1] | failed | 0.00149 seconds |
10
- ./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.0008 seconds |
11
- ./spec/integration/operation_spec.rb[1:1] | passed | 0.00012 seconds |
12
- ./spec/integration/operation_spec.rb[1:2] | passed | 0.00015 seconds |
13
- ./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00201 seconds |
14
- ./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00062 seconds |
15
- ./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00058 seconds |
16
- ./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00062 seconds |
17
- ./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.00058 seconds |
18
- ./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00065 seconds |
19
- ./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00055 seconds |
20
- ./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.00083 seconds |
21
- ./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00125 seconds |
22
- ./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.00083 seconds |
23
- ./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.0008 seconds |
24
- ./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00069 seconds |
25
- ./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00076 seconds |
26
- ./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00077 seconds |
27
- ./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00071 seconds |
28
- ./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00067 seconds |
29
- ./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00091 seconds |
30
- ./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00063 seconds |
31
- ./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.0005 seconds |
32
- ./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00105 seconds |
33
- ./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00064 seconds |
34
- ./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00105 seconds |
35
- ./spec/integration/transaction_spec.rb[1:10:1] | passed | 0.001 seconds |
36
- ./spec/integration/transaction_spec.rb[1:11:1] | passed | 0.00056 seconds |
37
- ./spec/integration/transaction_spec.rb[1:12:1] | passed | 0.00081 seconds |
38
- ./spec/integration/transaction_spec.rb[1:12:2] | passed | 0.00079 seconds |
39
- ./spec/integration/transaction_spec.rb[1:12:3] | passed | 0.00069 seconds |
40
- ./spec/integration/transaction_spec.rb[1:12:4] | passed | 0.00081 seconds |
41
- ./spec/integration/transaction_spec.rb[1:12:5] | passed | 0.00083 seconds |
42
- ./spec/integration/transaction_spec.rb[1:12:6] | passed | 0.00083 seconds |
43
- ./spec/integration/transaction_spec.rb[1:13:1] | passed | 0.00068 seconds |
44
- ./spec/integration/transaction_spec.rb[1:13:2] | passed | 0.00074 seconds |
45
- ./spec/integration/transaction_spec.rb[1:13:3] | passed | 0.00067 seconds |
46
- ./spec/integration/transaction_spec.rb[1:13:4] | passed | 0.00066 seconds |
47
- ./spec/integration/transaction_spec.rb[1:13:5] | passed | 0.00073 seconds |
48
- ./spec/integration/transaction_spec.rb[1:14:1] | passed | 0.00128 seconds |
49
- ./spec/integration/transaction_spec.rb[1:15:1] | passed | 0.00081 seconds |
50
- ./spec/integration/transaction_spec.rb[1:16:1:1:1] | passed | 0.00087 seconds |
51
- ./spec/integration/transaction_spec.rb[1:16:2:1:1] | passed | 0.00089 seconds |
52
- ./spec/integration/transaction_spec.rb[1:16:2:2:1] | passed | 0.00102 seconds |
53
- ./spec/integration/transaction_without_steps_spec.rb[1:1:1] | passed | 0.00232 seconds |
54
- ./spec/integration/transaction_without_steps_spec.rb[1:1:2] | passed | 0.00176 seconds |
55
- ./spec/integration/transaction_without_steps_spec.rb[1:1:3] | passed | 0.00187 seconds |
56
- ./spec/integration/transaction_without_steps_spec.rb[1:1:4] | passed | 0.00294 seconds |
57
- ./spec/integration/transaction_without_steps_spec.rb[1:2:1] | passed | 0.00107 seconds |
58
- ./spec/integration/transaction_without_steps_spec.rb[1:3:1] | passed | 0.00097 seconds |
59
- ./spec/unit/step_adapters/around_spec.rb[1:1:1:1] | passed | 0.00014 seconds |
60
- ./spec/unit/step_adapters/around_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
61
- ./spec/unit/step_adapters/around_spec.rb[1:1:3:1] | passed | 0.00009 seconds |
62
- ./spec/unit/step_adapters/check_spec.rb[1:1:1] | passed | 0.00009 seconds |
63
- ./spec/unit/step_adapters/check_spec.rb[1:1:2:1] | passed | 0.00009 seconds |
64
- ./spec/unit/step_adapters/check_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
10
+ ./spec/integration/custom_step_adapters_spec.rb[1:1] | passed | 0.00372 seconds |
11
+ ./spec/integration/operation_spec.rb[1:1] | passed | 0.00013 seconds |
12
+ ./spec/integration/operation_spec.rb[1:2] | passed | 0.00014 seconds |
13
+ ./spec/integration/passing_step_arguments_spec.rb[1:1:1] | passed | 0.00063 seconds |
14
+ ./spec/integration/passing_step_arguments_spec.rb[1:2:1] | passed | 0.00072 seconds |
15
+ ./spec/integration/passing_step_arguments_spec.rb[1:3:1] | passed | 0.00038 seconds |
16
+ ./spec/integration/publishing_step_events_spec.rb[1:1:1] | passed | 0.00057 seconds |
17
+ ./spec/integration/publishing_step_events_spec.rb[1:1:2] | passed | 0.0007 seconds |
18
+ ./spec/integration/publishing_step_events_spec.rb[1:2:1] | passed | 0.00054 seconds |
19
+ ./spec/integration/publishing_step_events_spec.rb[1:2:2] | passed | 0.00052 seconds |
20
+ ./spec/integration/publishing_step_events_spec.rb[1:3:1] | passed | 0.00075 seconds |
21
+ ./spec/integration/publishing_step_events_spec.rb[1:3:2] | passed | 0.00071 seconds |
22
+ ./spec/integration/transaction_spec.rb[1:1:1] | passed | 0.0006 seconds |
23
+ ./spec/integration/transaction_spec.rb[1:1:2] | passed | 0.0006 seconds |
24
+ ./spec/integration/transaction_spec.rb[1:1:3] | passed | 0.00058 seconds |
25
+ ./spec/integration/transaction_spec.rb[1:1:4] | passed | 0.00072 seconds |
26
+ ./spec/integration/transaction_spec.rb[1:1:5] | passed | 0.00058 seconds |
27
+ ./spec/integration/transaction_spec.rb[1:2:1] | passed | 0.00075 seconds |
28
+ ./spec/integration/transaction_spec.rb[1:3:1] | passed | 0.00055 seconds |
29
+ ./spec/integration/transaction_spec.rb[1:4:1] | passed | 0.00055 seconds |
30
+ ./spec/integration/transaction_spec.rb[1:5:1] | passed | 0.00059 seconds |
31
+ ./spec/integration/transaction_spec.rb[1:6:1] | passed | 0.00043 seconds |
32
+ ./spec/integration/transaction_spec.rb[1:7:1] | passed | 0.00047 seconds |
33
+ ./spec/integration/transaction_spec.rb[1:8:1] | passed | 0.00043 seconds |
34
+ ./spec/integration/transaction_spec.rb[1:9:1] | passed | 0.00068 seconds |
35
+ ./spec/integration/transaction_spec.rb[1:10:1] | passed | 0.00052 seconds |
36
+ ./spec/integration/transaction_spec.rb[1:11:1] | passed | 0.00053 seconds |
37
+ ./spec/integration/transaction_spec.rb[1:11:2] | passed | 0.00047 seconds |
38
+ ./spec/integration/transaction_spec.rb[1:12:1] | passed | 0.00065 seconds |
39
+ ./spec/integration/transaction_spec.rb[1:12:2] | passed | 0.00062 seconds |
40
+ ./spec/integration/transaction_spec.rb[1:12:3] | passed | 0.00066 seconds |
41
+ ./spec/integration/transaction_spec.rb[1:12:4] | passed | 0.00063 seconds |
42
+ ./spec/integration/transaction_spec.rb[1:12:5] | passed | 0.0006 seconds |
43
+ ./spec/integration/transaction_spec.rb[1:12:6] | passed | 0.00063 seconds |
44
+ ./spec/integration/transaction_spec.rb[1:13:1] | passed | 0.00076 seconds |
45
+ ./spec/integration/transaction_spec.rb[1:13:2] | passed | 0.0007 seconds |
46
+ ./spec/integration/transaction_spec.rb[1:13:3] | passed | 0.00198 seconds |
47
+ ./spec/integration/transaction_spec.rb[1:13:4] | passed | 0.00065 seconds |
48
+ ./spec/integration/transaction_spec.rb[1:13:5] | passed | 0.00068 seconds |
49
+ ./spec/integration/transaction_spec.rb[1:14:1] | passed | 0.00055 seconds |
50
+ ./spec/integration/transaction_spec.rb[1:15:1] | passed | 0.00042 seconds |
51
+ ./spec/integration/transaction_spec.rb[1:16:1:1:1] | passed | 0.0004 seconds |
52
+ ./spec/integration/transaction_spec.rb[1:16:2:1:1] | passed | 0.00037 seconds |
53
+ ./spec/integration/transaction_spec.rb[1:16:2:2:1] | passed | 0.00042 seconds |
54
+ ./spec/integration/transaction_without_steps_spec.rb[1:1:1] | passed | 0.00066 seconds |
55
+ ./spec/integration/transaction_without_steps_spec.rb[1:1:2] | passed | 0.0007 seconds |
56
+ ./spec/integration/transaction_without_steps_spec.rb[1:1:3] | passed | 0.00072 seconds |
57
+ ./spec/integration/transaction_without_steps_spec.rb[1:1:4] | passed | 0.00064 seconds |
58
+ ./spec/integration/transaction_without_steps_spec.rb[1:2:1] | passed | 0.0008 seconds |
59
+ ./spec/integration/transaction_without_steps_spec.rb[1:3:1] | passed | 0.00071 seconds |
60
+ ./spec/unit/step_adapters/around_spec.rb[1:1:1:1] | passed | 0.0016 seconds |
61
+ ./spec/unit/step_adapters/around_spec.rb[1:1:2:1] | passed | 0.00092 seconds |
62
+ ./spec/unit/step_adapters/around_spec.rb[1:1:3:1] | passed | 0.00011 seconds |
63
+ ./spec/unit/step_adapters/check_spec.rb[1:1:1] | passed | 0.00012 seconds |
64
+ ./spec/unit/step_adapters/check_spec.rb[1:1:2:1] | passed | 0.00012 seconds |
65
+ ./spec/unit/step_adapters/check_spec.rb[1:1:3:1] | passed | 0.00009 seconds |
65
66
  ./spec/unit/step_adapters/check_spec.rb[1:1:4:1] | passed | 0.00009 seconds |
66
- ./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00012 seconds |
67
- ./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
68
- ./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00013 seconds |
69
- ./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00013 seconds |
70
- ./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00013 seconds |
71
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00015 seconds |
72
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00013 seconds |
73
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00012 seconds |
74
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.0001 seconds |
75
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00014 seconds |
76
- ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2:1] | passed | 0.0001 seconds |
77
- ./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.00254 seconds |
78
- ./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.01294 seconds |
79
- ./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.00045 seconds |
80
- ./spec/unit/step_spec.rb[1:1:3:1] | passed | 0.00032 seconds |
81
- ./spec/unit/step_spec.rb[1:1:3:2] | passed | 0.00224 seconds |
82
- ./spec/unit/step_spec.rb[1:1:3:3] | passed | 0.00215 seconds |
67
+ ./spec/unit/step_adapters/map_spec.rb[1:1:1] | passed | 0.00009 seconds |
68
+ ./spec/unit/step_adapters/raw_spec.rb[1:1:1:1] | passed | 0.00014 seconds |
69
+ ./spec/unit/step_adapters/raw_spec.rb[1:1:2:1] | passed | 0.00009 seconds |
70
+ ./spec/unit/step_adapters/tee_spec.rb[1:1:1] | passed | 0.00012 seconds |
71
+ ./spec/unit/step_adapters/try_spec.rb[1:1:1:1] | passed | 0.00016 seconds |
72
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:1] | passed | 0.00013 seconds |
73
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:2] | passed | 0.00016 seconds |
74
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:1] | passed | 0.00017 seconds |
75
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:1:3:2] | passed | 0.00012 seconds |
76
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:1] | passed | 0.00012 seconds |
77
+ ./spec/unit/step_adapters/try_spec.rb[1:1:2:2:2:1] | passed | 0.00012 seconds |
78
+ ./spec/unit/step_spec.rb[1:1:1:1] | passed | 0.00225 seconds |
79
+ ./spec/unit/step_spec.rb[1:1:1:2] | passed | 0.00071 seconds |
80
+ ./spec/unit/step_spec.rb[1:1:2:1] | passed | 0.01719 seconds |
81
+ ./spec/unit/step_spec.rb[1:1:3:1] | passed | 0.00026 seconds |
82
+ ./spec/unit/step_spec.rb[1:1:3:2] | passed | 0.00306 seconds |
83
+ ./spec/unit/step_spec.rb[1:1:3:3] | passed | 0.00057 seconds |
83
84
  ./spec/unit/step_spec.rb[1:2:1:1] | passed | 0.00014 seconds |
84
- ./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00012 seconds |
85
- ./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00015 seconds |
86
- ./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00011 seconds |
85
+ ./spec/unit/step_spec.rb[1:2:2:1] | passed | 0.00014 seconds |
86
+ ./spec/unit/step_spec.rb[1:2:3:1] | passed | 0.00013 seconds |
87
+ ./spec/unit/step_spec.rb[1:3:1:1] | passed | 0.00014 seconds |
87
88
  ./spec/unit/step_spec.rb[1:3:2:1] | passed | 0.00013 seconds |
@@ -29,11 +29,11 @@ RSpec.describe "around steps" do
29
29
  Class.new do
30
30
  include Dry::Transaction(container: Test::Container)
31
31
 
32
- around :transaction
33
- step :validate
34
- step :persist_user
35
- step :persist_account
36
- step :finalize
32
+ around :transaction, with: :transaction
33
+ step :validate, with: :validate
34
+ step :persist_user, with: :persist_user
35
+ step :persist_account, with: :persist_account
36
+ step :finalize, with: :finalize
37
37
  end
38
38
  end
39
39
 
@@ -18,10 +18,10 @@ RSpec.describe "Transactions" do
18
18
  let(:transaction) {
19
19
  Class.new do
20
20
  include Dry::Transaction(container: Test::Container)
21
- map :process
22
- step :verify
23
- try :validate, catch: Test::NotValidError
24
- tee :persist
21
+ map :process, with: :process
22
+ step :verify, with: :verify
23
+ try :validate, with: :validate, catch: Test::NotValidError
24
+ tee :persist, with: :persist
25
25
  end.new(**dependencies)
26
26
  }
27
27
  let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
@@ -92,9 +92,9 @@ RSpec.describe "Transactions" do
92
92
  let(:transaction) {
93
93
  Class.new do
94
94
  include Dry::Transaction(container: Test::Container)
95
- map :process
95
+ map :process, with: :process
96
96
  step :verify_step, with: :verify
97
- tee :persist
97
+ tee :persist, with: :persist
98
98
  end.new(**dependencies)
99
99
  }
100
100
 
@@ -177,10 +177,11 @@ RSpec.describe "Transactions" do
177
177
  {process: -> input { Failure(input)} }
178
178
  end
179
179
 
180
+ # FIXME: needs a better description
180
181
  it "execute the transaction and execute the injected operation" do
181
182
  result = transaction.call([:hello])
182
183
 
183
- expect(result).to eq (Failure([:hello, :world]))
184
+ expect(result).to eq Failure([:hello])
184
185
  end
185
186
  end
186
187
 
@@ -286,9 +287,8 @@ RSpec.describe "Transactions" do
286
287
  end
287
288
  end
288
289
 
289
-
290
290
  context "all steps are local methods" do
291
- let(:transaction) do
291
+ let(:transaction_class) do
292
292
  Class.new do
293
293
  include Dry::Transaction
294
294
 
@@ -307,23 +307,30 @@ RSpec.describe "Transactions" do
307
307
  def persist(input)
308
308
  Test::Container[:database] << input and true
309
309
  end
310
- end.new
310
+ end
311
311
  end
312
312
 
313
313
  it "executes succesfully" do
314
- transaction.call("name" => "Jane", "email" => "jane@doe.com")
314
+ transaction_class.new.call("name" => "Jane", "email" => "jane@doe.com")
315
315
  expect(database).to include([["name", "Jane"], ["email", "jane@doe.com"]])
316
316
  end
317
+
318
+ it "allows replacement steps to be injected" do
319
+ verify = -> { Failure("nope") }
320
+
321
+ result = transaction_class.new(verify: verify).("name" => "Jane", "email" => "jane@doe.com")
322
+ expect(result).to eq Failure("nope")
323
+ end
317
324
  end
318
325
 
319
326
  context "failed in a try step" do
320
327
  let(:transaction) {
321
328
  Class.new do
322
329
  include Dry::Transaction(container: Test::Container)
323
- map :process
324
- step :verify
325
- try :validate, catch: Test::NotValidError
326
- tee :persist
330
+ map :process, with: :process
331
+ step :verify, with: :verify
332
+ try :validate, with: :validate, catch: Test::NotValidError
333
+ tee :persist, with: :persist
327
334
  end.new(**dependencies)
328
335
  }
329
336
  let(:input) { {"name" => "Jane"} }
@@ -498,7 +505,7 @@ RSpec.describe "Transactions" do
498
505
  let(:transaction) {
499
506
  Class.new do
500
507
  include Dry::Transaction(container: Test::ContainerRaw)
501
- map :not_a_proc
508
+ map :not_a_proc, with: :not_a_proc
502
509
  end.new
503
510
  }
504
511
 
@@ -28,10 +28,10 @@ RSpec.describe "Transactions steps without arguments" do
28
28
  let(:transaction) {
29
29
  Class.new do
30
30
  include Dry::Transaction(container: Test::Container)
31
- map :fetch_data
32
- map :process
33
- try :validate, catch: Test::NotValidError
34
- tee :persist
31
+ map :fetch_data, with: :fetch_data
32
+ map :process, with: :process
33
+ try :validate, with: :validate, catch: Test::NotValidError
34
+ tee :persist, with: :persist
35
35
  end.new(**dependencies)
36
36
  }
37
37
 
@@ -67,11 +67,11 @@ RSpec.describe "Transactions steps without arguments" do
67
67
  let(:transaction) {
68
68
  Class.new do
69
69
  include Dry::Transaction(container: Test::Container)
70
- tee :call_outside
71
- map :fetch_data
72
- map :process
73
- try :validate, catch: Test::NotValidError
74
- tee :external_store
70
+ tee :call_outside, with: :call_outside
71
+ map :fetch_data, with: :fetch_data
72
+ map :process, with: :process
73
+ try :validate, with: :validate, catch: Test::NotValidError
74
+ tee :external_store, with: :external_store
75
75
  end.new(**dependencies)
76
76
  }
77
77
 
@@ -85,10 +85,10 @@ RSpec.describe "Transactions steps without arguments" do
85
85
  let(:transaction) {
86
86
  Class.new do
87
87
  include Dry::Transaction(container: Test::Container)
88
- map :process
89
- try :validate, catch: Test::NotValidError
90
- tee :call_outside
91
- tee :external_store
88
+ map :process, with: :process
89
+ try :validate, with: :validate, catch: Test::NotValidError
90
+ tee :call_outside, with: :call_outside
91
+ tee :external_store, with: :external_store
92
92
  end.new(**dependencies)
93
93
  }
94
94
  let(:input) { {"name" => "Jane", "email" => "jane@doe.com"} }
@@ -3,7 +3,15 @@ RSpec.describe Dry::Transaction::Step do
3
3
  let(:step_name) { :test }
4
4
  let(:operation_name) { step_name }
5
5
 
6
- subject(:step) { described_class.new(step_adapter, step_name, operation_name, operation, {}) }
6
+ subject(:step) {
7
+ described_class.new(
8
+ adapter: step_adapter,
9
+ name: step_name,
10
+ operation_name: operation_name,
11
+ operation: operation,
12
+ options: {}
13
+ )
14
+ }
7
15
 
8
16
  describe "#call" do
9
17
  let(:listener) 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.12.1
4
+ version: 0.13.0
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-06-05 00:00:00.000000000 Z
11
+ date: 2018-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-container