blob: 1ec4fa30fb5f4a0cda1c5208f77e3bb1887d4b62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEventTag do
describe 'associations' do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:timeline_event_tag_links).class_name('IncidentManagement::TimelineEventTagLink') }
it {
is_expected.to have_many(:timeline_events)
.class_name('IncidentManagement::TimelineEvent').through(:timeline_event_tag_links)
}
end
describe 'validations' do
subject { build(:incident_management_timeline_event_tag) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_uniqueness_of(:name).scoped_to([:project_id]).ignoring_case_sensitivity }
it { is_expected.to allow_value('Test tag 1').for(:name) }
it { is_expected.not_to allow_value('Test tag, 1').for(:name) }
it { is_expected.not_to allow_value('').for(:name) }
it { is_expected.not_to allow_value('s' * 256).for(:name) }
end
describe '.pluck_names' do
it 'returns the names of the tags' do
tag1 = create(:incident_management_timeline_event_tag)
tag2 = create(:incident_management_timeline_event_tag)
expect(described_class.pluck_names).to contain_exactly(tag1.name, tag2.name)
end
end
describe 'constants' do
it { expect(described_class::START_TIME_TAG_NAME).to eq('Start time') }
it { expect(described_class::END_TIME_TAG_NAME).to eq('End time') }
end
describe '#by_names scope' do
let_it_be(:project) { create(:project) }
let_it_be(:project2) { create(:project) }
let_it_be(:tag1) { create(:incident_management_timeline_event_tag, name: 'Test tag 1', project: project) }
let_it_be(:tag2) { create(:incident_management_timeline_event_tag, name: 'Test tag 2', project: project) }
let_it_be(:tag3) { create(:incident_management_timeline_event_tag, name: 'Test tag 3', project: project2) }
it 'returns two matching tags' do
expect(described_class.by_names(['Test tag 1', 'Test tag 2'])).to contain_exactly(tag1, tag2)
end
it 'returns tags on the project' do
expect(project2.incident_management_timeline_event_tags.by_names(['Test tag 1',
'Test tag 3'])).to contain_exactly(tag3)
end
it 'returns one matching tag with case insensitive' do
expect(described_class.by_names(['tESt tAg 2'])).to contain_exactly(tag2)
end
end
end
|