提交 a343484b 编写于 作者: K Kamil Trzciński

Merge branch 'zj-sort-templates' into 'master'

Sort templates when fetching them

Closes #37153

See merge request !13920
---
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册