Commit ffd164d2 authored by Nick Thomas's avatar Nick Thomas

Fix bugs in Gitlab::Template::Finders preventing instances from...

Fix bugs in Gitlab::Template::Finders preventing instances from BaseTemplate.all from loading content
parent 6343964b
......@@ -21,7 +21,7 @@ module Gitlab
def category_directory(category)
return @base_dir unless category.present?
@base_dir + @categories[category]
File.join(@base_dir, @categories[category])
end
class << self
......
......@@ -27,7 +27,7 @@ module Gitlab
directory = select_directory(file_name)
raise FileNotFoundError if directory.nil?
category_directory(directory) + file_name
File.join(category_directory(directory), file_name)
end
def list_files_for(dir)
......@@ -37,8 +37,8 @@ module Gitlab
entries = @repository.tree(:head, dir).entries
names = entries.map(&:name)
names.select { |f| f =~ self.class.filter_regex(@extension) }
paths = entries.map(&:path)
paths.select { |f| f =~ self.class.filter_regex(@extension) }
end
private
......@@ -47,10 +47,10 @@ module Gitlab
return [] unless @commit
# Insert root as directory
directories = ["", @categories.keys]
directories = ["", *@categories.keys]
directories.find do |category|
path = category_directory(category) + file_name
path = File.join(category_directory(category), file_name)
@repository.blob_at(@commit.id, path)
end
end
......
require 'spec_helper'
describe Gitlab::Template::Finders::RepoTemplateFinder do
set(:project) { create(:project, :repository) }
let(:categories) { { 'HTML' => 'html' } }
subject(:finder) { described_class.new(project, 'files/', '.html', categories) }
describe '#read' do
it 'returns the content of the given path' do
result = finder.read('files/html/500.html')
expect(result).to be_present
end
it 'raises an error if the path does not exist' do
expect { finder.read('does/not/exist') }.to raise_error(described_class::FileNotFoundError)
end
end
describe '#find' do
it 'returns the full path of the found template' do
result = finder.find('500')
expect(result).to eq('files/html/500.html')
end
end
describe '#list_files_for' do
it 'returns the full path of the found files' do
result = finder.list_files_for('files/html')
expect(result).to contain_exactly('files/html/500.html')
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment