summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2019-02-14 11:40:28 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2019-08-26 10:45:37 +0200
commitefafc98bd8ca7d4ed4c86f19325eb2aa51edd227 (patch)
tree3a0c83856bbab2356b06fc1747053413d0b8f99e
parent41412f73604159ca735420396df73f7b6eef6f86 (diff)
downloadgitlab-ce-efafc98bd8ca7d4ed4c86f19325eb2aa51edd227.tar.gz
Move promote to put and add more specs
-rw-r--r--doc/api/labels.md4
-rw-r--r--lib/api/labels.rb2
-rw-r--r--spec/requests/api/labels_spec.rb34
3 files changed, 32 insertions, 8 deletions
diff --git a/doc/api/labels.md b/doc/api/labels.md
index 9b640a0203d..21ac8a99965 100644
--- a/doc/api/labels.md
+++ b/doc/api/labels.md
@@ -193,7 +193,7 @@ Example response:
Promotes a project label to a group label.
```
-POST /projects/:id/labels/promote
+PUT /projects/:id/labels/promote
```
| Attribute | Type | Required | Description |
@@ -202,7 +202,7 @@ POST /projects/:id/labels/promote
| `name` | string | yes | The name of the existing label |
```bash
-curl --request POST --data "name=documentation" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/promote"
+curl --request PUT --data "name=documentation" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/promote"
```
Example response:
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 9f847c39fac..321ffa241b5 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -70,7 +70,7 @@ module API
params do
requires :name, type: String, desc: 'The name of the label to be promoted'
end
- post ':id/labels/promote' do
+ put ':id/labels/promote' do
authorize! :admin_label, user_project
label = find_label(user_project, params[:name], include_ancestor_groups: false)
diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb
index 047e8b6c507..f7df9bb1b3f 100644
--- a/spec/requests/api/labels_spec.rb
+++ b/spec/requests/api/labels_spec.rb
@@ -473,23 +473,47 @@ describe API::Labels do
end
end
- describe 'POST /projects/:id/labels/promote' do
+ describe 'PUT /projects/:id/labels/promote' do
+ let(:group) { create(:group) }
+
+ before do
+ project.update(group: group)
+ end
+
it 'returns 200 if label is promoted' do
- post api("/projects/#{project.id}/labels/promote", user), params: { name: 'label1' }
+ put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name }
expect(response).to have_gitlab_http_status(200)
expect(json_response['name']).to eq(label1.name)
- expect(json_response['color']).to eq('#FFFFFF')
+ expect(json_response['color']).to eq(label1.color)
+ end
+
+ it 'returns 400 if group label already exists' do
+ create(:group_label, title: label1.name, group: group)
+
+ put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name }
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(json_response['message']).to eq('Failed to promote project label to group label')
+ end
+
+ it 'returns 403 if guest promotes label' do
+ guest = create(:user)
+ project.add_guest(guest)
+
+ put api("/projects/#{project.id}/labels/promote", guest), params: { name: label1.name }
+
+ expect(response).to have_gitlab_http_status(403)
end
it 'returns 404 if label does not exist' do
- post api("/projects/#{project.id}/labels/promote", user), params: { name: 'unknown' }
+ put api("/projects/#{project.id}/labels/promote", user), params: { name: 'unknown' }
expect(response).to have_gitlab_http_status(404)
end
it 'returns 400 if no label name given' do
- post api("/projects/#{project.id}/labels/promote", user)
+ put api("/projects/#{project.id}/labels/promote", user)
expect(response).to have_gitlab_http_status(400)
expect(json_response['error']).to eq('name is missing')