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.
This commit is contained in:
parent
9e7e0496ff
commit
ed8f7ed671
3 changed files with 28 additions and 1 deletions
5
changelogs/unreleased/zj-sort-templates.yml
Normal file
5
changelogs/unreleased/zj-sort-templates.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue