interactor_with_steroids 1.1.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/interactor.gemspec +2 -1
- data/lib/interactor/context.rb +1 -1
- data/lib/interactor/error.rb +7 -0
- data/lib/interactor.rb +1 -1
- data/spec/interactor/error_spec.rb +29 -0
- data/spec/interactor_spec.rb +11 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c29f3d44762d497592a20ae9da8a448fbdf2121116fc5c222f6323e1352c98e
|
4
|
+
data.tar.gz: b6f0cca693608e9c8cfecd0dd51098c9befb29ef26395e8750c9fd0ffd253699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 761a11f3eaead34c27ce5df13af3f17449d3b7317da05d77efd3091debfa1b249b2db8a5759ed189470f3f16e0aff25a70f8ac84d4b788d7ab06a08f2f1c7927
|
7
|
+
data.tar.gz: '039491509364e1df4dfb16084b782d8be7983900da3a15120001f811f68509a33656d376aa388ea279530ab2b7e17e5f3ebd704f158a98b17e3e877f5e9dd91c'
|
data/interactor.gemspec
CHANGED
@@ -2,7 +2,7 @@ require "English"
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "interactor_with_steroids"
|
5
|
-
spec.version = "1.
|
5
|
+
spec.version = "1.3.0"
|
6
6
|
|
7
7
|
spec.author = "Collective Idea/Sorare Team"
|
8
8
|
spec.email = "hello@sorare.com"
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.summary = "Simple interactor implementation"
|
11
11
|
spec.homepage = "https://github.com/sorare/interactor"
|
12
12
|
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = '>= 2.1'
|
13
14
|
|
14
15
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
15
16
|
spec.test_files = spec.files.grep(/^spec/)
|
data/lib/interactor/context.rb
CHANGED
data/lib/interactor/error.rb
CHANGED
data/lib/interactor.rb
CHANGED
@@ -145,7 +145,7 @@ module Interactor
|
|
145
145
|
end
|
146
146
|
rescue Failure => e
|
147
147
|
# Make sure we fail the current context when a call! to another interactor fails
|
148
|
-
context.fail!(error: e.context&.error)
|
148
|
+
context.fail!(error: e.context&.error, error_cause: e.cause)
|
149
149
|
end
|
150
150
|
|
151
151
|
# Public: Invoke an Interactor instance without any hooks, tracking, or
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Interactor
|
2
|
+
describe Failure do
|
3
|
+
describe ".cause_stack" do
|
4
|
+
subject { failure.cause_stack }
|
5
|
+
|
6
|
+
let(:exception_1) { Class.new(Exception) }
|
7
|
+
let(:exception_2) { Class.new(Exception) }
|
8
|
+
let(:interactor) do
|
9
|
+
Class.new.send(:include, Interactor) do
|
10
|
+
def call
|
11
|
+
begin
|
12
|
+
raise exception_1
|
13
|
+
rescue StandardError
|
14
|
+
raise exception_2
|
15
|
+
end
|
16
|
+
rescue StandardError
|
17
|
+
context.fail!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an empty stack" do
|
23
|
+
interactor.call!
|
24
|
+
rescue Failure => e
|
25
|
+
expect(e.cause_stack).to contain_exactly(described_class, exception_1, exception_2)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/interactor_spec.rb
CHANGED
@@ -63,6 +63,8 @@ describe Interactor do
|
|
63
63
|
|
64
64
|
describe "#run" do
|
65
65
|
let(:instance) { interactor.new }
|
66
|
+
let(:exception_klass) { Class.new(Exception) }
|
67
|
+
let(:failure_cause) { exception_klass.new }
|
66
68
|
|
67
69
|
it "runs the interactor" do
|
68
70
|
expect(instance).to receive(:run!).once.with(no_args)
|
@@ -78,6 +80,15 @@ describe Interactor do
|
|
78
80
|
}.not_to raise_error
|
79
81
|
end
|
80
82
|
|
83
|
+
it "persists failure cause" do
|
84
|
+
expect(instance).to receive(:call).and_raise(
|
85
|
+
Interactor::Failure.new(instance.context), cause: failure_cause
|
86
|
+
)
|
87
|
+
|
88
|
+
instance.run
|
89
|
+
expect(instance.context.error_cause).to eq(failure_cause)
|
90
|
+
end
|
91
|
+
|
81
92
|
it "raises other errors" do
|
82
93
|
expect(instance).to receive(:run!).and_raise("foo")
|
83
94
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactor_with_steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collective Idea/Sorare Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/interactor/organizer.rb
|
78
78
|
- spec/interactor/context_spec.rb
|
79
79
|
- spec/interactor/declaration_spec.rb
|
80
|
+
- spec/interactor/error_spec.rb
|
80
81
|
- spec/interactor/hooks_spec.rb
|
81
82
|
- spec/interactor/organizer_spec.rb
|
82
83
|
- spec/interactor_spec.rb
|
@@ -93,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
94
|
requirements:
|
94
95
|
- - ">="
|
95
96
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
97
|
+
version: '2.1'
|
97
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
99
|
requirements:
|
99
100
|
- - ">="
|
@@ -107,6 +108,7 @@ summary: Simple interactor implementation
|
|
107
108
|
test_files:
|
108
109
|
- spec/interactor/context_spec.rb
|
109
110
|
- spec/interactor/declaration_spec.rb
|
111
|
+
- spec/interactor/error_spec.rb
|
110
112
|
- spec/interactor/hooks_spec.rb
|
111
113
|
- spec/interactor/organizer_spec.rb
|
112
114
|
- spec/interactor_spec.rb
|