##// END OF EJS Templates
Refactor: Merged TrackersController#list and #index...
Eric Davis -
r3323:49bfee053593
parent child
Show More
@@ -1,69 +1,64
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class TrackersController < ApplicationController
18 class TrackersController < ApplicationController
19 layout 'admin'
19 layout 'admin'
20
20
21 before_filter :require_admin
21 before_filter :require_admin
22
22
23 def index
23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
24 list
25 render :action => 'list' unless request.xhr?
26 end
27
28 verify :method => :post, :only => :destroy, :redirect_to => { :action => :list }
29
24
30 def list
25 def index
31 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
26 @tracker_pages, @trackers = paginate :trackers, :per_page => 10, :order => 'position'
32 render :action => "list", :layout => false if request.xhr?
27 render :action => "index", :layout => false if request.xhr?
33 end
28 end
34
29
35 def new
30 def new
36 @tracker = Tracker.new(params[:tracker])
31 @tracker = Tracker.new(params[:tracker])
37 if request.post? and @tracker.save
32 if request.post? and @tracker.save
38 # workflow copy
33 # workflow copy
39 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
34 if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
40 @tracker.workflows.copy(copy_from)
35 @tracker.workflows.copy(copy_from)
41 end
36 end
42 flash[:notice] = l(:notice_successful_create)
37 flash[:notice] = l(:notice_successful_create)
43 redirect_to :action => 'list'
38 redirect_to :action => 'index'
44 return
39 return
45 end
40 end
46 @trackers = Tracker.find :all, :order => 'position'
41 @trackers = Tracker.find :all, :order => 'position'
47 @projects = Project.find(:all)
42 @projects = Project.find(:all)
48 end
43 end
49
44
50 def edit
45 def edit
51 @tracker = Tracker.find(params[:id])
46 @tracker = Tracker.find(params[:id])
52 if request.post? and @tracker.update_attributes(params[:tracker])
47 if request.post? and @tracker.update_attributes(params[:tracker])
53 flash[:notice] = l(:notice_successful_update)
48 flash[:notice] = l(:notice_successful_update)
54 redirect_to :action => 'list'
49 redirect_to :action => 'index'
55 return
50 return
56 end
51 end
57 @projects = Project.find(:all)
52 @projects = Project.find(:all)
58 end
53 end
59
54
60 def destroy
55 def destroy
61 @tracker = Tracker.find(params[:id])
56 @tracker = Tracker.find(params[:id])
62 unless @tracker.issues.empty?
57 unless @tracker.issues.empty?
63 flash[:error] = "This tracker contains issues and can\'t be deleted."
58 flash[:error] = "This tracker contains issues and can\'t be deleted."
64 else
59 else
65 @tracker.destroy
60 @tracker.destroy
66 end
61 end
67 redirect_to :action => 'list'
62 redirect_to :action => 'index'
68 end
63 end
69 end
64 end
1 NO CONTENT: file renamed from app/views/trackers/list.rhtml to app/views/trackers/index.html.erb
NO CONTENT: file renamed from app/views/trackers/list.rhtml to app/views/trackers/index.html.erb
@@ -1,120 +1,120
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'trackers_controller'
19 require 'trackers_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class TrackersController; def rescue_action(e) raise e end; end
22 class TrackersController; def rescue_action(e) raise e end; end
23
23
24 class TrackersControllerTest < ActionController::TestCase
24 class TrackersControllerTest < ActionController::TestCase
25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
25 fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields
26
26
27 def setup
27 def setup
28 @controller = TrackersController.new
28 @controller = TrackersController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 @request.session[:user_id] = 1 # admin
32 @request.session[:user_id] = 1 # admin
33 end
33 end
34
34
35 def test_index
35 def test_index
36 get :index
36 get :index
37 assert_response :success
37 assert_response :success
38 assert_template 'list'
38 assert_template 'index'
39 end
39 end
40
40
41 def test_get_new
41 def test_get_new
42 get :new
42 get :new
43 assert_response :success
43 assert_response :success
44 assert_template 'new'
44 assert_template 'new'
45 end
45 end
46
46
47 def test_post_new
47 def test_post_new
48 post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
48 post :new, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] }
49 assert_redirected_to '/trackers/list'
49 assert_redirected_to :action => 'index'
50 tracker = Tracker.find_by_name('New tracker')
50 tracker = Tracker.find_by_name('New tracker')
51 assert_equal [1], tracker.project_ids.sort
51 assert_equal [1], tracker.project_ids.sort
52 assert_equal [1, 6], tracker.custom_field_ids
52 assert_equal [1, 6], tracker.custom_field_ids
53 assert_equal 0, tracker.workflows.count
53 assert_equal 0, tracker.workflows.count
54 end
54 end
55
55
56 def test_post_new_with_workflow_copy
56 def test_post_new_with_workflow_copy
57 post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
57 post :new, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1
58 assert_redirected_to '/trackers/list'
58 assert_redirected_to :action => 'index'
59 tracker = Tracker.find_by_name('New tracker')
59 tracker = Tracker.find_by_name('New tracker')
60 assert_equal 0, tracker.projects.count
60 assert_equal 0, tracker.projects.count
61 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
61 assert_equal Tracker.find(1).workflows.count, tracker.workflows.count
62 end
62 end
63
63
64 def test_get_edit
64 def test_get_edit
65 Tracker.find(1).project_ids = [1, 3]
65 Tracker.find(1).project_ids = [1, 3]
66
66
67 get :edit, :id => 1
67 get :edit, :id => 1
68 assert_response :success
68 assert_response :success
69 assert_template 'edit'
69 assert_template 'edit'
70
70
71 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
71 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
72 :value => '1',
72 :value => '1',
73 :checked => 'checked' }
73 :checked => 'checked' }
74
74
75 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
75 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
76 :value => '2',
76 :value => '2',
77 :checked => nil }
77 :checked => nil }
78
78
79 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
79 assert_tag :input, :attributes => { :name => 'tracker[project_ids][]',
80 :value => '',
80 :value => '',
81 :type => 'hidden'}
81 :type => 'hidden'}
82 end
82 end
83
83
84 def test_post_edit
84 def test_post_edit
85 post :edit, :id => 1, :tracker => { :name => 'Renamed',
85 post :edit, :id => 1, :tracker => { :name => 'Renamed',
86 :project_ids => ['1', '2', ''] }
86 :project_ids => ['1', '2', ''] }
87 assert_redirected_to '/trackers/list'
87 assert_redirected_to :action => 'index'
88 assert_equal [1, 2], Tracker.find(1).project_ids.sort
88 assert_equal [1, 2], Tracker.find(1).project_ids.sort
89 end
89 end
90
90
91 def test_post_edit_without_projects
91 def test_post_edit_without_projects
92 post :edit, :id => 1, :tracker => { :name => 'Renamed',
92 post :edit, :id => 1, :tracker => { :name => 'Renamed',
93 :project_ids => [''] }
93 :project_ids => [''] }
94 assert_redirected_to '/trackers/list'
94 assert_redirected_to :action => 'index'
95 assert Tracker.find(1).project_ids.empty?
95 assert Tracker.find(1).project_ids.empty?
96 end
96 end
97
97
98 def test_move_lower
98 def test_move_lower
99 tracker = Tracker.find_by_position(1)
99 tracker = Tracker.find_by_position(1)
100 post :edit, :id => 1, :tracker => { :move_to => 'lower' }
100 post :edit, :id => 1, :tracker => { :move_to => 'lower' }
101 assert_equal 2, tracker.reload.position
101 assert_equal 2, tracker.reload.position
102 end
102 end
103
103
104 def test_destroy
104 def test_destroy
105 tracker = Tracker.create!(:name => 'Destroyable')
105 tracker = Tracker.create!(:name => 'Destroyable')
106 assert_difference 'Tracker.count', -1 do
106 assert_difference 'Tracker.count', -1 do
107 post :destroy, :id => tracker.id
107 post :destroy, :id => tracker.id
108 end
108 end
109 assert_redirected_to '/trackers/list'
109 assert_redirected_to :action => 'index'
110 assert_nil flash[:error]
110 assert_nil flash[:error]
111 end
111 end
112
112
113 def test_destroy_tracker_in_use
113 def test_destroy_tracker_in_use
114 assert_no_difference 'Tracker.count' do
114 assert_no_difference 'Tracker.count' do
115 post :destroy, :id => 1
115 post :destroy, :id => 1
116 end
116 end
117 assert_redirected_to '/trackers/list'
117 assert_redirected_to :action => 'index'
118 assert_not_nil flash[:error]
118 assert_not_nil flash[:error]
119 end
119 end
120 end
120 end
General Comments 0
You need to be logged in to leave comments. Login now