2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Groups::LabelsController do
|
2018-03-27 19:54:05 +05:30
|
|
|
set(:group) { create(:group) }
|
|
|
|
set(:user) { create(:user) }
|
|
|
|
set(:project) { create(:project, namespace: group) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
describe 'GET #index' do
|
|
|
|
set(:label_1) { create(:label, project: project, title: 'label_1') }
|
|
|
|
set(:group_label_1) { create(:group_label, group: group, title: 'group_label_1') }
|
|
|
|
|
|
|
|
it 'returns group and project labels by default' do
|
2019-02-13 22:33:31 +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
|
|
|
|
|
|
|
|
context 'with ancestor group', :nested_groups do
|
|
|
|
set(:subgroup) { create(:group, parent: group) }
|
|
|
|
set(:subgroup_label_1) { create(:group_label, group: subgroup, title: 'subgroup_label_1') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subgroup.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns ancestor group labels', :nested_groups do
|
2019-02-13 22:33:31 +05:30
|
|
|
get :index, params: { group_id: subgroup, include_ancestor_groups: true, only_group_labels: true }, format: :json
|
2018-03-27 19:54:05 +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
|
|
|
|
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-13 22:33:31 +05:30
|
|
|
post :toggle_subscription, params: { group_id: group.to_param, id: label.to_param }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|