Merge pull request #60 from turniere/ticket/TURNIERE-252

Assign unique number to each group
This commit is contained in:
Thor77 2019-06-17 13:47:00 +02:00 committed by GitHub
commit 7e2567a8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 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

@ -1,6 +1,6 @@
# frozen_string_literal: true
RSpec.describe GroupStageService, focus: true do
RSpec.describe GroupStageService do
before do
@teams1 = create_list(:team, 4)
@teams2 = create_list(:team, 4)
@ -19,6 +19,13 @@ RSpec.describe GroupStageService, focus: true 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