Commit 34243489 authored by drew cimino's avatar drew cimino

Don't render artifact download links on the project tags page for builds with expired artifacts

parent de44f3e1
...@@ -686,7 +686,7 @@ module Ci ...@@ -686,7 +686,7 @@ module Ci
# We purposely cast the builds to an Array here. Because we always use the # 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 # 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. # 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_not_expired.to_a
end end
def has_test_reports? def has_test_reports?
......
---
title: stop rendering download links for expired artifacts on the project tags page
merge_request: 26753
author: Drew Cimino
type: fixed
...@@ -2705,18 +2705,19 @@ describe Ci::Pipeline, :mailer do ...@@ -2705,18 +2705,19 @@ describe Ci::Pipeline, :mailer do
end end
describe '#latest_builds_with_artifacts' do describe '#latest_builds_with_artifacts' do
let!(:pipeline) { create(:ci_pipeline, :success) } let!(:fresh_build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
let!(:stale_build) { create(:ci_build, :success, :expired, :artifacts, pipeline: pipeline) }
let!(:build) do
create(:ci_build, :success, :artifacts, pipeline: pipeline)
end
it 'returns an Array' do it 'returns an Array' do
expect(pipeline.latest_builds_with_artifacts).to be_an_instance_of(Array) expect(pipeline.latest_builds_with_artifacts).to be_an_instance_of(Array)
end end
it 'returns the latest builds' do it 'returns the latest builds with non-expired artifacts' do
expect(pipeline.latest_builds_with_artifacts).to eq([build]) expect(pipeline.latest_builds_with_artifacts).to contain_exactly(fresh_build)
end
it 'does not return builds with expired artifacts' do
expect(pipeline.latest_builds_with_artifacts).not_to include(stale_build)
end end
it 'memoizes the returned relation' do it 'memoizes the returned relation' do
......
require 'spec_helper' require 'spec_helper'
describe 'projects/tags/index' do describe 'projects/tags/index' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:tags) { TagsFinder.new(project.repository, {}).execute }
let(:git_tag) { project.repository.tags.last }
let(:release) { create(:release, project: project, sha: git_tag.target_commit.sha) }
let(:pipeline) { create(:ci_pipeline, :success, project: project, ref: git_tag.name, sha: release.sha) }
let(:artifacts_download_header_regex) { %r(<li class="dropdown-bold-header">Download artifacts<\/li>) }
let(:artifacts_download_link_selector) { 'a[href="' + latest_succeeded_project_artifacts_path(project, "#{pipeline.ref}/download", job: 'test') + '"]' }
before do before do
assign(:project, project) assign(:project, project)
assign(:repository, project.repository) assign(:repository, project.repository)
assign(:tags, []) assign(:releases, project.releases)
assign(:tags, Kaminari.paginate_array(tags).page(0))
assign(:tags_pipelines, { git_tag.name => pipeline })
allow(view).to receive(:current_ref).and_return('master') allow(view).to receive(:current_ref).and_return('master')
allow(view).to receive(:can?).and_return(false) allow(view).to receive(:current_user).and_return(project.namespace.owner)
end end
it 'defaults sort dropdown toggle to last updated' do it 'defaults sort dropdown toggle to last updated' do
render render
expect(rendered).to have_button('Last updated') expect(rendered).to have_button('Last updated')
end end
context 'when the most recent build for a tag has artifacts' do
let!(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
it 'renders the Artifacts section in the download list' do
render
expect(rendered).to match(artifacts_download_header_regex)
end
it 'renders artifact download links' do
render
expect(rendered).to have_selector(artifacts_download_link_selector)
end
end
context 'when the most recent build for a tag has expired artifacts' do
let!(:build) { create(:ci_build, :success, :expired, :artifacts, pipeline: pipeline) }
it 'does not render the Artifacts section in the download list' do
render
expect(rendered).not_to match(artifacts_download_header_regex)
end
it 'renders artifact download links' do
render
expect(rendered).not_to have_selector(artifacts_download_link_selector)
end
end
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