Commit 64e85fda authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '33149-rename-more-builds' into 'master'

Fix raw_path with the new job path, rename builds to jobs in test

Closes #33149

See merge request !11941
parents 823b17cf f5b97e80
......@@ -25,7 +25,7 @@ class BuildDetailsEntity < JobEntity
end
expose :raw_path do |build|
raw_namespace_project_build_path(project.namespace, project, build)
raw_namespace_project_job_path(project.namespace, project, build)
end
private
......
......@@ -28,7 +28,7 @@ describe Projects::JobsController do
get_index(scope: 'running')
end
it 'has only running builds' do
it 'has only running jobs' do
expect(response).to have_http_status(:ok)
expect(assigns(:builds).first.status).to eq('running')
end
......@@ -41,7 +41,7 @@ describe Projects::JobsController do
get_index(scope: 'finished')
end
it 'has only finished builds' do
it 'has only finished jobs' do
expect(response).to have_http_status(:ok)
expect(assigns(:builds).first.status).to eq('success')
end
......@@ -67,7 +67,7 @@ describe Projects::JobsController do
context 'number of queries' do
before do
Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(status, status)
create_job(status, status)
end
end
......@@ -76,7 +76,7 @@ describe Projects::JobsController do
expect(recorded.count).to be_within(5).of(7)
end
def create_build(name, status)
def create_job(name, status)
pipeline = create(:ci_pipeline, project: project)
create(:ci_build, :tags, :triggered, :artifacts,
pipeline: pipeline, name: name, status: status)
......@@ -94,21 +94,21 @@ describe Projects::JobsController do
end
describe 'GET show' do
let!(:build) { create(:ci_build, :failed, pipeline: pipeline) }
let!(:job) { create(:ci_build, :failed, pipeline: pipeline) }
context 'when requesting HTML' do
context 'when build exists' do
context 'when job exists' do
before do
get_show(id: build.id)
get_show(id: job.id)
end
it 'has a build' do
it 'has a job' do
expect(response).to have_http_status(:ok)
expect(assigns(:build).id).to eq(build.id)
expect(assigns(:build).id).to eq(job.id)
end
end
context 'when build does not exist' do
context 'when job does not exist' do
before do
get_show(id: 1234)
end
......@@ -128,12 +128,12 @@ describe Projects::JobsController do
allow_any_instance_of(Ci::Build).to receive(:merge_request).and_return(merge_request)
get_show(id: build.id, format: :json)
get_show(id: job.id, format: :json)
end
it 'exposes needed information' do
expect(response).to have_http_status(:ok)
expect(json_response['raw_path']).to match(/builds\/\d+\/raw\z/)
expect(json_response['raw_path']).to match(/jobs\/\d+\/raw\z/)
expect(json_response.dig('merge_request', 'path')).to match(/merge_requests\/\d+\z/)
expect(json_response['new_issue_path'])
.to include('/issues/new')
......@@ -155,35 +155,35 @@ describe Projects::JobsController do
get_trace
end
context 'when build has a trace' do
let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
context 'when job has a trace' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
it 'returns a trace' do
expect(response).to have_http_status(:ok)
expect(json_response['id']).to eq build.id
expect(json_response['status']).to eq build.status
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
expect(json_response['html']).to eq('BUILD TRACE')
end
end
context 'when build has no traces' do
let(:build) { create(:ci_build, pipeline: pipeline) }
context 'when job has no traces' do
let(:job) { create(:ci_build, pipeline: pipeline) }
it 'returns no traces' do
expect(response).to have_http_status(:ok)
expect(json_response['id']).to eq build.id
expect(json_response['status']).to eq build.status
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
expect(json_response['html']).to be_nil
end
end
context 'when build has a trace with ANSI sequence and Unicode' do
let(:build) { create(:ci_build, :unicode_trace, pipeline: pipeline) }
context 'when job has a trace with ANSI sequence and Unicode' do
let(:job) { create(:ci_build, :unicode_trace, pipeline: pipeline) }
it 'returns a trace with Unicode' do
expect(response).to have_http_status(:ok)
expect(json_response['id']).to eq build.id
expect(json_response['status']).to eq build.status
expect(json_response['id']).to eq job.id
expect(json_response['status']).to eq job.status
expect(json_response['html']).to include("ヾ(´༎ຶД༎ຶ`)ノ")
end
end
......@@ -191,23 +191,23 @@ describe Projects::JobsController do
def get_trace
get :trace, namespace_id: project.namespace,
project_id: project,
id: build.id,
id: job.id,
format: :json
end
end
describe 'GET status.json' do
let(:build) { create(:ci_build, pipeline: pipeline) }
let(:status) { build.detailed_status(double('user')) }
let(:job) { create(:ci_build, pipeline: pipeline) }
let(:status) { job.detailed_status(double('user')) }
before do
get :status, namespace_id: project.namespace,
project_id: project,
id: build.id,
id: job.id,
format: :json
end
it 'return a detailed build status in json' do
it 'return a detailed job status in json' do
expect(response).to have_http_status(:ok)
expect(json_response['text']).to eq status.text
expect(json_response['label']).to eq status.label
......@@ -224,17 +224,17 @@ describe Projects::JobsController do
post_retry
end
context 'when build is retryable' do
let(:build) { create(:ci_build, :retryable, pipeline: pipeline) }
context 'when job is retryable' do
let(:job) { create(:ci_build, :retryable, pipeline: pipeline) }
it 'redirects to the retried build page' do
it 'redirects to the retried job page' do
expect(response).to have_http_status(:found)
expect(response).to redirect_to(namespace_project_job_path(id: Ci::Build.last.id))
end
end
context 'when build is not retryable' do
let(:build) { create(:ci_build, pipeline: pipeline) }
context 'when job is not retryable' do
let(:job) { create(:ci_build, pipeline: pipeline) }
it 'renders unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
......@@ -244,7 +244,7 @@ describe Projects::JobsController do
def post_retry
post :retry, namespace_id: project.namespace,
project_id: project,
id: build.id
id: job.id
end
end
......@@ -260,21 +260,21 @@ describe Projects::JobsController do
post_play
end
context 'when build is playable' do
let(:build) { create(:ci_build, :playable, pipeline: pipeline) }
context 'when job is playable' do
let(:job) { create(:ci_build, :playable, pipeline: pipeline) }
it 'redirects to the played build page' do
it 'redirects to the played job page' do
expect(response).to have_http_status(:found)
expect(response).to redirect_to(namespace_project_job_path(id: build.id))
expect(response).to redirect_to(namespace_project_job_path(id: job.id))
end
it 'transits to pending' do
expect(build.reload).to be_pending
expect(job.reload).to be_pending
end
end
context 'when build is not playable' do
let(:build) { create(:ci_build, pipeline: pipeline) }
context 'when job is not playable' do
let(:job) { create(:ci_build, pipeline: pipeline) }
it 'renders unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
......@@ -284,7 +284,7 @@ describe Projects::JobsController do
def post_play
post :play, namespace_id: project.namespace,
project_id: project,
id: build.id
id: job.id
end
end
......@@ -296,21 +296,21 @@ describe Projects::JobsController do
post_cancel
end
context 'when build is cancelable' do
let(:build) { create(:ci_build, :cancelable, pipeline: pipeline) }
context 'when job is cancelable' do
let(:job) { create(:ci_build, :cancelable, pipeline: pipeline) }
it 'redirects to the canceled build page' do
it 'redirects to the canceled job page' do
expect(response).to have_http_status(:found)
expect(response).to redirect_to(namespace_project_job_path(id: build.id))
expect(response).to redirect_to(namespace_project_job_path(id: job.id))
end
it 'transits to canceled' do
expect(build.reload).to be_canceled
expect(job.reload).to be_canceled
end
end
context 'when build is not cancelable' do
let(:build) { create(:ci_build, :canceled, pipeline: pipeline) }
context 'when job is not cancelable' do
let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
it 'returns unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
......@@ -320,7 +320,7 @@ describe Projects::JobsController do
def post_cancel
post :cancel, namespace_id: project.namespace,
project_id: project,
id: build.id
id: job.id
end
end
......@@ -330,7 +330,7 @@ describe Projects::JobsController do
sign_in(user)
end
context 'when builds are cancelable' do
context 'when jobs are cancelable' do
before do
create_list(:ci_build, 2, :cancelable, pipeline: pipeline)
......@@ -347,7 +347,7 @@ describe Projects::JobsController do
end
end
context 'when builds are not cancelable' do
context 'when jobs are not cancelable' do
before do
create_list(:ci_build, 2, :canceled, pipeline: pipeline)
......@@ -374,26 +374,26 @@ describe Projects::JobsController do
post_erase
end
context 'when build is erasable' do
let(:build) { create(:ci_build, :erasable, :trace, pipeline: pipeline) }
context 'when job is erasable' do
let(:job) { create(:ci_build, :erasable, :trace, pipeline: pipeline) }
it 'redirects to the erased build page' do
it 'redirects to the erased job page' do
expect(response).to have_http_status(:found)
expect(response).to redirect_to(namespace_project_job_path(id: build.id))
expect(response).to redirect_to(namespace_project_job_path(id: job.id))
end
it 'erases artifacts' do
expect(build.artifacts_file.exists?).to be_falsey
expect(build.artifacts_metadata.exists?).to be_falsey
expect(job.artifacts_file.exists?).to be_falsey
expect(job.artifacts_metadata.exists?).to be_falsey
end
it 'erases trace' do
expect(build.trace.exist?).to be_falsey
expect(job.trace.exist?).to be_falsey
end
end
context 'when build is not erasable' do
let(:build) { create(:ci_build, :erased, pipeline: pipeline) }
context 'when job is not erasable' do
let(:job) { create(:ci_build, :erased, pipeline: pipeline) }
it 'returns unprocessable_entity' do
expect(response).to have_http_status(:unprocessable_entity)
......@@ -403,7 +403,7 @@ describe Projects::JobsController do
def post_erase
post :erase, namespace_id: project.namespace,
project_id: project,
id: build.id
id: job.id
end
end
......@@ -412,8 +412,8 @@ describe Projects::JobsController do
get_raw
end
context 'when build has a trace file' do
let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
context 'when job has a trace file' do
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
it 'send a trace file' do
expect(response).to have_http_status(:ok)
......@@ -422,8 +422,8 @@ describe Projects::JobsController do
end
end
context 'when build does not have a trace file' do
let(:build) { create(:ci_build, pipeline: pipeline) }
context 'when job does not have a trace file' do
let(:job) { create(:ci_build, pipeline: pipeline) }
it 'returns not_found' do
expect(response).to have_http_status(:not_found)
......@@ -433,7 +433,7 @@ describe Projects::JobsController do
def get_raw
post :raw, namespace_id: project.namespace,
project_id: project,
id: build.id
id: job.id
end
end
end
......@@ -8,8 +8,8 @@ feature 'Jobs', :feature do
let(:namespace) { project.namespace }
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
let(:build2) { create(:ci_build) }
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
let(:job2) { create(:ci_build) }
let(:artifacts_file) do
fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif')
......@@ -21,7 +21,7 @@ feature 'Jobs', :feature do
end
describe "GET /:project/jobs" do
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:job) { create(:ci_build, pipeline: pipeline) }
context "Pending scope" do
before do
......@@ -31,30 +31,30 @@ feature 'Jobs', :feature do
it "shows Pending tab jobs" do
expect(page).to have_link 'Cancel running'
expect(page).to have_selector('.nav-links li.active', text: 'Pending')
expect(page).to have_content build.short_sha
expect(page).to have_content build.ref
expect(page).to have_content build.name
expect(page).to have_content job.short_sha
expect(page).to have_content job.ref
expect(page).to have_content job.name
end
end
context "Running scope" do
before do
build.run!
job.run!
visit namespace_project_jobs_path(project.namespace, project, scope: :running)
end
it "shows Running tab jobs" do
expect(page).to have_selector('.nav-links li.active', text: 'Running')
expect(page).to have_link 'Cancel running'
expect(page).to have_content build.short_sha
expect(page).to have_content build.ref
expect(page).to have_content build.name
expect(page).to have_content job.short_sha
expect(page).to have_content job.ref
expect(page).to have_content job.name
end
end
context "Finished scope" do
before do
build.run!
job.run!
visit namespace_project_jobs_path(project.namespace, project, scope: :finished)
end
......@@ -73,9 +73,9 @@ feature 'Jobs', :feature do
it "shows All tab jobs" do
expect(page).to have_selector('.nav-links li.active', text: 'All')
expect(page).to have_content build.short_sha
expect(page).to have_content build.ref
expect(page).to have_content build.name
expect(page).to have_content job.short_sha
expect(page).to have_content job.ref
expect(page).to have_content job.name
expect(page).not_to have_link 'Cancel running'
end
end
......@@ -97,7 +97,7 @@ feature 'Jobs', :feature do
describe "POST /:project/jobs/:id/cancel_all" do
before do
build.run!
job.run!
visit namespace_project_jobs_path(project.namespace, project)
click_link "Cancel running"
end
......@@ -105,19 +105,19 @@ feature 'Jobs', :feature do
it 'shows all necessary content' do
expect(page).to have_selector('.nav-links li.active', text: 'All')
expect(page).to have_content 'canceled'
expect(page).to have_content build.short_sha
expect(page).to have_content build.ref
expect(page).to have_content build.name
expect(page).to have_content job.short_sha
expect(page).to have_content job.ref
expect(page).to have_content job.name
expect(page).not_to have_link 'Cancel running'
end
end
describe "GET /:project/jobs/:id" do
context "Job from project" do
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let(:job) { create(:ci_build, :success, pipeline: pipeline) }
before do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
it 'shows status name', :js do
......@@ -131,33 +131,33 @@ feature 'Jobs', :feature do
expect(page).to have_content pipeline.git_author_name
end
it 'shows active build' do
it 'shows active job' do
expect(page).to have_selector('.build-job.active')
end
end
context 'when job is not running', :js do
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
let(:job) { create(:ci_build, :success, pipeline: pipeline) }
before do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
it 'shows retry button' do
expect(page).to have_link('Retry')
end
context 'if build passed' do
context 'if job passed' do
it 'does not show New issue button' do
expect(page).not_to have_link('New issue')
end
end
context 'if build failed' do
let(:build) { create(:ci_build, :failed, pipeline: pipeline) }
context 'if job failed' do
let(:job) { create(:ci_build, :failed, pipeline: pipeline) }
before do
visit namespace_project_job_path(namespace, project, build)
visit namespace_project_job_path(namespace, project, job)
end
it 'shows New issue button' do
......@@ -165,9 +165,9 @@ feature 'Jobs', :feature do
end
it 'links to issues/new with the title and description filled in' do
button_title = "Build Failed ##{build.id}"
build_path = namespace_project_job_path(namespace, project, build)
options = { issue: { title: button_title, description: build_path } }
button_title = "Build Failed ##{job.id}"
job_path = namespace_project_job_path(namespace, project, job)
options = { issue: { title: button_title, description: job_path } }
href = new_namespace_project_issue_path(namespace, project, options)
......@@ -180,7 +180,7 @@ feature 'Jobs', :feature do
context "Job from other project" do
before do
visit namespace_project_job_path(project.namespace, project, build2)
visit namespace_project_job_path(project.namespace, project, job2)
end
it { expect(page.status_code).to eq(404) }
......@@ -188,8 +188,8 @@ feature 'Jobs', :feature do
context "Download artifacts" do
before do
build.update_attributes(artifacts_file: artifacts_file)
visit namespace_project_job_path(project.namespace, project, build)
job.update_attributes(artifacts_file: artifacts_file)
visit namespace_project_job_path(project.namespace, project, job)
end
it 'has button to download artifacts' do
......@@ -199,10 +199,10 @@ feature 'Jobs', :feature do
context 'Artifacts expire date' do
before do
build.update_attributes(artifacts_file: artifacts_file,
job.update_attributes(artifacts_file: artifacts_file,
artifacts_expire_at: expire_at)
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
context 'no expire date defined' do
......@@ -248,7 +248,7 @@ feature 'Jobs', :feature do
context "when visiting old URL" do
let(:job_url) do
namespace_project_job_path(project.namespace, project, build)
namespace_project_job_path(project.namespace, project, job)
end
before do
......@@ -262,9 +262,9 @@ feature 'Jobs', :feature do
feature 'Raw trace' do
before do
build.run!
job.run!
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
it do
......@@ -274,16 +274,16 @@ feature 'Jobs', :feature do
feature 'HTML trace', :js do
before do
build.run!
job.run!
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
context 'when job has an initial trace' do
it 'loads job trace' do
expect(page).to have_content 'BUILD TRACE'
build.trace.write do |stream|
job.trace.write do |stream|
stream.append(' and more trace', 11)
end
......@@ -295,12 +295,12 @@ feature 'Jobs', :feature do
feature 'Variables' do
let(:trigger_request) { create(:ci_trigger_request_with_variables) }
let(:build) do
let(:job) do
create :ci_build, pipeline: pipeline, trigger_request: trigger_request
end
before do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
it 'shows variable key and value after click', js: true do
......@@ -322,20 +322,20 @@ feature 'Jobs', :feature do
context 'job is successfull and has deployment' do
let(:deployment) { create(:deployment) }
let(:build) { create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) }
let(:job) { create(:ci_build, :success, environment: environment.name, deployments: [deployment], pipeline: pipeline) }
it 'shows a link for the job' do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
expect(page).to have_link environment.name
end
end
context 'job is complete and not successful' do
let(:build) { create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) }
let(:job) { create(:ci_build, :failed, environment: environment.name, pipeline: pipeline) }
it 'shows a link for the job' do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
expect(page).to have_link environment.name
end
......@@ -343,10 +343,10 @@ feature 'Jobs', :feature do
context 'job creates a new deployment' do
let!(:deployment) { create(:deployment, environment: environment, sha: project.commit.id) }
let(:build) { create(:ci_build, :success, environment: environment.name, pipeline: pipeline) }
let(:job) { create(:ci_build, :success, environment: environment.name, pipeline: pipeline) }
it 'shows a link to latest deployment' do
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
expect(page).to have_link('latest deployment')
end
......@@ -357,8 +357,8 @@ feature 'Jobs', :feature do
describe "POST /:project/jobs/:id/cancel", :js do
context "Job from project" do
before do
build.run!
visit namespace_project_job_path(project.namespace, project, build)
job.run!
visit namespace_project_job_path(project.namespace, project, job)
find('.js-cancel-job').click()
end
......@@ -372,8 +372,8 @@ feature 'Jobs', :feature do
describe "POST /:project/jobs/:id/retry" do
context "Job from project", :js do
before do
build.run!
visit namespace_project_job_path(project.namespace, project, build)
job.run!
visit namespace_project_job_path(project.namespace, project, job)
find('.js-cancel-job').click()
find('.js-retry-button').trigger('click')
end
......@@ -388,13 +388,13 @@ feature 'Jobs', :feature do
context "Job that current user is not allowed to retry" do
before do
build.run!
build.cancel!
job.run!
job.cancel!
project.update(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
logout_direct
login_with(create(:user))
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
it 'does not show the Retry button' do
......@@ -407,15 +407,15 @@ feature 'Jobs', :feature do
describe "GET /:project/jobs/:id/download" do
before do
build.update_attributes(artifacts_file: artifacts_file)
visit namespace_project_job_path(project.namespace, project, build)
job.update_attributes(artifacts_file: artifacts_file)
visit namespace_project_job_path(project.namespace, project, job)
click_link 'Download'
end
context "Build from other project" do
before do
build2.update_attributes(artifacts_file: artifacts_file)
visit download_namespace_project_job_artifacts_path(project.namespace, project, build2)
job2.update_attributes(artifacts_file: artifacts_file)
visit download_namespace_project_job_artifacts_path(project.namespace, project, job2)
end
it { expect(page.status_code).to eq(404) }
......@@ -427,23 +427,23 @@ feature 'Jobs', :feature do
context 'job from project' do
before do
Capybara.current_session.driver.headers = { 'X-Sendfile-Type' => 'X-Sendfile' }
build.run!
visit namespace_project_job_path(project.namespace, project, build)
job.run!
visit namespace_project_job_path(project.namespace, project, job)
find('.js-raw-link-controller').click()
end
it 'sends the right headers' do
expect(page.status_code).to eq(200)
expect(page.response_headers['Content-Type']).to eq('text/plain; charset=utf-8')
expect(page.response_headers['X-Sendfile']).to eq(build.trace.send(:current_path))
expect(page.response_headers['X-Sendfile']).to eq(job.trace.send(:current_path))
end
end
context 'job from other project' do
before do
Capybara.current_session.driver.headers = { 'X-Sendfile-Type' => 'X-Sendfile' }
build2.run!
visit raw_namespace_project_job_path(project.namespace, project, build2)
job2.run!
visit raw_namespace_project_job_path(project.namespace, project, job2)
end
it 'sends the right headers' do
......@@ -458,16 +458,16 @@ feature 'Jobs', :feature do
before do
Capybara.current_session.driver.headers = { 'X-Sendfile-Type' => 'X-Sendfile' }
build.run!
job.run!
end
context 'when build has trace in file', :js do
context 'when job has trace in file', :js do
before do
allow_any_instance_of(Gitlab::Ci::Trace)
.to receive(:paths)
.and_return([existing_file])
visit namespace_project_job_path(namespace, project, build)
visit namespace_project_job_path(namespace, project, job)
find('.js-raw-link-controller').click
end
......@@ -485,7 +485,7 @@ feature 'Jobs', :feature do
.to receive(:paths)
.and_return([])
visit namespace_project_job_path(namespace, project, build)
visit namespace_project_job_path(namespace, project, job)
end
it 'sends the right headers' do
......@@ -496,7 +496,7 @@ feature 'Jobs', :feature do
context "when visiting old URL" do
let(:raw_job_url) do
raw_namespace_project_job_path(project.namespace, project, build)
raw_namespace_project_job_path(project.namespace, project, job)
end
before do
......@@ -512,7 +512,7 @@ feature 'Jobs', :feature do
describe "GET /:project/jobs/:id/trace.json" do
context "Job from project" do
before do
visit trace_namespace_project_job_path(project.namespace, project, build, format: :json)
visit trace_namespace_project_job_path(project.namespace, project, job, format: :json)
end
it { expect(page.status_code).to eq(200) }
......@@ -520,7 +520,7 @@ feature 'Jobs', :feature do
context "Job from other project" do
before do
visit trace_namespace_project_job_path(project.namespace, project, build2, format: :json)
visit trace_namespace_project_job_path(project.namespace, project, job2, format: :json)
end
it { expect(page.status_code).to eq(404) }
......@@ -530,7 +530,7 @@ feature 'Jobs', :feature do
describe "GET /:project/jobs/:id/status" do
context "Job from project" do
before do
visit status_namespace_project_job_path(project.namespace, project, build)
visit status_namespace_project_job_path(project.namespace, project, job)
end
it { expect(page.status_code).to eq(200) }
......@@ -538,7 +538,7 @@ feature 'Jobs', :feature do
context "Job from other project" do
before do
visit status_namespace_project_job_path(project.namespace, project, build2)
visit status_namespace_project_job_path(project.namespace, project, job2)
end
it { expect(page.status_code).to eq(404) }
......
......@@ -11,7 +11,7 @@ describe API::Jobs, :api do
ref: project.default_branch)
end
let!(:build) { create(:ci_build, pipeline: pipeline) }
let!(:job) { create(:ci_build, pipeline: pipeline) }
let(:user) { create(:user) }
let(:api_user) { user }
......@@ -42,13 +42,13 @@ describe API::Jobs, :api do
end
it 'returns pipeline data' do
json_build = json_response.first
json_job = json_response.first
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
expect(json_job['pipeline']).not_to be_empty
expect(json_job['pipeline']['id']).to eq job.pipeline.id
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
expect(json_job['pipeline']['status']).to eq job.pipeline.status
end
context 'filter project with one scope element' do
......@@ -79,7 +79,7 @@ describe API::Jobs, :api do
context 'unauthorized user' do
let(:api_user) { nil }
it 'does not return project builds' do
it 'does not return project jobs' do
expect(response).to have_http_status(401)
end
end
......@@ -105,13 +105,13 @@ describe API::Jobs, :api do
end
it 'returns pipeline data' do
json_build = json_response.first
json_job = json_response.first
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
expect(json_job['pipeline']).not_to be_empty
expect(json_job['pipeline']['id']).to eq job.pipeline.id
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
expect(json_job['pipeline']['status']).to eq job.pipeline.status
end
context 'filter jobs with one scope element' do
......@@ -140,7 +140,7 @@ describe API::Jobs, :api do
context 'jobs in different pipelines' do
let!(:pipeline2) { create(:ci_empty_pipeline, project: project) }
let!(:build2) { create(:ci_build, pipeline: pipeline2) }
let!(:job2) { create(:ci_build, pipeline: pipeline2) }
it 'excludes jobs from other pipelines' do
json_response.each { |job| expect(job['pipeline']['id']).to eq(pipeline.id) }
......@@ -159,7 +159,7 @@ describe API::Jobs, :api do
describe 'GET /projects/:id/jobs/:job_id' do
before do
get api("/projects/#{project.id}/jobs/#{build.id}", api_user)
get api("/projects/#{project.id}/jobs/#{job.id}", api_user)
end
context 'authorized user' do
......@@ -169,12 +169,13 @@ describe API::Jobs, :api do
end
it 'returns pipeline data' do
json_build = json_response
expect(json_build['pipeline']).not_to be_empty
expect(json_build['pipeline']['id']).to eq build.pipeline.id
expect(json_build['pipeline']['ref']).to eq build.pipeline.ref
expect(json_build['pipeline']['sha']).to eq build.pipeline.sha
expect(json_build['pipeline']['status']).to eq build.pipeline.status
json_job = json_response
expect(json_job['pipeline']).not_to be_empty
expect(json_job['pipeline']['id']).to eq job.pipeline.id
expect(json_job['pipeline']['ref']).to eq job.pipeline.ref
expect(json_job['pipeline']['sha']).to eq job.pipeline.sha
expect(json_job['pipeline']['status']).to eq job.pipeline.status
end
end
......@@ -189,11 +190,11 @@ describe API::Jobs, :api do
describe 'GET /projects/:id/jobs/:job_id/artifacts' do
before do
get api("/projects/#{project.id}/jobs/#{build.id}/artifacts", api_user)
get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user)
end
context 'job with artifacts' do
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
context 'authorized user' do
let(:download_headers) do
......@@ -204,7 +205,7 @@ describe API::Jobs, :api do
it 'returns specific job artifacts' do
expect(response).to have_http_status(200)
expect(response.headers).to include(download_headers)
expect(response.body).to match_file(build.artifacts_file.file.file)
expect(response.body).to match_file(job.artifacts_file.file.file)
end
end
......@@ -224,14 +225,14 @@ describe API::Jobs, :api do
describe 'GET /projects/:id/artifacts/:ref_name/download?job=name' do
let(:api_user) { reporter }
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
before do
build.success
job.success
end
def get_for_ref(ref = pipeline.ref, job = build.name)
get api("/projects/#{project.id}/jobs/artifacts/#{ref}/download", api_user), job: job
def get_for_ref(ref = pipeline.ref, job_name = job.name)
get api("/projects/#{project.id}/jobs/artifacts/#{ref}/download", api_user), job: job_name
end
context 'when not logged in' do
......@@ -285,7 +286,7 @@ describe API::Jobs, :api do
let(:download_headers) do
{ 'Content-Transfer-Encoding' => 'binary',
'Content-Disposition' =>
"attachment; filename=#{build.artifacts_file.filename}" }
"attachment; filename=#{job.artifacts_file.filename}" }
end
it { expect(response).to have_http_status(200) }
......@@ -321,16 +322,16 @@ describe API::Jobs, :api do
end
describe 'GET /projects/:id/jobs/:job_id/trace' do
let(:build) { create(:ci_build, :trace, pipeline: pipeline) }
let(:job) { create(:ci_build, :trace, pipeline: pipeline) }
before do
get api("/projects/#{project.id}/jobs/#{build.id}/trace", api_user)
get api("/projects/#{project.id}/jobs/#{job.id}/trace", api_user)
end
context 'authorized user' do
it 'returns specific job trace' do
expect(response).to have_http_status(200)
expect(response.body).to eq(build.trace.raw)
expect(response.body).to eq(job.trace.raw)
end
end
......@@ -345,7 +346,7 @@ describe API::Jobs, :api do
describe 'POST /projects/:id/jobs/:job_id/cancel' do
before do
post api("/projects/#{project.id}/jobs/#{build.id}/cancel", api_user)
post api("/projects/#{project.id}/jobs/#{job.id}/cancel", api_user)
end
context 'authorized user' do
......@@ -375,10 +376,10 @@ describe API::Jobs, :api do
end
describe 'POST /projects/:id/jobs/:job_id/retry' do
let(:build) { create(:ci_build, :canceled, pipeline: pipeline) }
let(:job) { create(:ci_build, :canceled, pipeline: pipeline) }
before do
post api("/projects/#{project.id}/jobs/#{build.id}/retry", api_user)
post api("/projects/#{project.id}/jobs/#{job.id}/retry", api_user)
end
context 'authorized user' do
......@@ -410,28 +411,29 @@ describe API::Jobs, :api do
describe 'POST /projects/:id/jobs/:job_id/erase' do
before do
post api("/projects/#{project.id}/jobs/#{build.id}/erase", user)
post api("/projects/#{project.id}/jobs/#{job.id}/erase", user)
end
context 'job is erasable' do
let(:build) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
let(:job) { create(:ci_build, :trace, :artifacts, :success, project: project, pipeline: pipeline) }
it 'erases job content' do
expect(response).to have_http_status(201)
expect(build).not_to have_trace
expect(build.artifacts_file.exists?).to be_falsy
expect(build.artifacts_metadata.exists?).to be_falsy
expect(job).not_to have_trace
expect(job.artifacts_file.exists?).to be_falsy
expect(job.artifacts_metadata.exists?).to be_falsy
end
it 'updates job' do
build.reload
expect(build.erased_at).to be_truthy
expect(build.erased_by).to eq(user)
job.reload
expect(job.erased_at).to be_truthy
expect(job.erased_by).to eq(user)
end
end
context 'job is not erasable' do
let(:build) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
let(:job) { create(:ci_build, :trace, project: project, pipeline: pipeline) }
it 'responds with forbidden' do
expect(response).to have_http_status(403)
......@@ -439,25 +441,25 @@ describe API::Jobs, :api do
end
end
describe 'POST /projects/:id/jobs/:build_id/artifacts/keep' do
describe 'POST /projects/:id/jobs/:job_id/artifacts/keep' do
before do
post api("/projects/#{project.id}/jobs/#{build.id}/artifacts/keep", user)
post api("/projects/#{project.id}/jobs/#{job.id}/artifacts/keep", user)
end
context 'artifacts did not expire' do
let(:build) do
let(:job) do
create(:ci_build, :trace, :artifacts, :success,
project: project, pipeline: pipeline, artifacts_expire_at: Time.now + 7.days)
end
it 'keeps artifacts' do
expect(response).to have_http_status(200)
expect(build.reload.artifacts_expire_at).to be_nil
expect(job.reload.artifacts_expire_at).to be_nil
end
end
context 'no artifacts' do
let(:build) { create(:ci_build, project: project, pipeline: pipeline) }
let(:job) { create(:ci_build, project: project, pipeline: pipeline) }
it 'responds with not found' do
expect(response).to have_http_status(404)
......@@ -467,18 +469,18 @@ describe API::Jobs, :api do
describe 'POST /projects/:id/jobs/:job_id/play' do
before do
post api("/projects/#{project.id}/jobs/#{build.id}/play", api_user)
post api("/projects/#{project.id}/jobs/#{job.id}/play", api_user)
end
context 'on an playable job' do
let(:build) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
let(:job) { create(:ci_build, :manual, project: project, pipeline: pipeline) }
context 'when user is authorized to trigger a manual action' do
it 'plays the job' do
expect(response).to have_http_status(200)
expect(json_response['user']['id']).to eq(user.id)
expect(json_response['id']).to eq(build.id)
expect(build.reload).to be_pending
expect(json_response['id']).to eq(job.id)
expect(job.reload).to be_pending
end
end
......@@ -487,7 +489,7 @@ describe API::Jobs, :api do
let(:api_user) { create(:user) }
it 'does not trigger a manual action' do
expect(build.reload).to be_manual
expect(job.reload).to be_manual
expect(response).to have_http_status(404)
end
end
......@@ -496,7 +498,7 @@ describe API::Jobs, :api do
let(:api_user) { reporter }
it 'does not trigger a manual action' do
expect(build.reload).to be_manual
expect(job.reload).to be_manual
expect(response).to have_http_status(403)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment