diff --git a/app/models/match.rb b/app/models/match.rb index 19edf02..2f0410b 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -19,6 +19,11 @@ class Match < ApplicationRecord stage ? stage.owner : group.owner end + def winner + evaluate_winner + # This should maybe be cached or put into db + end + private def evaluate_winner diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 01d34c5..f24ce70 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -43,6 +43,23 @@ RSpec.describe Match, type: :model do end end + context '#winner' do + before do + @undecided_match = create(:undecided_group_match) + @decided_match = create(:decided_playoff_match) + end + + it 'returns a winner Team for a decided match' do + winner = @decided_match.winner + expect(winner).to be_a Team + end + + it 'returns nil for an undecided match' do + winner = @undecided_match.winner + expect(winner).to be(nil) + end + end + context '#teams' do before do @playoff_match = create(:running_playoff_match)