activeinteractor 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -3
- data/lib/active_interactor/interactor/worker.rb +7 -1
- data/lib/active_interactor/organizer/perform.rb +8 -9
- data/lib/active_interactor/version.rb +1 -1
- metadata +7 -127
- data/spec/active_interactor/base_spec.rb +0 -85
- data/spec/active_interactor/config_spec.rb +0 -17
- data/spec/active_interactor/context/base_spec.rb +0 -443
- data/spec/active_interactor/error_spec.rb +0 -45
- data/spec/active_interactor/interactor/perform/options_spec.rb +0 -25
- data/spec/active_interactor/interactor/worker_spec.rb +0 -189
- data/spec/active_interactor/organizer/base_spec.rb +0 -276
- data/spec/active_interactor/organizer/interactor_interface_collection_spec.rb +0 -78
- data/spec/active_interactor/organizer/interactor_interface_spec.rb +0 -235
- data/spec/active_interactor/version_spec.rb +0 -119
- data/spec/active_interactor_spec.rb +0 -23
- data/spec/integration/a_basic_interactor_spec.rb +0 -154
- data/spec/integration/a_basic_organizer_spec.rb +0 -354
- data/spec/integration/a_failing_interactor_spec.rb +0 -43
- data/spec/integration/active_record_integration_spec.rb +0 -32
- data/spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb +0 -69
- data/spec/integration/an_interactor_with_after_perform_callbacks_spec.rb +0 -31
- data/spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb +0 -34
- data/spec/integration/an_interactor_with_an_existing_context_class_spec.rb +0 -50
- data/spec/integration/an_interactor_with_around_perform_callbacks_spec.rb +0 -35
- data/spec/integration/an_interactor_with_around_rollback_callbacks_spec.rb +0 -39
- data/spec/integration/an_interactor_with_before_perform_callbacks_spec.rb +0 -31
- data/spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb +0 -34
- data/spec/integration/an_interactor_with_deferred_after_callbacks.rb +0 -32
- data/spec/integration/an_interactor_with_validations_on_called_spec.rb +0 -41
- data/spec/integration/an_interactor_with_validations_on_calling_spec.rb +0 -37
- data/spec/integration/an_interactor_with_validations_spec.rb +0 -95
- data/spec/integration/an_organizer_containing_organizer_with_after_callbacks_deferred_spec.rb +0 -125
- data/spec/integration/an_organizer_performing_in_parallel_spec.rb +0 -48
- data/spec/integration/an_organizer_with_after_callbacks_deferred_spec.rb +0 -154
- data/spec/integration/an_organizer_with_after_each_callbacks_spec.rb +0 -35
- data/spec/integration/an_organizer_with_all_perform_callbacks.rb +0 -112
- data/spec/integration/an_organizer_with_around_each_callbacks_spec.rb +0 -39
- data/spec/integration/an_organizer_with_before_each_callbacks_spec.rb +0 -35
- data/spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb +0 -326
- data/spec/integration/an_organizer_with_failing_nested_organizer_spec.rb +0 -47
- data/spec/integration/an_organizer_with_options_callbacks_spec.rb +0 -64
- data/spec/spec_helper.rb +0 -33
- data/spec/support/coverage.rb +0 -50
- data/spec/support/helpers/factories.rb +0 -49
- data/spec/support/shared_examples/a_class_that_extends_active_interactor_models_example.rb +0 -81
- data/spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb +0 -107
- data/spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb +0 -60
- data/spec/support/shared_examples/a_class_with_interactor_methods_example.rb +0 -21
- data/spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb +0 -42
- data/spec/support/spec_helpers.rb +0 -7
@@ -1,443 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe ActiveInteractor::Context::Base do
|
6
|
-
describe '.attributes' do
|
7
|
-
context 'when no arguments are passed' do
|
8
|
-
subject { context_class.attributes }
|
9
|
-
|
10
|
-
let!(:context_class) { build_context }
|
11
|
-
|
12
|
-
it { is_expected.to eq [] }
|
13
|
-
|
14
|
-
context 'when an attribute :foo was previously defined' do
|
15
|
-
let!(:context_class) do
|
16
|
-
build_context do
|
17
|
-
attributes :foo
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it { is_expected.to eq %i[foo] }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when given arguments :foo and :bar' do
|
26
|
-
subject { context_class.attributes(:foo, :bar) }
|
27
|
-
|
28
|
-
let!(:context_class) { build_context }
|
29
|
-
|
30
|
-
it { is_expected.to eq %i[bar foo] }
|
31
|
-
|
32
|
-
context 'when an attribute :foo was previously defined' do
|
33
|
-
before { TestContext.attributes(:foo) }
|
34
|
-
|
35
|
-
it { is_expected.to eq %i[bar foo] }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#[]' do
|
41
|
-
subject { instance[attribute] }
|
42
|
-
|
43
|
-
context 'with class attributes []' do
|
44
|
-
let(:instance) { build_context.new }
|
45
|
-
|
46
|
-
context 'with attribute nil' do
|
47
|
-
let(:attribute) { :foo }
|
48
|
-
|
49
|
-
it { is_expected.to be_nil }
|
50
|
-
end
|
51
|
-
|
52
|
-
context 'with attribute equal to "foo"' do
|
53
|
-
let(:attribute) { :foo }
|
54
|
-
|
55
|
-
before { instance.foo = 'foo' }
|
56
|
-
|
57
|
-
it { is_expected.to eq 'foo' }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'with class attributes [:foo]' do
|
62
|
-
let!(:context_class) do
|
63
|
-
build_context do
|
64
|
-
attributes :foo
|
65
|
-
end
|
66
|
-
end
|
67
|
-
let(:instance) { context_class.new }
|
68
|
-
|
69
|
-
context 'with attribute nil' do
|
70
|
-
let(:attribute) { :foo }
|
71
|
-
|
72
|
-
it { is_expected.to be_nil }
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'with attribute equal to "foo"' do
|
76
|
-
let(:attribute) { :foo }
|
77
|
-
|
78
|
-
before { instance.foo = 'foo' }
|
79
|
-
|
80
|
-
it { is_expected.to eq 'foo' }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe '#attribute?' do
|
86
|
-
subject { instance.attribute?(attribute) }
|
87
|
-
|
88
|
-
context 'with class attributes []' do
|
89
|
-
let(:instance) { build_context.new }
|
90
|
-
let(:attribute) { :foo }
|
91
|
-
|
92
|
-
it { is_expected.to eq false }
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'with class attributes [:foo]' do
|
96
|
-
let!(:context_class) do
|
97
|
-
build_context do
|
98
|
-
attributes :foo
|
99
|
-
end
|
100
|
-
end
|
101
|
-
let(:instance) { context_class.new }
|
102
|
-
|
103
|
-
context 'checking attribute :foo' do
|
104
|
-
let(:attribute) { :foo }
|
105
|
-
|
106
|
-
it { is_expected.to eq true }
|
107
|
-
end
|
108
|
-
|
109
|
-
context 'checking attribute :bar' do
|
110
|
-
let(:attribute) { :bar }
|
111
|
-
|
112
|
-
it { is_expected.to eq false }
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '#attributes' do
|
118
|
-
subject { instance.attributes }
|
119
|
-
|
120
|
-
context 'with class attributes []' do
|
121
|
-
context 'with an instance having attributes { :foo => "foo", :bar => "bar", :baz => "baz" }' do
|
122
|
-
let(:instance) { described_class.new(foo: 'foo', bar: 'bar', baz: 'baz') }
|
123
|
-
|
124
|
-
it { is_expected.to be_a Hash }
|
125
|
-
it { is_expected.to be_empty }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'with class attributes [:foo, :bar, :baz]' do
|
130
|
-
before { build_context.attributes(:foo, :bar) }
|
131
|
-
|
132
|
-
context 'with an instance having attributes { :foo => "foo", :bar => "bar" }' do
|
133
|
-
let(:instance) { TestContext.new(foo: 'foo', bar: 'bar') }
|
134
|
-
|
135
|
-
it { is_expected.to be_a Hash }
|
136
|
-
it { is_expected.to eq(bar: 'bar', foo: 'foo') }
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'with an instance having attributes { :foo => "foo", :bar => "bar", :baz => "baz" }' do
|
140
|
-
let(:instance) { TestContext.new(foo: 'foo', bar: 'bar', baz: 'baz') }
|
141
|
-
|
142
|
-
it { is_expected.to be_a Hash }
|
143
|
-
it { is_expected.to eq(bar: 'bar', foo: 'foo') }
|
144
|
-
|
145
|
-
it 'is expected to assign :baz' do
|
146
|
-
expect(instance.baz).to eq 'baz'
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe '#called!' do
|
153
|
-
subject do
|
154
|
-
instance.called!(interactor1)
|
155
|
-
instance.called!(interactor2)
|
156
|
-
end
|
157
|
-
|
158
|
-
let(:instance) { described_class.new }
|
159
|
-
let(:interactor1) { double(:interactor1) }
|
160
|
-
let(:interactor2) { double(:interactor2) }
|
161
|
-
|
162
|
-
it 'is expected to append interactors to instance variable _called' do
|
163
|
-
expect { subject }.to change { instance.send(:_called) }
|
164
|
-
.from([])
|
165
|
-
.to([interactor1, interactor2])
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe '#fail!' do
|
170
|
-
subject { instance.fail!(errors) }
|
171
|
-
|
172
|
-
let(:instance) { described_class.new }
|
173
|
-
|
174
|
-
context 'with errors equal to nil' do
|
175
|
-
let(:errors) { nil }
|
176
|
-
|
177
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
178
|
-
|
179
|
-
it 'is expected not to merge errors' do
|
180
|
-
expect(instance.errors).not_to receive(:merge!).with(nil)
|
181
|
-
subject
|
182
|
-
rescue ActiveInteractor::Error::ContextFailure # rubocop:disable Lint/SuppressedException
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'is expected to be a failure' do
|
186
|
-
subject
|
187
|
-
rescue ActiveInteractor::Error::ContextFailure
|
188
|
-
expect(instance).to be_a_failure
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'with errors from another instance on the attribute :foo' do
|
193
|
-
let(:errors) { instance2.errors }
|
194
|
-
let(:instance2) { described_class.new }
|
195
|
-
|
196
|
-
before { instance2.errors.add(:foo, 'foo') }
|
197
|
-
|
198
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
199
|
-
|
200
|
-
it 'is expected to merge errors' do
|
201
|
-
subject
|
202
|
-
rescue ActiveInteractor::Error::ContextFailure
|
203
|
-
expect(instance.errors[:foo]).to eq instance2.errors[:foo]
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'is expected to be a failure' do
|
207
|
-
subject
|
208
|
-
rescue ActiveInteractor::Error::ContextFailure
|
209
|
-
expect(instance).to be_a_failure
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'with errors "foo"' do
|
214
|
-
let(:errors) { 'foo' }
|
215
|
-
|
216
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
217
|
-
|
218
|
-
it 'is expected to have error on :context equal to "foo"' do
|
219
|
-
subject
|
220
|
-
rescue ActiveInteractor::Error::ContextFailure
|
221
|
-
expect(instance.errors[:context]).to include 'foo'
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'is expected to be a failure' do
|
225
|
-
subject
|
226
|
-
rescue ActiveInteractor::Error::ContextFailure
|
227
|
-
expect(instance).to be_a_failure
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
describe '#failure?' do
|
233
|
-
subject { instance.failure? }
|
234
|
-
|
235
|
-
let(:instance) { described_class.new }
|
236
|
-
|
237
|
-
it { is_expected.to eq false }
|
238
|
-
|
239
|
-
context 'when context has failed' do
|
240
|
-
before { instance.instance_variable_set('@_failed', true) }
|
241
|
-
|
242
|
-
it { is_expected.to eq true }
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe '#merge' do
|
247
|
-
subject { instance.merge!(attributes) }
|
248
|
-
|
249
|
-
context 'with an instance having attributes { :foo => "foo"}' do
|
250
|
-
let(:instance) { described_class.new(foo: 'foo') }
|
251
|
-
|
252
|
-
context 'with a hash having attributes { :bar => "bar"}' do
|
253
|
-
let(:attributes) { { bar: 'bar' } }
|
254
|
-
|
255
|
-
it { is_expected.to be_a described_class }
|
256
|
-
it { is_expected.to have_attributes(foo: 'foo', bar: 'bar') }
|
257
|
-
end
|
258
|
-
|
259
|
-
context 'with a hash having attributes { :foo => "foobar"}' do
|
260
|
-
let(:attributes) { { foo: 'foobar' } }
|
261
|
-
|
262
|
-
it { is_expected.to be_a described_class }
|
263
|
-
it { is_expected.to have_attributes(foo: 'foobar') }
|
264
|
-
end
|
265
|
-
|
266
|
-
context 'with a previous instance having attributes { :bar => "bar" }' do
|
267
|
-
let(:attributes) { described_class.new(bar: 'bar') }
|
268
|
-
|
269
|
-
it { is_expected.to be_a described_class }
|
270
|
-
it { is_expected.to have_attributes(foo: 'foo', bar: 'bar') }
|
271
|
-
|
272
|
-
context 'having errors on :foo' do
|
273
|
-
before { attributes.errors.add(:foo, 'invalid') }
|
274
|
-
|
275
|
-
it 'is expected to have errors on :foo' do
|
276
|
-
expect(subject.errors[:foo]).not_to be_nil
|
277
|
-
expect(subject.errors[:foo]).to include 'invalid'
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
context 'having instance variable @_failed equal to true' do
|
282
|
-
before { attributes.instance_variable_set('@_failed', true) }
|
283
|
-
|
284
|
-
it { is_expected.to be_a described_class }
|
285
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
286
|
-
|
287
|
-
it 'is expected to preserve @_failed instance variable' do
|
288
|
-
expect(subject.instance_variable_get('@_failed')).to eq true
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context 'having instance variable @_rolled_back equal to true' do
|
293
|
-
before { attributes.instance_variable_set('@_rolled_back', true) }
|
294
|
-
|
295
|
-
it { is_expected.to be_a described_class }
|
296
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
297
|
-
|
298
|
-
it 'is expected to preserve @_rolled_back instance variable' do
|
299
|
-
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
context 'with a previous instance having attributes { :foo => "foobar"}' do
|
305
|
-
let(:attributes) { described_class.new(foo: 'foobar') }
|
306
|
-
|
307
|
-
it { is_expected.to be_a described_class }
|
308
|
-
it { is_expected.to have_attributes(foo: 'foobar') }
|
309
|
-
end
|
310
|
-
|
311
|
-
context 'having errors on :foo' do
|
312
|
-
before { instance.errors.add(:foo, 'invalid') }
|
313
|
-
|
314
|
-
context 'with a previous instance having attributes { :bar => "bar" }' do
|
315
|
-
let(:attributes) { described_class.new(bar: 'bar') }
|
316
|
-
|
317
|
-
it 'is expected to have errors on :foo' do
|
318
|
-
expect(subject.errors[:foo]).not_to be_nil
|
319
|
-
expect(subject.errors[:foo]).to include 'invalid'
|
320
|
-
end
|
321
|
-
|
322
|
-
context 'having errors on :bar' do
|
323
|
-
before { attributes.errors.add(:bar, 'invalid') }
|
324
|
-
|
325
|
-
it 'is expected to have errors on :foo' do
|
326
|
-
expect(subject.errors[:foo]).not_to be_nil
|
327
|
-
expect(subject.errors[:foo]).to include 'invalid'
|
328
|
-
end
|
329
|
-
|
330
|
-
it 'is expected to have errors on :bar' do
|
331
|
-
expect(subject.errors[:bar]).not_to be_nil
|
332
|
-
expect(subject.errors[:bar]).to include 'invalid'
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
describe '#new' do
|
341
|
-
subject { described_class.new(attributes) }
|
342
|
-
|
343
|
-
context 'with a hash having attributes { :foo => "foo"}' do
|
344
|
-
let(:attributes) { { foo: 'foo' } }
|
345
|
-
|
346
|
-
it { is_expected.to be_a described_class }
|
347
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
348
|
-
end
|
349
|
-
|
350
|
-
context 'with a previous instance having attributes { :foo => "foo" }' do
|
351
|
-
let(:attributes) { described_class.new(foo: 'foo') }
|
352
|
-
|
353
|
-
it { is_expected.to be_a described_class }
|
354
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
355
|
-
|
356
|
-
context 'having errors on :foo' do
|
357
|
-
before { attributes.errors.add(:foo, 'invalid') }
|
358
|
-
|
359
|
-
it { is_expected.to be_a described_class }
|
360
|
-
|
361
|
-
it 'is expected to have errors on :foo' do
|
362
|
-
expect(subject.errors[:foo]).not_to be_nil
|
363
|
-
expect(subject.errors[:foo]).to include 'invalid'
|
364
|
-
end
|
365
|
-
end
|
366
|
-
|
367
|
-
context 'having instance variable @_called equal to ["foo"]' do
|
368
|
-
before { attributes.instance_variable_set('@_called', %w[foo]) }
|
369
|
-
|
370
|
-
it { is_expected.to be_a described_class }
|
371
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
372
|
-
|
373
|
-
it 'is expected to preserve @_called instance variable' do
|
374
|
-
expect(subject.instance_variable_get('@_called')).to eq %w[foo]
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
context 'having instance variable @_failed equal to true' do
|
379
|
-
before { attributes.instance_variable_set('@_failed', true) }
|
380
|
-
|
381
|
-
it { is_expected.to be_a described_class }
|
382
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
383
|
-
|
384
|
-
it 'is expected to preserve @_failed instance variable' do
|
385
|
-
expect(subject.instance_variable_get('@_failed')).to eq true
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
context 'having instance variable @_rolled_back equal to true' do
|
390
|
-
before { attributes.instance_variable_set('@_rolled_back', true) }
|
391
|
-
|
392
|
-
it { is_expected.to be_a described_class }
|
393
|
-
it { is_expected.to have_attributes(foo: 'foo') }
|
394
|
-
|
395
|
-
it 'is expected to preserve @_rolled_back instance variable' do
|
396
|
-
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
397
|
-
end
|
398
|
-
end
|
399
|
-
end
|
400
|
-
end
|
401
|
-
|
402
|
-
describe '#rollback!' do
|
403
|
-
subject { instance.rollback! }
|
404
|
-
|
405
|
-
let(:instance) { described_class.new }
|
406
|
-
|
407
|
-
context 'with #called! interactors' do
|
408
|
-
let(:interactor1) { double(:interactor1) }
|
409
|
-
let(:interactor2) { double(:interactor2) }
|
410
|
-
|
411
|
-
before do
|
412
|
-
allow(instance).to receive(:_called).and_return([interactor1, interactor2])
|
413
|
-
end
|
414
|
-
|
415
|
-
it 'is expected to rollback each interactor in reverse order' do
|
416
|
-
expect(interactor2).to receive(:rollback).once.with(no_args).ordered
|
417
|
-
expect(interactor1).to receive(:rollback).once.with(no_args).ordered
|
418
|
-
subject
|
419
|
-
end
|
420
|
-
|
421
|
-
it 'is expected to ignore subsequent attempts' do
|
422
|
-
expect(interactor2).to receive(:rollback).once
|
423
|
-
expect(interactor1).to receive(:rollback).once
|
424
|
-
subject
|
425
|
-
subject
|
426
|
-
end
|
427
|
-
end
|
428
|
-
end
|
429
|
-
|
430
|
-
describe '#success?' do
|
431
|
-
subject { instance.success? }
|
432
|
-
|
433
|
-
let(:instance) { described_class.new }
|
434
|
-
|
435
|
-
it { is_expected.to eq true }
|
436
|
-
|
437
|
-
context 'when context has failed' do
|
438
|
-
before { instance.instance_variable_set('@_failed', true) }
|
439
|
-
|
440
|
-
it { is_expected.to eq false }
|
441
|
-
end
|
442
|
-
end
|
443
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe ActiveInteractor::Error::ContextFailure do
|
6
|
-
subject { described_class.new }
|
7
|
-
|
8
|
-
it { is_expected.to respond_to :context }
|
9
|
-
|
10
|
-
context 'when context is equal to nil' do
|
11
|
-
subject { described_class.new(nil) }
|
12
|
-
|
13
|
-
it { is_expected.to have_attributes(message: 'Context failed!') }
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when context is an instance of "TestContext"' do
|
17
|
-
subject { described_class.new(TestContext.new) }
|
18
|
-
|
19
|
-
before { build_context }
|
20
|
-
|
21
|
-
it { is_expected.to have_attributes(message: 'TestContext failed!') }
|
22
|
-
|
23
|
-
it 'is expected to have an instance of TestContext' do
|
24
|
-
expect(subject.context).to be_a TestContext
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
RSpec.describe ActiveInteractor::Error::InvalidContextClass do
|
30
|
-
subject { described_class.new }
|
31
|
-
|
32
|
-
it { is_expected.to respond_to :class_name }
|
33
|
-
|
34
|
-
context 'when class_name is equal to nil' do
|
35
|
-
subject { described_class.new(nil) }
|
36
|
-
|
37
|
-
it { is_expected.to have_attributes(message: 'invalid context class ') }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'when class_name is equal to "MyContect"' do
|
41
|
-
subject { described_class.new('MyContext') }
|
42
|
-
|
43
|
-
it { is_expected.to have_attributes(message: 'invalid context class MyContext') }
|
44
|
-
end
|
45
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe ActiveInteractor::Interactor::Perform::Options do
|
6
|
-
subject { described_class.new }
|
7
|
-
|
8
|
-
it { is_expected.to respond_to :skip_each_perform_callbacks }
|
9
|
-
it { is_expected.to respond_to :skip_perform_callbacks }
|
10
|
-
it { is_expected.to respond_to :skip_rollback }
|
11
|
-
it { is_expected.to respond_to :skip_rollback_callbacks }
|
12
|
-
it { is_expected.to respond_to :validate }
|
13
|
-
it { is_expected.to respond_to :validate_on_calling }
|
14
|
-
it { is_expected.to respond_to :validate_on_called }
|
15
|
-
|
16
|
-
describe 'defaults' do
|
17
|
-
it { is_expected.to have_attributes(skip_each_perform_callbacks: false) }
|
18
|
-
it { is_expected.to have_attributes(skip_perform_callbacks: false) }
|
19
|
-
it { is_expected.to have_attributes(skip_rollback: false) }
|
20
|
-
it { is_expected.to have_attributes(skip_rollback_callbacks: false) }
|
21
|
-
it { is_expected.to have_attributes(validate: true) }
|
22
|
-
it { is_expected.to have_attributes(validate_on_calling: true) }
|
23
|
-
it { is_expected.to have_attributes(validate_on_called: true) }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,189 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe ActiveInteractor::Interactor::Worker do
|
6
|
-
context 'with interactor class TestInteractor' do
|
7
|
-
before { build_interactor }
|
8
|
-
|
9
|
-
let(:interactor) { TestInteractor.new }
|
10
|
-
|
11
|
-
RSpec.shared_examples 'an interactor with options' do
|
12
|
-
context 'when interactor has options :skip_perform_callbacks eq to true' do
|
13
|
-
let(:interactor) { TestInteractor.new.with_options(skip_perform_callbacks: true) }
|
14
|
-
|
15
|
-
it 'is expected not to receive #run_callbacks with :perform' do
|
16
|
-
allow_any_instance_of(TestInteractor).to receive(:run_callbacks)
|
17
|
-
.with(:validation).and_call_original
|
18
|
-
expect_any_instance_of(TestInteractor).not_to receive(:run_callbacks)
|
19
|
-
.with(:perform)
|
20
|
-
subject
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when interactor has options :validate eq to false' do
|
25
|
-
let(:interactor) { TestInteractor.new.with_options(validate: false) }
|
26
|
-
|
27
|
-
it 'is expected not to receive #run_callbacks with :validation' do
|
28
|
-
expect_any_instance_of(TestInteractor).not_to receive(:run_callbacks)
|
29
|
-
.with(:validation)
|
30
|
-
subject
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when interactor has options :validate_on_calling eq to false' do
|
35
|
-
let(:interactor) { TestInteractor.new.with_options(validate_on_calling: false) }
|
36
|
-
|
37
|
-
before do
|
38
|
-
allow_any_instance_of(TestInteractor).to receive(:context_valid?)
|
39
|
-
.with(:called).and_return(true)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'is expected not to receive #context_valid? with :calling' do
|
43
|
-
expect_any_instance_of(TestInteractor).not_to receive(:context_valid?)
|
44
|
-
.with(:calling)
|
45
|
-
subject
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'is expected to receive #context_valid? with :called' do
|
49
|
-
expect_any_instance_of(TestInteractor).to receive(:context_valid?)
|
50
|
-
.with(:called)
|
51
|
-
subject
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context 'when interactor has options :validate_on_called eq to false' do
|
56
|
-
let(:interactor) { TestInteractor.new.with_options(validate_on_called: false) }
|
57
|
-
|
58
|
-
before do
|
59
|
-
allow_any_instance_of(TestInteractor).to receive(:context_valid?)
|
60
|
-
.with(:calling).and_return(true)
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'is expected to receive #context_valid? with :calling' do
|
64
|
-
expect_any_instance_of(TestInteractor).to receive(:context_valid?)
|
65
|
-
.with(:calling)
|
66
|
-
subject
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'is expected not to receive #context_valid? with :called' do
|
70
|
-
expect_any_instance_of(TestInteractor).not_to receive(:context_valid?)
|
71
|
-
.with(:called)
|
72
|
-
subject
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe '#execute_perform' do
|
78
|
-
subject { described_class.new(interactor).execute_perform }
|
79
|
-
|
80
|
-
it { is_expected.to be_an TestInteractor.context_class }
|
81
|
-
|
82
|
-
context 'when context fails' do
|
83
|
-
before do
|
84
|
-
allow_any_instance_of(TestInteractor).to receive(:perform)
|
85
|
-
.and_raise(ActiveInteractor::Error::ContextFailure)
|
86
|
-
end
|
87
|
-
|
88
|
-
it { expect { subject }.not_to raise_error }
|
89
|
-
it { is_expected.to be_an TestInteractor.context_class }
|
90
|
-
end
|
91
|
-
|
92
|
-
include_examples 'an interactor with options'
|
93
|
-
end
|
94
|
-
|
95
|
-
describe '#execute_perform!' do
|
96
|
-
subject { described_class.new(interactor).execute_perform! }
|
97
|
-
|
98
|
-
it { is_expected.to be_an TestInteractor.context_class }
|
99
|
-
|
100
|
-
it 'is expected to run perform callbacks on interactor' do
|
101
|
-
expect_any_instance_of(TestInteractor).to receive(:run_callbacks)
|
102
|
-
.with(:perform)
|
103
|
-
subject
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'is expected to receive #perform on interactor instance' do
|
107
|
-
expect_any_instance_of(TestInteractor).to receive(:perform)
|
108
|
-
subject
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'when interactor context is invalid on :calling' do
|
112
|
-
before do
|
113
|
-
allow_any_instance_of(TestInteractor.context_class).to receive(:valid?)
|
114
|
-
.with(:calling)
|
115
|
-
.and_return(false)
|
116
|
-
allow_any_instance_of(TestInteractor.context_class).to receive(:valid?)
|
117
|
-
.with(:called)
|
118
|
-
.and_return(true)
|
119
|
-
end
|
120
|
-
|
121
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
122
|
-
|
123
|
-
it 'is expected to rollback the interactor context' do
|
124
|
-
expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
|
125
|
-
expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'when interactor context is invalid on :called' do
|
130
|
-
before do
|
131
|
-
allow_any_instance_of(TestInteractor.context_class).to receive(:valid?)
|
132
|
-
.with(:calling)
|
133
|
-
.and_return(true)
|
134
|
-
allow_any_instance_of(TestInteractor.context_class).to receive(:valid?)
|
135
|
-
.with(:called)
|
136
|
-
.and_return(false)
|
137
|
-
end
|
138
|
-
|
139
|
-
it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
|
140
|
-
|
141
|
-
it 'is expected to rollback the interactor context' do
|
142
|
-
expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
|
143
|
-
expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
include_examples 'an interactor with options'
|
148
|
-
end
|
149
|
-
|
150
|
-
describe '#execute_rollback' do
|
151
|
-
subject { described_class.new(interactor).execute_rollback }
|
152
|
-
|
153
|
-
it 'is expected to receive #run_callbacks on interactor with :rollback' do
|
154
|
-
expect_any_instance_of(TestInteractor).to receive(:run_callbacks)
|
155
|
-
.with(:rollback)
|
156
|
-
subject
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'is expected to receive #context_rollback on interactor instance' do
|
160
|
-
expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
|
161
|
-
subject
|
162
|
-
end
|
163
|
-
|
164
|
-
context 'when interactor has options :skip_rollback eq to true' do
|
165
|
-
let(:interactor) { TestInteractor.new.with_options(skip_rollback: true) }
|
166
|
-
|
167
|
-
it 'is expected not to receive #context_rollback on interactor instance' do
|
168
|
-
expect_any_instance_of(TestInteractor).not_to receive(:context_rollback!)
|
169
|
-
subject
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
context 'when interactor has options :skip_rollback_callbacks eq to true' do
|
174
|
-
let(:interactor) { TestInteractor.new.with_options(skip_rollback_callbacks: true) }
|
175
|
-
|
176
|
-
it 'is expected to receive #context_rollback on interactor instance' do
|
177
|
-
expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
|
178
|
-
subject
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'is expected not to receive #run_callbacks on interactor with :rollback' do
|
182
|
-
expect_any_instance_of(TestInteractor).not_to receive(:run_callbacks)
|
183
|
-
.with(:rollback)
|
184
|
-
subject
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|