From 9f92ca7e5bbd85ad73febd4ccda3adc4b47bc251 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Thu, 23 May 2019 13:20:59 +0200 Subject: [PATCH] Move stopping of matches test --- spec/controllers/matches_controller_spec.rb | 68 ++++++++++----------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index ff12c79..9e3a26e 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -57,6 +57,39 @@ RSpec.describe MatchesController, type: :controller do body = deserialize_response response expect(body[:state]).to eq(valid_update[:state]) end + + context 'on a running playoff match' do + let(:finished) do + { + state: 'finished' + } + end + + before(:each) do + apply_authentication_headers_for @running_playoff_match.owner + end + + before do + @running_playoff_match.match_scores.each_with_index do |ms, i| + ms.points = i + ms.save + end + 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(@running_playoff_match.winner).to be_a(Team) + expect(match_below.teams).to include(@running_playoff_match.winner) + end + end end context 'with invalid params' do @@ -67,41 +100,6 @@ 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 do |ms, i| - ms.points = i - ms.save - end - 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(@running_playoff_match.winner).to be_a(Team) - 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