Commit ed8f7ed6 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Sort templates when fetching them

Used to rely on the underlying filesystem to sort the entries, now its
forced to be sorted on the name of the template.
parent 9e7e0496
---
title: Sort templates in the dropdown
merge_request:
author:
type: fixed
......@@ -18,6 +18,10 @@ module Gitlab
{ name: name, content: content }
end
def <=>(other)
name <=> other.name
end
class << self
def all(project = nil)
if categories.any?
......@@ -58,7 +62,7 @@ module Gitlab
directory = category_directory(category)
files = finder(project).list_files_for(directory)
files.map { |f| new(f, project) }
files.map { |f| new(f, project) }.sort
end
def category_directory(category)
......
......@@ -30,6 +30,14 @@ describe Gitlab::Template::GitlabCiYmlTemplate do
end
end
describe '.by_category' do
it 'returns sorted results' do
result = described_class.by_category('General')
expect(result).to eq(result.sort)
end
end
describe '#content' do
it 'loads the full file' do
gitignore = subject.new(Rails.root.join('vendor/gitlab-ci-yml/Ruby.gitlab-ci.yml'))
......@@ -38,4 +46,14 @@ describe Gitlab::Template::GitlabCiYmlTemplate do
expect(gitignore.content).to start_with('#')
end
end
describe '#<=>' do
it 'sorts lexicographically' do
one = described_class.new('a.gitlab-ci.yml')
other = described_class.new('z.gitlab-ci.yml')
expect(one.<=>(other)).to be(-1)
expect([other, one].sort).to eq([one, other])
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