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) }
|
|
|
|
let(:project) { create(: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
|
|
|
|
get :index, namespace_id: project.namespace.to_param, project_id: project.to_param
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|
|
|
|
end
|
2016-10-22 04:59:40 -04:00
|
|
|
|
|
|
|
describe 'POST #generate' do
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates labels' do
|
|
|
|
post :generate, namespace_id: project.namespace.to_param, project_id: project.to_param
|
|
|
|
|
2016-10-22 07:46:23 -04:00
|
|
|
expect(response).to have_http_status(302)
|
2016-10-22 04:59:40 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-07 06:57:09 -04:00
|
|
|
end
|