Commit e0986842 authored by edavis10's avatar edavis10

Converted routing and urls to follow the Rails REST convention.

Patch supplied by commits from Gerrit Kaiser on Github.  Existing routes will
still work (backwards compatible) but any new urls will be generated using the
new routing rules.

Changes listed below:

* made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id
* prettier URL for project roadmap
* more nice project URLs
* use GET for filtering form
* prettified URLs used on issues tab
* custom route for activity atom feeds
* prettier repository urls
* fixed broken route definition
* fixed failing tests for issuecontroller that were hardcoding the url string
* more RESTful routes for boards and messages
* RESTful routes for wiki pages
* RESTful routes for documents
* moved old routes that are retained for compatibility to the bottom and grouped them together
* added RESTful URIs for issues
* RESTfulness for the news section
* fixed route order
* changed hardcoded URLs in tests
* fixed badly written tests
* fixed forgotten parameter in routes
* changed hardcoded URLS to new scheme
* changed project add url to the standard POST to collection
* create new issue by POSTing to collection
* changed hardcoded URLs in integrations tests
* made project add form work again
* restful routes for project deletion
* prettier routes for project (un)archival
* made routes table more readable
* fixed note quoting
* user routing
* fixed bug
* always sort by GET
* Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled.
* prettified URLs used on issues tab
* urls for time log
* fixed reply routing
* eliminate revision query paremeter for diff and entry actions
* fixed test failures with hard-coded urls
* ensure ajax links always use get
* refactored ajax link generation into separate method

  #1901


