interactor_with_steroids 1.1.1 → 1.2.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: 0ecd9b8161803b5a16814d6b05d200a3107b0febfe13e2a82cd0d4a05e963b81
4
- data.tar.gz: 7e316f28acccbaa9f67dbc49d45cc1e5b47faafc5e2d5dfd4ba92f5be381f8d5
3
+ metadata.gz: ee0822c1b5d0c7e5ec36e35a2eb7989f19587f8b64a6a784e183fc6545c2ce4b
4
+ data.tar.gz: 4759c36e11b659a8ddef357ac928c297f5383b370d0a075c1dd0eb20e2a392bf
5
5
  SHA512:
6
- metadata.gz: 8b1eb706406fcbd856c2d23a3f43d19faed8cbed8478ee1a71fcf602ea773f6a259bfbf10ac987efdaaa54fb847d67aca710212706c630fbb655f0c9fc49312b
7
- data.tar.gz: d2676226b5ce8c0605d303a59fd30e3982d9da381d1020b18ffe826fe35fcb637eeef2ce01af9d0ad1945c3c7ed1ee5880c61790f0c8da4de75a38d31624257c
6
+ metadata.gz: ce654d725ec8ebec129d6667612d2bf74e309457589c05592c6ec6402fc69f5756ce05f392a132177c3b351ca362374ea1b75ce217c26c73a6a0313ee4e08bff
7
+ data.tar.gz: b562c0b40d1d4d95e16726b0aeb115b89ada4606d3371ebababda23be7ae74ca984138182c2790ee1fd9c837d614bcaf741c47dfe19f7083fd0d9d5f742f38bb
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.1"
5
+ spec.version = "1.2.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
data/lib/interactor.rb CHANGED
@@ -92,7 +92,7 @@ module Interactor
92
92
  # MyInteractor.new
93
93
  # # => #<MyInteractor @context=#<Interactor::Context>>
94
94
  def initialize(context = {})
95
- @context = self.context_class.build(context)
95
+ @context = self.context_class.build(**context.to_h)
96
96
  end
97
97
 
98
98
  # Internal: Invoke an interactor instance along with all defined hooks. The
@@ -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
@@ -27,7 +27,7 @@ module Interactor
27
27
 
28
28
  it "doesn't affect the original hash" do
29
29
  hash = { foo: "bar" }
30
- context = interactor.context_class.build(hash)
30
+ context = interactor.context_class.build(**hash)
31
31
 
32
32
  expect(context).to be_a(interactor.context_class)
33
33
  expect {
@@ -39,7 +39,7 @@ module Interactor
39
39
 
40
40
  it "ignores any additional argument" do
41
41
  hash = { foo: 'bar', bar: "baz" }
42
- expect { interactor.context_class.build(hash) }.not_to raise_error
42
+ expect { interactor.context_class.build(**hash) }.not_to raise_error
43
43
  end
44
44
  end
45
45
 
@@ -52,7 +52,7 @@ describe Interactor do
52
52
  end
53
53
 
54
54
  it "initializes a blank context if none is given" do
55
- expect(Interactor::Context).to receive(:build).once.with({}) { context }
55
+ expect(Interactor::Context).to receive(:build).once.with(no_args) { context }
56
56
 
57
57
  instance = interactor.new
58
58
 
@@ -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.1
4
+ version: 1.2.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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -93,14 +93,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.1'
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.1.6
103
+ rubygems_version: 3.3.3
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Simple interactor implementation