activeinteractor 1.2.0 → 1.2.2

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -3
  3. data/lib/active_interactor/interactor/worker.rb +7 -1
  4. data/lib/active_interactor/organizer/perform.rb +8 -9
  5. data/lib/active_interactor/version.rb +1 -1
  6. metadata +8 -128
  7. data/spec/active_interactor/base_spec.rb +0 -85
  8. data/spec/active_interactor/config_spec.rb +0 -17
  9. data/spec/active_interactor/context/base_spec.rb +0 -443
  10. data/spec/active_interactor/error_spec.rb +0 -45
  11. data/spec/active_interactor/interactor/perform/options_spec.rb +0 -25
  12. data/spec/active_interactor/interactor/worker_spec.rb +0 -189
  13. data/spec/active_interactor/organizer/base_spec.rb +0 -276
  14. data/spec/active_interactor/organizer/interactor_interface_collection_spec.rb +0 -78
  15. data/spec/active_interactor/organizer/interactor_interface_spec.rb +0 -235
  16. data/spec/active_interactor/version_spec.rb +0 -119
  17. data/spec/active_interactor_spec.rb +0 -23
  18. data/spec/integration/a_basic_interactor_spec.rb +0 -154
  19. data/spec/integration/a_basic_organizer_spec.rb +0 -354
  20. data/spec/integration/a_failing_interactor_spec.rb +0 -43
  21. data/spec/integration/active_record_integration_spec.rb +0 -32
  22. data/spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb +0 -69
  23. data/spec/integration/an_interactor_with_after_perform_callbacks_spec.rb +0 -31
  24. data/spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb +0 -34
  25. data/spec/integration/an_interactor_with_an_existing_context_class_spec.rb +0 -50
  26. data/spec/integration/an_interactor_with_around_perform_callbacks_spec.rb +0 -35
  27. data/spec/integration/an_interactor_with_around_rollback_callbacks_spec.rb +0 -39
  28. data/spec/integration/an_interactor_with_before_perform_callbacks_spec.rb +0 -31
  29. data/spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb +0 -34
  30. data/spec/integration/an_interactor_with_deferred_after_callbacks.rb +0 -32
  31. data/spec/integration/an_interactor_with_validations_on_called_spec.rb +0 -41
  32. data/spec/integration/an_interactor_with_validations_on_calling_spec.rb +0 -37
  33. data/spec/integration/an_interactor_with_validations_spec.rb +0 -95
  34. data/spec/integration/an_organizer_containing_organizer_with_after_callbacks_deferred_spec.rb +0 -125
  35. data/spec/integration/an_organizer_performing_in_parallel_spec.rb +0 -48
  36. data/spec/integration/an_organizer_with_after_callbacks_deferred_spec.rb +0 -154
  37. data/spec/integration/an_organizer_with_after_each_callbacks_spec.rb +0 -35
  38. data/spec/integration/an_organizer_with_all_perform_callbacks.rb +0 -112
  39. data/spec/integration/an_organizer_with_around_each_callbacks_spec.rb +0 -39
  40. data/spec/integration/an_organizer_with_before_each_callbacks_spec.rb +0 -35
  41. data/spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb +0 -326
  42. data/spec/integration/an_organizer_with_failing_nested_organizer_spec.rb +0 -47
  43. data/spec/integration/an_organizer_with_options_callbacks_spec.rb +0 -64
  44. data/spec/spec_helper.rb +0 -33
  45. data/spec/support/coverage.rb +0 -50
  46. data/spec/support/helpers/factories.rb +0 -49
  47. data/spec/support/shared_examples/a_class_that_extends_active_interactor_models_example.rb +0 -81
  48. data/spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb +0 -107
  49. data/spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb +0 -60
  50. data/spec/support/shared_examples/a_class_with_interactor_methods_example.rb +0 -21
  51. data/spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb +0 -42
  52. data/spec/support/spec_helpers.rb +0 -7
  53. /data/lib/rails/generators/templates/{interactor_text_unit.erb → interactor_test_unit.erb} +0 -0
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe ActiveInteractor do
6
- describe '.config' do
7
- subject { described_class.config }
8
-
9
- it { is_expected.to be_a ActiveInteractor::Config }
10
- end
11
-
12
- describe '.configure' do
13
- it 'is expected to yield config' do
14
- expect { |b| described_class.configure(&b) }.to yield_control
15
- end
16
- end
17
-
18
- describe '.logger' do
19
- subject { described_class.logger }
20
-
21
- it { is_expected.to be_a Logger }
22
- end
23
- end
@@ -1,154 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'A basic interactor', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- def perform
9
- context.test_field = 'test'
10
- end
11
- end
12
- end
13
-
14
- include_examples 'a class with interactor methods'
15
- include_examples 'a class with interactor callback methods'
16
- include_examples 'a class with interactor context methods'
17
-
18
- describe '.context_class' do
19
- subject { interactor_class.context_class }
20
-
21
- it { is_expected.to eq TestInteractor::Context }
22
- it { is_expected.to be < ActiveInteractor::Context::Base }
23
- end
24
-
25
- describe '.perform' do
26
- subject { interactor_class.perform }
27
-
28
- it { is_expected.to be_a interactor_class.context_class }
29
- it { is_expected.to be_successful }
30
- it { is_expected.to have_attributes(test_field: 'test') }
31
- end
32
-
33
- describe '.perform!' do
34
- subject { interactor_class.perform! }
35
-
36
- it { expect { subject }.not_to raise_error }
37
- it { is_expected.to be_a interactor_class.context_class }
38
- it { is_expected.to be_successful }
39
- it { is_expected.to have_attributes(test_field: 'test') }
40
- end
41
-
42
- context 'having #context_attributes :test_field' do
43
- let(:interactor_class) do
44
- build_interactor do
45
- context_attributes :test_field
46
-
47
- def perform
48
- context.test_field = 'test'
49
- context.some_other_field = 'test 2'
50
- end
51
- end
52
- end
53
-
54
- include_examples 'a class with interactor methods'
55
- include_examples 'a class with interactor callback methods'
56
- include_examples 'a class with interactor context methods'
57
-
58
- describe '.perform' do
59
- subject(:result) { interactor_class.perform }
60
-
61
- it { is_expected.to be_a interactor_class.context_class }
62
- it { is_expected.to be_successful }
63
- it { is_expected.to have_attributes(test_field: 'test', some_other_field: 'test 2') }
64
-
65
- describe '.attributes' do
66
- subject { result.attributes }
67
-
68
- it { is_expected.to eq(test_field: 'test') }
69
- end
70
- end
71
- end
72
-
73
- context 'having a .name "AnInteractor"' do
74
- let(:interactor_class) { build_interactor('AnInteractor') }
75
-
76
- context 'having a class defined named "AnInteractorContext"' do
77
- let!(:context_class) { build_context('AnInteractorContext') }
78
-
79
- describe '.context_class' do
80
- subject { interactor_class.context_class }
81
-
82
- it { is_expected.to eq AnInteractorContext }
83
- it { is_expected.to be < ActiveInteractor::Context::Base }
84
- end
85
- end
86
- end
87
-
88
- context 'with a context class named "ATestContext"' do
89
- let!(:context_class) { build_context('ATestContext') }
90
-
91
- context 'with .contextualize_with :a_test_context' do
92
- let(:interactor_class) do
93
- build_interactor do
94
- contextualize_with :a_test_context
95
- end
96
- end
97
-
98
- describe '.context_class' do
99
- subject { interactor_class.context_class }
100
-
101
- it { is_expected.to eq ATestContext }
102
- it { is_expected.to be < ActiveInteractor::Context::Base }
103
- end
104
- end
105
- end
106
-
107
- context 'having default context attributes {:foo => "foo"}' do
108
- let(:interactor_class) do
109
- build_interactor do
110
- context_attribute :foo, default: -> { 'foo' }
111
- end
112
- end
113
-
114
- describe '.perform' do
115
- subject { interactor_class.perform(context_attributes) }
116
-
117
- context 'when no context is passed' do
118
- let(:context_attributes) { {} }
119
-
120
- it { is_expected.to have_attributes(foo: 'foo') }
121
- end
122
-
123
- context 'when context {:foo => "bar"} is passed' do
124
- let(:context_attributes) { { foo: 'bar' } }
125
-
126
- it { is_expected.to have_attributes(foo: 'bar') }
127
- end
128
- end
129
- end
130
-
131
- context 'having default context attributes {:foo => "foo", :bar => "bar"} using the #context_attributes method' do
132
- let(:interactor_class) do
133
- build_interactor do
134
- context_attributes foo: { default: -> { 'foo' } }, bar: { default: -> { 'bar' } }
135
- end
136
-
137
- describe '.perform' do
138
- subject { interactor_class.perform(context_attributes) }
139
-
140
- context 'when no context is passed' do
141
- let(:context_attributes) { {} }
142
-
143
- it { is_expected.to have_attributes(foo: 'foo', bar: 'bar') }
144
- end
145
-
146
- context 'when context {:foo => "bar"} is passed' do
147
- let(:context_attributes) { { foo: 'bar' } }
148
-
149
- it { is_expected.to have_attributes(foo: 'bar', bar: 'bar') }
150
- end
151
- end
152
- end
153
- end
154
- end
@@ -1,354 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'A basic organizer', type: :integration do
6
- let!(:test_interactor_1) do
7
- build_interactor('TestInteractor1') do
8
- def perform
9
- context.test_field_1 = 'test 1'
10
- end
11
- end
12
- end
13
-
14
- let!(:test_interactor_2) do
15
- build_interactor('TestInteractor2') do
16
- def perform
17
- context.test_field_2 = 'test 2'
18
- end
19
- end
20
- end
21
-
22
- let(:interactor_class) do
23
- build_organizer do
24
- organize TestInteractor1, TestInteractor2
25
- end
26
- end
27
-
28
- include_examples 'a class with interactor methods'
29
- include_examples 'a class with interactor callback methods'
30
- include_examples 'a class with interactor context methods'
31
- include_examples 'a class with organizer callback methods'
32
-
33
- describe '.context_class' do
34
- subject { interactor_class.context_class }
35
-
36
- it { is_expected.to eq TestOrganizer::Context }
37
- it { is_expected.to be < ActiveInteractor::Context::Base }
38
- end
39
-
40
- describe '.perform' do
41
- subject { interactor_class.perform }
42
-
43
- it { is_expected.to be_a interactor_class.context_class }
44
- it { is_expected.to be_successful }
45
- it { is_expected.to have_attributes(test_field_1: 'test 1', test_field_2: 'test 2') }
46
- end
47
-
48
- context 'when the first interactor fails' do
49
- let!(:test_interactor_1) do
50
- build_interactor('TestInteractor1') do
51
- def perform
52
- context.fail!
53
- end
54
- end
55
- end
56
-
57
- describe '.perform' do
58
- subject { interactor_class.perform }
59
-
60
- it { expect { subject }.not_to raise_error }
61
- it { is_expected.to be_a interactor_class.context_class }
62
- it { is_expected.to be_failure }
63
-
64
- it 'is expected to receive #rollback on the first interactor' do
65
- expect_any_instance_of(test_interactor_1).to receive(:rollback)
66
- .and_call_original
67
- subject
68
- end
69
-
70
- it 'is expected not to receive #perform! on the second interactor' do
71
- expect_any_instance_of(test_interactor_2).not_to receive(:perform!)
72
- subject
73
- end
74
-
75
- # https://github.com/aaronmallen/activeinteractor/issues/169
76
- context 'with error message "something went wrong"' do
77
- let!(:test_interactor_1) do
78
- build_interactor('TestInteractor1') do
79
- def perform
80
- context.fail!('something went wrong')
81
- end
82
- end
83
- end
84
-
85
- it { expect { subject }.not_to raise_error }
86
- it { is_expected.to be_a interactor_class.context_class }
87
- it { is_expected.to be_failure }
88
- it { expect(subject.errors.count).to eq 1 }
89
-
90
- it 'is expected to have errors "something went wrong" on :context' do
91
- expect(subject.errors[:context]).not_to be_empty
92
- expect(subject.errors[:context]).to include 'something went wrong'
93
- end
94
- end
95
- end
96
- end
97
-
98
- context 'when the second interactor fails' do
99
- let!(:test_interactor_2) do
100
- build_interactor('TestInteractor2') do
101
- def perform
102
- context.fail!
103
- end
104
- end
105
- end
106
-
107
- describe '.perform' do
108
- subject { interactor_class.perform }
109
-
110
- it { expect { subject }.not_to raise_error }
111
- it { is_expected.to be_a interactor_class.context_class }
112
- it { is_expected.to be_failure }
113
-
114
- it 'is expected to receive #rollback on all interactors' do
115
- expect_any_instance_of(test_interactor_2).to receive(:rollback)
116
- expect_any_instance_of(test_interactor_1).to receive(:rollback)
117
- subject
118
- end
119
-
120
- # https://github.com/aaronmallen/activeinteractor/issues/169
121
- context 'with error message "something went wrong"' do
122
- let!(:test_interactor_2) do
123
- build_interactor('TestInteractor2') do
124
- def perform
125
- context.fail!('something went wrong')
126
- end
127
- end
128
- end
129
-
130
- it { expect { subject }.not_to raise_error }
131
- it { is_expected.to be_a interactor_class.context_class }
132
- it { is_expected.to be_failure }
133
- it { expect(subject.errors.count).to eq 1 }
134
-
135
- it 'is expected to have errors "something went wrong" on :context' do
136
- expect(subject.errors[:context]).not_to be_empty
137
- expect(subject.errors[:context]).to include 'something went wrong'
138
- end
139
- end
140
- end
141
- end
142
-
143
- # https://github.com/aaronmallen/activeinteractor/issues/151
144
- context 'with an interactor class having a predefined context class with attributes [:foo]' do
145
- let!(:test_context_class) do
146
- build_context('TestInteractor1Context') do
147
- attributes :foo
148
- attributes :baz
149
- attributes :zoo
150
- end
151
- end
152
-
153
- # rubocop:disable Metrics/AbcSize
154
- let!(:test_interactor_1) do
155
- build_interactor('TestInteractor1') do
156
- def perform
157
- context.has_foo_as_method = context.foo.present?
158
- context.has_foo_as_element = context[:foo].present?
159
- context.has_bar_as_method = context.bar.present?
160
- context.has_bar_as_element = context[:bar].present?
161
- context.baz = 'baz'
162
- context.has_baz_as_method = context.baz.present?
163
- context.has_baz_as_element = context[:baz].present?
164
- context[:zoo] = 'zoo'
165
- context.has_zoo_as_method = context.zoo.present?
166
- context.has_zoo_as_element = context[:zoo].present?
167
- end
168
- end
169
- end
170
- # rubocop:enable Metrics/AbcSize
171
-
172
- let(:interactor_class) do
173
- build_organizer do
174
- organize :test_interactor_1
175
- end
176
- end
177
-
178
- context 'when passing a context argument { :foo => "foo", :bar => "bar" }' do
179
- let(:context_attributes) { { foo: 'foo', bar: 'bar' } }
180
-
181
- describe '.perform' do
182
- subject(:result) { interactor_class.perform(context_attributes) }
183
-
184
- it { is_expected.to have_attributes(foo: 'foo', bar: 'bar', baz: 'baz', zoo: 'zoo') }
185
-
186
- it 'is expected to copy all attributes in the contexts to each interactor' do
187
- expect(subject.has_foo_as_method).to be true
188
- expect(subject.has_foo_as_element).to be true
189
- expect(subject.has_bar_as_method).to be true
190
- expect(subject.has_bar_as_element).to be true
191
- expect(subject.has_baz_as_method).to be true
192
- expect(subject.has_baz_as_element).to be true
193
- expect(subject.has_zoo_as_method).to be true
194
- expect(subject.has_zoo_as_element).to be true
195
- end
196
-
197
- describe '#attributes' do
198
- subject { result.attributes }
199
-
200
- it { is_expected.to be_a Hash }
201
- it { is_expected.to be_empty }
202
- end
203
- end
204
-
205
- context 'with attributes [:foo] on the organizer context class' do
206
- let!(:interactor_class) do
207
- build_organizer do
208
- context_attributes :foo
209
- organize :test_interactor_1
210
- end
211
- end
212
-
213
- describe '.perform' do
214
- subject(:result) { interactor_class.perform(context_attributes) }
215
-
216
- it { is_expected.to have_attributes(foo: 'foo', bar: 'bar') }
217
-
218
- it 'is expected to copy all attributes in the contexts to each interactor' do
219
- expect(subject.has_foo_as_method).to be true
220
- expect(subject.has_foo_as_element).to be true
221
- expect(subject.has_bar_as_method).to be true
222
- expect(subject.has_bar_as_element).to be true
223
- end
224
-
225
- describe '#attributes' do
226
- subject { result.attributes }
227
-
228
- it { is_expected.to be_a Hash }
229
- it { is_expected.to eq(foo: 'foo') }
230
- end
231
- end
232
- end
233
- end
234
-
235
- context 'when passing default attributes on the organizer and its interactors' do
236
- let!(:test_organizer_context_class) do
237
- build_context('TestOrganizerContext') do
238
- attribute :foo
239
- attribute :baz
240
- attribute :zoo, default: 'zoo'
241
- attribute :taz, default: 'taz0'
242
- end
243
- end
244
-
245
- let!(:test_interactor_3_context_class) do
246
- build_context('TestInteractor3Context') do
247
- attribute :foo
248
- attribute :bar, default: 'bar'
249
- attribute :baz, default: 'baz'
250
- attribute :zoo
251
- attribute :taz, default: 'taz3'
252
- end
253
- end
254
-
255
- let!(:test_interactor_4_context_class) do
256
- build_context('TestInteractor4Context') do
257
- attribute :foo
258
- attribute :bar, default: 'bar'
259
- attribute :baz
260
- end
261
- end
262
-
263
- let!(:test_interactor_3) do
264
- build_interactor('TestInteractor3') do
265
- def perform
266
- context.bar = 'bar'
267
- context.taz_is_set_at_3 = (context.taz == 'taz')
268
- context.baz_is_set_at_3 = (context.baz == 'baz')
269
- context.zoo_is_set_at_3 = (context.zoo == 'zoo')
270
- end
271
- end
272
- end
273
-
274
- let!(:test_interactor_4) do
275
- build_interactor('TestInteractor4') do
276
- def perform
277
- context.taz_is_set_at_4 = (context.taz == 'taz')
278
- context.baz_is_set_at_4 = (context.baz == 'baz')
279
- context.zoo_is_set_at_4 = (context.zoo == 'zoo')
280
- end
281
- end
282
- end
283
-
284
- let!(:interactor_class) do
285
- build_organizer('TestOrganizer') do
286
- organize TestInteractor3, TestInteractor4
287
- end
288
- end
289
-
290
- describe '.context_class' do
291
- describe 'TestOrganizer' do
292
- subject { interactor_class.context_class }
293
-
294
- it { is_expected.to eq TestOrganizerContext }
295
- it { is_expected.to be < ActiveInteractor::Context::Base }
296
- end
297
-
298
- describe 'TestInteractor3' do
299
- subject { test_interactor_3.context_class }
300
-
301
- it { is_expected.to eq TestInteractor3Context }
302
- it { is_expected.to be < ActiveInteractor::Context::Base }
303
- end
304
-
305
- describe 'TestInteractor4' do
306
- subject { test_interactor_4.context_class }
307
-
308
- it { is_expected.to eq TestInteractor4Context }
309
- it { is_expected.to be < ActiveInteractor::Context::Base }
310
- end
311
- end
312
-
313
- describe '.perform' do
314
- subject(:result) { interactor_class.perform(context_attributes) }
315
-
316
- context 'when inputs are not defined' do
317
- let(:context_attributes) { {} }
318
-
319
- it { is_expected.to have_attributes(foo: nil, bar: 'bar', baz: 'baz') }
320
- end
321
-
322
- context 'when [:foo] is defined' do
323
- let(:context_attributes) { { foo: 'foo' } }
324
-
325
- it { is_expected.to have_attributes(foo: 'foo', bar: 'bar', baz: 'baz') }
326
- end
327
-
328
- context 'when [:taz] is defined' do
329
- let(:context_attributes) { { taz: 'taz' } }
330
-
331
- it { is_expected.to have_attributes(taz: 'taz', taz_is_set_at_3: true, taz_is_set_at_4: true) }
332
- end
333
-
334
- context 'when [:bar] is nil' do
335
- let(:context_attributes) { { bar: nil } }
336
-
337
- it { is_expected.to have_attributes(foo: nil, bar: 'bar', baz: 'baz') }
338
- end
339
-
340
- context 'when [:baz] is nil' do
341
- let(:context_attributes) { {} }
342
-
343
- it { is_expected.to have_attributes(baz: 'baz', baz_is_set_at_3: true, baz_is_set_at_4: true) }
344
- end
345
-
346
- context 'when [:zoo] is nil' do
347
- let(:context_attributes) { {} }
348
-
349
- it { is_expected.to have_attributes(zoo: 'zoo', zoo_is_set_at_3: true, zoo_is_set_at_4: true) }
350
- end
351
- end
352
- end
353
- end
354
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'A failing interactor', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- def perform
9
- context.fail!
10
- end
11
- end
12
- end
13
-
14
- include_examples 'a class with interactor methods'
15
- include_examples 'a class with interactor callback methods'
16
- include_examples 'a class with interactor context methods'
17
-
18
- describe '.context_class' do
19
- subject { interactor_class.context_class }
20
-
21
- it { is_expected.to eq TestInteractor::Context }
22
- it { is_expected.to be < ActiveInteractor::Context::Base }
23
- end
24
-
25
- describe '.perform' do
26
- subject { interactor_class.perform }
27
-
28
- it { expect { subject }.not_to raise_error }
29
- it { is_expected.to be_a interactor_class.context_class }
30
- it { is_expected.to be_failure }
31
-
32
- it 'is expected to receive #rollback' do
33
- expect_any_instance_of(interactor_class).to receive(:rollback)
34
- subject
35
- end
36
- end
37
-
38
- describe '.perform!' do
39
- subject { interactor_class.perform! }
40
-
41
- it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
42
- end
43
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- begin
5
- require 'active_interactor/rails'
6
- require 'active_interactor/rails/orm/active_record'
7
-
8
- RSpec.describe 'ActiveRecord integration', type: :integration do
9
- let!(:active_record_base_mock) { build_class('ActiveRecordBaseMock') }
10
-
11
- context 'after ActiveSupport.run_load_hooks has been received with :active_record' do
12
- before { ActiveSupport.run_load_hooks(:active_record, active_record_base_mock) }
13
-
14
- describe 'an ActiveRecord model class with .acts_as_context and attribute :foo' do
15
- let(:model_class) do
16
- build_class('ModelClass', active_record_base_mock) do
17
- include ActiveModel::Attributes
18
- include ActiveModel::Model
19
- acts_as_context
20
- attribute :foo
21
- end
22
- end
23
-
24
- include_examples 'A class that extends ActiveInteractor::Models'
25
- end
26
- end
27
- end
28
- rescue LoadError
29
- RSpec.describe 'ActiveRecord Integration', type: :integration do
30
- pending 'Rails not found skipping specs...'
31
- end
32
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .after_context_validation callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- context_validates :test_field, presence: true
9
- after_context_validation :downcase_test_field
10
-
11
- private
12
-
13
- def downcase_test_field
14
- context.test_field = context.test_field.downcase
15
- end
16
- end
17
- end
18
-
19
- include_examples 'a class with interactor methods'
20
- include_examples 'a class with interactor callback methods'
21
- include_examples 'a class with interactor context methods'
22
-
23
- describe '.perform' do
24
- subject { interactor_class.perform(context_attributes) }
25
-
26
- context 'with valid context attributes' do
27
- let(:context_attributes) { { test_field: 'TEST' } }
28
-
29
- it { is_expected.to be_a interactor_class.context_class }
30
- it { is_expected.to be_successful }
31
- it { is_expected.to have_attributes(test_field: 'test') }
32
- end
33
- end
34
-
35
- context 'having a condition on #after_context_valdation' do
36
- let(:interactor_class) do
37
- build_interactor do
38
- context_validates :test_field, presence: true
39
- after_context_validation :downcase_test_field, if: -> { context.should_downcase }
40
-
41
- private
42
-
43
- def downcase_test_field
44
- context.test_field = context.test_field.downcase
45
- end
46
- end
47
- end
48
-
49
- describe '.perform' do
50
- subject { interactor_class.perform(context_attributes) }
51
-
52
- context 'with :test_field "TEST" and :should_downcase true' do
53
- let(:context_attributes) { { test_field: 'TEST', should_downcase: true } }
54
-
55
- it { is_expected.to be_a interactor_class.context_class }
56
- it { is_expected.to be_successful }
57
- it { is_expected.to have_attributes(test_field: 'test') }
58
- end
59
-
60
- context 'with :test_field "TEST" and :should_downcase false' do
61
- let(:context_attributes) { { test_field: 'TEST', should_downcase: false } }
62
-
63
- it { is_expected.to be_a interactor_class.context_class }
64
- it { is_expected.to be_successful }
65
- it { is_expected.to have_attributes(test_field: 'TEST') }
66
- end
67
- end
68
- end
69
- end