diff --git a/lib/interactor/organizer.rb b/lib/interactor/organizer.rb index fcba5bc..1d27992 100644 --- a/lib/interactor/organizer.rb +++ b/lib/interactor/organizer.rb @@ -41,11 +41,12 @@ module ClassMethods # include Interactor::Organizer # # organize [InteractorThree, InteractorFour] + # organize InteractorFive # end # # Returns nothing. def organize(*interactors) - @organized = interactors.flatten + organized.concat(interactors.flatten) end # Internal: An Array of declared Interactors to be invoked. diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index be6217f..d47ca74 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1774,4 +1774,30 @@ def rollback }.to raise_error("foo") end end + + context "when there are multiple organize calls" do + it "runs all passed interactors in correct order" do + organizer = build_organizer(organize: [organizer2, interactor3]) + organizer.organize(organizer4, interactor5) + + expect { + organizer.call(context) + }.to change { + context.steps + }.from([]).to([ + :around_before2, :before2, + :around_before2a, :before2a, :call2a, :after2a, :around_after2a, + :around_before2b, :before2b, :call2b, :after2b, :around_after2b, + :around_before2c, :before2c, :call2c, :after2c, :around_after2c, + :after2, :around_after2, + :around_before3, :before3, :call3, :after3, :around_after3, + :around_before4, :before4, + :around_before4a, :before4a, :call4a, :after4a, :around_after4a, + :around_before4b, :before4b, :call4b, :after4b, :around_after4b, + :around_before4c, :before4c, :call4c, :after4c, :around_after4c, + :after4, :around_after4, + :around_before5, :before5, :call5, :after5, :around_after5 + ]) + end + end end diff --git a/spec/interactor/organizer_spec.rb b/spec/interactor/organizer_spec.rb index 5b02aaa..a664c7b 100644 --- a/spec/interactor/organizer_spec.rb +++ b/spec/interactor/organizer_spec.rb @@ -23,6 +23,16 @@ module Interactor organizer.organized }.from([]).to([interactor2, interactor3]) end + + it "allows multiple organize calls" do + interactor4 = double(:interactor4) + expect { + organizer.organize(interactor2, interactor3) + organizer.organize(interactor4) + }.to change { + organizer.organized + }.from([]).to([interactor2, interactor3, interactor4]) + end end describe ".organized" do