2016-08-12 14:23:00 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
feature 'Pipelines for Merge Requests', :js do
|
2017-08-04 09:01:59 +00:00
|
|
|
describe 'pipeline tab' do
|
|
|
|
given(:user) { create(:user) }
|
|
|
|
given(:merge_request) { create(:merge_request) }
|
|
|
|
given(:project) { merge_request.target_project }
|
2016-08-12 14:23:00 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
sign_in user
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
context 'with pipelines' do
|
|
|
|
let!(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline,
|
|
|
|
project: merge_request.source_project,
|
|
|
|
ref: merge_request.source_branch,
|
|
|
|
sha: merge_request.diff_head_sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-09-07 07:58:15 +00:00
|
|
|
merge_request.update_attribute(:head_pipeline_id, pipeline.id)
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user visits merge request pipelines tab' do
|
2017-09-07 07:58:15 +00:00
|
|
|
visit project_merge_request_path(project, merge_request)
|
|
|
|
|
|
|
|
expect(page.find('.ci-widget')).to have_content('pending')
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
click_link('Pipelines')
|
|
|
|
end
|
|
|
|
wait_for_requests
|
|
|
|
|
2017-08-04 11:18:05 +00:00
|
|
|
expect(page).to have_selector('.stage-cell')
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
2017-09-07 07:58:15 +00:00
|
|
|
|
|
|
|
scenario 'pipeline sha does not equal last commit sha' do
|
|
|
|
pipeline.update_attribute(:sha, '19e2e9b4ef76b422ce1154af39a91323ccc57434')
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
expect(page.find('.ci-widget')).to have_content(
|
|
|
|
'Could not connect to the CI server. Please check your settings and try again')
|
|
|
|
end
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
context 'without pipelines' do
|
|
|
|
before do
|
|
|
|
visit project_merge_request_path(project, merge_request)
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
scenario 'user visits merge request page' do
|
|
|
|
page.within('.merge-request-tabs') do
|
|
|
|
expect(page).to have_no_link('Pipelines')
|
|
|
|
end
|
|
|
|
end
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
describe 'race condition' do
|
|
|
|
given(:project) { create(:project, :repository) }
|
|
|
|
given(:user) { create(:user) }
|
|
|
|
given(:build_push_data) { { ref: 'feature', checkout_sha: TestEnv::BRANCH_SHA['feature'] } }
|
|
|
|
|
|
|
|
given(:merge_request_params) do
|
2017-08-04 12:44:19 +00:00
|
|
|
{ "source_branch" => "feature", "source_project_id" => project.id,
|
|
|
|
"target_branch" => "master", "target_project_id" => project.id, "title" => "A" }
|
2017-08-04 09:01:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
background do
|
|
|
|
project.add_master(user)
|
|
|
|
sign_in user
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
context 'when pipeline and merge request were created simultaneously' do
|
|
|
|
background do
|
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
|
|
|
|
|
|
|
threads = []
|
2017-08-04 11:18:05 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
threads << Thread.new do
|
|
|
|
@merge_request = MergeRequests::CreateService.new(project, user, merge_request_params).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
threads << Thread.new do
|
|
|
|
@pipeline = Ci::CreatePipelineService.new(project, user, build_push_data).execute(:push)
|
|
|
|
end
|
|
|
|
|
|
|
|
threads.each { |thr| thr.join }
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user sees pipeline in merge request widget' do
|
|
|
|
visit project_merge_request_path(project, @merge_request)
|
2017-08-04 11:18:05 +00:00
|
|
|
|
2017-08-04 09:01:59 +00:00
|
|
|
expect(page.find(".ci-widget")).to have_content(TestEnv::BRANCH_SHA['feature'])
|
|
|
|
expect(page.find(".ci-widget")).to have_content("##{@pipeline.id}")
|
2016-08-12 14:23:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|