From 31b8287a1b4cc5ee4424c35045fa4540e9665184 Mon Sep 17 00:00:00 2001 From: Mike Wyatt Date: Wed, 5 Apr 2017 12:07:10 +0000 Subject: [PATCH] Return an empty array when dependencies is an empty array --- app/models/ci/build.rb | 6 ++++++ spec/requests/api/runner_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ad0be70c32a..8431c5f228c 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -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 diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 044b989e5ba..1cfac7353d4 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -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: []) }