summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-03-15 18:03:37 +0900
committerShinya Maeda <shinya@gitlab.com>2018-03-15 18:04:17 +0900
commit8b0b8e3bc4b1832d7c66e88ec26a3e244a11fec5 (patch)
treeb7b1a2d168472d34c1648349ecc482ae9a599795
parentc13887a1c219e8ff1a5134d7bd12529cfe656c77 (diff)
downloadgitlab-ce-8b0b8e3bc4b1832d7c66e88ec26a3e244a11fec5.tar.gz
Use with_artifacts_archive name. Add spec
-rw-r--r--app/models/ci/build.rb8
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--app/models/project.rb2
-rw-r--r--spec/models/ci/build_spec.rb36
4 files changed, 42 insertions, 6 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index dafad611060..5a381bdd6a2 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -41,12 +41,12 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
- scope :with_artifacts, ->(file_type) do
+ scope :with_artifacts_archive, ->() do
where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
- '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').public_send(file_type)) # rubocop:disable GitlabSecurity/PublicSend
+ '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').archive)
end
- scope :with_artifacts_not_expired, ->() { with_artifacts(:archive).where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
- scope :with_expired_artifacts, ->() { with_artifacts(:archive).where('artifacts_expire_at < ?', Time.now) }
+ scope :with_artifacts_not_expired, ->() { with_artifacts_archive.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
+ scope :with_expired_artifacts, ->() { with_artifacts_archive.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
scope :ref_protected, -> { where(protected: true) }
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 0eea6645985..8492d293343 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -514,7 +514,7 @@ module Ci
# We purposely cast the builds to an Array here. Because we always use the
# rows if there are more than 0 this prevents us from having to run two
# queries: one to get the count and one to get the rows.
- @latest_builds_with_artifacts ||= builds.latest.with_artifacts(:archive).to_a
+ @latest_builds_with_artifacts ||= builds.latest.with_artifacts_archive.to_a
end
private
diff --git a/app/models/project.rb b/app/models/project.rb
index d51f7c9e8cd..8ed236e5c98 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -542,7 +542,7 @@ class Project < ActiveRecord::Base
latest_pipeline = pipelines.latest_successful_for(ref)
if latest_pipeline
- latest_pipeline.builds.latest.with_artifacts(:archive)
+ latest_pipeline.builds.latest.with_artifacts_archive
else
builds.none
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 6e202de0db9..623b4d63db4 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -80,6 +80,42 @@ describe Ci::Build do
end
end
+ describe '.with_artifacts_archive' do
+ subject { described_class.with_artifacts_archive }
+
+ context 'when job does not have an archive' do
+ let!(:job) { create(:ci_build) }
+
+ it 'does not return the job' do
+ is_expected.not_to include(job)
+ end
+ end
+
+ context 'when job has a legacy archive' do
+ let!(:job) { create(:ci_build, :legacy_artifacts) }
+
+ it 'returns the job' do
+ is_expected.to include(job)
+ end
+ end
+
+ context 'when job has a job artifact archive' do
+ let!(:job) { create(:ci_build, :artifacts) }
+
+ it 'returns the job' do
+ is_expected.to include(job)
+ end
+ end
+
+ context 'when job has a job artifact trace' do
+ let!(:job) { create(:ci_build, :trace_artifact) }
+
+ it 'does not return the job' do
+ is_expected.not_to include(job)
+ end
+ end
+ end
+
describe '#actionize' do
context 'when build is a created' do
before do