2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 22:42:44 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-04 03:08:05 +00:00
|
|
|
RSpec.describe Groups::LabelsController do
|
2019-10-02 00:06:26 +00:00
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
2016-11-14 22:42:44 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2018-02-28 21:58:36 +00:00
|
|
|
describe 'GET #index' do
|
2019-10-02 00:06:26 +00:00
|
|
|
let_it_be(:label_1) { create(:label, project: project, title: 'label_1') }
|
|
|
|
let_it_be(:group_label_1) { create(:group_label, group: group, title: 'group_label_1') }
|
2018-02-28 21:58:36 +00:00
|
|
|
|
|
|
|
it 'returns group and project labels by default' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :index, params: { group_id: group }, format: :json
|
2018-02-28 21:58:36 +00:00
|
|
|
|
|
|
|
label_ids = json_response.map {|label| label['title']}
|
|
|
|
expect(label_ids).to match_array([label_1.title, group_label_1.title])
|
|
|
|
end
|
|
|
|
|
2019-07-24 09:20:54 +00:00
|
|
|
context 'with ancestor group' do
|
2019-10-02 00:06:26 +00:00
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
let_it_be(:subgroup_label_1) { create(:group_label, group: subgroup, title: 'subgroup_label_1') }
|
2018-02-28 21:58:36 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(user)
|
|
|
|
end
|
|
|
|
|
2019-07-24 09:20:54 +00:00
|
|
|
it 'returns ancestor group labels' do
|
2018-12-17 22:52:17 +00:00
|
|
|
get :index, params: { group_id: subgroup, include_ancestor_groups: true, only_group_labels: true }, format: :json
|
2018-02-28 21:58:36 +00:00
|
|
|
|
|
|
|
label_ids = json_response.map {|label| label['title']}
|
|
|
|
expect(label_ids).to match_array([group_label_1.title, subgroup_label_1.title])
|
|
|
|
end
|
|
|
|
end
|
2019-04-09 15:38:58 +00:00
|
|
|
|
|
|
|
context 'external authorization' do
|
|
|
|
subject { get :index, params: { group_id: group.to_param } }
|
|
|
|
|
|
|
|
it_behaves_like 'disabled when using an external authorization service'
|
|
|
|
end
|
2018-02-28 21:58:36 +00:00
|
|
|
end
|
|
|
|
|
2016-11-14 22:42:44 +00:00
|
|
|
describe 'POST #toggle_subscription' do
|
|
|
|
it 'allows user to toggle subscription on group labels' do
|
|
|
|
label = create(:group_label, group: group)
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
post :toggle_subscription, params: { group_id: group.to_param, id: label.to_param }
|
2016-11-14 22:42:44 +00:00
|
|
|
|
2020-02-06 09:09:06 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-11-14 22:42:44 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|