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 ...@@ -21,7 +21,7 @@ module Gitlab
def category_directory(category) def category_directory(category)
return @base_dir unless category.present? return @base_dir unless category.present?
@base_dir + @categories[category] File.join(@base_dir, @categories[category])
end end
class << self class << self
......
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
directory = select_directory(file_name) directory = select_directory(file_name)
raise FileNotFoundError if directory.nil? raise FileNotFoundError if directory.nil?
category_directory(directory) + file_name File.join(category_directory(directory), file_name)
end end
def list_files_for(dir) def list_files_for(dir)
...@@ -37,8 +37,8 @@ module Gitlab ...@@ -37,8 +37,8 @@ module Gitlab
entries = @repository.tree(:head, dir).entries entries = @repository.tree(:head, dir).entries
names = entries.map(&:name) paths = entries.map(&:path)
names.select { |f| f =~ self.class.filter_regex(@extension) } paths.select { |f| f =~ self.class.filter_regex(@extension) }
end end
private private
...@@ -47,10 +47,10 @@ module Gitlab ...@@ -47,10 +47,10 @@ module Gitlab
return [] unless @commit return [] unless @commit
# Insert root as directory # Insert root as directory
directories = ["", @categories.keys] directories = ["", *@categories.keys]
directories.find do |category| directories.find do |category|
path = category_directory(category) + file_name path = File.join(category_directory(category), file_name)
@repository.blob_at(@commit.id, path) @repository.blob_at(@commit.id, path)
end end
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