From 386155a69011bd165779df76ec1b32d207acf6ad Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Tue, 18 Jun 2019 12:55:55 +0200 Subject: [PATCH] Fix last Match not being stopped correctly --- app/services/playoff_stage_service.rb | 2 +- spec/controllers/matches_controller_spec.rb | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/services/playoff_stage_service.rb b/app/services/playoff_stage_service.rb index 3ee2e1f..11b28b1 100644 --- a/app/services/playoff_stage_service.rb +++ b/app/services/playoff_stage_service.rb @@ -79,7 +79,7 @@ class PlayoffStageService current_stage = current_match.stage next_stage = current_stage.tournament.stages.find { |s| s.level == current_stage.level - 1 } # return if next stage does not exist (there are no matches after the finale) - return if next_stage.nil? + return [] if next_stage.nil? current_position = current_match.position diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index 0078b61..061c4e8 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -174,6 +174,30 @@ RSpec.describe MatchesController, type: :controller do end end end + + context 'on the last match in the tournament' do + let(:updated_finale) do + only_final_tournament = create(:stage_tournament, stage_count: 1) + finale = only_final_tournament.stages.first.matches.first + + finale.match_scores.each_with_index do |ms, i| + ms.points = i + ms.save! + end + + apply_authentication_headers_for finale.owner + put :update, params: { id: finale.to_param }.merge(finished) + finale.reload + end + + it 'response is successful' do + expect(response).to be_successful + end + + it 'updates the matches status' do + expect(updated_finale.state).to eq(finished[:state]) + end + end end end