##// END OF EJS Templates
Fixes tests broken by r2532 (#2853)....
Jean-Philippe Lang -
r2470:a95a8aa40b7a
parent child
Show More
@@ -1,501 +1,501
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'projects_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class ProjectsController; def rescue_action(e) raise e end; end
23 23
24 24 class ProjectsControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details,
26 26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
27 27 :attachments
28 28
29 29 def setup
30 30 @controller = ProjectsController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 @request.session[:user_id] = nil
34 34 Setting.default_language = 'en'
35 35 end
36 36
37 37 def test_index_routing
38 38 assert_routing(
39 39 {:method => :get, :path => '/projects'},
40 40 :controller => 'projects', :action => 'index'
41 41 )
42 42 end
43 43
44 44 def test_index
45 45 get :index
46 46 assert_response :success
47 47 assert_template 'index'
48 48 assert_not_nil assigns(:projects)
49 49
50 50 assert_tag :ul, :child => {:tag => 'li',
51 51 :descendant => {:tag => 'a', :content => 'eCookbook'},
52 52 :child => { :tag => 'ul',
53 53 :descendant => { :tag => 'a',
54 54 :content => 'Child of private child'
55 55 }
56 56 }
57 57 }
58 58
59 59 assert_no_tag :a, :content => /Private child of eCookbook/
60 60 end
61 61
62 62 def test_index_atom_routing
63 63 assert_routing(
64 64 {:method => :get, :path => '/projects.atom'},
65 65 :controller => 'projects', :action => 'index', :format => 'atom'
66 66 )
67 67 end
68 68
69 69 def test_index_atom
70 70 get :index, :format => 'atom'
71 71 assert_response :success
72 72 assert_template 'common/feed.atom.rxml'
73 73 assert_select 'feed>title', :text => 'Redmine: Latest projects'
74 74 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current))
75 75 end
76 76
77 77 def test_add_routing
78 78 assert_routing(
79 79 {:method => :get, :path => '/projects/new'},
80 80 :controller => 'projects', :action => 'add'
81 81 )
82 82 assert_recognizes(
83 83 {:controller => 'projects', :action => 'add'},
84 84 {:method => :post, :path => '/projects/new'}
85 85 )
86 86 assert_recognizes(
87 87 {:controller => 'projects', :action => 'add'},
88 88 {:method => :post, :path => '/projects'}
89 89 )
90 90 end
91 91
92 92 def test_show_routing
93 93 assert_routing(
94 94 {:method => :get, :path => '/projects/test'},
95 95 :controller => 'projects', :action => 'show', :id => 'test'
96 96 )
97 97 end
98 98
99 99 def test_show_by_id
100 100 get :show, :id => 1
101 101 assert_response :success
102 102 assert_template 'show'
103 103 assert_not_nil assigns(:project)
104 104 end
105 105
106 106 def test_show_by_identifier
107 107 get :show, :id => 'ecookbook'
108 108 assert_response :success
109 109 assert_template 'show'
110 110 assert_not_nil assigns(:project)
111 111 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project)
112 112 end
113 113
114 114 def test_private_subprojects_hidden
115 115 get :show, :id => 'ecookbook'
116 116 assert_response :success
117 117 assert_template 'show'
118 118 assert_no_tag :tag => 'a', :content => /Private child/
119 119 end
120 120
121 121 def test_private_subprojects_visible
122 122 @request.session[:user_id] = 2 # manager who is a member of the private subproject
123 123 get :show, :id => 'ecookbook'
124 124 assert_response :success
125 125 assert_template 'show'
126 126 assert_tag :tag => 'a', :content => /Private child/
127 127 end
128 128
129 129 def test_settings_routing
130 130 assert_routing(
131 131 {:method => :get, :path => '/projects/4223/settings'},
132 132 :controller => 'projects', :action => 'settings', :id => '4223'
133 133 )
134 134 assert_routing(
135 135 {:method => :get, :path => '/projects/4223/settings/members'},
136 136 :controller => 'projects', :action => 'settings', :id => '4223', :tab => 'members'
137 137 )
138 138 end
139 139
140 140 def test_settings
141 141 @request.session[:user_id] = 2 # manager
142 142 get :settings, :id => 1
143 143 assert_response :success
144 144 assert_template 'settings'
145 145 end
146 146
147 147 def test_edit
148 148 @request.session[:user_id] = 2 # manager
149 149 post :edit, :id => 1, :project => {:name => 'Test changed name',
150 150 :issue_custom_field_ids => ['']}
151 151 assert_redirected_to 'projects/ecookbook/settings'
152 152 project = Project.find(1)
153 153 assert_equal 'Test changed name', project.name
154 154 end
155 155
156 156 def test_add_version_routing
157 157 assert_routing(
158 158 {:method => :get, :path => 'projects/64/versions/new'},
159 159 :controller => 'projects', :action => 'add_version', :id => '64'
160 160 )
161 161 assert_routing(
162 162 #TODO: use PUT
163 163 {:method => :post, :path => 'projects/64/versions/new'},
164 164 :controller => 'projects', :action => 'add_version', :id => '64'
165 165 )
166 166 end
167 167
168 168 def test_add_issue_category_routing
169 169 assert_routing(
170 170 {:method => :get, :path => 'projects/test/categories/new'},
171 171 :controller => 'projects', :action => 'add_issue_category', :id => 'test'
172 172 )
173 173 assert_routing(
174 174 #TODO: use PUT and update form
175 175 {:method => :post, :path => 'projects/64/categories/new'},
176 176 :controller => 'projects', :action => 'add_issue_category', :id => '64'
177 177 )
178 178 end
179 179
180 180 def test_destroy_routing
181 181 assert_routing(
182 182 {:method => :get, :path => '/projects/567/destroy'},
183 183 :controller => 'projects', :action => 'destroy', :id => '567'
184 184 )
185 185 assert_routing(
186 186 #TODO: use DELETE and update form
187 187 {:method => :post, :path => 'projects/64/destroy'},
188 188 :controller => 'projects', :action => 'destroy', :id => '64'
189 189 )
190 190 end
191 191
192 192 def test_get_destroy
193 193 @request.session[:user_id] = 1 # admin
194 194 get :destroy, :id => 1
195 195 assert_response :success
196 196 assert_template 'destroy'
197 197 assert_not_nil Project.find_by_id(1)
198 198 end
199 199
200 200 def test_post_destroy
201 201 @request.session[:user_id] = 1 # admin
202 202 post :destroy, :id => 1, :confirm => 1
203 203 assert_redirected_to 'admin/projects'
204 204 assert_nil Project.find_by_id(1)
205 205 end
206 206
207 207 def test_add_file
208 208 set_tmp_attachments_directory
209 209 @request.session[:user_id] = 2
210 210 Setting.notified_events = ['file_added']
211 211 ActionMailer::Base.deliveries.clear
212 212
213 213 assert_difference 'Attachment.count' do
214 214 post :add_file, :id => 1, :version_id => '',
215 215 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
216 216 end
217 217 assert_redirected_to 'projects/ecookbook/files'
218 218 a = Attachment.find(:first, :order => 'created_on DESC')
219 219 assert_equal 'testfile.txt', a.filename
220 220 assert_equal Project.find(1), a.container
221 221
222 222 mail = ActionMailer::Base.deliveries.last
223 223 assert_kind_of TMail::Mail, mail
224 224 assert_equal "[eCookbook] New file", mail.subject
225 225 assert mail.body.include?('testfile.txt')
226 226 end
227 227
228 228 def test_add_file_routing
229 229 assert_routing(
230 230 {:method => :get, :path => '/projects/33/files/new'},
231 231 :controller => 'projects', :action => 'add_file', :id => '33'
232 232 )
233 233 assert_routing(
234 234 {:method => :post, :path => '/projects/33/files/new'},
235 235 :controller => 'projects', :action => 'add_file', :id => '33'
236 236 )
237 237 end
238 238
239 239 def test_add_version_file
240 240 set_tmp_attachments_directory
241 241 @request.session[:user_id] = 2
242 242 Setting.notified_events = ['file_added']
243 243
244 244 assert_difference 'Attachment.count' do
245 245 post :add_file, :id => 1, :version_id => '2',
246 246 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
247 247 end
248 248 assert_redirected_to 'projects/ecookbook/files'
249 249 a = Attachment.find(:first, :order => 'created_on DESC')
250 250 assert_equal 'testfile.txt', a.filename
251 251 assert_equal Version.find(2), a.container
252 252 end
253 253
254 254 def test_list_files
255 255 get :list_files, :id => 1
256 256 assert_response :success
257 257 assert_template 'list_files'
258 258 assert_not_nil assigns(:containers)
259 259
260 260 # file attached to the project
261 261 assert_tag :a, :content => 'project_file.zip',
262 262 :attributes => { :href => '/attachments/download/8/project_file.zip' }
263 263
264 264 # file attached to a project's version
265 265 assert_tag :a, :content => 'version_file.zip',
266 266 :attributes => { :href => '/attachments/download/9/version_file.zip' }
267 267 end
268 268
269 269 def test_list_files_routing
270 270 assert_routing(
271 271 {:method => :get, :path => '/projects/33/files'},
272 272 :controller => 'projects', :action => 'list_files', :id => '33'
273 273 )
274 274 end
275 275
276 276 def test_changelog_routing
277 277 assert_routing(
278 278 {:method => :get, :path => '/projects/44/changelog'},
279 279 :controller => 'projects', :action => 'changelog', :id => '44'
280 280 )
281 281 end
282 282
283 283 def test_changelog
284 284 get :changelog, :id => 1
285 285 assert_response :success
286 286 assert_template 'changelog'
287 287 assert_not_nil assigns(:versions)
288 288 end
289 289
290 290 def test_roadmap_routing
291 291 assert_routing(
292 292 {:method => :get, :path => 'projects/33/roadmap'},
293 293 :controller => 'projects', :action => 'roadmap', :id => '33'
294 294 )
295 295 end
296 296
297 297 def test_roadmap
298 298 get :roadmap, :id => 1
299 299 assert_response :success
300 300 assert_template 'roadmap'
301 301 assert_not_nil assigns(:versions)
302 302 # Version with no date set appears
303 303 assert assigns(:versions).include?(Version.find(3))
304 304 # Completed version doesn't appear
305 305 assert !assigns(:versions).include?(Version.find(1))
306 306 end
307 307
308 308 def test_roadmap_with_completed_versions
309 309 get :roadmap, :id => 1, :completed => 1
310 310 assert_response :success
311 311 assert_template 'roadmap'
312 312 assert_not_nil assigns(:versions)
313 313 # Version with no date set appears
314 314 assert assigns(:versions).include?(Version.find(3))
315 315 # Completed version appears
316 316 assert assigns(:versions).include?(Version.find(1))
317 317 end
318 318
319 319 def test_project_activity_routing
320 320 assert_routing(
321 321 {:method => :get, :path => '/projects/1/activity'},
322 322 :controller => 'projects', :action => 'activity', :id => '1'
323 323 )
324 324 end
325 325
326 326 def test_project_activity_atom_routing
327 327 assert_routing(
328 328 {:method => :get, :path => '/projects/1/activity.atom'},
329 329 :controller => 'projects', :action => 'activity', :id => '1', :format => 'atom'
330 330 )
331 331 end
332 332
333 333 def test_project_activity
334 334 get :activity, :id => 1, :with_subprojects => 0
335 335 assert_response :success
336 336 assert_template 'activity'
337 337 assert_not_nil assigns(:events_by_day)
338 338
339 339 assert_tag :tag => "h3",
340 340 :content => /#{2.days.ago.to_date.day}/,
341 341 :sibling => { :tag => "dl",
342 342 :child => { :tag => "dt",
343 343 :attributes => { :class => /issue-edit/ },
344 344 :child => { :tag => "a",
345 345 :content => /(#{IssueStatus.find(2).name})/,
346 346 }
347 347 }
348 348 }
349 349 end
350 350
351 351 def test_previous_project_activity
352 352 get :activity, :id => 1, :from => 3.days.ago.to_date
353 353 assert_response :success
354 354 assert_template 'activity'
355 355 assert_not_nil assigns(:events_by_day)
356 356
357 357 assert_tag :tag => "h3",
358 358 :content => /#{3.day.ago.to_date.day}/,
359 359 :sibling => { :tag => "dl",
360 360 :child => { :tag => "dt",
361 361 :attributes => { :class => /issue/ },
362 362 :child => { :tag => "a",
363 363 :content => /#{Issue.find(1).subject}/,
364 364 }
365 365 }
366 366 }
367 367 end
368 368
369 369 def test_global_activity_routing
370 assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity')
370 assert_routing({:method => :get, :path => '/activity'}, :controller => 'projects', :action => 'activity', :id => nil)
371 371 end
372 372
373 373 def test_global_activity
374 374 get :activity
375 375 assert_response :success
376 376 assert_template 'activity'
377 377 assert_not_nil assigns(:events_by_day)
378 378
379 379 assert_tag :tag => "h3",
380 380 :content => /#{5.day.ago.to_date.day}/,
381 381 :sibling => { :tag => "dl",
382 382 :child => { :tag => "dt",
383 383 :attributes => { :class => /issue/ },
384 384 :child => { :tag => "a",
385 385 :content => /#{Issue.find(5).subject}/,
386 386 }
387 387 }
388 388 }
389 389 end
390 390
391 391 def test_user_activity
392 392 get :activity, :user_id => 2
393 393 assert_response :success
394 394 assert_template 'activity'
395 395 assert_not_nil assigns(:events_by_day)
396 396
397 397 assert_tag :tag => "h3",
398 398 :content => /#{3.day.ago.to_date.day}/,
399 399 :sibling => { :tag => "dl",
400 400 :child => { :tag => "dt",
401 401 :attributes => { :class => /issue/ },
402 402 :child => { :tag => "a",
403 403 :content => /#{Issue.find(1).subject}/,
404 404 }
405 405 }
406 406 }
407 407 end
408 408
409 409 def test_global_activity_atom_routing
410 assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :format => 'atom')
410 assert_routing({:method => :get, :path => '/activity.atom'}, :controller => 'projects', :action => 'activity', :id => nil, :format => 'atom')
411 411 end
412 412
413 413 def test_activity_atom_feed
414 414 get :activity, :format => 'atom'
415 415 assert_response :success
416 416 assert_template 'common/feed.atom.rxml'
417 417 end
418 418
419 419 def test_archive_routing
420 420 assert_routing(
421 421 #TODO: use PUT to project path and modify form
422 422 {:method => :post, :path => 'projects/64/archive'},
423 423 :controller => 'projects', :action => 'archive', :id => '64'
424 424 )
425 425 end
426 426
427 427 def test_archive
428 428 @request.session[:user_id] = 1 # admin
429 429 post :archive, :id => 1
430 430 assert_redirected_to 'admin/projects'
431 431 assert !Project.find(1).active?
432 432 end
433 433
434 434 def test_unarchive_routing
435 435 assert_routing(
436 436 #TODO: use PUT to project path and modify form
437 437 {:method => :post, :path => '/projects/567/unarchive'},
438 438 :controller => 'projects', :action => 'unarchive', :id => '567'
439 439 )
440 440 end
441 441
442 442 def test_unarchive
443 443 @request.session[:user_id] = 1 # admin
444 444 Project.find(1).archive
445 445 post :unarchive, :id => 1
446 446 assert_redirected_to 'admin/projects'
447 447 assert Project.find(1).active?
448 448 end
449 449
450 450 def test_project_breadcrumbs_should_be_limited_to_3_ancestors
451 451 CustomField.delete_all
452 452 parent = nil
453 453 6.times do |i|
454 454 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}")
455 455 p.set_parent!(parent)
456 456
457 457 get :show, :id => p
458 458 assert_tag :h1, :parent => { :attributes => {:id => 'header'}},
459 459 :children => { :count => [i, 3].min,
460 460 :only => { :tag => 'a' } }
461 461
462 462 parent = p
463 463 end
464 464 end
465 465
466 466 def test_jump_should_redirect_to_active_tab
467 467 get :show, :id => 1, :jump => 'issues'
468 468 assert_redirected_to 'projects/ecookbook/issues'
469 469 end
470 470
471 471 def test_jump_should_not_redirect_to_inactive_tab
472 472 get :show, :id => 3, :jump => 'documents'
473 473 assert_response :success
474 474 assert_template 'show'
475 475 end
476 476
477 477 def test_jump_should_not_redirect_to_unknown_tab
478 478 get :show, :id => 3, :jump => 'foobar'
479 479 assert_response :success
480 480 assert_template 'show'
481 481 end
482 482
483 483 # A hook that is manually registered later
484 484 class ProjectBasedTemplate < Redmine::Hook::ViewListener
485 485 def view_layouts_base_html_head(context)
486 486 # Adds a project stylesheet
487 487 stylesheet_link_tag(context[:project].identifier) if context[:project]
488 488 end
489 489 end
490 490 # Don't use this hook now
491 491 Redmine::Hook.clear_listeners
492 492
493 493 def test_hook_response
494 494 Redmine::Hook.add_listener(ProjectBasedTemplate)
495 495 get :show, :id => 1
496 496 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'},
497 497 :parent => {:tag => 'head'}
498 498
499 499 Redmine::Hook.clear_listeners
500 500 end
501 501 end
General Comments 0
You need to be logged in to leave comments. Login now