From 80f576912f0d706f2714be78632ceaa22009fd7c Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Tue, 4 Jun 2019 19:04:12 +0200 Subject: [PATCH] Test unprocessable entity response on a match that is not ready Unprocessable entity is returned when you try to start a match that is not ready yet. --- spec/controllers/matches_controller_spec.rb | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index f0a4fa4..f1721cd 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -8,6 +8,7 @@ RSpec.describe MatchesController, type: :controller do @amount_of_stages = 2 @tournament = create(:stage_tournament, stage_count: @amount_of_stages) @running_playoff_match = @tournament.stages.find_by(level: @amount_of_stages).matches.first + @not_ready_playoff_match = create(:running_playoff_match, state: :not_ready) @match.match_scores = create_pair(:match_score) end @@ -188,5 +189,26 @@ RSpec.describe MatchesController, type: :controller do end end end + + context 'on a playoff match that isn\'t ready yet' do + let(:invalid_update) do + { + state: 'in_progress' + } + end + + context 'as owner' do + before(:each) do + apply_authentication_headers_for @not_ready_playoff_match.owner + end + + context 'with invalid params' do + it 'renders an unprocessable entity response' do + put :update, params: { id: @not_ready_playoff_match.to_param }.merge(invalid_update) + expect(response).to have_http_status(:unprocessable_entity) + end + end + end + end end end