Return an empty array when dependencies is an empty array

This commit is contained in:
Mike Wyatt 2017-04-05 12:07:10 +00:00 committed by Rémy Coutable
parent 10a77824e1
commit 31b8287a1b
2 changed files with 29 additions and 0 deletions

View file

@ -540,6 +540,8 @@ module Ci
end
def dependencies
return [] if empty_dependencies?
depended_jobs = depends_on_builds
return depended_jobs unless options[:dependencies].present?
@ -549,6 +551,10 @@ module Ci
end
end
def empty_dependencies?
options[:dependencies]&.empty?
end
private
def update_artifacts_size

View file

@ -461,6 +461,29 @@ describe API::Runner do
end
end
context 'when dependencies is an empty array' do
let!(:job) { create(:ci_build_tag, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
let!(:job2) { create(:ci_build_tag, pipeline: pipeline, name: 'rubocop', stage: 'test', stage_idx: 0) }
let!(:empty_dependencies_job) do
create(:ci_build, pipeline: pipeline, token: 'test-job-token', name: 'empty_dependencies_job',
stage: 'deploy', stage_idx: 1,
options: { dependencies: [] })
end
before do
job.success
job2.success
end
it 'returns an empty array' do
request_job
expect(response).to have_http_status(201)
expect(json_response['id']).to eq(empty_dependencies_job.id)
expect(json_response['dependencies'].count).to eq(0)
end
end
context 'when job has no tags' do
before { job.update(tags: []) }