Commit 1501d7c9 authored by Kamil Trzciński's avatar Kamil Trzciński

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

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

See merge request !2129
parents 2cce73a2 1d111354
......@@ -28,7 +28,7 @@ class BuildDetailsEntity < BuildEntity
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(6).of(8)
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
......@@ -7,8 +7,8 @@ feature 'Jobs', :feature do
let(:project) { create(:project) }
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')
......@@ -20,7 +20,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
......@@ -30,30 +30,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
......@@ -72,9 +72,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
......@@ -96,7 +96,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
......@@ -104,17 +104,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(: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 commit`s data' do
......@@ -124,14 +126,14 @@ 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 "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) }
......@@ -139,8 +141,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
......@@ -150,10 +152,10 @@ feature 'Jobs', :feature do
context 'Artifacts expire date' do
before do
build.update_attributes(artifacts_file: artifacts_file,
artifacts_expire_at: expire_at)
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
......@@ -199,7 +201,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
......@@ -213,9 +215,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
......@@ -225,16 +227,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
......@@ -246,12 +248,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
......@@ -273,20 +275,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
......@@ -294,22 +296,22 @@ 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
end
end
context 'build project is over shared runners limit' do
context 'job project is over shared runners limit' do
let(:group) { create(:group, :with_used_build_minutes_limit) }
let(:project) { create(:project, namespace: group, shared_runners_enabled: true) }
it 'displays a warning message' do
visit namespace_project_build_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
expect(page).to have_content('You have used all your shared Runners pipeline minutes.')
end
......@@ -319,8 +321,8 @@ feature 'Jobs', :feature do
describe "POST /:project/jobs/:id/cancel" 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)
click_link "Cancel"
end
......@@ -333,9 +335,9 @@ feature 'Jobs', :feature do
context "Job from other project" do
before do
build.run!
visit namespace_project_job_path(project.namespace, project, build)
page.driver.post(cancel_namespace_project_job_path(project.namespace, project, build2))
job.run!
visit namespace_project_job_path(project.namespace, project, job)
page.driver.post(cancel_namespace_project_job_path(project.namespace, project, job2))
end
it { expect(page.status_code).to eq(404) }
......@@ -345,8 +347,8 @@ feature 'Jobs', :feature do
describe "POST /:project/jobs/:id/retry" 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)
click_link 'Cancel'
page.within('.build-header') do
click_link 'Retry job'
......@@ -364,10 +366,10 @@ feature 'Jobs', :feature do
context "Job from other 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)
click_link 'Cancel'
page.driver.post(retry_namespace_project_job_path(project.namespace, project, build2))
page.driver.post(retry_namespace_project_job_path(project.namespace, project, job2))
end
it { expect(page).to have_http_status(404) }
......@@ -375,13 +377,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
......@@ -394,15 +396,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) }
......@@ -414,23 +416,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
......@@ -445,15 +447,15 @@ feature 'Jobs', :feature do
before do
Capybara.current_session.driver.headers = { 'X-Sendfile-Type' => 'X-Sendfile' }
build.run!
job.run!
allow_any_instance_of(Gitlab::Ci::Trace).to receive(:paths)
.and_return(paths)
visit namespace_project_job_path(project.namespace, project, build)
visit namespace_project_job_path(project.namespace, project, job)
end
context 'when build has trace in file', :js do
context 'when job has trace in file', :js do
let(:paths) do
[existing_file]
end
......@@ -480,7 +482,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
......@@ -496,7 +498,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) }
......@@ -504,7 +506,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) }
......@@ -514,7 +516,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) }
......@@ -522,7 +524,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 }
......@@ -26,7 +26,7 @@ describe API::Jobs, :api do
let(:query) { Hash.new }
before do
build
job
get api("/projects/#{project.id}/jobs", api_user), query
end
......@@ -43,13 +43,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
......@@ -80,7 +80,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
......@@ -90,7 +90,7 @@ describe API::Jobs, :api do
let(:query) { Hash.new }
before do
build
job
get api("/projects/#{project.id}/pipelines/#{pipeline.id}/jobs", api_user), query
end
......@@ -107,13 +107,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
......@@ -142,7 +142,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) }
......@@ -161,7 +161,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
......@@ -171,12 +171,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
......@@ -192,12 +193,12 @@ describe API::Jobs, :api do
describe 'GET /projects/:id/jobs/:job_id/artifacts' do
before do
stub_artifacts_object_storage
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
context 'when artifacts are stored locally' 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
......@@ -208,7 +209,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
......@@ -222,7 +223,7 @@ describe API::Jobs, :api do
end
context 'when artifacts are stored remotely' do
let(:build) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) }
let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) }
it 'returns location redirect' do
expect(response).to have_http_status(302)
......@@ -237,15 +238,15 @@ 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
stub_artifacts_object_storage
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
......@@ -300,7 +301,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) }
......@@ -308,7 +309,7 @@ describe API::Jobs, :api do
end
context 'when artifacts are stored remotely' do
let(:build) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) }
let(:job) { create(:ci_build, :artifacts, :remote_store, pipeline: pipeline) }
it 'returns location redirect' do
expect(response).to have_http_status(302)
......@@ -345,16 +346,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
......@@ -369,7 +370,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
......@@ -399,10 +400,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
......@@ -434,28 +435,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)
......@@ -463,25 +465,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)
......@@ -491,18 +493,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
......@@ -511,7 +513,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
......@@ -520,7 +522,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