From 3109308817c513ebc6c0337e19195c684387ed22 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Mon, 17 Jun 2019 16:14:27 +0200 Subject: [PATCH 1/2] Fix teams not associated with created tournament when choosing a group stage --- app/controllers/tournaments_controller.rb | 2 ++ spec/controllers/tournaments_controller_spec.rb | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 9fa7f18..e62ae40 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -39,6 +39,8 @@ class TournamentsController < ApplicationController if group_stage params.require(:playoff_teams_amount) groups = organize_teams_in_groups(teams) + # associate provided teams with tournament + tournament.teams = groups.flatten # add groups to tournament result = AddGroupStageToTournamentAndSave.call(tournament: tournament, groups: groups) else diff --git a/spec/controllers/tournaments_controller_spec.rb b/spec/controllers/tournaments_controller_spec.rb index 06e05dc..cb1ef87 100644 --- a/spec/controllers/tournaments_controller_spec.rb +++ b/spec/controllers/tournaments_controller_spec.rb @@ -195,6 +195,10 @@ RSpec.describe TournamentsController, type: :controller do .to eq(create_group_tournament_data[:playoff_teams_amount]) end + it 'associates the given teams with the created tournament' do + expect(@group_stage_tournament.teams).to match_array(@teams16) + end + context 'playoff_teams_amount unacceptable' do shared_examples_for 'wrong playoff_teams_amount' do it 'fails' do From 2baefb9ae6d9ce04c4da14de4293b80e14764a19 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Tue, 18 Jun 2019 12:14:49 +0200 Subject: [PATCH 2/2] Associate teams only on interactor success --- app/controllers/tournaments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index e62ae40..78bcfee 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -39,10 +39,10 @@ class TournamentsController < ApplicationController if group_stage params.require(:playoff_teams_amount) groups = organize_teams_in_groups(teams) - # associate provided teams with tournament - tournament.teams = groups.flatten # add groups to tournament result = AddGroupStageToTournamentAndSave.call(tournament: tournament, groups: groups) + # associate provided teams with tournament on success + tournament.teams = groups.flatten if result.success? else # convert teams parameter into Team objects teams = teams.map(&method(:find_or_create_team))