activeinteractor 1.0.0 → 1.0.5
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/CHANGELOG.md +71 -1
- data/README.md +22 -7
- data/lib/active_interactor.rb +5 -1
- data/lib/active_interactor/config.rb +1 -1
- data/lib/active_interactor/context/attributes.rb +64 -15
- data/lib/active_interactor/context/base.rb +87 -0
- data/lib/active_interactor/context/errors.rb +47 -0
- data/lib/active_interactor/context/loader.rb +1 -1
- data/lib/active_interactor/context/status.rb +12 -19
- data/lib/active_interactor/interactor/context.rb +59 -3
- data/lib/active_interactor/interactor/perform.rb +5 -1
- data/lib/active_interactor/models.rb +13 -28
- data/lib/active_interactor/organizer/interactor_interface.rb +1 -1
- data/lib/active_interactor/organizer/interactor_interface_collection.rb +1 -0
- data/lib/active_interactor/rails/orm/dynamoid.rb +5 -0
- data/lib/active_interactor/rails/orm/mongoid.rb +5 -0
- data/lib/active_interactor/version.rb +1 -1
- data/lib/rails/generators/templates/organizer.erb +2 -2
- data/spec/active_interactor/base_spec.rb +33 -0
- data/spec/active_interactor/context/base_spec.rb +101 -12
- data/spec/integration/a_basic_interactor_spec.rb +48 -0
- data/spec/integration/a_basic_organizer_spec.rb +119 -0
- data/spec/integration/active_record_integration_spec.rb +8 -342
- data/spec/spec_helper.rb +18 -8
- data/spec/support/shared_examples/a_class_that_extends_active_interactor_models_example.rb +81 -0
- metadata +37 -42
- data/spec/support/coverage.rb +0 -4
- data/spec/support/coverage/reporters.rb +0 -11
- data/spec/support/coverage/reporters/codacy.rb +0 -39
- data/spec/support/coverage/reporters/simple_cov.rb +0 -54
- data/spec/support/coverage/runner.rb +0 -66
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
require 'simplecov-lcov'
|
6
|
+
|
7
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
enable_coverage :branch
|
11
|
+
add_filter '/spec/'
|
12
|
+
add_filter '/lib/rails/**/*.rb'
|
13
|
+
track_files '/lib/**/*.rb'
|
14
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
15
|
+
SimpleCov::Formatter::HTMLFormatter,
|
16
|
+
SimpleCov::Formatter::LcovFormatter
|
17
|
+
])
|
18
|
+
end
|
19
|
+
rescue LoadError
|
20
|
+
puts 'Skipping coverage...'
|
11
21
|
end
|
12
22
|
|
13
23
|
require 'bundler/setup'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'A class that extends ActiveInteractor::Models' do
|
4
|
+
it { expect(model_class).to respond_to :attribute }
|
5
|
+
it { expect(model_class).to respond_to :attributes }
|
6
|
+
|
7
|
+
describe 'as an instance' do
|
8
|
+
subject { model_class.new }
|
9
|
+
|
10
|
+
it { is_expected.to respond_to :attributes }
|
11
|
+
it { is_expected.to respond_to :called! }
|
12
|
+
it { is_expected.to respond_to :fail! }
|
13
|
+
it { is_expected.to respond_to :fail? }
|
14
|
+
it { is_expected.to respond_to :failure? }
|
15
|
+
it { is_expected.to respond_to :merge! }
|
16
|
+
it { is_expected.to respond_to :rollback! }
|
17
|
+
it { is_expected.to respond_to :success? }
|
18
|
+
it { is_expected.to respond_to :successful? }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.new' do
|
22
|
+
subject { model_class.new(attributes) }
|
23
|
+
|
24
|
+
describe 'with arguments {:foo => "foo"}' do
|
25
|
+
let(:attributes) { { foo: 'foo' } }
|
26
|
+
|
27
|
+
it { is_expected.to have_attributes(foo: 'foo') }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with arguments {:bar => "bar"}' do
|
31
|
+
let(:attributes) { model_class.new(bar: 'bar') }
|
32
|
+
|
33
|
+
it { expect { subject }.to raise_error(ActiveModel::UnknownAttributeError) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'with arguments <#ModelClass foo="foo">' do
|
37
|
+
let(:other_instance) { model_class.new(foo: 'foo') }
|
38
|
+
let(:attributes) { other_instance }
|
39
|
+
|
40
|
+
it { is_expected.to have_attributes(foo: 'foo') }
|
41
|
+
|
42
|
+
context 'with argument instance having @_failed eq to true' do
|
43
|
+
before { other_instance.instance_variable_set('@_failed', true) }
|
44
|
+
|
45
|
+
it { is_expected.to be_failure }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'with argument instance having @_called eq to ["foo"]' do
|
49
|
+
before { other_instance.instance_variable_set('@_called', %w[foo]) }
|
50
|
+
|
51
|
+
it 'is expected to have instance variable @_called eq to ["foo"]' do
|
52
|
+
expect(subject.instance_variable_get('@_called')).to eq %w[foo]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with argument instance having @_rolled_back eq to true' do
|
57
|
+
before { other_instance.instance_variable_set('@_rolled_back', true) }
|
58
|
+
|
59
|
+
it 'is expected to have instance variable @_rolled_back eq to true' do
|
60
|
+
expect(subject.instance_variable_get('@_rolled_back')).to eq true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'with arguments <#OtherClass bar="bar">' do
|
66
|
+
let(:attributes) { model_class.new(other_instance) }
|
67
|
+
let!(:other_class) do
|
68
|
+
build_class('OtherClass') do
|
69
|
+
include ActiveModel::Attributes
|
70
|
+
include ActiveModel::Model
|
71
|
+
extend ActiveInteractor::Models
|
72
|
+
acts_as_context
|
73
|
+
attribute :bar
|
74
|
+
end
|
75
|
+
end
|
76
|
+
let(:other_instance) { other_class.new(bar: 'bar') }
|
77
|
+
|
78
|
+
it { expect { subject }.to raise_error(ActiveModel::UnknownAttributeError) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeinteractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Allen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '3.9'
|
95
95
|
description: |
|
96
|
-
An implementation of the Command Pattern for Ruby with ActiveModel::Validations
|
96
|
+
An implementation of the Command Pattern for Ruby with ActiveModel::Validations inspired by the interactor gem.
|
97
97
|
Rich support for attributes, callbacks, and validations, and thread safe performance methods.
|
98
98
|
email:
|
99
99
|
- hello@aaronmallen.me
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/active_interactor/configurable.rb
|
112
112
|
- lib/active_interactor/context/attributes.rb
|
113
113
|
- lib/active_interactor/context/base.rb
|
114
|
+
- lib/active_interactor/context/errors.rb
|
114
115
|
- lib/active_interactor/context/loader.rb
|
115
116
|
- lib/active_interactor/context/status.rb
|
116
117
|
- lib/active_interactor/error.rb
|
@@ -127,6 +128,8 @@ files:
|
|
127
128
|
- lib/active_interactor/organizer/perform.rb
|
128
129
|
- lib/active_interactor/rails.rb
|
129
130
|
- lib/active_interactor/rails/orm/active_record.rb
|
131
|
+
- lib/active_interactor/rails/orm/dynamoid.rb
|
132
|
+
- lib/active_interactor/rails/orm/mongoid.rb
|
130
133
|
- lib/active_interactor/rails/railtie.rb
|
131
134
|
- lib/active_interactor/version.rb
|
132
135
|
- lib/rails/generators/active_interactor.rb
|
@@ -186,12 +189,8 @@ files:
|
|
186
189
|
- spec/integration/an_organizer_with_before_each_callbacks_spec.rb
|
187
190
|
- spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb
|
188
191
|
- spec/spec_helper.rb
|
189
|
-
- spec/support/coverage.rb
|
190
|
-
- spec/support/coverage/reporters.rb
|
191
|
-
- spec/support/coverage/reporters/codacy.rb
|
192
|
-
- spec/support/coverage/reporters/simple_cov.rb
|
193
|
-
- spec/support/coverage/runner.rb
|
194
192
|
- spec/support/helpers/factories.rb
|
193
|
+
- spec/support/shared_examples/a_class_that_extends_active_interactor_models_example.rb
|
195
194
|
- spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb
|
196
195
|
- spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb
|
197
196
|
- spec/support/shared_examples/a_class_with_interactor_methods_example.rb
|
@@ -202,10 +201,10 @@ licenses:
|
|
202
201
|
- MIT
|
203
202
|
metadata:
|
204
203
|
bug_tracker_uri: https://github.com/aaronmallen/activeinteractor/issues
|
205
|
-
changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v1.0.
|
206
|
-
documentation_uri: https://www.rubydoc.info/gems/activeinteractor/1.0.
|
204
|
+
changelog_uri: https://github.com/aaronmallen/activeinteractor/blob/v1.0.5/CHANGELOG.md
|
205
|
+
documentation_uri: https://www.rubydoc.info/gems/activeinteractor/1.0.5
|
207
206
|
hompage_uri: https://github.com/aaronmallen/activeinteractor
|
208
|
-
source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v1.0.
|
207
|
+
source_code_uri: https://github.com/aaronmallen/activeinteractor/tree/v1.0.5
|
209
208
|
wiki_uri: https://github.com/aaronmallen/activeinteractor/wiki
|
210
209
|
post_install_message:
|
211
210
|
rdoc_options: []
|
@@ -227,45 +226,41 @@ signing_key:
|
|
227
226
|
specification_version: 4
|
228
227
|
summary: Ruby interactors with ActiveModel::Validations
|
229
228
|
test_files:
|
230
|
-
- spec/
|
231
|
-
- spec/
|
232
|
-
- spec/
|
229
|
+
- spec/support/shared_examples/a_class_that_extends_active_interactor_models_example.rb
|
230
|
+
- spec/support/shared_examples/a_class_with_interactor_methods_example.rb
|
231
|
+
- spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb
|
232
|
+
- spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb
|
233
|
+
- spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb
|
234
|
+
- spec/support/spec_helpers.rb
|
235
|
+
- spec/support/helpers/factories.rb
|
236
|
+
- spec/integration/an_interactor_with_validations_on_calling_spec.rb
|
237
|
+
- spec/integration/a_basic_interactor_spec.rb
|
238
|
+
- spec/integration/a_basic_organizer_spec.rb
|
239
|
+
- spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb
|
240
|
+
- spec/integration/an_interactor_with_validations_spec.rb
|
241
|
+
- spec/integration/an_interactor_with_an_existing_context_class_spec.rb
|
242
|
+
- spec/integration/an_organizer_with_around_each_callbacks_spec.rb
|
233
243
|
- spec/integration/an_interactor_with_validations_on_called_spec.rb
|
234
244
|
- spec/integration/an_interactor_with_around_perform_callbacks_spec.rb
|
235
245
|
- spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb
|
236
|
-
- spec/integration/
|
246
|
+
- spec/integration/an_interactor_with_before_perform_callbacks_spec.rb
|
237
247
|
- spec/integration/an_interactor_with_around_rollback_callbacks_spec.rb
|
248
|
+
- spec/integration/an_interactor_with_after_perform_callbacks_spec.rb
|
249
|
+
- spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb
|
238
250
|
- spec/integration/an_organizer_with_after_each_callbacks_spec.rb
|
251
|
+
- spec/integration/active_record_integration_spec.rb
|
252
|
+
- spec/integration/a_failing_interactor_spec.rb
|
253
|
+
- spec/integration/an_organizer_with_before_each_callbacks_spec.rb
|
239
254
|
- spec/integration/an_organizer_performing_in_parallel_spec.rb
|
240
|
-
- spec/integration/an_interactor_with_an_existing_context_class_spec.rb
|
241
255
|
- spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb
|
242
|
-
- spec/
|
243
|
-
- spec/
|
244
|
-
- spec/integration/an_interactor_with_validations_on_calling_spec.rb
|
245
|
-
- spec/integration/an_interactor_with_before_perform_callbacks_spec.rb
|
246
|
-
- spec/integration/an_organizer_with_before_each_callbacks_spec.rb
|
247
|
-
- spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb
|
248
|
-
- spec/integration/an_organizer_with_around_each_callbacks_spec.rb
|
249
|
-
- spec/integration/an_interactor_with_after_context_validation_callbacks_spec.rb
|
250
|
-
- spec/integration/an_interactor_with_after_perform_callbacks_spec.rb
|
251
|
-
- spec/support/spec_helpers.rb
|
252
|
-
- spec/support/coverage/reporters.rb
|
253
|
-
- spec/support/coverage/reporters/codacy.rb
|
254
|
-
- spec/support/coverage/reporters/simple_cov.rb
|
255
|
-
- spec/support/coverage/runner.rb
|
256
|
-
- spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb
|
257
|
-
- spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb
|
258
|
-
- spec/support/shared_examples/a_class_with_interactor_methods_example.rb
|
259
|
-
- spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb
|
260
|
-
- spec/support/helpers/factories.rb
|
261
|
-
- spec/support/coverage.rb
|
262
|
-
- spec/spec_helper.rb
|
256
|
+
- spec/active_interactor/interactor/worker_spec.rb
|
257
|
+
- spec/active_interactor/interactor/perform/options_spec.rb
|
263
258
|
- spec/active_interactor/context/base_spec.rb
|
264
|
-
- spec/active_interactor/base_spec.rb
|
265
259
|
- spec/active_interactor/config_spec.rb
|
260
|
+
- spec/active_interactor/error_spec.rb
|
261
|
+
- spec/active_interactor/base_spec.rb
|
262
|
+
- spec/active_interactor/organizer/interactor_interface_collection_spec.rb
|
266
263
|
- spec/active_interactor/organizer/base_spec.rb
|
267
264
|
- spec/active_interactor/organizer/interactor_interface_spec.rb
|
268
|
-
- spec/
|
269
|
-
- spec/
|
270
|
-
- spec/active_interactor/interactor/perform/options_spec.rb
|
271
|
-
- spec/active_interactor/error_spec.rb
|
265
|
+
- spec/spec_helper.rb
|
266
|
+
- spec/active_interactor_spec.rb
|
data/spec/support/coverage.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Coverage
|
5
|
-
module Reporters
|
6
|
-
module Codacy
|
7
|
-
class << self
|
8
|
-
def load
|
9
|
-
return EMPTY_LOAD_RESULT unless load_dependencies
|
10
|
-
|
11
|
-
[formatters, initialize_steps, run_steps]
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def load_dependencies
|
17
|
-
require 'codacy-coverage'
|
18
|
-
true
|
19
|
-
rescue LoadError
|
20
|
-
puts 'Skipping Codacy Coverage reporting...'
|
21
|
-
false
|
22
|
-
end
|
23
|
-
|
24
|
-
def formatters
|
25
|
-
{ codacy: ::Codacy::Formatter }
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize_steps
|
29
|
-
[]
|
30
|
-
end
|
31
|
-
|
32
|
-
def run_steps
|
33
|
-
[]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Coverage
|
5
|
-
module Reporters
|
6
|
-
module SimpleCov
|
7
|
-
class << self
|
8
|
-
def load
|
9
|
-
return EMPTY_LOAD_RESULT unless load_dependencies
|
10
|
-
|
11
|
-
[formatters, initialize_steps, run_steps]
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def load_dependencies
|
17
|
-
require 'simplecov'
|
18
|
-
true
|
19
|
-
rescue LoadError
|
20
|
-
puts 'Skipping SimpleCov reporting...'
|
21
|
-
false
|
22
|
-
end
|
23
|
-
|
24
|
-
def formatters
|
25
|
-
{ simple_cov_html: ::SimpleCov::Formatter::HTMLFormatter }
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize_steps
|
29
|
-
[setup_formatters]
|
30
|
-
end
|
31
|
-
|
32
|
-
def run_steps
|
33
|
-
[start_simplecov]
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup_formatters
|
37
|
-
lambda do |runner|
|
38
|
-
::SimpleCov.formatter = ::SimpleCov::Formatter::MultiFormatter.new(runner.formatters)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def start_simplecov
|
43
|
-
lambda do |runner|
|
44
|
-
::SimpleCov.start do
|
45
|
-
runner.tracked_files.each { |f| track_files f }
|
46
|
-
runner.filtered_files.each { |f| add_filter f }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Coverage
|
5
|
-
class Runner
|
6
|
-
attr_accessor :filtered_files, :formatters, :tracked_files
|
7
|
-
|
8
|
-
def self.start(&block)
|
9
|
-
instance = new
|
10
|
-
instance.instance_eval(&block) if block
|
11
|
-
instance.start
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(options = {})
|
15
|
-
load_reporters!
|
16
|
-
@formatters = options[:formatters] || []
|
17
|
-
@filtered_files = options[:filtered_files] || []
|
18
|
-
@tracked_files = options[:tracked_files] || []
|
19
|
-
end
|
20
|
-
|
21
|
-
def add_formatter(formatter)
|
22
|
-
formatter_class = reporters[:formatters][formatter.to_sym]
|
23
|
-
formatters << formatter_class if formatter_class
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
def filter(pattern)
|
28
|
-
filtered_files << pattern
|
29
|
-
self
|
30
|
-
end
|
31
|
-
|
32
|
-
def start
|
33
|
-
initialize_reporters
|
34
|
-
run_reporters
|
35
|
-
end
|
36
|
-
|
37
|
-
def track(pattern)
|
38
|
-
tracked_files << pattern
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
attr_reader :reporters
|
45
|
-
|
46
|
-
def initialize_reporters
|
47
|
-
reporters[:initialize_steps].each { |step| step.call(self) }
|
48
|
-
end
|
49
|
-
|
50
|
-
def load_reporters!
|
51
|
-
@reporters = { formatters: {}, initialize_steps: [], run_steps: [] }
|
52
|
-
%w[SimpleCov Codacy].each do |dep|
|
53
|
-
reporter = Reporters.const_get(dep)
|
54
|
-
formatters, initialize_steps, run_steps = reporter.load
|
55
|
-
@reporters[:formatters].merge!(formatters)
|
56
|
-
@reporters[:initialize_steps].concat(initialize_steps)
|
57
|
-
@reporters[:run_steps].concat(run_steps)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def run_reporters
|
62
|
-
reporters[:run_steps].each { |step| step.call(self) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|