Add interactor to advance all teams stuck in single team matches

After playoffs are created, before saving the stage this interactor
goes to the intermediate stage, looks for all the matches that are
:single_team matches and populates the match below with their respective
"winner".
This commit is contained in:
Daniel Schädler 2019-06-12 21:53:36 +02:00
parent 98319e9625
commit c9e1e153df
4 changed files with 35 additions and 2 deletions

View File

@ -12,7 +12,8 @@ class AddPlayoffsToTournament
else else
tournament.stages.concat playoff_stages tournament.stages.concat playoff_stages
end end
context.object_to_save = tournament context.intermediate_stage = tournament.stages.find(&:intermediate_stage?)
context.object_to_save = [tournament]
else else
context.fail! context.fail!
end end

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class AdvanceTeamsInIntermediateStage
include Interactor
def call
intermediate_stage = context.intermediate_stage
return if intermediate_stage.nil?
intermediate_stage.matches.select { |m| m.state == 'single_team' }
.each { |match| PopulateMatchBelowAndSave.call(match: match) }
context.object_to_save << intermediate_stage
end
end

View File

@ -3,5 +3,5 @@
class AddPlayoffsToTournamentAndSave class AddPlayoffsToTournamentAndSave
include Interactor::Organizer include Interactor::Organizer
organize AddPlayoffsToTournament, SaveApplicationRecordObject organize AddPlayoffsToTournament, AdvanceTeamsInIntermediateStage, SaveApplicationRecordObject
end end

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
RSpec.describe AdvanceTeamsInIntermediateStage do
context 'intermediate_stage is nil' do
let(:context) do
AdvanceTeamsInIntermediateStage.call(intermediate_stage: nil)
end
it 'succeeds' do
expect(context).to be_a_success
end
it 'doesn\'t call PopulateMatchBelow' do
expect(PopulateMatchBelowAndSave).not_to receive(:call)
context
end
end
end