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
|
# associate provided teams with tournament
|
||||||
tournament.teams = teams
|
tournament.teams = teams
|
||||||
# add playoff stage to tournament
|
# add playoff stage to tournament
|
||||||
result = AddPlayoffsToTournamentAndSave.call(tournament: tournament)
|
result = AddPlayoffsToTournamentAndSave.call(tournament: tournament, teams: tournament.teams)
|
||||||
end
|
end
|
||||||
# validate tournament
|
# validate tournament
|
||||||
unless tournament.valid?
|
unless tournament.valid?
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ class AddPlayoffsToTournament
|
||||||
def call
|
def call
|
||||||
tournament = context.tournament
|
tournament = context.tournament
|
||||||
context.fail! if tournament.stages.size > 1
|
context.fail! if tournament.stages.size > 1
|
||||||
if (playoff_stages = PlayoffStageService.generate_playoff_stages_from_tournament(tournament,
|
if (playoff_stages = PlayoffStageService.generate_playoff_stages(context.teams, context.randomize_matches))
|
||||||
context.randomize_matches))
|
|
||||||
if tournament.stages.empty?
|
if tournament.stages.empty?
|
||||||
tournament.stages = playoff_stages
|
tournament.stages = playoff_stages
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,6 @@ class PlayoffStageService
|
||||||
playoffs
|
playoffs
|
||||||
end
|
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
|
# Generates given number of empty stages
|
||||||
#
|
#
|
||||||
# @param stage_count [Integer] number of stages to generate
|
# @param stage_count [Integer] number of stages to generate
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
||||||
let(:group_stage_tournament_context) 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
|
end
|
||||||
|
|
||||||
let(:playoff_stage_tournament_context) do
|
let(:playoff_stage_tournament_context) do
|
||||||
AddPlayoffsToTournament.call(tournament: @playoff_stage_tournament)
|
AddPlayoffsToTournament.call(tournament: @playoff_stage_tournament, teams: @playoff_stage_tournament.teams)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:full_tournament_context) do
|
let(:full_tournament_context) do
|
||||||
AddPlayoffsToTournament.call(tournament: @full_tournament)
|
AddPlayoffsToTournament.call(tournament: @full_tournament, teams: @full_tournament.teams)
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
@ -23,7 +23,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
||||||
context 'PlayoffStageService mocked' do
|
context 'PlayoffStageService mocked' do
|
||||||
before do
|
before do
|
||||||
expect(class_double('PlayoffStageService').as_stubbed_const(transfer_nested_constants: true))
|
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)
|
.and_return(@stages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
||||||
context 'playoff generation fails' do
|
context 'playoff generation fails' do
|
||||||
before do
|
before do
|
||||||
expect(class_double('PlayoffStageService').as_stubbed_const(transfer_nested_constants: true))
|
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)
|
.and_return(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue