@@ -1,145 +1,145 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'trackers_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class TrackersController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class TrackersControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = TrackersController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | @request.session[:user_id] = 1 # admin |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_index |
|
36 | 36 | get :index |
|
37 | 37 | assert_response :success |
|
38 | 38 | assert_template 'index' |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def test_index_by_anonymous_should_redirect_to_login_form |
|
42 | 42 | @request.session[:user_id] = nil |
|
43 | 43 | get :index |
|
44 | 44 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftrackers' |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def test_index_by_user_should_respond_with_406 |
|
48 | 48 | @request.session[:user_id] = 2 |
|
49 | 49 | get :index |
|
50 | 50 | assert_response 406 |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_new |
|
54 | 54 | get :new |
|
55 | 55 | assert_response :success |
|
56 | 56 | assert_template 'new' |
|
57 | 57 | end |
|
58 | 58 | |
|
59 | 59 | def test_create |
|
60 | 60 | assert_difference 'Tracker.count' do |
|
61 | 61 | post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } |
|
62 | 62 | end |
|
63 | 63 | assert_redirected_to :action => 'index' |
|
64 | 64 | tracker = Tracker.first(:order => 'id DESC') |
|
65 | 65 | assert_equal 'New tracker', tracker.name |
|
66 | 66 | assert_equal [1], tracker.project_ids.sort |
|
67 | assert_equal [1, 6], tracker.custom_field_ids | |
|
67 | assert_equal [1, 6], tracker.custom_field_ids.sort | |
|
68 | 68 | assert_equal 0, tracker.workflows.count |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def test_create_new_with_workflow_copy |
|
72 | 72 | assert_difference 'Tracker.count' do |
|
73 | 73 | post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 |
|
74 | 74 | end |
|
75 | 75 | assert_redirected_to :action => 'index' |
|
76 | 76 | tracker = Tracker.find_by_name('New tracker') |
|
77 | 77 | assert_equal 0, tracker.projects.count |
|
78 | 78 | assert_equal Tracker.find(1).workflows.count, tracker.workflows.count |
|
79 | 79 | end |
|
80 | 80 | |
|
81 | 81 | def test_create_new_failure |
|
82 | 82 | assert_no_difference 'Tracker.count' do |
|
83 | 83 | post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } |
|
84 | 84 | end |
|
85 | 85 | assert_response :success |
|
86 | 86 | assert_template 'new' |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def test_edit |
|
90 | 90 | Tracker.find(1).project_ids = [1, 3] |
|
91 | 91 | |
|
92 | 92 | get :edit, :id => 1 |
|
93 | 93 | assert_response :success |
|
94 | 94 | assert_template 'edit' |
|
95 | 95 | |
|
96 | 96 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
97 | 97 | :value => '1', |
|
98 | 98 | :checked => 'checked' } |
|
99 | 99 | |
|
100 | 100 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
101 | 101 | :value => '2', |
|
102 | 102 | :checked => nil } |
|
103 | 103 | |
|
104 | 104 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
105 | 105 | :value => '', |
|
106 | 106 | :type => 'hidden'} |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def test_update |
|
110 | 110 | put :update, :id => 1, :tracker => { :name => 'Renamed', |
|
111 | 111 | :project_ids => ['1', '2', ''] } |
|
112 | 112 | assert_redirected_to :action => 'index' |
|
113 | 113 | assert_equal [1, 2], Tracker.find(1).project_ids.sort |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def test_update_without_projects |
|
117 | 117 | put :update, :id => 1, :tracker => { :name => 'Renamed', |
|
118 | 118 | :project_ids => [''] } |
|
119 | 119 | assert_redirected_to :action => 'index' |
|
120 | 120 | assert Tracker.find(1).project_ids.empty? |
|
121 | 121 | end |
|
122 | 122 | |
|
123 | 123 | def test_move_lower |
|
124 | 124 | tracker = Tracker.find_by_position(1) |
|
125 | 125 | put :update, :id => 1, :tracker => { :move_to => 'lower' } |
|
126 | 126 | assert_equal 2, tracker.reload.position |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def test_destroy |
|
130 | 130 | tracker = Tracker.create!(:name => 'Destroyable') |
|
131 | 131 | assert_difference 'Tracker.count', -1 do |
|
132 | 132 | delete :destroy, :id => tracker.id |
|
133 | 133 | end |
|
134 | 134 | assert_redirected_to :action => 'index' |
|
135 | 135 | assert_nil flash[:error] |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def test_destroy_tracker_in_use |
|
139 | 139 | assert_no_difference 'Tracker.count' do |
|
140 | 140 | delete :destroy, :id => 1 |
|
141 | 141 | end |
|
142 | 142 | assert_redirected_to :action => 'index' |
|
143 | 143 | assert_not_nil flash[:error] |
|
144 | 144 | end |
|
145 | 145 | end |
General Comments 0
You need to be logged in to leave comments.
Login now