activeinteractor 1.2.0 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
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,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An organizer with failing nested organizer', type: :integration do
6
- let!(:parent_interactor1) { build_interactor('TestParentInteractor1') }
7
- let!(:parent_interactor2) { build_interactor('TestParentInteractor2') }
8
- let!(:child_interactor1) { build_interactor('TestChildInteractor1') }
9
- let!(:child_interactor2) do
10
- build_interactor('TestChildInteractor2') do
11
- def perform
12
- context.fail!
13
- end
14
- end
15
- end
16
-
17
- let!(:child_interactor_class) do
18
- build_organizer('TestChildOrganizer') do
19
- organize TestChildInteractor1, TestChildInteractor2
20
- end
21
- end
22
-
23
- let(:parent_interactor_class) do
24
- build_organizer('TestParentOrganizer') do
25
- organize TestParentInteractor1, TestChildOrganizer, TestParentInteractor2
26
- end
27
- end
28
-
29
- describe '.perform' do
30
- subject { parent_interactor_class.perform }
31
-
32
- before do
33
- expect_any_instance_of(child_interactor_class).to receive(:perform).exactly(:once).and_call_original
34
- expect_any_instance_of(child_interactor1).to receive(:perform).exactly(:once).and_call_original
35
- expect_any_instance_of(child_interactor2).to receive(:perform).exactly(:once).and_call_original
36
- expect_any_instance_of(child_interactor2).to receive(:rollback).exactly(:once).and_call_original
37
- expect_any_instance_of(child_interactor1).to receive(:rollback).exactly(:once).and_call_original
38
- expect_any_instance_of(parent_interactor1).to receive(:rollback).exactly(:once).and_call_original
39
- expect_any_instance_of(parent_interactor2).not_to receive(:perform).exactly(:once).and_call_original
40
- expect_any_instance_of(parent_interactor2).not_to receive(:rollback).exactly(:once).and_call_original
41
- end
42
-
43
- it { is_expected.to be_a parent_interactor_class.context_class }
44
-
45
- it { is_expected.to be_failure }
46
- end
47
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe 'An organizer with options callbacks', type: :integration do
6
- let!(:interactor1) do
7
- build_interactor('TestInteractor1') do
8
- def perform
9
- context.step = 3 if context.step == 2
10
- context.step = 6 if context.step == 5
11
- end
12
- end
13
- end
14
-
15
- let(:interactor_class) do
16
- build_organizer do
17
- organize do
18
- add TestInteractor1, before: :test_before_method, after: :test_after_method
19
- add TestInteractor1, before: lambda {
20
- context.step = 5 if context.step == 4
21
- }, after: lambda {
22
- context.step = 7 if context.step == 6
23
- }
24
- end
25
-
26
- private
27
-
28
- def test_before_method
29
- context.step = 2 if context.step == 1
30
- end
31
-
32
- def test_after_method
33
- context.step = 4 if context.step == 3
34
- end
35
- end
36
- end
37
-
38
- include_examples 'a class with interactor methods'
39
- include_examples 'a class with interactor callback methods'
40
- include_examples 'a class with interactor context methods'
41
- include_examples 'a class with organizer callback methods'
42
-
43
- describe '.perform' do
44
- subject { interactor_class.perform(step: 1) }
45
-
46
- it { is_expected.to be_a interactor_class.context_class }
47
-
48
- it 'is expected to receive #test_before_method once' do
49
- expect_any_instance_of(interactor_class).to receive(:test_before_method)
50
- .exactly(:once)
51
- subject
52
- end
53
-
54
- it 'is expected to receive #test_after_method once' do
55
- expect_any_instance_of(interactor_class).to receive(:test_after_method)
56
- .exactly(:once)
57
- subject
58
- end
59
-
60
- it 'runs callbacks in sequence' do
61
- expect(subject.step).to eq(7)
62
- end
63
- end
64
- end
data/spec/spec_helper.rb DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'support/coverage'
4
- ActiveInteractor::Spec::Coverage.start
5
-
6
- require 'bundler/setup'
7
- require 'active_interactor'
8
-
9
- RSpec.configure do |config|
10
- # Enable flags like --only-failures and --next-failure
11
- config.example_status_persistence_file_path = 'spec/.rspec_status'
12
-
13
- config.before do
14
- # suppress logs in test
15
- allow(ActiveInteractor.logger).to receive(:error).and_return(true)
16
- end
17
-
18
- config.after do
19
- clean_factories!
20
- end
21
-
22
- # Disable RSpec exposing methods globally on `Module` and `main`
23
- config.disable_monkey_patching!
24
-
25
- config.expect_with :rspec do |c|
26
- c.syntax = :expect
27
- end
28
-
29
- config.order = :random
30
- Kernel.srand config.seed
31
- end
32
-
33
- Dir[File.join(__dir__, 'support', '**', '*.rb')].sort.each { |f| require f }
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'simplecov'
4
- require 'simplecov-lcov'
5
-
6
- module ActiveInteractor
7
- module Spec
8
- class Coverage
9
- DEFAULT_COVERAGE_TYPE = 'unit'
10
- EXCLUDED_FILES_PATTERN = '/spec/'
11
- TRACKED_FILES_PATTERN = 'lib/**/*.rb'
12
-
13
- FORMATTERS = [
14
- SimpleCov::Formatter::HTMLFormatter,
15
- SimpleCov::Formatter::LcovFormatter
16
- ].freeze
17
-
18
- class << self
19
- def start
20
- setup_lcov_formatter
21
- start_simplecov
22
- end
23
-
24
- private
25
-
26
- def simplecov_formatter
27
- @simplecov_formatter ||= SimpleCov::Formatter::MultiFormatter.new(FORMATTERS)
28
- end
29
-
30
- def setup_lcov_formatter
31
- coverage_type = ENV.fetch('COVERAGE_TYPE', DEFAULT_COVERAGE_TYPE)
32
-
33
- SimpleCov::Formatter::LcovFormatter.config do |config|
34
- config.report_with_single_file = true
35
- config.single_report_path = "coverage/#{coverage_type}_lcov.info"
36
- end
37
- end
38
-
39
- def start_simplecov
40
- SimpleCov.start do
41
- add_filter EXCLUDED_FILES_PATTERN
42
- enable_coverage :branch
43
- track_files TRACKED_FILES_PATTERN
44
- formatter simplecov_formatter
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/string/inflections'
4
-
5
- module Spec
6
- module Helpers
7
- module FactoryCollection
8
- def self.factories
9
- @factories ||= []
10
- end
11
- end
12
-
13
- module Factories
14
- def build_class(class_name, parent_class = nil, &block)
15
- Object.send(:remove_const, class_name.to_sym) if Object.const_defined?(class_name)
16
- klass = create_class(class_name, parent_class)
17
- klass.class_eval(&block) if block
18
- FactoryCollection.factories << klass.name.to_sym
19
- klass
20
- end
21
-
22
- def build_context(class_name = 'TestContext', &block)
23
- build_class(class_name, ActiveInteractor::Context::Base, &block)
24
- end
25
-
26
- def build_interactor(class_name = 'TestInteractor', &block)
27
- build_class(class_name, ActiveInteractor::Base, &block)
28
- end
29
-
30
- def build_organizer(class_name = 'TestOrganizer', &block)
31
- build_class(class_name, ActiveInteractor::Organizer::Base, &block)
32
- end
33
-
34
- def clean_factories!
35
- FactoryCollection.factories.each do |factory|
36
- Object.send(:remove_const, factory) if Object.const_defined?(factory)
37
- end
38
- end
39
-
40
- private
41
-
42
- def create_class(class_name, parent_class = nil)
43
- return Object.const_set(class_name, Class.new) unless parent_class
44
-
45
- Object.const_set(class_name, Class.new(parent_class))
46
- end
47
- end
48
- end
49
- end
@@ -1,81 +0,0 @@
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
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'a class with interactor callback methods' do
4
- describe '.after_context_validation' do
5
- subject { interactor_class.after_context_validation(*args) }
6
-
7
- let(:args) { :some_method }
8
-
9
- it 'is expected to receive #set_callback with :validation, :after, :some_method, { :prepend => true }' do
10
- expect(interactor_class).to receive(:set_callback)
11
- .with(:validation, :after, :some_method, { prepend: true })
12
- .and_return(true)
13
- subject
14
- end
15
- end
16
-
17
- describe '.after_perform' do
18
- subject { interactor_class.after_perform(*args) }
19
-
20
- let(:args) { :some_method }
21
-
22
- it 'is expected to receive #set_callback with :perform, :after, :some_method' do
23
- expect(interactor_class).to receive(:set_callback)
24
- .with(:perform, :after, :some_method)
25
- .and_return(true)
26
- subject
27
- end
28
- end
29
-
30
- describe '.after_rollback' do
31
- subject { interactor_class.after_rollback(*args) }
32
-
33
- let(:args) { :some_method }
34
-
35
- it 'is expected to receive #set_callback with :rollback, :after, :some_method' do
36
- expect(interactor_class).to receive(:set_callback)
37
- .with(:rollback, :after, :some_method)
38
- .and_return(true)
39
- subject
40
- end
41
- end
42
-
43
- describe '.around_perform' do
44
- subject { interactor_class.around_perform(*args) }
45
-
46
- let(:args) { :some_method }
47
-
48
- it 'is expected to receive #set_callback with :perform, :around, :some_method' do
49
- expect(interactor_class).to receive(:set_callback)
50
- .with(:perform, :around, :some_method)
51
- .and_return(true)
52
- subject
53
- end
54
- end
55
-
56
- describe '.around_rollback' do
57
- subject { interactor_class.around_rollback(*args) }
58
-
59
- let(:args) { :some_method }
60
-
61
- it 'is expected to receive #set_callback with :rollback, :around, :some_method' do
62
- expect(interactor_class).to receive(:set_callback)
63
- .with(:rollback, :around, :some_method)
64
- .and_return(true)
65
- subject
66
- end
67
- end
68
-
69
- describe '.before_context_validation' do
70
- subject { interactor_class.before_context_validation(*args) }
71
-
72
- let(:args) { :some_method }
73
-
74
- it 'is expected to receive #set_callback with :validation, :before, :some_method' do
75
- expect(interactor_class).to receive(:set_callback)
76
- .with(:validation, :before, :some_method, {})
77
- .and_return(true)
78
- subject
79
- end
80
- end
81
-
82
- describe '.before_perform' do
83
- subject { interactor_class.before_perform(*args) }
84
-
85
- let(:args) { :some_method }
86
-
87
- it 'is expected to receive #set_callback with :perform, :before, :some_method' do
88
- expect(interactor_class).to receive(:set_callback)
89
- .with(:perform, :before, :some_method)
90
- .and_return(true)
91
- subject
92
- end
93
- end
94
-
95
- describe '.before_rollback' do
96
- subject { interactor_class.before_rollback(*args) }
97
-
98
- let(:args) { :some_method }
99
-
100
- it 'is expected to receive #set_callback with :rollback, :before, :some_method' do
101
- expect(interactor_class).to receive(:set_callback)
102
- .with(:rollback, :before, :some_method)
103
- .and_return(true)
104
- subject
105
- end
106
- end
107
- end
@@ -1,60 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'a class with interactor context methods' do
4
- describe '.context_attributes' do
5
- subject { interactor_class.context_attributes(attributes) }
6
-
7
- let(:attributes) { :some_attribute }
8
-
9
- it 'is expected to receive #attributes on .context_class with :some_attribute' do
10
- expect(interactor_class.context_class).to receive(:attributes)
11
- .with(:some_attribute)
12
- .and_return(true)
13
- subject
14
- end
15
- end
16
-
17
- describe '#context_fail!' do
18
- subject { interactor_class.new.context_fail! }
19
-
20
- it 'is expected to receive #fail! on instance of .context_class' do
21
- expect_any_instance_of(interactor_class.context_class).to receive(:fail!)
22
- .and_return(true)
23
- subject
24
- end
25
- end
26
-
27
- describe '#context_rollback!' do
28
- subject { interactor_class.new.context_rollback! }
29
-
30
- it 'is expected to receive #rollback! on instance of .context_class' do
31
- expect_any_instance_of(interactor_class.context_class).to receive(:rollback!)
32
- .and_return(true)
33
- subject
34
- end
35
- end
36
-
37
- describe '#context_valid?' do
38
- subject { interactor_class.new.context_valid? }
39
-
40
- it 'is expected to receive #valid? on instance of .context_class' do
41
- expect_any_instance_of(interactor_class.context_class).to receive(:valid?)
42
- .and_return(true)
43
- subject
44
- end
45
- end
46
-
47
- describe '#finalize_context!' do
48
- subject { instance.finalize_context! }
49
-
50
- let(:instance) { interactor_class.new }
51
-
52
- it 'is expected to receive #called! on instance of .context_class' do
53
- expect_any_instance_of(interactor_class.context_class).to receive(:called!)
54
- .with(instance)
55
- subject
56
- end
57
-
58
- it { is_expected.to be_an interactor_class.context_class }
59
- end
60
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'a class with interactor methods' do
4
- describe '.perform' do
5
- subject { interactor_class.perform }
6
-
7
- it 'is expected to receive #execute_perform on a new instance of ActiveInteractor::Interactor::Worker' do
8
- expect_any_instance_of(ActiveInteractor::Interactor::Worker).to receive(:execute_perform)
9
- subject
10
- end
11
- end
12
-
13
- describe '.perform!' do
14
- subject { interactor_class.perform! }
15
-
16
- it 'is expected to receive #execute_perform! on a new instance of ActiveInteractor::Interactor::Worker' do
17
- expect_any_instance_of(ActiveInteractor::Interactor::Worker).to receive(:execute_perform!)
18
- subject
19
- end
20
- end
21
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'a class with organizer callback methods' do
4
- describe '.after_each_perform' do
5
- subject { interactor_class.after_each_perform(*args) }
6
-
7
- let(:args) { :some_method }
8
-
9
- it 'is expected to receive #set_callback with :each_perform, :after, :some_method' do
10
- expect(interactor_class).to receive(:set_callback)
11
- .with(:each_perform, :after, :some_method)
12
- .and_return(true)
13
- subject
14
- end
15
- end
16
-
17
- describe '.around_each_perform' do
18
- subject { interactor_class.around_each_perform(*args) }
19
-
20
- let(:args) { :some_method }
21
-
22
- it 'is expected to receive #set_callback with :each_perform, :around, :some_method' do
23
- expect(interactor_class).to receive(:set_callback)
24
- .with(:each_perform, :around, :some_method)
25
- .and_return(true)
26
- subject
27
- end
28
- end
29
-
30
- describe '.before_each_perform' do
31
- subject { interactor_class.before_each_perform(*args) }
32
-
33
- let(:args) { :some_method }
34
-
35
- it 'is expected to receive #set_callback with :each_perform, :before, :some_method' do
36
- expect(interactor_class).to receive(:set_callback)
37
- .with(:each_perform, :before, :some_method)
38
- .and_return(true)
39
- subject
40
- end
41
- end
42
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dir[File.join(__dir__, 'helpers', '**', '*.rb')].sort.each { |f| require f }
4
-
5
- RSpec.configure do |config|
6
- config.include Spec::Helpers::Factories
7
- end