Read about our upcoming Code of Conduct on this issue

label_spec.rb 2.05 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
2
3
4
5
6
7
8
9
10
11
12
# == Schema Information
#
# Table name: labels
#
#  id         :integer          not null, primary key
#  title      :string(255)
#  color      :string(255)
#  project_id :integer
#  created_at :datetime
#  updated_at :datetime
#

13
14
15
16
17
require 'spec_helper'

describe Label do
  let(:label) { create(:label) }

18
19
20
21
22
23
24
25
26
27
28
29
30
31
  describe 'associations' do
    it { is_expected.to belong_to(:project) }
    it { is_expected.to have_many(:label_links).dependent(:destroy) }
    it { is_expected.to have_many(:issues).through(:label_links).source(:target) }
  end

  describe 'modules' do
    subject { described_class }

    it { is_expected.to include_module(Referable) }
  end

  describe 'validation' do
    it { is_expected.to validate_presence_of(:project) }
jubianchi's avatar
jubianchi committed
32
33

    it 'should validate color code' do
34
35
36
37
38
39
40
41
42
      expect(label).not_to allow_value('G-ITLAB').for(:color)
      expect(label).not_to allow_value('AABBCC').for(:color)
      expect(label).not_to allow_value('#AABBCCEE').for(:color)
      expect(label).not_to allow_value('GGHHII').for(:color)
      expect(label).not_to allow_value('#').for(:color)
      expect(label).not_to allow_value('').for(:color)

      expect(label).to allow_value('#AABBCC').for(:color)
      expect(label).to allow_value('#abcdef').for(:color)
jubianchi's avatar
jubianchi committed
43
44
45
    end

    it 'should validate title' do
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
      expect(label).not_to allow_value('G,ITLAB').for(:title)
      expect(label).not_to allow_value('G?ITLAB').for(:title)
      expect(label).not_to allow_value('G&ITLAB').for(:title)
      expect(label).not_to allow_value('').for(:title)

      expect(label).to allow_value('GITLAB').for(:title)
      expect(label).to allow_value('gitlab').for(:title)
      expect(label).to allow_value("customer's request").for(:title)
    end
  end

  describe '#to_reference' do
    it 'returns a String reference to the object' do
      expect(label.to_reference).to eq "~#{label.id}"
      expect(label.to_reference(double)).to eq "~#{label.id}"
    end
jubianchi's avatar
jubianchi committed
62

63
64
    it 'returns a String reference to the object using its name' do
      expect(label.to_reference(:name)).to eq %(~"#{label.name}")
jubianchi's avatar
jubianchi committed
65
66
    end
  end
67
end