Add winner method to match

This commit is contained in:
Daniel Schädler 2019-05-10 12:01:34 +02:00
parent 5c6c496d74
commit 1304f86652
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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)