From b8ce4d66c851e325d5f5e153a74e80e313fedf82 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 3 Jun 2019 17:50:21 +0200 Subject: [PATCH] Add field to tournament containing playoff_teams_amount This field represents how many teams advance into playoff stage after the group stage has ended. --- app/controllers/tournaments_controller.rb | 3 ++- db/migrate/0000_create_schema.rb | 1 + spec/controllers/tournaments_controller_spec.rb | 8 +++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 6f80705..d11667d 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -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 diff --git a/db/migrate/0000_create_schema.rb b/db/migrate/0000_create_schema.rb index 29d606a..f1d4a3f 100644 --- a/db/migrate/0000_create_schema.rb +++ b/db/migrate/0000_create_schema.rb @@ -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 } diff --git a/spec/controllers/tournaments_controller_spec.rb b/spec/controllers/tournaments_controller_spec.rb index 7231e60..c3313bd 100644 --- a/spec/controllers/tournaments_controller_spec.rb +++ b/spec/controllers/tournaments_controller_spec.rb @@ -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