summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/trackers_controller.rb24
-rw-r--r--app/helpers/application_helper.rb7
-rw-r--r--app/views/trackers/list.rhtml7
-rw-r--r--test/functional/trackers_controller_test.rb53
-rw-r--r--vendor/plugins/acts_as_list/lib/active_record/acts/list.rb14
5 files changed, 78 insertions, 27 deletions
diff --git a/app/controllers/trackers_controller.rb b/app/controllers/trackers_controller.rb
index 51e70ddf4..cf797d853 100644
--- a/app/controllers/trackers_controller.rb
+++ b/app/controllers/trackers_controller.rb
@@ -1,5 +1,5 @@
-# redMine - project management software
-# Copyright (C) 2006 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2009 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -22,9 +22,8 @@ class TrackersController < ApplicationController
list
render :action => 'list' unless request.xhr?
end
-
- # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
- verify :method => :post, :only => [ :destroy, :move ], :redirect_to => { :action => :list }
+
+ verify :method => :post, :only => :destroy, :redirect_to => { :action => :list }
def list
@tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
@@ -55,21 +54,6 @@ class TrackersController < ApplicationController
end
@projects = Project.find(:all)
end
-
- def move
- @tracker = Tracker.find(params[:id])
- case params[:position]
- when 'highest'
- @tracker.move_to_top
- when 'higher'
- @tracker.move_higher
- when 'lower'
- @tracker.move_lower
- when 'lowest'
- @tracker.move_to_bottom
- end if params[:position]
- redirect_to :action => 'list'
- end
def destroy
@tracker = Tracker.find(params[:id])
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 2e95ca5ff..1eabadcfc 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -265,6 +265,13 @@ module ApplicationHelper
end
links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
end
+
+ def reorder_links(name, url)
+ link_to(image_tag('2uparrow.png', :alt => l(:label_sort_highest)), url.merge({"#{name}[move_to]" => 'highest'}), :method => :post, :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)) +
+ link_to(image_tag('1downarrow.png', :alt => l(:label_sort_lower)), url.merge({"#{name}[move_to]" => 'lower'}), :method => :post, :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))
+ end
def breadcrumb(*args)
elements = args.flatten
diff --git a/app/views/trackers/list.rhtml b/app/views/trackers/list.rhtml
index 2531f334b..06eaf7105 100644
--- a/app/views/trackers/list.rhtml
+++ b/app/views/trackers/list.rhtml
@@ -16,12 +16,7 @@
<tr class="<%= cycle("odd", "even") %>">
<td><%= link_to tracker.name, :action => 'edit', :id => tracker %></td>
<td align="center"><% unless tracker.workflows.count > 0 %><span class="icon icon-warning"><%= l(:text_tracker_no_workflow) %> (<%= link_to l(:button_edit), {:controller => 'workflows', :action => 'edit', :tracker_id => tracker} %>)</span><% end %></td>
- <td align="center" style="width:15%;">
- <%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:action => 'move', :id => tracker, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %>
- <%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:action => 'move', :id => tracker, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> -
- <%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:action => 'move', :id => tracker, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %>
- <%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:action => 'move', :id => tracker, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %>
- </td>
+ <td align="center" style="width:15%;"><%= reorder_links('tracker', {:action => 'edit', :id => tracker}) %></td>
<td align="center" style="width:10%;">
<%= button_to l(:button_delete), { :action => 'destroy', :id => tracker }, :confirm => l(:text_are_you_sure), :class => "button-small" %>
</td>
diff --git a/test/functional/trackers_controller_test.rb b/test/functional/trackers_controller_test.rb
index 89bbf228f..e2109ba6f 100644
--- a/test/functional/trackers_controller_test.rb
+++ b/test/functional/trackers_controller_test.rb
@@ -22,7 +22,7 @@ require 'trackers_controller'
class TrackersController; def rescue_action(e) raise e end; end
class TrackersControllerTest < Test::Unit::TestCase
- fixtures :trackers, :projects, :projects_trackers, :users
+ fixtures :trackers, :projects, :projects_trackers, :users, :issues
def setup
@controller = TrackersController.new
@@ -32,6 +32,34 @@ class TrackersControllerTest < Test::Unit::TestCase
@request.session[:user_id] = 1 # admin
end
+ def test_index
+ get :index
+ assert_response :success
+ assert_template 'list'
+ end
+
+ def test_get_new
+ get :new
+ assert_response :success
+ assert_template 'new'
+ end
+
+ def test_post_new
+ post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''] }
+ assert_redirected_to '/trackers/list'
+ tracker = Tracker.find_by_name('New tracker')
+ assert_equal [1], tracker.project_ids.sort
+ assert_equal 0, tracker.workflows.count
+ end
+
+ def test_post_new_with_workflow_copy
+ post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
+ assert_redirected_to '/trackers/list'
+ 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
Tracker.find(1).project_ids = [1, 3]
@@ -65,4 +93,27 @@ class TrackersControllerTest < Test::Unit::TestCase
assert_redirected_to '/trackers/list'
assert Tracker.find(1).project_ids.empty?
end
+
+ def test_move_lower
+ tracker = Tracker.find_by_position(1)
+ post :edit, :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
+ end
+ assert_redirected_to '/trackers/list'
+ assert_nil flash[:error]
+ end
+
+ def test_destroy_tracker_in_use
+ assert_no_difference 'Tracker.count' do
+ post :destroy, :id => 1
+ end
+ assert_redirected_to '/trackers/list'
+ assert_not_nil flash[:error]
+ end
end
diff --git a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
index 00d86928d..01b414a1c 100644
--- a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
+++ b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb
@@ -118,6 +118,20 @@ module ActiveRecord
assume_top_position
end
end
+
+ # Move to the given position
+ def move_to=(pos)
+ case pos.to_s
+ when 'highest'
+ move_to_top
+ when 'higher'
+ move_higher
+ when 'lower'
+ move_lower
+ when 'lowest'
+ move_to_bottom
+ end
+ end
# Removes the item from the list.
def remove_from_list