blob: ac3f97e2d89e563a52ab60a496c5c8356819aa0e (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# frozen_string_literal: true
require 'spec_helper'
describe IncidentManagement::ProjectIncidentManagementSetting do
let_it_be(:project) { create(:project, :repository, create_templates: :issue) }
describe 'Associations' do
it { is_expected.to belong_to(:project) }
end
describe 'Validations' do
describe 'validate issue_template_exists' do
subject { build(:project_incident_management_setting, project: project) }
context 'with create_issue enabled' do
before do
subject.create_issue = true
end
context 'with valid issue_template_key' do
before do
subject.issue_template_key = 'bug'
end
it { is_expected.to be_valid }
end
context 'with empty issue_template_key' do
before do
subject.issue_template_key = ''
end
it { is_expected.to be_valid }
end
context 'with nil issue_template_key' do
before do
subject.issue_template_key = nil
end
it { is_expected.to be_valid }
end
context 'with invalid issue_template_key' do
before do
subject.issue_template_key = 'unknown'
end
it { is_expected.to be_invalid }
it 'returns error' do
subject.valid?
expect(subject.errors[:issue_template_key]).to eq(['not found'])
end
end
end
context 'with create_issue disabled' do
before do
subject.create_issue = false
end
context 'with unknown issue_template_key' do
before do
subject.issue_template_key = 'unknown'
end
it { is_expected.to be_valid }
end
end
end
end
describe '#issue_template_content' do
subject { build(:project_incident_management_setting, project: project) }
shared_examples 'no content' do
it 'returns no content' do
expect(subject.issue_template_content).to be_nil
end
end
context 'with valid issue_template_key' do
before do
subject.issue_template_key = 'bug'
end
it 'returns issue content' do
expect(subject.issue_template_content).to eq('something valid')
end
end
context 'with unknown issue_template_key' do
before do
subject.issue_template_key = 'unknown'
end
it_behaves_like 'no content'
end
context 'without issue_template_key' do
before do
subject.issue_template_key = nil
end
it_behaves_like 'no content'
end
end
end
|