2016-06-24 15:43:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Template::IssueTemplate do
|
|
|
|
subject { described_class }
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2016-12-08 06:11:52 -05:00
|
|
|
let(:project) do
|
|
|
|
create(:project,
|
2017-01-26 09:19:50 -05:00
|
|
|
:repository,
|
2016-12-08 06:11:52 -05:00
|
|
|
create_template: {
|
|
|
|
user: user,
|
|
|
|
access: Gitlab::Access::MASTER,
|
2017-02-22 12:44:44 -05:00
|
|
|
path: 'issue_templates'
|
|
|
|
})
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.all' do
|
|
|
|
it 'strips the md suffix' do
|
|
|
|
expect(subject.all(project).first.name).not_to end_with('.issue_template')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'combines the globals and rest' do
|
|
|
|
all = subject.all(project).map(&:name)
|
|
|
|
|
|
|
|
expect(all).to include('bug')
|
|
|
|
expect(all).to include('feature_proposal')
|
|
|
|
expect(all).to include('template_test')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.find' do
|
|
|
|
it 'returns nil if the file does not exist' do
|
|
|
|
expect { subject.find('mepmep-yadida', project) }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the issue object of a valid file' do
|
|
|
|
ruby = subject.find('bug', project)
|
|
|
|
|
2017-05-01 11:13:33 -04:00
|
|
|
expect(ruby).to be_a described_class
|
2016-06-24 15:43:46 -04:00
|
|
|
expect(ruby.name).to eq('bug')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.by_category' do
|
|
|
|
it 'return array of templates' do
|
|
|
|
all = subject.by_category('', project).map(&:name)
|
|
|
|
expect(all).to include('bug')
|
|
|
|
expect(all).to include('feature_proposal')
|
|
|
|
expect(all).to include('template_test')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when repo is bare or empty' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:empty_project) { create(:project) }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
empty_project.add_user(user, Gitlab::Access::MASTER)
|
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
it "returns empty array" do
|
|
|
|
templates = subject.by_category('', empty_project)
|
|
|
|
expect(templates).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#content' do
|
|
|
|
it 'loads the full file' do
|
|
|
|
issue_template = subject.new('.gitlab/issue_templates/bug.md', project)
|
|
|
|
|
|
|
|
expect(issue_template.name).to eq 'bug'
|
|
|
|
expect(issue_template.content).to eq('something valid')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises error when file is not found' do
|
|
|
|
issue_template = subject.new('.gitlab/issue_templates/bugnot.md', project)
|
|
|
|
expect { issue_template.content }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when repo is empty" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:empty_project) { create(:project) }
|
2016-06-24 15:43:46 -04:00
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
empty_project.add_user(user, Gitlab::Access::MASTER)
|
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
it "raises file not found" do
|
|
|
|
issue_template = subject.new('.gitlab/issue_templates/not_existent.md', empty_project)
|
|
|
|
expect { issue_template.content }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|