From 6577f37fc3c332a6d5e5a50f6d30820b93143436 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 22 Nov 2011 21:32:45 +0000 Subject: [PATCH] Resourcified trackers. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7888 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/trackers_controller.rb | 23 +++++++++--- app/helpers/application_helper.rb | 10 ++--- app/views/trackers/edit.html.erb | 4 +- app/views/trackers/index.html.erb | 10 ++--- app/views/trackers/new.html.erb | 4 +- config/routes.rb | 2 +- test/functional/trackers_controller_test.rb | 41 ++++++++++++++------- 7 files changed, 59 insertions(+), 35 deletions(-) diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb index 2f827af2e..1a7022f37 100644 --- a/app/controllers/trackers_controller.rb +++ b/app/controllers/trackers_controller.rb @@ -22,8 +22,6 @@ class TrackersController < ApplicationController before_filter :require_admin_or_api_request, :only => :index accept_api_auth :index - verify :method => :post, :only => :destroy, :redirect_to => { :action => :index } - def index respond_to do |format| format.html { @@ -37,6 +35,12 @@ class TrackersController < ApplicationController end def new + @tracker ||= Tracker.new(params[:tracker]) + @trackers = Tracker.find :all, :order => 'position' + @projects = Project.find(:all) + end + + def create @tracker = Tracker.new(params[:tracker]) if request.post? and @tracker.save # workflow copy @@ -47,20 +51,27 @@ class TrackersController < ApplicationController redirect_to :action => 'index' return end - @trackers = Tracker.find :all, :order => 'position' - @projects = Project.find(:all) + new + render :action => 'new' end def edit + @tracker ||= Tracker.find(params[:id]) + @projects = Project.find(:all) + end + + def update @tracker = Tracker.find(params[:id]) - if request.post? and @tracker.update_attributes(params[:tracker]) + if request.put? and @tracker.update_attributes(params[:tracker]) flash[:notice] = l(:notice_successful_update) redirect_to :action => 'index' return end - @projects = Project.find(:all) + edit + render :action => 'edit' end + verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index } def destroy @tracker = Tracker.find(params[:id]) unless @tracker.issues.empty? diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 764ef002e..56807adb3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -391,19 +391,19 @@ module ApplicationHelper links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil end - def reorder_links(name, url) + def reorder_links(name, url, method = :post) link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), - :method => :post, :title => l(:label_sort_highest)) + + :method => method, :title => l(:label_sort_highest)) + link_to(image_tag('1uparrow.png', :alt => l(:label_sort_higher)), url.merge({"#{name}[move_to]" => 'higher'}), - :method => :post, :title => l(:label_sort_higher)) + + :method => method, :title => l(:label_sort_higher)) + link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), - :method => :post, :title => l(:label_sort_lower)) + + :method => method, :title => l(:label_sort_lower)) + link_to(image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), url.merge({"#{name}[move_to]" => 'lowest'}), - :method => :post, :title => l(:label_sort_lowest)) + :method => method, :title => l(:label_sort_lowest)) end def breadcrumb(*args) diff --git a/app/views/trackers/edit.html.erb b/app/views/trackers/edit.html.erb index 135bafd5f..d7ba2591c 100644 --- a/app/views/trackers/edit.html.erb +++ b/app/views/trackers/edit.html.erb @@ -1,5 +1,5 @@ -

<%= link_to l(:label_tracker_plural), :controller => 'trackers', :action => 'index' %> » <%=h @tracker %>

+

<%= link_to l(:label_tracker_plural), trackers_path %> » <%=h @tracker %>

-<% form_for :tracker, @tracker, :url => { :action => 'edit' }, :builder => TabularFormBuilder do |f| %> +<% form_for @tracker, :builder => TabularFormBuilder do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <% end %> diff --git a/app/views/trackers/index.html.erb b/app/views/trackers/index.html.erb index 3234d312b..ef48bdc9e 100644 --- a/app/views/trackers/index.html.erb +++ b/app/views/trackers/index.html.erb @@ -1,5 +1,5 @@
-<%= link_to l(:label_tracker_new), {:action => 'new'}, :class => 'icon icon-add' %> +<%= link_to l(:label_tracker_new), new_tracker_path, :class => 'icon icon-add' %>

<%=l(:label_tracker_plural)%>

@@ -14,12 +14,12 @@ <% for tracker in @trackers %> "> - <%= link_to h(tracker.name), :action => 'edit', :id => tracker %> + <%= link_to h(tracker.name), edit_tracker_path(tracker) %> <% unless tracker.workflows.count > 0 %><%= l(:text_tracker_no_workflow) %> (<%= link_to l(:button_edit), {:controller => 'workflows', :action => 'edit', :tracker_id => tracker} %>)<% end %> - <%= reorder_links('tracker', {:action => 'edit', :id => tracker}) %> + <%= reorder_links('tracker', {:action => 'update', :id => tracker}, :put) %> - <%= link_to(l(:button_delete), { :action => 'destroy', :id => tracker }, - :method => :post, + <%= link_to(l(:button_delete), tracker_path(tracker), + :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> diff --git a/app/views/trackers/new.html.erb b/app/views/trackers/new.html.erb index db32471dc..93b0bc1ae 100644 --- a/app/views/trackers/new.html.erb +++ b/app/views/trackers/new.html.erb @@ -1,5 +1,5 @@ -

<%= link_to l(:label_tracker_plural), :controller => 'trackers', :action => 'index' %> » <%=l(:label_tracker_new)%>

+

<%= link_to l(:label_tracker_plural), trackers_path %> » <%=l(:label_tracker_new)%>

-<% form_for :tracker, @tracker, :url => { :action => 'new' }, :builder => TabularFormBuilder do |f| %> +<% form_for @tracker, :builder => TabularFormBuilder do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 8d5735cff..813399187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -222,9 +222,9 @@ ActionController::Routing::Routes.draw do |map| map.connect 'attachments/download/:id/:filename', :controller => 'attachments', :action => 'download', :id => /\d+/, :filename => /.*/ map.resources :groups + map.resources :trackers, :except => :show #left old routes at the bottom for backwards compat - map.connect 'trackers.:format', :controller => 'trackers', :action => 'index' map.connect 'issue_statuses.:format', :controller => 'issue_statuses', :action => 'index' map.connect 'projects/:project_id/issues/:action', :controller => 'issues' map.connect 'projects/:project_id/documents/:action', :controller => 'documents' diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb index 4d9b228f1..bc5b26401 100644 --- a/test/functional/trackers_controller_test.rb +++ b/test/functional/trackers_controller_test.rb @@ -50,30 +50,43 @@ class TrackersControllerTest < ActionController::TestCase assert_response 406 end - def test_get_new + def test_new get :new assert_response :success assert_template 'new' end - def test_post_new - post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } + def test_create + assert_difference 'Tracker.count' do + post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } + end assert_redirected_to :action => 'index' - tracker = Tracker.find_by_name('New tracker') + tracker = Tracker.first(:order => 'id DESC') + assert_equal 'New tracker', tracker.name assert_equal [1], tracker.project_ids.sort assert_equal [1, 6], tracker.custom_field_ids assert_equal 0, tracker.workflows.count end - def test_post_new_with_workflow_copy - post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 + def test_create_new_with_workflow_copy + assert_difference 'Tracker.count' do + post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 + end assert_redirected_to :action => 'index' tracker = Tracker.find_by_name('New tracker') assert_equal 0, tracker.projects.count assert_equal Tracker.find(1).workflows.count, tracker.workflows.count end - def test_get_edit + def test_create_new_failure + assert_no_difference 'Tracker.count' do + post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } + end + assert_response :success + assert_template 'new' + end + + def test_edit Tracker.find(1).project_ids = [1, 3] get :edit, :id => 1 @@ -93,15 +106,15 @@ class TrackersControllerTest < ActionController::TestCase :type => 'hidden'} end - def test_post_edit - post :edit, :id => 1, :tracker => { :name => 'Renamed', + def test_update + put :update, :id => 1, :tracker => { :name => 'Renamed', :project_ids => ['1', '2', ''] } assert_redirected_to :action => 'index' assert_equal [1, 2], Tracker.find(1).project_ids.sort end - def test_post_edit_without_projects - post :edit, :id => 1, :tracker => { :name => 'Renamed', + def test_update_without_projects + put :update, :id => 1, :tracker => { :name => 'Renamed', :project_ids => [''] } assert_redirected_to :action => 'index' assert Tracker.find(1).project_ids.empty? @@ -109,14 +122,14 @@ class TrackersControllerTest < ActionController::TestCase def test_move_lower tracker = Tracker.find_by_position(1) - post :edit, :id => 1, :tracker => { :move_to => 'lower' } + put :update, :id => 1, :tracker => { :move_to => 'lower' } assert_equal 2, tracker.reload.position end def test_destroy tracker = Tracker.create!(:name => 'Destroyable') assert_difference 'Tracker.count', -1 do - post :destroy, :id => tracker.id + delete :destroy, :id => tracker.id end assert_redirected_to :action => 'index' assert_nil flash[:error] @@ -124,7 +137,7 @@ class TrackersControllerTest < ActionController::TestCase def test_destroy_tracker_in_use assert_no_difference 'Tracker.count' do - post :destroy, :id => 1 + delete :destroy, :id => 1 end assert_redirected_to :action => 'index' assert_not_nil flash[:error] -- 2.39.5