diff options
Diffstat (limited to 'spec/controllers/projects/jobs_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/jobs_controller_spec.rb | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index e9e7c3c3bb3..06c29e767ad 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -755,23 +755,52 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do before do project.add_developer(user) sign_in(user) - - post_retry end context 'when job is retryable' do let(:job) { create(:ci_build, :retryable, pipeline: pipeline) } it 'redirects to the retried job page' do + post_retry + expect(response).to have_gitlab_http_status(:found) expect(response).to redirect_to(namespace_project_job_path(id: Ci::Build.last.id)) end + + shared_examples_for 'retried job has the same attributes' do + it 'creates a new build has the same attributes from the previous build' do + expect { post_retry }.to change { Ci::Build.count }.by(1) + + retried_build = Ci::Build.last + + Ci::RetryBuildService.clone_accessors.each do |accessor| + expect(job.read_attribute(accessor)) + .to eq(retried_build.read_attribute(accessor)), + "Mismatched attribute on \"#{accessor}\". " \ + "It was \"#{job.read_attribute(accessor)}\" but changed to \"#{retried_build.read_attribute(accessor)}\"" + end + end + end + + context 'with branch pipeline' do + let!(:job) { create(:ci_build, :retryable, tag: true, when: 'on_success', pipeline: pipeline) } + + it_behaves_like 'retried job has the same attributes' + end + + context 'with tag pipeline' do + let!(:job) { create(:ci_build, :retryable, tag: false, when: 'on_success', pipeline: pipeline) } + + it_behaves_like 'retried job has the same attributes' + end end context 'when job is not retryable' do let(:job) { create(:ci_build, pipeline: pipeline) } it 'renders unprocessable_entity' do + post_retry + expect(response).to have_gitlab_http_status(:unprocessable_entity) end end |