Skip to content
Snippets Groups Projects
Commit 9ce8aa31 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Respond with validation errors in commit status API

If validation errors are present, include validation errors in the
commit status API payload, instead of depending on state machine errors
caused by invalid record.
parent 53f4f849
No related branches found
No related tags found
No related merge requests found
Loading
@@ -78,6 +78,8 @@ module API
Loading
@@ -78,6 +78,8 @@ module API
description: params[:description] description: params[:description]
) )
   
render_validation_error!(status) if status.invalid?
begin begin
case params[:state] case params[:state]
when 'pending' when 'pending'
Loading
Loading
Loading
@@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do
Loading
@@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do
end end
end end
   
context 'invalid status' do context 'when status is invalid' do
before { post api(post_url, developer), state: 'invalid' } before { post api(post_url, developer), state: 'invalid' }
   
it 'does not create commit status' do it 'does not create commit status' do
Loading
@@ -180,7 +180,7 @@ describe API::CommitStatuses, api: true do
Loading
@@ -180,7 +180,7 @@ describe API::CommitStatuses, api: true do
end end
end end
   
context 'request without state' do context 'when request without a state made' do
before { post api(post_url, developer) } before { post api(post_url, developer) }
   
it 'does not create commit status' do it 'does not create commit status' do
Loading
@@ -188,7 +188,7 @@ describe API::CommitStatuses, api: true do
Loading
@@ -188,7 +188,7 @@ describe API::CommitStatuses, api: true do
end end
end end
   
context 'invalid commit' do context 'when commit SHA is invalid' do
let(:sha) { 'invalid_sha' } let(:sha) { 'invalid_sha' }
before { post api(post_url, developer), state: 'running' } before { post api(post_url, developer), state: 'running' }
   
Loading
@@ -196,6 +196,19 @@ describe API::CommitStatuses, api: true do
Loading
@@ -196,6 +196,19 @@ describe API::CommitStatuses, api: true do
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
context 'when target URL is an invalid address' do
before do
post api(post_url, developer), state: 'pending',
target_url: 'invalid url'
end
it 'responds with bad request status and validation errors' do
expect(response).to have_http_status(400)
expect(json_response['message']['target_url'])
.to include 'must be a valid URL'
end
end
end end
   
context 'reporter user' do context 'reporter user' do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment