Add field to tournament containing playoff_teams_amount

This field represents how many teams advance into playoff stage after
the group stage has ended.
This commit is contained in:
Daniel Schädler 2019-06-03 17:50:21 +02:00
parent fc13634769
commit bd2af09339
3 changed files with 10 additions and 2 deletions

View File

@ -36,6 +36,7 @@ class TournamentsController < ApplicationController
# create tournament
tournament = current_user.tournaments.new params
if group_stage
params.require(:playoff_teams_amount)
groups = organize_teams_in_groups(teams)
# add groups to tournament
result = AddGroupStageToTournamentAndSave.call(tournament: tournament, groups: groups)
@ -103,7 +104,7 @@ class TournamentsController < ApplicationController
end
def tournament_params
params.slice(:name, :description, :public, :teams, :group_stage).permit!
params.slice(:name, :description, :public, :teams, :group_stage, :playoff_teams_amount).permit!
end
def validate_create_params

View File

@ -51,6 +51,7 @@ class CreateSchema < ActiveRecord::Migration[5.2]
t.string :code, null: false, index: { unique: true }
t.string :description
t.boolean :public, default: true
t.integer :playoff_teams_amount
# relation to owner
t.belongs_to :user, index: true, null: false, foreign_key: { on_delete: :cascade }

View File

@ -121,7 +121,8 @@ RSpec.describe TournamentsController, type: :controller do
description: Faker::Movies::HarryPotter.quote,
public: false,
group_stage: true,
teams: teams_with_groups
teams: teams_with_groups,
playoff_teams_amount: (@teams16.size / 2)
}
end
@ -188,6 +189,11 @@ RSpec.describe TournamentsController, type: :controller do
group_stage = @group_stage_tournament.stages.find_by(level: -1)
expect(group_stage).to be_a(Stage)
end
it 'saves the amount of teams that advance into playoffs' do
expect(@group_stage_tournament.playoff_teams_amount)
.to eq(create_group_tournament_data[:playoff_teams_amount])
end
end
it 'renders a JSON response with the new tournament' do