Skip to content

Commit

Permalink
allow multiple organize calls in an organizer (implements collectivei…
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgesky committed Mar 31, 2017
1 parent 31efe66 commit 5d28fbe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/interactor/organizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1761,4 +1761,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
10 changes: 10 additions & 0 deletions spec/interactor/organizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d28fbe

Please sign in to comment.