From 65ff6a830ede12a420e9a0aa5b6a8161e0f0da47 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Mon, 27 May 2019 23:18:49 +0200 Subject: [PATCH] Correctly handle matches that are not started yet --- app/models/match.rb | 1 + spec/models/match_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/match.rb b/app/models/match.rb index dee7f66..db55459 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -48,6 +48,7 @@ class Match < ApplicationRecord end def group_points_of(team) + return 0 unless finished? || in_progress? return 0 unless teams.include?(team) case current_leading_team diff --git a/spec/models/match_spec.rb b/spec/models/match_spec.rb index 05322b2..1491bfa 100644 --- a/spec/models/match_spec.rb +++ b/spec/models/match_spec.rb @@ -126,6 +126,25 @@ RSpec.describe Match, type: :model do 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 before do @match.match_scores.each do |ms|