Fix match points specs

This commit is contained in:
Daniel Schädler 2026-04-15 11:22:55 +02:00
parent bb9b900b39
commit ce7b5c5ac7
2 changed files with 23 additions and 21 deletions

View File

@ -41,6 +41,7 @@ class Match < ApplicationRecord
def scored_points_of(team) def scored_points_of(team)
return 0 if decider? return 0 if decider?
return 0 unless (finished? || in_progress?) && teams.include?(team)
match_score = match_score_for(team) match_score = match_score_for(team)
match_score ? match_score.points : 0 match_score ? match_score.points : 0
@ -48,6 +49,7 @@ class Match < ApplicationRecord
def received_points_of(team) def received_points_of(team)
return 0 if decider? return 0 if decider?
return 0 unless (finished? || in_progress?) && teams.include?(team)
opponent_match_score = opponent_match_score_for(team) opponent_match_score = opponent_match_score_for(team)
opponent_match_score ? opponent_match_score.points : 0 opponent_match_score ? opponent_match_score.points : 0

View File

@ -109,21 +109,21 @@ RSpec.describe Match, type: :model do
end end
it 'returns correct group_points' do it 'returns correct group_points' do
expect(@match.group_points_of(@team1)).to be(1) expect(@match.group_points_of(@team1)).to eq(1)
expect(@match.group_points_of(@team2)).to be(1) expect(@match.group_points_of(@team2)).to eq(1)
expect(@match.group_points_of(@uninvolved_team)).to be(0) expect(@match.group_points_of(@uninvolved_team)).to eq(0)
end end
it 'returns correct scored_points' do it 'returns correct scored_points' do
expect(@match.scored_points_of(@team1)).to be(34) expect(@match.scored_points_of(@team1)).to eq(34)
expect(@match.scored_points_of(@team2)).to be(34) expect(@match.scored_points_of(@team2)).to eq(34)
expect(@match.scored_points_of(@uninvolved_team)).to be(0) expect(@match.scored_points_of(@uninvolved_team)).to eq(0)
end end
it 'returns correct received_points' do it 'returns correct received_points' do
expect(@match.received_points_of(@team1)).to be(34) expect(@match.received_points_of(@team1)).to eq(34)
expect(@match.received_points_of(@team2)).to be(34) expect(@match.received_points_of(@team2)).to eq(34)
expect(@match.received_points_of(@uninvolved_team)).to be(0) expect(@match.received_points_of(@uninvolved_team)).to eq(0)
end end
end end
@ -134,15 +134,15 @@ RSpec.describe Match, type: :model do
end end
it 'returns correct group_points' do it 'returns correct group_points' do
expect(@not_started_match.group_points_of(@team1)).to be(0) expect(@not_started_match.group_points_of(@team1)).to eq(0)
end end
it 'returns correct scored_points' do it 'returns correct scored_points' do
expect(@match.scored_points_of(@team1)).to be(0) expect(@not_started_match.scored_points_of(@team1)).to eq(0)
end end
it 'returns correct received_points' do it 'returns correct received_points' do
expect(@match.received_points_of(@team1)).to be(0) expect(@not_started_match.received_points_of(@team1)).to eq(0)
end end
end end
@ -155,21 +155,21 @@ RSpec.describe Match, type: :model do
end end
it 'returns correct group_points' do it 'returns correct group_points' do
expect(@match.group_points_of(@team1)).to be(3) expect(@match.group_points_of(@team1)).to eq(3)
expect(@match.group_points_of(@team2)).to be(0) expect(@match.group_points_of(@team2)).to eq(0)
expect(@match.group_points_of(@uninvolved_team)).to be(0) expect(@match.group_points_of(@uninvolved_team)).to eq(0)
end end
it 'returns correct scored_points' do it 'returns correct scored_points' do
expect(@match.scored_points_of(@team1)).to be(42) expect(@match.scored_points_of(@team1)).to eq(42)
expect(@match.scored_points_of(@team2)).to be(17) expect(@match.scored_points_of(@team2)).to eq(17)
expect(@match.scored_points_of(@uninvolved_team)).to be(0) expect(@match.scored_points_of(@uninvolved_team)).to eq(0)
end end
it 'returns correct received_points' do it 'returns correct received_points' do
expect(@match.received_points_of(@team1)).to be(17) expect(@match.received_points_of(@team1)).to eq(17)
expect(@match.received_points_of(@team2)).to be(42) expect(@match.received_points_of(@team2)).to eq(42)
expect(@match.received_points_of(@uninvolved_team)).to be(0) expect(@match.received_points_of(@uninvolved_team)).to eq(0)
end end
end end
end end