2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Groups::LabelsController do
|
2019-12-21 20:55:43 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
2021-01-03 14:25:43 +05:30
|
|
|
# by default FFs are enabled in specs so we turn it off
|
|
|
|
stub_feature_flags(show_inherited_labels: false)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe 'GET #index' do
|
2019-12-21 20:55:43 +05:30
|
|
|
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-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
it 'returns group and project labels by default' do
|
2019-02-15 15:39:39 +05:30
|
|
|
get :index, params: { group_id: group }, format: :json
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
label_ids = json_response.map {|label| label['title']}
|
|
|
|
expect(label_ids).to match_array([label_1.title, group_label_1.title])
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
context 'with ancestor group' do
|
2019-12-21 20:55:43 +05:30
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
let_it_be(:subgroup_label_1) { create(:group_label, group: subgroup, title: 'subgroup_label_1') }
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(user)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
RSpec.shared_examples 'returns ancestor group labels' do
|
|
|
|
it 'returns ancestor group labels' do
|
|
|
|
get :index, params: params, format: :json
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
label_ids = json_response.map {|label| label['title']}
|
|
|
|
expect(label_ids).to match_array([group_label_1.title, subgroup_label_1.title])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when include_ancestor_groups true' do
|
|
|
|
let(:params) { { group_id: subgroup, include_ancestor_groups: true, only_group_labels: true } }
|
|
|
|
|
|
|
|
it_behaves_like 'returns ancestor group labels'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when include_ancestor_groups false' do
|
|
|
|
let(:params) { { group_id: subgroup, only_group_labels: true } }
|
|
|
|
|
|
|
|
it 'does not return ancestor group labels', :aggregate_failures do
|
|
|
|
get :index, params: params, format: :json
|
|
|
|
|
|
|
|
label_ids = json_response.map {|label| label['title']}
|
|
|
|
expect(label_ids).to match_array([subgroup_label_1.title])
|
|
|
|
expect(label_ids).not_to include([group_label_1.title])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when show_inherited_labels enabled' do
|
|
|
|
let(:params) { { group_id: subgroup } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(show_inherited_labels: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'returns ancestor group labels'
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
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-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'POST #toggle_subscription' do
|
|
|
|
it 'allows user to toggle subscription on group labels' do
|
|
|
|
label = create(:group_label, group: group)
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
post :toggle_subscription, params: { group_id: group.to_param, id: label.to_param }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
describe 'DELETE #destroy' do
|
|
|
|
context 'when current user has ability to destroy the label' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes the label' do
|
|
|
|
label = create(:group_label, group: group)
|
|
|
|
delete :destroy, params: { group_id: group.to_param, id: label.to_param }
|
|
|
|
|
|
|
|
expect { label.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when label is succesfuly destroyed' do
|
|
|
|
it 'redirects to the group labels page' do
|
|
|
|
label = create(:group_label, group: group)
|
|
|
|
delete :destroy, params: { group_id: group.to_param, id: label.to_param }
|
|
|
|
|
|
|
|
expect(response).to redirect_to(group_labels_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when current_user does not have ability to destroy the label' do
|
|
|
|
let(:another_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(another_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds with status 404' do
|
|
|
|
label = create(:group_label, group: group)
|
|
|
|
delete :destroy, params: { group_id: group.to_param, id: label.to_param }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|