diff --git a/spec/factories/tournaments.rb b/spec/factories/tournaments.rb index 7b61999..4e2ab21 100644 --- a/spec/factories/tournaments.rb +++ b/spec/factories/tournaments.rb @@ -7,13 +7,23 @@ FactoryBot.define do user transient do teams_count { 8 } + teams { nil } + playoff_teams_amount { 4 } + instant_finalists_amount { 4 } + intermediate_round_participants_amount { 0 } end after(:create) do |tournament, evaluator| - tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament) - tournament.playoff_teams_amount = (tournament.teams.size / 2) - tournament.instant_finalists_amount = (tournament.playoff_teams_amount / 2) - tournament.intermediate_round_participants_amount = ((tournament.playoff_teams_amount - - tournament.instant_finalists_amount) * 2) + if evaluator.teams.present? + tournament.teams = evaluator.teams + else + tournament.teams = create_list(:team, evaluator.teams_count, tournament: tournament) + end + tournament.playoff_teams_amount = evaluator.playoff_teams_amount + tournament.instant_finalists_amount = evaluator.instant_finalists_amount + tournament.intermediate_round_participants_amount = evaluator.intermediate_round_participants_amount + if tournament.playoff_teams_amount != tournament.instant_finalists_amount + tournament.intermediate_round_participants_amount / 2 + raise 'playoff_teams_amount must be equal to instant_finalists_amount + intermediate_round_participants_amount / 2' + end tournament.save! end diff --git a/spec/services/group_stage_service_spec.rb b/spec/services/group_stage_service_spec.rb index 55f8576..fb093d8 100644 --- a/spec/services/group_stage_service_spec.rb +++ b/spec/services/group_stage_service_spec.rb @@ -200,9 +200,9 @@ RSpec.describe GroupStageService do groups = teams.each_slice(4).to_a # iterate over all groups and number the teams in their name - groups.each do |group| - group.each_with_index do |team, i| - team.name = "#{team.name} #{i}" + groups.each_with_index do |group, group_index| + group.each_with_index do |team, team_index| + team.name = "#{team.name} #{group_index} #{team_index}" team.save! end end @@ -210,8 +210,12 @@ RSpec.describe GroupStageService do # Generate the group stage @group_stage = GroupStageService.generate_group_stage(groups) - @tournament = create(:prepared_group_stage_tournament, group_stage: @group_stage) - + @tournament = create(:prepared_group_stage_tournament, + group_stage: @group_stage, + teams: teams, + playoff_teams_amount: 16, + instant_finalists_amount: 16, + intermediate_round_participants_amount: 0) # iterate over all groups and update the matches within to all be decided @group_stage.groups.each do |group| group.matches.each do |match|