git-svn-id: https://svn.redmine.org/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 569b817b
......@@ -243,39 +243,36 @@ module ApplicationHelper
url_param.clear if url_param.has_key?(:set_filter)
html = ''
html << link_to_remote(('&#171; ' + l(:label_previous)),
{:update => 'content',
:url => url_param.merge(page_param => paginator.current.previous),
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
if paginator.current.previous
html << link_to_remote_content_update('&#171; ' + l(:label_previous), url_param.merge(page_param => paginator.current.previous)) + ' '
end
html << (pagination_links_each(paginator, options) do |n|
link_to_remote(n.to_s,
{:url => {:params => url_param.merge(page_param => n)},
:update => 'content',
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => n))})
link_to_remote_content_update(n.to_s, url_param.merge(page_param => n))
end || '')
html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
{:update => 'content',
:url => url_param.merge(page_param => paginator.current.next),
:complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
if paginator.current.next
html << ' ' + link_to_remote_content_update((l(:label_next) + ' &#187;'), url_param.merge(page_param => paginator.current.next))
end
unless count.nil?
html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
html << [
" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})",
per_page_links(paginator.items_per_page)
].compact.join(' | ')
end
html
end
def per_page_links(selected=nil)
url_param = params.dup
url_param.clear if url_param.has_key?(:set_filter)
links = Setting.per_page_options_array.collect do |n|
n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
n == selected ? n : link_to_remote(n, {:update => "content",
:url => params.dup.merge(:per_page => n),
:method => :get},
{:href => url_for(url_param.merge(:per_page => n))})
end
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
......@@ -664,4 +661,12 @@ module ApplicationHelper
extend helper
return self
end
def link_to_remote_content_update(text, url_params)
link_to_remote(text,
{:url => url_params, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'},
{:href => url_for(:params => url_params)}
)
end
end
......@@ -121,7 +121,7 @@ module SortHelper
url_options = params.has_key?(:set_filter) ? sort_options : params.merge(sort_options)
link_to_remote(caption,
{:update => "content", :url => url_options},
{:update => "content", :url => url_options, :method => :get},
{:href => url_for(url_options)}) +
(icon ? nbsp(2) + image_tag(icon) : '')
end
......
......@@ -26,7 +26,7 @@
<% end %>
<% content_for :sidebar do %>
<% form_tag do %>
<% form_tag({},:method => :get) do %>
<h3><%= l(:label_change_log) %></h3>
<% @trackers.each do |tracker| %>
<label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %>
......
......@@ -6,7 +6,9 @@
<h2><%= l(:label_spent_time) %></h2>
<% form_remote_tag( :url => {}, :method => :get, :update => 'content' ) do %>
<% form_remote_tag( :url => {}, :html => {:method => :get}, :method => :get, :update => 'content' ) do %>
<%# TOOD: remove the project_id and issue_id hidden fields, that information is
already in the URI %>
<%= hidden_field_tag 'project_id', params[:project_id] %>
<%= hidden_field_tag 'issue_id', params[:issue_id] if @issue %>
<%= render :partial => 'date_range' %>
......
......@@ -6,10 +6,11 @@
<h2><%= l(:label_spent_time) %></h2>
<% form_remote_tag(:url => {}, :update => 'content') do %>
<% form_remote_tag(:url => {}, :html => {:method => :get}, :method => :get, :update => 'content') do %>
<% @criterias.each do |criteria| %>
<%= hidden_field_tag 'criterias[]', criteria, :id => nil %>
<% end %>
<%# TODO: get rid of the project_id field, that should already be in the URL %>
<%= hidden_field_tag 'project_id', params[:project_id] %>
<%= render :partial => 'date_range' %>
......@@ -25,6 +26,7 @@
:id => nil,
:disabled => (@criterias.length >= 3)) %>
<%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :period_type => params[:period_type], :period => params[:period], :from => @from, :to => @to, :columns => @columns},
:method => :get,
:update => 'content'
}, :class => 'icon icon-reload' %></p>
<% end %>
......
<% labelled_tabular_form_for :user, @user, :url => { :action => "edit" } do |f| %>
<% labelled_tabular_form_for :user, @user, :url => { :action => "edit", :tab => nil } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
<% end %>
This diff is collapsed.
......@@ -38,6 +38,13 @@ class AdminControllerTest < Test::Unit::TestCase
:attributes => { :class => /nodata/ }
end
def test_projects_routing
assert_routing(
{:method => :get, :path => '/admin/projects'},
:controller => 'admin', :action => 'projects'
)
end
def test_index_with_no_configuration_data
delete_configuration_data
get :index
......
......@@ -31,6 +31,13 @@ class BoardsControllerTest < Test::Unit::TestCase
User.current = nil
end
def test_index_routing
assert_routing(
{:method => :get, :path => '/projects/world_domination/boards'},
:controller => 'boards', :action => 'index', :project_id => 'world_domination'
)
end
def test_index
get :index, :project_id => 1
assert_response :success
......@@ -39,6 +46,24 @@ class BoardsControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:project)
end
def test_new_routing
assert_routing(
{:method => :get, :path => '/projects/world_domination/boards/new'},
:controller => 'boards', :action => 'new', :project_id => 'world_domination'
)
assert_recognizes(
{:controller => 'boards', :action => 'new', :project_id => 'world_domination'},
{:method => :post, :path => '/projects/world_domination/boards'}
)
end
def test_show_routing
assert_routing(
{:method => :get, :path => '/projects/world_domination/boards/44'},
:controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination'
)
end
def test_show
get :show, :project_id => 1, :id => 1
assert_response :success
......@@ -47,4 +72,22 @@ class BoardsControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:project)
assert_not_nil assigns(:topics)
end
def test_edit_routing
assert_routing(
{:method => :get, :path => '/projects/world_domination/boards/44/edit'},
:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'
)
assert_recognizes(#TODO: use PUT method to board_path, modify form accordingly
{:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'},
{:method => :post, :path => '/projects/world_domination/boards/44/edit'}
)
end
def test_destroy_routing
assert_routing(#TODO: use DELETE method to board_path, modify form accoringly
{:method => :post, :path => '/projects/world_domination/boards/44/destroy'},
:controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination'
)
end
end
......@@ -30,7 +30,14 @@ class DocumentsControllerTest < Test::Unit::TestCase
@response = ActionController::TestResponse.new
User.current = nil
end
def test_index_routing
assert_routing(
{:method => :get, :path => '/projects/567/documents'},
:controller => 'documents', :action => 'index', :project_id => '567'
)
end
def test_index
# Sets a default category
e = Enumeration.find_by_name('Technical documentation')
......@@ -47,6 +54,17 @@ class DocumentsControllerTest < Test::Unit::TestCase
:content => 'Technical documentation'}
end
def test_new_routing
assert_routing(
{:method => :get, :path => '/projects/567/documents/new'},
:controller => 'documents', :action => 'new', :project_id => '567'
)
assert_recognizes(
{:controller => 'documents', :action => 'new', :project_id => '567'},
{:method => :post, :path => '/projects/567/documents'}
)
end
def test_new_with_one_attachment
@request.session[:user_id] = 2
set_tmp_attachments_directory
......@@ -66,6 +84,31 @@ class DocumentsControllerTest < Test::Unit::TestCase
assert_equal 'testfile.txt', document.attachments.first.filename
end
def test_edit_routing
assert_routing(
{:method => :get, :path => '/documents/22/edit'},
:controller => 'documents', :action => 'edit', :id => '22'
)
assert_recognizes(#TODO: should be using PUT on document URI
{:controller => 'documents', :action => 'edit', :id => '567'},
{:method => :post, :path => '/documents/567/edit'}
)
end
def test_show_routing
assert_routing(
{:method => :get, :path => '/documents/22'},
:controller => 'documents', :action => 'show', :id => '22'
)
end
def test_destroy_routing
assert_recognizes(#TODO: should be using DELETE on document URI
{:controller => 'documents', :action => 'destroy', :id => '567'},
{:method => :post, :path => '/documents/567/destroy'}
)
end
def test_destroy
@request.session[:user_id] = 2
post :destroy, :id => 1
......
require File.dirname(__FILE__) + '/../test_helper'
require 'issue_relations_controller'
# Re-raise errors caught by the controller.
class IssueRelationsController; def rescue_action(e) raise e end; end
class IssueRelationsControllerTest < Test::Unit::TestCase
def test_new_routing
assert_routing(
{:method => :post, :path => '/issues/1/relations'},
{:controller => 'issue_relations', :action => 'new', :issue_id => '1'}
)
end
def test_destroy_routing
assert_recognizes( #TODO: use DELETE on issue URI
{:controller => 'issue_relations', :action => 'destroy', :issue_id => '1', :id => '23'},
{:method => :post, :path => '/issues/1/relations/23/destroy'}
)
end
end
This diff is collapsed.
require File.dirname(__FILE__) + '/../test_helper'
require 'members_controller'
# Re-raise errors caught by the controller.
class MembersController; def rescue_action(e) raise e end; end
class MembersControllerTest < Test::Unit::TestCase
def test_members_routing
assert_routing(
{:method => :post, :path => 'projects/5234/members/new'},
:controller => 'members', :action => 'new', :id => '5234'
)
end
end
......@@ -31,6 +31,13 @@ class MessagesControllerTest < Test::Unit::TestCase
User.current = nil
end
def test_show_routing
assert_routing(
{:method => :get, :path => '/boards/22/topics/2'},
:controller => 'messages', :action => 'show', :id => '2', :board_id => '22'
)
end
def test_show
get :show, :board_id => 1, :id => 1
assert_response :success
......@@ -54,6 +61,17 @@ class MessagesControllerTest < Test::Unit::TestCase
assert_response 404
end
def test_new_routing
assert_routing(
{:method => :get, :path => '/boards/lala/topics/new'},
:controller => 'messages', :action => 'new', :board_id => 'lala'
)
assert_recognizes(#TODO: POST to collection, need to adjust form accordingly
{:controller => 'messages', :action => 'new', :board_id => 'lala'},
{:method => :post, :path => '/boards/lala/topics/new'}
)
end
def test_get_new
@request.session[:user_id] = 2
get :new, :board_id => 1
......@@ -86,6 +104,17 @@ class MessagesControllerTest < Test::Unit::TestCase
assert mail.bcc.include?('dlopper@somenet.foo')
end
def test_edit_routing
assert_routing(
{:method => :get, :path => '/boards/lala/topics/22/edit'},
:controller => 'messages', :action => 'edit', :board_id => 'lala', :id => '22'
)
assert_recognizes( #TODO: use PUT to topic_path, modify form accordingly
{:controller => 'messages', :action => 'edit', :board_id => 'lala', :id => '22'},
{:method => :post, :path => '/boards/lala/topics/22/edit'}
)
end
def test_get_edit
@request.session[:user_id] = 2
get :edit, :board_id => 1, :id => 1
......@@ -104,6 +133,13 @@ class MessagesControllerTest < Test::Unit::TestCase
assert_equal 'New body', message.content
end
def test_reply_routing
assert_recognizes(
{:controller => 'messages', :action => 'reply', :board_id => '22', :id => '555'},
{:method => :post, :path => '/boards/22/topics/555/replies'}
)
end
def test_reply
@request.session[:user_id] = 2
post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
......@@ -111,6 +147,13 @@ class MessagesControllerTest < Test::Unit::TestCase
assert Message.find_by_subject('Test reply')
end
def test_destroy_routing
assert_recognizes(#TODO: use DELETE to topic_path, adjust form accordingly
{:controller => 'messages', :action => 'destroy', :board_id => '22', :id => '555'},
{:method => :post, :path => '/boards/22/topics/555/destroy'}
)
end
def test_destroy_topic
@request.session[:user_id] = 2
post :destroy, :board_id => 1, :id => 1
......
......@@ -31,6 +31,20 @@ class NewsControllerTest < Test::Unit::TestCase
User.current = nil
end
def test_index_routing
assert_routing(
{:method => :get, :path => '/news'},
:controller => 'news', :action => 'index'
)
end
def test_index_routing_formatted
assert_routing(
{:method => :get, :path => '/news.atom'},
:controller => 'news', :action => 'index', :format => 'atom'
)
end
def test_index
get :index
assert_response :success
......@@ -38,6 +52,20 @@ class NewsControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:newss)
assert_nil assigns(:project)
end
def test_index_with_project_routing
assert_routing(
{:method => :get, :path => '/projects/567/news'},
:controller => 'news', :action => 'index', :project_id => '567'
)
end
def test_index_with_project_routing_formatted
assert_routing(
{:method => :get, :path => '/projects/567/news.atom'},
:controller => 'news', :action => 'index', :project_id => '567', :format => 'atom'
)
end
def test_index_with_project
get :index, :project_id => 1
......@@ -46,6 +74,13 @@ class NewsControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:newss)
end
def test_show_routing
assert_routing(
{:method => :get, :path => '/news/2'},
:controller => 'news', :action => 'show', :id => '2'
)
end
def test_show
get :show, :id => 1
assert_response :success
......@@ -58,6 +93,17 @@ class NewsControllerTest < Test::Unit::TestCase
assert_response 404
end
def test_new_routing
assert_routing(
{:method => :get, :path => '/projects/567/news/new'},
:controller => 'news', :action => 'new', :project_id => '567'
)
assert_recognizes(
{:controller => 'news', :action => 'new', :project_id => '567'},
{:method => :post, :path => '/projects/567/news'}
)
end
def test_get_new
@request.session[:user_id] = 2
get :new, :project_id => 1
......@@ -79,6 +125,17 @@ class NewsControllerTest < Test::Unit::TestCase
assert_equal Project.find(1), news.project
end
def test_edit_routing
assert_routing(
{:method => :get, :path => '/news/234'},
:controller => 'news', :action => 'show', :id => '234'
)
assert_recognizes(#TODO: PUT to news URI instead, need to modify form
{:controller => 'news', :action => 'edit', :id => '567'},
{:method => :post, :path => '/news/567/edit'}
)
end
def test_get_edit
@request.session[:user_id] = 2
get :edit, :id => 1
......@@ -127,6 +184,13 @@ class NewsControllerTest < Test::Unit::TestCase
assert_equal comments_count - 1, News.find(1).comments.size
end
def test_destroy_routing
assert_recognizes(#TODO: should use DELETE to news URI, need to change form
{:controller => 'news', :action => 'destroy', :id => '567'},
{:method => :post, :path => '/news/567/destroy'}
)
end
def test_destroy
@request.session[:user_id] = 2
post :destroy, :id => 1
......
......@@ -33,7 +33,14 @@ class ProjectsControllerTest < Test::Unit::TestCase
@request.session[:user_id] = nil
Setting.default_language = 'en'
end
def test_index_routing
assert_routing(
{:method => :get, :path => '/projects'},
:controller => 'projects', :action => 'index'
)
end
def test_index
get :index
assert_response :success
......@@ -50,7 +57,14 @@ class ProjectsControllerTest < Test::Unit::TestCase
}
assert_no_tag :a, :content => /Private child of eCookbook/
end
end
def test_index_atom_routing
assert_routing(
{:method => :get, :path => '/projects.atom'},
:controller => 'projects', :action => 'index', :format => 'atom'
)
end
def test_index_atom
get :index, :format => 'atom'
......@@ -59,12 +73,34 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_select 'feed>title', :text => 'Redmine: Latest projects'
assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
end
def test_show_by_id
get :show, :id => 1
def test_add_routing
assert_routing(
{:method => :get, :path => '/projects/new'},
:controller => 'projects', :action => 'add'
)
assert_recognizes(
{:controller => 'projects', :action => 'add'},
{:method => :post, :path => '/projects/new'}
)
assert_recognizes(
{:controller => 'projects', :action => 'add'},
{:method => :post, :path => '/projects'}
)
end
def test_show_routing
assert_routing(
{:method => :get, :path => '/projects/test'},
:controller => 'projects', :action => 'show', :id => 'test'
)
end
def test_show_by_id
get :show, :id => 1
assert_response :success
assert_template 'show'
assert_not_nil assigns(:project)
assert_template 'show'
assert_not_nil assigns(:project)
end
def test_show_by_identifier
......@@ -90,6 +126,17 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_tag :tag => 'a', :content => /Private child/
end
def test_settings_routing
assert_routing(
{:method => :get, :path => '/projects/4223/settings'},
:controller => 'projects', :action => 'settings', :id => '4223'
)
assert_routing(
{:method => :get, :path => '/projects/4223/settings/members'},
:controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
)
end
def test_settings
@request.session[:user_id] = 2 # manager
get :settings, :id => 1
......@@ -106,13 +153,49 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_equal 'Test changed name', project.name
end
def test_add_version_routing
assert_routing(
{:method => :get, :path => 'projects/64/versions/new'},
:controller => 'projects', :action => 'add_version', :id => '64'
)
assert_routing(
#TODO: use PUT
{:method => :post, :path => 'projects/64/versions/new'},
:controller => 'projects', :action => 'add_version', :id => '64'
)
end
def test_add_issue_category_routing
assert_routing(
{:method => :get, :path => 'projects/test/categories/new'},
:controller => 'projects', :action => 'add_issue_category', :id => 'test'
)
assert_routing(
#TODO: use PUT and update form
{:method => :post, :path => 'projects/64/categories/new'},
:controller => 'projects', :action => 'add_issue_category', :id => '64'
)
end
def test_destroy_routing
assert_routing(
{:method => :get, :path => '/projects/567/destroy'},
:controller => 'projects', :action => 'destroy', :id => '567'
)
assert_routing(
#TODO: use DELETE and update form
{:method => :post, :path => 'projects/64/destroy'},
:controller => 'projects', :action => 'destroy', :id => '64'
)
end
def test_get_destroy
@request.session[:user_id] = 1 # admin
get :destroy, :id => 1
assert_response :success
assert_template 'destroy'
assert_not_nil Project.find_by_id(1)
end
end
def test_post_destroy
@request.session[:user_id] = 1 # admin
......@@ -142,6 +225,17 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert mail.body.include?('testfile.txt')
end
def test_add_file_routing
assert_routing(
{:method => :get, :path => '/projects/33/files/new'},
:controller => 'projects', :action => 'add_file', :id => '33'
)
assert_routing(
{:method => :post, :path => '/projects/33/files/new'},
:controller => 'projects', :action => 'add_file', :id => '33'
)
end
def test_add_version_file
set_tmp_attachments_directory
@request.session[:user_id] = 2
......@@ -156,27 +250,48 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_equal 'testfile.txt', a.filename
assert_equal Version.find(2), a.container
end
def test_list_files
get :list_files, :id => 1
assert_response :success
assert_template 'list_files'
def test_list_files
get :list_files, :id => 1
assert_response :success
assert_template 'list_files'
assert_not_nil assigns(:containers)
# file attached to the project
assert_tag :a, :content => 'project_file.zip',
:attributes => { :href => '/attachments/download/8/project_file.zip' }
# file attached to a project's version
assert_tag :a, :content => 'version_file.zip',
:attributes => { :href => '/attachments/download/9/version_file.zip' }
end
def test_changelog
get :changelog, :id => 1
assert_response :success
assert_template 'changelog'
assert_not_nil assigns(:versions)
end
def test_list_files_routing
assert_routing(
{:method => :get, :path => '/projects/33/files'},
:controller => 'projects', :action => 'list_files', :id => '33'
)
end
def test_changelog_routing
assert_routing(
{:method => :get, :path => '/projects/44/changelog'},