Test returning unprocessable entity response
We now test sending a senseless state and also what happens when the match.update method fails for some reason.
This commit is contained in:
parent
c1b2b72ca3
commit
d03ceeffa4
|
|
@ -27,6 +27,7 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #update' do
|
describe 'POST #update' do
|
||||||
|
context 'on a running playoff match' do
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
{
|
{
|
||||||
state: 'in_progress'
|
state: 'in_progress'
|
||||||
|
|
@ -39,6 +40,12 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:senseless_update) do
|
||||||
|
{
|
||||||
|
state: 'not_ready'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
context 'as owner' do
|
context 'as owner' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
apply_authentication_headers_for @match.owner
|
apply_authentication_headers_for @match.owner
|
||||||
|
|
@ -70,6 +77,7 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
apply_authentication_headers_for @running_playoff_match.owner
|
apply_authentication_headers_for @running_playoff_match.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'match update succeeds' do
|
||||||
context 'on a decided match' do
|
context 'on a decided match' do
|
||||||
before do
|
before do
|
||||||
@running_playoff_match.match_scores.each_with_index do |ms, i|
|
@running_playoff_match.match_scores.each_with_index do |ms, i|
|
||||||
|
|
@ -136,6 +144,20 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'match update fails' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Match)
|
||||||
|
.to receive(:update)
|
||||||
|
.and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
context 'with invalid params' do
|
context 'with invalid params' do
|
||||||
|
|
@ -144,6 +166,13 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
expect(response).to have_http_status(:unprocessable_entity)
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with senseless params' do
|
||||||
|
it 'renders an unprocessable entity response' do
|
||||||
|
put :update, params: { id: @match.to_param }.merge(senseless_update)
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as another user' do
|
context 'as another user' do
|
||||||
|
|
@ -160,3 +189,4 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue