interactor 3.1.1 → 3.2.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.
@@ -16,7 +16,7 @@ module Interactor
16
16
  end
17
17
 
18
18
  it "doesn't affect the original hash" do
19
- hash = { foo: "bar" }
19
+ hash = {foo: "bar"}
20
20
  context = Context.build(hash)
21
21
 
22
22
  expect(context).to be_a(Context)
@@ -61,7 +61,11 @@ module Interactor
61
61
 
62
62
  it "sets success to false" do
63
63
  expect {
64
- context.fail! rescue nil
64
+ begin
65
+ context.fail!
66
+ rescue
67
+ nil
68
+ end
65
69
  }.to change {
66
70
  context.success?
67
71
  }.from(true).to(false)
@@ -69,17 +73,29 @@ module Interactor
69
73
 
70
74
  it "sets failure to true" do
71
75
  expect {
72
- context.fail! rescue nil
76
+ begin
77
+ context.fail!
78
+ rescue
79
+ nil
80
+ end
73
81
  }.to change {
74
82
  context.failure?
75
83
  }.from(false).to(true)
76
84
  end
77
85
 
78
86
  it "preserves failure" do
79
- context.fail! rescue nil
87
+ begin
88
+ context.fail!
89
+ rescue
90
+ nil
91
+ end
80
92
 
81
93
  expect {
82
- context.fail! rescue nil
94
+ begin
95
+ context.fail!
96
+ rescue
97
+ nil
98
+ end
83
99
  }.not_to change {
84
100
  context.failure?
85
101
  }
@@ -87,7 +103,11 @@ module Interactor
87
103
 
88
104
  it "preserves the context" do
89
105
  expect {
90
- context.fail! rescue nil
106
+ begin
107
+ context.fail!
108
+ rescue
109
+ nil
110
+ end
91
111
  }.not_to change {
92
112
  context.foo
93
113
  }
@@ -95,7 +115,11 @@ module Interactor
95
115
 
96
116
  it "updates the context" do
97
117
  expect {
98
- context.fail!(foo: "baz") rescue nil
118
+ begin
119
+ context.fail!(foo: "baz")
120
+ rescue
121
+ nil
122
+ end
99
123
  }.to change {
100
124
  context.foo
101
125
  }.from("bar").to("baz")
@@ -103,7 +127,11 @@ module Interactor
103
127
 
104
128
  it "updates the context with a string key" do
105
129
  expect {
106
- context.fail!("foo" => "baz") rescue nil
130
+ begin
131
+ context.fail!("foo" => "baz")
132
+ rescue
133
+ nil
134
+ end
107
135
  }.to change {
108
136
  context.foo
109
137
  }.from("bar").to("baz")
@@ -171,5 +199,20 @@ module Interactor
171
199
  expect(context._called).to eq([])
172
200
  end
173
201
  end
202
+
203
+ describe "#deconstruct_keys" do
204
+ let(:context) { Context.build(foo: :bar) }
205
+
206
+ let(:deconstructed) { context.deconstruct_keys([:foo, :success, :failure]) }
207
+
208
+ it "deconstructs as hash pattern" do
209
+ expect(deconstructed[:foo]).to eq(:bar)
210
+ end
211
+
212
+ it "includes success and failure" do
213
+ expect(deconstructed[:success]).to eq(true)
214
+ expect(deconstructed[:failure]).to eq(false)
215
+ end
216
+ end
174
217
  end
175
218
  end
data/spec/spec_helper.rb CHANGED
@@ -5,4 +5,4 @@ end
5
5
 
6
6
  require "interactor"
7
7
 
8
- Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f }
8
+ Dir[File.expand_path("../support/*.rb", __FILE__)].sort.each { |f| require f }
data/spec/support/lint.rb CHANGED
@@ -6,7 +6,7 @@ shared_examples :lint do
6
6
  let(:instance) { double(:instance, context: context) }
7
7
 
8
8
  it "calls an instance with the given context" do
9
- expect(interactor).to receive(:new).once.with(foo: "bar") { instance }
9
+ expect(interactor).to receive(:new).once.with({foo: "bar"}) { instance }
10
10
  expect(instance).to receive(:run).once.with(no_args)
11
11
 
12
12
  expect(interactor.call(foo: "bar")).to eq(context)
@@ -25,7 +25,7 @@ shared_examples :lint do
25
25
  let(:instance) { double(:instance, context: context) }
26
26
 
