Assign number to each group

This commit is contained in:
Daniel Schädler 2019-06-16 18:04:18 +02:00
parent c2056df1ba
commit db70e33882
2 changed files with 8 additions and 1 deletions

View File

@ -8,7 +8,7 @@ class GroupStageService
# raise an error if the average group size is not a whole number
raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero?
groups = groups.map(&method(:get_group_object_from))
groups = groups.map(&method(:get_group_object_from)).each_with_index { |group, i| group.number = i + 1 }
Stage.new level: -1, groups: groups, state: :in_progress
end

View File

@ -19,6 +19,13 @@ RSpec.describe GroupStageService do
expect(prepared_groups_groupstage.state).to eq('in_progress')
end
it 'assigns unique numbers to each group' do
groups = prepared_groups_groupstage.groups
groups.sort_by(&:number).each_with_index do |group, i|
expect(group.number).to eq(i + 1)
end
end
it 'returns a stage object with level -1' do
expect(prepared_groups_groupstage.level).to be(-1)
end