activeinteractor 1.0.5 → 1.1.3

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -2
  3. data/README.md +10 -29
  4. data/lib/active_interactor/context/attributes.rb +25 -4
  5. data/lib/active_interactor/context/errors.rb +11 -1
  6. data/lib/active_interactor/organizer/interactor_interface.rb +24 -7
  7. data/lib/active_interactor/organizer/perform.rb +11 -2
  8. data/lib/active_interactor/version.rb +41 -3
  9. data/spec/active_interactor/base_spec.rb +1 -0
  10. data/spec/active_interactor/config_spec.rb +1 -0
  11. data/spec/active_interactor/context/base_spec.rb +16 -0
  12. data/spec/active_interactor/error_spec.rb +3 -1
  13. data/spec/active_interactor/interactor/worker_spec.rb +3 -0
  14. data/spec/active_interactor/organizer/base_spec.rb +18 -1
  15. data/spec/active_interactor/organizer/interactor_interface_collection_spec.rb +2 -0
  16. data/spec/active_interactor/organizer/interactor_interface_spec.rb +75 -2
  17. data/spec/active_interactor/version_spec.rb +119 -0
  18. data/spec/active_interactor_spec.rb +0 -6
  19. data/spec/integration/a_basic_organizer_spec.rb +139 -1
  20. data/spec/integration/a_failing_interactor_spec.rb +1 -0
  21. data/spec/integration/an_interactor_with_after_perform_callbacks_spec.rb +1 -0
  22. data/spec/integration/an_interactor_with_after_rollback_callbacks_spec.rb +1 -0
  23. data/spec/integration/an_interactor_with_an_existing_context_class_spec.rb +1 -0
  24. data/spec/integration/an_interactor_with_before_perform_callbacks_spec.rb +1 -0
  25. data/spec/integration/an_interactor_with_before_rollback_callbacks_spec.rb +1 -0
  26. data/spec/integration/an_interactor_with_validations_on_called_spec.rb +1 -0
  27. data/spec/integration/an_interactor_with_validations_on_calling_spec.rb +1 -0
  28. data/spec/integration/an_interactor_with_validations_spec.rb +2 -0
  29. data/spec/integration/an_organizer_with_after_each_callbacks_spec.rb +1 -0
  30. data/spec/integration/an_organizer_with_before_each_callbacks_spec.rb +1 -0
  31. data/spec/integration/an_organizer_with_conditionally_organized_interactors_spec.rb +14 -2
  32. data/spec/integration/an_organizer_with_failing_nested_organizer_spec.rb +47 -0
  33. data/spec/integration/an_organizer_with_options_callbacks_spec.rb +64 -0
  34. data/spec/spec_helper.rb +3 -20
  35. data/spec/support/coverage.rb +50 -0
  36. data/spec/support/shared_examples/a_class_with_interactor_callback_methods_example.rb +8 -0
  37. data/spec/support/shared_examples/a_class_with_interactor_context_methods_example.rb +2 -0
  38. data/spec/support/shared_examples/a_class_with_organizer_callback_methods_example.rb +3 -0
  39. metadata +45 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 491bd06fcc2f9baf372f817dab6e40c69a07d5ff15721f5136815bcdeb04656b
4
- data.tar.gz: 80e520f97369ab0f9465842eb31f9b0c0e638135cdc73ee27ded9cdc12272cf1
3
+ metadata.gz: 6326a8924b24caa906991b69c80eebeb735183386bf0914b6efb04881910ff03
4
+ data.tar.gz: aa2c69acce205ff007a54ec141b7eef0a917d9af68805ce7bd68b91686882139
5
5
  SHA512:
