From d7bbee7593ee54a9685c9eded00b121cca3913be Mon Sep 17 00:00:00 2001
From: Lin Jen-Shin <godfat@godfat.org>
Date: Thu, 14 Jul 2016 16:45:46 +0800
Subject: [PATCH] Update routes based on feedback from:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5142#note_13058785

And note that job/build_name could contain `/`
---
 app/controllers/projects/artifacts_controller.rb  |  2 +-
 config/routes.rb                                  | 15 ++++++++-------
 .../projects/artifacts_controller_spec.rb         |  8 ++++----
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb
index f1370efd64e..3e487c24cbd 100644
--- a/app/controllers/projects/artifacts_controller.rb
+++ b/app/controllers/projects/artifacts_controller.rb
@@ -61,7 +61,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
 
   def build_from_ref
     if params[:ref_name]
-      builds = project.builds_for(params[:build_name], params[:ref_name])
+      builds = project.builds_for(params[:job], params[:ref_name])
 
       builds.success.latest.first
     end
diff --git a/config/routes.rb b/config/routes.rb
index 203f679226e..ea6465038df 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -733,16 +733,17 @@ Rails.application.routes.draw do
 
         resources :environments, only: [:index, :show, :new, :create, :destroy]
 
-        resources :artifacts, only: [] do
-          collection do
-            get :search, path: ':ref_name/:build_name/*path', format: false,
-                         constraints: { ref_name: /.+/ } # ref could have /
-          end
-        end
-
         resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
           collection do
             post :cancel_all
+
+            resources :artifacts, only: [] do
+              collection do
+                get :search, path: ':ref_name/*path',
+                             format: false,
+                             constraints: { ref_name: /.+/ } # could have /
+              end
+            end
           end
 
           member do
diff --git a/spec/requests/projects/artifacts_controller_spec.rb b/spec/requests/projects/artifacts_controller_spec.rb
index d44901289d8..574b7028617 100644
--- a/spec/requests/projects/artifacts_controller_spec.rb
+++ b/spec/requests/projects/artifacts_controller_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
 require_relative '../shared/artifacts_context'
 
 describe Projects::ArtifactsController do
-  describe 'GET /:project/artifacts/:ref/:build_name/browse' do
+  describe 'GET /:project/builds/artifacts/:ref_name/browse?job=name' do
     include_context 'artifacts from ref and build name'
 
     before do
@@ -10,13 +10,13 @@ describe Projects::ArtifactsController do
     end
 
     def path_from_ref(
-      ref = pipeline.sha, build_name = build.name, path = 'browse')
+      ref = pipeline.sha, job = build.name, path = 'browse')
       search_namespace_project_artifacts_path(
         project.namespace,
         project,
         ref,
-        build_name,
-        path)
+        path,
+        job: job)
     end
 
     context '404' do
-- 
GitLab