Commit e38e2ce29a2d0ce731bafd5012eae8d21de05d4b

Authored by Dmitriy Zaporozhets
2 parents d03af842 83435e3d

Merge pull request #3154 from hiroponz/fix-routing-error

Fix routing error
config/routes.rb
... ... @@ -165,7 +165,7 @@ Gitlab::Application.routes.draw do
165 165 #
166 166 # Project Area
167 167 #
168   - resources :projects, constraints: { id: /[a-zA-Z.0-9_\-\/]+/ }, except: [:new, :create, :index], path: "/" do
  168 + resources :projects, constraints: { id: /(?:[a-zA-Z.0-9_\-]+\/)?[a-zA-Z.0-9_\-]+/ }, except: [:new, :create, :index], path: "/" do
169 169 member do
170 170 get "wall"
171 171 get "files"
... ... @@ -174,10 +174,10 @@ Gitlab::Application.routes.draw do
174 174 resources :blob, only: [:show], constraints: {id: /.+/}
175 175 resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/}
176 176 resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/}
177   - resources :commits, only: [:show], constraints: {id: /.+/}
  177 + resources :commits, only: [:show], constraints: {id: /(?:[^.]|\.(?!atom$))+/, format: /atom/}
178 178 resources :compare, only: [:index, :create]
179 179 resources :blame, only: [:show], constraints: {id: /.+/}
180   - resources :graph, only: [:show], constraints: {id: /.+/}
  180 + resources :graph, only: [:show], constraints: {id: /(?:[^.]|\.(?!json$))+/, format: /json/}
181 181 match "/compare/:from...:to" => "compare#show", as: "compare",
182 182 :via => [:get, :post], constraints: {from: /.+/, to: /.+/}
183 183  
... ...
features/steps/project/project_network_graph.rb
... ... @@ -27,6 +27,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
27 27  
28 28 And 'I switch ref to "stable"' do
29 29 page.select 'stable', :from => 'ref'
  30 + sleep 2
30 31 end
31 32  
32 33 And 'page should select "stable" in select box' do
... ... @@ -44,6 +45,7 @@ class ProjectNetworkGraph < Spinach::FeatureSteps
44 45 fill_in 'q', :with => '98d6492'
45 46 find('button').click
46 47 end
  48 + sleep 2
47 49 end
48 50  
49 51 And 'page should have "v2.1.0" on graph' do
... ...
lib/extracts_path.rb
... ... @@ -105,12 +105,6 @@ module ExtractsPath
105 105 # Automatically renders `not_found!` if a valid tree path could not be
106 106 # resolved (e.g., when a user inserts an invalid path or ref).
107 107 def assign_ref_vars
108   - # Handle formats embedded in the id
109   - if params[:id].ends_with?('.atom')
110   - params[:id].gsub!(/\.atom$/, '')
111   - request.format = :atom
112   - end
113   -
114 108 path = CGI::unescape(request.fullpath.dup)
115 109  
116 110 @ref, @path = extract_ref(path)
... ...
spec/controllers/commits_controller_spec.rb
... ... @@ -13,7 +13,7 @@ describe CommitsController do
13 13 describe "GET show" do
14 14 context "as atom feed" do
15 15 it "should render as atom" do
16   - get :show, project_id: project.path, id: "master.atom"
  16 + get :show, project_id: project.path, id: "master", format: "atom"
17 17 response.should be_success
18 18 response.content_type.should == 'application/atom+xml'
19 19 end
... ...
spec/routing/project_routing_spec.rb
... ... @@ -56,7 +56,6 @@ end
56 56 # projects POST /projects(.:format) projects#create
57 57 # new_project GET /projects/new(.:format) projects#new
58 58 # wall_project GET /:id/wall(.:format) projects#wall
59   -# graph_project GET /:id/graph(.:format) projects#graph
60 59 # files_project GET /:id/files(.:format) projects#files
61 60 # edit_project GET /:id/edit(.:format) projects#edit
62 61 # project GET /:id(.:format) projects#show
... ... @@ -75,10 +74,6 @@ describe ProjectsController, "routing" do
75 74 get("/gitlabhq/wall").should route_to('projects#wall', id: 'gitlabhq')
76 75 end
77 76  
78   - it "to #graph" do
79   - get("/gitlabhq/graph/master").should route_to('graph#show', project_id: 'gitlabhq', id: 'master')
80   - end
81   -
82 77 it "to #files" do
83 78 get("/gitlabhq/files").should route_to('projects#files', id: 'gitlabhq')
84 79 end
... ... @@ -202,6 +197,7 @@ describe RefsController, "routing" do
202 197 it "to #logs_tree" do
203 198 get("/gitlabhq/refs/stable/logs_tree").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable')
204 199 get("/gitlabhq/refs/stable/logs_tree/foo/bar/baz").should route_to('refs#logs_tree', project_id: 'gitlabhq', id: 'stable', path: 'foo/bar/baz')
  200 + get("/gitlab/gitlabhq/refs/stable/logs_tree/files.scss").should route_to('refs#logs_tree', project_id: 'gitlab/gitlabhq', id: 'stable', path: 'files.scss')
205 201 end
206 202 end
207 203  
... ... @@ -301,6 +297,10 @@ describe CommitsController, "routing" do
301 297 let(:actions) { [:show] }
302 298 let(:controller) { 'commits' }
303 299 end
  300 +
  301 + it "to #show" do
  302 + get("/gitlab/gitlabhq/commits/master.atom").should route_to('commits#show', project_id: 'gitlab/gitlabhq', id: "master", format: "atom")
  303 + end
304 304 end
305 305  
306 306 # project_team_members GET /:project_id/team_members(.:format) team_members#index
... ... @@ -385,6 +385,7 @@ end
385 385 describe BlameController, "routing" do
386 386 it "to #show" do
387 387 get("/gitlabhq/blame/master/app/models/project.rb").should route_to('blame#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
  388 + get("/gitlab/gitlabhq/blame/master/files.scss").should route_to('blame#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
388 389 end
389 390 end
390 391  
... ... @@ -393,6 +394,7 @@ describe BlobController, "routing" do
393 394 it "to #show" do
394 395 get("/gitlabhq/blob/master/app/models/project.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
395 396 get("/gitlabhq/blob/master/app/models/compare.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/compare.rb')
  397 + get("/gitlab/gitlabhq/blob/master/files.scss").should route_to('blob#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
396 398 end
397 399 end
398 400  
... ... @@ -400,6 +402,7 @@ end
400 402 describe TreeController, "routing" do
401 403 it "to #show" do
402 404 get("/gitlabhq/tree/master/app/models/project.rb").should route_to('tree#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb')
  405 + get("/gitlab/gitlabhq/tree/master/files.scss").should route_to('tree#show', project_id: 'gitlab/gitlabhq', id: 'master/files.scss')
403 406 end
404 407 end
405 408  
... ... @@ -420,3 +423,10 @@ describe CompareController, "routing" do
420 423 get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable')
421 424 end
422 425 end
  426 +
  427 +describe GraphController, "routing" do
  428 + it "to #show" do
  429 + get("/gitlabhq/graph/master").should route_to('graph#show', project_id: 'gitlabhq', id: 'master')
  430 + get("/gitlabhq/graph/master.json").should route_to('graph#show', project_id: 'gitlabhq', id: 'master', format: "json")
  431 + end
  432 +end
... ...