diff options
Diffstat (limited to 'spec/controllers/groups/labels_controller_spec.rb')
-rw-r--r-- | spec/controllers/groups/labels_controller_spec.rb | 79 |
1 files changed, 75 insertions, 4 deletions
diff --git a/spec/controllers/groups/labels_controller_spec.rb b/spec/controllers/groups/labels_controller_spec.rb index 20ee19b01d1..33041f1af9f 100644 --- a/spec/controllers/groups/labels_controller_spec.rb +++ b/spec/controllers/groups/labels_controller_spec.rb @@ -9,6 +9,8 @@ RSpec.describe Groups::LabelsController do before do group.add_owner(user) + # by default FFs are enabled in specs so we turn it off + stub_feature_flags(show_inherited_labels: false) sign_in(user) end @@ -32,11 +34,41 @@ RSpec.describe Groups::LabelsController do subgroup.add_owner(user) end - it 'returns ancestor group labels' do - get :index, params: { group_id: subgroup, include_ancestor_groups: true, only_group_labels: true }, format: :json + RSpec.shared_examples 'returns ancestor group labels' do + it 'returns ancestor group labels' do + get :index, params: params, format: :json - label_ids = json_response.map {|label| label['title']} - expect(label_ids).to match_array([group_label_1.title, subgroup_label_1.title]) + 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' end end @@ -56,4 +88,43 @@ RSpec.describe Groups::LabelsController do expect(response).to have_gitlab_http_status(:ok) end end + + 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 end |