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,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .after_perform callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- after_perform :test_after_perform
9
-
10
- private
11
-
12
- def test_after_perform; end
13
- end
14
- end
15
-
16
- include_examples 'a class with interactor methods'
17
- include_examples 'a class with interactor callback methods'
18
- include_examples 'a class with interactor context methods'
19
-
20
- describe '.perform' do
21
- subject { interactor_class.perform }
22
-
23
- it { is_expected.to be_a interactor_class.context_class }
24
- it { is_expected.to be_successful }
25
-
26
- it 'is expected to receive #test_after_perform' do
27
- expect_any_instance_of(interactor_class).to receive(:test_after_perform)
28
- subject
29
- end
30
- end
31
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .after_rollback callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- after_rollback :test_after_rollback
9
-
10
- def perform
11
- context.fail!
12
- end
13
-
14
- private
15
-
16
- def test_after_rollback; end
17
- end
18
- end
19
-
20
- include_examples 'a class with interactor methods'
21
- include_examples 'a class with interactor callback methods'
22
- include_examples 'a class with interactor context methods'
23
-
24
- describe '.perform' do
25
- subject { interactor_class.perform }
26
-
27
- it { is_expected.to be_a interactor_class.context_class }
28
-
29
- it 'is expected to receive #test_after_rollback' do
30
- expect_any_instance_of(interactor_class).to receive(:test_after_rollback)
31
- subject
32
- end
33
- end
34
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with an existing .context_class', type: :integration do
6
- context 'having .name "AnInteractor"' do
7
- let(:interactor_class) { build_interactor('AnInteractor') }
8
-
9
- include_examples 'a class with interactor methods'
10
- include_examples 'a class with interactor callback methods'
11
- include_examples 'a class with interactor context methods'
12
-
13
- context 'having a class named "AnInteractorContext" with validations' do
14
- let!(:context_class) do
15
- build_context('AnInteractorContext') do
16
- validates :test_field, presence: true
17
- end
18
- end
19
-
20
- describe '.context_class' do
21
- subject { interactor_class.context_class }
22
-
23
- it { is_expected.to eq AnInteractorContext }
24
- it { is_expected.to be < ActiveInteractor::Context::Base }
25
- end
26
-
27
- describe '.perform' do
28
- subject { interactor_class.perform(context_attributes) }
29
-
30
- context 'with valid context attributes' do
31
- let(:context_attributes) { { test_field: 'test' } }
32
-
33
- it { is_expected.to be_an AnInteractorContext }
34
- it { is_expected.to be_successful }
35
- end
36
-
37
- context 'with invalid context attributes' do
38
- let(:context_attributes) { {} }
39
-
40
- it { is_expected.to be_an AnInteractorContext }
41
- it { is_expected.to be_failure }
42
-
43
- it 'is expected to have errors on :some_field' do
44
- expect(subject.errors[:test_field]).not_to be_nil
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .around_perform callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- around_perform :test_around_perform
9
-
10
- def perform
11
- context.perform_step << 2
12
- end
13
-
14
- private
15
-
16
- def test_around_perform
17
- context.perform_step = []
18
- context.perform_step << 1
19
- yield
20
- context.perform_step << 3
21
- end
22
- end
23
- end
24
-
25
- include_examples 'a class with interactor methods'
26
- include_examples 'a class with interactor callback methods'
27
- include_examples 'a class with interactor context methods'
28
-
29
- describe '.perform' do
30
- subject { interactor_class.perform }
31
-
32
- it { is_expected.to be_a interactor_class.context_class }
33
- it { is_expected.to have_attributes(perform_step: [1, 2, 3]) }
34
- end
35
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .around_rollback callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- around_rollback :test_around_rollback
9
-
10
- def perform
11
- context.fail!
12
- end
13
-
14
- def rollback
15
- context.rollback_step << 2
16
- end
17
-
18
- private
19
-
20
- def test_around_rollback
21
- context.rollback_step = []
22
- context.rollback_step << 1
23
- yield
24
- context.rollback_step << 3
25
- end
26
- end
27
- end
28
-
29
- include_examples 'a class with interactor methods'
30
- include_examples 'a class with interactor callback methods'
31
- include_examples 'a class with interactor context methods'
32
-
33
- describe '.perform' do
34
- subject { interactor_class.perform }
35
-
36
- it { is_expected.to be_a interactor_class.context_class }
37
- it { is_expected.to have_attributes(rollback_step: [1, 2, 3]) }
38
- end
39
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .before_perform callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- before_perform :test_before_perform
9
-
10
- private
11
-
12
- def test_before_perform; end
13
- end
14
- end
15
-
16
- include_examples 'a class with interactor methods'
17
- include_examples 'a class with interactor callback methods'
18
- include_examples 'a class with interactor context methods'
19
-
20
- describe '.perform' do
21
- subject { interactor_class.perform }
22
-
23
- it { is_expected.to be_a interactor_class.context_class }
24
- it { is_expected.to be_successful }
25
-
26
- it 'is expected to receive #test_before_perform' do
27
- expect_any_instance_of(interactor_class).to receive(:test_before_perform)
28
- subject
29
- end
30
- end
31
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with .before_rollback callbacks', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- before_rollback :test_before_rollback
9
-
10
- def perform
11
- context.fail!
12
- end
13
-
14
- private
15
-
16
- def test_before_rollback; end
17
- end
18
- end
19
-
20
- include_examples 'a class with interactor methods'
21
- include_examples 'a class with interactor callback methods'
22
- include_examples 'a class with interactor context methods'
23
-
24
- describe '.perform' do
25
- subject { interactor_class.perform }
26
-
27
- it { is_expected.to be_a interactor_class.context_class }
28
-
29
- it 'is expected to receive #test_before_rollback' do
30
- expect_any_instance_of(interactor_class).to receive(:test_before_rollback)
31
- subject
32
- end
33
- end
34
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with deferred after callbacks', type: :integration do
6
- let!(:interactor_with_config) do
7
- build_interactor('InteractorWithConfig') do
8
- defer_after_callbacks_when_organized
9
-
10
- def perform
11
- context.test_field_1 = 'test'
12
- end
13
- end
14
- end
15
-
16
- let!(:interactor_without_config) do
17
- build_interactor('InteractorWithoutConfig') do
18
-
19
- def perform
20
- context.test_field_2 = 'test'
21
- end
22
- end
23
- end
24
-
25
- it 'is expected to have true for InteractorWithConfig#after_callbacks_deferred_when_organized' do
26
- expect(InteractorWithConfig).to have_attributes(after_callbacks_deferred_when_organized: true)
27
- end
28
-
29
- it 'is expected to have false for InteractorWithoutConfig#after_callbacks_deferred_when_organized' do
30
- expect(InteractorWithoutConfig).to have_attributes(after_callbacks_deferred_when_organized: false)
31
- end
32
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with validations on :called', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- context_validates :test_field, presence: true, on: :called
9
-
10
- def perform
11
- context.test_field = 'test' if context.should_have_test_field
12
- end
13
- end
14
- end
15
-
16
- include_examples 'a class with interactor methods'
17
- include_examples 'a class with interactor callback methods'
18
- include_examples 'a class with interactor context methods'
19
-
20
- describe '.perform' do
21
- subject { interactor_class.perform(context_attributes) }
22
-
23
- context 'with :should_have_test_field true' do
24
- let(:context_attributes) { { should_have_test_field: true } }
25
-
26
- it { is_expected.to be_an TestInteractor::Context }
27
- it { is_expected.to be_successful }
28
- end
29
-
30
- context 'with :should_have_test_field false' do
31
- let(:context_attributes) { { should_have_test_field: false } }
32
-
33
- it { is_expected.to be_an TestInteractor::Context }
34
- it { is_expected.to be_failure }
35
-
36
- it 'is expected to have errors on :some_field' do
37
- expect(subject.errors[:test_field]).not_to be_nil
38
- end
39
- end
40
- end
41
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with validations on :calling', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- context_validates :test_field, presence: true, on: :calling
9
- end
10
- end
11
-
12
- include_examples 'a class with interactor methods'
13
- include_examples 'a class with interactor callback methods'
14
- include_examples 'a class with interactor context methods'
15
-
16
- describe '.perform' do
17
- subject { interactor_class.perform(context_attributes) }
18
-
19
- context 'with :test_field "test"' do
20
- let(:context_attributes) { { test_field: 'test' } }
21
-
22
- it { is_expected.to be_an TestInteractor::Context }
23
- it { is_expected.to be_successful }
24
- end
25
-
26
- context 'with :test_field nil' do
27
- let(:context_attributes) { {} }
28
-
29
- it { is_expected.to be_an TestInteractor::Context }
30
- it { is_expected.to be_failure }
31
-
32
- it 'is expected to have errors on :some_field' do
33
- expect(subject.errors[:test_field]).not_to be_nil
34
- end
35
- end
36
- end
37
- end
@@ -1,95 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An interactor with validations', type: :integration do
6
- let(:interactor_class) do
7
- build_interactor do
8
- context_validates :test_field, presence: true
9
-
10
- def perform
11
- context.other_field = context.test_field
12
- end
13
-
14
- def rollback
15
- context.other_field = 'failed'
16
- end
17
- end
18
- end
19
-
20
- include_examples 'a class with interactor methods'
21
- include_examples 'a class with interactor callback methods'
22
- include_examples 'a class with interactor context methods'
23
-
24
- describe '.perform' do
25
- subject { interactor_class.perform(context_attributes) }
26
-
27
- context 'with valid context attributes' do
28
- let(:context_attributes) { { test_field: 'test' } }
29
-
30
- it { is_expected.to be_a interactor_class.context_class }
31
- it { is_expected.to be_successful }
32
- it { is_expected.to have_attributes(test_field: 'test', other_field: 'test') }
33
- end
34
-
35
- context 'with invalid context attributes' do
36
- let(:context_attributes) { {} }
37
-
38
- it { is_expected.to be_a interactor_class.context_class }
39
- it { is_expected.to be_failure }
40
- it { is_expected.to have_attributes(other_field: 'failed') }
41
-
42
- it 'is expected to have errors on :test_field' do
43
- expect(subject.errors[:test_field]).not_to be_nil
44
- end
45
- end
46
- end
47
-
48
- context 'having conditional validations' do
49
- let(:interactor_class) do
50
- build_interactor do
51
- context_validates :test_field, presence: true, if: :test_condition
52
-
53
- def perform
54
- context.other_field = context.test_field
55
- end
56
-
57
- def rollback
58
- context.other_field = 'failed'
59
- end
60
- end
61
- end
62
-
63
- describe '.perform' do
64
- subject { interactor_class.perform(context_attributes) }
65
-
66
- context 'with :test_field defined and :test_condition false' do
67
- let(:context_attributes) { { test_field: 'test', test_condition: false } }
68
-
69
- it { is_expected.to be_a interactor_class.context_class }
70
- it { is_expected.to be_successful }
71
- it { is_expected.to have_attributes(test_field: 'test', test_condition: false, other_field: 'test') }
72
- end
73
-
74
- context 'with :test_field defined and :test_condition true' do
75
- let(:context_attributes) { { test_field: 'test', test_condition: true } }
76
-
77
- it { is_expected.to be_a interactor_class.context_class }
78
- it { is_expected.to be_successful }
79
- it { is_expected.to have_attributes(test_field: 'test', test_condition: true, other_field: 'test') }
80
- end
81
-
82
- context 'with :test_field undefined and :test_condition true' do
83
- let(:context_attributes) { { test_condition: true } }
84
-
85
- it { is_expected.to be_a interactor_class.context_class }
86
- it { is_expected.to be_failure }
87
- it { is_expected.to have_attributes(test_condition: true, other_field: 'failed') }
88
-
89
- it 'is expected to have errors on :test_field' do
90
- expect(subject.errors[:test_field]).not_to be_nil
91
- end
92
- end
93
- end
94
- end
95
- end
@@ -1,125 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An organizer containing an organizer with after callbacks deferred', type: :integration do
6
- let!(:test_interactor_1) do
7
- build_interactor('TestInteractor1') do
8
- defer_after_callbacks_when_organized
9
-
10
- after_perform do
11
- context.after_perform_1a = context.after_perform_1b + 1
12
- end
13
-
14
- after_perform do
15
- context.after_perform_1b = context.after_perform_2 + 1
16
- end
17
-
18
- def perform
19
- context.perform_1 = 1
20
- end
21
- end
22
- end
23
-
24
- let!(:test_interactor_2) do
25
- build_interactor('TestInteractor2') do
26
- after_perform do
27
- context.after_perform_2 = context.perform_2 + 1
28
- end
29
-
30
- def perform
31
- context.perform_2 = context.after_perform_3a + 1
32
- end
33
- end
34
- end
35
-
36
- let!(:test_interactor_3) do
37
- build_interactor('TestInteractor3') do
38
- defer_after_callbacks_when_organized
39
-
40
- after_perform do
41
- context.after_perform_3a = context.after_perform_3b + 1
42
- end
43
-
44
- after_perform do
45
- context.after_perform_3b = context.after_perform_4a + 1
46
- end
47
-
48
- def perform
49
- context.perform_3 = context.perform_1 + 1
50
- end
51
- end
52
- end
53
-
54
- let!(:test_interactor_4) do
55
- build_interactor('TestInteractor4') do
56
- after_perform do
57
- context.after_perform_4a = context.after_perform_4b + 1
58
- end
59
-
60
- after_perform do
61
- context.after_perform_4b = context.perform_4 + 1
62
- end
63
-
64
- def perform
65
- context.perform_4 = context.perform_3 + 1
66
- end
67
- end
68
- end
69
-
70
- let!(:test_sub_organizer_5) do
71
- build_organizer('TestSubOrganizer5') do
72
- defer_after_callbacks_when_organized
73
-
74
- after_perform do
75
- context.after_perform_5a = context.after_perform_5b + 1
76
- end
77
-
78
- after_perform do
79
- context.after_perform_5b = context.after_perform_1a + 1
80
- end
81
-
82
- organize TestInteractor3, TestInteractor4
83
- end
84
- end
85
-
86
- let(:interactor_class) do
87
- build_organizer do
88
- organize TestInteractor1, TestSubOrganizer5, TestInteractor2
89
- end
90
- end
91
-
92
- include_examples 'a class with interactor methods'
93
- include_examples 'a class with interactor callback methods'
94
- include_examples 'a class with interactor context methods'
95
- include_examples 'a class with organizer callback methods'
96
-
97
- describe '.context_class' do
98
- subject { interactor_class.context_class }
99
-
100
- it { is_expected.to eq TestOrganizer::Context }
101
- it { is_expected.to be < ActiveInteractor::Context::Base }
102
- end
103
-
104
- describe '.perform' do
105
- subject { interactor_class.perform }
106
-
107
- it { is_expected.to be_a interactor_class.context_class }
108
- it { is_expected.to be_successful }
109
- it { is_expected.to have_attributes(
110
- perform_1: 1,
111
- perform_3: 2,
112
- perform_4: 3,
113
- after_perform_4b: 4,
114
- after_perform_4a: 5,
115
- after_perform_3b: 6,
116
- after_perform_3a: 7,
117
- perform_2: 8,
118
- after_perform_2: 9,
119
- after_perform_1b: 10,
120
- after_perform_1a: 11,
121
- after_perform_5b: 12,
122
- after_perform_5a: 13,
123
- ) }
124
- end
125
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An organizer performing in parallel', 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
- perform_in_parallel
25
- organize TestInteractor1, TestInteractor2
26
- end
27
- end
28
-
29
- include_examples 'a class with interactor methods'
30
- include_examples 'a class with interactor callback methods'
31
- include_examples 'a class with interactor context methods'
32
- include_examples 'a class with organizer callback methods'
33
-
34
- describe '.context_class' do
35
- subject { interactor_class.context_class }
36
-
37
- it { is_expected.to eq TestOrganizer::Context }
38
- it { is_expected.to be < ActiveInteractor::Context::Base }
39
- end
40
-
41
- describe '.perform' do
42
- subject { interactor_class.perform }
43
-
44
- it { is_expected.to be_a interactor_class.context_class }
45
- it { is_expected.to be_successful }
46
- it { is_expected.to have_attributes(test_field_1: 'test 1', test_field_2: 'test 2') }
47
- end
48
- end