Commit 74906f3d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix updaing commit status with optional attributes

Passing different optional attributes in case of updating an existing
commit status should not create a new commit status with the same name.
parent 48d7ed63
...@@ -72,14 +72,15 @@ module API ...@@ -72,14 +72,15 @@ module API
status = GenericCommitStatus.running_or_pending.find_or_initialize_by( status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
project: @project, project: @project,
pipeline: pipeline, pipeline: pipeline,
user: current_user,
name: name, name: name,
ref: ref, ref: ref,
target_url: params[:target_url], user: current_user
description: params[:description],
coverage: params[:coverage]
) )
optional_attributes =
attributes_for_keys(%w[target_url description coverage])
status.update(optional_attributes) if optional_attributes.any?
render_validation_error!(status) if status.invalid? render_validation_error!(status) if status.invalid?
begin begin
......
...@@ -151,26 +151,59 @@ describe API::CommitStatuses, api: true do ...@@ -151,26 +151,59 @@ describe API::CommitStatuses, api: true do
end end
context 'with all optional parameters' do context 'with all optional parameters' do
before do context 'when creating a commit status' do
optional_params = { state: 'success', it 'creates commit status' do
context: 'coverage', post api(post_url, developer), {
ref: 'develop', state: 'success',
description: 'test', context: 'coverage',
coverage: 80.0, ref: 'develop',
target_url: 'http://gitlab.com/status' } description: 'test',
coverage: 80.0,
post api(post_url, developer), optional_params target_url: 'http://gitlab.com/status' }
expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage')
expect(json_response['ref']).to eq('develop')
expect(json_response['coverage']).to eq(80.0)
expect(json_response['description']).to eq('test')
expect(json_response['target_url']).to eq('http://gitlab.com/status')
end
end end
it 'creates commit status' do context 'when updatig a commit status' do
expect(response).to have_http_status(201) before do
expect(json_response['sha']).to eq(commit.id) post api(post_url, developer), {
expect(json_response['status']).to eq('success') state: 'running',
expect(json_response['name']).to eq('coverage') context: 'coverage',
expect(json_response['ref']).to eq('develop') ref: 'develop',
expect(json_response['coverage']).to eq(80.0) description: 'coverage test',
expect(json_response['description']).to eq('test') coverage: 0.0,
expect(json_response['target_url']).to eq('http://gitlab.com/status') target_url: 'http://gitlab.com/status' }
post api(post_url, developer), {
state: 'success',
name: 'coverage',
ref: 'develop',
description: 'new description',
coverage: 90.0 }
end
it 'updates a commit status' do
expect(response).to have_http_status(201)
expect(json_response['sha']).to eq(commit.id)
expect(json_response['status']).to eq('success')
expect(json_response['name']).to eq('coverage')
expect(json_response['ref']).to eq('develop')
expect(json_response['coverage']).to eq(90.0)
expect(json_response['description']).to eq('new description')
expect(json_response['target_url']).to eq('http://gitlab.com/status')
end
it 'does not create a new commit status' do
expect(CommitStatus.count).to eq 1
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment