Add GroupScore objects for every team to the group stage

This commit is contained in:
Daniel Schädler 2019-05-29 21:53:27 +02:00
parent 3cad50776f
commit 5809a062a6
2 changed files with 8 additions and 1 deletions

View File

@ -13,7 +13,8 @@ class GroupStageService
end end
def get_group_object_from(team_array) def get_group_object_from(team_array)
Group.new matches: generate_all_matches_between(team_array) Group.new matches: generate_all_matches_between(team_array),
group_scores: team_array.map { |team| GroupScore.new team: team }
end end
def generate_all_matches_between(teams) def generate_all_matches_between(teams)

View File

@ -23,6 +23,12 @@ RSpec.describe GroupStageService do
expect(group_stage_teams).to match_array(@groups.flatten) expect(group_stage_teams).to match_array(@groups.flatten)
end end
it 'adds GroupScore objects for every team present in the group' do
group_stage = GroupStageService.generate_group_stage(@groups)
teams_in_group_scores = group_stage.groups.map{ |g| g.group_scores.map(&:team) }.flatten
expect(teams_in_group_scores).to match_array(@groups.flatten)
end
it 'raises exception when given different sizes of groups' do it 'raises exception when given different sizes of groups' do
unequal_groups = @groups unequal_groups = @groups
unequal_groups.first.pop unequal_groups.first.pop