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.
- checksums.yaml +4 -4
- data/.yardopts +12 -0
- data/CHANGELOG.md +50 -158
- data/README.md +13 -856
- data/lib/active_interactor.rb +61 -4
- data/lib/active_interactor/base.rb +26 -20
- data/lib/active_interactor/config.rb +36 -18
- data/lib/active_interactor/configurable.rb +17 -9
- data/lib/active_interactor/context/attributes.rb +73 -26
- data/lib/active_interactor/context/base.rb +236 -65
- data/lib/active_interactor/context/loader.rb +20 -15
- data/lib/active_interactor/context/status.rb +38 -56
- data/lib/active_interactor/error.rb +15 -7
- data/lib/active_interactor/interactor/callbacks.rb +174 -160
- data/lib/active_interactor/interactor/context.rb +279 -87
- data/lib/active_interactor/interactor/perform.rb +256 -0
- data/lib/active_interactor/interactor/worker.rb +19 -14
- data/lib/active_interactor/models.rb +65 -0
- data/lib/active_interactor/organizer/base.rb +18 -0
- data/lib/active_interactor/organizer/callbacks.rb +153 -0
- data/lib/active_interactor/organizer/interactor_interface.rb +38 -26
- data/lib/active_interactor/organizer/interactor_interface_collection.rb +35 -32
- data/lib/active_interactor/organizer/organize.rb +67 -0
- data/lib/active_interactor/organizer/perform.rb +93 -0
- data/lib/active_interactor/rails.rb +0 -10
- data/lib/active_interactor/rails/orm/active_record.rb +1 -1
- data/lib/active_interactor/rails/railtie.rb +8 -11
- data/lib/active_interactor/version.rb +2 -1
- data/lib/rails/generators/active_interactor.rb +1 -38
- data/lib/rails/generators/active_interactor/application_context_generator.rb +21 -0
- data/lib/rails/generators/active_interactor/application_interactor_generator.rb +5 -15
- data/lib/rails/generators/active_interactor/application_organizer_generator.rb +21 -0
- data/lib/rails/generators/active_interactor/base.rb +29 -0
- data/lib/rails/generators/active_interactor/generator.rb +21 -0
- data/lib/rails/generators/active_interactor/install_generator.rb +2 -9
- data/lib/rails/generators/interactor/context/rspec_generator.rb +3 -10
- data/lib/rails/generators/interactor/context/test_unit_generator.rb +4 -11
- data/lib/rails/generators/interactor/context_generator.rb +7 -10
- data/lib/rails/generators/interactor/generates_context.rb +28 -0
- data/lib/rails/generators/interactor/interactor_generator.rb +8 -10
- data/lib/rails/generators/interactor/organizer_generator.rb +8 -12
- data/lib/rails/generators/interactor/rspec_generator.rb +2 -9
- data/lib/rails/generators/interactor/test_unit_generator.rb +3 -10
- data/lib/rails/generators/{active_interactor/templates/initializer.erb → templates/active_interactor.erb} +3 -11
- data/lib/rails/generators/{active_interactor/templates → templates}/application_context.rb +0 -0
- data/lib/rails/generators/{active_interactor/templates → templates}/application_interactor.rb +0 -0
- data/lib/rails/generators/templates/application_organizer.rb +4 -0
- data/lib/rails/generators/{interactor/templates → templates}/context.erb +0 -0
- data/lib/rails/generators/{interactor/context/templates/rspec.erb → templates/context_spec.erb} +0 -0
- data/lib/rails/generators/{interactor/context/templates/test_unit.erb → templates/context_test_unit.erb} +0 -0
- data/lib/rails/generators/{interactor/templates → templates}/interactor.erb +0 -0
- data/lib/rails/generators/{interactor/templates/rspec.erb → templates/interactor_spec.erb} +0 -0
- data/lib/rails/generators/{interactor/templates/test_unit.erb → templates/interactor_text_unit.erb} +0 -0
- data/lib/rails/generators/{interactor/templates → templates}/organizer.erb +0 -0
- data/spec/active_interactor/base_spec.rb +3 -3
- data/spec/active_interactor/interactor/{perform_options_spec.rb → perform/options_spec.rb} +1 -1
- data/spec/active_interactor/interactor/worker_spec.rb +14 -15
- data/spec/active_interactor/{organizer_spec.rb → organizer/base_spec.rb} +27 -17
- data/spec/integration/a_basic_interactor_spec.rb +106 -0
- data/spec/integration/a_basic_organizer_spec.rb +97 -0
- data/spec/integration/a_failing_interactor_spec.rb +42 -0
- data/spec/integration/active_record_integration_spec.rb +9 -9
- data/spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb +69 -0
- data/spec/integration/an_interactor_with_after_perform_callbacks_spec.rb +30 -0
- data/spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb +33 -0
- data/spec/integration/an_interactor_with_an_existing_context_class_spec.rb +49 -0
- data/spec/integration/an_interactor_with_around_perform_callbacks_spec.rb +35 -0
- data/spec/integration/an_interactor_with_around_rollback_callbacks_spec.rb +39 -0
- data/spec/integration/an_interactor_with_before_perform_callbacks_spec.rb +30 -0
- data/spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb +33 -0
- data/spec/integration/an_interactor_with_validations_on_called_spec.rb +40 -0
- data/spec/integration/an_interactor_with_validations_on_calling_spec.rb +36 -0
- data/spec/integration/an_interactor_with_validations_spec.rb +93 -0
- data/spec/integration/an_organizer_performing_in_parallel_spec.rb +48 -0
- data/spec/integration/an_organizer_with_after_each_callbacks_spec.rb +34 -0
- data/spec/integration/an_organizer_with_around_each_callbacks_spec.rb +39 -0
- data/spec/integration/an_organizer_with_before_each_callbacks_spec.rb +34 -0
- data/spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb +314 -0
- data/spec/spec_helper.rb +8 -12
- data/spec/support/coverage.rb +4 -0
- data/spec/support/coverage/reporters.rb +11 -0
- data/spec/support/coverage/reporters/codacy.rb +39 -0
- data/spec/support/coverage/reporters/simple_cov.rb +54 -0
- data/spec/support/coverage/runner.rb +66 -0
- data/spec/support/helpers/factories.rb +1 -1
- data/spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb +8 -8
- data/spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb +5 -5
- data/spec/support/shared_examples/a_class_with_interactor_methods_example.rb +2 -2
- data/spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb +3 -3
- metadata +83 -40
- data/lib/active_interactor/interactor.rb +0 -84
- data/lib/active_interactor/interactor/perform_options.rb +0 -29
- data/lib/active_interactor/organizer.rb +0 -269
- data/lib/active_interactor/rails/config.rb +0 -45
- data/lib/active_interactor/rails/models.rb +0 -58
- data/lib/rails/generators/active_interactor/templates/application_organizer.rb +0 -4
- data/spec/active_interactor/rails/config_spec.rb +0 -29
- data/spec/active_interactor/rails_spec.rb +0 -24
- data/spec/integration/basic_callback_integration_spec.rb +0 -355
- data/spec/integration/basic_context_integration_spec.rb +0 -73
- data/spec/integration/basic_integration_spec.rb +0 -570
- data/spec/integration/basic_validations_integration_spec.rb +0 -204
@@ -1,204 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe 'Basic Validations Integration', type: :integration do
|
6
|
-
describe 'An interactor with validations' do
|
7
|
-
let(:interactor_class) do
|
8
|
-
build_interactor do
|
9
|
-
context_validates :test_field, presence: true
|
10
|
-
|
11
|
-
def perform
|
12
|
-
context.other_field = context.test_field
|
13
|
-
end
|
14
|
-
|
15
|
-
def rollback
|
16
|
-
context.other_field = 'failed'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
include_examples 'a class with interactor methods'
|
22
|
-
include_examples 'a class with interactor callback methods'
|
23
|
-
include_examples 'a class with interactor context methods'
|
24
|
-
|
25
|
-
describe '.perform' do
|
26
|
-
subject { interactor_class.perform(context_attributes) }
|
27
|
-
|
28
|
-
context 'with valid context attributes' do
|
29
|
-
let(:context_attributes) { { test_field: 'test' } }
|
30
|
-
|
31
|
-
it { is_expected.to be_a interactor_class.context_class }
|
32
|
-
it { is_expected.to be_successful }
|
33
|
-
it { is_expected.to have_attributes(test_field: 'test', other_field: 'test') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with invalid context attributes' do
|
37
|
-
let(:context_attributes) { {} }
|
38
|
-
|
39
|
-
it { is_expected.to be_a interactor_class.context_class }
|
40
|
-
it { is_expected.to be_failure }
|
41
|
-
it { is_expected.to have_attributes(other_field: 'failed') }
|
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
|
-
end
|
48
|
-
|
49
|
-
describe 'An interactor with conditional validations' do
|
50
|
-
let(:interactor_class) do
|
51
|
-
build_interactor do
|
52
|
-
context_validates :test_field, presence: true, if: :test_condition
|
53
|
-
|
54
|
-
def perform
|
55
|
-
context.other_field = context.test_field
|
56
|
-
end
|
57
|
-
|
58
|
-
def rollback
|
59
|
-
context.other_field = 'failed'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
include_examples 'a class with interactor methods'
|
65
|
-
include_examples 'a class with interactor callback methods'
|
66
|
-
include_examples 'a class with interactor context methods'
|
67
|
-
|
68
|
-
describe '.perform' do
|
69
|
-
subject { interactor_class.perform(context_attributes) }
|
70
|
-
|
71
|
-
context 'with :test_field defined and :test_condition false' do
|
72
|
-
let(:context_attributes) { { test_field: 'test', test_condition: false } }
|
73
|
-
|
74
|
-
it { is_expected.to be_a interactor_class.context_class }
|
75
|
-
it { is_expected.to be_successful }
|
76
|
-
it { is_expected.to have_attributes(test_field: 'test', test_condition: false, other_field: 'test') }
|
77
|
-
end
|
78
|
-
|
79
|
-
context 'with :test_field defined and :test_condition true' do
|
80
|
-
let(:context_attributes) { { test_field: 'test', test_condition: true } }
|
81
|
-
|
82
|
-
it { is_expected.to be_a interactor_class.context_class }
|
83
|
-
it { is_expected.to be_successful }
|
84
|
-
it { is_expected.to have_attributes(test_field: 'test', test_condition: true, other_field: 'test') }
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'with :test_field undefined and :test_condition true' do
|
88
|
-
let(:context_attributes) { { test_condition: true } }
|
89
|
-
|
90
|
-
it { is_expected.to be_a interactor_class.context_class }
|
91
|
-
it { is_expected.to be_failure }
|
92
|
-
it { is_expected.to have_attributes(test_condition: true, other_field: 'failed') }
|
93
|
-
it 'is expected to have errors on :test_field' do
|
94
|
-
expect(subject.errors[:test_field]).not_to be_nil
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'An interactor named "AnInteractor" with validations on context class named "AnInteractorContext"' do
|
101
|
-
let!(:context_class) do
|
102
|
-
build_context('AnInteractorContext') do
|
103
|
-
validates :test_field, presence: true
|
104
|
-
end
|
105
|
-
end
|
106
|
-
let(:interactor_class) { build_interactor('AnInteractor') }
|
107
|
-
|
108
|
-
include_examples 'a class with interactor methods'
|
109
|
-
include_examples 'a class with interactor callback methods'
|
110
|
-
include_examples 'a class with interactor context methods'
|
111
|
-
|
112
|
-
describe '.context_class' do
|
113
|
-
subject { interactor_class.context_class }
|
114
|
-
|
115
|
-
it { is_expected.to eq AnInteractorContext }
|
116
|
-
it { is_expected.to be < ActiveInteractor::Context::Base }
|
117
|
-
end
|
118
|
-
|
119
|
-
subject { interactor_class.perform(context_attributes) }
|
120
|
-
|
121
|
-
context 'with valid context attributes' do
|
122
|
-
let(:context_attributes) { { test_field: 'test' } }
|
123
|
-
|
124
|
-
it { is_expected.to be_an AnInteractorContext }
|
125
|
-
it { is_expected.to be_successful }
|
126
|
-
end
|
127
|
-
|
128
|
-
context 'with invalid context attributes' do
|
129
|
-
let(:context_attributes) { {} }
|
130
|
-
|
131
|
-
it { is_expected.to be_an AnInteractorContext }
|
132
|
-
it { is_expected.to be_failure }
|
133
|
-
it 'is expected to have errors on :some_field' do
|
134
|
-
expect(subject.errors[:test_field]).not_to be_nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe 'An interactor with validations having validation context on :calling' do
|
140
|
-
let(:interactor_class) do
|
141
|
-
build_interactor do
|
142
|
-
context_validates :test_field, presence: true, on: :calling
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
include_examples 'a class with interactor methods'
|
147
|
-
include_examples 'a class with interactor callback methods'
|
148
|
-
include_examples 'a class with interactor context methods'
|
149
|
-
|
150
|
-
subject { interactor_class.perform(context_attributes) }
|
151
|
-
|
152
|
-
context 'with :test_field "test"' do
|
153
|
-
let(:context_attributes) { { test_field: 'test' } }
|
154
|
-
|
155
|
-
it { is_expected.to be_an TestInteractor::Context }
|
156
|
-
it { is_expected.to be_successful }
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'with :test_field nil' do
|
160
|
-
let(:context_attributes) { {} }
|
161
|
-
|
162
|
-
it { is_expected.to be_an TestInteractor::Context }
|
163
|
-
it { is_expected.to be_failure }
|
164
|
-
it 'is expected to have errors on :some_field' do
|
165
|
-
expect(subject.errors[:test_field]).not_to be_nil
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'An interactor with validations having validation context on :called' do
|
171
|
-
let(:interactor_class) do
|
172
|
-
build_interactor do
|
173
|
-
context_validates :test_field, presence: true, on: :called
|
174
|
-
|
175
|
-
def perform
|
176
|
-
context.test_field = 'test' if context.should_have_test_field
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
include_examples 'a class with interactor methods'
|
182
|
-
include_examples 'a class with interactor callback methods'
|
183
|
-
include_examples 'a class with interactor context methods'
|
184
|
-
|
185
|
-
subject { interactor_class.perform(context_attributes) }
|
186
|
-
|
187
|
-
context 'with :should_have_test_field true' do
|
188
|
-
let(:context_attributes) { { should_have_test_field: true } }
|
189
|
-
|
190
|
-
it { is_expected.to be_an TestInteractor::Context }
|
191
|
-
it { is_expected.to be_successful }
|
192
|
-
end
|
193
|
-
|
194
|
-
context 'with :should_have_test_field false' do
|
195
|
-
let(:context_attributes) { { should_have_test_field: false } }
|
196
|
-
|
197
|
-
it { is_expected.to be_an TestInteractor::Context }
|
198
|
-
it { is_expected.to be_failure }
|
199
|
-
it 'is expected to have errors on :some_field' do
|
200
|
-
expect(subject.errors[:test_field]).not_to be_nil
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|