From 27bf7ae59eb95bff0254b8ad3c001ea2397ec544 Mon Sep 17 00:00:00 2001 From: ZJ van de Weg Date: Fri, 27 May 2016 11:00:56 +0200 Subject: Refactor Gitlab::Gitignores --- spec/lib/gitlab/gitignore_spec.rb | 40 ------------------------------ spec/lib/gitlab/template/gitignore_spec.rb | 40 ++++++++++++++++++++++++++++++ spec/requests/api/gitignores_spec.rb | 2 +- 3 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 spec/lib/gitlab/gitignore_spec.rb create mode 100644 spec/lib/gitlab/template/gitignore_spec.rb (limited to 'spec') diff --git a/spec/lib/gitlab/gitignore_spec.rb b/spec/lib/gitlab/gitignore_spec.rb deleted file mode 100644 index 72baa516cc4..00000000000 --- a/spec/lib/gitlab/gitignore_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Gitignore do - subject { Gitlab::Gitignore } - - describe '.all' do - it 'strips the gitignore suffix' do - expect(subject.all.first.name).not_to end_with('.gitignore') - end - - it 'combines the globals and rest' do - all = subject.all.map(&:name) - - expect(all).to include('Vim') - expect(all).to include('Ruby') - end - end - - describe '.find' do - it 'returns nil if the file does not exist' do - expect(subject.find('mepmep-yadida')).to be nil - end - - it 'returns the Gitignore object of a valid file' do - ruby = subject.find('Ruby') - - expect(ruby).to be_a Gitlab::Gitignore - expect(ruby.name).to eq('Ruby') - end - end - - describe '#content' do - it 'loads the full file' do - gitignore = subject.new(Rails.root.join('vendor/gitignore/Ruby.gitignore')) - - expect(gitignore.name).to eq 'Ruby' - expect(gitignore.content).to start_with('*.gem') - end - end -end diff --git a/spec/lib/gitlab/template/gitignore_spec.rb b/spec/lib/gitlab/template/gitignore_spec.rb new file mode 100644 index 00000000000..bc0ec9325cc --- /dev/null +++ b/spec/lib/gitlab/template/gitignore_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Gitlab::Template::Gitignore do + subject { described_class } + + describe '.all' do + it 'strips the gitignore suffix' do + expect(subject.all.first.name).not_to end_with('.gitignore') + end + + it 'combines the globals and rest' do + all = subject.all.map(&:name) + + expect(all).to include('Vim') + expect(all).to include('Ruby') + end + end + + describe '.find' do + it 'returns nil if the file does not exist' do + expect(subject.find('mepmep-yadida')).to be nil + end + + it 'returns the Gitignore object of a valid file' do + ruby = subject.find('Ruby') + + expect(ruby).to be_a Gitlab::Template::Gitignore + expect(ruby.name).to eq('Ruby') + end + end + + describe '#content' do + it 'loads the full file' do + gitignore = subject.new(Rails.root.join('vendor/gitignore/Ruby.gitignore')) + + expect(gitignore.name).to eq 'Ruby' + expect(gitignore.content).to start_with('*.gem') + end + end +end diff --git a/spec/requests/api/gitignores_spec.rb b/spec/requests/api/gitignores_spec.rb index aab2d8c81b9..9130312c057 100644 --- a/spec/requests/api/gitignores_spec.rb +++ b/spec/requests/api/gitignores_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe API::Gitignores, api: true do +describe API::Templates, api: true do include ApiHelpers describe 'Entity Gitignore' do -- cgit v1.2.1 From 620d014aefd23030ed6ae043e223ccc5dc52fc8a Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Thu, 2 Jun 2016 18:20:08 +0200 Subject: Implement backend gitlab ci dropdown This commit builds on the groundwork in ee008e300b1ec0abcc90e6a30816ec0754cea0dd, which refactored the backend so the same code could be used for new dropdowns. In this commit its used for templates for the `.gitlab-ci.yml` files. --- spec/requests/api/gitignores_spec.rb | 29 ------------------------ spec/requests/api/templates_spec.rb | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 29 deletions(-) delete mode 100644 spec/requests/api/gitignores_spec.rb create mode 100644 spec/requests/api/templates_spec.rb (limited to 'spec') diff --git a/spec/requests/api/gitignores_spec.rb b/spec/requests/api/gitignores_spec.rb deleted file mode 100644 index 9130312c057..00000000000 --- a/spec/requests/api/gitignores_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'spec_helper' - -describe API::Templates, api: true do - include ApiHelpers - - describe 'Entity Gitignore' do - before { get api('/gitignores/Ruby') } - - it { expect(json_response['name']).to eq('Ruby') } - it { expect(json_response['content']).to include('*.gem') } - end - - describe 'Entity GitignoresList' do - before { get api('/gitignores') } - - it { expect(json_response.first['name']).not_to be_nil } - it { expect(json_response.first['content']).to be_nil } - end - - describe 'GET /gitignores' do - it 'returns a list of available license templates' do - get api('/gitignores') - - expect(response.status).to eq(200) - expect(json_response).to be_an Array - expect(json_response.size).to be > 15 - end - end -end diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb new file mode 100644 index 00000000000..0e9a28b1ff6 --- /dev/null +++ b/spec/requests/api/templates_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe API::Templates, api: true do + include ApiHelpers + + describe 'the Template Entity' do + before { get api('/gitignores/Ruby') } + + it { expect(json_response['name']).to eq('Ruby') } + it { expect(json_response['content']).to include('*.gem') } + end + + describe 'the TemplateList Entity' do + before { get api('/gitignores') } + + it { expect(json_response.first['name']).not_to be_nil } + it { expect(json_response.first['content']).to be_nil } + end + + context 'requesting gitignores' do + describe 'GET /gitignores' do + it 'returns a list of available gitignore templates' do + get api('/gitignores') + + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.size).to be > 15 + end + end + end + + context 'requesting gitlab-ci-ymls' do + describe 'GET /gitlab_ci_ymls' do + it 'returns a list of available gitlab_ci_ymls' do + get api('/gitlab_ci_ymls') + + expect(response.status).to eq(200) + expect(json_response).to be_an Array + expect(json_response.first['name']).not_to be_nil + end + end + end +end -- cgit v1.2.1 From 483dc62eaac0e11717b5b103317c4441ec0ff23d Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Thu, 16 Jun 2016 15:33:11 +0200 Subject: Incorporate review --- spec/requests/api/templates_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/requests/api/templates_spec.rb b/spec/requests/api/templates_spec.rb index 0e9a28b1ff6..a6d5ade3013 100644 --- a/spec/requests/api/templates_spec.rb +++ b/spec/requests/api/templates_spec.rb @@ -40,4 +40,13 @@ describe API::Templates, api: true do end end end + + describe 'GET /gitlab_ci_ymls/Ruby' do + it 'adds a disclaimer on the top' do + get api('/gitlab_ci_ymls/Ruby') + + expect(response.status).to eq(200) + expect(json_response['content']).to start_with("# This file is a template,") + end + end end -- cgit v1.2.1 From a18df1d15af68be4d129412ad2a6145277ca43d3 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 16 Jun 2016 18:53:41 -0500 Subject: Add feature test for gitab CI dropdown --- .../projects/files/gitlab_ci_yml_dropdown_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 spec/features/projects/files/gitlab_ci_yml_dropdown_spec.rb (limited to 'spec') diff --git a/spec/features/projects/files/gitlab_ci_yml_dropdown_spec.rb b/spec/features/projects/files/gitlab_ci_yml_dropdown_spec.rb new file mode 100644 index 00000000000..d516e8ce55a --- /dev/null +++ b/spec/features/projects/files/gitlab_ci_yml_dropdown_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +feature 'User wants to add a .gitlab-ci.yml file', feature: true do + include WaitForAjax + + before do + user = create(:user) + project = create(:project) + project.team << [user, :master] + login_as user + visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: '.gitlab-ci.yml') + end + + scenario 'user can see .gitlab-ci.yml dropdown' do + expect(page).to have_css('.gitlab-ci-yml-selector') + end + + scenario 'user can pick a template from the dropdown', js: true do + find('.js-gitlab-ci-yml-selector').click + wait_for_ajax + within '.gitlab-ci-yml-selector' do + find('.dropdown-input-field').set('jekyll') + find('.dropdown-content li', text: 'jekyll').click + end + wait_for_ajax + + expect(page).to have_content('This file is a template, and might need editing before it works on your project') + expect(page).to have_content('jekyll build -d test') + end +end -- cgit v1.2.1