activeinteractor 1.0.0.beta.7 → 1.0.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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +12 -0
  3. data/CHANGELOG.md +50 -158
  4. data/README.md +13 -856
  5. data/lib/active_interactor.rb +61 -4
  6. data/lib/active_interactor/base.rb +26 -20
  7. data/lib/active_interactor/config.rb +36 -18
  8. data/lib/active_interactor/configurable.rb +17 -9
  9. data/lib/active_interactor/context/attributes.rb +73 -26
  10. data/lib/active_interactor/context/base.rb +236 -65
  11. data/lib/active_interactor/context/loader.rb +20 -15
  12. data/lib/active_interactor/context/status.rb +38 -56
  13. data/lib/active_interactor/error.rb +15 -7
  14. data/lib/active_interactor/interactor/callbacks.rb +174 -160
  15. data/lib/active_interactor/interactor/context.rb +279 -87
  16. data/lib/active_interactor/interactor/perform.rb +256 -0
  17. data/lib/active_interactor/interactor/worker.rb +19 -14
  18. data/lib/active_interactor/models.rb +65 -0
  19. data/lib/active_interactor/organizer/base.rb +18 -0
  20. data/lib/active_interactor/organizer/callbacks.rb +153 -0
  21. data/lib/active_interactor/organizer/interactor_interface.rb +38 -26
  22. data/lib/active_interactor/organizer/interactor_interface_collection.rb +35 -32
  23. data/lib/active_interactor/organizer/organize.rb +67 -0
  24. data/lib/active_interactor/organizer/perform.rb +93 -0
  25. data/lib/active_interactor/rails.rb +0 -10
  26. data/lib/active_interactor/rails/orm/active_record.rb +1 -1
  27. data/lib/active_interactor/rails/railtie.rb +8 -11
  28. data/lib/active_interactor/version.rb +2 -1
  29. data/lib/rails/generators/active_interactor.rb +1 -38
  30. data/lib/rails/generators/active_interactor/application_context_generator.rb +21 -0
  31. data/lib/rails/generators/active_interactor/application_interactor_generator.rb +5 -15
  32. data/lib/rails/generators/active_interactor/application_organizer_generator.rb +21 -0
  33. data/lib/rails/generators/active_interactor/base.rb +29 -0
  34. data/lib/rails/generators/active_interactor/generator.rb +21 -0
  35. data/lib/rails/generators/active_interactor/install_generator.rb +2 -9
  36. data/lib/rails/generators/interactor/context/rspec_generator.rb +3 -10
  37. data/lib/rails/generators/interactor/context/test_unit_generator.rb +4 -11
  38. data/lib/rails/generators/interactor/context_generator.rb +7 -10
  39. data/lib/rails/generators/interactor/generates_context.rb +28 -0
  40. data/lib/rails/generators/interactor/interactor_generator.rb +8 -10
  41. data/lib/rails/generators/interactor/organizer_generator.rb +8 -12
  42. data/lib/rails/generators/interactor/rspec_generator.rb +2 -9
  43. data/lib/rails/generators/interactor/test_unit_generator.rb +3 -10
  44. data/lib/rails/generators/{active_interactor/templates/initializer.erb → templates/active_interactor.erb} +3 -11
  45. data/lib/rails/generators/{active_interactor/templates → templates}/application_context.rb +0 -0
  46. data/lib/rails/generators/{active_interactor/templates → templates}/application_interactor.rb +0 -0
  47. data/lib/rails/generators/templates/application_organizer.rb +4 -0
  48. data/lib/rails/generators/{interactor/templates → templates}/context.erb +0 -0
  49. data/lib/rails/generators/{interactor/context/templates/rspec.erb → templates/context_spec.erb} +0 -0
  50. data/lib/rails/generators/{interactor/context/templates/test_unit.erb → templates/context_test_unit.erb} +0 -0
  51. data/lib/rails/generators/{interactor/templates → templates}/interactor.erb +0 -0
  52. data/lib/rails/generators/{interactor/templates/rspec.erb → templates/interactor_spec.erb} +0 -0
  53. data/lib/rails/generators/{interactor/templates/test_unit.erb → templates/interactor_text_unit.erb} +0 -0
  54. data/lib/rails/generators/{interactor/templates → templates}/organizer.erb +0 -0
  55. data/spec/active_interactor/base_spec.rb +3 -3
  56. data/spec/active_interactor/interactor/{perform_options_spec.rb → perform/options_spec.rb} +1 -1
  57. data/spec/active_interactor/interactor/worker_spec.rb +14 -15
  58. data/spec/active_interactor/{organizer_spec.rb → organizer/base_spec.rb} +27 -17
  59. data/spec/integration/a_basic_interactor_spec.rb +106 -0
  60. data/spec/integration/a_basic_organizer_spec.rb +97 -0
  61. data/spec/integration/a_failing_interactor_spec.rb +42 -0
  62. data/spec/integration/active_record_integration_spec.rb +9 -9
  63. data/spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb +69 -0
  64. data/spec/integration/an_interactor_with_after_perform_callbacks_spec.rb +30 -0
  65. data/spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb +33 -0
  66. data/spec/integration/an_interactor_with_an_existing_context_class_spec.rb +49 -0
  67. data/spec/integration/an_interactor_with_around_perform_callbacks_spec.rb +35 -0
  68. data/spec/integration/an_interactor_with_around_rollback_callbacks_spec.rb +39 -0
  69. data/spec/integration/an_interactor_with_before_perform_callbacks_spec.rb +30 -0
  70. data/spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb +33 -0
  71. data/spec/integration/an_interactor_with_validations_on_called_spec.rb +40 -0
  72. data/spec/integration/an_interactor_with_validations_on_calling_spec.rb +36 -0
  73. data/spec/integration/an_interactor_with_validations_spec.rb +93 -0
  74. data/spec/integration/an_organizer_performing_in_parallel_spec.rb +48 -0
  75. data/spec/integration/an_organizer_with_after_each_callbacks_spec.rb +34 -0
  76. data/spec/integration/an_organizer_with_around_each_callbacks_spec.rb +39 -0
  77. data/spec/integration/an_organizer_with_before_each_callbacks_spec.rb +34 -0
  78. data/spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb +314 -0
  79. data/spec/spec_helper.rb +8 -12
  80. data/spec/support/coverage.rb +4 -0
  81. data/spec/support/coverage/reporters.rb +11 -0
  82. data/spec/support/coverage/reporters/codacy.rb +39 -0
  83. data/spec/support/coverage/reporters/simple_cov.rb +54 -0
  84. data/spec/support/coverage/runner.rb +66 -0
  85. data/spec/support/helpers/factories.rb +1 -1
  86. data/spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb +8 -8
  87. data/spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb +5 -5
  88. data/spec/support/shared_examples/a_class_with_interactor_methods_example.rb +2 -2
  89. data/spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb +3 -3
  90. metadata +83 -40
  91. data/lib/active_interactor/interactor.rb +0 -84
  92. data/lib/active_interactor/interactor/perform_options.rb +0 -29
  93. data/lib/active_interactor/organizer.rb +0 -269
  94. data/lib/active_interactor/rails/config.rb +0 -45
  95. data/lib/active_interactor/rails/models.rb +0 -58
  96. data/lib/rails/generators/active_interactor/templates/application_organizer.rb +0 -4
  97. data/spec/active_interactor/rails/config_spec.rb +0 -29
  98. data/spec/active_interactor/rails_spec.rb +0 -24
  99. data/spec/integration/basic_callback_integration_spec.rb +0 -355
  100. data/spec/integration/basic_context_integration_spec.rb +0 -73
  101. data/spec/integration/basic_integration_spec.rb +0 -570
  102. data/spec/integration/basic_validations_integration_spec.rb +0 -204
