Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-09-05 16:45:02 +0300
committerNick Thomas <nick@gitlab.com>2018-09-05 17:10:39 +0300
commitca92fcd9de5863532bd54cc1b601883c8f1ad37c (patch)
tree91803a4e24b2d278e6cc7cc5333c8c8571c67d89
parent03c733849c1fad9885b0b947e60744633b7f5bd6 (diff)
Allow the TemplateFinder to handle licenses as well
-rw-r--r--app/finders/template_finder.rb10
-rw-r--r--lib/api/templates.rb6
-rw-r--r--spec/finders/template_finder_spec.rb15
3 files changed, 28 insertions, 3 deletions
diff --git a/app/finders/template_finder.rb b/app/finders/template_finder.rb
index a9e6fc9edb3..ea0251bffb6 100644
--- a/app/finders/template_finder.rb
+++ b/app/finders/template_finder.rb
@@ -5,6 +5,16 @@ class TemplateFinder
gitlab_ci_ymls: ::Gitlab::Template::GitlabCiYmlTemplate
}.freeze
+ class << self
+ def build(type, params = {})
+ if type == :licenses
+ LicenseTemplateFinder.new(params)
+ else
+ new(type, params)
+ end
+ end
+ end
+
attr_reader :type, :params
attr_reader :vendored_templates
diff --git a/lib/api/templates.rb b/lib/api/templates.rb
index 5d817d36032..7bf0e0f5934 100644
--- a/lib/api/templates.rb
+++ b/lib/api/templates.rb
@@ -33,7 +33,7 @@ module API
popular = declared(params)[:popular]
popular = to_boolean(popular) if popular.present?
- templates = LicenseTemplateFinder.new(popular: popular).execute
+ templates = TemplateFinder.build(:licenses, popular: popular).execute
present paginate(::Kaminari.paginate_array(templates)), with: ::API::Entities::License
end
@@ -46,7 +46,7 @@ module API
requires :name, type: String, desc: 'The name of the template'
end
get "templates/licenses/:name", requirements: { name: /[\w\.-]+/ } do
- templates = LicenseTemplateFinder.new.execute
+ templates = TemplateFinder.build(:licenses).execute
template = templates.find { |template| template.key == params[:name] }
not_found!('License') unless template.present?
@@ -82,7 +82,7 @@ module API
requires :name, type: String, desc: 'The name of the template'
end
get "templates/#{template_type}/:name" do
- finder = TemplateFinder.new(template_type, name: declared(params)[:name])
+ finder = TemplateFinder.build(template_type, name: declared(params)[:name])
new_template = finder.execute
render_response(template_type, new_template)
diff --git a/spec/finders/template_finder_spec.rb b/spec/finders/template_finder_spec.rb
index 59c5427ee50..1d399e8194f 100644
--- a/spec/finders/template_finder_spec.rb
+++ b/spec/finders/template_finder_spec.rb
@@ -3,6 +3,21 @@ require 'spec_helper'
describe TemplateFinder do
using RSpec::Parameterized::TableSyntax
+ describe '#build' do
+ where(:type, :expected_class) do
+ :dockerfiles | described_class
+ :gitignores | described_class
+ :gitlab_ci_ymls | described_class
+ :licenses | ::LicenseTemplateFinder
+ end
+
+ with_them do
+ subject { described_class.build(type) }
+
+ it { is_expected.to be_a(expected_class) }
+ end
+ end
+
describe '#execute' do
where(:type, :vendored_name) do
:dockerfiles | 'Binary'