summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/group_labels_spec.rb80
-rw-r--r--spec/requests/api/groups_spec.rb23
-rw-r--r--spec/requests/api/labels_spec.rb46
3 files changed, 124 insertions, 25 deletions
diff --git a/spec/requests/api/group_labels_spec.rb b/spec/requests/api/group_labels_spec.rb
index 0be4e2e9121..3ac394b57c5 100644
--- a/spec/requests/api/group_labels_spec.rb
+++ b/spec/requests/api/group_labels_spec.rb
@@ -5,9 +5,11 @@ require 'spec_helper'
describe API::GroupLabels do
let(:user) { create(:user) }
let(:group) { create(:group) }
+ let(:subgroup) { create(:group, parent: group) }
let!(:group_member) { create(:group_member, group: group, user: user) }
- let!(:label1) { create(:group_label, title: 'feature', group: group) }
- let!(:label2) { create(:group_label, title: 'bug', group: group) }
+ let!(:group_label1) { create(:group_label, title: 'feature', group: group) }
+ let!(:group_label2) { create(:group_label, title: 'bug', group: group) }
+ let!(:subgroup_label) { create(:group_label, title: 'support', group: subgroup) }
describe 'GET :id/labels' do
it 'returns all available labels for the group' do
@@ -35,6 +37,34 @@ describe API::GroupLabels do
end
end
+ describe 'GET :subgroup_id/labels' do
+ context 'when the include_ancestor_groups parameter is not set' do
+ it 'returns all available labels for the group and ancestor groups' do
+ get api("/groups/#{subgroup.id}/labels", user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response).to all(match_schema('public_api/v4/labels/label'))
+ expect(json_response.size).to eq(3)
+ expect(json_response.map {|r| r['name'] }).to contain_exactly('feature', 'bug', 'support')
+ end
+ end
+
+ context 'when the include_ancestor_groups parameter is set to false' do
+ it 'returns all available labels for the group but not for ancestor groups' do
+ get api("/groups/#{subgroup.id}/labels", user), params: { include_ancestor_groups: false }
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response).to all(match_schema('public_api/v4/labels/label'))
+ expect(json_response.size).to eq(1)
+ expect(json_response.map {|r| r['name'] }).to contain_exactly('support')
+ end
+ end
+ end
+
describe 'POST /groups/:id/labels' do
it 'returns created label when all params are given' do
post api("/groups/#{group.id}/labels", user),
@@ -78,7 +108,7 @@ describe API::GroupLabels do
it 'returns 409 if label already exists' do
post api("/groups/#{group.id}/labels", user),
params: {
- name: label1.name,
+ name: group_label1.name,
color: '#FFAABB'
}
@@ -89,13 +119,13 @@ describe API::GroupLabels do
describe 'DELETE /groups/:id/labels' do
it 'returns 204 for existing label' do
- delete api("/groups/#{group.id}/labels", user), params: { name: label1.name }
+ delete api("/groups/#{group.id}/labels", user), params: { name: group_label1.name }
expect(response).to have_gitlab_http_status(204)
end
it 'returns 404 for non existing label' do
- delete api("/groups/#{group.id}/labels", user), params: { name: 'label2' }
+ delete api("/groups/#{group.id}/labels", user), params: { name: 'not_exists' }
expect(response).to have_gitlab_http_status(404)
expect(json_response['message']).to eq('404 Label Not Found')
@@ -115,12 +145,12 @@ describe API::GroupLabels do
expect(response).to have_gitlab_http_status(204)
expect(subgroup.labels.size).to eq(0)
- expect(group.labels).to include(label1)
+ expect(group.labels).to include(group_label1)
end
it_behaves_like '412 response' do
let(:request) { api("/groups/#{group.id}/labels", user) }
- let(:params) { { name: label1.name } }
+ let(:params) { { name: group_label1.name } }
end
end
@@ -128,7 +158,7 @@ describe API::GroupLabels do
it 'returns 200 if name and colors and description are changed' do
put api("/groups/#{group.id}/labels", user),
params: {
- name: label1.name,
+ name: group_label1.name,
new_name: 'New Label',
color: '#FFFFFF',
description: 'test'
@@ -152,13 +182,13 @@ describe API::GroupLabels do
expect(response).to have_gitlab_http_status(200)
expect(subgroup.labels[0].name).to eq('New Label')
- expect(label1.name).to eq('feature')
+ expect(group_label1.name).to eq('feature')
end
it 'returns 404 if label does not exist' do
put api("/groups/#{group.id}/labels", user),
params: {
- name: 'label2',
+ name: 'not_exists',
new_name: 'label3'
}
@@ -166,14 +196,14 @@ describe API::GroupLabels do
end
it 'returns 400 if no label name given' do
- put api("/groups/#{group.id}/labels", user), params: { new_name: label1.name }
+ put api("/groups/#{group.id}/labels", user), params: { new_name: group_label1.name }
expect(response).to have_gitlab_http_status(400)
expect(json_response['error']).to eq('name is missing')
end
it 'returns 400 if no new parameters given' do
- put api("/groups/#{group.id}/labels", user), params: { name: label1.name }
+ put api("/groups/#{group.id}/labels", user), params: { name: group_label1.name }
expect(response).to have_gitlab_http_status(400)
expect(json_response['error']).to eq('new_name, color, description are missing, '\
@@ -184,31 +214,31 @@ describe API::GroupLabels do
describe 'POST /groups/:id/labels/:label_id/subscribe' do
context 'when label_id is a label title' do
it 'subscribes to the label' do
- post api("/groups/#{group.id}/labels/#{label1.title}/subscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.title}/subscribe", user)
expect(response).to have_gitlab_http_status(201)
- expect(json_response['name']).to eq(label1.title)
+ expect(json_response['name']).to eq(group_label1.title)
expect(json_response['subscribed']).to be_truthy
end
end
context 'when label_id is a label ID' do
it 'subscribes to the label' do
- post api("/groups/#{group.id}/labels/#{label1.id}/subscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.id}/subscribe", user)
expect(response).to have_gitlab_http_status(201)
- expect(json_response['name']).to eq(label1.title)
+ expect(json_response['name']).to eq(group_label1.title)
expect(json_response['subscribed']).to be_truthy
end
end
context 'when user is already subscribed to label' do
before do
- label1.subscribe(user)
+ group_label1.subscribe(user)
end
it 'returns 304' do
- post api("/groups/#{group.id}/labels/#{label1.id}/subscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.id}/subscribe", user)
expect(response).to have_gitlab_http_status(304)
end
@@ -225,36 +255,36 @@ describe API::GroupLabels do
describe 'POST /groups/:id/labels/:label_id/unsubscribe' do
before do
- label1.subscribe(user)
+ group_label1.subscribe(user)
end
context 'when label_id is a label title' do
it 'unsubscribes from the label' do
- post api("/groups/#{group.id}/labels/#{label1.title}/unsubscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.title}/unsubscribe", user)
expect(response).to have_gitlab_http_status(201)
- expect(json_response['name']).to eq(label1.title)
+ expect(json_response['name']).to eq(group_label1.title)
expect(json_response['subscribed']).to be_falsey
end
end
context 'when label_id is a label ID' do
it 'unsubscribes from the label' do
- post api("/groups/#{group.id}/labels/#{label1.id}/unsubscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.id}/unsubscribe", user)
expect(response).to have_gitlab_http_status(201)
- expect(json_response['name']).to eq(label1.title)
+ expect(json_response['name']).to eq(group_label1.title)
expect(json_response['subscribed']).to be_falsey
end
end
context 'when user is already unsubscribed from label' do
before do
- label1.unsubscribe(user)
+ group_label1.unsubscribe(user)
end
it 'returns 304' do
- post api("/groups/#{group.id}/labels/#{label1.id}/unsubscribe", user)
+ post api("/groups/#{group.id}/labels/#{group_label1.id}/unsubscribe", user)
expect(response).to have_gitlab_http_status(304)
end
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index b3acf531ccb..ec587a28f4f 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -497,6 +497,29 @@ describe API::Groups do
expect(response).to have_gitlab_http_status(404)
end
+
+ context 'within a subgroup' do
+ let(:group3) { create(:group, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
+ let!(:subgroup) { create(:group, parent: group3, visibility_level: Gitlab::VisibilityLevel::PUBLIC) }
+
+ before do
+ group3.add_owner(user3)
+ end
+
+ it 'does not change visibility when not requested' do
+ put api("/groups/#{group3.id}", user3), params: { description: 'Bug #23083' }
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(json_response['visibility']).to eq('public')
+ end
+
+ it 'prevents making private a group containing public subgroups' do
+ put api("/groups/#{group3.id}", user3), params: { visibility: 'private' }
+
+ expect(response).to have_gitlab_http_status(400)
+ expect(json_response['message']['visibility_level']).to contain_exactly('private is not allowed since there are sub-groups with higher visibility.')
+ end
+ end
end
context 'when authenticated as the admin' do
diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb
index 9aef67e28a7..4f8233a9110 100644
--- a/spec/requests/api/labels_spec.rb
+++ b/spec/requests/api/labels_spec.rb
@@ -256,6 +256,52 @@ describe API::Labels do
'is_project_label' => true)
end
end
+
+ context 'when the include_ancestor_groups parameter is not set' do
+ let(:group) { create(:group) }
+ let!(:group_label) { create(:group_label, title: 'feature', group: group) }
+ let(:subgroup) { create(:group, parent: group) }
+ let!(:subgroup_label) { create(:group_label, title: 'support', group: subgroup) }
+
+ before do
+ subgroup.add_owner(user)
+ project.update!(group: subgroup)
+ end
+
+ it 'returns all available labels for the project, parent group and ancestor groups' do
+ get api("/projects/#{project.id}/labels", user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response).to all(match_schema('public_api/v4/labels/label'))
+ expect(json_response.size).to eq(4)
+ expect(json_response.map {|r| r['name'] }).to contain_exactly(group_label.name, subgroup_label.name, priority_label.name, label1.name)
+ end
+ end
+
+ context 'when the include_ancestor_groups parameter is set to false' do
+ let(:group) { create(:group) }
+ let!(:group_label) { create(:group_label, title: 'feature', group: group) }
+ let(:subgroup) { create(:group, parent: group) }
+ let!(:subgroup_label) { create(:group_label, title: 'support', group: subgroup) }
+
+ before do
+ subgroup.add_owner(user)
+ project.update!(group: subgroup)
+ end
+
+ it 'returns all available labels for the project and the parent group only' do
+ get api("/projects/#{project.id}/labels", user), params: { include_ancestor_groups: false }
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response).to all(match_schema('public_api/v4/labels/label'))
+ expect(json_response.size).to eq(3)
+ expect(json_response.map {|r| r['name'] }).to contain_exactly(subgroup_label.name, priority_label.name, label1.name)
+ end
+ end
end
describe 'POST /projects/:id/labels' do