2016-06-24 15:43:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Template::IssueTemplate do
|
2017-08-09 05:31:25 -04:00
|
|
|
let(:project) { create(:project, :repository, create_templates: :issue) }
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
describe '.all' do
|
|
|
|
it 'strips the md suffix' do
|
2017-08-09 05:31:25 -04:00
|
|
|
expect(described_class.all(project).first.name).not_to end_with('.issue_template')
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'combines the globals and rest' do
|
2017-08-09 05:31:25 -04:00
|
|
|
all = described_class.all(project).map(&:name)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
expect(all).to include('bug')
|
|
|
|
expect(all).to include('feature_proposal')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.find' do
|
|
|
|
it 'returns nil if the file does not exist' do
|
2017-08-09 05:31:25 -04:00
|
|
|
expect { described_class.find('mepmep-yadida', project) }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the issue object of a valid file' do
|
2017-08-09 05:31:25 -04:00
|
|
|
ruby = described_class.find('bug', project)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
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
|
2017-08-09 05:31:25 -04:00
|
|
|
all = described_class.by_category('', project).map(&:name)
|
2016-06-24 15:43:46 -04:00
|
|
|
expect(all).to include('bug')
|
|
|
|
expect(all).to include('feature_proposal')
|
|
|
|
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
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
it "returns empty array" do
|
2017-08-09 05:31:25 -04:00
|
|
|
templates = described_class.by_category('', empty_project)
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
expect(templates).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#content' do
|
|
|
|
it 'loads the full file' do
|
2017-08-09 05:31:25 -04:00
|
|
|
issue_template = described_class.new('.gitlab/issue_templates/bug.md', project)
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
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
|
2017-08-09 05:31:25 -04:00
|
|
|
issue_template = described_class.new('.gitlab/issue_templates/bugnot.md', project)
|
2016-06-24 15:43:46 -04:00
|
|
|
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
|
|
|
|
|
|
|
it "raises file not found" do
|
2017-08-09 05:31:25 -04:00
|
|
|
issue_template = described_class.new('.gitlab/issue_templates/not_existent.md', empty_project)
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
expect { issue_template.content }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|