27
27
  it "calls an instance with the given context" do
28
- expect(interactor).to receive(:new).once.with(foo: "bar") { instance }
28
+ expect(interactor).to receive(:new).once.with({foo: "bar"}) { instance }
29
29
  expect(instance).to receive(:run!).once.with(no_args)
30
30
 
31
31
  expect(interactor.call!(foo: "bar")).to eq(context)
@@ -43,7 +43,7 @@ shared_examples :lint do
43
43
  let(:context) { double(:context) }
44
44
 
45
45
  it "initializes a context" do
46
- expect(Interactor::Context).to receive(:build).once.with(foo: "bar") { context }
46
+ expect(Interactor::Context).to receive(:build).once.with({foo: "bar"}) { context }
47
47
 
48
48
  instance = interactor.new(foo: "bar")
49
49
 
@@ -70,14 +70,22 @@ shared_examples :lint do
70
70
  instance.run
71
71
  end
72
72
 
73
- it "rescues failure" do
74
- expect(instance).to receive(:run!).and_raise(Interactor::Failure)
73
+ it "rescues failure with the same context" do
74
+ expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(instance.context))
75
75
 
76
76
  expect {
77
77
  instance.run
78
78
  }.not_to raise_error
79
79
  end
80
80
 
81
+ it "raises other failures" do
82
+ expect(instance).to receive(:run!).and_raise(Interactor::Failure.new(Interactor::Context.new))
83
+
84
+ expect {
85
+ instance.run
86
+ }.to raise_error(Interactor::Failure)
87
+ end
88
+
81
89
  it "raises other errors" do
82
90
  expect(instance).to receive(:run!).and_raise("foo")
83
91
 
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collective Idea
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ostruct
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: bundler
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -44,9 +57,10 @@ executables: []
44
57
  extensions: []
45
58
  extra_rdoc_files: []
46
59
  files:
60
+ - ".github/workflows/tests.yml"
47
61
  - ".gitignore"
48
62
  - ".rspec"
49
- - ".travis.yml"
63
+ - ".standard.yml"
50
64
  - CHANGELOG.md
51
65
  - CONTRIBUTING.md
52
66
  - Gemfile
@@ -70,7 +84,6 @@ homepage: https://github.com/collectiveidea/interactor
70
84
  licenses:
71
85
  - MIT
72
86
  metadata: {}
73
- post_install_message:
74
87
  rdoc_options: []
75
88
  require_paths:
76
89
  - lib
@@ -85,16 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
98
  - !ruby/object:Gem::Version
86
99
  version: '0'
87
100
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.7.6
90
- signing_key:
101
+ rubygems_version: 3.6.9
91
102
  specification_version: 4
92
103
  summary: Simple interactor implementation
93
- test_files:
94
- - spec/integration_spec.rb
95
- - spec/interactor/context_spec.rb
96
- - spec/interactor/hooks_spec.rb
97
- - spec/interactor/organizer_spec.rb
98
- - spec/interactor_spec.rb
99
- - spec/spec_helper.rb
100
- - spec/support/lint.rb
104
+ test_files: []
data/.travis.yml DELETED
@@ -1,35 +0,0 @@
1
- after_success:
2
- - bundle exec codeclimate-test-reporter
3
- before_install:
4
- - gem update bundler rake
5
- branches:
6
- only:
7
- - master
8
- - v3
9
- env:
10
- global:
11
- - secure: | # CODECLIMATE_REPO_TOKEN
12
- BIemhM273wHZMpuULDMYGPsxYdfw+NMw7IQbOD6gy5r+dha07y9ssTYYE5Gn
13
- t1ptAb09lhQ4gexXTr83i6angMrnHgQ1ZX2wfeoZ0FvWDHQht9YkXyiNH+R6
14
- odHUeDIYAlUiqLX9nAkklL89Rc22BrHMGGNyuA8Uc5sktW5P/FE=
15
- language: ruby
16
- matrix:
17
- allow_failures:
18
- - rvm: "2.0"
19
- - rvm: "2.1"
20
- - rvm: "2.2"
21
- - rvm: ruby-head
22
- notifications:
23
- webhooks:
24
- on_start: always
25
- urls:
26
- - http://buildlight.collectiveidea.com/
27
- rvm:
28
- - "2.0"
29
- - "2.1"
30
- - "2.2"
31
- - "2.3"
32
- - "2.4"
33
- - "2.5"
34
- - ruby-head
35
- script: bundle exec rspec