2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-13 13:57:16 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::Ci::LintsController do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
context 'with enough privileges' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { namespace_id: project.namespace, project_id: project }
|
2018-03-13 13:57:16 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'is success' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'renders show page' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'retrieves project' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(assigns(:project)).to eq(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without enough privileges' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { namespace_id: project.namespace, project_id: project }
|
2018-03-13 13:57:16 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'responds with 404' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
let(:remote_file_path) { 'https://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' }
|
|
|
|
|
|
|
|
let(:remote_file_content) do
|
|
|
|
<<~HEREDOC
|
|
|
|
before_script:
|
|
|
|
- apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
|
|
|
|
- ruby -v
|
|
|
|
- which ruby
|
|
|
|
- bundle install --jobs $(nproc) "${FLAGS[@]}"
|
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:content) do
|
|
|
|
<<~HEREDOC
|
|
|
|
include:
|
|
|
|
- #{remote_file_path}
|
|
|
|
|
|
|
|
rubocop:
|
|
|
|
script:
|
|
|
|
- bundle exec rubocop
|
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a valid gitlab-ci.yml' do
|
|
|
|
before do
|
|
|
|
WebMock.stub_request(:get, remote_file_path).to_return(body: remote_file_content)
|
|
|
|
project.add_developer(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: { namespace_id: project.namespace, project_id: project, content: content }
|
2018-03-13 13:57:16 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'is success' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'render show page' do
|
|
|
|
expect(response).to render_template :show
|
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'retrieves project' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(assigns(:project)).to eq(project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an invalid gitlab-ci.yml' do
|
|
|
|
let(:content) do
|
|
|
|
<<~HEREDOC
|
|
|
|
rubocop:
|
|
|
|
scriptt:
|
|
|
|
- bundle exec rubocop
|
|
|
|
HEREDOC
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: { namespace_id: project.namespace, project_id: project, content: content }
|
2018-03-13 13:57:16 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'assigns errors' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(assigns[:error]).to eq('jobs:rubocop config contains unknown keys: scriptt')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without enough privileges' do
|
|
|
|
before do
|
|
|
|
project.add_guest(user)
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :create, params: { namespace_id: project.namespace, project_id: project, content: content }
|
2018-03-13 13:57:16 -04:00
|
|
|
end
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'responds with 404' do
|
2018-03-13 13:57:16 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|