Refactor: Merged TrackersController#list and #index

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3437 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2010-02-15 16:41:27 +00:00
parent c5f30fde28
commit 49bfee0535
3 changed files with 13 additions and 18 deletions

View File

@ -20,16 +20,11 @@ class TrackersController < ApplicationController
before_filter :require_admin before_filter :require_admin
def index verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
list
render :action => 'list' unless request.xhr?
end
verify :method => :post, :only => :destroy, :redirect_to => { :action => :list }
def list def index
@tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position' @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
render :action => "list", :layout => false if request.xhr? render :action => "index", :layout => false if request.xhr?
end end
def new def new
@ -40,7 +35,7 @@ class TrackersController < ApplicationController
@tracker.workflows.copy(copy_from) @tracker.workflows.copy(copy_from)
end end
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list' redirect_to :action => 'index'
return return
end end
@trackers = Tracker.find :all, :order => 'position' @trackers = Tracker.find :all, :order => 'position'
@ -51,7 +46,7 @@ class TrackersController < ApplicationController
@tracker = Tracker.find(params[:id]) @tracker = Tracker.find(params[:id])
if request.post? and @tracker.update_attributes(params[:tracker]) if request.post? and @tracker.update_attributes(params[:tracker])
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'list' redirect_to :action => 'index'
return return
end end
@projects = Project.find(:all) @projects = Project.find(:all)
@ -64,6 +59,6 @@ class TrackersController < ApplicationController
else else
@tracker.destroy @tracker.destroy
end end
redirect_to :action => 'list' redirect_to :action => 'index'
end end
end end

View File

@ -35,7 +35,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_index def test_index
get :index get :index
assert_response :success assert_response :success
assert_template 'list' assert_template 'index'
end end
def test_get_new def test_get_new
@ -46,7 +46,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_post_new def test_post_new
post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
tracker = Tracker.find_by_name('New tracker') tracker = Tracker.find_by_name('New tracker')
assert_equal [1], tracker.project_ids.sort assert_equal [1], tracker.project_ids.sort
assert_equal [1, 6], tracker.custom_field_ids assert_equal [1, 6], tracker.custom_field_ids
@ -55,7 +55,7 @@ class TrackersControllerTest < ActionController::TestCase
def test_post_new_with_workflow_copy def test_post_new_with_workflow_copy
post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
tracker = Tracker.find_by_name('New tracker') tracker = Tracker.find_by_name('New tracker')
assert_equal 0, tracker.projects.count assert_equal 0, tracker.projects.count
assert_equal Tracker.find(1).workflows.count, tracker.workflows.count assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
@ -84,14 +84,14 @@ class TrackersControllerTest < ActionController::TestCase
def test_post_edit def test_post_edit
post :edit, :id => 1, :tracker => { :name => 'Renamed', post :edit, :id => 1, :tracker => { :name => 'Renamed',
:project_ids => ['1', '2', ''] } :project_ids => ['1', '2', ''] }
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
assert_equal [1, 2], Tracker.find(1).project_ids.sort assert_equal [1, 2], Tracker.find(1).project_ids.sort
end end
def test_post_edit_without_projects def test_post_edit_without_projects
post :edit, :id => 1, :tracker => { :name => 'Renamed', post :edit, :id => 1, :tracker => { :name => 'Renamed',
:project_ids => [''] } :project_ids => [''] }
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
assert Tracker.find(1).project_ids.empty? assert Tracker.find(1).project_ids.empty?
end end
@ -106,7 +106,7 @@ class TrackersControllerTest < ActionController::TestCase
assert_difference 'Tracker.count', -1 do assert_difference 'Tracker.count', -1 do
post :destroy, :id => tracker.id post :destroy, :id => tracker.id
end end
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
assert_nil flash[:error] assert_nil flash[:error]
end end
@ -114,7 +114,7 @@ class TrackersControllerTest < ActionController::TestCase
assert_no_difference 'Tracker.count' do assert_no_difference 'Tracker.count' do
post :destroy, :id => 1 post :destroy, :id => 1
end end
assert_redirected_to '/trackers/list' assert_redirected_to :action => 'index'
assert_not_nil flash[:error] assert_not_nil flash[:error]
end end
end end