diff --git a/lib/gitlab/client.rb b/lib/gitlab/client.rb index 45b473c65..ea698d31a 100644 --- a/lib/gitlab/client.rb +++ b/lib/gitlab/client.rb @@ -40,6 +40,7 @@ class Client < API include Snippets include SystemHooks include Tags + include Templates include Todos include Users include Versions diff --git a/lib/gitlab/client/projects.rb b/lib/gitlab/client/projects.rb index c208dedd3..340dcce7f 100644 --- a/lib/gitlab/client/projects.rb +++ b/lib/gitlab/client/projects.rb @@ -538,5 +538,37 @@ def user_projects(user_id, options = {}) def upload_file(id, file) post("/projects/#{url_encode id}/uploads", body: { file: file }) end + + # Get all project templates of a particular type + # @see https://docs.gitlab.com/ce/api/project_templates.html + # + # @example + # Gitlab.project_templates(1, 'dockerfiles') + # Gitlab.project_templates(1, 'licenses') + # + # @param [Integer, String] id The ID or URL-encoded path of the project. + # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template + # @return [Array] + def project_templates(project, type) + get("/projects/#{url_encode project}/templates/#{type}") + end + + # Get one project template of a particular type + # @see https://docs.gitlab.com/ce/api/project_templates.html + # + # @example + # Gitlab.project_template(1, 'dockerfiles', 'dockey') + # Gitlab.project_template(1, 'licenses', 'gpl', { project: 'some project', fullname: 'Holder Holding' }) + # + # @param [Integer, String] project The ID or URL-encoded path of the project. + # @param [String] type The type (dockerfiles|gitignores|gitlab_ci_ymls|licenses) of the template + # @param [String] key The key of the template, as obtained from the collection endpoint + # @param [Hash] options A customizable set of options. + # @option options [String] project(optional) The project name to use when expanding placeholders in the template. Only affects licenses + # @option options [String] fullname(optional) The full name of the copyright holder to use when expanding placeholders in the template. Only affects licenses + # @return [Gitlab::ObjectifiedHash] + def project_template(project, type, key, options = {}) + get("/projects/#{url_encode project}/templates/#{type}/#{key}", query: options) + end end end diff --git a/lib/gitlab/client/templates.rb b/lib/gitlab/client/templates.rb new file mode 100644 index 000000000..6fcef9d0d --- /dev/null +++ b/lib/gitlab/client/templates.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +class Gitlab::Client + # Defines methods related to templates. + # @see https://docs.gitlab.com/ce/api/templates/dockerfiles.html + # @see https://docs.gitlab.com/ce/api/templates/gitignores.html + # @see https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html + # @see https://docs.gitlab.com/ce/api/templates/licenses.html + module Templates + # Get all Dockerfile templates. + # + # @example + # Gitlab.dockerfile_templates + # + # @return [Array] + def dockerfile_templates + get('/templates/dockerfiles') + end + + # Get a single Dockerfile template. + # + # @example + # Gitlab.dockerfile_template('Binary') + # + # @param [String] key The key of the Dockerfile template + # @return [Gitlab::ObjectifiedHash] + def dockerfile_template(key) + get("/templates/dockerfiles/#{key}") + end + + # Get all gitignore templates. + # + # @example + # Gitlab.gitignore_templates + # + # @return [Array] + def gitignore_templates + get('/templates/gitignores') + end + + # Get a single gitignore template. + # + # @example + # Gitlab.gitignore_template('Ruby') + # + # @param [String] key The key of the gitignore template + # @return [Gitlab::ObjectifiedHash] + def gitignore_template(key) + get("/templates/gitignores/#{key}") + end + + # Get all `gitlab_ci.yml` templates. + # + # @example + # Gitlab.gitlab_ci_yml_templates + # + # @return [Array] + def gitlab_ci_yml_templates + get('/templates/gitlab_ci_ymls') + end + + # Get a single `gitlab_ci.yml` template. + # + # @example + # Gitlab.gitlab_ci_yml_template('Ruby') + # + # @param [String] key The key of the gitlab_ci_yml template + # @return [Gitlab::ObjectifiedHash] + def gitlab_ci_yml_template(key) + get("/templates/gitlab_ci_ymls/#{key}") + end + + # Get all license templates. + # + # @example + # Gitlab.license_templates + # Gitlab.license_templates(popular: true) + # + # @param [Hash] options A customizable set of options. + # @option options [Boolean] popular(optional) If passed, returns only popular licenses. + # @return [Array] + def license_templates(options = {}) + get('/templates/licenses', query: options) + end + + # Get a single license template. You can pass parameters to replace the license placeholder. + # + # @example + # Gitlab.license_template('Ruby') + # + # @param [String] key The key of the license template + # @param [Hash] options A customizable set of options. + # @option options [String] project(optional) The copyrighted project name. + # @option options [String] fullname(optional) The full-name of the copyright holder + # @return [Gitlab::ObjectifiedHash] + def license_template(key, options = {}) + get("/templates/licenses/#{key}", query: options) + end + end +end diff --git a/spec/fixtures/dockerfile_project_template.json b/spec/fixtures/dockerfile_project_template.json new file mode 100644 index 000000000..52baf26ac --- /dev/null +++ b/spec/fixtures/dockerfile_project_template.json @@ -0,0 +1,5 @@ +{ + "name": "Binary", + "content": "# This file is a template, and might need editing before it works on your project.\n# This Dockerfile installs a compiled binary into a bare system.\n# You must either commit your compiled binary into source control (not recommended)\n# or build the binary first as part of a CI/CD pipeline.\n\nFROM buildpack-deps:jessie\n\nWORKDIR /usr/local/bin\n\n# Change `app` to whatever your binary is called\nAdd app .\nCMD [\"./app\"]\n" +} + diff --git a/spec/fixtures/dockerfile_templates.json b/spec/fixtures/dockerfile_templates.json new file mode 100644 index 000000000..257f8d678 --- /dev/null +++ b/spec/fixtures/dockerfile_templates.json @@ -0,0 +1,70 @@ +[ + { + "key": "Binary", + "name": "Binary" + }, + { + "key": "Binary-alpine", + "name": "Binary-alpine" + }, + { + "key": "Binary-scratch", + "name": "Binary-scratch" + }, + { + "key": "Golang", + "name": "Golang" + }, + { + "key": "Golang-alpine", + "name": "Golang-alpine" + }, + { + "key": "Golang-scratch", + "name": "Golang-scratch" + }, + { + "key": "HTTPd", + "name": "HTTPd" + }, + { + "key": "Node", + "name": "Node" + }, + { + "key": "Node-alpine", + "name": "Node-alpine" + }, + { + "key": "OpenJDK", + "name": "OpenJDK" + }, + { + "key": "OpenJDK-alpine", + "name": "OpenJDK-alpine" + }, + { + "key": "PHP", + "name": "PHP" + }, + { + "key": "Python", + "name": "Python" + }, + { + "key": "Python-alpine", + "name": "Python-alpine" + }, + { + "key": "Python2", + "name": "Python2" + }, + { + "key": "Ruby", + "name": "Ruby" + }, + { + "key": "Ruby-alpine", + "name": "Ruby-alpine" + } +] diff --git a/spec/fixtures/gitignore_template.json b/spec/fixtures/gitignore_template.json new file mode 100644 index 000000000..a19637a1b --- /dev/null +++ b/spec/fixtures/gitignore_template.json @@ -0,0 +1,4 @@ +{ + "name": "Ruby", + "content": "*.gem\n*.rbc\n/.config\n/coverage/\n/InstalledFiles\n/pkg/\n/spec/reports/\n/spec/examples.txt\n/test/tmp/\n/test/version_tmp/\n/tmp/\n\n# Used by dotenv library to load environment variables.\n# .env\n\n## Specific to RubyMotion:\n.dat*\n.repl_history\nbuild/\n*.bridgesupport\nbuild-iPhoneOS/\nbuild-iPhoneSimulator/\n\n## Specific to RubyMotion (use of CocoaPods):\n#\n# We recommend against adding the Pods directory to your .gitignore. However\n# you should judge for yourself, the pros and cons are mentioned at:\n# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control\n#\n# vendor/Pods/\n\n## Documentation cache and generated files:\n/.yardoc/\n/_yardoc/\n/doc/\n/rdoc/\n\n## Environment normalization:\n/.bundle/\n/vendor/bundle\n/lib/bundler/man/\n\n# for a library or gem, you might want to ignore these files since the code is\n# intended to run in multiple environments; otherwise, check them in:\n# Gemfile.lock\n# .ruby-version\n# .ruby-gemset\n\n# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:\n.rvmrc\n" +} diff --git a/spec/fixtures/gitignore_templates.json b/spec/fixtures/gitignore_templates.json new file mode 100644 index 000000000..156b14ce1 --- /dev/null +++ b/spec/fixtures/gitignore_templates.json @@ -0,0 +1,82 @@ +[ + { + "key": "Actionscript", + "name": "Actionscript" + }, + { + "key": "Ada", + "name": "Ada" + }, + { + "key": "Agda", + "name": "Agda" + }, + { + "key": "Android", + "name": "Android" + }, + { + "key": "AppEngine", + "name": "AppEngine" + }, + { + "key": "AppceleratorTitanium", + "name": "AppceleratorTitanium" + }, + { + "key": "ArchLinuxPackages", + "name": "ArchLinuxPackages" + }, + { + "key": "Autotools", + "name": "Autotools" + }, + { + "key": "C", + "name": "C" + }, + { + "key": "C++", + "name": "C++" + }, + { + "key": "CFWheels", + "name": "CFWheels" + }, + { + "key": "CMake", + "name": "CMake" + }, + { + "key": "CUDA", + "name": "CUDA" + }, + { + "key": "CakePHP", + "name": "CakePHP" + }, + { + "key": "ChefCookbook", + "name": "ChefCookbook" + }, + { + "key": "Clojure", + "name": "Clojure" + }, + { + "key": "CodeIgniter", + "name": "CodeIgniter" + }, + { + "key": "CommonLisp", + "name": "CommonLisp" + }, + { + "key": "Composer", + "name": "Composer" + }, + { + "key": "Concrete5", + "name": "Concrete5" + } +] diff --git a/spec/fixtures/gitlab_ci_yml_template.json b/spec/fixtures/gitlab_ci_yml_template.json new file mode 100644 index 000000000..8f26cf148 --- /dev/null +++ b/spec/fixtures/gitlab_ci_yml_template.json @@ -0,0 +1,4 @@ +{ + "name": "Ruby", + "content": "# This file is a template, and might need editing before it works on your project.\n# Official language image. Look for the different tagged releases at:\n# https://hub.docker.com/r/library/ruby/tags/\nimage: \"ruby:2.3\"\n\n# Pick zero or more services to be used on all builds.\n# Only needed when using a docker container to run your tests in.\n# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-service\nservices:\n - mysql:latest\n - redis:latest\n - postgres:latest\n\nvariables:\n POSTGRES_DB: database_name\n\n# Cache gems in between builds\ncache:\n paths:\n - vendor/ruby\n\n# This is a basic example for a gem or script which doesn't use\n# services such as redis or postgres\nbefore_script:\n - ruby -v # Print out ruby version for debugging\n # Uncomment next line if your rails app needs a JS runtime:\n # - apt-get update -q && apt-get install nodejs -yqq\n - gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image\n - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby\n\n# Optional - Delete if not using `rubocop`\nrubocop:\n script:\n - rubocop\n\nrspec:\n script:\n - rspec spec\n\nrails:\n variables:\n DATABASE_URL: \"postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB\"\n script:\n - bundle exec rake db:migrate\n - bundle exec rake db:seed\n - bundle exec rake test\n" +} diff --git a/spec/fixtures/gitlab_ci_yml_templates.json b/spec/fixtures/gitlab_ci_yml_templates.json new file mode 100644 index 000000000..dee9d5f97 --- /dev/null +++ b/spec/fixtures/gitlab_ci_yml_templates.json @@ -0,0 +1,82 @@ +[ + { + "key": "Android", + "name": "Android" + }, + { + "key": "Auto-DevOps", + "name": "Auto-DevOps" + }, + { + "key": "Bash", + "name": "Bash" + }, + { + "key": "C++", + "name": "C++" + }, + { + "key": "Chef", + "name": "Chef" + }, + { + "key": "Clojure", + "name": "Clojure" + }, + { + "key": "Crystal", + "name": "Crystal" + }, + { + "key": "Django", + "name": "Django" + }, + { + "key": "Docker", + "name": "Docker" + }, + { + "key": "Elixir", + "name": "Elixir" + }, + { + "key": "Go", + "name": "Go" + }, + { + "key": "Gradle", + "name": "Gradle" + }, + { + "key": "Grails", + "name": "Grails" + }, + { + "key": "Julia", + "name": "Julia" + }, + { + "key": "LaTeX", + "name": "LaTeX" + }, + { + "key": "Laravel", + "name": "Laravel" + }, + { + "key": "Maven", + "name": "Maven" + }, + { + "key": "Mono", + "name": "Mono" + }, + { + "key": "Nodejs", + "name": "Nodejs" + }, + { + "key": "OpenShift", + "name": "OpenShift" + } +] diff --git a/spec/fixtures/license_project_template.json b/spec/fixtures/license_project_template.json new file mode 100644 index 000000000..7cf099d14 --- /dev/null +++ b/spec/fixtures/license_project_template.json @@ -0,0 +1,23 @@ +{ + "key": "mit", + "name": "MIT License", + "nickname": null, + "popular": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "https://opensource.org/licenses/MIT", + "description": "A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "liability", + "warranty" + ], + "content": "MIT License\n\nCopyright (c) 2018 [fullname]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" +} \ No newline at end of file diff --git a/spec/fixtures/license_template.json b/spec/fixtures/license_template.json new file mode 100644 index 000000000..3c56b39f0 --- /dev/null +++ b/spec/fixtures/license_template.json @@ -0,0 +1,22 @@ +{ + "key": "mit", + "name": "MIT License", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "http://opensource.org/licenses/MIT", + "description": "A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": "The MIT License (MIT)\n\nCopyright (c) 2016 John Doe\n [...]" +} diff --git a/spec/fixtures/license_templates.json b/spec/fixtures/license_templates.json new file mode 100644 index 000000000..b34d1559e --- /dev/null +++ b/spec/fixtures/license_templates.json @@ -0,0 +1,75 @@ +[ + { + "key": "apache-2.0", + "name": "Apache License 2.0", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/apache-2.0/", + "source_url": "http://www.apache.org/licenses/LICENSE-2.0.html", + "description": "A permissive license that also provides an express grant of patent rights from contributors to users.", + "conditions": [ + "include-copyright", + "document-changes" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "patent-use", + "private-use" + ], + "limitations": [ + "trademark-use", + "no-liability" + ], + "content": " Apache License\n Version 2.0, January 2004\n [...]" + }, + { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0", + "nickname": "GNU GPLv3", + "featured": true, + "html_url": "http://choosealicense.com/licenses/gpl-3.0/", + "source_url": "http://www.gnu.org/licenses/gpl-3.0.txt", + "description": "The GNU GPL is the most widely used free software license and has a strong copyleft requirement. When distributing derived works, the source code of the work must be made available under the same license.", + "conditions": [ + "include-copyright", + "document-changes", + "disclose-source", + "same-license" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "patent-use", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n [...]" + }, + { + "key": "mit", + "name": "MIT License", + "nickname": null, + "featured": true, + "html_url": "http://choosealicense.com/licenses/mit/", + "source_url": "http://opensource.org/licenses/MIT", + "description": "A permissive license that is short and to the point. It lets people do anything with your code with proper attribution and without warranty.", + "conditions": [ + "include-copyright" + ], + "permissions": [ + "commercial-use", + "modifications", + "distribution", + "private-use" + ], + "limitations": [ + "no-liability" + ], + "content": "The MIT License (MIT)\n\nCopyright (c) [year] [fullname]\n [...]" + } +] diff --git a/spec/fixtures/project_templates.json b/spec/fixtures/project_templates.json new file mode 100644 index 000000000..01d27631a --- /dev/null +++ b/spec/fixtures/project_templates.json @@ -0,0 +1,50 @@ +[ + { + "key": "epl-1.0", + "name": "Eclipse Public License 1.0" + }, + { + "key": "lgpl-3.0", + "name": "GNU Lesser General Public License v3.0" + }, + { + "key": "unlicense", + "name": "The Unlicense" + }, + { + "key": "agpl-3.0", + "name": "GNU Affero General Public License v3.0" + }, + { + "key": "gpl-3.0", + "name": "GNU General Public License v3.0" + }, + { + "key": "bsd-3-clause", + "name": "BSD 3-clause \"New\" or \"Revised\" License" + }, + { + "key": "lgpl-2.1", + "name": "GNU Lesser General Public License v2.1" + }, + { + "key": "mit", + "name": "MIT License" + }, + { + "key": "apache-2.0", + "name": "Apache License 2.0" + }, + { + "key": "bsd-2-clause", + "name": "BSD 2-clause \"Simplified\" License" + }, + { + "key": "mpl-2.0", + "name": "Mozilla Public License 2.0" + }, + { + "key": "gpl-2.0", + "name": "GNU General Public License v2.0" + } +] diff --git a/spec/gitlab/client/project_templates_spec.rb b/spec/gitlab/client/project_templates_spec.rb new file mode 100644 index 000000000..d35bea9c4 --- /dev/null +++ b/spec/gitlab/client/project_templates_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.project_templates' do + before do + stub_get('/projects/3/templates/licenses', 'project_templates') + @project_templates = Gitlab.project_templates(3, 'licenses') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses')).to have_been_made + end + + it "returns a paginated response of project's templates" do + expect(@project_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.project_template' do + context 'when dockerfiles' do + before do + stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template') + @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made + end + end + + context 'when licenses' do + before do + stub_get('/projects/3/templates/licenses/mit', 'license_project_template') + @project_template = Gitlab.project_template(3, 'licenses', 'mit') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made + end + end + end +end diff --git a/spec/gitlab/client/projects_spec.rb b/spec/gitlab/client/projects_spec.rb index 67303345d..873990062 100644 --- a/spec/gitlab/client/projects_spec.rb +++ b/spec/gitlab/client/projects_spec.rb @@ -712,4 +712,43 @@ expect(@file.markdown).to eq('[null](/uploads/f22e67e35e1bcb339058212c54bb8772/null)') end end + + describe '.project_templates' do + before do + stub_get('/projects/3/templates/licenses', 'project_templates') + @project_templates = Gitlab.project_templates(3, 'licenses') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses')).to have_been_made + end + + it "returns a paginated response of project's templates" do + expect(@project_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.project_template' do + context 'when dockerfiles' do + before do + stub_get('/projects/3/templates/dockerfiles/dock', 'dockerfile_project_template') + @project_template = Gitlab.project_template(3, 'dockerfiles', 'dock') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/dockerfiles/dock')).to have_been_made + end + end + + context 'when licenses' do + before do + stub_get('/projects/3/templates/licenses/mit', 'license_project_template') + @project_template = Gitlab.project_template(3, 'licenses', 'mit') + end + + it 'gets the correct resource' do + expect(a_get('/projects/3/templates/licenses/mit')).to have_been_made + end + end + end end diff --git a/spec/gitlab/client/templates_spec.rb b/spec/gitlab/client/templates_spec.rb new file mode 100644 index 000000000..6f16066ba --- /dev/null +++ b/spec/gitlab/client/templates_spec.rb @@ -0,0 +1,125 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Client do + describe '.dockerfile_templates' do + before do + stub_get('/templates/dockerfiles', 'dockerfile_templates') + @dockerfile_templates = Gitlab.dockerfile_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/dockerfiles')).to have_been_made + end + + it 'returns a paginated response of dockerfile templates' do + expect(@dockerfile_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.dockerfile_template' do + before do + stub_get('/templates/dockerfiles/Binary', 'dockerfile_project_template') + @dockerfile_template = Gitlab.dockerfile_template('Binary') + end + + it 'gets the correct resource' do + expect(a_get('/templates/dockerfiles/Binary')).to have_been_made + end + + it 'returns the correct information about the dockerfile template' do + expect(@dockerfile_template.name).to eq 'Binary' + end + end + + describe '.gitignore_templates' do + before do + stub_get('/templates/gitignores', 'gitignore_templates') + @gitignore_templates = Gitlab.gitignore_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitignores')).to have_been_made + end + + it 'returns a paginated response of gitignore templates' do + expect(@gitignore_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.gitignore_template' do + before do + stub_get('/templates/gitignores/Ruby', 'gitignore_template') + @gitignore_template = Gitlab.gitignore_template('Ruby') + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitignores/Ruby')).to have_been_made + end + + it 'returns the correct information about the gitignore template' do + expect(@gitignore_template.name).to eq 'Ruby' + end + end + + describe '.gitlab_ci_yml_templates' do + before do + stub_get('/templates/gitlab_ci_ymls', 'gitlab_ci_yml_templates') + @gitlab_ci_yml_templates = Gitlab.gitlab_ci_yml_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitlab_ci_ymls')).to have_been_made + end + + it 'returns a paginated response of gitlab_ci_yml templates' do + expect(@gitlab_ci_yml_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.gitlab_ci_yml_template' do + before do + stub_get('/templates/gitlab_ci_ymls/Ruby', 'gitlab_ci_yml_template') + @gitlab_ci_yml_template = Gitlab.gitlab_ci_yml_template('Ruby') + end + + it 'gets the correct resource' do + expect(a_get('/templates/gitlab_ci_ymls/Ruby')).to have_been_made + end + + it 'returns the correct information about the gitlab_ci_yml template' do + expect(@gitlab_ci_yml_template.name).to eq 'Ruby' + end + end + + describe '.license_templates' do + before do + stub_get('/templates/licenses', 'license_templates') + @license_templates = Gitlab.license_templates + end + + it 'gets the correct resource' do + expect(a_get('/templates/licenses')).to have_been_made + end + + it 'returns a paginated response of license templates' do + expect(@license_templates).to be_a Gitlab::PaginatedResponse + end + end + + describe '.license_template' do + before do + stub_get('/templates/licenses/mit', 'license_template') + @license_template = Gitlab.license_template('mit') + end + + it 'gets the correct resource' do + expect(a_get('/templates/licenses/mit')).to have_been_made + end + + it 'returns the correct information about the license template' do + expect(@license_template.key).to eq 'mit' + end + end +end