From 9c9a8562652fb15757cd433ff923b781a40de503 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Tue, 4 Jun 2019 23:39:34 +0200 Subject: [PATCH] Test returning unprocessable entity when error occurs in match population --- spec/controllers/matches_controller_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/controllers/matches_controller_spec.rb b/spec/controllers/matches_controller_spec.rb index f1721cd..0825e8e 100644 --- a/spec/controllers/matches_controller_spec.rb +++ b/spec/controllers/matches_controller_spec.rb @@ -158,6 +158,22 @@ RSpec.describe MatchesController, type: :controller do expect(response).to have_http_status(:unprocessable_entity) end end + + context 'PopulateMatchBelowAndSave fails' do + before do + expect(PopulateMatchBelowAndSave).to receive(:call).once.with(match: @running_playoff_match) + .and_return(context) + end + + context 'when unsuccessful' do + let(:context) { double(:context, success?: false) } + + it 'returns unprocessable entity' do + put :update, params: { id: @running_playoff_match.to_param }.merge(finished) + expect(response).to have_http_status(:unprocessable_entity) + end + end + end end end