Commit 948fc737 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Complete all legacy builds URL. Tests are added

parent 1b74e422
require 'constraints/project_url_constrainer' require 'constraints/project_url_constrainer'
require 'gitlab/routes/legacy_builds'
resources :projects, only: [:index, :new, :create] resources :projects, only: [:index, :new, :create]
...@@ -247,28 +248,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -247,28 +248,7 @@ constraints(ProjectUrlConstrainer.new) do
end end
end end
redirect_builds_to_jobs = redirect do |params, req| Gitlab::Routes::LegacyBuilds.new(self).draw
args = params.values_at(:namespace_id, :project_id, :id).compact
url_helpers = Gitlab::Routing.url_helpers
if params[:id]
case params[:action]
when 'status'
url_helpers.status_namespace_project_job_path(*args, format: params[:format])
when 'trace'
url_helpers.trace_namespace_project_job_path(*args, format: params[:format])
when 'raw'
url_helpers.raw_namespace_project_job_path(*args)
else # show
url_helpers.namespace_project_job_path(*args)
end
else # index
url_helpers.namespace_project_jobs_path(*args)
end
end
get '/builds(/:id(/:action))', to: redirect_builds_to_jobs,
as: 'legacy_build'
resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do resources :hooks, only: [:index, :create, :edit, :update, :destroy], constraints: { id: /\d+/ } do
member do member do
......
module Gitlab
module Routes
class LegacyBuilds
def initialize(map)
@map = map
end
def draw
redirect_builds_to_jobs = @map.redirect(&method(:redirect))
@map.get '/builds(/:id(/*action))', to: redirect_builds_to_jobs,
as: 'legacy_build',
format: false
end
def redirect(params, req)
args = params.values_at(:namespace_id, :project_id, :id).compact
url_helpers = Gitlab::Routing.url_helpers
if params[:id]
case params[:action]
when 'status'
url_helpers.status_namespace_project_job_path(*args, format: params[:format])
when 'trace'
url_helpers.trace_namespace_project_job_path(*args, format: params[:format])
when 'raw'
url_helpers.raw_namespace_project_job_path(*args)
when String
if params[:id] == 'artifacts'
url_helpers.latest_succeeded_namespace_project_artifacts_path(params[:namespace_id], params[:project_id], params[:action], job: req.GET[:job])
else
"#{url_helpers.namespace_project_job_path(*args)}/#{params[:action]}"
end
else # show
url_helpers.namespace_project_job_path(*args)
end
else # index
url_helpers.namespace_project_jobs_path(*args)
end
end
end
end
end
require 'spec_helper'
feature 'Browse artifact', :js, feature: true do
let(:project) { create(:project, :public) }
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master') }
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
def browse_path(path)
browse_namespace_project_job_artifacts_path(project.namespace, project, job, path)
end
context 'when visiting old URL' do
let(:browse_url) do
browse_path('other_artifacts_0.1.2')
end
before do
visit browse_url.sub('jobs', 'builds')
end
it "redirects to new URL" do
expect(page.current_path).to eq(browse_url)
end
end
end
require 'spec_helper'
feature 'Download artifact', :js, feature: true do
let(:project) { create(:project, :public) }
let(:pipeline) { create(:ci_empty_pipeline, status: :success, project: project, sha: project.commit.sha, ref: 'master') }
let(:job) { create(:ci_build, :artifacts, :success, pipeline: pipeline) }
shared_examples 'downloading' do
it 'downloads the zip' do
expect(page.response_headers['Content-Disposition'])
.to eq(%Q{attachment; filename="#{job.artifacts_file.filename}"})
# Check the content does match, but don't print this as error message
expect(page.source.b == job.artifacts_file.file.read.b)
end
end
context 'when downloading' do
before do
visit download_url
end
context 'via job id' do
let(:download_url) do
download_namespace_project_job_artifacts_path(project.namespace, project, job)
end
it_behaves_like 'downloading'
end
context 'via branch name and job name' do
let(:download_url) do
latest_succeeded_namespace_project_artifacts_path(project.namespace, project, "#{pipeline.ref}/download", job: job.name)
end
it_behaves_like 'downloading'
end
end
context 'when visiting old URL' do
before do
visit download_url.sub('jobs', 'builds')
end
context 'via job id' do
let(:download_url) do
download_namespace_project_job_artifacts_path(project.namespace, project, job)
end
it_behaves_like 'downloading'
end
context 'via branch name and job name' do
let(:download_url) do
latest_succeeded_namespace_project_artifacts_path(project.namespace, project, "#{pipeline.ref}/download", job: job.name)
end
it_behaves_like 'downloading'
end
end
end
...@@ -6,7 +6,11 @@ feature 'Artifact file', :js, feature: true do ...@@ -6,7 +6,11 @@ feature 'Artifact file', :js, feature: true do
let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) } let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }
def visit_file(path) def visit_file(path)
visit file_namespace_project_job_artifacts_path(project.namespace, project, build, path) visit file_path(path)
end
def file_path(path)
file_namespace_project_job_artifacts_path(project.namespace, project, build, path)
end end
context 'Text file' do context 'Text file' do
...@@ -56,4 +60,18 @@ feature 'Artifact file', :js, feature: true do ...@@ -56,4 +60,18 @@ feature 'Artifact file', :js, feature: true do
end end
end end
end end
context 'when visiting old URL' do
let(:file_url) do
file_path('other_artifacts_0.1.2/doc_sample.txt')
end
before do
visit file_url.sub('jobs', 'builds')
end
it "redirects to new URL" do
expect(page.current_path).to eq(file_url)
end
end
end end
require 'spec_helper'
feature 'Raw artifact', :js, feature: true do
let(:project) { create(:project, :public) }
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master') }
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
def raw_path(path)
raw_namespace_project_job_artifacts_path(project.namespace, project, job, path)
end
context 'when visiting old URL' do
let(:raw_url) do
raw_path('other_artifacts_0.1.2/doc_sample.txt')
end
before do
visit raw_url.sub('jobs', 'builds')
end
it "redirects to new URL" do
expect(page.current_path).to eq(raw_url)
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