2015-09-11 14:41:01 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe ExternalIssue, models: true do
|
2015-09-11 14:41:01 +05:30
|
|
|
let(:project) { double('project', to_reference: 'namespace1/project1') }
|
|
|
|
let(:issue) { described_class.new('EXT-1234', project) }
|
|
|
|
|
|
|
|
describe 'modules' do
|
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
it { is_expected.to include_module(Referable) }
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '.reference_pattern' do
|
|
|
|
it 'allows underscores in the project name' do
|
|
|
|
expect(ExternalIssue.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows numbers in the project name' do
|
|
|
|
expect(ExternalIssue.reference_pattern.match('EXT3_EXT-1234')[0]).to eq 'EXT3_EXT-1234'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'requires the project name to begin with A-Z' do
|
|
|
|
expect(ExternalIssue.reference_pattern.match('3EXT_EXT-1234')).to eq nil
|
|
|
|
expect(ExternalIssue.reference_pattern.match('EXT_EXT-1234')[0]).to eq 'EXT_EXT-1234'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
describe '#to_reference' do
|
|
|
|
it 'returns a String reference to the object' do
|
|
|
|
expect(issue.to_reference).to eq issue.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#title' do
|
|
|
|
it 'returns a title' do
|
|
|
|
expect(issue.title).to eq "External Issue #{issue}"
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
describe '#reference_link_text' do
|
|
|
|
context 'if issue id has a prefix' do
|
|
|
|
it 'returns the issue ID' do
|
|
|
|
expect(issue.reference_link_text).to eq 'EXT-1234'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'if issue id is a number' do
|
|
|
|
let(:issue) { described_class.new('1234', project) }
|
|
|
|
it 'returns the issue ID prefixed by #' do
|
|
|
|
expect(issue.reference_link_text).to eq '#1234'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|