@@ -1,570 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'Basic Integration', type: :integration do
6
- describe 'A basic interactor' do
7
- let(:interactor_class) do
8
- build_interactor do
9
- def perform
10
- context.test_field = 'test'
11
- end
12
- end
13
- end
14
-
15
- include_examples 'a class with interactor methods'
16
- include_examples 'a class with interactor callback methods'
17
- include_examples 'a class with interactor context methods'
18
-
19
- describe '.context_class' do
20
- subject { interactor_class.context_class }
21
-
22
- it { is_expected.to eq TestInteractor::Context }
23
- it { is_expected.to be < ActiveInteractor::Context::Base }
24
- end
25
-
26
- describe '.perform' do
27
- subject { interactor_class.perform }
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
-
34
- describe '.perform!' do
35
- subject { interactor_class.perform! }
36
-
37
- it { expect { subject }.not_to raise_error }
38
- it { is_expected.to be_a interactor_class.context_class }
39
- it { is_expected.to be_successful }
40
- it { is_expected.to have_attributes(test_field: 'test') }
41
- end
42
- end
43
-
44
- describe 'A failing interactor' do
45
- let(:interactor_class) do
46
- build_interactor do
47
- def perform
48
- context.fail!
49
- end
50
- end
51
- end
52
-
53
- include_examples 'a class with interactor methods'
54
- include_examples 'a class with interactor callback methods'
55
- include_examples 'a class with interactor context methods'
56
-
57
- describe '.context_class' do
58
- subject { interactor_class.context_class }
59
-
60
- it { is_expected.to eq TestInteractor::Context }
61
- it { is_expected.to be < ActiveInteractor::Context::Base }
62
- end
63
-
64
- describe '.perform' do
65
- subject { interactor_class.perform }
66
-
67
- it { expect { subject }.not_to raise_error }
68
- it { is_expected.to be_a interactor_class.context_class }
69
- it { is_expected.to be_failure }
70
- it 'is expected to #rollback' do
71
- expect_any_instance_of(interactor_class).to receive(:rollback)
72
- subject
73
- end
74
- end
75
-
76
- describe '.perform!' do
77
- subject { interactor_class.perform! }
78
-
79
- it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
80
- end
81
- end
82
-
83
- describe 'A basic organizer' do
84
- let!(:test_interactor_1) do
85
- build_interactor('TestInteractor1') do
86
- def perform
87
- context.test_field_1 = 'test 1'
88
- end
89
- end
90
- end
91
-
92
- let!(:test_interactor_2) do
93
- build_interactor('TestInteractor2') do
94
- def perform
95
- context.test_field_2 = 'test 2'
96
- end
97
- end
98
- end
99
-
100
- let(:interactor_class) do
101
- build_organizer do
102
- organize TestInteractor1, TestInteractor2
103
- end
104
- end
105
-
106
- include_examples 'a class with interactor methods'
107
- include_examples 'a class with interactor callback methods'
108
- include_examples 'a class with interactor context methods'
109
- include_examples 'a class with organizer callback methods'
110
-
111
- describe '.context_class' do
112
- subject { interactor_class.context_class }
113
-
114
- it { is_expected.to eq TestOrganizer::Context }
115
- it { is_expected.to be < ActiveInteractor::Context::Base }
116
- end
117
-
118
- describe '.perform' do
119
- subject { interactor_class.perform }
120
-
121
- it { is_expected.to be_a interactor_class.context_class }
122
- it { is_expected.to be_successful }
123
- it { is_expected.to have_attributes(test_field_1: 'test 1', test_field_2: 'test 2') }
124
- end
125
- end
126
-
127
- describe 'A basic organizer having the first interactor fail' do
128
- let!(:test_interactor_1) do
129
- build_interactor('TestInteractor1') do
130
- def perform
131
- context.fail!
132
- end
133
- end
134
- end
135
-
136
- let!(:test_interactor_2) do
137
- build_interactor('TestInteractor2') do
138
- def perform
139
- context.test_field_2 = 'test 2'
140
- end
141
- end
142
- end
143
-
144
- let(:interactor_class) do
145
- build_organizer do
146
- organize TestInteractor1, TestInteractor2
147
- end
148
- end
149
-
150
- include_examples 'a class with interactor methods'
151
- include_examples 'a class with interactor callback methods'
152
- include_examples 'a class with interactor context methods'
153
- include_examples 'a class with organizer callback methods'
154
-
155
- describe '.perform' do
156
- subject { interactor_class.perform }
157
-
158
- it { expect { subject }.not_to raise_error }
159
- it { is_expected.to be_a interactor_class.context_class }
160
- it { is_expected.to be_failure }
161
- it 'is expected to rollback the first interactor' do
162
- expect_any_instance_of(test_interactor_1).to receive(:rollback)
163
- .and_call_original
164
- subject
165
- end
166
- it 'is expected not to call #perform! on the second interactor' do
167
- expect_any_instance_of(test_interactor_2).not_to receive(:perform!)
168
- subject
169
- end
170
- end
171
- end
172
-
173
- describe 'A basic organizer having the second interactor fail' do
174
- let!(:test_interactor_1) do
175
- build_interactor('TestInteractor1') do
176
- def perform
177
- context.test_field_1 = 'test 1'
178
- end
179
- end
180
- end
181
-
182
- let!(:test_interactor_2) do
183
- build_interactor('TestInteractor2') do
184
- def perform
185
- context.fail!
186
- end
187
- end
188
- end
189
-
190
- let(:interactor_class) do
191
- build_organizer do
192
- organize TestInteractor1, TestInteractor2
193
- end
194
- end
195
-
196
- include_examples 'a class with interactor methods'
197
- include_examples 'a class with interactor callback methods'
198
- include_examples 'a class with interactor context methods'
199
- include_examples 'a class with organizer callback methods'
200
-
201
- describe '.perform' do
202
- subject { interactor_class.perform }
203
-
204
- it { expect { subject }.not_to raise_error }
205
- it { is_expected.to be_a interactor_class.context_class }
206
- it { is_expected.to be_failure }
207
- it 'is expected to rollback all interactors' do
208
- expect_any_instance_of(test_interactor_2).to receive(:rollback)
209
- expect_any_instance_of(test_interactor_1).to receive(:rollback)
210
- subject
211
- end
212
- end
213
- end
214
-
215
- describe 'A basic organizer performing in parallel' do
216
- let!(:test_interactor_1) do
217
- build_interactor('TestInteractor1') do
218
- def perform
219
- context.test_field_1 = 'test 1'
220
- end
221
- end
222
- end
223
-
224
- let!(:test_interactor_2) do
225
- build_interactor('TestInteractor2') do
226
- def perform
227
- context.test_field_2 = 'test 2'
228
- end
229
- end
230
- end
231
-
232
- let(:interactor_class) do
233
- build_organizer do
234
- perform_in_parallel
235
- organize TestInteractor1, TestInteractor2
236
- end
237
- end
238
-
239
- include_examples 'a class with interactor methods'
240
- include_examples 'a class with interactor callback methods'
241
- include_examples 'a class with interactor context methods'
242
- include_examples 'a class with organizer callback methods'
243
-
244
- describe '.context_class' do
245
- subject { interactor_class.context_class }
246
-
247
- it { is_expected.to eq TestOrganizer::Context }
248
- it { is_expected.to be < ActiveInteractor::Context::Base }
249
- end
250
-
251
- describe '.perform' do
252
- subject { interactor_class.perform }
253
-
254
- it { is_expected.to be_a interactor_class.context_class }
255
- it { is_expected.to be_successful }
256
- it { is_expected.to have_attributes(test_field_1: 'test 1', test_field_2: 'test 2') }
257
- end
258
- end
259
-
260
- describe 'A basic with conditionally organized interactors' do
261
- let!(:test_interactor_1) { build_interactor('TestInteractor1') }
262
- let!(:test_interactor_2) { build_interactor('TestInteractor2') }
263
-
264
- context 'with a condition on the first interactor { :if => -> { context.test_1 } } ' \
265
- 'and a condition on the second interactor { :if => -> { context.test_2 } }' do
266
- let(:interactor_class) do
267
- build_organizer do
268
- organize do
269
- add :test_interactor_1, if: -> { context.test_1 }
270
- add :test_interactor_2, if: -> { context.test_2 }
271
- end
272
- end
273
- end
274
-
275
- include_examples 'a class with interactor methods'
276
- include_examples 'a class with interactor callback methods'
277
- include_examples 'a class with interactor context methods'
278
- include_examples 'a class with organizer callback methods'
279
-
280
- describe '.perform' do
281
- subject { interactor_class.perform(context_attributes) }
282
-
283
- context 'with context_attributes test_1 and test_2 both eq to true' do
284
- let(:context_attributes) { { test_1: true, test_2: true } }
285
-
286
- it { is_expected.to be_a interactor_class.context_class }
287
- it { is_expected.to be_successful }
288
- it 'is expected to invoke #perform on both interactors' do
289
- expect_any_instance_of(test_interactor_1).to receive(:perform)
290
- expect_any_instance_of(test_interactor_2).to receive(:perform)
291
- subject
292
- end
293
- end
294
-
295
- context 'with context_attributes test_1 eq to true and test_2 eq to false' do
296
- let(:context_attributes) { { test_1: true, test_2: false } }
297
-
298
- it { is_expected.to be_a interactor_class.context_class }
299
- it { is_expected.to be_successful }
300
- it 'is expected to invoke #perform on the first interactor' do
301
- expect_any_instance_of(test_interactor_1).to receive(:perform)
302
- subject
303
- end
304
-
305
- it 'is expected not to invoke #perform on the first interactor' do
306
- expect_any_instance_of(test_interactor_2).not_to receive(:perform)
307
- subject
308
- end
309
- end
310
-
311
- context 'with context_attributes test_1 eq to false and test_2 eq to true' do
312
- let(:context_attributes) { { test_1: false, test_2: true } }
313
-
314
- it { is_expected.to be_a interactor_class.context_class }
315
- it { is_expected.to be_successful }
316
- it 'is expected not to invoke #perform on the first interactor' do
317
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
318
- subject
319
- end
320
-
321
- it 'is expected to invoke #perform on the first interactor' do
322
- expect_any_instance_of(test_interactor_2).to receive(:perform)
323
- subject
324
- end
325
- end
326
-
327
- context 'with context_attributes test_1 and test_2 both eq to false' do
328
- let(:context_attributes) { { test_1: false, test_2: false } }
329
-
330
- it { is_expected.to be_a interactor_class.context_class }
331
- it { is_expected.to be_successful }
332
- it 'is expected not to invoke #perform on the first interactor' do
333
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
334
- subject
335
- end
336
-
337
- it 'is expected not to invoke #perform on the first interactor' do
338
- expect_any_instance_of(test_interactor_2).not_to receive(:perform)
339
- subject
340
- end
341
- end
342
- end
343
- end
344
-
345
- context 'with a condition on the first interactor { :unless => -> { context.test_1 } } ' \
346
- 'and a condition on the second interactor { :unless => -> { context.test_2 } }' do
347
- let(:interactor_class) do
348
- build_organizer do
349
- organize do
350
- add :test_interactor_1, unless: -> { context.test_1 }
351
- add :test_interactor_2, unless: -> { context.test_2 }
352
- end
353
- end
354
- end
355
-
356
- include_examples 'a class with interactor methods'
357
- include_examples 'a class with interactor callback methods'
358
- include_examples 'a class with interactor context methods'
359
- include_examples 'a class with organizer callback methods'
360
-
361
- describe '.perform' do
362
- subject { interactor_class.perform(context_attributes) }
363
-
364
- context 'with context_attributes test_1 and test_2 both eq to true' do
365
- let(:context_attributes) { { test_1: true, test_2: true } }
366
-
367
- it { is_expected.to be_a interactor_class.context_class }
368
- it { is_expected.to be_successful }
369
- it 'is expected not to invoke #perform on the first interactor' do
370
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
371
- subject
372
- end
373
-
374
- it 'is expected not to invoke #perform on the second interactor' do
375
- expect_any_instance_of(test_interactor_2).not_to receive(:perform)
376
- subject
377
- end
378
- end
379
-
380
- context 'with context_attributes test_1 eq to true and test_2 eq to false' do
381
- let(:context_attributes) { { test_1: true, test_2: false } }
382
-
383
- it { is_expected.to be_a interactor_class.context_class }
384
- it { is_expected.to be_successful }
385
- it 'is expected not to invoke #perform on the first interactor' do
386
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
387
- subject
388
- end
389
-
390
- it 'is expected to invoke #perform on the second interactor' do
391
- expect_any_instance_of(test_interactor_2).to receive(:perform)
392
- subject
393
- end
394
- end
395
-
396
- context 'with context_attributes test_1 eq to false and test_2 eq to true' do
397
- let(:context_attributes) { { test_1: false, test_2: true } }
398
-
399
- it { is_expected.to be_a interactor_class.context_class }
400
- it { is_expected.to be_successful }
401
- it 'is expected to invoke #perform on the first interactor' do
402
- expect_any_instance_of(test_interactor_1).to receive(:perform)
403
- subject
404
- end
405
-
406
- it 'is expected not to invoke #perform on the second interactor' do
407
- expect_any_instance_of(test_interactor_2).not_to receive(:perform)
408
- subject
409
- end
410
- end
411
-
412
- context 'with context_attributes test_1 and test_2 both eq to false' do
413
- let(:context_attributes) { { test_1: false, test_2: false } }
414
-
415
- it { is_expected.to be_a interactor_class.context_class }
416
- it { is_expected.to be_successful }
417
- it 'is expected to invoke #perform on both interactors' do
418
- expect_any_instance_of(test_interactor_1).to receive(:perform)
419
- expect_any_instance_of(test_interactor_2).to receive(:perform)
420
- subject
421
- end
422
- end
423
- end
424
- end
425
-
426
- context 'with a condition on the first interactor { :if => :test_method } and :test_method returning true' do
427
- let(:interactor_class) do
428
- build_organizer do
429
- organize do
430
- add :test_interactor_1, if: :test_method
431
- add :test_interactor_2
432
- end
433
-
434
- private
435
-
436
- def test_method
437
- true
438
- end
439
- end
440
- end
441
-
442
- include_examples 'a class with interactor methods'
443
- include_examples 'a class with interactor callback methods'
444
- include_examples 'a class with interactor context methods'
445
- include_examples 'a class with organizer callback methods'
446
-
447
- describe '.perform' do
448
- subject { interactor_class.perform }
449
-
450
- it { is_expected.to be_a interactor_class.context_class }
451
- it { is_expected.to be_successful }
452
- it 'is expected to invoke #perform on both interactors' do
453
- expect_any_instance_of(test_interactor_1).to receive(:perform)
454
- expect_any_instance_of(test_interactor_2).to receive(:perform)
455
- subject
456
- end
457
- end
458
- end
459
-
460
- context 'with a condition on the first interactor { :if => :test_method } and :test_method returning false' do
461
- let(:interactor_class) do
462
- build_organizer do
463
- organize do
464
- add :test_interactor_1, if: :test_method
465
- add :test_interactor_2
466
- end
467
-
468
- private
469
-
470
- def test_method
471
- false
472
- end
473
- end
474
- end
475
-
476
- include_examples 'a class with interactor methods'
477
- include_examples 'a class with interactor callback methods'
478
- include_examples 'a class with interactor context methods'
479
- include_examples 'a class with organizer callback methods'
480
-
481
- describe '.perform' do
482
- subject { interactor_class.perform }
483
-
484
- it { is_expected.to be_a interactor_class.context_class }
485
- it { is_expected.to be_successful }
486
- it 'is expected not to invoke #perform on the first interactor' do
487
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
488
- subject
489
- end
490
-
491
- it 'is expected to invoke #perform on the second interactor' do
492
- expect_any_instance_of(test_interactor_2).to receive(:perform)
493
- subject
494
- end
495
- end
496
- end
497
-
498
- context 'with a condition on the first interactor { :unless => :test_method } and :test_method returning true' do
499
- let(:interactor_class) do
500
- build_organizer do
501
- organize do
502
- add :test_interactor_1, unless: :test_method
503
- add :test_interactor_2
504
- end
505
-
506
- private
507
-
508
- def test_method
509
- true
510
- end
511
- end
512
- end
513
-
514
- include_examples 'a class with interactor methods'
515
- include_examples 'a class with interactor callback methods'
516
- include_examples 'a class with interactor context methods'
517
- include_examples 'a class with organizer callback methods'
518
-
519
- describe '.perform' do
520
- subject { interactor_class.perform }
521
-
522
- it { is_expected.to be_a interactor_class.context_class }
523
- it { is_expected.to be_successful }
524
- it 'is expected not to invoke #perform on the first interactor' do
525
- expect_any_instance_of(test_interactor_1).not_to receive(:perform)
526
- subject
527
- end
528
-
529
- it 'is expected to invoke #perform on the second interactor' do
530
- expect_any_instance_of(test_interactor_2).to receive(:perform)
531
- subject
532
- end
533
- end
534
- end
535
-
536
- context 'with a condition on the first interactor { :unless => :test_method } and :test_method returning false' do
537
- let(:interactor_class) do
538
- build_organizer do
539
- organize do
540
- add :test_interactor_1, unless: :test_method
541
- add :test_interactor_2
542
- end
543
-
544
- private
545
-
546
- def test_method
547
- false
548
- end
549
- end
550
- end
551
-
552
- include_examples 'a class with interactor methods'
553
- include_examples 'a class with interactor callback methods'
554
- include_examples 'a class with interactor context methods'
555
- include_examples 'a class with organizer callback methods'
556
-
557
- describe '.perform' do
558
- subject { interactor_class.perform }
559
-
560
- it { is_expected.to be_a interactor_class.context_class }
561
- it { is_expected.to be_successful }
562
- it 'is expected to invoke #perform on both interactors' do
563
- expect_any_instance_of(test_interactor_1).to receive(:perform)
564
- expect_any_instance_of(test_interactor_2).to receive(:perform)
565
- subject
566
- end
567
- end
568
- end
569
- end
570
- end