6
- metadata.gz: 3409d7c2a1c81fcfa6482493569a015356f6239635b4ea539947687c2e2ba44947825b8914ee264df7280e7f612184b35ae67cc10010a6df793087f249aacc81
7
- data.tar.gz: dd892f0304bd572a8074c56cad88a231a9ca328b6365ffb96cf87ea7c60c5121f11ed32c3de70a550e3d9ea7fdeb5489667b653041e41c64e90dd661ea35d5e7
6
+ metadata.gz: 145052b08089c27b93ef87cfe7a9e29a6ffca822d3a190e8b9925117331a262a2179c2275365fe14c6e4d6997f81fbd96a4a581d8412797743c941a34caed8ec
7
+ data.tar.gz: 8eafb80d3c0fab16fe28a9b5669b237f00ca738e37729869488c4a32ebe36b0afd39b82384a9c66e758e1c8f10159f68a71e38914154361484fedc8c9407a910
data/CHANGELOG.md CHANGED
@@ -7,11 +7,48 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [v1.1.3] - 2022-02-16
11
+
12
+ ### Changed
13
+
14
+ - [\#338] Bump activemodel and activesupport to 6.1.4.4
15
+
16
+ ## [v1.1.2] - 2020-11-10
17
+
18
+ ### Changed
19
+
20
+ - [\#300](https://github.com/aaronmallen/activeinteractor/pull/300) `ActiveModel` and `ActiveSupport` v6.1 will be the
21
+ highest supported version for `ActiveInteractor` v1.1.x
22
+
23
+ ### Fixed
24
+
25
+ - [\#300](https://github.com/aaronmallen/activeinteractor/pull/300) `ActiveInteractor::Context::Error` compatibility
26
+ with `ActiveModel` v6.1
27
+
28
+ ## [v1.1.1] - 2020-10-21
29
+
30
+ ### Fixed
31
+
32
+ - [\#267](https://github.com/aaronmallen/activeinteractor/pull/267) Allow default attributes to propagate to
33
+ sibling/child interactors
34
+
35
+ ## [v1.1.0] - 2020-10-04
36
+
37
+ ### Added
38
+
39
+ - [\#247](https://github.com/aaronmallen/activeinteractor/issues/247) Support in place callbacks
40
+
41
+ ### Fixed
42
+
43
+ - [\#242](https://github.com/aaronmallen/activeinteractor/issues/242) Optional attributes are always null
44
+ - [\#243](https://github.com/aaronmallen/activeinteractor/issues/243) Nested Organizers do not rollback parent context
45
+
10
46
  ## [v1.0.5] - 2020-09-15
11
47
 
12
48
  ### Fixed
13
49
 
14
- - [\#200](https://github.com/aaronmallen/activeinteractor/issues/200) Context attributes assigned in interactor not accessible as element within interactor
50
+ - [\#200](https://github.com/aaronmallen/activeinteractor/issues/200) Context attributes assigned in interactor not
51
+ accessible as element within interactor
15
52
 
16
53
  ## [v1.0.4] - 2020-02-11
17
54
 
@@ -200,7 +237,12 @@ and this project adheres to [Semantic Versioning].
200
237
 
201
238
  <!-- versions -->
202
239
 
203
- [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.4...HEAD
240
+ [Unreleased]: https://github.com/aaronmallen/activeinteractor/compare/v1.1.3...HEAD
241
+ [v1.1.3]: https://github.com/aaronmallen/activeinteractor/compare/v1.1.2...v1.1.3
242
+ [v1.1.2]: https://github.com/aaronmallen/activeinteractor/compare/v1.1.1...v1.1.2
243
+ [v1.1.1]: https://github.com/aaronmallen/activeinteractor/compare/v1.1.0...v1.1.1
244
+ [v1.1.0]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.5...v1.1.0
245
+ [v1.0.5]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.4...v1.0.5
204
246
  [v1.0.4]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.3...v1.0.4
205
247
  [v1.0.3]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.2...v1.0.3
206
248
  [v1.0.2]: https://github.com/aaronmallen/activeinteractor/compare/v1.0.1...v1.0.2
data/README.md CHANGED
@@ -22,7 +22,13 @@ course on how to use ActiveInteractors. Read the [wiki] for detailed usage infor
22
22
  * Thread safe performance calls
23
23
  * Organize multiple interactors [conditionally][wiki_organizers_conditionally] or in [parallel][wiki_organizers_parallel]
24
24
 
25
- ## Getting Started
25
+ ## Documentation
26
+
27
+ Be sure to read the [wiki] for detailed information on how to use ActiveInteractor.
28
+
29
+ For technical documentation please see the gem's [ruby docs].
30
+
31
+ ## Install
26
32
 
27
33
  Add this line to your application's Gemfile:
28
34
 
@@ -30,54 +36,29 @@ Add this line to your application's Gemfile:
30
36
  gem 'activeinteractor', require: 'active_interactor'
31
37
  ```
32
38
 
33
- And then execute:
34
-
35
- ```bash
36
- bundle
37
- ```
38
-
39
39
  Or install it yourself as:
40
40
 
41
- ```bash
41
+ ```sh
42
42
  gem install activeinteractor
43
43
  ```
44
44
 
45
- ## Usage
46
-
47
- Be sure to read the [wiki] for detailed information on how to use ActiveInteractor.
48
-
49
- For technical documentation please see the gem's [ruby docs].
50
-
51
- ## Development
52
-
53
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
54
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
-
56
- To install this gem onto your local machine, run `bundle exec rake install`.
57
-
58
45
  ## Contributing
59
46
 
60
47
  Read our guidelines for [Contributing](CONTRIBUTING.md).
61
48
 
62
49
  ## Acknowledgements
63
50
 
64
- * Special thanks to [@collectiveidea] for their amazing foundational work on
65
- the [interactor][collective_idea_interactors] gem.
66
- * Special thanks to the [@rails] team for their work on [ActiveModel][active_model_git]
67
- and [ActiveSupport][active_support_git] gems.
51
+ ActiveInteractor is made possible by wonderful [humans].
68
52
 
69
53
  ## License
70
54
 
71
55
  The gem is available as open source under the terms of the [MIT License][mit_license].
72
56
 
73
- [@collectiveidea]: https://github.com/collectiveidea
74
- [@rails]: https://github.com/rails
75
- [active_model_git]: https://github.com/rails/rails/tree/master/activemodel
76
- [active_support_git]: https://github.com/rails/rails/tree/master/activesupport
77
57
  [ActiveModel::Validations]: https://api.rubyonrails.org/classes/ActiveModel/Validations.html
78
58
  [business_logic_wikipedia]: https://en.wikipedia.org/wiki/Business_logic
79
59
  [collective_idea_interactors]: https://github.com/collectiveidea/interactor
80
60
  [command pattern]: https://en.wikipedia.org/wiki/Command_pattern
61
+ [humans]: https://github.com/aaronmallen/activeinteractor/tree/main/HUMANS.md
81
62
  [Medium article]: https://medium.com/@aaronmallen/activeinteractor-8557c0dc78db
82
63
  [mit_license]: https://opensource.org/licenses/MIT
83
64
  [ruby docs]: https://www.rubydoc.info/gems/activeinteractor
@@ -69,6 +69,19 @@ module ActiveInteractor
69
69
  @table[name.to_sym] || attributes[name.to_sym]
70
70
  end
71
71
 
72
+ # Sets value of a Hash attribute in context.attributes
73
+ #
74
+ # @since 1.1.0
75
+ #
76
+ # @param name [String, Symbol] the key name of the attribute
77
+ # @param value [*] the value to be given attribute name
78
+ # @returns [*] the attribute value
79
+ def []=(name, value)
80
+ public_send("#{name}=", value)
81
+
82
+ super unless @table.nil?
83
+ end
84
+
72
85
  # Get values defined on the instance of {Base context} whose keys are defined on the {Base context} class'
73
86
  # {ClassMethods#attributes .attributes}
74
87
  #
@@ -117,8 +130,9 @@ module ActiveInteractor
117
130
  def merge!(context)
118
131
  merge_errors!(context) if context.respond_to?(:errors)
119
132
  copy_flags!(context)
120
- context.each_pair do |key, value|
121
- public_send("#{key}=", value) unless value.nil?
133
+
134
+ merged_context_attributes(context).each_pair do |key, value|
135
+ self[key] = value unless value.nil?
122
136
  end
123
137
  self
124
138
  end
@@ -129,6 +143,13 @@ module ActiveInteractor
129
143
  @_called ||= []
130
144
  end
131
145
 
146
+ def merged_context_attributes(context)
147
+ attrs = {}
148
+ attrs.merge!(context.to_h) if context.respond_to?(:to_h)
149
+ attrs.merge!(context.attributes.to_h) if context.respond_to?(:attributes)
150
+ attrs
151
+ end
152
+
132
153
  def context_attributes_as_hash(context)
133
154
  return context.to_h if context&.respond_to?(:to_h)
134
155
  return context.attributes.to_h if context.respond_to?(:attributes)
@@ -149,8 +170,8 @@ module ActiveInteractor
149
170
  def merge_attribute_values(context)
150
171
  return unless context
151
172
 
152
- context.each_pair do |key, value|
153
- public_send("#{key}=", value)
173
+ attributes.compact.merge(context).each_pair do |key, value|
174
+ self[key] = value
154
175
  end
155
176
  end
156
177
  end
@@ -18,6 +18,16 @@ module ActiveInteractor
18
18
 
19
19
  private
20
20
 
21
+ def add_errors(errors)
22
+ errors.each do |error|
23
+ if self.errors.respond_to?(:import)
24
+ self.errors.import(error)
25
+ else
26
+ self.errors.add(error[0], error[1])
27
+ end
28
+ end
29
+ end
30
+
21
31
  def clear_all_errors
22
32
  errors.clear
23
33
  failure_errors.clear
@@ -40,7 +50,7 @@ module ActiveInteractor
40
50
  def resolve_errors
41
51
  all_errors = (failure_errors.uniq + errors.uniq).compact.uniq
42
52
  clear_all_errors
43
- all_errors.each { |error| errors.add(error[0], error[1]) }
53
+ add_errors(all_errors)
44
54
  end
45
55
  end
46
56
  end
@@ -14,6 +14,13 @@ module ActiveInteractor
14
14
  #
15
15
  # @return [Hash{Symbol=>Proc, Symbol}] conditional options for the {ActiveInteractor::Base interactor} class
16
16
  #
17
+ # @!attribute [r] callbacks
18
+ # Callbacks for the interactor_class
19
+ #
20
+ # @since 1.1.0
21
+ #
22
+ # @return [Hash{Symbol=>*}] the interactor callbacks
23
+ #
17
24
  # @!attribute [r] interactor_class
18
25
  # An {ActiveInteractor::Base interactor} class
19
26
  #
@@ -27,11 +34,12 @@ module ActiveInteractor
27
34
  # @return [Hash{Symbol=>*}] {Interactor::Perform::Options} for the {ActiveInteractor::Base interactor}
28
35
  # {Interactor::Perform#perform #perform}
29
36
  class InteractorInterface
30
- attr_reader :filters, :interactor_class, :perform_options
37
+ attr_reader :filters, :callbacks, :interactor_class, :perform_options
31
38
 
32
39
  # Keywords for conditional filters
33
40
  # @return [Array<Symbol>]
34
41
  CONDITIONAL_FILTERS = %i[if unless].freeze
42
+ CALLBACKS = %i[before after].freeze
35
43
 
36
44
  # Initialize a new instance of {InteractorInterface}
37
45
  #
@@ -42,7 +50,8 @@ module ActiveInteractor
42
50
  def initialize(interactor_class, options = {})
43
51
  @interactor_class = interactor_class.to_s.camelize.safe_constantize
44
52
  @filters = options.select { |key, _value| CONDITIONAL_FILTERS.include?(key) }
45
- @perform_options = options.reject { |key, _value| CONDITIONAL_FILTERS.include?(key) }
53
+ @callbacks = options.select { |key, _value| CALLBACKS.include?(key) }
54
+ @perform_options = options.reject { |key, _value| CONDITIONAL_FILTERS.include?(key) || CALLBACKS.include?(key) }
46
55
  end
47
56
 
48
57
  # Call the {#interactor_class} {Interactor::Perform::ClassMethods#perform .perform} or
@@ -57,21 +66,29 @@ module ActiveInteractor
57
66
  # {Context::Status#fail! fails} its {Context::Base context}.
58
67
  # @return [Class] an instance of {Context::Base context}
59
68
  def perform(target, context, fail_on_error = false, perform_options = {})
60
- return if check_conditionals(target, filters[:if]) == false
61
- return if check_conditionals(target, filters[:unless]) == true
69
+ return if check_conditionals(target, :if) == false
70
+ return if check_conditionals(target, :unless) == true
62
71
 
63
72
  method = fail_on_error ? :perform! : :perform
64
73
  options = self.perform_options.merge(perform_options)
65
74
  interactor_class.send(method, context, options)
66
75
  end
67
76
 
77
+ def execute_inplace_callback(target, callback)
78
+ resolve_option(target, callbacks[callback])
79
+ end
80
+
68
81
  private
69
82
 
70
83
  def check_conditionals(target, filter)
71
- return unless filter
84
+ resolve_option(target, filters[filter])
85
+ end
86
+
87
+ def resolve_option(target, opt)
88
+ return unless opt
72
89
 
73
- return target.send(filter) if filter.is_a?(Symbol)
74
- return target.instance_exec(&filter) if filter.is_a?(Proc)
90
+ return target.send(opt) if opt.is_a?(Symbol)
91
+ return target.instance_exec(&opt) if opt.is_a?(Proc)
75
92
  end
76
93
  end
77
94
  end
@@ -73,10 +73,19 @@ module ActiveInteractor
73
73
  context_fail! if contexts.any?(&:failure?)
74
74
  end
75
75
 
76
+ def execute_and_merge_contexts(interface)
77
+ interface.execute_inplace_callback(self, :before)
78
+ result = execute_interactor_with_callbacks(interface, true)
79
+ return if result.nil?
80
+
81
+ context.merge!(result)
82
+ context_fail! if result.failure?
83
+ interface.execute_inplace_callback(self, :after)
84
+ end
85
+
76
86
  def perform_in_order
77
87
  self.class.organized.each do |interface|
78
- result = execute_interactor_with_callbacks(interface, true)
79
- context.merge!(result) if result
88
+ execute_and_merge_contexts(interface)
80
89
  end
81
90
  rescue ActiveInteractor::Error::ContextFailure => e
82
91
  context.merge!(e.context)
@@ -1,7 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveInteractor
4
- # The ActiveInteractor version
5
- # @return [String] the ActiveInteractor version
6
- VERSION = '1.0.5'
4
+ # The ActiveInteractor version info
5
+ #
6
+ # @author Aaron Allen <hello@aaronmallen.me>
7
+ # @since unreleased
8
+ module Version
9
+ # The ActiveInterctor major version number
10
+ # @return [Integer] The ActiveInteractor major version number
11
+ MAJOR = 1
12
+
13
+ # The ActiveInterctor minor version number
14
+ # @return [Integer] The ActiveInteractor minor version number
15
+ MINOR = 1
16
+
17
+ # The ActiveInterctor patch version number
18
+ # @return [Integer] The ActiveInteractor patch version number
19
+ PATCH = 3
20
+
21
+ # The ActiveInterctor pre-release version
22
+ # @return [String | nil] The ActiveInteractor pre-release version
23
+ PRE = nil
24
+
25
+ # The ActiveInterctor meta version
26
+ # @return [String | nil] The ActiveInteractor meta version
27
+ META = nil
28
+
29
+ # The ActiveInterctor rubygems version
30
+ # @return [String] The ActiveInteractor rubygems version
31
+ def self.gem_version
32
+ pre_meta = PRE.nil? ? nil : [PRE, META].compact.join('.').freeze
33
+ [MAJOR, MINOR, PATCH, pre_meta].compact.join('.').freeze
34
+ end
35
+
36
+ # The ActiveInterctor semver version
37
+ # @return [String] The ActiveInteractor semver version
38
+ def self.semver
39
+ version = [MAJOR, MINOR, PATCH].join('.')
40
+ version = "#{version}-#{PRE}" if PRE
41
+ version = "#{version}+#{META}" if META
42
+ version.freeze
43
+ end
44
+ end
7
45
  end
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe ActiveInteractor::Base do
6
6
  let(:interactor_class) { described_class }
7
+
7
8
  include_examples 'a class with interactor methods'
8
9
  include_examples 'a class with interactor callback methods'
9
10
  include_examples 'a class with interactor context methods'
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe ActiveInteractor::Config do
6
6
  subject { described_class.new }
7
+
7
8
  it { is_expected.to respond_to :logger }
8
9
 
9
10
  describe '.defaults' do
@@ -6,7 +6,9 @@ RSpec.describe ActiveInteractor::Context::Base do
6
6
  describe '.attributes' do
7
7
  context 'when no arguments are passed' do
8
8
  subject { context_class.attributes }
9
+
9
10
  let!(:context_class) { build_context }
11
+
10
12
  it { is_expected.to eq [] }
11
13
 
12
14
  context 'when an attribute :foo was previously defined' do
@@ -22,6 +24,7 @@ RSpec.describe ActiveInteractor::Context::Base do
22
24
 
23
25
  context 'when given arguments :foo and :bar' do
24
26
  subject { context_class.attributes(:foo, :bar) }
27
+
25
28
  let!(:context_class) { build_context }
26
29
 
27
30
  it { is_expected.to eq %i[bar foo] }
@@ -48,6 +51,7 @@ RSpec.describe ActiveInteractor::Context::Base do
48
51
 
49
52
  context 'with attribute equal to "foo"' do
50
53
  let(:attribute) { :foo }
54
+
51
55
  before { instance.foo = 'foo' }
52
56
 
53
57
  it { is_expected.to eq 'foo' }
@@ -70,6 +74,7 @@ RSpec.describe ActiveInteractor::Context::Base do
70
74
 
71
75
  context 'with attribute equal to "foo"' do
72
76
  let(:attribute) { :foo }
77
+
73
78
  before { instance.foo = 'foo' }
74
79
 
75
80
  it { is_expected.to eq 'foo' }
@@ -136,6 +141,7 @@ RSpec.describe ActiveInteractor::Context::Base do
136
141
 
137
142
  it { is_expected.to be_a Hash }
138
143
  it { is_expected.to eq(bar: 'bar', foo: 'foo') }
144
+
139
145
  it 'is expected to assign :baz' do
140
146
  expect(instance.baz).to eq 'baz'
141
147
  end
@@ -162,6 +168,7 @@ RSpec.describe ActiveInteractor::Context::Base do
162
168
 
163
169
  describe '#fail!' do
164
170
  subject { instance.fail!(errors) }
171
+
165
172
  let(:instance) { described_class.new }
166
173
 
167
174
  context 'with errors equal to nil' do
@@ -224,6 +231,7 @@ RSpec.describe ActiveInteractor::Context::Base do
224
231
 
225
232
  describe '#failure?' do
226
233
  subject { instance.failure? }
234
+
227
235
  let(:instance) { described_class.new }
228
236
 
229
237
  it { is_expected.to eq false }
@@ -275,6 +283,7 @@ RSpec.describe ActiveInteractor::Context::Base do
275
283
 
276
284
  it { is_expected.to be_a described_class }
277
285
  it { is_expected.to have_attributes(foo: 'foo') }
286
+
278
287
  it 'is expected to preserve @_failed instance variable' do
279
288
  expect(subject.instance_variable_get('@_failed')).to eq true
280
289
  end
@@ -285,6 +294,7 @@ RSpec.describe ActiveInteractor::Context::Base do
285
294
 
286
295
  it { is_expected.to be_a described_class }
287
296
  it { is_expected.to have_attributes(foo: 'foo') }
297
+
288
298
  it 'is expected to preserve @_rolled_back instance variable' do
289
299
  expect(subject.instance_variable_get('@_rolled_back')).to eq true
290
300
  end
@@ -347,6 +357,7 @@ RSpec.describe ActiveInteractor::Context::Base do
347
357
  before { attributes.errors.add(:foo, 'invalid') }
348
358
 
349
359
  it { is_expected.to be_a described_class }
360
+
350
361
  it 'is expected to have errors on :foo' do
351
362
  expect(subject.errors[:foo]).not_to be_nil
352
363
  expect(subject.errors[:foo]).to include 'invalid'
@@ -358,6 +369,7 @@ RSpec.describe ActiveInteractor::Context::Base do
358
369
 
359
370
  it { is_expected.to be_a described_class }
360
371
  it { is_expected.to have_attributes(foo: 'foo') }
372
+
361
373
  it 'is expected to preserve @_called instance variable' do
362
374
  expect(subject.instance_variable_get('@_called')).to eq %w[foo]
363
375
  end
@@ -368,6 +380,7 @@ RSpec.describe ActiveInteractor::Context::Base do
368
380
 
369
381
  it { is_expected.to be_a described_class }
370
382
  it { is_expected.to have_attributes(foo: 'foo') }
383
+
371
384
  it 'is expected to preserve @_failed instance variable' do
372
385
  expect(subject.instance_variable_get('@_failed')).to eq true
373
386
  end
@@ -378,6 +391,7 @@ RSpec.describe ActiveInteractor::Context::Base do
378
391
 
379
392
  it { is_expected.to be_a described_class }
380
393
  it { is_expected.to have_attributes(foo: 'foo') }
394
+
381
395
  it 'is expected to preserve @_rolled_back instance variable' do
382
396
  expect(subject.instance_variable_get('@_rolled_back')).to eq true
383
397
  end
@@ -387,6 +401,7 @@ RSpec.describe ActiveInteractor::Context::Base do
387
401
 
388
402
  describe '#rollback!' do
389
403
  subject { instance.rollback! }
404
+
390
405
  let(:instance) { described_class.new }
391
406
 
392
407
  context 'with #called! interactors' do
@@ -414,6 +429,7 @@ RSpec.describe ActiveInteractor::Context::Base do
414
429
 
415
430
  describe '#success?' do
416
431
  subject { instance.success? }
432
+
417
433
  let(:instance) { described_class.new }
418
434
 
419
435
  it { is_expected.to eq true }
@@ -14,10 +14,12 @@ RSpec.describe ActiveInteractor::Error::ContextFailure do
14
14
  end
15
15
 
16
16
  context 'when context is an instance of "TestContext"' do
17
- before { build_context }
18
17
  subject { described_class.new(TestContext.new) }
19
18
 
19
+ before { build_context }
20
+
20
21
  it { is_expected.to have_attributes(message: 'TestContext failed!') }
22
+
21
23
  it 'is expected to have an instance of TestContext' do
22
24
  expect(subject.context).to be_a TestContext
23
25
  end
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe ActiveInteractor::Interactor::Worker do
6
6
  context 'with interactor class TestInteractor' do
7
7
  before { build_interactor }
8
+
8
9
  let(:interactor) { TestInteractor.new }
9
10
 
10
11
  RSpec.shared_examples 'an interactor with options' do
@@ -118,6 +119,7 @@ RSpec.describe ActiveInteractor::Interactor::Worker do
118
119
  end
119
120
 
120
121
  it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
122
+
121
123
  it 'is expected to rollback the interactor context' do
122
124
  expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
123
125
  expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure)
@@ -135,6 +137,7 @@ RSpec.describe ActiveInteractor::Interactor::Worker do
135
137
  end
136
138
 
137
139
  it { expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure) }
140
+
138
141
  it 'is expected to rollback the interactor context' do
139
142
  expect_any_instance_of(TestInteractor).to receive(:context_rollback!)
140
143
  expect { subject }.to raise_error(ActiveInteractor::Error::ContextFailure)
@@ -4,6 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe ActiveInteractor::Organizer::Base do
6
6
  let(:interactor_class) { described_class }
7
+
7
8
  include_examples 'a class with interactor methods'
8
9
  include_examples 'a class with interactor callback methods'
9
10
  include_examples 'a class with interactor context methods'
@@ -66,6 +67,7 @@ RSpec.describe ActiveInteractor::Organizer::Base do
66
67
  subject { organizer.organized }
67
68
 
68
69
  it { expect(subject.collection).to all(be_a ActiveInteractor::Organizer::InteractorInterface) }
70
+
69
71
  it 'is expected to organize the approriate interactors' do
70
72
  expect(subject.collection.first.interactor_class).to eq TestInteractor1
71
73
  expect(subject.collection.last.interactor_class).to eq TestInteractor2
@@ -87,6 +89,7 @@ RSpec.describe ActiveInteractor::Organizer::Base do
87
89
  subject { organizer.organized }
88
90
 
89
91
  it { expect(subject.collection).to all(be_a ActiveInteractor::Organizer::InteractorInterface) }
92
+
90
93
  it 'is expected to organize the approriate interactors' do
91
94
  expect(subject.collection.first.interactor_class).to eq TestInteractor1
92
95
  expect(subject.collection.last.interactor_class).to eq TestInteractor2
@@ -103,11 +106,12 @@ RSpec.describe ActiveInteractor::Organizer::Base do
103
106
  end
104
107
  end
105
108
 
106
- it { should have_attributes(parallel: true) }
109
+ it { is_expected.to have_attributes(parallel: true) }
107
110
  end
108
111
 
109
112
  describe '#perform' do
110
113
  subject { interactor_class.perform }
114
+
111
115
  context 'with two existing interactors' do
112
116
  let!(:interactor1) { build_interactor('TestInteractor1') }
113
117
  let!(:interactor2) { build_interactor('TestInteractor2') }
@@ -118,6 +122,7 @@ RSpec.describe ActiveInteractor::Organizer::Base do
118
122
  end
119
123
 
120
124
  it { is_expected.to be_a interactor_class.context_class }
125
+
121
126
  it 'is expected to receive #perform on both interactors' do
122
127
  expect_any_instance_of(interactor1).to receive(:perform)
123
128
  expect_any_instance_of(interactor2).to receive(:perform)
@@ -128,11 +133,13 @@ RSpec.describe ActiveInteractor::Organizer::Base do
128
133
  subject { interactor_class.perform({}, skip_each_perform_callbacks: true) }
129
134
 
130
135
  it { is_expected.to be_a interactor_class.context_class }
136
+
131
137
  it 'is expected to receive #perform on both interactors' do
132
138
  expect_any_instance_of(interactor1).to receive(:perform)
133
139
  expect_any_instance_of(interactor2).to receive(:perform)
134
140
  subject
135
141
  end
142
+
136
143
  it 'is expected not to receive #run_callbacks with :each_perform' do
137
144
  expect_any_instance_of(interactor_class).not_to receive(:run_callbacks)
138
145
  .with(:each_perform)
@@ -152,14 +159,17 @@ RSpec.describe ActiveInteractor::Organizer::Base do
152
159
  it { expect { subject }.not_to raise_error }
153
160
  it { is_expected.to be_failure }
154
161
  it { is_expected.to be_a interactor_class.context_class }
162
+
155
163
  it 'is expected to receive #perform on the first interactor' do
156
164
  expect_any_instance_of(interactor1).to receive(:perform)
157
165
  subject
158
166
  end
167
+
159
168
  it 'is expected not to receive #perform on the second interactor' do
160
169
  expect_any_instance_of(interactor2).not_to receive(:perform)
161
170
  subject
162
171
  end
172
+
163
173
  it 'is expected to receive #rollback on the first interactor' do
164
174
  expect_any_instance_of(interactor1).to receive(:rollback)
165
175
  subject
@@ -178,11 +188,13 @@ RSpec.describe ActiveInteractor::Organizer::Base do
178
188
  it { expect { subject }.not_to raise_error }
179
189
  it { is_expected.to be_failure }
180
190
  it { is_expected.to be_a interactor_class.context_class }
191
+
181
192
  it 'is expected to receive #perform on both interactors' do
182
193
  expect_any_instance_of(interactor1).to receive(:perform)
183
194
  expect_any_instance_of(interactor2).to receive(:perform)
184
195
  subject
185
196
  end
197
+
186
198
  it 'is expected to receive #rollback on both interactors' do
187
199
  expect_any_instance_of(interactor1).to receive(:rollback)
188
200
  expect_any_instance_of(interactor2).to receive(:rollback)
@@ -200,6 +212,7 @@ RSpec.describe ActiveInteractor::Organizer::Base do
200
212
  end
201
213
 
202
214
  it { is_expected.to be_a interactor_class.context_class }
215
+
203
216
  it 'is expected to receive #perform on both interactors' do
204
217
  expect_any_instance_of(interactor1).to receive(:perform)
205
218
  expect_any_instance_of(interactor2).to receive(:perform)
@@ -218,11 +231,13 @@ RSpec.describe ActiveInteractor::Organizer::Base do
218
231
  it { expect { subject }.not_to raise_error }
219
232
  it { is_expected.to be_failure }
220
233
  it { is_expected.to be_a interactor_class.context_class }
234
+
221
235
  it 'is expected to receive #perform on both interactors' do
222
236
  expect_any_instance_of(interactor1).to receive(:perform)
223
237
  expect_any_instance_of(interactor2).to receive(:perform)
224
238
  subject
225
239
  end
240
+
226
241
  it 'is expected to receive #rollback both interactors' do
227
242
  expect_any_instance_of(interactor1).to receive(:rollback)
228
243
  expect_any_instance_of(interactor2).to receive(:rollback)
@@ -242,11 +257,13 @@ RSpec.describe ActiveInteractor::Organizer::Base do
242
257
  it { expect { subject }.not_to raise_error }
243
258
  it { is_expected.to be_failure }
244
259
  it { is_expected.to be_a interactor_class.context_class }
260
+
245
261
  it 'is expected to receive #perform on both interactors' do
246
262
  expect_any_instance_of(interactor1).to receive(:perform)
247
263
  expect_any_instance_of(interactor2).to receive(:perform)
248
264
  subject
249
265
  end
266
+
250
267
  it 'is expected to receive #rollback on both interactors' do
251
268
  expect_any_instance_of(interactor1).to receive(:rollback)
252
269
  expect_any_instance_of(interactor2).to receive(:rollback)