Chris@1115: # Redmine - project management software Chris@1115: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@1115: # Chris@1115: # This program is free software; you can redistribute it and/or Chris@1115: # modify it under the terms of the GNU General Public License Chris@1115: # as published by the Free Software Foundation; either version 2 Chris@1115: # of the License, or (at your option) any later version. Chris@1115: # Chris@1115: # This program is distributed in the hope that it will be useful, Chris@1115: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1115: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1115: # GNU General Public License for more details. Chris@1115: # Chris@1115: # You should have received a copy of the GNU General Public License Chris@1115: # along with this program; if not, write to the Free Software Chris@1115: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1115: Chris@1115: require File.expand_path('../../../test_helper', __FILE__) Chris@1115: Chris@1115: class RoutingRepositoriesTest < ActionController::IntegrationTest Chris@1115: def setup Chris@1115: @path_hash = repository_path_hash(%w[path to file.c]) Chris@1115: assert_equal "path/to/file.c", @path_hash[:path] Chris@1115: assert_equal "path/to/file.c", @path_hash[:param] Chris@1115: end Chris@1115: Chris@1115: def test_repositories_resources Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repositories/new" }, Chris@1115: { :controller => 'repositories', :action => 'new', :project_id => 'redmine' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'post', Chris@1115: :path => "/projects/redmine/repositories" }, Chris@1115: { :controller => 'repositories', :action => 'create', :project_id => 'redmine' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/repositories/1/edit" }, Chris@1115: { :controller => 'repositories', :action => 'edit', :id => '1' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'put', Chris@1115: :path => "/repositories/1" }, Chris@1115: { :controller => 'repositories', :action => 'update', :id => '1' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'delete', Chris@1115: :path => "/repositories/1" }, Chris@1115: { :controller => 'repositories', :action => 'destroy', :id => '1' } Chris@1115: ) Chris@1115: ["get", "post"].each do |method| Chris@1115: assert_routing( Chris@1115: { :method => method, Chris@1115: :path => "/repositories/1/committers" }, Chris@1115: { :controller => 'repositories', :action => 'committers', :id => '1' } Chris@1115: ) Chris@1115: end Chris@1115: end Chris@1115: Chris@1115: def test_repositories_show Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/statistics" }, Chris@1115: { :controller => 'repositories', :action => 'stats', :id => 'redmine' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/graph" }, Chris@1115: { :controller => 'repositories', :action => 'graph', :id => 'redmine' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_show_with_repository_id Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_with_repository_id Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/statistics" }, Chris@1115: { :controller => 'repositories', :action => 'stats', :id => 'redmine', :repository_id => 'foo' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/graph" }, Chris@1115: { :controller => 'repositories', :action => 'graph', :id => 'redmine', :repository_id => 'foo' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_revisions Chris@1115: empty_path_param = [] Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions" }, Chris@1115: { :controller => 'repositories', :action => 'revisions', :id => 'redmine' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions.atom" }, Chris@1115: { :controller => 'repositories', :action => 'revisions', :id => 'redmine', Chris@1115: :format => 'atom' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2457" }, Chris@1115: { :controller => 'repositories', :action => 'revision', :id => 'redmine', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2457/show" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2457/show/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine', Chris@1115: :path => @path_hash[:param] , :rev => '2457'} Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2457/diff" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2457/diff" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', Chris@1115: :rev => '2457', :format => 'diff' }, Chris@1115: {}, Chris@1115: { :format => 'diff' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => '2', :format => 'diff' }, Chris@1115: {}, Chris@1115: { :format => 'diff' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2/entry/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'entry', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'raw', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revisions/2/annotate/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'annotate', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_revisions_with_repository_id Chris@1115: empty_path_param = [] Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions" }, Chris@1115: { :controller => 'repositories', :action => 'revisions', :id => 'redmine', :repository_id => 'foo' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions.atom" }, Chris@1115: { :controller => 'repositories', :action => 'revisions', :id => 'redmine', :repository_id => 'foo', Chris@1115: :format => 'atom' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2457" }, Chris@1115: { :controller => 'repositories', :action => 'revision', :id => 'redmine', :repository_id => 'foo', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2457/show" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2457/show/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] , :rev => '2457'} Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2457/diff" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', Chris@1115: :rev => '2457' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2457/diff" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', Chris@1115: :rev => '2457', :format => 'diff' }, Chris@1115: {}, Chris@1115: { :format => 'diff' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param], :rev => '2', :format => 'diff' }, Chris@1115: {}, Chris@1115: { :format => 'diff' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2/entry/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/2/annotate/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'annotate', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param], :rev => '2' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_non_revisions_path Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/changes" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine' } Chris@1115: ) Chris@1115: ['2457', 'master', 'slash/slash'].each do |rev| Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/changes" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine', Chris@1115: :rev => rev }, Chris@1115: {}, Chris@1115: { :rev => rev } Chris@1115: ) Chris@1115: end Chris@1115: ['2457', 'master', 'slash/slash'].each do |rev| Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine', Chris@1115: :path => @path_hash[:param], :rev => rev }, Chris@1115: {}, Chris@1115: { :rev => rev } Chris@1115: ) Chris@1115: end Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/browse/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'browse', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/entry/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'entry', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'raw', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/annotate/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'annotate', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/revision" }, Chris@1115: { :controller => 'repositories', :action => 'revision', :id => 'redmine' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_non_revisions_path_with_repository_id Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/changes" }, Chris@1115: { :controller => 'repositories', :action => 'changes', Chris@1115: :id => 'redmine', :repository_id => 'foo' } Chris@1115: ) Chris@1115: ['2457', 'master', 'slash/slash'].each do |rev| Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/changes" }, Chris@1115: { :controller => 'repositories', :action => 'changes', Chris@1115: :id => 'redmine', Chris@1115: :repository_id => 'foo', :rev => rev }, Chris@1115: {}, Chris@1115: { :rev => rev } Chris@1115: ) Chris@1115: end Chris@1115: ['2457', 'master', 'slash/slash'].each do |rev| Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/changes/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine', Chris@1115: :repository_id => 'foo', :path => @path_hash[:param], :rev => rev }, Chris@1115: {}, Chris@1115: { :rev => rev } Chris@1115: ) Chris@1115: end Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/diff/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/browse/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'browse', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/entry/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'raw', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/annotate/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'annotate', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/changes/#{@path_hash[:path]}" }, Chris@1115: { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', Chris@1115: :path => @path_hash[:param] } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'get', Chris@1115: :path => "/projects/redmine/repository/foo/revision" }, Chris@1115: { :controller => 'repositories', :action => 'revision', :id => 'redmine', :repository_id => 'foo'} Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_related_issues Chris@1115: assert_routing( Chris@1115: { :method => 'post', Chris@1115: :path => "/projects/redmine/repository/revisions/123/issues" }, Chris@1115: { :controller => 'repositories', :action => 'add_related_issue', Chris@1115: :id => 'redmine', :rev => '123' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'delete', Chris@1115: :path => "/projects/redmine/repository/revisions/123/issues/25" }, Chris@1115: { :controller => 'repositories', :action => 'remove_related_issue', Chris@1115: :id => 'redmine', :rev => '123', :issue_id => '25' } Chris@1115: ) Chris@1115: end Chris@1115: Chris@1115: def test_repositories_related_issues_with_repository_id Chris@1115: assert_routing( Chris@1115: { :method => 'post', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/123/issues" }, Chris@1115: { :controller => 'repositories', :action => 'add_related_issue', Chris@1115: :id => 'redmine', :repository_id => 'foo', :rev => '123' } Chris@1115: ) Chris@1115: assert_routing( Chris@1115: { :method => 'delete', Chris@1115: :path => "/projects/redmine/repository/foo/revisions/123/issues/25" }, Chris@1115: { :controller => 'repositories', :action => 'remove_related_issue', Chris@1115: :id => 'redmine', :repository_id => 'foo', :rev => '123', :issue_id => '25' } Chris@1115: ) Chris@1115: end Chris@1115: end