Correctly handle matches that are not started yet

This commit is contained in:
Daniel Schädler 2019-05-27 23:18:49 +02:00
parent c1dc43948b
commit 752beefca6
2 changed files with 20 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class Match < ApplicationRecord
end end
def group_points_of(team) def group_points_of(team)
return 0 unless teams.include?(team) return 0 unless (finished? || in_progress?) && teams.include?(team)
case current_leading_team case current_leading_team
when team when team

View File

@ -126,6 +126,25 @@ RSpec.describe Match, type: :model do
end end
end end
context 'not started match' do
before do
@not_started_match = create(:running_group_match, state: :not_started)
@team1 = @not_started_match.teams.first
end
it 'returns correct group_points' do
expect(@not_started_match.group_points_of(@team1)).to be(0)
end
it 'returns correct scored_points' do
expect(@match.scored_points_of(@team1)).to be(0)
end
it 'returns correct received_points' do
expect(@match.received_points_of(@team1)).to be(0)
end
end
context 'uneven match' do context 'uneven match' do
before do before do
@match.match_scores.each do |ms| @match.match_scores.each do |ms|