Fix last Match not being stopped correctly

This commit is contained in:
Daniel Schädler 2019-06-18 12:55:55 +02:00
parent b57c2498c3
commit 386155a690
2 changed files with 25 additions and 1 deletions

View File

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

View File

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