debian-mirror-gitlab/spec/lib/gitlab/template/merge_request_template_spec.rb

76 lines
2.3 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
describe Gitlab::Template::MergeRequestTemplate do
2018-03-17 18:26:18 +05:30
let(:project) { create(:project, :repository, create_templates: :merge_request) }
2016-09-13 17:45:13 +05:30
describe '.all' do
it 'strips the md suffix' do
2018-03-17 18:26:18 +05:30
expect(described_class.all(project).first.name).not_to end_with('.issue_template')
2016-09-13 17:45:13 +05:30
end
it 'combines the globals and rest' do
2018-03-17 18:26:18 +05:30
all = described_class.all(project).map(&:name)
2016-09-13 17:45:13 +05:30
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
2018-03-17 18:26:18 +05:30
expect { described_class.find('mepmep-yadida', project) }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
2016-09-13 17:45:13 +05:30
end
it 'returns the merge request object of a valid file' do
2018-03-17 18:26:18 +05:30
ruby = described_class.find('bug', project)
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
expect(ruby).to be_a described_class
2016-09-13 17:45:13 +05:30
expect(ruby.name).to eq('bug')
end
end
describe '.by_category' do
it 'return array of templates' do
2018-03-17 18:26:18 +05:30
all = described_class.by_category('', project).map(&:name)
2016-09-13 17:45:13 +05:30
expect(all).to include('bug')
expect(all).to include('feature_proposal')
end
context 'when repo is bare or empty' do
2017-09-10 17:25:29 +05:30
let(:empty_project) { create(:project) }
2016-09-13 17:45:13 +05:30
it "returns empty array" do
2018-03-17 18:26:18 +05:30
templates = described_class.by_category('', empty_project)
2016-09-13 17:45:13 +05:30
expect(templates).to be_empty
end
end
end
describe '#content' do
it 'loads the full file' do
2018-03-17 18:26:18 +05:30
issue_template = described_class.new('.gitlab/merge_request_templates/bug.md', project)
2016-09-13 17:45:13 +05:30
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
2018-03-17 18:26:18 +05:30
issue_template = described_class.new('.gitlab/merge_request_templates/bugnot.md', project)
2016-09-13 17:45:13 +05:30
expect { issue_template.content }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
end
context "when repo is empty" do
2017-09-10 17:25:29 +05:30
let(:empty_project) { create(:project) }
2016-09-13 17:45:13 +05:30
it "raises file not found" do
2018-03-17 18:26:18 +05:30
issue_template = described_class.new('.gitlab/merge_request_templates/not_existent.md', empty_project)
2016-09-13 17:45:13 +05:30
expect { issue_template.content }.to raise_error(Gitlab::Template::Finders::RepoTemplateFinder::FileNotFoundError)
end
end
end
end