blob: 6685720778abcc90f8774e24aa0aef18e36ab3f4 (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WorkItems::Type do
describe 'modules' do
it { is_expected.to include_module(CacheMarkdownField) }
end
describe 'associations' do
it { is_expected.to have_many(:work_items).with_foreign_key('work_item_type_id') }
it { is_expected.to belong_to(:namespace) }
end
describe 'scopes' do
describe 'order_by_name_asc' do
subject { described_class.order_by_name_asc.pluck(:name) }
before do
# Deletes all so we have control on the entire list of names
described_class.delete_all
create(:work_item_type, name: 'Ztype')
create(:work_item_type, name: 'atype')
create(:work_item_type, name: 'gtype')
end
it { is_expected.to match(%w[atype gtype Ztype]) }
end
end
describe '#destroy' do
let!(:work_item) { create :issue }
context 'when there are no work items of that type' do
it 'deletes type but not unrelated issues' do
type = create(:work_item_type)
expect(WorkItems::Type.count).to eq(8)
expect { type.destroy! }.not_to change(Issue, :count)
expect(WorkItems::Type.count).to eq(7)
end
end
it 'does not delete type when there are related issues' do
type = create(:work_item_type, work_items: [work_item])
expect { type.destroy! }.to raise_error(ActiveRecord::InvalidForeignKey)
expect(Issue.count).to eq(1)
end
end
describe 'validation' do
describe 'name uniqueness' do
subject { create(:work_item_type) }
it { is_expected.to validate_uniqueness_of(:name).case_insensitive.scoped_to([:namespace_id]) }
end
it { is_expected.not_to allow_value('s' * 256).for(:icon_name) }
end
describe '.available_widgets' do
subject { described_class.available_widgets }
it 'returns list of all possible widgets' do
is_expected.to include(
::WorkItems::Widgets::Description,
::WorkItems::Widgets::Hierarchy,
::WorkItems::Widgets::Labels,
::WorkItems::Widgets::Assignees,
::WorkItems::Widgets::StartAndDueDate,
::WorkItems::Widgets::Milestone
)
end
end
describe '#default?' do
subject { build(:work_item_type, namespace: namespace).default? }
context 'when namespace is nil' do
let(:namespace) { nil }
it { is_expected.to be_truthy }
end
context 'when namespace is present' do
let(:namespace) { build(:namespace) }
it { is_expected.to be_falsey }
end
end
describe '#name' do
it 'strips name' do
work_item_type = described_class.new(name: ' label😸 ')
work_item_type.valid?
expect(work_item_type.name).to eq('label😸')
end
end
end
|