Make teams added to PlayoffStage configurable
This commit is contained in:
parent
748ac18b35
commit
4925ea9d83
|
|
@ -49,7 +49,7 @@ class TournamentsController < ApplicationController
|
|||
# associate provided teams with tournament
|
||||
tournament.teams = teams
|
||||
# add playoff stage to tournament
|
||||
result = AddPlayoffsToTournamentAndSave.call(tournament: tournament)
|
||||
result = AddPlayoffsToTournamentAndSave.call(tournament: tournament, teams: tournament.teams)
|
||||
end
|
||||
# validate tournament
|
||||
unless tournament.valid?
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ class AddPlayoffsToTournament
|
|||
def call
|
||||
tournament = context.tournament
|
||||
context.fail! if tournament.stages.size > 1
|
||||
if (playoff_stages = PlayoffStageService.generate_playoff_stages_from_tournament(tournament,
|
||||
context.randomize_matches))
|
||||
if (playoff_stages = PlayoffStageService.generate_playoff_stages(context.teams, context.randomize_matches))
|
||||
if tournament.stages.empty?
|
||||
tournament.stages = playoff_stages
|
||||
else
|
||||
|
|
|
|||
|
|
@ -21,14 +21,6 @@ class PlayoffStageService
|
|||
playoffs
|
||||
end
|
||||
|
||||
# Generates the playoff stage given the tournament
|
||||
#
|
||||
# @param tournament [Tournament] The tournament to generate the playoff stages from
|
||||
# @return [Array] the generated playoff stages
|
||||
def generate_playoff_stages_from_tournament(tournament, randomize_matches)
|
||||
generate_playoff_stages(tournament.teams, randomize_matches)
|
||||
end
|
||||
|
||||
# Generates given number of empty stages
|
||||
#
|
||||
# @param stage_count [Integer] number of stages to generate
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
||||
let(:group_stage_tournament_context) do
|
||||
AddPlayoffsToTournament.call(tournament: @group_stage_tournament)
|
||||
AddPlayoffsToTournament.call(tournament: @group_stage_tournament, teams: @group_stage_tournament.teams)
|
||||
end
|
||||
|
||||
let(:playoff_stage_tournament_context) do
|
||||
AddPlayoffsToTournament.call(tournament: @playoff_stage_tournament)
|
||||
AddPlayoffsToTournament.call(tournament: @playoff_stage_tournament, teams: @playoff_stage_tournament.teams)
|
||||
end
|
||||
|
||||
let(:full_tournament_context) do
|
||||
AddPlayoffsToTournament.call(tournament: @full_tournament)
|
||||
AddPlayoffsToTournament.call(tournament: @full_tournament, teams: @full_tournament.teams)
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
@ -23,7 +23,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
|||
context 'PlayoffStageService mocked' do
|
||||
before do
|
||||
expect(class_double('PlayoffStageService').as_stubbed_const(transfer_nested_constants: true))
|
||||
.to receive(:generate_playoff_stages_from_tournament)
|
||||
.to receive(:generate_playoff_stages)
|
||||
.and_return(@stages)
|
||||
end
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
|||
context 'playoff generation fails' do
|
||||
before do
|
||||
expect(class_double('PlayoffStageService').as_stubbed_const(transfer_nested_constants: true))
|
||||
.to receive(:generate_playoff_stages_from_tournament)
|
||||
.to receive(:generate_playoff_stages)
|
||||
.and_return(nil)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue