Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-10-08 15:38:19 +0300
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-10-08 15:38:19 +0300
commit6d7b9cf210d72df5ba2da757b51d4c3cb31081dd (patch)
tree221d1dfed0dfae54392b12d189bdc1de12294634 /spec
parentecbcda22d31737f343d2e2e79a698cb265340940 (diff)
parent4899dfcafe55ca2935d699f85c13fc35a8e16545 (diff)
Merge branch 'Fix-pipeline-redirect' into 'master'
Redirect to the pipeline builds page when a build is canceled Closes #39161 See merge request gitlab-org/gitlab-ce!21595
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/jobs_controller_spec.rb65
1 files changed, 49 insertions, 16 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb
index 383d6c1a2a9..5c8180baf8a 100644
--- a/spec/controllers/projects/jobs_controller_spec.rb
+++ b/spec/controllers/projects/jobs_controller_spec.rb
@@ -599,35 +599,68 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
before do
project.add_developer(user)
sign_in(user)
-
- post_cancel
end
- context 'when job is cancelable' do
+ context 'when continue url is present' do
let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
- it 'redirects to the canceled job page' do
- expect(response).to have_gitlab_http_status(:found)
- expect(response).to redirect_to(namespace_project_job_path(id: job.id))
+ context 'when continue to is a safe url' do
+ let(:url) { '/test' }
+
+ before do
+ post_cancel(continue: { to: url })
+ end
+
+ it 'redirects to the continue url' do
+ expect(response).to have_gitlab_http_status(:found)
+ expect(response).to redirect_to(url)
+ end
+
+ it 'transits to canceled' do
+ expect(job.reload).to be_canceled
+ end
end
- it 'transits to canceled' do
- expect(job.reload).to be_canceled
+ context 'when continue to is not a safe url' do
+ let(:url) { 'http://example.com' }
+
+ it 'raises an error' do
+ expect { cancel_with_redirect(url) }.to raise_error
+ end
end
end
- context 'when job is not cancelable' do
- let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
+ context 'when continue url is not present' do
+ before do
+ post_cancel
+ end
- it 'returns unprocessable_entity' do
- expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ context 'when job is cancelable' do
+ let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
+
+ it 'redirects to the builds page' do
+ expect(response).to have_gitlab_http_status(:found)
+ expect(response).to redirect_to(builds_namespace_project_pipeline_path(id: pipeline.id))
+ end
+
+ it 'transits to canceled' do
+ expect(job.reload).to be_canceled
+ end
+ end
+
+ context 'when job is not cancelable' do
+ let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
+
+ it 'returns unprocessable_entity' do
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ end
end
end
- def post_cancel
- post :cancel, namespace_id: project.namespace,
- project_id: project,
- id: job.id
+ def post_cancel(additional_params = {})
+ post :cancel, { namespace_id: project.namespace,
+ project_id: project,
+ id: job.id }.merge(additional_params)
end
end