diff options
Diffstat (limited to 'spec/controllers/projects/pipelines_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/pipelines_controller_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 71bb256cee9..3ddfdd478a3 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -10,6 +10,7 @@ describe Projects::PipelinesController do let(:feature) { ProjectFeature::ENABLED } before do + allow(Sidekiq.logger).to receive(:info) stub_not_protect_default_branch project.add_developer(user) project.project_feature.update(builds_access_level: feature) @@ -583,6 +584,71 @@ describe Projects::PipelinesController do end end + describe 'POST create' do + let(:project) { create(:project, :public, :repository) } + + before do + project.add_developer(user) + project.project_feature.update(builds_access_level: feature) + end + + context 'with a valid .gitlab-ci.yml file' do + before do + stub_ci_pipeline_yaml_file(YAML.dump({ + test: { + stage: 'test', + script: 'echo' + } + })) + end + + shared_examples 'creates a pipeline' do + it do + expect { post_request }.to change { project.ci_pipelines.count }.by(1) + + pipeline = project.ci_pipelines.last + expected_redirect_path = Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline) + expect(pipeline).to be_pending + expect(response).to redirect_to(expected_redirect_path) + end + end + + it_behaves_like 'creates a pipeline' + + context 'when latest commit contains [ci skip]' do + before do + project.repository.create_file(user, 'new-file.txt', 'A new file', + message: '[skip ci] This is a test', + branch_name: 'master') + end + + it_behaves_like 'creates a pipeline' + end + end + + context 'with an invalid .gitlab-ci.yml file' do + before do + stub_ci_pipeline_yaml_file('invalid yaml file') + end + + it 'does not persist a pipeline' do + expect { post_request }.not_to change { project.ci_pipelines.count } + + expect(response).to have_gitlab_http_status(:ok) + end + end + + def post_request + post :create, params: { + namespace_id: project.namespace, + project_id: project, + pipeline: { + ref: 'master' + } + } + end + end + describe 'POST retry.json' do let!(:pipeline) { create(:ci_pipeline, :failed, project: project) } let!(:build) { create(:ci_build, :failed, pipeline: pipeline) } |