2016-06-07 06:57:09 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::LabelsController do
|
2016-09-20 10:03:41 -04:00
|
|
|
let(:group) { create(:group) }
|
2016-10-28 05:31:45 -04:00
|
|
|
let(:project) { create(:empty_project, namespace: group) }
|
2016-06-07 06:57:09 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
2016-09-20 10:03:41 -04:00
|
|
|
|
2016-06-07 06:57:09 -04:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
2016-09-20 10:03:41 -04:00
|
|
|
let!(:label_1) { create(:label, project: project, priority: 1, title: 'Label 1') }
|
|
|
|
let!(:label_2) { create(:label, project: project, priority: 3, title: 'Label 2') }
|
|
|
|
let!(:label_3) { create(:label, project: project, priority: 1, title: 'Label 3') }
|
2016-10-14 19:06:26 -04:00
|
|
|
let!(:label_4) { create(:label, project: project, title: 'Label 4') }
|
|
|
|
let!(:label_5) { create(:label, project: project, title: 'Label 5') }
|
2016-06-07 06:57:09 -04:00
|
|
|
|
2016-10-14 19:06:26 -04:00
|
|
|
let!(:group_label_1) { create(:group_label, group: group, title: 'Group Label 1') }
|
|
|
|
let!(:group_label_2) { create(:group_label, group: group, title: 'Group Label 2') }
|
|
|
|
let!(:group_label_3) { create(:group_label, group: group, title: 'Group Label 3') }
|
|
|
|
let!(:group_label_4) { create(:group_label, group: group, title: 'Group Label 4') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:label_priority, project: project, label: group_label_1, priority: 3)
|
|
|
|
create(:label_priority, project: project, label: group_label_2, priority: 1)
|
|
|
|
end
|
2016-06-07 06:57:09 -04:00
|
|
|
|
|
|
|
context '@prioritized_labels' do
|
2016-09-20 10:03:41 -04:00
|
|
|
before do
|
|
|
|
list_labels
|
|
|
|
end
|
2016-06-07 06:57:09 -04:00
|
|
|
|
2016-10-14 19:06:26 -04:00
|
|
|
it 'does not include labels without priority' do
|
|
|
|
list_labels
|
|
|
|
|
|
|
|
expect(assigns(:prioritized_labels)).not_to include(group_label_3, group_label_4, label_4, label_5)
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is sorted by priority, then label title' do
|
2016-09-29 00:03:28 -04:00
|
|
|
expect(assigns(:prioritized_labels)).to eq [group_label_2, label_1, label_3, group_label_1, label_2]
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 00:03:28 -04:00
|
|
|
context '@labels' do
|
2016-10-14 19:06:26 -04:00
|
|
|
it 'is sorted by label title' do
|
2016-09-20 10:03:41 -04:00
|
|
|
list_labels
|
|
|
|
|
2016-10-14 19:06:26 -04:00
|
|
|
expect(assigns(:labels)).to eq [group_label_3, group_label_4, label_4, label_5]
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
|
|
|
|
2016-10-14 19:06:26 -04:00
|
|
|
it 'does not include labels with priority' do
|
2016-09-20 10:03:41 -04:00
|
|
|
list_labels
|
2016-06-07 06:57:09 -04:00
|
|
|
|
2016-10-14 19:06:26 -04:00
|
|
|
expect(assigns(:labels)).not_to include(group_label_2, label_1, label_3, group_label_1, label_2)
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
2016-09-20 10:03:41 -04:00
|
|
|
|
2016-09-29 00:03:28 -04:00
|
|
|
it 'does not include group labels when project does not belong to a group' do
|
2016-09-20 10:03:41 -04:00
|
|
|
project.update(namespace: create(:namespace))
|
|
|
|
|
|
|
|
list_labels
|
|
|
|
|
2016-09-29 00:03:28 -04:00
|
|
|
expect(assigns(:labels)).not_to include(group_label_3, group_label_4)
|
2016-09-20 10:03:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_labels
|
2017-02-23 18:55:01 -05:00
|
|
|
get :index, namespace_id: project.namespace.to_param, project_id: project
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
|
|
|
end
|
2016-10-22 04:59:40 -04:00
|
|
|
|
|
|
|
describe 'POST #generate' do
|
2016-10-28 05:31:45 -04:00
|
|
|
context 'personal project' do
|
2016-11-01 13:02:58 -04:00
|
|
|
let(:personal_project) { create(:empty_project, namespace: user.namespace) }
|
2016-10-22 04:59:40 -04:00
|
|
|
|
2016-10-28 05:31:45 -04:00
|
|
|
it 'creates labels' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :generate, namespace_id: personal_project.namespace.to_param, project_id: personal_project
|
2016-10-28 05:31:45 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(302)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'project belonging to a group' do
|
|
|
|
it 'creates labels' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :generate, namespace_id: project.namespace.to_param, project_id: project
|
2016-10-28 05:31:45 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(302)
|
|
|
|
end
|
2016-10-22 04:59:40 -04:00
|
|
|
end
|
|
|
|
end
|
2016-11-01 13:02:58 -04:00
|
|
|
|
|
|
|
describe 'POST #toggle_subscription' do
|
|
|
|
it 'allows user to toggle subscription on project labels' do
|
|
|
|
label = create(:label, project: project)
|
|
|
|
|
2016-11-04 14:22:57 -04:00
|
|
|
toggle_subscription(label)
|
2016-11-01 13:02:58 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows user to toggle subscription on group labels' do
|
|
|
|
group_label = create(:group_label, group: group)
|
|
|
|
|
2016-11-04 14:22:57 -04:00
|
|
|
toggle_subscription(group_label)
|
2016-11-01 13:02:58 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2016-11-04 14:22:57 -04:00
|
|
|
|
|
|
|
def toggle_subscription(label)
|
2017-02-23 18:55:01 -05:00
|
|
|
post :toggle_subscription, namespace_id: project.namespace.to_param, project_id: project, id: label.to_param
|
2016-11-04 14:22:57 -04:00
|
|
|
end
|
2016-11-01 13:02:58 -04:00
|
|
|
end
|
2016-11-02 07:58:59 -04:00
|
|
|
|
|
|
|
describe 'POST #promote' do
|
|
|
|
let!(:promoted_label_name) { "Promoted Label" }
|
|
|
|
let!(:label_1) { create(:label, title: promoted_label_name, project: project) }
|
|
|
|
|
2017-06-08 06:44:33 -04:00
|
|
|
context 'not group reporters' do
|
2016-11-02 07:58:59 -04:00
|
|
|
it 'denies access' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :promote, namespace_id: project.namespace.to_param, project_id: project, id: label_1.to_param
|
2016-11-02 07:58:59 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-08 06:44:33 -04:00
|
|
|
context 'group reporter' do
|
2016-11-02 07:58:59 -04:00
|
|
|
before do
|
2017-06-08 06:44:33 -04:00
|
|
|
group.add_reporter(user)
|
2016-11-02 07:58:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'gives access' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :promote, namespace_id: project.namespace.to_param, project_id: project, id: label_1.to_param
|
2016-11-02 07:58:59 -04:00
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_labels_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'promotes the label' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :promote, namespace_id: project.namespace.to_param, project_id: project, id: label_1.to_param
|
2016-11-02 07:58:59 -04:00
|
|
|
|
|
|
|
expect(Label.where(id: label_1.id)).to be_empty
|
|
|
|
expect(GroupLabel.find_by(title: promoted_label_name)).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'service raising InvalidRecord' do
|
|
|
|
before do
|
|
|
|
expect_any_instance_of(Labels::PromoteService).to receive(:execute) do |label|
|
|
|
|
raise ActiveRecord::RecordInvalid.new(label_1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns to label list' do
|
2017-02-23 18:55:01 -05:00
|
|
|
post :promote, namespace_id: project.namespace.to_param, project_id: project, id: label_1.to_param
|
2016-11-02 07:58:59 -04:00
|
|
|
expect(response).to redirect_to(namespace_project_labels_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-05-18 19:23:05 -04:00
|
|
|
|
|
|
|
describe '#ensure_canonical_path' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a GET request' do
|
|
|
|
context 'when requesting the canonical path' do
|
|
|
|
context 'non-show path' do
|
|
|
|
context 'with exactly matching casing' do
|
|
|
|
it 'does not redirect' do
|
|
|
|
get :index, namespace_id: project.namespace, project_id: project.to_param
|
|
|
|
|
|
|
|
expect(response).not_to have_http_status(301)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with different casing' do
|
|
|
|
it 'redirects to the correct casing' do
|
|
|
|
get :index, namespace_id: project.namespace, project_id: project.to_param.upcase
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_labels_path(project.namespace, project))
|
|
|
|
expect(controller).not_to set_flash[:notice]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting a redirected path' do
|
|
|
|
let!(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') }
|
|
|
|
|
|
|
|
it 'redirects to the canonical path' do
|
|
|
|
get :index, namespace_id: project.namespace, project_id: project.to_param + 'old'
|
|
|
|
|
|
|
|
expect(response).to redirect_to(namespace_project_labels_path(project.namespace, project))
|
|
|
|
expect(controller).to set_flash[:notice].to(project_moved_message(redirect_route, project))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for a non-GET request' do
|
|
|
|
context 'when requesting the canonical path with different casing' do
|
|
|
|
it 'does not 404' do
|
|
|
|
post :generate, namespace_id: project.namespace, project_id: project
|
|
|
|
|
|
|
|
expect(response).not_to have_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not redirect to the correct casing' do
|
|
|
|
post :generate, namespace_id: project.namespace, project_id: project
|
|
|
|
|
|
|
|
expect(response).not_to have_http_status(301)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when requesting a redirected path' do
|
|
|
|
let!(:redirect_route) { project.redirect_routes.create(path: project.full_path + 'old') }
|
|
|
|
|
|
|
|
it 'returns not found' do
|
|
|
|
post :generate, namespace_id: project.namespace, project_id: project.to_param + 'old'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_moved_message(redirect_route, project)
|
|
|
|
"Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path."
|
|
|
|
end
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|