diff --git a/lib/active_interactor/organizer/interactor_interface.rb b/lib/active_interactor/organizer/interactor_interface.rb index 34ced30..d3d555e 100644 --- a/lib/active_interactor/organizer/interactor_interface.rb +++ b/lib/active_interactor/organizer/interactor_interface.rb @@ -121,7 +121,7 @@ def skip_deferred_after_perform_callbacks return unless deferred_after_perform_callbacks.present? deferred_after_perform_callbacks.each do |callback| - interactor_class.skip_callback(:perform, :after, callback.filter, raise: false) + interactor_class.skip_callback(:perform, :after, callback.filter, raise: false, if: -> { self.options.organizer.present? }) end end diff --git a/spec/integration/an_organizer_with_after_callbacks_deferred_spec.rb b/spec/integration/an_organizer_with_interactor_with_after_callbacks_deferred_spec.rb similarity index 62% rename from spec/integration/an_organizer_with_after_callbacks_deferred_spec.rb rename to spec/integration/an_organizer_with_interactor_with_after_callbacks_deferred_spec.rb index e8002c3..2ceb365 100644 --- a/spec/integration/an_organizer_with_after_callbacks_deferred_spec.rb +++ b/spec/integration/an_organizer_with_interactor_with_after_callbacks_deferred_spec.rb @@ -9,6 +9,7 @@ after_perform do context.steps << 'after_perform_1a' + context.called_test_after_perform = true end after_perform do @@ -16,6 +17,7 @@ end def perform + context.fail! if context.should_fail context.steps = [] context.steps << 'perform_1' end @@ -57,6 +59,8 @@ def perform organize TestInteractor1, TestInteractor2, TestInteractor3 end end + + let(:organizer) { interactor_class } include_examples 'a class with interactor methods' include_examples 'a class with interactor callback methods' @@ -147,5 +151,55 @@ def perform ] )} end + + context 'when interactor is called via organizer' do + context 'and interactor is called individually prior' do + it 'calls the after_perform callbacks in both cases' do + result = test_interactor_1.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + + result = organizer.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + end + + context 'and interactor fails when called individually' do + it 'calls the after_perform callbacks just when organized' do + result = test_interactor_1.perform(should_fail: true) + expect(result).to be_failure + expect(result.called_test_after_perform).to be_nil + + result = organizer.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + end + end + end + + context 'and interactor is called individually after' do + it 'calls the after_perform callbacks in both cases' do + result = organizer.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + + result = test_interactor_1.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + end + + context 'and interactor fails when called individually' do + it 'calls the after_perform callbacks just when organized' do + result = organizer.perform + expect(result).to be_success + expect(result.called_test_after_perform).to be(true) + + result = test_interactor_1.perform(should_fail: true) + expect(result).to be_failure + expect(result.called_test_after_perform).to be_nil + end + end + end + end end -end \ No newline at end of file +end