2016-09-19 11:04:38 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe GroupLabel do
|
2016-09-19 11:04:38 -04:00
|
|
|
describe 'relationships' do
|
|
|
|
it { is_expected.to belong_to(:group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:group) }
|
|
|
|
end
|
2016-09-28 23:21:47 -04:00
|
|
|
|
2016-10-17 15:48:46 -04:00
|
|
|
describe '#subject' do
|
|
|
|
it 'aliases group to subject' do
|
|
|
|
subject = described_class.new(group: build(:group))
|
|
|
|
|
|
|
|
expect(subject.subject).to be(subject.group)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-28 23:21:47 -04:00
|
|
|
describe '#to_reference' do
|
2016-11-09 13:21:52 -05:00
|
|
|
let(:label) { create(:group_label, title: 'feature') }
|
2016-09-28 23:21:47 -04:00
|
|
|
|
|
|
|
context 'using id' do
|
|
|
|
it 'returns a String reference to the object' do
|
|
|
|
expect(label.to_reference).to eq "~#{label.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using name' do
|
|
|
|
it 'returns a String reference to the object' do
|
|
|
|
expect(label.to_reference(format: :name)).to eq %(~"#{label.name}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses id when name contains double quote' do
|
|
|
|
label = create(:label, name: %q{"irony"})
|
|
|
|
expect(label.to_reference(format: :name)).to eq "~#{label.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-02 19:49:13 -04:00
|
|
|
context 'cross-project' do
|
|
|
|
let(:namespace) { build_stubbed(:namespace) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:source_project) { build_stubbed(:project, name: 'project-1', namespace: namespace) }
|
|
|
|
let(:target_project) { build_stubbed(:project, name: 'project-2', namespace: namespace) }
|
2016-11-02 19:49:13 -04:00
|
|
|
|
|
|
|
it 'returns a String reference to the object' do
|
2016-12-21 11:41:33 -05:00
|
|
|
expect(label.to_reference(source_project, target_project: target_project)).to eq %(project-1~#{label.id})
|
2016-11-02 19:49:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-28 23:21:47 -04:00
|
|
|
context 'using invalid format' do
|
|
|
|
it 'raises error' do
|
|
|
|
expect { label.to_reference(format: :invalid) }
|
|
|
|
.to raise_error StandardError, /Unknown format/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-19 11:04:38 -04:00
|
|
|
end
|