From 524cd689cf8743c389aab6a767a09383891dc5c6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 17 Dec 2007 21:00:56 +0000 Subject: [PATCH] Project identifier is now used in URLs (instead of project id). URLs with a project id will still be recognized. git-svn-id: http://redmine.rubyforge.org/svn/trunk@1007 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 14 ++++++++++++++ test/fixtures/projects.yml | 2 +- test/functional/issues_controller_test.rb | 2 +- test/functional/projects_controller_test.rb | 18 +++++++++++++----- test/functional/repositories_controller_test.rb | 4 ++-- test/functional/versions_controller_test.rb | 4 ++-- test/functional/wiki_controller_test.rb | 12 ++++++------ test/functional/wikis_controller_test.rb | 2 +- test/integration/issues_test.rb | 2 +- 9 files changed, 41 insertions(+), 19 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 84eeefee..60a7a84a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -111,6 +111,20 @@ class Project < ActiveRecord::Base end end + def self.find(*args) + if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/) + project = find_by_identifier(*args) + raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil? + project + else + super + end + end + + def to_param + identifier + end + def active? self.status == STATUS_ACTIVE end diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml index d3758c9e..ad5cf4aa 100644 --- a/test/fixtures/projects.yml +++ b/test/fixtures/projects.yml @@ -41,5 +41,5 @@ projects_004: description: eCookbook Subproject 2 homepage: "" is_public: true - identifier: subproject1 + identifier: subproject2 parent_id: 1 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 638362db..ebcf78f2 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -144,7 +144,7 @@ class IssuesControllerTest < Test::Unit::TestCase def test_destroy @request.session[:user_id] = 2 post :destroy, :id => 1 - assert_redirected_to 'projects/1/issues' + assert_redirected_to 'projects/ecookbook/issues' assert_nil Issue.find_by_id(1) end diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index b6ac5914..556d5d40 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -47,12 +47,20 @@ class ProjectsControllerTest < Test::Unit::TestCase assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) end - def test_show + def test_show_by_id get :show, :id => 1 assert_response :success assert_template 'show' assert_not_nil assigns(:project) end + + def test_show_by_identifier + get :show, :id => 'ecookbook' + assert_response :success + assert_template 'show' + assert_not_nil assigns(:project) + assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) + end def test_settings @request.session[:user_id] = 2 # manager @@ -64,7 +72,7 @@ class ProjectsControllerTest < Test::Unit::TestCase def test_edit @request.session[:user_id] = 2 # manager post :edit, :id => 1, :project => {:name => 'Test changed name'} - assert_redirected_to 'projects/settings/1' + assert_redirected_to 'projects/settings/ecookbook' project = Project.find(1) assert_equal 'Test changed name', project.name end @@ -104,7 +112,7 @@ class ProjectsControllerTest < Test::Unit::TestCase def test_move_issues_to_another_project @request.session[:user_id] = 1 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 - assert_redirected_to 'projects/1/issues' + assert_redirected_to 'projects/ecookbook/issues' assert_equal 2, Issue.find(1).project_id assert_equal 2, Issue.find(2).project_id end @@ -112,7 +120,7 @@ class ProjectsControllerTest < Test::Unit::TestCase def test_move_issues_to_another_tracker @request.session[:user_id] = 1 post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3 - assert_redirected_to 'projects/1/issues' + assert_redirected_to 'projects/ecookbook/issues' assert_equal 3, Issue.find(1).tracker_id assert_equal 3, Issue.find(2).tracker_id end @@ -242,7 +250,7 @@ class ProjectsControllerTest < Test::Unit::TestCase assert_response :success assert_template 'add_issue' post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5} - assert_redirected_to 'projects/1/issues' + assert_redirected_to 'projects/ecookbook/issues' assert Issue.find_by_subject('This is the test_add_issue issue') end diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 2f045950..47455dc5 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -43,10 +43,10 @@ class RepositoriesControllerTest < Test::Unit::TestCase assert_response :success assert_template 'revision' assert_no_tag :tag => "div", :attributes => { :class => "contextual" }, - :child => { :tag => "a", :attributes => { :href => '/repositories/revision/1?rev=0'} + :child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=0'} } assert_tag :tag => "div", :attributes => { :class => "contextual" }, - :child => { :tag => "a", :attributes => { :href => '/repositories/revision/1?rev=2'} + :child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=2'} } end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index 17ebd351..3477c5ed 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -52,7 +52,7 @@ class VersionsControllerTest < Test::Unit::TestCase post :edit, :id => 2, :version => { :name => 'New version name', :effective_date => Date.today.strftime("%Y-%m-%d")} - assert_redirected_to 'projects/settings/1' + assert_redirected_to 'projects/settings/ecookbook' version = Version.find(2) assert_equal 'New version name', version.name assert_equal Date.today, version.effective_date @@ -61,7 +61,7 @@ class VersionsControllerTest < Test::Unit::TestCase def test_destroy @request.session[:user_id] = 2 post :destroy, :id => 2 - assert_redirected_to 'projects/settings/1' + assert_redirected_to 'projects/settings/ecookbook' assert_nil Version.find_by_id(2) end diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 6ee5ab27..043b0e80 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -64,7 +64,7 @@ class WikiControllerTest < Test::Unit::TestCase :content => {:comments => 'Created the page', :text => "h1. New page\n\nThis is a new page", :version => 0} - assert_redirected_to 'wiki/1/New_page' + assert_redirected_to 'wiki/ecookbook/New_page' page = Project.find(1).wiki.find_page('New page') assert !page.new_record? assert_not_nil page.content @@ -103,7 +103,7 @@ class WikiControllerTest < Test::Unit::TestCase post :rename, :id => 1, :page => 'Another_page', :wiki_page => { :title => 'Another renamed page', :redirect_existing_links => 1 } - assert_redirected_to 'wiki/1/Another_renamed_page' + assert_redirected_to 'wiki/ecookbook/Another_renamed_page' wiki = Project.find(1).wiki # Check redirects assert_not_nil wiki.find_page('Another page') @@ -115,7 +115,7 @@ class WikiControllerTest < Test::Unit::TestCase post :rename, :id => 1, :page => 'Another_page', :wiki_page => { :title => 'Another renamed page', :redirect_existing_links => "0" } - assert_redirected_to 'wiki/1/Another_renamed_page' + assert_redirected_to 'wiki/ecookbook/Another_renamed_page' wiki = Project.find(1).wiki # Check that there's no redirects assert_nil wiki.find_page('Another page') @@ -124,17 +124,17 @@ class WikiControllerTest < Test::Unit::TestCase def test_destroy @request.session[:user_id] = 2 post :destroy, :id => 1, :page => 'CookBook_documentation' - assert_redirected_to 'wiki/1/Page_index/special' + assert_redirected_to 'wiki/ecookbook/Page_index/special' end def test_page_index - get :special, :id => 1, :page => 'Page_index' + get :special, :id => 'ecookbook', :page => 'Page_index' assert_response :success assert_template 'special_page_index' pages = assigns(:pages) assert_not_nil pages assert_equal 2, pages.size - assert_tag :tag => 'a', :attributes => { :href => '/wiki/1/CookBook_documentation' }, + assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, :content => /CookBook documentation/ end diff --git a/test/functional/wikis_controller_test.rb b/test/functional/wikis_controller_test.rb index 93ad7e32..3e51314a 100644 --- a/test/functional/wikis_controller_test.rb +++ b/test/functional/wikis_controller_test.rb @@ -44,7 +44,7 @@ class WikisControllerTest < Test::Unit::TestCase def test_destroy @request.session[:user_id] = 1 post :destroy, :id => 1, :confirm => 1 - assert_redirected_to 'projects/settings/1' + assert_redirected_to 'projects/settings/ecookbook' assert_nil Project.find(1).wiki end diff --git a/test/integration/issues_test.rb b/test/integration/issues_test.rb index eac407b1..702fbc02 100644 --- a/test/integration/issues_test.rb +++ b/test/integration/issues_test.rb @@ -24,7 +24,7 @@ class IssuesTest < ActionController::IntegrationTest assert_kind_of Issue, issue # check redirection - assert_redirected_to "projects/1/issues" + assert_redirected_to "projects/ecookbook/issues" follow_redirect! assert assigns(:issues).include?(issue) -- 2.11.0