Mercurial > hg > soundsoftware-site
comparison test/functional/projects_controller_test.rb @ 0:513646585e45
* Import Redmine trunk SVN rev 3859
author | Chris Cannam |
---|---|
date | Fri, 23 Jul 2010 15:52:44 +0100 |
parents | |
children | 40f7cfd4df19 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:513646585e45 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
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 | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.dirname(__FILE__) + '/../test_helper' | |
19 require 'projects_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class ProjectsController; def rescue_action(e) raise e end; end | |
23 | |
24 class ProjectsControllerTest < ActionController::TestCase | |
25 fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, | |
26 :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, | |
27 :attachments, :custom_fields, :custom_values, :time_entries | |
28 | |
29 def setup | |
30 @controller = ProjectsController.new | |
31 @request = ActionController::TestRequest.new | |
32 @response = ActionController::TestResponse.new | |
33 @request.session[:user_id] = nil | |
34 Setting.default_language = 'en' | |
35 end | |
36 | |
37 def test_index | |
38 get :index | |
39 assert_response :success | |
40 assert_template 'index' | |
41 assert_not_nil assigns(:projects) | |
42 | |
43 assert_tag :ul, :child => {:tag => 'li', | |
44 :descendant => {:tag => 'a', :content => 'eCookbook'}, | |
45 :child => { :tag => 'ul', | |
46 :descendant => { :tag => 'a', | |
47 :content => 'Child of private child' | |
48 } | |
49 } | |
50 } | |
51 | |
52 assert_no_tag :a, :content => /Private child of eCookbook/ | |
53 end | |
54 | |
55 def test_index_atom | |
56 get :index, :format => 'atom' | |
57 assert_response :success | |
58 assert_template 'common/feed.atom.rxml' | |
59 assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_by(User.current)) | |
61 end | |
62 | |
63 context "#index" do | |
64 context "by non-admin user with view_time_entries permission" do | |
65 setup do | |
66 @request.session[:user_id] = 3 | |
67 end | |
68 should "show overall spent time link" do | |
69 get :index | |
70 assert_template 'index' | |
71 assert_tag :a, :attributes => {:href => '/time_entries'} | |
72 end | |
73 end | |
74 | |
75 context "by non-admin user without view_time_entries permission" do | |
76 setup do | |
77 Role.find(2).remove_permission! :view_time_entries | |
78 Role.non_member.remove_permission! :view_time_entries | |
79 Role.anonymous.remove_permission! :view_time_entries | |
80 @request.session[:user_id] = 3 | |
81 end | |
82 should "not show overall spent time link" do | |
83 get :index | |
84 assert_template 'index' | |
85 assert_no_tag :a, :attributes => {:href => '/time_entries'} | |
86 end | |
87 end | |
88 end | |
89 | |
90 context "#add" do | |
91 context "by admin user" do | |
92 setup do | |
93 @request.session[:user_id] = 1 | |
94 end | |
95 | |
96 should "accept get" do | |
97 get :add | |
98 assert_response :success | |
99 assert_template 'add' | |
100 end | |
101 | |
102 should "accept post" do | |
103 post :add, :project => { :name => "blog", | |
104 :description => "weblog", | |
105 :identifier => "blog", | |
106 :is_public => 1, | |
107 :custom_field_values => { '3' => 'Beta' } | |
108 } | |
109 assert_redirected_to '/projects/blog/settings' | |
110 | |
111 project = Project.find_by_name('blog') | |
112 assert_kind_of Project, project | |
113 assert_equal 'weblog', project.description | |
114 assert_equal true, project.is_public? | |
115 assert_nil project.parent | |
116 end | |
117 | |
118 should "accept post with parent" do | |
119 post :add, :project => { :name => "blog", | |
120 :description => "weblog", | |
121 :identifier => "blog", | |
122 :is_public => 1, | |
123 :custom_field_values => { '3' => 'Beta' }, | |
124 :parent_id => 1 | |
125 } | |
126 assert_redirected_to '/projects/blog/settings' | |
127 | |
128 project = Project.find_by_name('blog') | |
129 assert_kind_of Project, project | |
130 assert_equal Project.find(1), project.parent | |
131 end | |
132 end | |
133 | |
134 context "by non-admin user with add_project permission" do | |
135 setup do | |
136 Role.non_member.add_permission! :add_project | |
137 @request.session[:user_id] = 9 | |
138 end | |
139 | |
140 should "accept get" do | |
141 get :add | |
142 assert_response :success | |
143 assert_template 'add' | |
144 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} | |
145 end | |
146 | |
147 should "accept post" do | |
148 post :add, :project => { :name => "blog", | |
149 :description => "weblog", | |
150 :identifier => "blog", | |
151 :is_public => 1, | |
152 :custom_field_values => { '3' => 'Beta' } | |
153 } | |
154 | |
155 assert_redirected_to '/projects/blog/settings' | |
156 | |
157 project = Project.find_by_name('blog') | |
158 assert_kind_of Project, project | |
159 assert_equal 'weblog', project.description | |
160 assert_equal true, project.is_public? | |
161 | |
162 # User should be added as a project member | |
163 assert User.find(9).member_of?(project) | |
164 assert_equal 1, project.members.size | |
165 end | |
166 | |
167 should "fail with parent_id" do | |
168 assert_no_difference 'Project.count' do | |
169 post :add, :project => { :name => "blog", | |
170 :description => "weblog", | |
171 :identifier => "blog", | |
172 :is_public => 1, | |
173 :custom_field_values => { '3' => 'Beta' }, | |
174 :parent_id => 1 | |
175 } | |
176 end | |
177 assert_response :success | |
178 project = assigns(:project) | |
179 assert_kind_of Project, project | |
180 assert_not_nil project.errors.on(:parent_id) | |
181 end | |
182 end | |
183 | |
184 context "by non-admin user with add_subprojects permission" do | |
185 setup do | |
186 Role.find(1).remove_permission! :add_project | |
187 Role.find(1).add_permission! :add_subprojects | |
188 @request.session[:user_id] = 2 | |
189 end | |
190 | |
191 should "accept get" do | |
192 get :add, :parent_id => 'ecookbook' | |
193 assert_response :success | |
194 assert_template 'add' | |
195 # parent project selected | |
196 assert_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
197 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
198 # no empty value | |
199 assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, | |
200 :child => {:tag => 'option', :attributes => {:value => ''}} | |
201 end | |
202 | |
203 should "accept post with parent_id" do | |
204 post :add, :project => { :name => "blog", | |
205 :description => "weblog", | |
206 :identifier => "blog", | |
207 :is_public => 1, | |
208 :custom_field_values => { '3' => 'Beta' }, | |
209 :parent_id => 1 | |
210 } | |
211 assert_redirected_to '/projects/blog/settings' | |
212 project = Project.find_by_name('blog') | |
213 end | |
214 | |
215 should "fail without parent_id" do | |
216 assert_no_difference 'Project.count' do | |
217 post :add, :project => { :name => "blog", | |
218 :description => "weblog", | |
219 :identifier => "blog", | |
220 :is_public => 1, | |
221 :custom_field_values => { '3' => 'Beta' } | |
222 } | |
223 end | |
224 assert_response :success | |
225 project = assigns(:project) | |
226 assert_kind_of Project, project | |
227 assert_not_nil project.errors.on(:parent_id) | |
228 end | |
229 | |
230 should "fail with unauthorized parent_id" do | |
231 assert !User.find(2).member_of?(Project.find(6)) | |
232 assert_no_difference 'Project.count' do | |
233 post :add, :project => { :name => "blog", | |
234 :description => "weblog", | |
235 :identifier => "blog", | |
236 :is_public => 1, | |
237 :custom_field_values => { '3' => 'Beta' }, | |
238 :parent_id => 6 | |
239 } | |
240 end | |
241 assert_response :success | |
242 project = assigns(:project) | |
243 assert_kind_of Project, project | |
244 assert_not_nil project.errors.on(:parent_id) | |
245 end | |
246 end | |
247 end | |
248 | |
249 def test_show_by_id | |
250 get :show, :id => 1 | |
251 assert_response :success | |
252 assert_template 'show' | |
253 assert_not_nil assigns(:project) | |
254 end | |
255 | |
256 def test_show_by_identifier | |
257 get :show, :id => 'ecookbook' | |
258 assert_response :success | |
259 assert_template 'show' | |
260 assert_not_nil assigns(:project) | |
261 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
262 end | |
263 | |
264 def test_show_should_not_fail_when_custom_values_are_nil | |
265 project = Project.find_by_identifier('ecookbook') | |
266 project.custom_values.first.update_attribute(:value, nil) | |
267 get :show, :id => 'ecookbook' | |
268 assert_response :success | |
269 assert_template 'show' | |
270 assert_not_nil assigns(:project) | |
271 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
272 end | |
273 | |
274 def test_private_subprojects_hidden | |
275 get :show, :id => 'ecookbook' | |
276 assert_response :success | |
277 assert_template 'show' | |
278 assert_no_tag :tag => 'a', :content => /Private child/ | |
279 end | |
280 | |
281 def test_private_subprojects_visible | |
282 @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
283 get :show, :id => 'ecookbook' | |
284 assert_response :success | |
285 assert_template 'show' | |
286 assert_tag :tag => 'a', :content => /Private child/ | |
287 end | |
288 | |
289 def test_settings | |
290 @request.session[:user_id] = 2 # manager | |
291 get :settings, :id => 1 | |
292 assert_response :success | |
293 assert_template 'settings' | |
294 end | |
295 | |
296 def test_edit | |
297 @request.session[:user_id] = 2 # manager | |
298 post :edit, :id => 1, :project => {:name => 'Test changed name', | |
299 :issue_custom_field_ids => ['']} | |
300 assert_redirected_to 'projects/ecookbook/settings' | |
301 project = Project.find(1) | |
302 assert_equal 'Test changed name', project.name | |
303 end | |
304 | |
305 def test_get_destroy | |
306 @request.session[:user_id] = 1 # admin | |
307 get :destroy, :id => 1 | |
308 assert_response :success | |
309 assert_template 'destroy' | |
310 assert_not_nil Project.find_by_id(1) | |
311 end | |
312 | |
313 def test_post_destroy | |
314 @request.session[:user_id] = 1 # admin | |
315 post :destroy, :id => 1, :confirm => 1 | |
316 assert_redirected_to 'admin/projects' | |
317 assert_nil Project.find_by_id(1) | |
318 end | |
319 | |
320 def test_add_file | |
321 set_tmp_attachments_directory | |
322 @request.session[:user_id] = 2 | |
323 Setting.notified_events = ['file_added'] | |
324 ActionMailer::Base.deliveries.clear | |
325 | |
326 assert_difference 'Attachment.count' do | |
327 post :add_file, :id => 1, :version_id => '', | |
328 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
329 end | |
330 assert_redirected_to 'projects/ecookbook/files' | |
331 a = Attachment.find(:first, :order => 'created_on DESC') | |
332 assert_equal 'testfile.txt', a.filename | |
333 assert_equal Project.find(1), a.container | |
334 | |
335 mail = ActionMailer::Base.deliveries.last | |
336 assert_kind_of TMail::Mail, mail | |
337 assert_equal "[eCookbook] New file", mail.subject | |
338 assert mail.body.include?('testfile.txt') | |
339 end | |
340 | |
341 def test_add_version_file | |
342 set_tmp_attachments_directory | |
343 @request.session[:user_id] = 2 | |
344 Setting.notified_events = ['file_added'] | |
345 | |
346 assert_difference 'Attachment.count' do | |
347 post :add_file, :id => 1, :version_id => '2', | |
348 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | |
349 end | |
350 assert_redirected_to 'projects/ecookbook/files' | |
351 a = Attachment.find(:first, :order => 'created_on DESC') | |
352 assert_equal 'testfile.txt', a.filename | |
353 assert_equal Version.find(2), a.container | |
354 end | |
355 | |
356 def test_list_files | |
357 get :list_files, :id => 1 | |
358 assert_response :success | |
359 assert_template 'list_files' | |
360 assert_not_nil assigns(:containers) | |
361 | |
362 # file attached to the project | |
363 assert_tag :a, :content => 'project_file.zip', | |
364 :attributes => { :href => '/attachments/download/8/project_file.zip' } | |
365 | |
366 # file attached to a project's version | |
367 assert_tag :a, :content => 'version_file.zip', | |
368 :attributes => { :href => '/attachments/download/9/version_file.zip' } | |
369 end | |
370 | |
371 def test_roadmap | |
372 get :roadmap, :id => 1 | |
373 assert_response :success | |
374 assert_template 'roadmap' | |
375 assert_not_nil assigns(:versions) | |
376 # Version with no date set appears | |
377 assert assigns(:versions).include?(Version.find(3)) | |
378 # Completed version doesn't appear | |
379 assert !assigns(:versions).include?(Version.find(1)) | |
380 end | |
381 | |
382 def test_roadmap_with_completed_versions | |
383 get :roadmap, :id => 1, :completed => 1 | |
384 assert_response :success | |
385 assert_template 'roadmap' | |
386 assert_not_nil assigns(:versions) | |
387 # Version with no date set appears | |
388 assert assigns(:versions).include?(Version.find(3)) | |
389 # Completed version appears | |
390 assert assigns(:versions).include?(Version.find(1)) | |
391 end | |
392 | |
393 def test_roadmap_showing_subprojects_versions | |
394 @subproject_version = Version.generate!(:project => Project.find(3)) | |
395 get :roadmap, :id => 1, :with_subprojects => 1 | |
396 assert_response :success | |
397 assert_template 'roadmap' | |
398 assert_not_nil assigns(:versions) | |
399 | |
400 assert assigns(:versions).include?(Version.find(4)), "Shared version not found" | |
401 assert assigns(:versions).include?(@subproject_version), "Subproject version not found" | |
402 end | |
403 def test_project_activity | |
404 get :activity, :id => 1, :with_subprojects => 0 | |
405 assert_response :success | |
406 assert_template 'activity' | |
407 assert_not_nil assigns(:events_by_day) | |
408 | |
409 assert_tag :tag => "h3", | |
410 :content => /#{2.days.ago.to_date.day}/, | |
411 :sibling => { :tag => "dl", | |
412 :child => { :tag => "dt", | |
413 :attributes => { :class => /issue-edit/ }, | |
414 :child => { :tag => "a", | |
415 :content => /(#{IssueStatus.find(2).name})/, | |
416 } | |
417 } | |
418 } | |
419 end | |
420 | |
421 def test_previous_project_activity | |
422 get :activity, :id => 1, :from => 3.days.ago.to_date | |
423 assert_response :success | |
424 assert_template 'activity' | |
425 assert_not_nil assigns(:events_by_day) | |
426 | |
427 assert_tag :tag => "h3", | |
428 :content => /#{3.day.ago.to_date.day}/, | |
429 :sibling => { :tag => "dl", | |
430 :child => { :tag => "dt", | |
431 :attributes => { :class => /issue/ }, | |
432 :child => { :tag => "a", | |
433 :content => /#{Issue.find(1).subject}/, | |
434 } | |
435 } | |
436 } | |
437 end | |
438 | |
439 def test_global_activity | |
440 get :activity | |
441 assert_response :success | |
442 assert_template 'activity' | |
443 assert_not_nil assigns(:events_by_day) | |
444 | |
445 assert_tag :tag => "h3", | |
446 :content => /#{5.day.ago.to_date.day}/, | |
447 :sibling => { :tag => "dl", | |
448 :child => { :tag => "dt", | |
449 :attributes => { :class => /issue/ }, | |
450 :child => { :tag => "a", | |
451 :content => /#{Issue.find(5).subject}/, | |
452 } | |
453 } | |
454 } | |
455 end | |
456 | |
457 def test_user_activity | |
458 get :activity, :user_id => 2 | |
459 assert_response :success | |
460 assert_template 'activity' | |
461 assert_not_nil assigns(:events_by_day) | |
462 | |
463 assert_tag :tag => "h3", | |
464 :content => /#{3.day.ago.to_date.day}/, | |
465 :sibling => { :tag => "dl", | |
466 :child => { :tag => "dt", | |
467 :attributes => { :class => /issue/ }, | |
468 :child => { :tag => "a", | |
469 :content => /#{Issue.find(1).subject}/, | |
470 } | |
471 } | |
472 } | |
473 end | |
474 | |
475 def test_activity_atom_feed | |
476 get :activity, :format => 'atom' | |
477 assert_response :success | |
478 assert_template 'common/feed.atom.rxml' | |
479 assert_tag :tag => 'entry', :child => { | |
480 :tag => 'link', | |
481 :attributes => {:href => 'http://test.host/issues/11'}} | |
482 end | |
483 | |
484 def test_archive | |
485 @request.session[:user_id] = 1 # admin | |
486 post :archive, :id => 1 | |
487 assert_redirected_to 'admin/projects' | |
488 assert !Project.find(1).active? | |
489 end | |
490 | |
491 def test_unarchive | |
492 @request.session[:user_id] = 1 # admin | |
493 Project.find(1).archive | |
494 post :unarchive, :id => 1 | |
495 assert_redirected_to 'admin/projects' | |
496 assert Project.find(1).active? | |
497 end | |
498 | |
499 def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
500 CustomField.delete_all | |
501 parent = nil | |
502 6.times do |i| | |
503 p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") | |
504 p.set_parent!(parent) | |
505 get :show, :id => p | |
506 assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, | |
507 :children => { :count => [i, 3].min, | |
508 :only => { :tag => 'a' } } | |
509 | |
510 parent = p | |
511 end | |
512 end | |
513 | |
514 def test_copy_with_project | |
515 @request.session[:user_id] = 1 # admin | |
516 get :copy, :id => 1 | |
517 assert_response :success | |
518 assert_template 'copy' | |
519 assert assigns(:project) | |
520 assert_equal Project.find(1).description, assigns(:project).description | |
521 assert_nil assigns(:project).id | |
522 end | |
523 | |
524 def test_copy_without_project | |
525 @request.session[:user_id] = 1 # admin | |
526 get :copy | |
527 assert_response :redirect | |
528 assert_redirected_to :controller => 'admin', :action => 'projects' | |
529 end | |
530 | |
531 def test_jump_should_redirect_to_active_tab | |
532 get :show, :id => 1, :jump => 'issues' | |
533 assert_redirected_to 'projects/ecookbook/issues' | |
534 end | |
535 | |
536 def test_jump_should_not_redirect_to_inactive_tab | |
537 get :show, :id => 3, :jump => 'documents' | |
538 assert_response :success | |
539 assert_template 'show' | |
540 end | |
541 | |
542 def test_jump_should_not_redirect_to_unknown_tab | |
543 get :show, :id => 3, :jump => 'foobar' | |
544 assert_response :success | |
545 assert_template 'show' | |
546 end | |
547 | |
548 def test_reset_activities | |
549 @request.session[:user_id] = 2 # manager | |
550 project_activity = TimeEntryActivity.new({ | |
551 :name => 'Project Specific', | |
552 :parent => TimeEntryActivity.find(:first), | |
553 :project => Project.find(1), | |
554 :active => true | |
555 }) | |
556 assert project_activity.save | |
557 project_activity_two = TimeEntryActivity.new({ | |
558 :name => 'Project Specific Two', | |
559 :parent => TimeEntryActivity.find(:last), | |
560 :project => Project.find(1), | |
561 :active => true | |
562 }) | |
563 assert project_activity_two.save | |
564 | |
565 delete :reset_activities, :id => 1 | |
566 assert_response :redirect | |
567 assert_redirected_to 'projects/ecookbook/settings/activities' | |
568 | |
569 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
570 assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | |
571 end | |
572 | |
573 def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity | |
574 @request.session[:user_id] = 2 # manager | |
575 project_activity = TimeEntryActivity.new({ | |
576 :name => 'Project Specific Design', | |
577 :parent => TimeEntryActivity.find(9), | |
578 :project => Project.find(1), | |
579 :active => true | |
580 }) | |
581 assert project_activity.save | |
582 assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | |
583 assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | |
584 | |
585 delete :reset_activities, :id => 1 | |
586 assert_response :redirect | |
587 assert_redirected_to 'projects/ecookbook/settings/activities' | |
588 | |
589 assert_nil TimeEntryActivity.find_by_id(project_activity.id) | |
590 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | |
591 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | |
592 end | |
593 | |
594 def test_save_activities_to_override_system_activities | |
595 @request.session[:user_id] = 2 # manager | |
596 billable_field = TimeEntryActivityCustomField.find_by_name("Billable") | |
597 | |
598 post :save_activities, :id => 1, :enumerations => { | |
599 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate | |
600 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value | |
601 "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value | |
602 "11"=>{"parent_id"=>"11", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"} # QA, no changes | |
603 } | |
604 | |
605 assert_response :redirect | |
606 assert_redirected_to 'projects/ecookbook/settings/activities' | |
607 | |
608 # Created project specific activities... | |
609 project = Project.find('ecookbook') | |
610 | |
611 # ... Design | |
612 design = project.time_entry_activities.find_by_name("Design") | |
613 assert design, "Project activity not found" | |
614 | |
615 assert_equal 9, design.parent_id # Relate to the system activity | |
616 assert_not_equal design.parent.id, design.id # Different records | |
617 assert_equal design.parent.name, design.name # Same name | |
618 assert !design.active? | |
619 | |
620 # ... Development | |
621 development = project.time_entry_activities.find_by_name("Development") | |
622 assert development, "Project activity not found" | |
623 | |
624 assert_equal 10, development.parent_id # Relate to the system activity | |
625 assert_not_equal development.parent.id, development.id # Different records | |
626 assert_equal development.parent.name, development.name # Same name | |
627 assert development.active? | |
628 assert_equal "0", development.custom_value_for(billable_field).value | |
629 | |
630 # ... Inactive Activity | |
631 previously_inactive = project.time_entry_activities.find_by_name("Inactive Activity") | |
632 assert previously_inactive, "Project activity not found" | |
633 | |
634 assert_equal 14, previously_inactive.parent_id # Relate to the system activity | |
635 assert_not_equal previously_inactive.parent.id, previously_inactive.id # Different records | |
636 assert_equal previously_inactive.parent.name, previously_inactive.name # Same name | |
637 assert previously_inactive.active? | |
638 assert_equal "1", previously_inactive.custom_value_for(billable_field).value | |
639 | |
640 # ... QA | |
641 assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" | |
642 end | |
643 | |
644 def test_save_activities_will_update_project_specific_activities | |
645 @request.session[:user_id] = 2 # manager | |
646 | |
647 project_activity = TimeEntryActivity.new({ | |
648 :name => 'Project Specific', | |
649 :parent => TimeEntryActivity.find(:first), | |
650 :project => Project.find(1), | |
651 :active => true | |
652 }) | |
653 assert project_activity.save | |
654 project_activity_two = TimeEntryActivity.new({ | |
655 :name => 'Project Specific Two', | |
656 :parent => TimeEntryActivity.find(:last), | |
657 :project => Project.find(1), | |
658 :active => true | |
659 }) | |
660 assert project_activity_two.save | |
661 | |
662 | |
663 post :save_activities, :id => 1, :enumerations => { | |
664 project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate | |
665 project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate | |
666 } | |
667 | |
668 assert_response :redirect | |
669 assert_redirected_to 'projects/ecookbook/settings/activities' | |
670 | |
671 # Created project specific activities... | |
672 project = Project.find('ecookbook') | |
673 assert_equal 2, project.time_entry_activities.count | |
674 | |
675 activity_one = project.time_entry_activities.find_by_name(project_activity.name) | |
676 assert activity_one, "Project activity not found" | |
677 assert_equal project_activity.id, activity_one.id | |
678 assert !activity_one.active? | |
679 | |
680 activity_two = project.time_entry_activities.find_by_name(project_activity_two.name) | |
681 assert activity_two, "Project activity not found" | |
682 assert_equal project_activity_two.id, activity_two.id | |
683 assert !activity_two.active? | |
684 end | |
685 | |
686 def test_save_activities_when_creating_new_activities_will_convert_existing_data | |
687 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | |
688 | |
689 @request.session[:user_id] = 2 # manager | |
690 post :save_activities, :id => 1, :enumerations => { | |
691 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate | |
692 } | |
693 assert_response :redirect | |
694 | |
695 # No more TimeEntries using the system activity | |
696 assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries still assigned to system activities" | |
697 # All TimeEntries using project activity | |
698 project_specific_activity = TimeEntryActivity.find_by_parent_id_and_project_id(9, 1) | |
699 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity" | |
700 end | |
701 | |
702 def test_save_activities_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | |
703 # TODO: Need to cause an exception on create but these tests | |
704 # aren't setup for mocking. Just create a record now so the | |
705 # second one is a dupicate | |
706 parent = TimeEntryActivity.find(9) | |
707 TimeEntryActivity.create!({:name => parent.name, :project_id => 1, :position => parent.position, :active => true}) | |
708 TimeEntry.create!({:project_id => 1, :hours => 1.0, :user => User.find(1), :issue_id => 3, :activity_id => 10, :spent_on => '2009-01-01'}) | |
709 | |
710 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size | |
711 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size | |
712 | |
713 @request.session[:user_id] = 2 # manager | |
714 post :save_activities, :id => 1, :enumerations => { | |
715 "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design | |
716 "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value | |
717 } | |
718 assert_response :redirect | |
719 | |
720 # TimeEntries shouldn't have been reassigned on the failed record | |
721 assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "Time Entries are not assigned to system activities" | |
722 # TimeEntries shouldn't have been reassigned on the saved record either | |
723 assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" | |
724 end | |
725 | |
726 # A hook that is manually registered later | |
727 class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
728 def view_layouts_base_html_head(context) | |
729 # Adds a project stylesheet | |
730 stylesheet_link_tag(context[:project].identifier) if context[:project] | |
731 end | |
732 end | |
733 # Don't use this hook now | |
734 Redmine::Hook.clear_listeners | |
735 | |
736 def test_hook_response | |
737 Redmine::Hook.add_listener(ProjectBasedTemplate) | |
738 get :show, :id => 1 | |
739 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
740 :parent => {:tag => 'head'} | |
741 | |
742 Redmine::Hook.clear_listeners | |
743 end | |
744 end |