Commit a343484b authored by Kamil Trzciński's avatar Kamil Trzciński
Browse files

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 @@ def to_json
{ name: name, content: content }
end
def <=>(other)
name <=> other.name
end
class << self
def all(project = nil)
if categories.any?
......@@ -58,7 +62,7 @@ def by_category(category, project = nil)
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 @@
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 @@
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