2014-07-29 14:10:15 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 09:50:51 +00:00
|
|
|
describe Label, models: true do
|
2016-09-20 20:07:56 +00:00
|
|
|
describe 'modules' do
|
|
|
|
it { is_expected.to include_module(Referable) }
|
|
|
|
it { is_expected.to include_module(Subscribable) }
|
|
|
|
end
|
2014-07-29 14:10:15 +00:00
|
|
|
|
2015-05-03 03:11:21 +00:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to have_many(:issues).through(:label_links).source(:target) }
|
2016-09-20 20:07:56 +00:00
|
|
|
it { is_expected.to have_many(:label_links).dependent(:destroy) }
|
2016-08-08 19:14:22 +00:00
|
|
|
it { is_expected.to have_many(:lists).dependent(:destroy) }
|
2016-10-14 19:12:07 +00:00
|
|
|
it { is_expected.to have_many(:priorities).class_name('LabelPriority') }
|
2015-05-03 03:11:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validation' do
|
2016-09-21 20:47:58 +00:00
|
|
|
it { is_expected.to validate_uniqueness_of(:title).scoped_to([:group_id, :project_id]) }
|
2014-08-20 10:31:16 +00:00
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'validates color code' do
|
2016-09-20 20:07:56 +00:00
|
|
|
is_expected.not_to allow_value('G-ITLAB').for(:color)
|
|
|
|
is_expected.not_to allow_value('AABBCC').for(:color)
|
|
|
|
is_expected.not_to allow_value('#AABBCCEE').for(:color)
|
|
|
|
is_expected.not_to allow_value('GGHHII').for(:color)
|
|
|
|
is_expected.not_to allow_value('#').for(:color)
|
|
|
|
is_expected.not_to allow_value('').for(:color)
|
|
|
|
|
|
|
|
is_expected.to allow_value('#AABBCC').for(:color)
|
|
|
|
is_expected.to allow_value('#abcdef').for(:color)
|
2014-08-20 10:31:16 +00:00
|
|
|
end
|
|
|
|
|
2016-08-01 15:00:44 +00:00
|
|
|
it 'validates title' do
|
2016-09-20 20:07:56 +00:00
|
|
|
is_expected.not_to allow_value('G,ITLAB').for(:title)
|
|
|
|
is_expected.not_to allow_value('').for(:title)
|
2016-08-11 07:37:09 +00:00
|
|
|
is_expected.not_to allow_value('s' * 256).for(:title)
|
2016-09-20 20:07:56 +00:00
|
|
|
|
|
|
|
is_expected.to allow_value('GITLAB').for(:title)
|
|
|
|
is_expected.to allow_value('gitlab').for(:title)
|
|
|
|
is_expected.to allow_value('G?ITLAB').for(:title)
|
|
|
|
is_expected.to allow_value('G&ITLAB').for(:title)
|
|
|
|
is_expected.to allow_value("customer's request").for(:title)
|
2016-08-11 07:37:09 +00:00
|
|
|
is_expected.to allow_value('s' * 255).for(:title)
|
2015-05-03 03:11:21 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:13 +00:00
|
|
|
describe '#title' do
|
|
|
|
it 'sanitizes title' do
|
|
|
|
label = described_class.new(title: '<b>foo & bar?</b>')
|
|
|
|
expect(label.title).to eq('foo & bar?')
|
2016-05-04 21:21:57 +00:00
|
|
|
end
|
|
|
|
end
|
2016-10-17 18:34:22 +00:00
|
|
|
|
|
|
|
describe 'priorization' do
|
|
|
|
subject(:label) { create(:label) }
|
|
|
|
|
|
|
|
let(:project) { label.project }
|
|
|
|
|
|
|
|
describe '#prioritize!' do
|
|
|
|
context 'when label is not prioritized' do
|
|
|
|
it 'creates a label priority' do
|
|
|
|
expect { label.prioritize!(project, 1) }.to change(label.priorities, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets label priority' do
|
|
|
|
label.prioritize!(project, 1)
|
|
|
|
|
|
|
|
expect(label.priorities.first.priority).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when label is prioritized' do
|
|
|
|
let!(:priority) { create(:label_priority, project: project, label: label, priority: 0) }
|
|
|
|
|
|
|
|
it 'does not create a label priority' do
|
|
|
|
expect { label.prioritize!(project, 1) }.not_to change(label.priorities, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates label priority' do
|
|
|
|
label.prioritize!(project, 1)
|
|
|
|
|
|
|
|
expect(priority.reload.priority).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#unprioritize!' do
|
|
|
|
it 'removes label priority' do
|
|
|
|
create(:label_priority, project: project, label: label, priority: 0)
|
|
|
|
|
|
|
|
expect { label.unprioritize!(project) }.to change(label.priorities, :count).by(-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#priority' do
|
|
|
|
context 'when label is not prioritized' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(label.priority(project)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when label is prioritized' do
|
|
|
|
it 'returns label priority' do
|
|
|
|
create(:label_priority, project: project, label: label, priority: 1)
|
|
|
|
|
|
|
|
expect(label.priority(project)).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-29 14:10:15 +00:00
|
|
|
end
|