Add winner method to match
This commit is contained in:
parent
280b0c1dec
commit
2f77d2d25b
|
|
@ -19,13 +19,20 @@ class Match < ApplicationRecord
|
||||||
stage ? stage.owner : group.owner
|
stage ? stage.owner : group.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def winner
|
||||||
|
return nil unless finished?
|
||||||
|
return nil if match_scores.first.points == match_scores.second.points
|
||||||
|
|
||||||
def stage_xor_group
|
match_scores.max_by(&:points).team
|
||||||
errors.add(:stage_xor_group, 'Stage and Group missing or both present') unless stage.present? ^ group.present?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_match?
|
def group_match?
|
||||||
group.present?
|
group.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def stage_xor_group
|
||||||
|
errors.add(:stage_xor_group, 'Stage and Group missing or both present') unless stage.present? ^ group.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -70,4 +70,11 @@ class PlayoffStageService
|
||||||
stage_count.to_int
|
stage_count.to_int
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.populate_match_below(match)
|
||||||
|
current_stage = match.stage
|
||||||
|
next_stage = match.stage.tournament.stages.
|
||||||
|
|
||||||
|
puts
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,20 @@ RSpec.describe Match, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#winner' do
|
||||||
|
it 'returns a winner Team for a decided match' do
|
||||||
|
decided_playoff_match = create(:decided_playoff_match)
|
||||||
|
winning_team_match_score = decided_playoff_match.match_scores.first
|
||||||
|
winning_team_match_score.points = 9999
|
||||||
|
winning_team = winning_team_match_score.team
|
||||||
|
expect(decided_playoff_match.winner).to be winning_team
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for an undecided match' do
|
||||||
|
expect(create(:undecided_group_match).winner).to be(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#teams' do
|
context '#teams' do
|
||||||
before do
|
before do
|
||||||
@playoff_match = create(:running_playoff_match)
|
@playoff_match = create(:running_playoff_match)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue