@@ -1,212 +1,212 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 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 | |
|
20 | 20 | class TrackersControllerTest < ActionController::TestCase |
|
21 | 21 | fixtures :trackers, :projects, :projects_trackers, :users, :issues, :custom_fields |
|
22 | 22 | |
|
23 | 23 | def setup |
|
24 | 24 | User.current = nil |
|
25 | 25 | @request.session[:user_id] = 1 # admin |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def test_index |
|
29 | 29 | get :index |
|
30 | 30 | assert_response :success |
|
31 | 31 | assert_template 'index' |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_index_by_anonymous_should_redirect_to_login_form |
|
35 | 35 | @request.session[:user_id] = nil |
|
36 | 36 | get :index |
|
37 | 37 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftrackers' |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def test_index_by_user_should_respond_with_406 |
|
41 | 41 | @request.session[:user_id] = 2 |
|
42 | 42 | get :index |
|
43 | 43 | assert_response 406 |
|
44 | 44 | end |
|
45 | 45 | |
|
46 | 46 | def test_new |
|
47 | 47 | get :new |
|
48 | 48 | assert_response :success |
|
49 | 49 | assert_template 'new' |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_create |
|
53 | 53 | assert_difference 'Tracker.count' do |
|
54 | 54 | post :create, :tracker => { :name => 'New tracker', :project_ids => ['1', '', ''], :custom_field_ids => ['1', '6', ''] } |
|
55 | 55 | end |
|
56 | 56 | assert_redirected_to :action => 'index' |
|
57 | 57 | tracker = Tracker.order('id DESC').first |
|
58 | 58 | assert_equal 'New tracker', tracker.name |
|
59 | 59 | assert_equal [1], tracker.project_ids.sort |
|
60 | 60 | assert_equal Tracker::CORE_FIELDS, tracker.core_fields |
|
61 | 61 | assert_equal [1, 6], tracker.custom_field_ids.sort |
|
62 | 62 | assert_equal 0, tracker.workflow_rules.count |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def create_with_disabled_core_fields |
|
66 | 66 | assert_difference 'Tracker.count' do |
|
67 | 67 | post :create, :tracker => { :name => 'New tracker', :core_fields => ['assigned_to_id', 'fixed_version_id', ''] } |
|
68 | 68 | end |
|
69 | 69 | assert_redirected_to :action => 'index' |
|
70 | 70 | tracker = Tracker.order('id DESC').first |
|
71 | 71 | assert_equal 'New tracker', tracker.name |
|
72 | 72 | assert_equal %w(assigned_to_id fixed_version_id), tracker.core_fields |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def test_create_new_with_workflow_copy |
|
76 | 76 | assert_difference 'Tracker.count' do |
|
77 | 77 | post :create, :tracker => { :name => 'New tracker' }, :copy_workflow_from => 1 |
|
78 | 78 | end |
|
79 | 79 | assert_redirected_to :action => 'index' |
|
80 | 80 | tracker = Tracker.find_by_name('New tracker') |
|
81 | 81 | assert_equal 0, tracker.projects.count |
|
82 | 82 | assert_equal Tracker.find(1).workflow_rules.count, tracker.workflow_rules.count |
|
83 | 83 | end |
|
84 | 84 | |
|
85 | 85 | def test_create_with_failure |
|
86 | 86 | assert_no_difference 'Tracker.count' do |
|
87 | 87 | post :create, :tracker => { :name => '', :project_ids => ['1', '', ''], |
|
88 | 88 | :custom_field_ids => ['1', '6', ''] } |
|
89 | 89 | end |
|
90 | 90 | assert_response :success |
|
91 | 91 | assert_template 'new' |
|
92 |
assert_error_tag :content => /name |
|
|
92 | assert_error_tag :content => /name #{ESCAPED_CANT} be blank/i | |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def test_edit |
|
96 | 96 | Tracker.find(1).project_ids = [1, 3] |
|
97 | 97 | |
|
98 | 98 | get :edit, :id => 1 |
|
99 | 99 | assert_response :success |
|
100 | 100 | assert_template 'edit' |
|
101 | 101 | |
|
102 | 102 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
103 | 103 | :value => '1', |
|
104 | 104 | :checked => 'checked' } |
|
105 | 105 | |
|
106 | 106 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
107 | 107 | :value => '2', |
|
108 | 108 | :checked => nil } |
|
109 | 109 | |
|
110 | 110 | assert_tag :input, :attributes => { :name => 'tracker[project_ids][]', |
|
111 | 111 | :value => '', |
|
112 | 112 | :type => 'hidden'} |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def test_edit_should_check_core_fields |
|
116 | 116 | tracker = Tracker.find(1) |
|
117 | 117 | tracker.core_fields = %w(assigned_to_id fixed_version_id) |
|
118 | 118 | tracker.save! |
|
119 | 119 | |
|
120 | 120 | get :edit, :id => 1 |
|
121 | 121 | assert_response :success |
|
122 | 122 | assert_template 'edit' |
|
123 | 123 | |
|
124 | 124 | assert_select 'input[name=?][value=assigned_to_id][checked=checked]', 'tracker[core_fields][]' |
|
125 | 125 | assert_select 'input[name=?][value=fixed_version_id][checked=checked]', 'tracker[core_fields][]' |
|
126 | 126 | |
|
127 | 127 | assert_select 'input[name=?][value=category_id]', 'tracker[core_fields][]' |
|
128 | 128 | assert_select 'input[name=?][value=category_id][checked=checked]', 'tracker[core_fields][]', 0 |
|
129 | 129 | |
|
130 | 130 | assert_select 'input[name=?][value=][type=hidden]', 'tracker[core_fields][]' |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def test_update |
|
134 | 134 | put :update, :id => 1, :tracker => { :name => 'Renamed', |
|
135 | 135 | :project_ids => ['1', '2', ''] } |
|
136 | 136 | assert_redirected_to :action => 'index' |
|
137 | 137 | assert_equal [1, 2], Tracker.find(1).project_ids.sort |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | def test_update_without_projects |
|
141 | 141 | put :update, :id => 1, :tracker => { :name => 'Renamed', |
|
142 | 142 | :project_ids => [''] } |
|
143 | 143 | assert_redirected_to :action => 'index' |
|
144 | 144 | assert Tracker.find(1).project_ids.empty? |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | def test_update_without_core_fields |
|
148 | 148 | put :update, :id => 1, :tracker => { :name => 'Renamed', :core_fields => [''] } |
|
149 | 149 | assert_redirected_to :action => 'index' |
|
150 | 150 | assert Tracker.find(1).core_fields.empty? |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def test_update_with_failure |
|
154 | 154 | put :update, :id => 1, :tracker => { :name => '' } |
|
155 | 155 | assert_response :success |
|
156 | 156 | assert_template 'edit' |
|
157 |
assert_error_tag :content => /name |
|
|
157 | assert_error_tag :content => /name #{ESCAPED_CANT} be blank/i | |
|
158 | 158 | end |
|
159 | 159 | |
|
160 | 160 | def test_move_lower |
|
161 | 161 | tracker = Tracker.find_by_position(1) |
|
162 | 162 | put :update, :id => 1, :tracker => { :move_to => 'lower' } |
|
163 | 163 | assert_equal 2, tracker.reload.position |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def test_destroy |
|
167 | 167 | tracker = Tracker.create!(:name => 'Destroyable') |
|
168 | 168 | assert_difference 'Tracker.count', -1 do |
|
169 | 169 | delete :destroy, :id => tracker.id |
|
170 | 170 | end |
|
171 | 171 | assert_redirected_to :action => 'index' |
|
172 | 172 | assert_nil flash[:error] |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | def test_destroy_tracker_in_use |
|
176 | 176 | assert_no_difference 'Tracker.count' do |
|
177 | 177 | delete :destroy, :id => 1 |
|
178 | 178 | end |
|
179 | 179 | assert_redirected_to :action => 'index' |
|
180 | 180 | assert_not_nil flash[:error] |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | 183 | def test_get_fields |
|
184 | 184 | get :fields |
|
185 | 185 | assert_response :success |
|
186 | 186 | assert_template 'fields' |
|
187 | 187 | |
|
188 | 188 | assert_select 'form' do |
|
189 | 189 | assert_select 'input[type=checkbox][name=?][value=assigned_to_id]', 'trackers[1][core_fields][]' |
|
190 | 190 | assert_select 'input[type=checkbox][name=?][value=2]', 'trackers[1][custom_field_ids][]' |
|
191 | 191 | |
|
192 | 192 | assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][core_fields][]' |
|
193 | 193 | assert_select 'input[type=hidden][name=?][value=]', 'trackers[1][custom_field_ids][]' |
|
194 | 194 | end |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def test_post_fields |
|
198 | 198 | post :fields, :trackers => { |
|
199 | 199 | '1' => {'core_fields' => ['assigned_to_id', 'due_date', ''], 'custom_field_ids' => ['1', '2']}, |
|
200 | 200 | '2' => {'core_fields' => [''], 'custom_field_ids' => ['']} |
|
201 | 201 | } |
|
202 | 202 | assert_redirected_to '/trackers/fields' |
|
203 | 203 | |
|
204 | 204 | tracker = Tracker.find(1) |
|
205 | 205 | assert_equal %w(assigned_to_id due_date), tracker.core_fields |
|
206 | 206 | assert_equal [1, 2], tracker.custom_field_ids.sort |
|
207 | 207 | |
|
208 | 208 | tracker = Tracker.find(2) |
|
209 | 209 | assert_equal [], tracker.core_fields |
|
210 | 210 | assert_equal [], tracker.custom_field_ids.sort |
|
211 | 211 | end |
|
212 | 212 | end |
General Comments 0
You need to be logged in to leave comments.
Login now