##// END OF EJS Templates
cover the issues pdf test in English and CJK locales...
Toshi MARUYAMA -
r7820:88a713c719c7
parent child
Show More
@@ -1,1896 +1,1916
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 class IssuesControllerTest < ActionController::TestCase
21 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects,
22 fixtures :projects,
23 :users,
23 :users,
24 :roles,
24 :roles,
25 :members,
25 :members,
26 :member_roles,
26 :member_roles,
27 :issues,
27 :issues,
28 :issue_statuses,
28 :issue_statuses,
29 :versions,
29 :versions,
30 :trackers,
30 :trackers,
31 :projects_trackers,
31 :projects_trackers,
32 :issue_categories,
32 :issue_categories,
33 :enabled_modules,
33 :enabled_modules,
34 :enumerations,
34 :enumerations,
35 :attachments,
35 :attachments,
36 :workflows,
36 :workflows,
37 :custom_fields,
37 :custom_fields,
38 :custom_values,
38 :custom_values,
39 :custom_fields_projects,
39 :custom_fields_projects,
40 :custom_fields_trackers,
40 :custom_fields_trackers,
41 :time_entries,
41 :time_entries,
42 :journals,
42 :journals,
43 :journal_details,
43 :journal_details,
44 :queries
44 :queries
45
45
46 include Redmine::I18n
47
46 def setup
48 def setup
47 @controller = IssuesController.new
49 @controller = IssuesController.new
48 @request = ActionController::TestRequest.new
50 @request = ActionController::TestRequest.new
49 @response = ActionController::TestResponse.new
51 @response = ActionController::TestResponse.new
50 User.current = nil
52 User.current = nil
51 end
53 end
52
54
53 def test_index
55 def test_index
54 Setting.default_language = 'en'
56 Setting.default_language = 'en'
55
57
56 get :index
58 get :index
57 assert_response :success
59 assert_response :success
58 assert_template 'index'
60 assert_template 'index'
59 assert_not_nil assigns(:issues)
61 assert_not_nil assigns(:issues)
60 assert_nil assigns(:project)
62 assert_nil assigns(:project)
61 assert_tag :tag => 'a', :content => /Can't print recipes/
63 assert_tag :tag => 'a', :content => /Can't print recipes/
62 assert_tag :tag => 'a', :content => /Subproject issue/
64 assert_tag :tag => 'a', :content => /Subproject issue/
63 # private projects hidden
65 # private projects hidden
64 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
65 assert_no_tag :tag => 'a', :content => /Issue on project 2/
67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
66 # project column
68 # project column
67 assert_tag :tag => 'th', :content => /Project/
69 assert_tag :tag => 'th', :content => /Project/
68 end
70 end
69
71
70 def test_index_should_not_list_issues_when_module_disabled
72 def test_index_should_not_list_issues_when_module_disabled
71 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
72 get :index
74 get :index
73 assert_response :success
75 assert_response :success
74 assert_template 'index'
76 assert_template 'index'
75 assert_not_nil assigns(:issues)
77 assert_not_nil assigns(:issues)
76 assert_nil assigns(:project)
78 assert_nil assigns(:project)
77 assert_no_tag :tag => 'a', :content => /Can't print recipes/
79 assert_no_tag :tag => 'a', :content => /Can't print recipes/
78 assert_tag :tag => 'a', :content => /Subproject issue/
80 assert_tag :tag => 'a', :content => /Subproject issue/
79 end
81 end
80
82
81 def test_index_should_list_visible_issues_only
83 def test_index_should_list_visible_issues_only
82 get :index, :per_page => 100
84 get :index, :per_page => 100
83 assert_response :success
85 assert_response :success
84 assert_not_nil assigns(:issues)
86 assert_not_nil assigns(:issues)
85 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
86 end
88 end
87
89
88 def test_index_with_project
90 def test_index_with_project
89 Setting.display_subprojects_issues = 0
91 Setting.display_subprojects_issues = 0
90 get :index, :project_id => 1
92 get :index, :project_id => 1
91 assert_response :success
93 assert_response :success
92 assert_template 'index'
94 assert_template 'index'
93 assert_not_nil assigns(:issues)
95 assert_not_nil assigns(:issues)
94 assert_tag :tag => 'a', :content => /Can't print recipes/
96 assert_tag :tag => 'a', :content => /Can't print recipes/
95 assert_no_tag :tag => 'a', :content => /Subproject issue/
97 assert_no_tag :tag => 'a', :content => /Subproject issue/
96 end
98 end
97
99
98 def test_index_with_project_and_subprojects
100 def test_index_with_project_and_subprojects
99 Setting.display_subprojects_issues = 1
101 Setting.display_subprojects_issues = 1
100 get :index, :project_id => 1
102 get :index, :project_id => 1
101 assert_response :success
103 assert_response :success
102 assert_template 'index'
104 assert_template 'index'
103 assert_not_nil assigns(:issues)
105 assert_not_nil assigns(:issues)
104 assert_tag :tag => 'a', :content => /Can't print recipes/
106 assert_tag :tag => 'a', :content => /Can't print recipes/
105 assert_tag :tag => 'a', :content => /Subproject issue/
107 assert_tag :tag => 'a', :content => /Subproject issue/
106 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
107 end
109 end
108
110
109 def test_index_with_project_and_subprojects_should_show_private_subprojects
111 def test_index_with_project_and_subprojects_should_show_private_subprojects
110 @request.session[:user_id] = 2
112 @request.session[:user_id] = 2
111 Setting.display_subprojects_issues = 1
113 Setting.display_subprojects_issues = 1
112 get :index, :project_id => 1
114 get :index, :project_id => 1
113 assert_response :success
115 assert_response :success
114 assert_template 'index'
116 assert_template 'index'
115 assert_not_nil assigns(:issues)
117 assert_not_nil assigns(:issues)
116 assert_tag :tag => 'a', :content => /Can't print recipes/
118 assert_tag :tag => 'a', :content => /Can't print recipes/
117 assert_tag :tag => 'a', :content => /Subproject issue/
119 assert_tag :tag => 'a', :content => /Subproject issue/
118 assert_tag :tag => 'a', :content => /Issue of a private subproject/
120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
119 end
121 end
120
122
121 def test_index_with_project_and_default_filter
123 def test_index_with_project_and_default_filter
122 get :index, :project_id => 1, :set_filter => 1
124 get :index, :project_id => 1, :set_filter => 1
123 assert_response :success
125 assert_response :success
124 assert_template 'index'
126 assert_template 'index'
125 assert_not_nil assigns(:issues)
127 assert_not_nil assigns(:issues)
126
128
127 query = assigns(:query)
129 query = assigns(:query)
128 assert_not_nil query
130 assert_not_nil query
129 # default filter
131 # default filter
130 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
131 end
133 end
132
134
133 def test_index_with_project_and_filter
135 def test_index_with_project_and_filter
134 get :index, :project_id => 1, :set_filter => 1,
136 get :index, :project_id => 1, :set_filter => 1,
135 :f => ['tracker_id'],
137 :f => ['tracker_id'],
136 :op => {'tracker_id' => '='},
138 :op => {'tracker_id' => '='},
137 :v => {'tracker_id' => ['1']}
139 :v => {'tracker_id' => ['1']}
138 assert_response :success
140 assert_response :success
139 assert_template 'index'
141 assert_template 'index'
140 assert_not_nil assigns(:issues)
142 assert_not_nil assigns(:issues)
141
143
142 query = assigns(:query)
144 query = assigns(:query)
143 assert_not_nil query
145 assert_not_nil query
144 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
145 end
147 end
146
148
147 def test_index_with_short_filters
149 def test_index_with_short_filters
148
150
149 to_test = {
151 to_test = {
150 'status_id' => {
152 'status_id' => {
151 'o' => { :op => 'o', :values => [''] },
153 'o' => { :op => 'o', :values => [''] },
152 'c' => { :op => 'c', :values => [''] },
154 'c' => { :op => 'c', :values => [''] },
153 '7' => { :op => '=', :values => ['7'] },
155 '7' => { :op => '=', :values => ['7'] },
154 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
155 '=7' => { :op => '=', :values => ['7'] },
157 '=7' => { :op => '=', :values => ['7'] },
156 '!3' => { :op => '!', :values => ['3'] },
158 '!3' => { :op => '!', :values => ['3'] },
157 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
158 'subject' => {
160 'subject' => {
159 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
160 'o' => { :op => '=', :values => ['o'] },
162 'o' => { :op => '=', :values => ['o'] },
161 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
163 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
162 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
164 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
163 'tracker_id' => {
165 'tracker_id' => {
164 '3' => { :op => '=', :values => ['3'] },
166 '3' => { :op => '=', :values => ['3'] },
165 '=3' => { :op => '=', :values => ['3'] }},
167 '=3' => { :op => '=', :values => ['3'] }},
166 'start_date' => {
168 'start_date' => {
167 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
168 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
169 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
171 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
170 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
172 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
171 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
173 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
172 '<t+2' => { :op => '<t+', :values => ['2'] },
174 '<t+2' => { :op => '<t+', :values => ['2'] },
173 '>t+2' => { :op => '>t+', :values => ['2'] },
175 '>t+2' => { :op => '>t+', :values => ['2'] },
174 't+2' => { :op => 't+', :values => ['2'] },
176 't+2' => { :op => 't+', :values => ['2'] },
175 't' => { :op => 't', :values => [''] },
177 't' => { :op => 't', :values => [''] },
176 'w' => { :op => 'w', :values => [''] },
178 'w' => { :op => 'w', :values => [''] },
177 '>t-2' => { :op => '>t-', :values => ['2'] },
179 '>t-2' => { :op => '>t-', :values => ['2'] },
178 '<t-2' => { :op => '<t-', :values => ['2'] },
180 '<t-2' => { :op => '<t-', :values => ['2'] },
179 't-2' => { :op => 't-', :values => ['2'] }},
181 't-2' => { :op => 't-', :values => ['2'] }},
180 'created_on' => {
182 'created_on' => {
181 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
182 '<t+2' => { :op => '=', :values => ['<t+2'] },
184 '<t+2' => { :op => '=', :values => ['<t+2'] },
183 '>t+2' => { :op => '=', :values => ['>t+2'] },
185 '>t+2' => { :op => '=', :values => ['>t+2'] },
184 't+2' => { :op => 't', :values => ['+2'] }},
186 't+2' => { :op => 't', :values => ['+2'] }},
185 'cf_1' => {
187 'cf_1' => {
186 'c' => { :op => '=', :values => ['c'] },
188 'c' => { :op => '=', :values => ['c'] },
187 '!c' => { :op => '!', :values => ['c'] },
189 '!c' => { :op => '!', :values => ['c'] },
188 '!*' => { :op => '!*', :values => [''] },
190 '!*' => { :op => '!*', :values => [''] },
189 '*' => { :op => '*', :values => [''] }},
191 '*' => { :op => '*', :values => [''] }},
190 'estimated_hours' => {
192 'estimated_hours' => {
191 '=13.4' => { :op => '=', :values => ['13.4'] },
193 '=13.4' => { :op => '=', :values => ['13.4'] },
192 '>=45' => { :op => '>=', :values => ['45'] },
194 '>=45' => { :op => '>=', :values => ['45'] },
193 '<=125' => { :op => '<=', :values => ['125'] },
195 '<=125' => { :op => '<=', :values => ['125'] },
194 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
195 '!*' => { :op => '!*', :values => [''] },
197 '!*' => { :op => '!*', :values => [''] },
196 '*' => { :op => '*', :values => [''] }}
198 '*' => { :op => '*', :values => [''] }}
197 }
199 }
198
200
199 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
200
202
201 to_test.each do |field, expression_and_expected|
203 to_test.each do |field, expression_and_expected|
202 expression_and_expected.each do |filter_expression, expected|
204 expression_and_expected.each do |filter_expression, expected|
203
205
204 get :index, :set_filter => 1, field => filter_expression
206 get :index, :set_filter => 1, field => filter_expression
205
207
206 assert_response :success
208 assert_response :success
207 assert_template 'index'
209 assert_template 'index'
208 assert_not_nil assigns(:issues)
210 assert_not_nil assigns(:issues)
209
211
210 query = assigns(:query)
212 query = assigns(:query)
211 assert_not_nil query
213 assert_not_nil query
212 assert query.has_filter?(field)
214 assert query.has_filter?(field)
213 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
214 end
216 end
215 end
217 end
216
218
217 end
219 end
218
220
219 def test_index_with_project_and_empty_filters
221 def test_index_with_project_and_empty_filters
220 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
221 assert_response :success
223 assert_response :success
222 assert_template 'index'
224 assert_template 'index'
223 assert_not_nil assigns(:issues)
225 assert_not_nil assigns(:issues)
224
226
225 query = assigns(:query)
227 query = assigns(:query)
226 assert_not_nil query
228 assert_not_nil query
227 # no filter
229 # no filter
228 assert_equal({}, query.filters)
230 assert_equal({}, query.filters)
229 end
231 end
230
232
231 def test_index_with_query
233 def test_index_with_query
232 get :index, :project_id => 1, :query_id => 5
234 get :index, :project_id => 1, :query_id => 5
233 assert_response :success
235 assert_response :success
234 assert_template 'index'
236 assert_template 'index'
235 assert_not_nil assigns(:issues)
237 assert_not_nil assigns(:issues)
236 assert_nil assigns(:issue_count_by_group)
238 assert_nil assigns(:issue_count_by_group)
237 end
239 end
238
240
239 def test_index_with_query_grouped_by_tracker
241 def test_index_with_query_grouped_by_tracker
240 get :index, :project_id => 1, :query_id => 6
242 get :index, :project_id => 1, :query_id => 6
241 assert_response :success
243 assert_response :success
242 assert_template 'index'
244 assert_template 'index'
243 assert_not_nil assigns(:issues)
245 assert_not_nil assigns(:issues)
244 assert_not_nil assigns(:issue_count_by_group)
246 assert_not_nil assigns(:issue_count_by_group)
245 end
247 end
246
248
247 def test_index_with_query_grouped_by_list_custom_field
249 def test_index_with_query_grouped_by_list_custom_field
248 get :index, :project_id => 1, :query_id => 9
250 get :index, :project_id => 1, :query_id => 9
249 assert_response :success
251 assert_response :success
250 assert_template 'index'
252 assert_template 'index'
251 assert_not_nil assigns(:issues)
253 assert_not_nil assigns(:issues)
252 assert_not_nil assigns(:issue_count_by_group)
254 assert_not_nil assigns(:issue_count_by_group)
253 end
255 end
254
256
255 def test_private_query_should_not_be_available_to_other_users
257 def test_private_query_should_not_be_available_to_other_users
256 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
258 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
257 @request.session[:user_id] = 3
259 @request.session[:user_id] = 3
258
260
259 get :index, :query_id => q.id
261 get :index, :query_id => q.id
260 assert_response 403
262 assert_response 403
261 end
263 end
262
264
263 def test_private_query_should_be_available_to_its_user
265 def test_private_query_should_be_available_to_its_user
264 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
266 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
265 @request.session[:user_id] = 2
267 @request.session[:user_id] = 2
266
268
267 get :index, :query_id => q.id
269 get :index, :query_id => q.id
268 assert_response :success
270 assert_response :success
269 end
271 end
270
272
271 def test_public_query_should_be_available_to_other_users
273 def test_public_query_should_be_available_to_other_users
272 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
274 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
273 @request.session[:user_id] = 3
275 @request.session[:user_id] = 3
274
276
275 get :index, :query_id => q.id
277 get :index, :query_id => q.id
276 assert_response :success
278 assert_response :success
277 end
279 end
278
280
279 def test_index_csv
281 def test_index_csv
280 get :index, :format => 'csv'
282 get :index, :format => 'csv'
281 assert_response :success
283 assert_response :success
282 assert_not_nil assigns(:issues)
284 assert_not_nil assigns(:issues)
283 assert_equal 'text/csv', @response.content_type
285 assert_equal 'text/csv', @response.content_type
284 assert @response.body.starts_with?("#,")
286 assert @response.body.starts_with?("#,")
285 lines = @response.body.chomp.split("\n")
287 lines = @response.body.chomp.split("\n")
286 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
288 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
287 end
289 end
288
290
289 def test_index_csv_with_project
291 def test_index_csv_with_project
290 get :index, :project_id => 1, :format => 'csv'
292 get :index, :project_id => 1, :format => 'csv'
291 assert_response :success
293 assert_response :success
292 assert_not_nil assigns(:issues)
294 assert_not_nil assigns(:issues)
293 assert_equal 'text/csv', @response.content_type
295 assert_equal 'text/csv', @response.content_type
294 end
296 end
295
297
296 def test_index_csv_with_description
298 def test_index_csv_with_description
297 get :index, :format => 'csv', :description => '1'
299 get :index, :format => 'csv', :description => '1'
298 assert_response :success
300 assert_response :success
299 assert_not_nil assigns(:issues)
301 assert_not_nil assigns(:issues)
300 assert_equal 'text/csv', @response.content_type
302 assert_equal 'text/csv', @response.content_type
301 assert @response.body.starts_with?("#,")
303 assert @response.body.starts_with?("#,")
302 lines = @response.body.chomp.split("\n")
304 lines = @response.body.chomp.split("\n")
303 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
305 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
304 end
306 end
305
307
306 def test_index_csv_with_all_columns
308 def test_index_csv_with_all_columns
307 get :index, :format => 'csv', :columns => 'all'
309 get :index, :format => 'csv', :columns => 'all'
308 assert_response :success
310 assert_response :success
309 assert_not_nil assigns(:issues)
311 assert_not_nil assigns(:issues)
310 assert_equal 'text/csv', @response.content_type
312 assert_equal 'text/csv', @response.content_type
311 assert @response.body.starts_with?("#,")
313 assert @response.body.starts_with?("#,")
312 lines = @response.body.chomp.split("\n")
314 lines = @response.body.chomp.split("\n")
313 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
315 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
314 end
316 end
315
317
316 def test_index_csv_big_5
318 def test_index_csv_big_5
317 with_settings :default_language => "zh-TW" do
319 with_settings :default_language => "zh-TW" do
318 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
320 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
319 str_big5 = "\xa4@\xa4\xeb"
321 str_big5 = "\xa4@\xa4\xeb"
320 if str_utf8.respond_to?(:force_encoding)
322 if str_utf8.respond_to?(:force_encoding)
321 str_utf8.force_encoding('UTF-8')
323 str_utf8.force_encoding('UTF-8')
322 str_big5.force_encoding('Big5')
324 str_big5.force_encoding('Big5')
323 end
325 end
324 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
326 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
325 :status_id => 1, :priority => IssuePriority.all.first,
327 :status_id => 1, :priority => IssuePriority.all.first,
326 :subject => str_utf8)
328 :subject => str_utf8)
327 assert issue.save
329 assert issue.save
328
330
329 get :index, :project_id => 1,
331 get :index, :project_id => 1,
330 :f => ['subject'],
332 :f => ['subject'],
331 :op => '=', :values => [str_utf8],
333 :op => '=', :values => [str_utf8],
332 :format => 'csv'
334 :format => 'csv'
333 assert_equal 'text/csv', @response.content_type
335 assert_equal 'text/csv', @response.content_type
334 lines = @response.body.chomp.split("\n")
336 lines = @response.body.chomp.split("\n")
335 s1 = "\xaa\xac\xbaA"
337 s1 = "\xaa\xac\xbaA"
336 if str_utf8.respond_to?(:force_encoding)
338 if str_utf8.respond_to?(:force_encoding)
337 s1.force_encoding('Big5')
339 s1.force_encoding('Big5')
338 end
340 end
339 assert lines[0].include?(s1)
341 assert lines[0].include?(s1)
340 assert lines[1].include?(str_big5)
342 assert lines[1].include?(str_big5)
341 end
343 end
342 end
344 end
343
345
344 def test_index_csv_cannot_convert_should_be_replaced_big_5
346 def test_index_csv_cannot_convert_should_be_replaced_big_5
345 with_settings :default_language => "zh-TW" do
347 with_settings :default_language => "zh-TW" do
346 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
348 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
347 if str_utf8.respond_to?(:force_encoding)
349 if str_utf8.respond_to?(:force_encoding)
348 str_utf8.force_encoding('UTF-8')
350 str_utf8.force_encoding('UTF-8')
349 end
351 end
350 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
352 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
351 :status_id => 1, :priority => IssuePriority.all.first,
353 :status_id => 1, :priority => IssuePriority.all.first,
352 :subject => str_utf8)
354 :subject => str_utf8)
353 assert issue.save
355 assert issue.save
354
356
355 get :index, :project_id => 1,
357 get :index, :project_id => 1,
356 :f => ['subject'],
358 :f => ['subject'],
357 :op => '=', :values => [str_utf8],
359 :op => '=', :values => [str_utf8],
358 :c => ['status', 'subject'],
360 :c => ['status', 'subject'],
359 :format => 'csv',
361 :format => 'csv',
360 :set_filter => 1
362 :set_filter => 1
361 assert_equal 'text/csv', @response.content_type
363 assert_equal 'text/csv', @response.content_type
362 lines = @response.body.chomp.split("\n")
364 lines = @response.body.chomp.split("\n")
363 s1 = "\xaa\xac\xbaA" # status
365 s1 = "\xaa\xac\xbaA" # status
364 if str_utf8.respond_to?(:force_encoding)
366 if str_utf8.respond_to?(:force_encoding)
365 s1.force_encoding('Big5')
367 s1.force_encoding('Big5')
366 end
368 end
367 assert lines[0].include?(s1)
369 assert lines[0].include?(s1)
368 s2 = lines[1].split(",")[2]
370 s2 = lines[1].split(",")[2]
369 if s1.respond_to?(:force_encoding)
371 if s1.respond_to?(:force_encoding)
370 s3 = "\xa5H?" # subject
372 s3 = "\xa5H?" # subject
371 s3.force_encoding('Big5')
373 s3.force_encoding('Big5')
372 assert_equal s3, s2
374 assert_equal s3, s2
373 elsif RUBY_PLATFORM == 'java'
375 elsif RUBY_PLATFORM == 'java'
374 assert_equal "??", s2
376 assert_equal "??", s2
375 else
377 else
376 assert_equal "\xa5H???", s2
378 assert_equal "\xa5H???", s2
377 end
379 end
378 end
380 end
379 end
381 end
380
382
381 def test_index_pdf
383 def test_index_pdf
384 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
385 with_settings :default_language => lang do
386
387 get :index
388 assert_response :success
389 assert_template 'index'
390
391 if lang == "ja"
392 if RUBY_PLATFORM != 'java'
393 assert_equal "CP932", l(:general_pdf_encoding)
394 end
395 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
396 next
397 end
398 end
399
382 get :index, :format => 'pdf'
400 get :index, :format => 'pdf'
383 assert_response :success
401 assert_response :success
384 assert_not_nil assigns(:issues)
402 assert_not_nil assigns(:issues)
385 assert_equal 'application/pdf', @response.content_type
403 assert_equal 'application/pdf', @response.content_type
386
404
387 get :index, :project_id => 1, :format => 'pdf'
405 get :index, :project_id => 1, :format => 'pdf'
388 assert_response :success
406 assert_response :success
389 assert_not_nil assigns(:issues)
407 assert_not_nil assigns(:issues)
390 assert_equal 'application/pdf', @response.content_type
408 assert_equal 'application/pdf', @response.content_type
391
409
392 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
410 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
393 assert_response :success
411 assert_response :success
394 assert_not_nil assigns(:issues)
412 assert_not_nil assigns(:issues)
395 assert_equal 'application/pdf', @response.content_type
413 assert_equal 'application/pdf', @response.content_type
396 end
414 end
415 end
416 end
397
417
398 def test_index_pdf_with_query_grouped_by_list_custom_field
418 def test_index_pdf_with_query_grouped_by_list_custom_field
399 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
419 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
400 assert_response :success
420 assert_response :success
401 assert_not_nil assigns(:issues)
421 assert_not_nil assigns(:issues)
402 assert_not_nil assigns(:issue_count_by_group)
422 assert_not_nil assigns(:issue_count_by_group)
403 assert_equal 'application/pdf', @response.content_type
423 assert_equal 'application/pdf', @response.content_type
404 end
424 end
405
425
406 def test_index_sort
426 def test_index_sort
407 get :index, :sort => 'tracker,id:desc'
427 get :index, :sort => 'tracker,id:desc'
408 assert_response :success
428 assert_response :success
409
429
410 sort_params = @request.session['issues_index_sort']
430 sort_params = @request.session['issues_index_sort']
411 assert sort_params.is_a?(String)
431 assert sort_params.is_a?(String)
412 assert_equal 'tracker,id:desc', sort_params
432 assert_equal 'tracker,id:desc', sort_params
413
433
414 issues = assigns(:issues)
434 issues = assigns(:issues)
415 assert_not_nil issues
435 assert_not_nil issues
416 assert !issues.empty?
436 assert !issues.empty?
417 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
437 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
418 end
438 end
419
439
420 def test_index_sort_by_field_not_included_in_columns
440 def test_index_sort_by_field_not_included_in_columns
421 Setting.issue_list_default_columns = %w(subject author)
441 Setting.issue_list_default_columns = %w(subject author)
422 get :index, :sort => 'tracker'
442 get :index, :sort => 'tracker'
423 end
443 end
424
444
425 def test_index_sort_by_assigned_to
445 def test_index_sort_by_assigned_to
426 get :index, :sort => 'assigned_to'
446 get :index, :sort => 'assigned_to'
427 assert_response :success
447 assert_response :success
428 assignees = assigns(:issues).collect(&:assigned_to).compact
448 assignees = assigns(:issues).collect(&:assigned_to).compact
429 assert_equal assignees.sort, assignees
449 assert_equal assignees.sort, assignees
430 end
450 end
431
451
432 def test_index_sort_by_assigned_to_desc
452 def test_index_sort_by_assigned_to_desc
433 get :index, :sort => 'assigned_to:desc'
453 get :index, :sort => 'assigned_to:desc'
434 assert_response :success
454 assert_response :success
435 assignees = assigns(:issues).collect(&:assigned_to).compact
455 assignees = assigns(:issues).collect(&:assigned_to).compact
436 assert_equal assignees.sort.reverse, assignees
456 assert_equal assignees.sort.reverse, assignees
437 end
457 end
438
458
439 def test_index_group_by_assigned_to
459 def test_index_group_by_assigned_to
440 get :index, :group_by => 'assigned_to', :sort => 'priority'
460 get :index, :group_by => 'assigned_to', :sort => 'priority'
441 assert_response :success
461 assert_response :success
442 end
462 end
443
463
444 def test_index_sort_by_author
464 def test_index_sort_by_author
445 get :index, :sort => 'author'
465 get :index, :sort => 'author'
446 assert_response :success
466 assert_response :success
447 authors = assigns(:issues).collect(&:author)
467 authors = assigns(:issues).collect(&:author)
448 assert_equal authors.sort, authors
468 assert_equal authors.sort, authors
449 end
469 end
450
470
451 def test_index_sort_by_author_desc
471 def test_index_sort_by_author_desc
452 get :index, :sort => 'author:desc'
472 get :index, :sort => 'author:desc'
453 assert_response :success
473 assert_response :success
454 authors = assigns(:issues).collect(&:author)
474 authors = assigns(:issues).collect(&:author)
455 assert_equal authors.sort.reverse, authors
475 assert_equal authors.sort.reverse, authors
456 end
476 end
457
477
458 def test_index_group_by_author
478 def test_index_group_by_author
459 get :index, :group_by => 'author', :sort => 'priority'
479 get :index, :group_by => 'author', :sort => 'priority'
460 assert_response :success
480 assert_response :success
461 end
481 end
462
482
463 def test_index_with_columns
483 def test_index_with_columns
464 columns = ['tracker', 'subject', 'assigned_to']
484 columns = ['tracker', 'subject', 'assigned_to']
465 get :index, :set_filter => 1, :c => columns
485 get :index, :set_filter => 1, :c => columns
466 assert_response :success
486 assert_response :success
467
487
468 # query should use specified columns
488 # query should use specified columns
469 query = assigns(:query)
489 query = assigns(:query)
470 assert_kind_of Query, query
490 assert_kind_of Query, query
471 assert_equal columns, query.column_names.map(&:to_s)
491 assert_equal columns, query.column_names.map(&:to_s)
472
492
473 # columns should be stored in session
493 # columns should be stored in session
474 assert_kind_of Hash, session[:query]
494 assert_kind_of Hash, session[:query]
475 assert_kind_of Array, session[:query][:column_names]
495 assert_kind_of Array, session[:query][:column_names]
476 assert_equal columns, session[:query][:column_names].map(&:to_s)
496 assert_equal columns, session[:query][:column_names].map(&:to_s)
477
497
478 # ensure only these columns are kept in the selected columns list
498 # ensure only these columns are kept in the selected columns list
479 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
499 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
480 :children => { :count => 3 }
500 :children => { :count => 3 }
481 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
501 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
482 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
502 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
483 end
503 end
484
504
485 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
505 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
486 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
506 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
487 get :index, :set_filter => 1
507 get :index, :set_filter => 1
488
508
489 # query should use specified columns
509 # query should use specified columns
490 query = assigns(:query)
510 query = assigns(:query)
491 assert_kind_of Query, query
511 assert_kind_of Query, query
492 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
512 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
493 end
513 end
494
514
495 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
515 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
496 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
516 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
497 columns = ['tracker', 'subject', 'assigned_to']
517 columns = ['tracker', 'subject', 'assigned_to']
498 get :index, :set_filter => 1, :c => columns
518 get :index, :set_filter => 1, :c => columns
499
519
500 # query should use specified columns
520 # query should use specified columns
501 query = assigns(:query)
521 query = assigns(:query)
502 assert_kind_of Query, query
522 assert_kind_of Query, query
503 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
523 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
504 end
524 end
505
525
506 def test_index_with_custom_field_column
526 def test_index_with_custom_field_column
507 columns = %w(tracker subject cf_2)
527 columns = %w(tracker subject cf_2)
508 get :index, :set_filter => 1, :c => columns
528 get :index, :set_filter => 1, :c => columns
509 assert_response :success
529 assert_response :success
510
530
511 # query should use specified columns
531 # query should use specified columns
512 query = assigns(:query)
532 query = assigns(:query)
513 assert_kind_of Query, query
533 assert_kind_of Query, query
514 assert_equal columns, query.column_names.map(&:to_s)
534 assert_equal columns, query.column_names.map(&:to_s)
515
535
516 assert_tag :td,
536 assert_tag :td,
517 :attributes => {:class => 'cf_2 string'},
537 :attributes => {:class => 'cf_2 string'},
518 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
538 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
519 end
539 end
520
540
521 def test_index_send_html_if_query_is_invalid
541 def test_index_send_html_if_query_is_invalid
522 get :index, :f => ['start_date'], :op => {:start_date => '='}
542 get :index, :f => ['start_date'], :op => {:start_date => '='}
523 assert_equal 'text/html', @response.content_type
543 assert_equal 'text/html', @response.content_type
524 assert_template 'index'
544 assert_template 'index'
525 end
545 end
526
546
527 def test_index_send_nothing_if_query_is_invalid
547 def test_index_send_nothing_if_query_is_invalid
528 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
548 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
529 assert_equal 'text/csv', @response.content_type
549 assert_equal 'text/csv', @response.content_type
530 assert @response.body.blank?
550 assert @response.body.blank?
531 end
551 end
532
552
533 def test_show_by_anonymous
553 def test_show_by_anonymous
534 get :show, :id => 1
554 get :show, :id => 1
535 assert_response :success
555 assert_response :success
536 assert_template 'show'
556 assert_template 'show'
537 assert_not_nil assigns(:issue)
557 assert_not_nil assigns(:issue)
538 assert_equal Issue.find(1), assigns(:issue)
558 assert_equal Issue.find(1), assigns(:issue)
539
559
540 # anonymous role is allowed to add a note
560 # anonymous role is allowed to add a note
541 assert_tag :tag => 'form',
561 assert_tag :tag => 'form',
542 :descendant => { :tag => 'fieldset',
562 :descendant => { :tag => 'fieldset',
543 :child => { :tag => 'legend',
563 :child => { :tag => 'legend',
544 :content => /Notes/ } }
564 :content => /Notes/ } }
545 assert_tag :tag => 'title',
565 assert_tag :tag => 'title',
546 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
566 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
547 end
567 end
548
568
549 def test_show_by_manager
569 def test_show_by_manager
550 @request.session[:user_id] = 2
570 @request.session[:user_id] = 2
551 get :show, :id => 1
571 get :show, :id => 1
552 assert_response :success
572 assert_response :success
553
573
554 assert_tag :tag => 'a',
574 assert_tag :tag => 'a',
555 :content => /Quote/
575 :content => /Quote/
556
576
557 assert_tag :tag => 'form',
577 assert_tag :tag => 'form',
558 :descendant => { :tag => 'fieldset',
578 :descendant => { :tag => 'fieldset',
559 :child => { :tag => 'legend',
579 :child => { :tag => 'legend',
560 :content => /Change properties/ } },
580 :content => /Change properties/ } },
561 :descendant => { :tag => 'fieldset',
581 :descendant => { :tag => 'fieldset',
562 :child => { :tag => 'legend',
582 :child => { :tag => 'legend',
563 :content => /Log time/ } },
583 :content => /Log time/ } },
564 :descendant => { :tag => 'fieldset',
584 :descendant => { :tag => 'fieldset',
565 :child => { :tag => 'legend',
585 :child => { :tag => 'legend',
566 :content => /Notes/ } }
586 :content => /Notes/ } }
567 end
587 end
568
588
569 def test_update_form_should_not_display_inactive_enumerations
589 def test_update_form_should_not_display_inactive_enumerations
570 @request.session[:user_id] = 2
590 @request.session[:user_id] = 2
571 get :show, :id => 1
591 get :show, :id => 1
572 assert_response :success
592 assert_response :success
573
593
574 assert ! IssuePriority.find(15).active?
594 assert ! IssuePriority.find(15).active?
575 assert_no_tag :option, :attributes => {:value => '15'},
595 assert_no_tag :option, :attributes => {:value => '15'},
576 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
596 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
577 end
597 end
578
598
579 def test_update_form_should_allow_attachment_upload
599 def test_update_form_should_allow_attachment_upload
580 @request.session[:user_id] = 2
600 @request.session[:user_id] = 2
581 get :show, :id => 1
601 get :show, :id => 1
582
602
583 assert_tag :tag => 'form',
603 assert_tag :tag => 'form',
584 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
604 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
585 :descendant => {
605 :descendant => {
586 :tag => 'input',
606 :tag => 'input',
587 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
607 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
588 }
608 }
589 end
609 end
590
610
591 def test_show_should_deny_anonymous_access_without_permission
611 def test_show_should_deny_anonymous_access_without_permission
592 Role.anonymous.remove_permission!(:view_issues)
612 Role.anonymous.remove_permission!(:view_issues)
593 get :show, :id => 1
613 get :show, :id => 1
594 assert_response :redirect
614 assert_response :redirect
595 end
615 end
596
616
597 def test_show_should_deny_anonymous_access_to_private_issue
617 def test_show_should_deny_anonymous_access_to_private_issue
598 Issue.update_all(["is_private = ?", true], "id = 1")
618 Issue.update_all(["is_private = ?", true], "id = 1")
599 get :show, :id => 1
619 get :show, :id => 1
600 assert_response :redirect
620 assert_response :redirect
601 end
621 end
602
622
603 def test_show_should_deny_non_member_access_without_permission
623 def test_show_should_deny_non_member_access_without_permission
604 Role.non_member.remove_permission!(:view_issues)
624 Role.non_member.remove_permission!(:view_issues)
605 @request.session[:user_id] = 9
625 @request.session[:user_id] = 9
606 get :show, :id => 1
626 get :show, :id => 1
607 assert_response 403
627 assert_response 403
608 end
628 end
609
629
610 def test_show_should_deny_non_member_access_to_private_issue
630 def test_show_should_deny_non_member_access_to_private_issue
611 Issue.update_all(["is_private = ?", true], "id = 1")
631 Issue.update_all(["is_private = ?", true], "id = 1")
612 @request.session[:user_id] = 9
632 @request.session[:user_id] = 9
613 get :show, :id => 1
633 get :show, :id => 1
614 assert_response 403
634 assert_response 403
615 end
635 end
616
636
617 def test_show_should_deny_member_access_without_permission
637 def test_show_should_deny_member_access_without_permission
618 Role.find(1).remove_permission!(:view_issues)
638 Role.find(1).remove_permission!(:view_issues)
619 @request.session[:user_id] = 2
639 @request.session[:user_id] = 2
620 get :show, :id => 1
640 get :show, :id => 1
621 assert_response 403
641 assert_response 403
622 end
642 end
623
643
624 def test_show_should_deny_member_access_to_private_issue_without_permission
644 def test_show_should_deny_member_access_to_private_issue_without_permission
625 Issue.update_all(["is_private = ?", true], "id = 1")
645 Issue.update_all(["is_private = ?", true], "id = 1")
626 @request.session[:user_id] = 3
646 @request.session[:user_id] = 3
627 get :show, :id => 1
647 get :show, :id => 1
628 assert_response 403
648 assert_response 403
629 end
649 end
630
650
631 def test_show_should_allow_author_access_to_private_issue
651 def test_show_should_allow_author_access_to_private_issue
632 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
652 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
633 @request.session[:user_id] = 3
653 @request.session[:user_id] = 3
634 get :show, :id => 1
654 get :show, :id => 1
635 assert_response :success
655 assert_response :success
636 end
656 end
637
657
638 def test_show_should_allow_assignee_access_to_private_issue
658 def test_show_should_allow_assignee_access_to_private_issue
639 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
659 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
640 @request.session[:user_id] = 3
660 @request.session[:user_id] = 3
641 get :show, :id => 1
661 get :show, :id => 1
642 assert_response :success
662 assert_response :success
643 end
663 end
644
664
645 def test_show_should_allow_member_access_to_private_issue_with_permission
665 def test_show_should_allow_member_access_to_private_issue_with_permission
646 Issue.update_all(["is_private = ?", true], "id = 1")
666 Issue.update_all(["is_private = ?", true], "id = 1")
647 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
667 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
648 @request.session[:user_id] = 3
668 @request.session[:user_id] = 3
649 get :show, :id => 1
669 get :show, :id => 1
650 assert_response :success
670 assert_response :success
651 end
671 end
652
672
653 def test_show_should_not_disclose_relations_to_invisible_issues
673 def test_show_should_not_disclose_relations_to_invisible_issues
654 Setting.cross_project_issue_relations = '1'
674 Setting.cross_project_issue_relations = '1'
655 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
675 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
656 # Relation to a private project issue
676 # Relation to a private project issue
657 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
677 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
658
678
659 get :show, :id => 1
679 get :show, :id => 1
660 assert_response :success
680 assert_response :success
661
681
662 assert_tag :div, :attributes => { :id => 'relations' },
682 assert_tag :div, :attributes => { :id => 'relations' },
663 :descendant => { :tag => 'a', :content => /#2$/ }
683 :descendant => { :tag => 'a', :content => /#2$/ }
664 assert_no_tag :div, :attributes => { :id => 'relations' },
684 assert_no_tag :div, :attributes => { :id => 'relations' },
665 :descendant => { :tag => 'a', :content => /#4$/ }
685 :descendant => { :tag => 'a', :content => /#4$/ }
666 end
686 end
667
687
668 def test_show_atom
688 def test_show_atom
669 get :show, :id => 2, :format => 'atom'
689 get :show, :id => 2, :format => 'atom'
670 assert_response :success
690 assert_response :success
671 assert_template 'journals/index'
691 assert_template 'journals/index'
672 # Inline image
692 # Inline image
673 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
693 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
674 end
694 end
675
695
676 def test_show_export_to_pdf
696 def test_show_export_to_pdf
677 get :show, :id => 3, :format => 'pdf'
697 get :show, :id => 3, :format => 'pdf'
678 assert_response :success
698 assert_response :success
679 assert_equal 'application/pdf', @response.content_type
699 assert_equal 'application/pdf', @response.content_type
680 assert @response.body.starts_with?('%PDF')
700 assert @response.body.starts_with?('%PDF')
681 assert_not_nil assigns(:issue)
701 assert_not_nil assigns(:issue)
682 end
702 end
683
703
684 def test_get_new
704 def test_get_new
685 @request.session[:user_id] = 2
705 @request.session[:user_id] = 2
686 get :new, :project_id => 1, :tracker_id => 1
706 get :new, :project_id => 1, :tracker_id => 1
687 assert_response :success
707 assert_response :success
688 assert_template 'new'
708 assert_template 'new'
689
709
690 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
710 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
691 :value => 'Default string' }
711 :value => 'Default string' }
692
712
693 # Be sure we don't display inactive IssuePriorities
713 # Be sure we don't display inactive IssuePriorities
694 assert ! IssuePriority.find(15).active?
714 assert ! IssuePriority.find(15).active?
695 assert_no_tag :option, :attributes => {:value => '15'},
715 assert_no_tag :option, :attributes => {:value => '15'},
696 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
716 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
697 end
717 end
698
718
699 def test_get_new_without_default_start_date_is_creation_date
719 def test_get_new_without_default_start_date_is_creation_date
700 Setting.default_issue_start_date_to_creation_date = 0
720 Setting.default_issue_start_date_to_creation_date = 0
701
721
702 @request.session[:user_id] = 2
722 @request.session[:user_id] = 2
703 get :new, :project_id => 1, :tracker_id => 1
723 get :new, :project_id => 1, :tracker_id => 1
704 assert_response :success
724 assert_response :success
705 assert_template 'new'
725 assert_template 'new'
706
726
707 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
727 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
708 :value => nil }
728 :value => nil }
709 end
729 end
710
730
711 def test_get_new_with_default_start_date_is_creation_date
731 def test_get_new_with_default_start_date_is_creation_date
712 Setting.default_issue_start_date_to_creation_date = 1
732 Setting.default_issue_start_date_to_creation_date = 1
713
733
714 @request.session[:user_id] = 2
734 @request.session[:user_id] = 2
715 get :new, :project_id => 1, :tracker_id => 1
735 get :new, :project_id => 1, :tracker_id => 1
716 assert_response :success
736 assert_response :success
717 assert_template 'new'
737 assert_template 'new'
718
738
719 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
739 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
720 :value => Date.today.to_s }
740 :value => Date.today.to_s }
721 end
741 end
722
742
723 def test_get_new_form_should_allow_attachment_upload
743 def test_get_new_form_should_allow_attachment_upload
724 @request.session[:user_id] = 2
744 @request.session[:user_id] = 2
725 get :new, :project_id => 1, :tracker_id => 1
745 get :new, :project_id => 1, :tracker_id => 1
726
746
727 assert_tag :tag => 'form',
747 assert_tag :tag => 'form',
728 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
748 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
729 :descendant => {
749 :descendant => {
730 :tag => 'input',
750 :tag => 'input',
731 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
751 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
732 }
752 }
733 end
753 end
734
754
735 def test_get_new_without_tracker_id
755 def test_get_new_without_tracker_id
736 @request.session[:user_id] = 2
756 @request.session[:user_id] = 2
737 get :new, :project_id => 1
757 get :new, :project_id => 1
738 assert_response :success
758 assert_response :success
739 assert_template 'new'
759 assert_template 'new'
740
760
741 issue = assigns(:issue)
761 issue = assigns(:issue)
742 assert_not_nil issue
762 assert_not_nil issue
743 assert_equal Project.find(1).trackers.first, issue.tracker
763 assert_equal Project.find(1).trackers.first, issue.tracker
744 end
764 end
745
765
746 def test_get_new_with_no_default_status_should_display_an_error
766 def test_get_new_with_no_default_status_should_display_an_error
747 @request.session[:user_id] = 2
767 @request.session[:user_id] = 2
748 IssueStatus.delete_all
768 IssueStatus.delete_all
749
769
750 get :new, :project_id => 1
770 get :new, :project_id => 1
751 assert_response 500
771 assert_response 500
752 assert_error_tag :content => /No default issue/
772 assert_error_tag :content => /No default issue/
753 end
773 end
754
774
755 def test_get_new_with_no_tracker_should_display_an_error
775 def test_get_new_with_no_tracker_should_display_an_error
756 @request.session[:user_id] = 2
776 @request.session[:user_id] = 2
757 Tracker.delete_all
777 Tracker.delete_all
758
778
759 get :new, :project_id => 1
779 get :new, :project_id => 1
760 assert_response 500
780 assert_response 500
761 assert_error_tag :content => /No tracker/
781 assert_error_tag :content => /No tracker/
762 end
782 end
763
783
764 def test_update_new_form
784 def test_update_new_form
765 @request.session[:user_id] = 2
785 @request.session[:user_id] = 2
766 xhr :post, :new, :project_id => 1,
786 xhr :post, :new, :project_id => 1,
767 :issue => {:tracker_id => 2,
787 :issue => {:tracker_id => 2,
768 :subject => 'This is the test_new issue',
788 :subject => 'This is the test_new issue',
769 :description => 'This is the description',
789 :description => 'This is the description',
770 :priority_id => 5}
790 :priority_id => 5}
771 assert_response :success
791 assert_response :success
772 assert_template 'attributes'
792 assert_template 'attributes'
773
793
774 issue = assigns(:issue)
794 issue = assigns(:issue)
775 assert_kind_of Issue, issue
795 assert_kind_of Issue, issue
776 assert_equal 1, issue.project_id
796 assert_equal 1, issue.project_id
777 assert_equal 2, issue.tracker_id
797 assert_equal 2, issue.tracker_id
778 assert_equal 'This is the test_new issue', issue.subject
798 assert_equal 'This is the test_new issue', issue.subject
779 end
799 end
780
800
781 def test_post_create
801 def test_post_create
782 @request.session[:user_id] = 2
802 @request.session[:user_id] = 2
783 assert_difference 'Issue.count' do
803 assert_difference 'Issue.count' do
784 post :create, :project_id => 1,
804 post :create, :project_id => 1,
785 :issue => {:tracker_id => 3,
805 :issue => {:tracker_id => 3,
786 :status_id => 2,
806 :status_id => 2,
787 :subject => 'This is the test_new issue',
807 :subject => 'This is the test_new issue',
788 :description => 'This is the description',
808 :description => 'This is the description',
789 :priority_id => 5,
809 :priority_id => 5,
790 :start_date => '2010-11-07',
810 :start_date => '2010-11-07',
791 :estimated_hours => '',
811 :estimated_hours => '',
792 :custom_field_values => {'2' => 'Value for field 2'}}
812 :custom_field_values => {'2' => 'Value for field 2'}}
793 end
813 end
794 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
814 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
795
815
796 issue = Issue.find_by_subject('This is the test_new issue')
816 issue = Issue.find_by_subject('This is the test_new issue')
797 assert_not_nil issue
817 assert_not_nil issue
798 assert_equal 2, issue.author_id
818 assert_equal 2, issue.author_id
799 assert_equal 3, issue.tracker_id
819 assert_equal 3, issue.tracker_id
800 assert_equal 2, issue.status_id
820 assert_equal 2, issue.status_id
801 assert_equal Date.parse('2010-11-07'), issue.start_date
821 assert_equal Date.parse('2010-11-07'), issue.start_date
802 assert_nil issue.estimated_hours
822 assert_nil issue.estimated_hours
803 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
823 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
804 assert_not_nil v
824 assert_not_nil v
805 assert_equal 'Value for field 2', v.value
825 assert_equal 'Value for field 2', v.value
806 end
826 end
807
827
808 def test_post_new_with_group_assignment
828 def test_post_new_with_group_assignment
809 group = Group.find(11)
829 group = Group.find(11)
810 project = Project.find(1)
830 project = Project.find(1)
811 project.members << Member.new(:principal => group, :roles => [Role.first])
831 project.members << Member.new(:principal => group, :roles => [Role.first])
812
832
813 with_settings :issue_group_assignment => '1' do
833 with_settings :issue_group_assignment => '1' do
814 @request.session[:user_id] = 2
834 @request.session[:user_id] = 2
815 assert_difference 'Issue.count' do
835 assert_difference 'Issue.count' do
816 post :create, :project_id => project.id,
836 post :create, :project_id => project.id,
817 :issue => {:tracker_id => 3,
837 :issue => {:tracker_id => 3,
818 :status_id => 1,
838 :status_id => 1,
819 :subject => 'This is the test_new_with_group_assignment issue',
839 :subject => 'This is the test_new_with_group_assignment issue',
820 :assigned_to_id => group.id}
840 :assigned_to_id => group.id}
821 end
841 end
822 end
842 end
823 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
843 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
824
844
825 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
845 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
826 assert_not_nil issue
846 assert_not_nil issue
827 assert_equal group, issue.assigned_to
847 assert_equal group, issue.assigned_to
828 end
848 end
829
849
830 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
850 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
831 Setting.default_issue_start_date_to_creation_date = 0
851 Setting.default_issue_start_date_to_creation_date = 0
832
852
833 @request.session[:user_id] = 2
853 @request.session[:user_id] = 2
834 assert_difference 'Issue.count' do
854 assert_difference 'Issue.count' do
835 post :create, :project_id => 1,
855 post :create, :project_id => 1,
836 :issue => {:tracker_id => 3,
856 :issue => {:tracker_id => 3,
837 :status_id => 2,
857 :status_id => 2,
838 :subject => 'This is the test_new issue',
858 :subject => 'This is the test_new issue',
839 :description => 'This is the description',
859 :description => 'This is the description',
840 :priority_id => 5,
860 :priority_id => 5,
841 :estimated_hours => '',
861 :estimated_hours => '',
842 :custom_field_values => {'2' => 'Value for field 2'}}
862 :custom_field_values => {'2' => 'Value for field 2'}}
843 end
863 end
844 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
864 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
845
865
846 issue = Issue.find_by_subject('This is the test_new issue')
866 issue = Issue.find_by_subject('This is the test_new issue')
847 assert_not_nil issue
867 assert_not_nil issue
848 assert_nil issue.start_date
868 assert_nil issue.start_date
849 end
869 end
850
870
851 def test_post_create_without_start_date_and_default_start_date_is_creation_date
871 def test_post_create_without_start_date_and_default_start_date_is_creation_date
852 Setting.default_issue_start_date_to_creation_date = 1
872 Setting.default_issue_start_date_to_creation_date = 1
853
873
854 @request.session[:user_id] = 2
874 @request.session[:user_id] = 2
855 assert_difference 'Issue.count' do
875 assert_difference 'Issue.count' do
856 post :create, :project_id => 1,
876 post :create, :project_id => 1,
857 :issue => {:tracker_id => 3,
877 :issue => {:tracker_id => 3,
858 :status_id => 2,
878 :status_id => 2,
859 :subject => 'This is the test_new issue',
879 :subject => 'This is the test_new issue',
860 :description => 'This is the description',
880 :description => 'This is the description',
861 :priority_id => 5,
881 :priority_id => 5,
862 :estimated_hours => '',
882 :estimated_hours => '',
863 :custom_field_values => {'2' => 'Value for field 2'}}
883 :custom_field_values => {'2' => 'Value for field 2'}}
864 end
884 end
865 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
885 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
866
886
867 issue = Issue.find_by_subject('This is the test_new issue')
887 issue = Issue.find_by_subject('This is the test_new issue')
868 assert_not_nil issue
888 assert_not_nil issue
869 assert_equal Date.today, issue.start_date
889 assert_equal Date.today, issue.start_date
870 end
890 end
871
891
872 def test_post_create_and_continue
892 def test_post_create_and_continue
873 @request.session[:user_id] = 2
893 @request.session[:user_id] = 2
874 assert_difference 'Issue.count' do
894 assert_difference 'Issue.count' do
875 post :create, :project_id => 1,
895 post :create, :project_id => 1,
876 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
896 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
877 :continue => ''
897 :continue => ''
878 end
898 end
879
899
880 issue = Issue.first(:order => 'id DESC')
900 issue = Issue.first(:order => 'id DESC')
881 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
901 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
882 assert_not_nil flash[:notice], "flash was not set"
902 assert_not_nil flash[:notice], "flash was not set"
883 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
903 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
884 end
904 end
885
905
886 def test_post_create_without_custom_fields_param
906 def test_post_create_without_custom_fields_param
887 @request.session[:user_id] = 2
907 @request.session[:user_id] = 2
888 assert_difference 'Issue.count' do
908 assert_difference 'Issue.count' do
889 post :create, :project_id => 1,
909 post :create, :project_id => 1,
890 :issue => {:tracker_id => 1,
910 :issue => {:tracker_id => 1,
891 :subject => 'This is the test_new issue',
911 :subject => 'This is the test_new issue',
892 :description => 'This is the description',
912 :description => 'This is the description',
893 :priority_id => 5}
913 :priority_id => 5}
894 end
914 end
895 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
915 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
896 end
916 end
897
917
898 def test_post_create_with_required_custom_field_and_without_custom_fields_param
918 def test_post_create_with_required_custom_field_and_without_custom_fields_param
899 field = IssueCustomField.find_by_name('Database')
919 field = IssueCustomField.find_by_name('Database')
900 field.update_attribute(:is_required, true)
920 field.update_attribute(:is_required, true)
901
921
902 @request.session[:user_id] = 2
922 @request.session[:user_id] = 2
903 post :create, :project_id => 1,
923 post :create, :project_id => 1,
904 :issue => {:tracker_id => 1,
924 :issue => {:tracker_id => 1,
905 :subject => 'This is the test_new issue',
925 :subject => 'This is the test_new issue',
906 :description => 'This is the description',
926 :description => 'This is the description',
907 :priority_id => 5}
927 :priority_id => 5}
908 assert_response :success
928 assert_response :success
909 assert_template 'new'
929 assert_template 'new'
910 issue = assigns(:issue)
930 issue = assigns(:issue)
911 assert_not_nil issue
931 assert_not_nil issue
912 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
932 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
913 end
933 end
914
934
915 def test_post_create_with_watchers
935 def test_post_create_with_watchers
916 @request.session[:user_id] = 2
936 @request.session[:user_id] = 2
917 ActionMailer::Base.deliveries.clear
937 ActionMailer::Base.deliveries.clear
918
938
919 assert_difference 'Watcher.count', 2 do
939 assert_difference 'Watcher.count', 2 do
920 post :create, :project_id => 1,
940 post :create, :project_id => 1,
921 :issue => {:tracker_id => 1,
941 :issue => {:tracker_id => 1,
922 :subject => 'This is a new issue with watchers',
942 :subject => 'This is a new issue with watchers',
923 :description => 'This is the description',
943 :description => 'This is the description',
924 :priority_id => 5,
944 :priority_id => 5,
925 :watcher_user_ids => ['2', '3']}
945 :watcher_user_ids => ['2', '3']}
926 end
946 end
927 issue = Issue.find_by_subject('This is a new issue with watchers')
947 issue = Issue.find_by_subject('This is a new issue with watchers')
928 assert_not_nil issue
948 assert_not_nil issue
929 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
949 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
930
950
931 # Watchers added
951 # Watchers added
932 assert_equal [2, 3], issue.watcher_user_ids.sort
952 assert_equal [2, 3], issue.watcher_user_ids.sort
933 assert issue.watched_by?(User.find(3))
953 assert issue.watched_by?(User.find(3))
934 # Watchers notified
954 # Watchers notified
935 mail = ActionMailer::Base.deliveries.last
955 mail = ActionMailer::Base.deliveries.last
936 assert_kind_of TMail::Mail, mail
956 assert_kind_of TMail::Mail, mail
937 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
957 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
938 end
958 end
939
959
940 def test_post_create_subissue
960 def test_post_create_subissue
941 @request.session[:user_id] = 2
961 @request.session[:user_id] = 2
942
962
943 assert_difference 'Issue.count' do
963 assert_difference 'Issue.count' do
944 post :create, :project_id => 1,
964 post :create, :project_id => 1,
945 :issue => {:tracker_id => 1,
965 :issue => {:tracker_id => 1,
946 :subject => 'This is a child issue',
966 :subject => 'This is a child issue',
947 :parent_issue_id => 2}
967 :parent_issue_id => 2}
948 end
968 end
949 issue = Issue.find_by_subject('This is a child issue')
969 issue = Issue.find_by_subject('This is a child issue')
950 assert_not_nil issue
970 assert_not_nil issue
951 assert_equal Issue.find(2), issue.parent
971 assert_equal Issue.find(2), issue.parent
952 end
972 end
953
973
954 def test_post_create_subissue_with_non_numeric_parent_id
974 def test_post_create_subissue_with_non_numeric_parent_id
955 @request.session[:user_id] = 2
975 @request.session[:user_id] = 2
956
976
957 assert_difference 'Issue.count' do
977 assert_difference 'Issue.count' do
958 post :create, :project_id => 1,
978 post :create, :project_id => 1,
959 :issue => {:tracker_id => 1,
979 :issue => {:tracker_id => 1,
960 :subject => 'This is a child issue',
980 :subject => 'This is a child issue',
961 :parent_issue_id => 'ABC'}
981 :parent_issue_id => 'ABC'}
962 end
982 end
963 issue = Issue.find_by_subject('This is a child issue')
983 issue = Issue.find_by_subject('This is a child issue')
964 assert_not_nil issue
984 assert_not_nil issue
965 assert_nil issue.parent
985 assert_nil issue.parent
966 end
986 end
967
987
968 def test_post_create_private
988 def test_post_create_private
969 @request.session[:user_id] = 2
989 @request.session[:user_id] = 2
970
990
971 assert_difference 'Issue.count' do
991 assert_difference 'Issue.count' do
972 post :create, :project_id => 1,
992 post :create, :project_id => 1,
973 :issue => {:tracker_id => 1,
993 :issue => {:tracker_id => 1,
974 :subject => 'This is a private issue',
994 :subject => 'This is a private issue',
975 :is_private => '1'}
995 :is_private => '1'}
976 end
996 end
977 issue = Issue.first(:order => 'id DESC')
997 issue = Issue.first(:order => 'id DESC')
978 assert issue.is_private?
998 assert issue.is_private?
979 end
999 end
980
1000
981 def test_post_create_private_with_set_own_issues_private_permission
1001 def test_post_create_private_with_set_own_issues_private_permission
982 role = Role.find(1)
1002 role = Role.find(1)
983 role.remove_permission! :set_issues_private
1003 role.remove_permission! :set_issues_private
984 role.add_permission! :set_own_issues_private
1004 role.add_permission! :set_own_issues_private
985
1005
986 @request.session[:user_id] = 2
1006 @request.session[:user_id] = 2
987
1007
988 assert_difference 'Issue.count' do
1008 assert_difference 'Issue.count' do
989 post :create, :project_id => 1,
1009 post :create, :project_id => 1,
990 :issue => {:tracker_id => 1,
1010 :issue => {:tracker_id => 1,
991 :subject => 'This is a private issue',
1011 :subject => 'This is a private issue',
992 :is_private => '1'}
1012 :is_private => '1'}
993 end
1013 end
994 issue = Issue.first(:order => 'id DESC')
1014 issue = Issue.first(:order => 'id DESC')
995 assert issue.is_private?
1015 assert issue.is_private?
996 end
1016 end
997
1017
998 def test_post_create_should_send_a_notification
1018 def test_post_create_should_send_a_notification
999 ActionMailer::Base.deliveries.clear
1019 ActionMailer::Base.deliveries.clear
1000 @request.session[:user_id] = 2
1020 @request.session[:user_id] = 2
1001 assert_difference 'Issue.count' do
1021 assert_difference 'Issue.count' do
1002 post :create, :project_id => 1,
1022 post :create, :project_id => 1,
1003 :issue => {:tracker_id => 3,
1023 :issue => {:tracker_id => 3,
1004 :subject => 'This is the test_new issue',
1024 :subject => 'This is the test_new issue',
1005 :description => 'This is the description',
1025 :description => 'This is the description',
1006 :priority_id => 5,
1026 :priority_id => 5,
1007 :estimated_hours => '',
1027 :estimated_hours => '',
1008 :custom_field_values => {'2' => 'Value for field 2'}}
1028 :custom_field_values => {'2' => 'Value for field 2'}}
1009 end
1029 end
1010 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1030 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1011
1031
1012 assert_equal 1, ActionMailer::Base.deliveries.size
1032 assert_equal 1, ActionMailer::Base.deliveries.size
1013 end
1033 end
1014
1034
1015 def test_post_create_should_preserve_fields_values_on_validation_failure
1035 def test_post_create_should_preserve_fields_values_on_validation_failure
1016 @request.session[:user_id] = 2
1036 @request.session[:user_id] = 2
1017 post :create, :project_id => 1,
1037 post :create, :project_id => 1,
1018 :issue => {:tracker_id => 1,
1038 :issue => {:tracker_id => 1,
1019 # empty subject
1039 # empty subject
1020 :subject => '',
1040 :subject => '',
1021 :description => 'This is a description',
1041 :description => 'This is a description',
1022 :priority_id => 6,
1042 :priority_id => 6,
1023 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1043 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1024 assert_response :success
1044 assert_response :success
1025 assert_template 'new'
1045 assert_template 'new'
1026
1046
1027 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1047 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1028 :content => 'This is a description'
1048 :content => 'This is a description'
1029 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1049 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1030 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1050 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1031 :value => '6' },
1051 :value => '6' },
1032 :content => 'High' }
1052 :content => 'High' }
1033 # Custom fields
1053 # Custom fields
1034 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1054 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1035 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1055 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1036 :value => 'Oracle' },
1056 :value => 'Oracle' },
1037 :content => 'Oracle' }
1057 :content => 'Oracle' }
1038 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1058 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1039 :value => 'Value for field 2'}
1059 :value => 'Value for field 2'}
1040 end
1060 end
1041
1061
1042 def test_post_create_should_ignore_non_safe_attributes
1062 def test_post_create_should_ignore_non_safe_attributes
1043 @request.session[:user_id] = 2
1063 @request.session[:user_id] = 2
1044 assert_nothing_raised do
1064 assert_nothing_raised do
1045 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1065 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1046 end
1066 end
1047 end
1067 end
1048
1068
1049 def test_post_create_with_attachment
1069 def test_post_create_with_attachment
1050 set_tmp_attachments_directory
1070 set_tmp_attachments_directory
1051 @request.session[:user_id] = 2
1071 @request.session[:user_id] = 2
1052
1072
1053 assert_difference 'Issue.count' do
1073 assert_difference 'Issue.count' do
1054 assert_difference 'Attachment.count' do
1074 assert_difference 'Attachment.count' do
1055 post :create, :project_id => 1,
1075 post :create, :project_id => 1,
1056 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1076 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1057 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1077 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1058 end
1078 end
1059 end
1079 end
1060
1080
1061 issue = Issue.first(:order => 'id DESC')
1081 issue = Issue.first(:order => 'id DESC')
1062 attachment = Attachment.first(:order => 'id DESC')
1082 attachment = Attachment.first(:order => 'id DESC')
1063
1083
1064 assert_equal issue, attachment.container
1084 assert_equal issue, attachment.container
1065 assert_equal 2, attachment.author_id
1085 assert_equal 2, attachment.author_id
1066 assert_equal 'testfile.txt', attachment.filename
1086 assert_equal 'testfile.txt', attachment.filename
1067 assert_equal 'text/plain', attachment.content_type
1087 assert_equal 'text/plain', attachment.content_type
1068 assert_equal 'test file', attachment.description
1088 assert_equal 'test file', attachment.description
1069 assert_equal 59, attachment.filesize
1089 assert_equal 59, attachment.filesize
1070 assert File.exists?(attachment.diskfile)
1090 assert File.exists?(attachment.diskfile)
1071 assert_equal 59, File.size(attachment.diskfile)
1091 assert_equal 59, File.size(attachment.diskfile)
1072 end
1092 end
1073
1093
1074 context "without workflow privilege" do
1094 context "without workflow privilege" do
1075 setup do
1095 setup do
1076 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1096 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1077 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1097 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1078 end
1098 end
1079
1099
1080 context "#new" do
1100 context "#new" do
1081 should "propose default status only" do
1101 should "propose default status only" do
1082 get :new, :project_id => 1
1102 get :new, :project_id => 1
1083 assert_response :success
1103 assert_response :success
1084 assert_template 'new'
1104 assert_template 'new'
1085 assert_tag :tag => 'select',
1105 assert_tag :tag => 'select',
1086 :attributes => {:name => 'issue[status_id]'},
1106 :attributes => {:name => 'issue[status_id]'},
1087 :children => {:count => 1},
1107 :children => {:count => 1},
1088 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1108 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1089 end
1109 end
1090
1110
1091 should "accept default status" do
1111 should "accept default status" do
1092 assert_difference 'Issue.count' do
1112 assert_difference 'Issue.count' do
1093 post :create, :project_id => 1,
1113 post :create, :project_id => 1,
1094 :issue => {:tracker_id => 1,
1114 :issue => {:tracker_id => 1,
1095 :subject => 'This is an issue',
1115 :subject => 'This is an issue',
1096 :status_id => 1}
1116 :status_id => 1}
1097 end
1117 end
1098 issue = Issue.last(:order => 'id')
1118 issue = Issue.last(:order => 'id')
1099 assert_equal IssueStatus.default, issue.status
1119 assert_equal IssueStatus.default, issue.status
1100 end
1120 end
1101
1121
1102 should "ignore unauthorized status" do
1122 should "ignore unauthorized status" do
1103 assert_difference 'Issue.count' do
1123 assert_difference 'Issue.count' do
1104 post :create, :project_id => 1,
1124 post :create, :project_id => 1,
1105 :issue => {:tracker_id => 1,
1125 :issue => {:tracker_id => 1,
1106 :subject => 'This is an issue',
1126 :subject => 'This is an issue',
1107 :status_id => 3}
1127 :status_id => 3}
1108 end
1128 end
1109 issue = Issue.last(:order => 'id')
1129 issue = Issue.last(:order => 'id')
1110 assert_equal IssueStatus.default, issue.status
1130 assert_equal IssueStatus.default, issue.status
1111 end
1131 end
1112 end
1132 end
1113
1133
1114 context "#update" do
1134 context "#update" do
1115 should "ignore status change" do
1135 should "ignore status change" do
1116 assert_difference 'Journal.count' do
1136 assert_difference 'Journal.count' do
1117 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1137 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1118 end
1138 end
1119 assert_equal 1, Issue.find(1).status_id
1139 assert_equal 1, Issue.find(1).status_id
1120 end
1140 end
1121
1141
1122 should "ignore attributes changes" do
1142 should "ignore attributes changes" do
1123 assert_difference 'Journal.count' do
1143 assert_difference 'Journal.count' do
1124 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1144 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1125 end
1145 end
1126 issue = Issue.find(1)
1146 issue = Issue.find(1)
1127 assert_equal "Can't print recipes", issue.subject
1147 assert_equal "Can't print recipes", issue.subject
1128 assert_nil issue.assigned_to
1148 assert_nil issue.assigned_to
1129 end
1149 end
1130 end
1150 end
1131 end
1151 end
1132
1152
1133 context "with workflow privilege" do
1153 context "with workflow privilege" do
1134 setup do
1154 setup do
1135 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1155 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1136 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1156 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1137 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1157 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1138 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1158 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1139 end
1159 end
1140
1160
1141 context "#update" do
1161 context "#update" do
1142 should "accept authorized status" do
1162 should "accept authorized status" do
1143 assert_difference 'Journal.count' do
1163 assert_difference 'Journal.count' do
1144 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1164 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1145 end
1165 end
1146 assert_equal 3, Issue.find(1).status_id
1166 assert_equal 3, Issue.find(1).status_id
1147 end
1167 end
1148
1168
1149 should "ignore unauthorized status" do
1169 should "ignore unauthorized status" do
1150 assert_difference 'Journal.count' do
1170 assert_difference 'Journal.count' do
1151 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1171 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1152 end
1172 end
1153 assert_equal 1, Issue.find(1).status_id
1173 assert_equal 1, Issue.find(1).status_id
1154 end
1174 end
1155
1175
1156 should "accept authorized attributes changes" do
1176 should "accept authorized attributes changes" do
1157 assert_difference 'Journal.count' do
1177 assert_difference 'Journal.count' do
1158 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1178 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1159 end
1179 end
1160 issue = Issue.find(1)
1180 issue = Issue.find(1)
1161 assert_equal 2, issue.assigned_to_id
1181 assert_equal 2, issue.assigned_to_id
1162 end
1182 end
1163
1183
1164 should "ignore unauthorized attributes changes" do
1184 should "ignore unauthorized attributes changes" do
1165 assert_difference 'Journal.count' do
1185 assert_difference 'Journal.count' do
1166 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1186 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1167 end
1187 end
1168 issue = Issue.find(1)
1188 issue = Issue.find(1)
1169 assert_equal "Can't print recipes", issue.subject
1189 assert_equal "Can't print recipes", issue.subject
1170 end
1190 end
1171 end
1191 end
1172
1192
1173 context "and :edit_issues permission" do
1193 context "and :edit_issues permission" do
1174 setup do
1194 setup do
1175 Role.anonymous.add_permission! :add_issues, :edit_issues
1195 Role.anonymous.add_permission! :add_issues, :edit_issues
1176 end
1196 end
1177
1197
1178 should "accept authorized status" do
1198 should "accept authorized status" do
1179 assert_difference 'Journal.count' do
1199 assert_difference 'Journal.count' do
1180 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1200 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1181 end
1201 end
1182 assert_equal 3, Issue.find(1).status_id
1202 assert_equal 3, Issue.find(1).status_id
1183 end
1203 end
1184
1204
1185 should "ignore unauthorized status" do
1205 should "ignore unauthorized status" do
1186 assert_difference 'Journal.count' do
1206 assert_difference 'Journal.count' do
1187 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1207 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1188 end
1208 end
1189 assert_equal 1, Issue.find(1).status_id
1209 assert_equal 1, Issue.find(1).status_id
1190 end
1210 end
1191
1211
1192 should "accept authorized attributes changes" do
1212 should "accept authorized attributes changes" do
1193 assert_difference 'Journal.count' do
1213 assert_difference 'Journal.count' do
1194 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1214 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1195 end
1215 end
1196 issue = Issue.find(1)
1216 issue = Issue.find(1)
1197 assert_equal "changed", issue.subject
1217 assert_equal "changed", issue.subject
1198 assert_equal 2, issue.assigned_to_id
1218 assert_equal 2, issue.assigned_to_id
1199 end
1219 end
1200 end
1220 end
1201 end
1221 end
1202
1222
1203 def test_copy_issue
1223 def test_copy_issue
1204 @request.session[:user_id] = 2
1224 @request.session[:user_id] = 2
1205 get :new, :project_id => 1, :copy_from => 1
1225 get :new, :project_id => 1, :copy_from => 1
1206 assert_template 'new'
1226 assert_template 'new'
1207 assert_not_nil assigns(:issue)
1227 assert_not_nil assigns(:issue)
1208 orig = Issue.find(1)
1228 orig = Issue.find(1)
1209 assert_equal orig.subject, assigns(:issue).subject
1229 assert_equal orig.subject, assigns(:issue).subject
1210 end
1230 end
1211
1231
1212 def test_get_edit
1232 def test_get_edit
1213 @request.session[:user_id] = 2
1233 @request.session[:user_id] = 2
1214 get :edit, :id => 1
1234 get :edit, :id => 1
1215 assert_response :success
1235 assert_response :success
1216 assert_template 'edit'
1236 assert_template 'edit'
1217 assert_not_nil assigns(:issue)
1237 assert_not_nil assigns(:issue)
1218 assert_equal Issue.find(1), assigns(:issue)
1238 assert_equal Issue.find(1), assigns(:issue)
1219
1239
1220 # Be sure we don't display inactive IssuePriorities
1240 # Be sure we don't display inactive IssuePriorities
1221 assert ! IssuePriority.find(15).active?
1241 assert ! IssuePriority.find(15).active?
1222 assert_no_tag :option, :attributes => {:value => '15'},
1242 assert_no_tag :option, :attributes => {:value => '15'},
1223 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1243 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1224 end
1244 end
1225
1245
1226 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1246 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1227 @request.session[:user_id] = 2
1247 @request.session[:user_id] = 2
1228 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1248 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1229
1249
1230 get :edit, :id => 1
1250 get :edit, :id => 1
1231 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1251 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1232 end
1252 end
1233
1253
1234 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1254 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1235 @request.session[:user_id] = 2
1255 @request.session[:user_id] = 2
1236 Role.find_by_name('Manager').remove_permission! :log_time
1256 Role.find_by_name('Manager').remove_permission! :log_time
1237
1257
1238 get :edit, :id => 1
1258 get :edit, :id => 1
1239 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1259 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1240 end
1260 end
1241
1261
1242 def test_get_edit_with_params
1262 def test_get_edit_with_params
1243 @request.session[:user_id] = 2
1263 @request.session[:user_id] = 2
1244 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1264 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1245 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1265 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1246 assert_response :success
1266 assert_response :success
1247 assert_template 'edit'
1267 assert_template 'edit'
1248
1268
1249 issue = assigns(:issue)
1269 issue = assigns(:issue)
1250 assert_not_nil issue
1270 assert_not_nil issue
1251
1271
1252 assert_equal 5, issue.status_id
1272 assert_equal 5, issue.status_id
1253 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1273 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1254 :child => { :tag => 'option',
1274 :child => { :tag => 'option',
1255 :content => 'Closed',
1275 :content => 'Closed',
1256 :attributes => { :selected => 'selected' } }
1276 :attributes => { :selected => 'selected' } }
1257
1277
1258 assert_equal 7, issue.priority_id
1278 assert_equal 7, issue.priority_id
1259 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1279 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1260 :child => { :tag => 'option',
1280 :child => { :tag => 'option',
1261 :content => 'Urgent',
1281 :content => 'Urgent',
1262 :attributes => { :selected => 'selected' } }
1282 :attributes => { :selected => 'selected' } }
1263
1283
1264 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1284 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1265 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1285 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1266 :child => { :tag => 'option',
1286 :child => { :tag => 'option',
1267 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1287 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1268 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1288 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1269 end
1289 end
1270
1290
1271 def test_update_edit_form
1291 def test_update_edit_form
1272 @request.session[:user_id] = 2
1292 @request.session[:user_id] = 2
1273 xhr :post, :new, :project_id => 1,
1293 xhr :post, :new, :project_id => 1,
1274 :id => 1,
1294 :id => 1,
1275 :issue => {:tracker_id => 2,
1295 :issue => {:tracker_id => 2,
1276 :subject => 'This is the test_new issue',
1296 :subject => 'This is the test_new issue',
1277 :description => 'This is the description',
1297 :description => 'This is the description',
1278 :priority_id => 5}
1298 :priority_id => 5}
1279 assert_response :success
1299 assert_response :success
1280 assert_template 'attributes'
1300 assert_template 'attributes'
1281
1301
1282 issue = assigns(:issue)
1302 issue = assigns(:issue)
1283 assert_kind_of Issue, issue
1303 assert_kind_of Issue, issue
1284 assert_equal 1, issue.id
1304 assert_equal 1, issue.id
1285 assert_equal 1, issue.project_id
1305 assert_equal 1, issue.project_id
1286 assert_equal 2, issue.tracker_id
1306 assert_equal 2, issue.tracker_id
1287 assert_equal 'This is the test_new issue', issue.subject
1307 assert_equal 'This is the test_new issue', issue.subject
1288 end
1308 end
1289
1309
1290 def test_update_using_invalid_http_verbs
1310 def test_update_using_invalid_http_verbs
1291 @request.session[:user_id] = 2
1311 @request.session[:user_id] = 2
1292 subject = 'Updated by an invalid http verb'
1312 subject = 'Updated by an invalid http verb'
1293
1313
1294 get :update, :id => 1, :issue => {:subject => subject}
1314 get :update, :id => 1, :issue => {:subject => subject}
1295 assert_not_equal subject, Issue.find(1).subject
1315 assert_not_equal subject, Issue.find(1).subject
1296
1316
1297 post :update, :id => 1, :issue => {:subject => subject}
1317 post :update, :id => 1, :issue => {:subject => subject}
1298 assert_not_equal subject, Issue.find(1).subject
1318 assert_not_equal subject, Issue.find(1).subject
1299
1319
1300 delete :update, :id => 1, :issue => {:subject => subject}
1320 delete :update, :id => 1, :issue => {:subject => subject}
1301 assert_not_equal subject, Issue.find(1).subject
1321 assert_not_equal subject, Issue.find(1).subject
1302 end
1322 end
1303
1323
1304 def test_put_update_without_custom_fields_param
1324 def test_put_update_without_custom_fields_param
1305 @request.session[:user_id] = 2
1325 @request.session[:user_id] = 2
1306 ActionMailer::Base.deliveries.clear
1326 ActionMailer::Base.deliveries.clear
1307
1327
1308 issue = Issue.find(1)
1328 issue = Issue.find(1)
1309 assert_equal '125', issue.custom_value_for(2).value
1329 assert_equal '125', issue.custom_value_for(2).value
1310 old_subject = issue.subject
1330 old_subject = issue.subject
1311 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1331 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1312
1332
1313 assert_difference('Journal.count') do
1333 assert_difference('Journal.count') do
1314 assert_difference('JournalDetail.count', 2) do
1334 assert_difference('JournalDetail.count', 2) do
1315 put :update, :id => 1, :issue => {:subject => new_subject,
1335 put :update, :id => 1, :issue => {:subject => new_subject,
1316 :priority_id => '6',
1336 :priority_id => '6',
1317 :category_id => '1' # no change
1337 :category_id => '1' # no change
1318 }
1338 }
1319 end
1339 end
1320 end
1340 end
1321 assert_redirected_to :action => 'show', :id => '1'
1341 assert_redirected_to :action => 'show', :id => '1'
1322 issue.reload
1342 issue.reload
1323 assert_equal new_subject, issue.subject
1343 assert_equal new_subject, issue.subject
1324 # Make sure custom fields were not cleared
1344 # Make sure custom fields were not cleared
1325 assert_equal '125', issue.custom_value_for(2).value
1345 assert_equal '125', issue.custom_value_for(2).value
1326
1346
1327 mail = ActionMailer::Base.deliveries.last
1347 mail = ActionMailer::Base.deliveries.last
1328 assert_kind_of TMail::Mail, mail
1348 assert_kind_of TMail::Mail, mail
1329 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1349 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1330 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1350 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1331 end
1351 end
1332
1352
1333 def test_put_update_with_custom_field_change
1353 def test_put_update_with_custom_field_change
1334 @request.session[:user_id] = 2
1354 @request.session[:user_id] = 2
1335 issue = Issue.find(1)
1355 issue = Issue.find(1)
1336 assert_equal '125', issue.custom_value_for(2).value
1356 assert_equal '125', issue.custom_value_for(2).value
1337
1357
1338 assert_difference('Journal.count') do
1358 assert_difference('Journal.count') do
1339 assert_difference('JournalDetail.count', 3) do
1359 assert_difference('JournalDetail.count', 3) do
1340 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1360 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1341 :priority_id => '6',
1361 :priority_id => '6',
1342 :category_id => '1', # no change
1362 :category_id => '1', # no change
1343 :custom_field_values => { '2' => 'New custom value' }
1363 :custom_field_values => { '2' => 'New custom value' }
1344 }
1364 }
1345 end
1365 end
1346 end
1366 end
1347 assert_redirected_to :action => 'show', :id => '1'
1367 assert_redirected_to :action => 'show', :id => '1'
1348 issue.reload
1368 issue.reload
1349 assert_equal 'New custom value', issue.custom_value_for(2).value
1369 assert_equal 'New custom value', issue.custom_value_for(2).value
1350
1370
1351 mail = ActionMailer::Base.deliveries.last
1371 mail = ActionMailer::Base.deliveries.last
1352 assert_kind_of TMail::Mail, mail
1372 assert_kind_of TMail::Mail, mail
1353 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1373 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1354 end
1374 end
1355
1375
1356 def test_put_update_with_status_and_assignee_change
1376 def test_put_update_with_status_and_assignee_change
1357 issue = Issue.find(1)
1377 issue = Issue.find(1)
1358 assert_equal 1, issue.status_id
1378 assert_equal 1, issue.status_id
1359 @request.session[:user_id] = 2
1379 @request.session[:user_id] = 2
1360 assert_difference('TimeEntry.count', 0) do
1380 assert_difference('TimeEntry.count', 0) do
1361 put :update,
1381 put :update,
1362 :id => 1,
1382 :id => 1,
1363 :issue => { :status_id => 2, :assigned_to_id => 3 },
1383 :issue => { :status_id => 2, :assigned_to_id => 3 },
1364 :notes => 'Assigned to dlopper',
1384 :notes => 'Assigned to dlopper',
1365 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1385 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1366 end
1386 end
1367 assert_redirected_to :action => 'show', :id => '1'
1387 assert_redirected_to :action => 'show', :id => '1'
1368 issue.reload
1388 issue.reload
1369 assert_equal 2, issue.status_id
1389 assert_equal 2, issue.status_id
1370 j = Journal.find(:first, :order => 'id DESC')
1390 j = Journal.find(:first, :order => 'id DESC')
1371 assert_equal 'Assigned to dlopper', j.notes
1391 assert_equal 'Assigned to dlopper', j.notes
1372 assert_equal 2, j.details.size
1392 assert_equal 2, j.details.size
1373
1393
1374 mail = ActionMailer::Base.deliveries.last
1394 mail = ActionMailer::Base.deliveries.last
1375 assert mail.body.include?("Status changed from New to Assigned")
1395 assert mail.body.include?("Status changed from New to Assigned")
1376 # subject should contain the new status
1396 # subject should contain the new status
1377 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1397 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1378 end
1398 end
1379
1399
1380 def test_put_update_with_note_only
1400 def test_put_update_with_note_only
1381 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1401 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1382 # anonymous user
1402 # anonymous user
1383 put :update,
1403 put :update,
1384 :id => 1,
1404 :id => 1,
1385 :notes => notes
1405 :notes => notes
1386 assert_redirected_to :action => 'show', :id => '1'
1406 assert_redirected_to :action => 'show', :id => '1'
1387 j = Journal.find(:first, :order => 'id DESC')
1407 j = Journal.find(:first, :order => 'id DESC')
1388 assert_equal notes, j.notes
1408 assert_equal notes, j.notes
1389 assert_equal 0, j.details.size
1409 assert_equal 0, j.details.size
1390 assert_equal User.anonymous, j.user
1410 assert_equal User.anonymous, j.user
1391
1411
1392 mail = ActionMailer::Base.deliveries.last
1412 mail = ActionMailer::Base.deliveries.last
1393 assert mail.body.include?(notes)
1413 assert mail.body.include?(notes)
1394 end
1414 end
1395
1415
1396 def test_put_update_with_note_and_spent_time
1416 def test_put_update_with_note_and_spent_time
1397 @request.session[:user_id] = 2
1417 @request.session[:user_id] = 2
1398 spent_hours_before = Issue.find(1).spent_hours
1418 spent_hours_before = Issue.find(1).spent_hours
1399 assert_difference('TimeEntry.count') do
1419 assert_difference('TimeEntry.count') do
1400 put :update,
1420 put :update,
1401 :id => 1,
1421 :id => 1,
1402 :notes => '2.5 hours added',
1422 :notes => '2.5 hours added',
1403 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1423 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
1404 end
1424 end
1405 assert_redirected_to :action => 'show', :id => '1'
1425 assert_redirected_to :action => 'show', :id => '1'
1406
1426
1407 issue = Issue.find(1)
1427 issue = Issue.find(1)
1408
1428
1409 j = Journal.find(:first, :order => 'id DESC')
1429 j = Journal.find(:first, :order => 'id DESC')
1410 assert_equal '2.5 hours added', j.notes
1430 assert_equal '2.5 hours added', j.notes
1411 assert_equal 0, j.details.size
1431 assert_equal 0, j.details.size
1412
1432
1413 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1433 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
1414 assert_not_nil t
1434 assert_not_nil t
1415 assert_equal 2.5, t.hours
1435 assert_equal 2.5, t.hours
1416 assert_equal spent_hours_before + 2.5, issue.spent_hours
1436 assert_equal spent_hours_before + 2.5, issue.spent_hours
1417 end
1437 end
1418
1438
1419 def test_put_update_with_attachment_only
1439 def test_put_update_with_attachment_only
1420 set_tmp_attachments_directory
1440 set_tmp_attachments_directory
1421
1441
1422 # Delete all fixtured journals, a race condition can occur causing the wrong
1442 # Delete all fixtured journals, a race condition can occur causing the wrong
1423 # journal to get fetched in the next find.
1443 # journal to get fetched in the next find.
1424 Journal.delete_all
1444 Journal.delete_all
1425
1445
1426 # anonymous user
1446 # anonymous user
1427 assert_difference 'Attachment.count' do
1447 assert_difference 'Attachment.count' do
1428 put :update, :id => 1,
1448 put :update, :id => 1,
1429 :notes => '',
1449 :notes => '',
1430 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1450 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1431 end
1451 end
1432
1452
1433 assert_redirected_to :action => 'show', :id => '1'
1453 assert_redirected_to :action => 'show', :id => '1'
1434 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1454 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
1435 assert j.notes.blank?
1455 assert j.notes.blank?
1436 assert_equal 1, j.details.size
1456 assert_equal 1, j.details.size
1437 assert_equal 'testfile.txt', j.details.first.value
1457 assert_equal 'testfile.txt', j.details.first.value
1438 assert_equal User.anonymous, j.user
1458 assert_equal User.anonymous, j.user
1439
1459
1440 attachment = Attachment.first(:order => 'id DESC')
1460 attachment = Attachment.first(:order => 'id DESC')
1441 assert_equal Issue.find(1), attachment.container
1461 assert_equal Issue.find(1), attachment.container
1442 assert_equal User.anonymous, attachment.author
1462 assert_equal User.anonymous, attachment.author
1443 assert_equal 'testfile.txt', attachment.filename
1463 assert_equal 'testfile.txt', attachment.filename
1444 assert_equal 'text/plain', attachment.content_type
1464 assert_equal 'text/plain', attachment.content_type
1445 assert_equal 'test file', attachment.description
1465 assert_equal 'test file', attachment.description
1446 assert_equal 59, attachment.filesize
1466 assert_equal 59, attachment.filesize
1447 assert File.exists?(attachment.diskfile)
1467 assert File.exists?(attachment.diskfile)
1448 assert_equal 59, File.size(attachment.diskfile)
1468 assert_equal 59, File.size(attachment.diskfile)
1449
1469
1450 mail = ActionMailer::Base.deliveries.last
1470 mail = ActionMailer::Base.deliveries.last
1451 assert mail.body.include?('testfile.txt')
1471 assert mail.body.include?('testfile.txt')
1452 end
1472 end
1453
1473
1454 def test_put_update_with_attachment_that_fails_to_save
1474 def test_put_update_with_attachment_that_fails_to_save
1455 set_tmp_attachments_directory
1475 set_tmp_attachments_directory
1456
1476
1457 # Delete all fixtured journals, a race condition can occur causing the wrong
1477 # Delete all fixtured journals, a race condition can occur causing the wrong
1458 # journal to get fetched in the next find.
1478 # journal to get fetched in the next find.
1459 Journal.delete_all
1479 Journal.delete_all
1460
1480
1461 # Mock out the unsaved attachment
1481 # Mock out the unsaved attachment
1462 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1482 Attachment.any_instance.stubs(:create).returns(Attachment.new)
1463
1483
1464 # anonymous user
1484 # anonymous user
1465 put :update,
1485 put :update,
1466 :id => 1,
1486 :id => 1,
1467 :notes => '',
1487 :notes => '',
1468 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1488 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
1469 assert_redirected_to :action => 'show', :id => '1'
1489 assert_redirected_to :action => 'show', :id => '1'
1470 assert_equal '1 file(s) could not be saved.', flash[:warning]
1490 assert_equal '1 file(s) could not be saved.', flash[:warning]
1471
1491
1472 end if Object.const_defined?(:Mocha)
1492 end if Object.const_defined?(:Mocha)
1473
1493
1474 def test_put_update_with_no_change
1494 def test_put_update_with_no_change
1475 issue = Issue.find(1)
1495 issue = Issue.find(1)
1476 issue.journals.clear
1496 issue.journals.clear
1477 ActionMailer::Base.deliveries.clear
1497 ActionMailer::Base.deliveries.clear
1478
1498
1479 put :update,
1499 put :update,
1480 :id => 1,
1500 :id => 1,
1481 :notes => ''
1501 :notes => ''
1482 assert_redirected_to :action => 'show', :id => '1'
1502 assert_redirected_to :action => 'show', :id => '1'
1483
1503
1484 issue.reload
1504 issue.reload
1485 assert issue.journals.empty?
1505 assert issue.journals.empty?
1486 # No email should be sent
1506 # No email should be sent
1487 assert ActionMailer::Base.deliveries.empty?
1507 assert ActionMailer::Base.deliveries.empty?
1488 end
1508 end
1489
1509
1490 def test_put_update_should_send_a_notification
1510 def test_put_update_should_send_a_notification
1491 @request.session[:user_id] = 2
1511 @request.session[:user_id] = 2
1492 ActionMailer::Base.deliveries.clear
1512 ActionMailer::Base.deliveries.clear
1493 issue = Issue.find(1)
1513 issue = Issue.find(1)
1494 old_subject = issue.subject
1514 old_subject = issue.subject
1495 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1515 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1496
1516
1497 put :update, :id => 1, :issue => {:subject => new_subject,
1517 put :update, :id => 1, :issue => {:subject => new_subject,
1498 :priority_id => '6',
1518 :priority_id => '6',
1499 :category_id => '1' # no change
1519 :category_id => '1' # no change
1500 }
1520 }
1501 assert_equal 1, ActionMailer::Base.deliveries.size
1521 assert_equal 1, ActionMailer::Base.deliveries.size
1502 end
1522 end
1503
1523
1504 def test_put_update_with_invalid_spent_time_hours_only
1524 def test_put_update_with_invalid_spent_time_hours_only
1505 @request.session[:user_id] = 2
1525 @request.session[:user_id] = 2
1506 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1526 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1507
1527
1508 assert_no_difference('Journal.count') do
1528 assert_no_difference('Journal.count') do
1509 put :update,
1529 put :update,
1510 :id => 1,
1530 :id => 1,
1511 :notes => notes,
1531 :notes => notes,
1512 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1532 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1513 end
1533 end
1514 assert_response :success
1534 assert_response :success
1515 assert_template 'edit'
1535 assert_template 'edit'
1516
1536
1517 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1537 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1518 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1538 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1519 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1539 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1520 end
1540 end
1521
1541
1522 def test_put_update_with_invalid_spent_time_comments_only
1542 def test_put_update_with_invalid_spent_time_comments_only
1523 @request.session[:user_id] = 2
1543 @request.session[:user_id] = 2
1524 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1544 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1525
1545
1526 assert_no_difference('Journal.count') do
1546 assert_no_difference('Journal.count') do
1527 put :update,
1547 put :update,
1528 :id => 1,
1548 :id => 1,
1529 :notes => notes,
1549 :notes => notes,
1530 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1550 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1531 end
1551 end
1532 assert_response :success
1552 assert_response :success
1533 assert_template 'edit'
1553 assert_template 'edit'
1534
1554
1535 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1555 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1536 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1556 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1537 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1557 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1538 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1558 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1539 end
1559 end
1540
1560
1541 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1561 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1542 issue = Issue.find(2)
1562 issue = Issue.find(2)
1543 @request.session[:user_id] = 2
1563 @request.session[:user_id] = 2
1544
1564
1545 put :update,
1565 put :update,
1546 :id => issue.id,
1566 :id => issue.id,
1547 :issue => {
1567 :issue => {
1548 :fixed_version_id => 4
1568 :fixed_version_id => 4
1549 }
1569 }
1550
1570
1551 assert_response :redirect
1571 assert_response :redirect
1552 issue.reload
1572 issue.reload
1553 assert_equal 4, issue.fixed_version_id
1573 assert_equal 4, issue.fixed_version_id
1554 assert_not_equal issue.project_id, issue.fixed_version.project_id
1574 assert_not_equal issue.project_id, issue.fixed_version.project_id
1555 end
1575 end
1556
1576
1557 def test_put_update_should_redirect_back_using_the_back_url_parameter
1577 def test_put_update_should_redirect_back_using_the_back_url_parameter
1558 issue = Issue.find(2)
1578 issue = Issue.find(2)
1559 @request.session[:user_id] = 2
1579 @request.session[:user_id] = 2
1560
1580
1561 put :update,
1581 put :update,
1562 :id => issue.id,
1582 :id => issue.id,
1563 :issue => {
1583 :issue => {
1564 :fixed_version_id => 4
1584 :fixed_version_id => 4
1565 },
1585 },
1566 :back_url => '/issues'
1586 :back_url => '/issues'
1567
1587
1568 assert_response :redirect
1588 assert_response :redirect
1569 assert_redirected_to '/issues'
1589 assert_redirected_to '/issues'
1570 end
1590 end
1571
1591
1572 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1592 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1573 issue = Issue.find(2)
1593 issue = Issue.find(2)
1574 @request.session[:user_id] = 2
1594 @request.session[:user_id] = 2
1575
1595
1576 put :update,
1596 put :update,
1577 :id => issue.id,
1597 :id => issue.id,
1578 :issue => {
1598 :issue => {
1579 :fixed_version_id => 4
1599 :fixed_version_id => 4
1580 },
1600 },
1581 :back_url => 'http://google.com'
1601 :back_url => 'http://google.com'
1582
1602
1583 assert_response :redirect
1603 assert_response :redirect
1584 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1604 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1585 end
1605 end
1586
1606
1587 def test_get_bulk_edit
1607 def test_get_bulk_edit
1588 @request.session[:user_id] = 2
1608 @request.session[:user_id] = 2
1589 get :bulk_edit, :ids => [1, 2]
1609 get :bulk_edit, :ids => [1, 2]
1590 assert_response :success
1610 assert_response :success
1591 assert_template 'bulk_edit'
1611 assert_template 'bulk_edit'
1592
1612
1593 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1613 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1594
1614
1595 # Project specific custom field, date type
1615 # Project specific custom field, date type
1596 field = CustomField.find(9)
1616 field = CustomField.find(9)
1597 assert !field.is_for_all?
1617 assert !field.is_for_all?
1598 assert_equal 'date', field.field_format
1618 assert_equal 'date', field.field_format
1599 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1619 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1600
1620
1601 # System wide custom field
1621 # System wide custom field
1602 assert CustomField.find(1).is_for_all?
1622 assert CustomField.find(1).is_for_all?
1603 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1623 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1604
1624
1605 # Be sure we don't display inactive IssuePriorities
1625 # Be sure we don't display inactive IssuePriorities
1606 assert ! IssuePriority.find(15).active?
1626 assert ! IssuePriority.find(15).active?
1607 assert_no_tag :option, :attributes => {:value => '15'},
1627 assert_no_tag :option, :attributes => {:value => '15'},
1608 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1628 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1609 end
1629 end
1610
1630
1611 def test_get_bulk_edit_on_different_projects
1631 def test_get_bulk_edit_on_different_projects
1612 @request.session[:user_id] = 2
1632 @request.session[:user_id] = 2
1613 get :bulk_edit, :ids => [1, 2, 6]
1633 get :bulk_edit, :ids => [1, 2, 6]
1614 assert_response :success
1634 assert_response :success
1615 assert_template 'bulk_edit'
1635 assert_template 'bulk_edit'
1616
1636
1617 # Can not set issues from different projects as children of an issue
1637 # Can not set issues from different projects as children of an issue
1618 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1638 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1619
1639
1620 # Project specific custom field, date type
1640 # Project specific custom field, date type
1621 field = CustomField.find(9)
1641 field = CustomField.find(9)
1622 assert !field.is_for_all?
1642 assert !field.is_for_all?
1623 assert !field.project_ids.include?(Issue.find(6).project_id)
1643 assert !field.project_ids.include?(Issue.find(6).project_id)
1624 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1644 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1625 end
1645 end
1626
1646
1627 def test_get_bulk_edit_with_user_custom_field
1647 def test_get_bulk_edit_with_user_custom_field
1628 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1648 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
1629
1649
1630 @request.session[:user_id] = 2
1650 @request.session[:user_id] = 2
1631 get :bulk_edit, :ids => [1, 2]
1651 get :bulk_edit, :ids => [1, 2]
1632 assert_response :success
1652 assert_response :success
1633 assert_template 'bulk_edit'
1653 assert_template 'bulk_edit'
1634
1654
1635 assert_tag :select,
1655 assert_tag :select,
1636 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1656 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1637 :children => {
1657 :children => {
1638 :only => {:tag => 'option'},
1658 :only => {:tag => 'option'},
1639 :count => Project.find(1).users.count + 1
1659 :count => Project.find(1).users.count + 1
1640 }
1660 }
1641 end
1661 end
1642
1662
1643 def test_get_bulk_edit_with_version_custom_field
1663 def test_get_bulk_edit_with_version_custom_field
1644 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1664 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
1645
1665
1646 @request.session[:user_id] = 2
1666 @request.session[:user_id] = 2
1647 get :bulk_edit, :ids => [1, 2]
1667 get :bulk_edit, :ids => [1, 2]
1648 assert_response :success
1668 assert_response :success
1649 assert_template 'bulk_edit'
1669 assert_template 'bulk_edit'
1650
1670
1651 assert_tag :select,
1671 assert_tag :select,
1652 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1672 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
1653 :children => {
1673 :children => {
1654 :only => {:tag => 'option'},
1674 :only => {:tag => 'option'},
1655 :count => Project.find(1).shared_versions.count + 1
1675 :count => Project.find(1).shared_versions.count + 1
1656 }
1676 }
1657 end
1677 end
1658
1678
1659 def test_bulk_update
1679 def test_bulk_update
1660 @request.session[:user_id] = 2
1680 @request.session[:user_id] = 2
1661 # update issues priority
1681 # update issues priority
1662 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1682 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1663 :issue => {:priority_id => 7,
1683 :issue => {:priority_id => 7,
1664 :assigned_to_id => '',
1684 :assigned_to_id => '',
1665 :custom_field_values => {'2' => ''}}
1685 :custom_field_values => {'2' => ''}}
1666
1686
1667 assert_response 302
1687 assert_response 302
1668 # check that the issues were updated
1688 # check that the issues were updated
1669 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1689 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1670
1690
1671 issue = Issue.find(1)
1691 issue = Issue.find(1)
1672 journal = issue.journals.find(:first, :order => 'created_on DESC')
1692 journal = issue.journals.find(:first, :order => 'created_on DESC')
1673 assert_equal '125', issue.custom_value_for(2).value
1693 assert_equal '125', issue.custom_value_for(2).value
1674 assert_equal 'Bulk editing', journal.notes
1694 assert_equal 'Bulk editing', journal.notes
1675 assert_equal 1, journal.details.size
1695 assert_equal 1, journal.details.size
1676 end
1696 end
1677
1697
1678 def test_bulk_update_with_group_assignee
1698 def test_bulk_update_with_group_assignee
1679 group = Group.find(11)
1699 group = Group.find(11)
1680 project = Project.find(1)
1700 project = Project.find(1)
1681 project.members << Member.new(:principal => group, :roles => [Role.first])
1701 project.members << Member.new(:principal => group, :roles => [Role.first])
1682
1702
1683 @request.session[:user_id] = 2
1703 @request.session[:user_id] = 2
1684 # update issues assignee
1704 # update issues assignee
1685 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1705 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1686 :issue => {:priority_id => '',
1706 :issue => {:priority_id => '',
1687 :assigned_to_id => group.id,
1707 :assigned_to_id => group.id,
1688 :custom_field_values => {'2' => ''}}
1708 :custom_field_values => {'2' => ''}}
1689
1709
1690 assert_response 302
1710 assert_response 302
1691 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1711 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
1692 end
1712 end
1693
1713
1694 def test_bulk_update_on_different_projects
1714 def test_bulk_update_on_different_projects
1695 @request.session[:user_id] = 2
1715 @request.session[:user_id] = 2
1696 # update issues priority
1716 # update issues priority
1697 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1717 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1698 :issue => {:priority_id => 7,
1718 :issue => {:priority_id => 7,
1699 :assigned_to_id => '',
1719 :assigned_to_id => '',
1700 :custom_field_values => {'2' => ''}}
1720 :custom_field_values => {'2' => ''}}
1701
1721
1702 assert_response 302
1722 assert_response 302
1703 # check that the issues were updated
1723 # check that the issues were updated
1704 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1724 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1705
1725
1706 issue = Issue.find(1)
1726 issue = Issue.find(1)
1707 journal = issue.journals.find(:first, :order => 'created_on DESC')
1727 journal = issue.journals.find(:first, :order => 'created_on DESC')
1708 assert_equal '125', issue.custom_value_for(2).value
1728 assert_equal '125', issue.custom_value_for(2).value
1709 assert_equal 'Bulk editing', journal.notes
1729 assert_equal 'Bulk editing', journal.notes
1710 assert_equal 1, journal.details.size
1730 assert_equal 1, journal.details.size
1711 end
1731 end
1712
1732
1713 def test_bulk_update_on_different_projects_without_rights
1733 def test_bulk_update_on_different_projects_without_rights
1714 @request.session[:user_id] = 3
1734 @request.session[:user_id] = 3
1715 user = User.find(3)
1735 user = User.find(3)
1716 action = { :controller => "issues", :action => "bulk_update" }
1736 action = { :controller => "issues", :action => "bulk_update" }
1717 assert user.allowed_to?(action, Issue.find(1).project)
1737 assert user.allowed_to?(action, Issue.find(1).project)
1718 assert ! user.allowed_to?(action, Issue.find(6).project)
1738 assert ! user.allowed_to?(action, Issue.find(6).project)
1719 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1739 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1720 :issue => {:priority_id => 7,
1740 :issue => {:priority_id => 7,
1721 :assigned_to_id => '',
1741 :assigned_to_id => '',
1722 :custom_field_values => {'2' => ''}}
1742 :custom_field_values => {'2' => ''}}
1723 assert_response 403
1743 assert_response 403
1724 assert_not_equal "Bulk should fail", Journal.last.notes
1744 assert_not_equal "Bulk should fail", Journal.last.notes
1725 end
1745 end
1726
1746
1727 def test_bullk_update_should_send_a_notification
1747 def test_bullk_update_should_send_a_notification
1728 @request.session[:user_id] = 2
1748 @request.session[:user_id] = 2
1729 ActionMailer::Base.deliveries.clear
1749 ActionMailer::Base.deliveries.clear
1730 post(:bulk_update,
1750 post(:bulk_update,
1731 {
1751 {
1732 :ids => [1, 2],
1752 :ids => [1, 2],
1733 :notes => 'Bulk editing',
1753 :notes => 'Bulk editing',
1734 :issue => {
1754 :issue => {
1735 :priority_id => 7,
1755 :priority_id => 7,
1736 :assigned_to_id => '',
1756 :assigned_to_id => '',
1737 :custom_field_values => {'2' => ''}
1757 :custom_field_values => {'2' => ''}
1738 }
1758 }
1739 })
1759 })
1740
1760
1741 assert_response 302
1761 assert_response 302
1742 assert_equal 2, ActionMailer::Base.deliveries.size
1762 assert_equal 2, ActionMailer::Base.deliveries.size
1743 end
1763 end
1744
1764
1745 def test_bulk_update_status
1765 def test_bulk_update_status
1746 @request.session[:user_id] = 2
1766 @request.session[:user_id] = 2
1747 # update issues priority
1767 # update issues priority
1748 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1768 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1749 :issue => {:priority_id => '',
1769 :issue => {:priority_id => '',
1750 :assigned_to_id => '',
1770 :assigned_to_id => '',
1751 :status_id => '5'}
1771 :status_id => '5'}
1752
1772
1753 assert_response 302
1773 assert_response 302
1754 issue = Issue.find(1)
1774 issue = Issue.find(1)
1755 assert issue.closed?
1775 assert issue.closed?
1756 end
1776 end
1757
1777
1758 def test_bulk_update_parent_id
1778 def test_bulk_update_parent_id
1759 @request.session[:user_id] = 2
1779 @request.session[:user_id] = 2
1760 post :bulk_update, :ids => [1, 3],
1780 post :bulk_update, :ids => [1, 3],
1761 :notes => 'Bulk editing parent',
1781 :notes => 'Bulk editing parent',
1762 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1782 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1763
1783
1764 assert_response 302
1784 assert_response 302
1765 parent = Issue.find(2)
1785 parent = Issue.find(2)
1766 assert_equal parent.id, Issue.find(1).parent_id
1786 assert_equal parent.id, Issue.find(1).parent_id
1767 assert_equal parent.id, Issue.find(3).parent_id
1787 assert_equal parent.id, Issue.find(3).parent_id
1768 assert_equal [1, 3], parent.children.collect(&:id).sort
1788 assert_equal [1, 3], parent.children.collect(&:id).sort
1769 end
1789 end
1770
1790
1771 def test_bulk_update_custom_field
1791 def test_bulk_update_custom_field
1772 @request.session[:user_id] = 2
1792 @request.session[:user_id] = 2
1773 # update issues priority
1793 # update issues priority
1774 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1794 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1775 :issue => {:priority_id => '',
1795 :issue => {:priority_id => '',
1776 :assigned_to_id => '',
1796 :assigned_to_id => '',
1777 :custom_field_values => {'2' => '777'}}
1797 :custom_field_values => {'2' => '777'}}
1778
1798
1779 assert_response 302
1799 assert_response 302
1780
1800
1781 issue = Issue.find(1)
1801 issue = Issue.find(1)
1782 journal = issue.journals.find(:first, :order => 'created_on DESC')
1802 journal = issue.journals.find(:first, :order => 'created_on DESC')
1783 assert_equal '777', issue.custom_value_for(2).value
1803 assert_equal '777', issue.custom_value_for(2).value
1784 assert_equal 1, journal.details.size
1804 assert_equal 1, journal.details.size
1785 assert_equal '125', journal.details.first.old_value
1805 assert_equal '125', journal.details.first.old_value
1786 assert_equal '777', journal.details.first.value
1806 assert_equal '777', journal.details.first.value
1787 end
1807 end
1788
1808
1789 def test_bulk_update_unassign
1809 def test_bulk_update_unassign
1790 assert_not_nil Issue.find(2).assigned_to
1810 assert_not_nil Issue.find(2).assigned_to
1791 @request.session[:user_id] = 2
1811 @request.session[:user_id] = 2
1792 # unassign issues
1812 # unassign issues
1793 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1813 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1794 assert_response 302
1814 assert_response 302
1795 # check that the issues were updated
1815 # check that the issues were updated
1796 assert_nil Issue.find(2).assigned_to
1816 assert_nil Issue.find(2).assigned_to
1797 end
1817 end
1798
1818
1799 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1819 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1800 @request.session[:user_id] = 2
1820 @request.session[:user_id] = 2
1801
1821
1802 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1822 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1803
1823
1804 assert_response :redirect
1824 assert_response :redirect
1805 issues = Issue.find([1,2])
1825 issues = Issue.find([1,2])
1806 issues.each do |issue|
1826 issues.each do |issue|
1807 assert_equal 4, issue.fixed_version_id
1827 assert_equal 4, issue.fixed_version_id
1808 assert_not_equal issue.project_id, issue.fixed_version.project_id
1828 assert_not_equal issue.project_id, issue.fixed_version.project_id
1809 end
1829 end
1810 end
1830 end
1811
1831
1812 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1832 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1813 @request.session[:user_id] = 2
1833 @request.session[:user_id] = 2
1814 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1834 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1815
1835
1816 assert_response :redirect
1836 assert_response :redirect
1817 assert_redirected_to '/issues'
1837 assert_redirected_to '/issues'
1818 end
1838 end
1819
1839
1820 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1840 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1821 @request.session[:user_id] = 2
1841 @request.session[:user_id] = 2
1822 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1842 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1823
1843
1824 assert_response :redirect
1844 assert_response :redirect
1825 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1845 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1826 end
1846 end
1827
1847
1828 def test_destroy_issue_with_no_time_entries
1848 def test_destroy_issue_with_no_time_entries
1829 assert_nil TimeEntry.find_by_issue_id(2)
1849 assert_nil TimeEntry.find_by_issue_id(2)
1830 @request.session[:user_id] = 2
1850 @request.session[:user_id] = 2
1831 post :destroy, :id => 2
1851 post :destroy, :id => 2
1832 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1852 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1833 assert_nil Issue.find_by_id(2)
1853 assert_nil Issue.find_by_id(2)
1834 end
1854 end
1835
1855
1836 def test_destroy_issues_with_time_entries
1856 def test_destroy_issues_with_time_entries
1837 @request.session[:user_id] = 2
1857 @request.session[:user_id] = 2
1838 post :destroy, :ids => [1, 3]
1858 post :destroy, :ids => [1, 3]
1839 assert_response :success
1859 assert_response :success
1840 assert_template 'destroy'
1860 assert_template 'destroy'
1841 assert_not_nil assigns(:hours)
1861 assert_not_nil assigns(:hours)
1842 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1862 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1843 end
1863 end
1844
1864
1845 def test_destroy_issues_and_destroy_time_entries
1865 def test_destroy_issues_and_destroy_time_entries
1846 @request.session[:user_id] = 2
1866 @request.session[:user_id] = 2
1847 post :destroy, :ids => [1, 3], :todo => 'destroy'
1867 post :destroy, :ids => [1, 3], :todo => 'destroy'
1848 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1868 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1849 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1869 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1850 assert_nil TimeEntry.find_by_id([1, 2])
1870 assert_nil TimeEntry.find_by_id([1, 2])
1851 end
1871 end
1852
1872
1853 def test_destroy_issues_and_assign_time_entries_to_project
1873 def test_destroy_issues_and_assign_time_entries_to_project
1854 @request.session[:user_id] = 2
1874 @request.session[:user_id] = 2
1855 post :destroy, :ids => [1, 3], :todo => 'nullify'
1875 post :destroy, :ids => [1, 3], :todo => 'nullify'
1856 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1876 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1857 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1877 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1858 assert_nil TimeEntry.find(1).issue_id
1878 assert_nil TimeEntry.find(1).issue_id
1859 assert_nil TimeEntry.find(2).issue_id
1879 assert_nil TimeEntry.find(2).issue_id
1860 end
1880 end
1861
1881
1862 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1882 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1863 @request.session[:user_id] = 2
1883 @request.session[:user_id] = 2
1864 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1884 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1865 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1885 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1866 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1886 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1867 assert_equal 2, TimeEntry.find(1).issue_id
1887 assert_equal 2, TimeEntry.find(1).issue_id
1868 assert_equal 2, TimeEntry.find(2).issue_id
1888 assert_equal 2, TimeEntry.find(2).issue_id
1869 end
1889 end
1870
1890
1871 def test_destroy_issues_from_different_projects
1891 def test_destroy_issues_from_different_projects
1872 @request.session[:user_id] = 2
1892 @request.session[:user_id] = 2
1873 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1893 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1874 assert_redirected_to :controller => 'issues', :action => 'index'
1894 assert_redirected_to :controller => 'issues', :action => 'index'
1875 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1895 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1876 end
1896 end
1877
1897
1878 def test_destroy_parent_and_child_issues
1898 def test_destroy_parent_and_child_issues
1879 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1899 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1880 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1900 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1881 assert child.is_descendant_of?(parent.reload)
1901 assert child.is_descendant_of?(parent.reload)
1882
1902
1883 @request.session[:user_id] = 2
1903 @request.session[:user_id] = 2
1884 assert_difference 'Issue.count', -2 do
1904 assert_difference 'Issue.count', -2 do
1885 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1905 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1886 end
1906 end
1887 assert_response 302
1907 assert_response 302
1888 end
1908 end
1889
1909
1890 def test_default_search_scope
1910 def test_default_search_scope
1891 get :index
1911 get :index
1892 assert_tag :div, :attributes => {:id => 'quick-search'},
1912 assert_tag :div, :attributes => {:id => 'quick-search'},
1893 :child => {:tag => 'form',
1913 :child => {:tag => 'form',
1894 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1914 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1895 end
1915 end
1896 end
1916 end
General Comments 0
You need to be logged in to leave comments. Login now