summaryrefslogtreecommitdiff
path: root/spec/models/label_spec.rb
blob: 8644ac46605af0a17c6e4c43e3254a510d9f971b (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
# == 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
#

require 'spec_helper'

describe Label do
  let(:label) { create(:label) }
  it { expect(label).to be_valid }

  it { is_expected.to belong_to(:project) }

  describe 'Validation' do
    it 'should validate color code' do
      expect(build(:label, color: 'G-ITLAB')).not_to be_valid
      expect(build(:label, color: 'AABBCC')).not_to be_valid
      expect(build(:label, color: '#AABBCCEE')).not_to be_valid
      expect(build(:label, color: '#GGHHII')).not_to be_valid
      expect(build(:label, color: '#')).not_to be_valid
      expect(build(:label, color: '')).not_to be_valid

      expect(build(:label, color: '#AABBCC')).to be_valid
    end

    it 'should validate title' do
      expect(build(:label, title: 'G,ITLAB')).not_to be_valid
      expect(build(:label, title: 'G?ITLAB')).not_to be_valid
      expect(build(:label, title: 'G&ITLAB')).not_to be_valid
      expect(build(:label, title: '')).not_to be_valid

      expect(build(:label, title: 'GITLAB')).to be_valid
      expect(build(:label, title: 'gitlab')).to be_valid
    end
  end
end