interactor_with_steroids 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66961ad27a598bec0b93dc0297720eb97d0cdd5199b05e7e1490b731bc098de0
4
- data.tar.gz: 6432d13df06f22d9f30c8ad4a766b80dc5f3726be2f5a80495efc3edd6b0d444
3
+ metadata.gz: 7c29f3d44762d497592a20ae9da8a448fbdf2121116fc5c222f6323e1352c98e
4
+ data.tar.gz: b6f0cca693608e9c8cfecd0dd51098c9befb29ef26395e8750c9fd0ffd253699
5
5
  SHA512:
6
- metadata.gz: 23295d8872c9888924deb8f6937f3030f371a74ecb6c3ee0e5d0d79a7bf2a0419aa590c1705e18b76a731bb1f1bf5893599cd677835c8666b075fb3b86766cd4
7
- data.tar.gz: ac5eaf844aa979041a8fe09c11336f413310576d9736209083baaf27a617208f5d8cc39be9a7e2ff308d0879488171099afd4e845d4bbb6da804a61e0c62e282
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.1.2"
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/)
@@ -58,7 +58,7 @@ module Interactor
58
58
  end
59
59
  end
60
60
 
61
- attr_accessor :error
61
+ attr_accessor :error, :error_cause
62
62
  delegate :to_s, to: :to_h
63
63
 
64
64
  # Public: Whether the Interactor::Context is successful. By default, a new
@@ -27,5 +27,12 @@ module Interactor
27
27
  @context = context
28
28
  super
29
29
  end
30
+
31
+ def cause_stack
32
+ causes = [context.error_cause]
33
+ causes << causes.last.cause while causes.last&.cause
34
+
35
+ causes.compact
36
+ end
30
37
  end
31
38
  end
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
@@ -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.1.2
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-01-13 00:00:00.000000000 Z
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: '0'
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