diff --git a/app/models/match.rb b/app/models/match.rb index 8007619..2779fa7 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -19,13 +19,20 @@ class Match < ApplicationRecord stage ? stage.owner : group.owner end - private + def winner + return nil unless finished? + return nil if match_scores.first.points == match_scores.second.points - def stage_xor_group - errors.add(:stage_xor_group, 'Stage and Group missing or both present') unless stage.present? ^ group.present? + match_scores.max_by(&:points).team end def group_match? group.present? 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 diff --git a/app/services/playoff_stage_service.rb b/app/services/playoff_stage_service.rb index 340a9a2..ed0e19a 100644 --- a/app/services/playoff_stage_service.rb +++ b/app/services/playoff_stage_service.rb @@ -70,4 +70,11 @@ class PlayoffStageService stage_count.to_int end end + + def self.populate_match_below(match) + current_stage = match.stage + next_stage = match.stage.tournament.stages. + + puts + end end diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 5acec23..0d4656c 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -43,6 +43,20 @@ RSpec.describe Match, type: :model do 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 before do @playoff_match = create(:running_playoff_match)