Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-03 06:11:21 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-05-26 22:48:30 +0300
commitc0faf91ff23815404a95cf4510b43dcf5e331c4f (patch)
tree81769f125569dd6ea012920544ada1e8666ba4e5 /spec/models/label_spec.rb
parentb06dc74d611192744d34acda944d7ed9e554342a (diff)
Add `to_reference` for models that support references
Now there is a single source of information for which attribute a model uses to be referenced, and its special character.
Diffstat (limited to 'spec/models/label_spec.rb')
-rw-r--r--spec/models/label_spec.rb58
1 files changed, 41 insertions, 17 deletions
diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb
index 8644ac46605..a13f9ac926c 100644
--- a/spec/models/label_spec.rb
+++ b/spec/models/label_spec.rb
@@ -14,30 +14,54 @@ require 'spec_helper'
describe Label do
let(:label) { create(:label) }
- it { expect(label).to be_valid }
- it { is_expected.to belong_to(:project) }
+ 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) }
- 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
+ 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)
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(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
- expect(build(:label, title: 'GITLAB')).to be_valid
- expect(build(:label, title: 'gitlab')).to be_valid
+ it 'returns a String reference to the object using its name' do
+ expect(label.to_reference(:name)).to eq %(~"#{label.name}")
end
end
end