From 5c6b683526d9f5cc3f3caa639c91d5aa265fe514 Mon Sep 17 00:00:00 2001 From: Malaber Date: Sat, 8 Mar 2025 17:46:55 +0100 Subject: [PATCH] All groups are created equal --- spec/services/group_stage_service_spec.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spec/services/group_stage_service_spec.rb b/spec/services/group_stage_service_spec.rb index 61768c9..55f8576 100644 --- a/spec/services/group_stage_service_spec.rb +++ b/spec/services/group_stage_service_spec.rb @@ -194,12 +194,18 @@ RSpec.describe GroupStageService do describe '#get_advancing_teams', focus: true do context 'when special case for po2 applies' do before do - # Create some example teams - teams1 = [Team.new(name: 'Team 1'), Team.new(name: 'Team 2'), Team.new(name: 'Team 3'), Team.new(name: 'Team 4')] - teams2 = [Team.new(name: 'Team 5'), Team.new(name: 'Team 6'), Team.new(name: 'Team 7'), Team.new(name: 'Team 8')] + teams = create_list(:team, 32) - # Group the teams - groups = [teams1, teams2] + # put the teams in groups of four + 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}" + team.save! + end + end # Generate the group stage @group_stage = GroupStageService.generate_group_stage(groups) @@ -210,8 +216,9 @@ RSpec.describe GroupStageService do @group_stage.groups.each do |group| group.matches.each do |match| match.match_scores.each do |ms| - # give the team the amount of points as in their name - ms.points = ms.team.name.split(' ').last.to_i + # give the team 10 points minus the number in their name + # this results in the team 1 always winning and getting to place 1 in the group etc. + ms.points = 10 - ms.team.name.split(' ').last.to_i ms.save! end match.state = 'finished'