Test returning unprocessable entity when match_score update fails

This commit is contained in:
Daniel Schädler 2019-06-05 10:13:26 +02:00
parent 24ce5b7a62
commit 15e344fa2e
1 changed files with 23 additions and 9 deletions

View File

@ -34,18 +34,32 @@ RSpec.describe MatchScoresController, type: :controller do
before(:each) do
apply_authentication_headers_for @owner
end
context 'when match_score update succeeds' do
it 'updates the requested score' do
put :update, params: { id: @match_score.to_param }.merge(valid_update)
@match_score.reload
expect(@match_score.points).to eq(valid_update[:points])
end
it 'updates the requested score' do
put :update, params: { id: @match_score.to_param }.merge(valid_update)
@match_score.reload
expect(@match_score.points).to eq(valid_update[:points])
it 'renders a response with the updated team' do
put :update, params: { id: @match_score.to_param }.merge(valid_update)
expect(response).to be_successful
body = deserialize_response response
expect(body[:points]).to eq(valid_update[:points])
end
end
it 'renders a response with the updated team' do
put :update, params: { id: @match_score.to_param }.merge(valid_update)
expect(response).to be_successful
body = deserialize_response response
expect(body[:points]).to eq(valid_update[:points])
context 'when match_score update fails' do
before do
allow_any_instance_of(MatchScore)
.to receive(:update)
.and_return(false)
end
it 'returns unprocessable entity' do
put :update, params: { id: @match_score.to_param }.merge(valid_update)
expect(response).to have_http_status(:unprocessable_entity)
end
end
end