From b4350ca91abef0a031e89984bf17fa55e3db0b86 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Thu, 3 May 2012 14:49:29 +0000 Subject: [PATCH] route: scm: fix git and mercurial changes action If branch name has special character, "View revisions" link has route error. For example, Redmine Mercurial hgsubversion mirror has "../sandbox/rails-3.2" named branch. Git default branch of bare repository is defined at HEAD. In most cases, it is *master*. Mercurial GUI standard behavior is showing all revisions on top page. So, Redmine default branch is *nil*. Mercurial top page "View revisions" link has route error. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9617 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- config/routes.rb | 10 ++- test/integration/routing/repositories_test.rb | 62 +++++++++++++------ 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 94f978bdd..22c61acb8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -214,6 +214,9 @@ RedmineApp::Application.routes.draw do get 'projects/:id/repository/:repository_id/statistics', :to => 'repositories#stats' get 'projects/:id/repository/:repository_id/graph', :to => 'repositories#graph' + get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', + :to => 'repositories#changes' + get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/:repository_id/revision', :to => 'repositories#revision' post 'projects/:id/repository/:repository_id/revisions/:rev/issues', :to => 'repositories#add_related_issue' @@ -228,13 +231,16 @@ RedmineApp::Application.routes.draw do get 'projects/:id/repository/:repository_id/revisions/:rev/:action(/*path(.:ext))', :controller => 'repositories', :constraints => { - :action => /(browse|show|entry|changes|annotate|diff)/, + :action => /(browse|show|entry|annotate|diff)/, :rev => /[a-z0-9\.\-_]+/ } get 'projects/:id/repository/statistics', :to => 'repositories#stats' get 'projects/:id/repository/graph', :to => 'repositories#graph' + get 'projects/:id/repository/changes(/*path(.:ext))', + :to => 'repositories#changes' + get 'projects/:id/repository/revisions', :to => 'repositories#revisions' get 'projects/:id/repository/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/revision', :to => 'repositories#revision' @@ -249,7 +255,7 @@ RedmineApp::Application.routes.draw do get 'projects/:id/repository/revisions/:rev/:action(/*path(.:ext))', :controller => 'repositories', :constraints => { - :action => /(browse|show|entry|changes|annotate|diff)/, + :action => /(browse|show|entry|annotate|diff)/, :rev => /[a-z0-9\.\-_]+/ } get 'projects/:id/repository/:repository_id/:format(/*path(.:ext))', :to => 'repositories#entry', :format => /raw/ diff --git a/test/integration/routing/repositories_test.rb b/test/integration/routing/repositories_test.rb index 0b0761ee6..f02791b9f 100644 --- a/test/integration/routing/repositories_test.rb +++ b/test/integration/routing/repositories_test.rb @@ -134,16 +134,29 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest ) assert_routing( { :method => 'get', - :path => "/projects/redmine/repository/revisions/2457/changes" }, - { :controller => 'repositories', :action => 'changes', :id => 'redmine', - :rev => '2457' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/redmine/repository/revisions/2457/changes/#{@path_hash[:path]}" }, - { :controller => 'repositories', :action => 'changes', :id => 'redmine', - :path => @path_hash[:param] , :rev => '2457'} + :path => "/projects/redmine/repository/changes" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine' } ) + ['2457', 'master', 'slash/slash'].each do |rev| + assert_routing( + { :method => 'get', + :path => "/projects/redmine/repository/changes" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine', + :rev => rev }, + {}, + { :rev => rev } + ) + end + ['2457', 'master', 'slash/slash'].each do |rev| + assert_routing( + { :method => 'get', + :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine', + :path => @path_hash[:param], :rev => rev }, + {}, + { :rev => rev } + ) + end assert_routing( { :method => 'get', :path => "/projects/redmine/repository/revisions/2457/diff" }, @@ -215,16 +228,29 @@ class RoutingRepositoriesTest < ActionController::IntegrationTest ) assert_routing( { :method => 'get', - :path => "/projects/redmine/repository/foo/revisions/2457/changes" }, - { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', - :rev => '2457' } - ) - assert_routing( - { :method => 'get', - :path => "/projects/redmine/repository/foo/revisions/2457/changes/#{@path_hash[:path]}" }, - { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', - :path => @path_hash[:param] , :rev => '2457'} + :path => "/projects/redmine/repository/foo/changes" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo' } ) + ['2457', 'master', 'slash/slash'].each do |rev| + assert_routing( + { :method => 'get', + :path => "/projects/redmine/repository/foo/changes" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine', + :repository_id => 'foo', :rev => rev }, + {}, + { :rev => rev } + ) + end + ['2457', 'master', 'slash/slash'].each do |rev| + assert_routing( + { :method => 'get', + :path => "/projects/redmine/repository/foo/changes/#{@path_hash[:path]}" }, + { :controller => 'repositories', :action => 'changes', :id => 'redmine', + :repository_id => 'foo', :path => @path_hash[:param], :rev => rev }, + {}, + { :rev => rev } + ) + end assert_routing( { :method => 'get', :path => "/projects/redmine/repository/foo/revisions/2457/diff" }, -- 2.39.5