From bc055843d983d5f4046a850007ad573de69e2409 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 10 May 2019 11:46:19 +0200 Subject: [PATCH] Test stopping of Matches --- spec/controllers/matches_controller_spec.rb | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index c75a1c5..35dd4e0 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -5,6 +5,8 @@ require 'rails_helper' RSpec.describe MatchesController, type: :controller do before do @match = create(:match, state: :not_started) + @tournament = create(:group_stage_tournament, stage_count: 3) + @running_playoff_match = @tournament.stages.find { |s| s.level == 3 }.matches.first @match.match_scores = create_pair(:match_score) end @@ -65,6 +67,38 @@ RSpec.describe MatchesController, type: :controller do end end + context 'as another owner' do + let(:finished) do + { + state: 'finished' + } + end + + before(:each) do + apply_authentication_headers_for @running_playoff_match.owner + end + + context 'stops the match' do + before do + @running_playoff_match.match_scores.each_with_index { |ms, i| ms.points = i } + @running_playoff_match.save + put :update, params: { id: @running_playoff_match.to_param }.merge(finished) + @running_playoff_match.reload + end + + it 'updates the matches status' do + expect(response).to be_successful + expect(@running_playoff_match.state).to eq(finished[:state]) + end + + it 'populates the match below' do + match_below = @tournament.stages.find { |s| s.level == 2 }.matches + .find { |m| m.position == @running_playoff_match.position / 2 }.reload + expect(match_below.teams).to include(@running_playoff_match.winner) + end + end + end + context 'as another user' do context 'with valid params' do before(:each) do