comparison test/functional/issues_controller_test.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents dffacf8a6908
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2014 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.
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'
20 19
21 class IssuesControllerTest < ActionController::TestCase 20 class IssuesControllerTest < ActionController::TestCase
22 fixtures :projects, 21 fixtures :projects,
23 :users, 22 :users,
24 :roles, 23 :roles,
46 :changesets 45 :changesets
47 46
48 include Redmine::I18n 47 include Redmine::I18n
49 48
50 def setup 49 def setup
51 @controller = IssuesController.new
52 @request = ActionController::TestRequest.new
53 @response = ActionController::TestResponse.new
54 User.current = nil 50 User.current = nil
55 end 51 end
56 52
57 def test_index 53 def test_index
58 with_settings :default_language => "en" do 54 with_settings :default_language => "en" do
61 assert_template 'index' 57 assert_template 'index'
62 assert_not_nil assigns(:issues) 58 assert_not_nil assigns(:issues)
63 assert_nil assigns(:project) 59 assert_nil assigns(:project)
64 60
65 # links to visible issues 61 # links to visible issues
66 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/ 62 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
67 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
68 # private projects hidden 64 # private projects hidden
69 assert_select 'a[href=/issues/6]', 0 65 assert_select 'a[href=/issues/6]', 0
70 assert_select 'a[href=/issues/4]', 0 66 assert_select 'a[href=/issues/4]', 0
71 # project column 67 # project column
97 get :index, :project_id => 1 93 get :index, :project_id => 1
98 assert_response :success 94 assert_response :success
99 assert_template 'index' 95 assert_template 'index'
100 assert_not_nil assigns(:issues) 96 assert_not_nil assigns(:issues)
101 97
102 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/ 98 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
103 assert_select 'a[href=/issues/5]', 0 99 assert_select 'a[href=/issues/5]', 0
104 end 100 end
105 101
106 def test_index_with_project_and_subprojects 102 def test_index_with_project_and_subprojects
107 Setting.display_subprojects_issues = 1 103 Setting.display_subprojects_issues = 1
108 get :index, :project_id => 1 104 get :index, :project_id => 1
109 assert_response :success 105 assert_response :success
110 assert_template 'index' 106 assert_template 'index'
111 assert_not_nil assigns(:issues) 107 assert_not_nil assigns(:issues)
112 108
113 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/ 109 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
114 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
115 assert_select 'a[href=/issues/6]', 0 111 assert_select 'a[href=/issues/6]', 0
116 end 112 end
117 113
118 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission 114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
121 get :index, :project_id => 1 117 get :index, :project_id => 1
122 assert_response :success 118 assert_response :success
123 assert_template 'index' 119 assert_template 'index'
124 assert_not_nil assigns(:issues) 120 assert_not_nil assigns(:issues)
125 121
126 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/ 122 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
127 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
128 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/ 124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
129 end 125 end
130 126
131 def test_index_with_project_and_default_filter 127 def test_index_with_project_and_default_filter
295 assert_select 'a', :text => 'Dave Lopper' 291 assert_select 'a', :text => 'Dave Lopper'
296 assert_select 'span.count', :text => '2' 292 assert_select 'span.count', :text => '2'
297 end 293 end
298 end 294 end
299 295
300 def test_index_with_query_grouped_by_tracker 296 def test_index_with_query_grouped_by_tracker_in_normal_order
301 3.times {|i| Issue.generate!(:tracker_id => (i + 1))} 297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
302 298
303 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc' 299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
304 assert_response :success 300 assert_response :success
305 301
329 get :index, :project_id => 1, :query_id => 999 325 get :index, :project_id => 1, :query_id => 999
330 assert_response 404 326 assert_response 404
331 end 327 end
332 328
333 def test_index_with_cross_project_query_in_session_should_show_project_issues 329 def test_index_with_cross_project_query_in_session_should_show_project_issues
334 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil) 330 q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
335 @request.session[:query] = {:id => q.id, :project_id => 1} 331 @request.session[:query] = {:id => q.id, :project_id => 1}
336 332
337 with_settings :display_subprojects_issues => '0' do 333 with_settings :display_subprojects_issues => '0' do
338 get :index, :project_id => 1 334 get :index, :project_id => 1
339 end 335 end
343 assert_equal 1, assigns(:query).project_id 339 assert_equal 1, assigns(:query).project_id
344 assert_equal [1], assigns(:issues).map(&:project_id).uniq 340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
345 end 341 end
346 342
347 def test_private_query_should_not_be_available_to_other_users 343 def test_private_query_should_not_be_available_to_other_users
348 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) 344 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
349 @request.session[:user_id] = 3 345 @request.session[:user_id] = 3
350 346
351 get :index, :query_id => q.id 347 get :index, :query_id => q.id
352 assert_response 403 348 assert_response 403
353 end 349 end
354 350
355 def test_private_query_should_be_available_to_its_user 351 def test_private_query_should_be_available_to_its_user
356 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) 352 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
357 @request.session[:user_id] = 2 353 @request.session[:user_id] = 2
358 354
359 get :index, :query_id => q.id 355 get :index, :query_id => q.id
360 assert_response :success 356 assert_response :success
361 end 357 end
362 358
363 def test_public_query_should_be_available_to_other_users 359 def test_public_query_should_be_available_to_other_users
364 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) 360 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
365 @request.session[:user_id] = 3 361 @request.session[:user_id] = 3
366 362
367 get :index, :query_id => q.id 363 get :index, :query_id => q.id
368 assert_response :success 364 assert_response :success
369 end 365 end
375 assert_select 'a.csv[href=/issues.csv]' 371 assert_select 'a.csv[href=/issues.csv]'
376 assert_select 'a.pdf[href=/issues.pdf]' 372 assert_select 'a.pdf[href=/issues.pdf]'
377 assert_select 'form#csv-export-form[action=/issues.csv]' 373 assert_select 'form#csv-export-form[action=/issues.csv]'
378 end 374 end
379 375
376 def test_index_should_not_warn_when_not_exceeding_export_limit
377 with_settings :issues_export_limit => 200 do
378 get :index
379 assert_select '#csv-export-options p.icon-warning', 0
380 end
381 end
382
383 def test_index_should_warn_when_exceeding_export_limit
384 with_settings :issues_export_limit => 2 do
385 get :index
386 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
387 end
388 end
389
380 def test_index_csv 390 def test_index_csv
381 get :index, :format => 'csv' 391 get :index, :format => 'csv'
382 assert_response :success 392 assert_response :success
383 assert_not_nil assigns(:issues) 393 assert_not_nil assigns(:issues)
384 assert_equal 'text/csv; header=present', @response.content_type 394 assert_equal 'text/csv; header=present', @response.content_type
385 assert @response.body.starts_with?("#,") 395 assert @response.body.starts_with?("#,")
386 lines = @response.body.chomp.split("\n") 396 lines = @response.body.chomp.split("\n")
387 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size 397 assert_equal assigns(:query).columns.size, lines[0].split(',').size
388 end 398 end
389 399
390 def test_index_csv_with_project 400 def test_index_csv_with_project
391 get :index, :project_id => 1, :format => 'csv' 401 get :index, :project_id => 1, :format => 'csv'
392 assert_response :success 402 assert_response :success
393 assert_not_nil assigns(:issues) 403 assert_not_nil assigns(:issues)
394 assert_equal 'text/csv; header=present', @response.content_type 404 assert_equal 'text/csv; header=present', @response.content_type
395 end 405 end
396 406
397 def test_index_csv_with_description 407 def test_index_csv_with_description
398 get :index, :format => 'csv', :description => '1' 408 Issue.generate!(:description => 'test_index_csv_with_description')
399 assert_response :success 409
400 assert_not_nil assigns(:issues) 410 with_settings :default_language => 'en' do
401 assert_equal 'text/csv; header=present', @response.content_type 411 get :index, :format => 'csv', :description => '1'
402 assert @response.body.starts_with?("#,") 412 assert_response :success
403 lines = @response.body.chomp.split("\n") 413 assert_not_nil assigns(:issues)
404 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size 414 end
415
416 assert_equal 'text/csv; header=present', response.content_type
417 headers = response.body.chomp.split("\n").first.split(',')
418 assert_include 'Description', headers
419 assert_include 'test_index_csv_with_description', response.body
405 end 420 end
406 421
407 def test_index_csv_with_spent_time_column 422 def test_index_csv_with_spent_time_column
408 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) 423 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
409 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) 424 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
418 def test_index_csv_with_all_columns 433 def test_index_csv_with_all_columns
419 get :index, :format => 'csv', :columns => 'all' 434 get :index, :format => 'csv', :columns => 'all'
420 assert_response :success 435 assert_response :success
421 assert_not_nil assigns(:issues) 436 assert_not_nil assigns(:issues)
422 assert_equal 'text/csv; header=present', @response.content_type 437 assert_equal 'text/csv; header=present', @response.content_type
423 assert @response.body.starts_with?("#,") 438 assert_match /\A#,/, response.body
424 lines = @response.body.chomp.split("\n") 439 lines = response.body.chomp.split("\n")
425 assert_equal assigns(:query).available_inline_columns.size + 1, lines[0].split(',').size 440 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
426 end 441 end
427 442
428 def test_index_csv_with_multi_column_field 443 def test_index_csv_with_multi_column_field
429 CustomField.find(1).update_attribute :multiple, true 444 CustomField.find(1).update_attribute :multiple, true
430 issue = Issue.find(1) 445 issue = Issue.find(1)
433 448
434 get :index, :format => 'csv', :columns => 'all' 449 get :index, :format => 'csv', :columns => 'all'
435 assert_response :success 450 assert_response :success
436 lines = @response.body.chomp.split("\n") 451 lines = @response.body.chomp.split("\n")
437 assert lines.detect {|line| line.include?('"MySQL, Oracle"')} 452 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
453 end
454
455 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
456 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
457 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
458
459 with_settings :default_language => 'fr' do
460 get :index, :format => 'csv', :columns => 'all'
461 assert_response :success
462 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
463 assert_include '185,60', issue_line
464 end
465
466 with_settings :default_language => 'en' do
467 get :index, :format => 'csv', :columns => 'all'
468 assert_response :success
469 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
470 assert_include '185.60', issue_line
471 end
438 end 472 end
439 473
440 def test_index_csv_big_5 474 def test_index_csv_big_5
441 with_settings :default_language => "zh-TW" do 475 with_settings :default_language => "zh-TW" do
442 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" 476 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
455 lines = @response.body.chomp.split("\n") 489 lines = @response.body.chomp.split("\n")
456 s1 = "\xaa\xac\xbaA" 490 s1 = "\xaa\xac\xbaA"
457 if str_utf8.respond_to?(:force_encoding) 491 if str_utf8.respond_to?(:force_encoding)
458 s1.force_encoding('Big5') 492 s1.force_encoding('Big5')
459 end 493 end
460 assert lines[0].include?(s1) 494 assert_include s1, lines[0]
461 assert lines[1].include?(str_big5) 495 assert_include str_big5, lines[1]
462 end 496 end
463 end 497 end
464 498
465 def test_index_csv_cannot_convert_should_be_replaced_big_5 499 def test_index_csv_cannot_convert_should_be_replaced_big_5
466 with_settings :default_language => "zh-TW" do 500 with_settings :default_language => "zh-TW" do
668 get :index, :set_filter => 1, :c => columns 702 get :index, :set_filter => 1, :c => columns
669 assert_response :success 703 assert_response :success
670 704
671 # query should use specified columns 705 # query should use specified columns
672 query = assigns(:query) 706 query = assigns(:query)
673 assert_kind_of Query, query 707 assert_kind_of IssueQuery, query
674 assert_equal columns, query.column_names.map(&:to_s) 708 assert_equal columns, query.column_names.map(&:to_s)
675 709
676 # columns should be stored in session 710 # columns should be stored in session
677 assert_kind_of Hash, session[:query] 711 assert_kind_of Hash, session[:query]
678 assert_kind_of Array, session[:query][:column_names] 712 assert_kind_of Array, session[:query][:column_names]
690 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] 724 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
691 get :index, :set_filter => 1 725 get :index, :set_filter => 1
692 726
693 # query should use specified columns 727 # query should use specified columns
694 query = assigns(:query) 728 query = assigns(:query)
695 assert_kind_of Query, query 729 assert_kind_of IssueQuery, query
696 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) 730 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
697 end 731 end
698 732
699 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column 733 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
700 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] 734 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
701 columns = ['tracker', 'subject', 'assigned_to'] 735 columns = ['id', 'tracker', 'subject', 'assigned_to']
702 get :index, :set_filter => 1, :c => columns 736 get :index, :set_filter => 1, :c => columns
703 737
704 # query should use specified columns 738 # query should use specified columns
705 query = assigns(:query) 739 query = assigns(:query)
706 assert_kind_of Query, query 740 assert_kind_of IssueQuery, query
707 assert_equal columns.map(&:to_sym), query.columns.map(&:name) 741 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
708 end 742 end
709 743
710 def test_index_with_custom_field_column 744 def test_index_with_custom_field_column
711 columns = %w(tracker subject cf_2) 745 columns = %w(tracker subject cf_2)
712 get :index, :set_filter => 1, :c => columns 746 get :index, :set_filter => 1, :c => columns
713 assert_response :success 747 assert_response :success
714 748
715 # query should use specified columns 749 # query should use specified columns
716 query = assigns(:query) 750 query = assigns(:query)
717 assert_kind_of Query, query 751 assert_kind_of IssueQuery, query
718 assert_equal columns, query.column_names.map(&:to_s) 752 assert_equal columns, query.column_names.map(&:to_s)
719 753
720 assert_select 'table.issues td.cf_2.string' 754 assert_select 'table.issues td.cf_2.string'
721 end 755 end
722 756
751 end 785 end
752 786
753 def test_index_with_date_column 787 def test_index_with_date_column
754 with_settings :date_format => '%d/%m/%Y' do 788 with_settings :date_format => '%d/%m/%Y' do
755 Issue.find(1).update_attribute :start_date, '1987-08-24' 789 Issue.find(1).update_attribute :start_date, '1987-08-24'
756
757 get :index, :set_filter => 1, :c => %w(start_date) 790 get :index, :set_filter => 1, :c => %w(start_date)
758
759 assert_select "table.issues td.start_date", :text => '24/08/1987' 791 assert_select "table.issues td.start_date", :text => '24/08/1987'
760 end 792 end
761 end 793 end
762 794
763 def test_index_with_done_ratio_column 795 def test_index_with_done_ratio_column
764 Issue.find(1).update_attribute :done_ratio, 40 796 Issue.find(1).update_attribute :done_ratio, 40
765
766 get :index, :set_filter => 1, :c => %w(done_ratio) 797 get :index, :set_filter => 1, :c => %w(done_ratio)
767
768 assert_select 'table.issues td.done_ratio' do 798 assert_select 'table.issues td.done_ratio' do
769 assert_select 'table.progress' do 799 assert_select 'table.progress' do
770 assert_select 'td.closed[style=?]', 'width: 40%;' 800 assert_select 'td.closed[style=?]', 'width: 40%;'
771 end 801 end
772 end 802 end
773 end 803 end
774 804
775 def test_index_with_spent_hours_column 805 def test_index_with_spent_hours_column
776 get :index, :set_filter => 1, :c => %w(subject spent_hours) 806 get :index, :set_filter => 1, :c => %w(subject spent_hours)
777
778 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00' 807 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
779 end 808 end
780 809
781 def test_index_should_not_show_spent_hours_column_without_permission 810 def test_index_should_not_show_spent_hours_column_without_permission
782 Role.anonymous.remove_permission! :view_time_entries 811 Role.anonymous.remove_permission! :view_time_entries
783 get :index, :set_filter => 1, :c => %w(subject spent_hours) 812 get :index, :set_filter => 1, :c => %w(subject spent_hours)
784
785 assert_select 'td.spent_hours', 0 813 assert_select 'td.spent_hours', 0
786 end 814 end
787 815
788 def test_index_with_fixed_version_column 816 def test_index_with_fixed_version_column
789 get :index, :set_filter => 1, :c => %w(fixed_version) 817 get :index, :set_filter => 1, :c => %w(fixed_version)
790
791 assert_select 'table.issues td.fixed_version' do 818 assert_select 'table.issues td.fixed_version' do
792 assert_select 'a[href=?]', '/versions/2', :text => '1.0' 819 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
793 end 820 end
794 end 821 end
795 822
855 def test_show_by_anonymous 882 def test_show_by_anonymous
856 get :show, :id => 1 883 get :show, :id => 1
857 assert_response :success 884 assert_response :success
858 assert_template 'show' 885 assert_template 'show'
859 assert_equal Issue.find(1), assigns(:issue) 886 assert_equal Issue.find(1), assigns(:issue)
860
861 assert_select 'div.issue div.description', :text => /Unable to print recipes/ 887 assert_select 'div.issue div.description', :text => /Unable to print recipes/
862
863 # anonymous role is allowed to add a note 888 # anonymous role is allowed to add a note
864 assert_select 'form#issue-form' do 889 assert_select 'form#issue-form' do
865 assert_select 'fieldset' do 890 assert_select 'fieldset' do
866 assert_select 'legend', :text => 'Notes' 891 assert_select 'legend', :text => 'Notes'
867 assert_select 'textarea[name=?]', 'issue[notes]' 892 assert_select 'textarea[name=?]', 'issue[notes]'
868 end 893 end
869 end 894 end
870 895 assert_select 'title', :text => "Bug #1: #{ESCAPED_UCANT} print recipes - eCookbook - Redmine"
871 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
872 end 896 end
873 897
874 def test_show_by_manager 898 def test_show_by_manager
875 @request.session[:user_id] = 2 899 @request.session[:user_id] = 2
876 get :show, :id => 1 900 get :show, :id => 1
877 assert_response :success 901 assert_response :success
878
879 assert_select 'a', :text => /Quote/ 902 assert_select 'a', :text => /Quote/
880
881 assert_select 'form#issue-form' do 903 assert_select 'form#issue-form' do
882 assert_select 'fieldset' do 904 assert_select 'fieldset' do
883 assert_select 'legend', :text => 'Change properties' 905 assert_select 'legend', :text => 'Change properties'
884 assert_select 'input[name=?]', 'issue[subject]' 906 assert_select 'input[name=?]', 'issue[subject]'
885 end 907 end
897 def test_show_should_display_update_form 919 def test_show_should_display_update_form
898 @request.session[:user_id] = 2 920 @request.session[:user_id] = 2
899 get :show, :id => 1 921 get :show, :id => 1
900 assert_response :success 922 assert_response :success
901 923
902 assert_tag 'form', :attributes => {:id => 'issue-form'} 924 assert_select 'form#issue-form' do
903 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} 925 assert_select 'input[name=?]', 'issue[is_private]'
904 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 926 assert_select 'select[name=?]', 'issue[project_id]'
905 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 927 assert_select 'select[name=?]', 'issue[tracker_id]'
906 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 928 assert_select 'input[name=?]', 'issue[subject]'
907 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 929 assert_select 'textarea[name=?]', 'issue[description]'
908 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 930 assert_select 'select[name=?]', 'issue[status_id]'
909 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 931 assert_select 'select[name=?]', 'issue[priority_id]'
910 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 932 assert_select 'select[name=?]', 'issue[assigned_to_id]'
911 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 933 assert_select 'select[name=?]', 'issue[category_id]'
912 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 934 assert_select 'select[name=?]', 'issue[fixed_version_id]'
913 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 935 assert_select 'input[name=?]', 'issue[parent_issue_id]'
914 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 936 assert_select 'input[name=?]', 'issue[start_date]'
915 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 937 assert_select 'input[name=?]', 'issue[due_date]'
916 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 938 assert_select 'select[name=?]', 'issue[done_ratio]'
917 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 939 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
918 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 940 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
919 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 941 assert_select 'textarea[name=?]', 'issue[notes]'
942 end
920 end 943 end
921 944
922 def test_show_should_display_update_form_with_minimal_permissions 945 def test_show_should_display_update_form_with_minimal_permissions
923 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] 946 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
924 WorkflowTransition.delete_all :role_id => 1 947 WorkflowTransition.delete_all :role_id => 1
925 948
926 @request.session[:user_id] = 2 949 @request.session[:user_id] = 2
927 get :show, :id => 1 950 get :show, :id => 1
928 assert_response :success 951 assert_response :success
929 952
930 assert_tag 'form', :attributes => {:id => 'issue-form'} 953 assert_select 'form#issue-form' do
931 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 954 assert_select 'input[name=?]', 'issue[is_private]', 0
932 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 955 assert_select 'select[name=?]', 'issue[project_id]', 0
933 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 956 assert_select 'select[name=?]', 'issue[tracker_id]', 0
934 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} 957 assert_select 'input[name=?]', 'issue[subject]', 0
935 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} 958 assert_select 'textarea[name=?]', 'issue[description]', 0
936 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'} 959 assert_select 'select[name=?]', 'issue[status_id]', 0
937 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} 960 assert_select 'select[name=?]', 'issue[priority_id]', 0
938 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 961 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
939 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} 962 assert_select 'select[name=?]', 'issue[category_id]', 0
940 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 963 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
941 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 964 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
942 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} 965 assert_select 'input[name=?]', 'issue[start_date]', 0
943 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} 966 assert_select 'input[name=?]', 'issue[due_date]', 0
944 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 967 assert_select 'select[name=?]', 'issue[done_ratio]', 0
945 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 968 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
946 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 969 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
947 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 970 assert_select 'textarea[name=?]', 'issue[notes]'
971 end
948 end 972 end
949 973
950 def test_show_should_display_update_form_with_workflow_permissions 974 def test_show_should_display_update_form_with_workflow_permissions
951 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] 975 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
952 976
953 @request.session[:user_id] = 2 977 @request.session[:user_id] = 2
954 get :show, :id => 1 978 get :show, :id => 1
955 assert_response :success 979 assert_response :success
956 980
957 assert_tag 'form', :attributes => {:id => 'issue-form'} 981 assert_select 'form#issue-form' do
958 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 982 assert_select 'input[name=?]', 'issue[is_private]', 0
959 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 983 assert_select 'select[name=?]', 'issue[project_id]', 0
960 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 984 assert_select 'select[name=?]', 'issue[tracker_id]', 0
961 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} 985 assert_select 'input[name=?]', 'issue[subject]', 0
962 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} 986 assert_select 'textarea[name=?]', 'issue[description]', 0
963 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 987 assert_select 'select[name=?]', 'issue[status_id]'
964 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} 988 assert_select 'select[name=?]', 'issue[priority_id]', 0
965 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 989 assert_select 'select[name=?]', 'issue[assigned_to_id]'
966 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} 990 assert_select 'select[name=?]', 'issue[category_id]', 0
967 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 991 assert_select 'select[name=?]', 'issue[fixed_version_id]'
968 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 992 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
969 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} 993 assert_select 'input[name=?]', 'issue[start_date]', 0
970 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} 994 assert_select 'input[name=?]', 'issue[due_date]', 0
971 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 995 assert_select 'select[name=?]', 'issue[done_ratio]'
972 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 996 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
973 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 997 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
974 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 998 assert_select 'textarea[name=?]', 'issue[notes]'
999 end
975 end 1000 end
976 1001
977 def test_show_should_not_display_update_form_without_permissions 1002 def test_show_should_not_display_update_form_without_permissions
978 Role.find(1).update_attribute :permissions, [:view_issues] 1003 Role.find(1).update_attribute :permissions, [:view_issues]
979 1004
1002 def test_update_form_should_allow_attachment_upload 1027 def test_update_form_should_allow_attachment_upload
1003 @request.session[:user_id] = 2 1028 @request.session[:user_id] = 2
1004 get :show, :id => 1 1029 get :show, :id => 1
1005 1030
1006 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do 1031 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
1007 assert_select 'input[type=file][name=?]', 'attachments[1][file]' 1032 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1008 end 1033 end
1009 end 1034 end
1010 1035
1011 def test_show_should_deny_anonymous_access_without_permission 1036 def test_show_should_deny_anonymous_access_without_permission
1012 Role.anonymous.remove_permission!(:view_issues) 1037 Role.anonymous.remove_permission!(:view_issues)
1013 get :show, :id => 1 1038 get :show, :id => 1
1014 assert_response :redirect 1039 assert_response :redirect
1015 end 1040 end
1016 1041
1017 def test_show_should_deny_anonymous_access_to_private_issue 1042 def test_show_should_deny_anonymous_access_to_private_issue
1018 Issue.update_all(["is_private = ?", true], "id = 1") 1043 Issue.where(:id => 1).update_all(["is_private = ?", true])
1019 get :show, :id => 1 1044 get :show, :id => 1
1020 assert_response :redirect 1045 assert_response :redirect
1021 end 1046 end
1022 1047
1023 def test_show_should_deny_non_member_access_without_permission 1048 def test_show_should_deny_non_member_access_without_permission
1026 get :show, :id => 1 1051 get :show, :id => 1
1027 assert_response 403 1052 assert_response 403
1028 end 1053 end
1029 1054
1030 def test_show_should_deny_non_member_access_to_private_issue 1055 def test_show_should_deny_non_member_access_to_private_issue
1031 Issue.update_all(["is_private = ?", true], "id = 1") 1056 Issue.where(:id => 1).update_all(["is_private = ?", true])
1032 @request.session[:user_id] = 9 1057 @request.session[:user_id] = 9
1033 get :show, :id => 1 1058 get :show, :id => 1
1034 assert_response 403 1059 assert_response 403
1035 end 1060 end
1036 1061
1040 get :show, :id => 1 1065 get :show, :id => 1
1041 assert_response 403 1066 assert_response 403
1042 end 1067 end
1043 1068
1044 def test_show_should_deny_member_access_to_private_issue_without_permission 1069 def test_show_should_deny_member_access_to_private_issue_without_permission
1045 Issue.update_all(["is_private = ?", true], "id = 1") 1070 Issue.where(:id => 1).update_all(["is_private = ?", true])
1046 @request.session[:user_id] = 3 1071 @request.session[:user_id] = 3
1047 get :show, :id => 1 1072 get :show, :id => 1
1048 assert_response 403 1073 assert_response 403
1049 end 1074 end
1050 1075
1051 def test_show_should_allow_author_access_to_private_issue 1076 def test_show_should_allow_author_access_to_private_issue
1052 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") 1077 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
1053 @request.session[:user_id] = 3 1078 @request.session[:user_id] = 3
1054 get :show, :id => 1 1079 get :show, :id => 1
1055 assert_response :success 1080 assert_response :success
1056 end 1081 end
1057 1082
1058 def test_show_should_allow_assignee_access_to_private_issue 1083 def test_show_should_allow_assignee_access_to_private_issue
1059 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") 1084 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
1060 @request.session[:user_id] = 3 1085 @request.session[:user_id] = 3
1061 get :show, :id => 1 1086 get :show, :id => 1
1062 assert_response :success 1087 assert_response :success
1063 end 1088 end
1064 1089
1065 def test_show_should_allow_member_access_to_private_issue_with_permission 1090 def test_show_should_allow_member_access_to_private_issue_with_permission
1066 Issue.update_all(["is_private = ?", true], "id = 1") 1091 Issue.where(:id => 1).update_all(["is_private = ?", true])
1067 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' 1092 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1068 @request.session[:user_id] = 3 1093 @request.session[:user_id] = 3
1069 get :show, :id => 1 1094 get :show, :id => 1
1070 assert_response :success 1095 assert_response :success
1071 end 1096 end
1138 assert_select 'span.position', :text => "3 of #{count}" 1163 assert_select 'span.position', :text => "3 of #{count}"
1139 end 1164 end
1140 end 1165 end
1141 1166
1142 def test_show_should_display_prev_next_links_with_saved_query_in_session 1167 def test_show_should_display_prev_next_links_with_saved_query_in_session
1143 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, 1168 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
1144 :filters => {'status_id' => {:values => ['5'], :operator => '='}}, 1169 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1145 :sort_criteria => [['id', 'asc']]) 1170 :sort_criteria => [['id', 'asc']])
1146 @request.session[:query] = {:id => query.id, :project_id => nil} 1171 @request.session[:query] = {:id => query.id, :project_id => nil}
1147 1172
1148 get :show, :id => 11 1173 get :show, :id => 11
1230 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') 1255 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1231 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') 1256 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1232 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') 1257 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1233 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') 1258 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1234 1259
1235 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {}, 1260 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
1236 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) 1261 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1237 @request.session[:query] = {:id => query.id, :project_id => nil} 1262 @request.session[:query] = {:id => query.id, :project_id => nil}
1238 1263
1239 get :show, :id => 3 1264 get :show, :id => 3
1240 assert_response :success 1265 assert_response :success
1348 issue.save! 1373 issue.save!
1349 1374
1350 get :show, :id => 1 1375 get :show, :id => 1
1351 assert_response :success 1376 assert_response :success
1352 1377
1353 # TODO: should display links 1378 assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do
1354 assert_select 'td', :text => 'Dave Lopper, John Smith' 1379 assert_select 'a', :text => 'Dave Lopper'
1380 assert_select 'a', :text => 'John Smith'
1381 end
1355 end 1382 end
1356 1383
1357 def test_show_should_display_private_notes_with_permission_only 1384 def test_show_should_display_private_notes_with_permission_only
1358 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) 1385 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1359 @request.session[:user_id] = 2 1386 @request.session[:user_id] = 2
1410 assert_equal 'application/pdf', @response.content_type 1437 assert_equal 'application/pdf', @response.content_type
1411 assert @response.body.starts_with?('%PDF') 1438 assert @response.body.starts_with?('%PDF')
1412 end 1439 end
1413 1440
1414 def test_show_export_to_pdf_with_changesets 1441 def test_show_export_to_pdf_with_changesets
1415 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102) 1442 [[100], [100, 101], [100, 101, 102]].each do |cs|
1416 1443 issue1 = Issue.find(3)
1417 get :show, :id => 3, :format => 'pdf' 1444 issue1.changesets = Changeset.find(cs)
1418 assert_response :success 1445 issue1.save!
1419 assert_equal 'application/pdf', @response.content_type 1446 issue = Issue.find(3)
1420 assert @response.body.starts_with?('%PDF') 1447 assert_equal issue.changesets.count, cs.size
1448 get :show, :id => 3, :format => 'pdf'
1449 assert_response :success
1450 assert_equal 'application/pdf', @response.content_type
1451 assert @response.body.starts_with?('%PDF')
1452 end
1453 end
1454
1455 def test_show_invalid_should_respond_with_404
1456 get :show, :id => 999
1457 assert_response 404
1421 end 1458 end
1422 1459
1423 def test_get_new 1460 def test_get_new
1424 @request.session[:user_id] = 2 1461 @request.session[:user_id] = 2
1425 get :new, :project_id => 1, :tracker_id => 1 1462 get :new, :project_id => 1, :tracker_id => 1
1426 assert_response :success 1463 assert_response :success
1427 assert_template 'new' 1464 assert_template 'new'
1428 1465
1429 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} 1466 assert_select 'form#issue-form' do
1430 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 1467 assert_select 'input[name=?]', 'issue[is_private]'
1431 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 1468 assert_select 'select[name=?]', 'issue[project_id]', 0
1432 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 1469 assert_select 'select[name=?]', 'issue[tracker_id]'
1433 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 1470 assert_select 'input[name=?]', 'issue[subject]'
1434 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 1471 assert_select 'textarea[name=?]', 'issue[description]'
1435 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 1472 assert_select 'select[name=?]', 'issue[status_id]'
1436 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 1473 assert_select 'select[name=?]', 'issue[priority_id]'
1437 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 1474 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1438 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 1475 assert_select 'select[name=?]', 'issue[category_id]'
1439 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 1476 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1440 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 1477 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1441 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 1478 assert_select 'input[name=?]', 'issue[start_date]'
1442 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 1479 assert_select 'input[name=?]', 'issue[due_date]'
1443 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } 1480 assert_select 'select[name=?]', 'issue[done_ratio]'
1444 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 1481 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1482 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1483 end
1445 1484
1446 # Be sure we don't display inactive IssuePriorities 1485 # Be sure we don't display inactive IssuePriorities
1447 assert ! IssuePriority.find(15).active? 1486 assert ! IssuePriority.find(15).active?
1448 assert_no_tag :option, :attributes => {:value => '15'}, 1487 assert_select 'select[name=?]', 'issue[priority_id]' do
1449 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 1488 assert_select 'option[value=15]', 0
1489 end
1450 end 1490 end
1451 1491
1452 def test_get_new_with_minimal_permissions 1492 def test_get_new_with_minimal_permissions
1453 Role.find(1).update_attribute :permissions, [:add_issues] 1493 Role.find(1).update_attribute :permissions, [:add_issues]
1454 WorkflowTransition.delete_all :role_id => 1 1494 WorkflowTransition.delete_all :role_id => 1
1456 @request.session[:user_id] = 2 1496 @request.session[:user_id] = 2
1457 get :new, :project_id => 1, :tracker_id => 1 1497 get :new, :project_id => 1, :tracker_id => 1
1458 assert_response :success 1498 assert_response :success
1459 assert_template 'new' 1499 assert_template 'new'
1460 1500
1461 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 1501 assert_select 'form#issue-form' do
1462 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 1502 assert_select 'input[name=?]', 'issue[is_private]', 0
1463 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 1503 assert_select 'select[name=?]', 'issue[project_id]', 0
1464 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 1504 assert_select 'select[name=?]', 'issue[tracker_id]'
1465 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 1505 assert_select 'input[name=?]', 'issue[subject]'
1466 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 1506 assert_select 'textarea[name=?]', 'issue[description]'
1467 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 1507 assert_select 'select[name=?]', 'issue[status_id]'
1468 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 1508 assert_select 'select[name=?]', 'issue[priority_id]'
1469 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 1509 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1470 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 1510 assert_select 'select[name=?]', 'issue[category_id]'
1471 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 1511 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1472 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 1512 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1473 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 1513 assert_select 'input[name=?]', 'issue[start_date]'
1474 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 1514 assert_select 'input[name=?]', 'issue[due_date]'
1475 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } 1515 assert_select 'select[name=?]', 'issue[done_ratio]'
1476 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 1516 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1517 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1518 end
1477 end 1519 end
1478 1520
1479 def test_get_new_with_list_custom_field 1521 def test_get_new_with_list_custom_field
1480 @request.session[:user_id] = 2 1522 @request.session[:user_id] = 2
1481 get :new, :project_id => 1, :tracker_id => 1 1523 get :new, :project_id => 1, :tracker_id => 1
1539 1581
1540 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]" 1582 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1541 end 1583 end
1542 1584
1543 def test_get_new_without_default_start_date_is_creation_date 1585 def test_get_new_without_default_start_date_is_creation_date
1544 Setting.default_issue_start_date_to_creation_date = 0 1586 with_settings :default_issue_start_date_to_creation_date => 0 do
1545 1587 @request.session[:user_id] = 2
1588 get :new, :project_id => 1, :tracker_id => 1
1589 assert_response :success
1590 assert_template 'new'
1591 assert_select 'input[name=?]', 'issue[start_date]'
1592 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1593 end
1594 end
1595
1596 def test_get_new_with_default_start_date_is_creation_date
1597 with_settings :default_issue_start_date_to_creation_date => 1 do
1598 @request.session[:user_id] = 2
1599 get :new, :project_id => 1, :tracker_id => 1
1600 assert_response :success
1601 assert_template 'new'
1602 assert_select 'input[name=?][value=?]', 'issue[start_date]',
1603 Date.today.to_s
1604 end
1605 end
1606
1607 def test_get_new_form_should_allow_attachment_upload
1546 @request.session[:user_id] = 2 1608 @request.session[:user_id] = 2
1547 get :new, :project_id => 1, :tracker_id => 1 1609 get :new, :project_id => 1, :tracker_id => 1
1548 assert_response :success
1549 assert_template 'new'
1550
1551 assert_select 'input[name=?]', 'issue[start_date]'
1552 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1553 end
1554
1555 def test_get_new_with_default_start_date_is_creation_date
1556 Setting.default_issue_start_date_to_creation_date = 1
1557
1558 @request.session[:user_id] = 2
1559 get :new, :project_id => 1, :tracker_id => 1
1560 assert_response :success
1561 assert_template 'new'
1562
1563 assert_select 'input[name=?][value=?]', 'issue[start_date]', Date.today.to_s
1564 end
1565
1566 def test_get_new_form_should_allow_attachment_upload
1567 @request.session[:user_id] = 2
1568 get :new, :project_id => 1, :tracker_id => 1
1569 1610
1570 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do 1611 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1571 assert_select 'input[name=?][type=file]', 'attachments[1][file]' 1612 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1572 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
1573 end 1613 end
1574 end 1614 end
1575 1615
1576 def test_get_new_should_prefill_the_form_from_params 1616 def test_get_new_should_prefill_the_form_from_params
1577 @request.session[:user_id] = 2 1617 @request.session[:user_id] = 2
1661 get :new, :project_id => 1 1701 get :new, :project_id => 1
1662 assert_response 500 1702 assert_response 500
1663 assert_error_tag :content => /No tracker/ 1703 assert_error_tag :content => /No tracker/
1664 end 1704 end
1665 1705
1666 def test_update_new_form 1706 def test_update_form_for_new_issue
1667 @request.session[:user_id] = 2 1707 @request.session[:user_id] = 2
1668 xhr :post, :new, :project_id => 1, 1708 xhr :post, :update_form, :project_id => 1,
1669 :issue => {:tracker_id => 2, 1709 :issue => {:tracker_id => 2,
1670 :subject => 'This is the test_new issue', 1710 :subject => 'This is the test_new issue',
1671 :description => 'This is the description', 1711 :description => 'This is the description',
1672 :priority_id => 5} 1712 :priority_id => 5}
1673 assert_response :success 1713 assert_response :success
1674 assert_template 'update_form' 1714 assert_template 'update_form'
1675 assert_template 'form' 1715 assert_template :partial => '_form'
1676 assert_equal 'text/javascript', response.content_type 1716 assert_equal 'text/javascript', response.content_type
1677 1717
1678 issue = assigns(:issue) 1718 issue = assigns(:issue)
1679 assert_kind_of Issue, issue 1719 assert_kind_of Issue, issue
1680 assert_equal 1, issue.project_id 1720 assert_equal 1, issue.project_id
1681 assert_equal 2, issue.tracker_id 1721 assert_equal 2, issue.tracker_id
1682 assert_equal 'This is the test_new issue', issue.subject 1722 assert_equal 'This is the test_new issue', issue.subject
1683 end 1723 end
1684 1724
1685 def test_update_new_form_should_propose_transitions_based_on_initial_status 1725 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1686 @request.session[:user_id] = 2 1726 @request.session[:user_id] = 2
1687 WorkflowTransition.delete_all 1727 WorkflowTransition.delete_all
1688 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) 1728 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1689 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) 1729 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1690 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) 1730 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1691 1731
1692 xhr :post, :new, :project_id => 1, 1732 xhr :post, :update_form, :project_id => 1,
1693 :issue => {:tracker_id => 1, 1733 :issue => {:tracker_id => 1,
1694 :status_id => 5, 1734 :status_id => 5,
1695 :subject => 'This is an issue'} 1735 :subject => 'This is an issue'}
1696 1736
1697 assert_equal 5, assigns(:issue).status_id 1737 assert_equal 5, assigns(:issue).status_id
1718 assert_equal 2, issue.author_id 1758 assert_equal 2, issue.author_id
1719 assert_equal 3, issue.tracker_id 1759 assert_equal 3, issue.tracker_id
1720 assert_equal 2, issue.status_id 1760 assert_equal 2, issue.status_id
1721 assert_equal Date.parse('2010-11-07'), issue.start_date 1761 assert_equal Date.parse('2010-11-07'), issue.start_date
1722 assert_nil issue.estimated_hours 1762 assert_nil issue.estimated_hours
1723 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) 1763 v = issue.custom_values.where(:custom_field_id => 2).first
1724 assert_not_nil v 1764 assert_not_nil v
1725 assert_equal 'Value for field 2', v.value 1765 assert_equal 'Value for field 2', v.value
1726 end 1766 end
1727 1767
1728 def test_post_new_with_group_assignment 1768 def test_post_new_with_group_assignment
1746 assert_not_nil issue 1786 assert_not_nil issue
1747 assert_equal group, issue.assigned_to 1787 assert_equal group, issue.assigned_to
1748 end 1788 end
1749 1789
1750 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date 1790 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1751 Setting.default_issue_start_date_to_creation_date = 0 1791 with_settings :default_issue_start_date_to_creation_date => 0 do
1752 1792 @request.session[:user_id] = 2
1753 @request.session[:user_id] = 2 1793 assert_difference 'Issue.count' do
1754 assert_difference 'Issue.count' do 1794 post :create, :project_id => 1,
1755 post :create, :project_id => 1,
1756 :issue => {:tracker_id => 3, 1795 :issue => {:tracker_id => 3,
1757 :status_id => 2, 1796 :status_id => 2,
1758 :subject => 'This is the test_new issue', 1797 :subject => 'This is the test_new issue',
1759 :description => 'This is the description', 1798 :description => 'This is the description',
1760 :priority_id => 5, 1799 :priority_id => 5,
1761 :estimated_hours => '', 1800 :estimated_hours => '',
1762 :custom_field_values => {'2' => 'Value for field 2'}} 1801 :custom_field_values => {'2' => 'Value for field 2'}}
1763 end 1802 end
1764 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id 1803 assert_redirected_to :controller => 'issues', :action => 'show',
1765 1804 :id => Issue.last.id
1766 issue = Issue.find_by_subject('This is the test_new issue') 1805 issue = Issue.find_by_subject('This is the test_new issue')
1767 assert_not_nil issue 1806 assert_not_nil issue
1768 assert_nil issue.start_date 1807 assert_nil issue.start_date
1808 end
1769 end 1809 end
1770 1810
1771 def test_post_create_without_start_date_and_default_start_date_is_creation_date 1811 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1772 Setting.default_issue_start_date_to_creation_date = 1 1812 with_settings :default_issue_start_date_to_creation_date => 1 do
1773 1813 @request.session[:user_id] = 2
1774 @request.session[:user_id] = 2 1814 assert_difference 'Issue.count' do
1775 assert_difference 'Issue.count' do 1815 post :create, :project_id => 1,
1776 post :create, :project_id => 1,
1777 :issue => {:tracker_id => 3, 1816 :issue => {:tracker_id => 3,
1778 :status_id => 2, 1817 :status_id => 2,
1779 :subject => 'This is the test_new issue', 1818 :subject => 'This is the test_new issue',
1780 :description => 'This is the description', 1819 :description => 'This is the description',
1781 :priority_id => 5, 1820 :priority_id => 5,
1782 :estimated_hours => '', 1821 :estimated_hours => '',
1783 :custom_field_values => {'2' => 'Value for field 2'}} 1822 :custom_field_values => {'2' => 'Value for field 2'}}
1784 end 1823 end
1785 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id 1824 assert_redirected_to :controller => 'issues', :action => 'show',
1786 1825 :id => Issue.last.id
1787 issue = Issue.find_by_subject('This is the test_new issue') 1826 issue = Issue.find_by_subject('This is the test_new issue')
1788 assert_not_nil issue 1827 assert_not_nil issue
1789 assert_equal Date.today, issue.start_date 1828 assert_equal Date.today, issue.start_date
1829 end
1790 end 1830 end
1791 1831
1792 def test_post_create_and_continue 1832 def test_post_create_and_continue
1793 @request.session[:user_id] = 2 1833 @request.session[:user_id] = 2
1794 assert_difference 'Issue.count' do 1834 assert_difference 'Issue.count' do
1795 post :create, :project_id => 1, 1835 post :create, :project_id => 1,
1796 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, 1836 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1797 :continue => '' 1837 :continue => ''
1798 end 1838 end
1799 1839
1800 issue = Issue.first(:order => 'id DESC') 1840 issue = Issue.order('id DESC').first
1801 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} 1841 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1802 assert_not_nil flash[:notice], "flash was not set" 1842 assert_not_nil flash[:notice], "flash was not set"
1803 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message" 1843 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
1804 end 1844 end
1805 1845
1827 :description => 'This is the description', 1867 :description => 'This is the description',
1828 :priority_id => 5, 1868 :priority_id => 5,
1829 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} 1869 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1830 end 1870 end
1831 assert_response 302 1871 assert_response 302
1832 issue = Issue.first(:order => 'id DESC') 1872 issue = Issue.order('id DESC').first
1833 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort 1873 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1834 end 1874 end
1835 1875
1836 def test_post_create_with_empty_multi_custom_field 1876 def test_post_create_with_empty_multi_custom_field
1837 field = IssueCustomField.find_by_name('Database') 1877 field = IssueCustomField.find_by_name('Database')
1845 :description => 'This is the description', 1885 :description => 'This is the description',
1846 :priority_id => 5, 1886 :priority_id => 5,
1847 :custom_field_values => {'1' => ['']}} 1887 :custom_field_values => {'1' => ['']}}
1848 end 1888 end
1849 assert_response 302 1889 assert_response 302
1850 issue = Issue.first(:order => 'id DESC') 1890 issue = Issue.order('id DESC').first
1851 assert_equal [''], issue.custom_field_value(1).sort 1891 assert_equal [''], issue.custom_field_value(1).sort
1852 end 1892 end
1853 1893
1854 def test_post_create_with_multi_user_custom_field 1894 def test_post_create_with_multi_user_custom_field
1855 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, 1895 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1863 :description => 'This is the description', 1903 :description => 'This is the description',
1864 :priority_id => 5, 1904 :priority_id => 5,
1865 :custom_field_values => {field.id.to_s => ['', '2', '3']}} 1905 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1866 end 1906 end
1867 assert_response 302 1907 assert_response 302
1868 issue = Issue.first(:order => 'id DESC') 1908 issue = Issue.order('id DESC').first
1869 assert_equal ['2', '3'], issue.custom_field_value(field).sort 1909 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1870 end 1910 end
1871 1911
1872 def test_post_create_with_required_custom_field_and_without_custom_fields_param 1912 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1873 field = IssueCustomField.find_by_name('Database') 1913 field = IssueCustomField.find_by_name('Database')
1883 end 1923 end
1884 assert_response :success 1924 assert_response :success
1885 assert_template 'new' 1925 assert_template 'new'
1886 issue = assigns(:issue) 1926 issue = assigns(:issue)
1887 assert_not_nil issue 1927 assert_not_nil issue
1888 assert_error_tag :content => /Database can&#x27;t be blank/ 1928 assert_error_tag :content => /Database #{ESCAPED_CANT} be blank/
1889 end 1929 end
1890 1930
1891 def test_create_should_validate_required_fields 1931 def test_create_should_validate_required_fields
1892 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1932 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1893 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1933 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1907 } 1947 }
1908 assert_response :success 1948 assert_response :success
1909 assert_template 'new' 1949 assert_template 'new'
1910 end 1950 end
1911 1951
1912 assert_error_tag :content => /Due date can&#x27;t be blank/i 1952 assert_error_tag :content => /Due date #{ESCAPED_CANT} be blank/i
1913 assert_error_tag :content => /Bar can&#x27;t be blank/i 1953 assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i
1914 end 1954 end
1915 1955
1916 def test_create_should_ignore_readonly_fields 1956 def test_create_should_ignore_readonly_fields
1917 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1957 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1918 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1958 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1931 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'} 1971 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1932 } 1972 }
1933 assert_response 302 1973 assert_response 302
1934 end 1974 end
1935 1975
1936 issue = Issue.first(:order => 'id DESC') 1976 issue = Issue.order('id DESC').first
1937 assert_equal Date.parse('2012-07-14'), issue.start_date 1977 assert_equal Date.parse('2012-07-14'), issue.start_date
1938 assert_nil issue.due_date 1978 assert_nil issue.due_date
1939 assert_equal 'value1', issue.custom_field_value(cf1) 1979 assert_equal 'value1', issue.custom_field_value(cf1)
1940 assert_nil issue.custom_field_value(cf2) 1980 assert_nil issue.custom_field_value(cf2)
1941 end 1981 end
2030 post :create, :project_id => 1, 2070 post :create, :project_id => 1,
2031 :issue => {:tracker_id => 1, 2071 :issue => {:tracker_id => 1,
2032 :subject => 'This is a private issue', 2072 :subject => 'This is a private issue',
2033 :is_private => '1'} 2073 :is_private => '1'}
2034 end 2074 end
2035 issue = Issue.first(:order => 'id DESC') 2075 issue = Issue.order('id DESC').first
2036 assert issue.is_private? 2076 assert issue.is_private?
2037 end 2077 end
2038 2078
2039 def test_post_create_private_with_set_own_issues_private_permission 2079 def test_post_create_private_with_set_own_issues_private_permission
2040 role = Role.find(1) 2080 role = Role.find(1)
2047 post :create, :project_id => 1, 2087 post :create, :project_id => 1,
2048 :issue => {:tracker_id => 1, 2088 :issue => {:tracker_id => 1,
2049 :subject => 'This is a private issue', 2089 :subject => 'This is a private issue',
2050 :is_private => '1'} 2090 :is_private => '1'}
2051 end 2091 end
2052 issue = Issue.first(:order => 'id DESC') 2092 issue = Issue.order('id DESC').first
2053 assert issue.is_private? 2093 assert issue.is_private?
2054 end 2094 end
2055 2095
2056 def test_post_create_should_send_a_notification 2096 def test_post_create_should_send_a_notification
2057 ActionMailer::Base.deliveries.clear 2097 ActionMailer::Base.deliveries.clear
2080 :priority_id => 6, 2120 :priority_id => 6,
2081 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} 2121 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2082 assert_response :success 2122 assert_response :success
2083 assert_template 'new' 2123 assert_template 'new'
2084 2124
2085 assert_tag :textarea, :attributes => { :name => 'issue[description]' }, 2125 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2086 :content => "\nThis is a description" 2126 assert_select 'select[name=?]', 'issue[priority_id]' do
2087 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, 2127 assert_select 'option[value=6][selected=selected]', :text => 'High'
2088 :child => { :tag => 'option', :attributes => { :selected => 'selected', 2128 end
2089 :value => '6' },
2090 :content => 'High' }
2091 # Custom fields 2129 # Custom fields
2092 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, 2130 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2093 :child => { :tag => 'option', :attributes => { :selected => 'selected', 2131 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2094 :value => 'Oracle' }, 2132 end
2095 :content => 'Oracle' } 2133 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
2096 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
2097 :value => 'Value for field 2'}
2098 end 2134 end
2099 2135
2100 def test_post_create_with_failure_should_preserve_watchers 2136 def test_post_create_with_failure_should_preserve_watchers
2101 assert !User.find(8).member_of?(Project.find(1)) 2137 assert !User.find(8).member_of?(Project.find(1))
2102 2138
2105 :issue => {:tracker_id => 1, 2141 :issue => {:tracker_id => 1,
2106 :watcher_user_ids => ['3', '8']} 2142 :watcher_user_ids => ['3', '8']}
2107 assert_response :success 2143 assert_response :success
2108 assert_template 'new' 2144 assert_template 'new'
2109 2145
2110 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil} 2146 assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]'
2111 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'} 2147 assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]'
2112 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'} 2148 assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]'
2113 end 2149 end
2114 2150
2115 def test_post_create_should_ignore_non_safe_attributes 2151 def test_post_create_should_ignore_non_safe_attributes
2116 @request.session[:user_id] = 2 2152 @request.session[:user_id] = 2
2117 assert_nothing_raised do 2153 assert_nothing_raised do
2129 :issue => { :tracker_id => '1', :subject => 'With attachment' }, 2165 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2130 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 2166 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2131 end 2167 end
2132 end 2168 end
2133 2169
2134 issue = Issue.first(:order => 'id DESC') 2170 issue = Issue.order('id DESC').first
2135 attachment = Attachment.first(:order => 'id DESC') 2171 attachment = Attachment.order('id DESC').first
2136 2172
2137 assert_equal issue, attachment.container 2173 assert_equal issue, attachment.container
2138 assert_equal 2, attachment.author_id 2174 assert_equal 2, attachment.author_id
2139 assert_equal 'testfile.txt', attachment.filename 2175 assert_equal 'testfile.txt', attachment.filename
2140 assert_equal 'text/plain', attachment.content_type 2176 assert_equal 'text/plain', attachment.content_type
2142 assert_equal 59, attachment.filesize 2178 assert_equal 59, attachment.filesize
2143 assert File.exists?(attachment.diskfile) 2179 assert File.exists?(attachment.diskfile)
2144 assert_equal 59, File.size(attachment.diskfile) 2180 assert_equal 59, File.size(attachment.diskfile)
2145 end 2181 end
2146 2182
2183 def test_post_create_with_attachment_should_notify_with_attachments
2184 ActionMailer::Base.deliveries.clear
2185 set_tmp_attachments_directory
2186 @request.session[:user_id] = 2
2187
2188 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
2189 assert_difference 'Issue.count' do
2190 post :create, :project_id => 1,
2191 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2192 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2193 end
2194 end
2195
2196 assert_not_nil ActionMailer::Base.deliveries.last
2197 assert_select_email do
2198 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
2199 end
2200 end
2201
2147 def test_post_create_with_failure_should_save_attachments 2202 def test_post_create_with_failure_should_save_attachments
2148 set_tmp_attachments_directory 2203 set_tmp_attachments_directory
2149 @request.session[:user_id] = 2 2204 @request.session[:user_id] = 2
2150 2205
2151 assert_no_difference 'Issue.count' do 2206 assert_no_difference 'Issue.count' do
2156 assert_response :success 2211 assert_response :success
2157 assert_template 'new' 2212 assert_template 'new'
2158 end 2213 end
2159 end 2214 end
2160 2215
2161 attachment = Attachment.first(:order => 'id DESC') 2216 attachment = Attachment.order('id DESC').first
2162 assert_equal 'testfile.txt', attachment.filename 2217 assert_equal 'testfile.txt', attachment.filename
2163 assert File.exists?(attachment.diskfile) 2218 assert File.exists?(attachment.diskfile)
2164 assert_nil attachment.container 2219 assert_nil attachment.container
2165 2220
2166 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 2221 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2167 assert_tag 'span', :content => /testfile.txt/ 2222 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2168 end 2223 end
2169 2224
2170 def test_post_create_with_failure_should_keep_saved_attachments 2225 def test_post_create_with_failure_should_keep_saved_attachments
2171 set_tmp_attachments_directory 2226 set_tmp_attachments_directory
2172 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 2227 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2180 assert_response :success 2235 assert_response :success
2181 assert_template 'new' 2236 assert_template 'new'
2182 end 2237 end
2183 end 2238 end
2184 2239
2185 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 2240 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2186 assert_tag 'span', :content => /testfile.txt/ 2241 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2187 end 2242 end
2188 2243
2189 def test_post_create_should_attach_saved_attachments 2244 def test_post_create_should_attach_saved_attachments
2190 set_tmp_attachments_directory 2245 set_tmp_attachments_directory
2191 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 2246 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2198 :attachments => {'p0' => {'token' => attachment.token}} 2253 :attachments => {'p0' => {'token' => attachment.token}}
2199 assert_response 302 2254 assert_response 302
2200 end 2255 end
2201 end 2256 end
2202 2257
2203 issue = Issue.first(:order => 'id DESC') 2258 issue = Issue.order('id DESC').first
2204 assert_equal 1, issue.attachments.count 2259 assert_equal 1, issue.attachments.count
2205 2260
2206 attachment.reload 2261 attachment.reload
2207 assert_equal issue, attachment.container 2262 assert_equal issue, attachment.container
2208 end 2263 end
2209 2264
2210 context "without workflow privilege" do 2265 def setup_without_workflow_privilege
2211 setup do 2266 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2212 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) 2267 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2213 Role.anonymous.add_permission! :add_issues, :add_issue_notes 2268 end
2214 end 2269 private :setup_without_workflow_privilege
2215 2270
2216 context "#new" do 2271 test "without workflow privilege #new should propose default status only" do
2217 should "propose default status only" do 2272 setup_without_workflow_privilege
2218 get :new, :project_id => 1 2273 get :new, :project_id => 1
2219 assert_response :success 2274 assert_response :success
2220 assert_template 'new' 2275 assert_template 'new'
2221 assert_tag :tag => 'select', 2276 assert_select 'select[name=?]', 'issue[status_id]' do
2222 :attributes => {:name => 'issue[status_id]'}, 2277 assert_select 'option', 1
2223 :children => {:count => 1}, 2278 assert_select 'option[value=?]', IssueStatus.default.id.to_s
2224 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} 2279 end
2225 end 2280 end
2226 2281
2227 should "accept default status" do 2282 test "without workflow privilege #new should accept default status" do
2228 assert_difference 'Issue.count' do 2283 setup_without_workflow_privilege
2229 post :create, :project_id => 1, 2284 assert_difference 'Issue.count' do
2230 :issue => {:tracker_id => 1, 2285 post :create, :project_id => 1,
2286 :issue => {:tracker_id => 1,
2231 :subject => 'This is an issue', 2287 :subject => 'This is an issue',
2232 :status_id => 1} 2288 :status_id => 1}
2233 end 2289 end
2234 issue = Issue.last(:order => 'id') 2290 issue = Issue.order('id').last
2235 assert_equal IssueStatus.default, issue.status 2291 assert_equal IssueStatus.default, issue.status
2236 end 2292 end
2237 2293
2238 should "ignore unauthorized status" do 2294 test "without workflow privilege #new should ignore unauthorized status" do
2239 assert_difference 'Issue.count' do 2295 setup_without_workflow_privilege
2240 post :create, :project_id => 1, 2296 assert_difference 'Issue.count' do
2297 post :create, :project_id => 1,
2241 :issue => {:tracker_id => 1, 2298 :issue => {:tracker_id => 1,
2242 :subject => 'This is an issue', 2299 :subject => 'This is an issue',
2243 :status_id => 3} 2300 :status_id => 3}
2244 end 2301 end
2245 issue = Issue.last(:order => 'id') 2302 issue = Issue.order('id').last
2246 assert_equal IssueStatus.default, issue.status 2303 assert_equal IssueStatus.default, issue.status
2247 end 2304 end
2248 end 2305
2249 2306 test "without workflow privilege #update should ignore status change" do
2250 context "#update" do 2307 setup_without_workflow_privilege
2251 should "ignore status change" do 2308 assert_difference 'Journal.count' do
2252 assert_difference 'Journal.count' do 2309 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2253 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2310 end
2254 end 2311 assert_equal 1, Issue.find(1).status_id
2255 assert_equal 1, Issue.find(1).status_id 2312 end
2256 end 2313
2257 2314 test "without workflow privilege #update ignore attributes changes" do
2258 should "ignore attributes changes" do 2315 setup_without_workflow_privilege
2259 assert_difference 'Journal.count' do 2316 assert_difference 'Journal.count' do
2260 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'} 2317 put :update, :id => 1,
2261 end 2318 :issue => {:subject => 'changed', :assigned_to_id => 2,
2262 issue = Issue.find(1) 2319 :notes => 'just trying'}
2263 assert_equal "Can't print recipes", issue.subject 2320 end
2264 assert_nil issue.assigned_to 2321 issue = Issue.find(1)
2265 end 2322 assert_equal "Can't print recipes", issue.subject
2266 end 2323 assert_nil issue.assigned_to
2267 end 2324 end
2268 2325
2269 context "with workflow privilege" do 2326 def setup_with_workflow_privilege
2270 setup do 2327 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2271 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) 2328 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2272 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) 2329 :old_status_id => 1, :new_status_id => 3)
2273 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) 2330 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2274 Role.anonymous.add_permission! :add_issues, :add_issue_notes 2331 :old_status_id => 1, :new_status_id => 4)
2275 end 2332 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2276 2333 end
2277 context "#update" do 2334 private :setup_with_workflow_privilege
2278 should "accept authorized status" do 2335
2279 assert_difference 'Journal.count' do 2336 test "with workflow privilege #update should accept authorized status" do
2280 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2337 setup_with_workflow_privilege
2281 end 2338 assert_difference 'Journal.count' do
2282 assert_equal 3, Issue.find(1).status_id 2339 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2283 end 2340 end
2284 2341 assert_equal 3, Issue.find(1).status_id
2285 should "ignore unauthorized status" do 2342 end
2286 assert_difference 'Journal.count' do 2343
2287 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} 2344 test "with workflow privilege #update should ignore unauthorized status" do
2288 end 2345 setup_with_workflow_privilege
2289 assert_equal 1, Issue.find(1).status_id 2346 assert_difference 'Journal.count' do
2290 end 2347 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2291 2348 end
2292 should "accept authorized attributes changes" do 2349 assert_equal 1, Issue.find(1).status_id
2293 assert_difference 'Journal.count' do 2350 end
2294 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'} 2351
2295 end 2352 test "with workflow privilege #update should accept authorized attributes changes" do
2296 issue = Issue.find(1) 2353 setup_with_workflow_privilege
2297 assert_equal 2, issue.assigned_to_id 2354 assert_difference 'Journal.count' do
2298 end 2355 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2299 2356 end
2300 should "ignore unauthorized attributes changes" do 2357 issue = Issue.find(1)
2301 assert_difference 'Journal.count' do 2358 assert_equal 2, issue.assigned_to_id
2302 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'} 2359 end
2303 end 2360
2304 issue = Issue.find(1) 2361 test "with workflow privilege #update should ignore unauthorized attributes changes" do
2305 assert_equal "Can't print recipes", issue.subject 2362 setup_with_workflow_privilege
2306 end 2363 assert_difference 'Journal.count' do
2307 end 2364 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2308 2365 end
2309 context "and :edit_issues permission" do 2366 issue = Issue.find(1)
2310 setup do 2367 assert_equal "Can't print recipes", issue.subject
2311 Role.anonymous.add_permission! :add_issues, :edit_issues 2368 end
2312 end 2369
2313 2370 def setup_with_workflow_privilege_and_edit_issues_permission
2314 should "accept authorized status" do 2371 setup_with_workflow_privilege
2315 assert_difference 'Journal.count' do 2372 Role.anonymous.add_permission! :add_issues, :edit_issues
2316 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2373 end
2317 end 2374 private :setup_with_workflow_privilege_and_edit_issues_permission
2318 assert_equal 3, Issue.find(1).status_id 2375
2319 end 2376 test "with workflow privilege and :edit_issues permission should accept authorized status" do
2320 2377 setup_with_workflow_privilege_and_edit_issues_permission
2321 should "ignore unauthorized status" do 2378 assert_difference 'Journal.count' do
2322 assert_difference 'Journal.count' do 2379 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2323 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} 2380 end
2324 end 2381 assert_equal 3, Issue.find(1).status_id
2325 assert_equal 1, Issue.find(1).status_id 2382 end
2326 end 2383
2327 2384 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
2328 should "accept authorized attributes changes" do 2385 setup_with_workflow_privilege_and_edit_issues_permission
2329 assert_difference 'Journal.count' do 2386 assert_difference 'Journal.count' do
2330 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'} 2387 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2331 end 2388 end
2332 issue = Issue.find(1) 2389 assert_equal 1, Issue.find(1).status_id
2333 assert_equal "changed", issue.subject 2390 end
2334 assert_equal 2, issue.assigned_to_id 2391
2335 end 2392 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
2336 end 2393 setup_with_workflow_privilege_and_edit_issues_permission
2394 assert_difference 'Journal.count' do
2395 put :update, :id => 1,
2396 :issue => {:subject => 'changed', :assigned_to_id => 2,
2397 :notes => 'just trying'}
2398 end
2399 issue = Issue.find(1)
2400 assert_equal "changed", issue.subject
2401 assert_equal 2, issue.assigned_to_id
2337 end 2402 end
2338 2403
2339 def test_new_as_copy 2404 def test_new_as_copy
2340 @request.session[:user_id] = 2 2405 @request.session[:user_id] = 2
2341 get :new, :project_id => 1, :copy_from => 1 2406 get :new, :project_id => 1, :copy_from => 1
2347 orig = Issue.find(1) 2412 orig = Issue.find(1)
2348 assert_equal 1, assigns(:issue).project_id 2413 assert_equal 1, assigns(:issue).project_id
2349 assert_equal orig.subject, assigns(:issue).subject 2414 assert_equal orig.subject, assigns(:issue).subject
2350 assert assigns(:issue).copy? 2415 assert assigns(:issue).copy?
2351 2416
2352 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} 2417 assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do
2353 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 2418 assert_select 'select[name=?]', 'issue[project_id]' do
2354 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2419 assert_select 'option[value=1][selected=selected]', :text => 'eCookbook'
2355 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'} 2420 assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore'
2356 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2421 end
2357 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'} 2422 assert_select 'input[name=copy_from][value=1]'
2358 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} 2423 end
2359 2424
2360 # "New issue" menu item should not link to copy 2425 # "New issue" menu item should not link to copy
2361 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' 2426 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]'
2362 end 2427 end
2363 2428
2365 @request.session[:user_id] = 2 2430 @request.session[:user_id] = 2
2366 issue = Issue.find(3) 2431 issue = Issue.find(3)
2367 assert issue.attachments.count > 0 2432 assert issue.attachments.count > 0
2368 get :new, :project_id => 1, :copy_from => 3 2433 get :new, :project_id => 1, :copy_from => 3
2369 2434
2370 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} 2435 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]'
2371 end 2436 end
2372 2437
2373 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox 2438 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2374 @request.session[:user_id] = 2 2439 @request.session[:user_id] = 2
2375 issue = Issue.find(3) 2440 issue = Issue.find(3)
2376 issue.attachments.delete_all 2441 issue.attachments.delete_all
2377 get :new, :project_id => 1, :copy_from => 3 2442 get :new, :project_id => 1, :copy_from => 3
2378 2443
2379 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} 2444 assert_select 'input[name=copy_attachments]', 0
2380 end 2445 end
2381 2446
2382 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox 2447 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2383 @request.session[:user_id] = 2 2448 @request.session[:user_id] = 2
2384 issue = Issue.generate_with_descendants! 2449 issue = Issue.generate_with_descendants!
2400 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2465 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2401 2466
2402 assert_not_nil assigns(:issue) 2467 assert_not_nil assigns(:issue)
2403 assert assigns(:issue).copy? 2468 assert assigns(:issue).copy?
2404 end 2469 end
2405 issue = Issue.first(:order => 'id DESC') 2470 issue = Issue.order('id DESC').first
2406 assert_redirected_to "/issues/#{issue.id}" 2471 assert_redirected_to "/issues/#{issue.id}"
2407 2472
2408 assert_equal 2, issue.project_id 2473 assert_equal 2, issue.project_id
2409 assert_equal 3, issue.tracker_id 2474 assert_equal 3, issue.tracker_id
2410 assert_equal 'Copy', issue.subject 2475 assert_equal 'Copy', issue.subject
2413 def test_create_as_copy_should_copy_attachments 2478 def test_create_as_copy_should_copy_attachments
2414 @request.session[:user_id] = 2 2479 @request.session[:user_id] = 2
2415 issue = Issue.find(3) 2480 issue = Issue.find(3)
2416 count = issue.attachments.count 2481 count = issue.attachments.count
2417 assert count > 0 2482 assert count > 0
2418
2419 assert_difference 'Issue.count' do 2483 assert_difference 'Issue.count' do
2420 assert_difference 'Attachment.count', count do 2484 assert_difference 'Attachment.count', count do
2421 assert_no_difference 'Journal.count' do 2485 assert_difference 'Journal.count', 2 do
2422 post :create, :project_id => 1, :copy_from => 3, 2486 post :create, :project_id => 1, :copy_from => 3,
2423 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, 2487 :issue => {:project_id => '1', :tracker_id => '3',
2488 :status_id => '1', :subject => 'Copy with attachments'},
2424 :copy_attachments => '1' 2489 :copy_attachments => '1'
2425 end 2490 end
2426 end 2491 end
2427 end 2492 end
2428 copy = Issue.first(:order => 'id DESC') 2493 copy = Issue.order('id DESC').first
2429 assert_equal count, copy.attachments.count 2494 assert_equal count, copy.attachments.count
2430 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort 2495 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2431 end 2496 end
2432 2497
2433 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments 2498 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2434 @request.session[:user_id] = 2 2499 @request.session[:user_id] = 2
2435 issue = Issue.find(3) 2500 issue = Issue.find(3)
2436 count = issue.attachments.count 2501 count = issue.attachments.count
2437 assert count > 0 2502 assert count > 0
2438
2439 assert_difference 'Issue.count' do 2503 assert_difference 'Issue.count' do
2440 assert_no_difference 'Attachment.count' do 2504 assert_no_difference 'Attachment.count' do
2441 assert_no_difference 'Journal.count' do 2505 assert_difference 'Journal.count', 2 do
2442 post :create, :project_id => 1, :copy_from => 3, 2506 post :create, :project_id => 1, :copy_from => 3,
2443 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} 2507 :issue => {:project_id => '1', :tracker_id => '3',
2508 :status_id => '1', :subject => 'Copy with attachments'}
2444 end 2509 end
2445 end 2510 end
2446 end 2511 end
2447 copy = Issue.first(:order => 'id DESC') 2512 copy = Issue.order('id DESC').first
2448 assert_equal 0, copy.attachments.count 2513 assert_equal 0, copy.attachments.count
2449 end 2514 end
2450 2515
2451 def test_create_as_copy_with_attachments_should_add_new_files 2516 def test_create_as_copy_with_attachments_should_add_new_files
2452 @request.session[:user_id] = 2 2517 @request.session[:user_id] = 2
2453 issue = Issue.find(3) 2518 issue = Issue.find(3)
2454 count = issue.attachments.count 2519 count = issue.attachments.count
2455 assert count > 0 2520 assert count > 0
2456
2457 assert_difference 'Issue.count' do 2521 assert_difference 'Issue.count' do
2458 assert_difference 'Attachment.count', count + 1 do 2522 assert_difference 'Attachment.count', count + 1 do
2459 assert_no_difference 'Journal.count' do 2523 assert_difference 'Journal.count', 2 do
2460 post :create, :project_id => 1, :copy_from => 3, 2524 post :create, :project_id => 1, :copy_from => 3,
2461 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, 2525 :issue => {:project_id => '1', :tracker_id => '3',
2526 :status_id => '1', :subject => 'Copy with attachments'},
2462 :copy_attachments => '1', 2527 :copy_attachments => '1',
2463 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 2528 :attachments => {'1' =>
2529 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2530 'description' => 'test file'}}
2464 end 2531 end
2465 end 2532 end
2466 end 2533 end
2467 copy = Issue.first(:order => 'id DESC') 2534 copy = Issue.order('id DESC').first
2468 assert_equal count + 1, copy.attachments.count 2535 assert_equal count + 1, copy.attachments.count
2469 end 2536 end
2470 2537
2471 def test_create_as_copy_should_add_relation_with_copied_issue 2538 def test_create_as_copy_should_add_relation_with_copied_issue
2472 @request.session[:user_id] = 2 2539 @request.session[:user_id] = 2
2473
2474 assert_difference 'Issue.count' do 2540 assert_difference 'Issue.count' do
2475 assert_difference 'IssueRelation.count' do 2541 assert_difference 'IssueRelation.count' do
2476 post :create, :project_id => 1, :copy_from => 1, 2542 post :create, :project_id => 1, :copy_from => 1,
2477 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2543 :issue => {:project_id => '1', :tracker_id => '3',
2478 end 2544 :status_id => '1', :subject => 'Copy'}
2479 end 2545 end
2480 copy = Issue.first(:order => 'id DESC') 2546 end
2547 copy = Issue.order('id DESC').first
2481 assert_equal 1, copy.relations.size 2548 assert_equal 1, copy.relations.size
2482 end 2549 end
2483 2550
2484 def test_create_as_copy_should_copy_subtasks 2551 def test_create_as_copy_should_copy_subtasks
2485 @request.session[:user_id] = 2 2552 @request.session[:user_id] = 2
2486 issue = Issue.generate_with_descendants! 2553 issue = Issue.generate_with_descendants!
2487 count = issue.descendants.count 2554 count = issue.descendants.count
2488 2555 assert_difference 'Issue.count', count + 1 do
2489 assert_difference 'Issue.count', count+1 do 2556 assert_difference 'Journal.count', (count + 1) * 2 do
2490 assert_no_difference 'Journal.count' do
2491 post :create, :project_id => 1, :copy_from => issue.id, 2557 post :create, :project_id => 1, :copy_from => issue.id,
2492 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}, 2558 :issue => {:project_id => '1', :tracker_id => '3',
2559 :status_id => '1', :subject => 'Copy with subtasks'},
2493 :copy_subtasks => '1' 2560 :copy_subtasks => '1'
2494 end 2561 end
2495 end 2562 end
2496 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2563 copy = Issue.where(:parent_id => nil).order('id DESC').first
2497 assert_equal count, copy.descendants.count 2564 assert_equal count, copy.descendants.count
2498 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort 2565 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2499 end 2566 end
2500 2567
2501 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks 2568 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2502 @request.session[:user_id] = 2 2569 @request.session[:user_id] = 2
2503 issue = Issue.generate_with_descendants! 2570 issue = Issue.generate_with_descendants!
2504
2505 assert_difference 'Issue.count', 1 do 2571 assert_difference 'Issue.count', 1 do
2506 assert_no_difference 'Journal.count' do 2572 assert_difference 'Journal.count', 2 do
2507 post :create, :project_id => 1, :copy_from => 3, 2573 post :create, :project_id => 1, :copy_from => 3,
2508 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'} 2574 :issue => {:project_id => '1', :tracker_id => '3',
2509 end 2575 :status_id => '1', :subject => 'Copy with subtasks'}
2510 end 2576 end
2511 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2577 end
2578 copy = Issue.where(:parent_id => nil).order('id DESC').first
2512 assert_equal 0, copy.descendants.count 2579 assert_equal 0, copy.descendants.count
2513 end 2580 end
2514 2581
2515 def test_create_as_copy_with_failure 2582 def test_create_as_copy_with_failure
2516 @request.session[:user_id] = 2 2583 @request.session[:user_id] = 2
2521 assert_template 'new' 2588 assert_template 'new'
2522 2589
2523 assert_not_nil assigns(:issue) 2590 assert_not_nil assigns(:issue)
2524 assert assigns(:issue).copy? 2591 assert assigns(:issue).copy?
2525 2592
2526 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} 2593 assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do
2527 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 2594 assert_select 'select[name=?]', 'issue[project_id]' do
2528 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2595 assert_select 'option[value=1]:not([selected])', :text => 'eCookbook'
2529 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'} 2596 assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore'
2530 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2597 end
2531 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'} 2598 assert_select 'input[name=copy_from][value=1]'
2532 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} 2599 end
2533 end 2600 end
2534 2601
2535 def test_create_as_copy_on_project_without_permission_should_ignore_target_project 2602 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2536 @request.session[:user_id] = 2 2603 @request.session[:user_id] = 2
2537 assert !User.find(2).member_of?(Project.find(4)) 2604 assert !User.find(2).member_of?(Project.find(4))
2538 2605
2539 assert_difference 'Issue.count' do 2606 assert_difference 'Issue.count' do
2540 post :create, :project_id => 1, :copy_from => 1, 2607 post :create, :project_id => 1, :copy_from => 1,
2541 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2608 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2542 end 2609 end
2543 issue = Issue.first(:order => 'id DESC') 2610 issue = Issue.order('id DESC').first
2544 assert_equal 1, issue.project_id 2611 assert_equal 1, issue.project_id
2545 end 2612 end
2546 2613
2547 def test_get_edit 2614 def test_get_edit
2548 @request.session[:user_id] = 2 2615 @request.session[:user_id] = 2
2552 assert_not_nil assigns(:issue) 2619 assert_not_nil assigns(:issue)
2553 assert_equal Issue.find(1), assigns(:issue) 2620 assert_equal Issue.find(1), assigns(:issue)
2554 2621
2555 # Be sure we don't display inactive IssuePriorities 2622 # Be sure we don't display inactive IssuePriorities
2556 assert ! IssuePriority.find(15).active? 2623 assert ! IssuePriority.find(15).active?
2557 assert_no_tag :option, :attributes => {:value => '15'}, 2624 assert_select 'select[name=?]', 'issue[priority_id]' do
2558 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 2625 assert_select 'option[value=15]', 0
2626 end
2559 end 2627 end
2560 2628
2561 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission 2629 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2562 @request.session[:user_id] = 2 2630 @request.session[:user_id] = 2
2563 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] 2631 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2564 2632
2565 get :edit, :id => 1 2633 get :edit, :id => 1
2566 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'} 2634 assert_select 'input[name=?]', 'time_entry[hours]'
2567 end 2635 end
2568 2636
2569 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission 2637 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2570 @request.session[:user_id] = 2 2638 @request.session[:user_id] = 2
2571 Role.find_by_name('Manager').remove_permission! :log_time 2639 Role.find_by_name('Manager').remove_permission! :log_time
2572 2640
2573 get :edit, :id => 1 2641 get :edit, :id => 1
2574 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'} 2642 assert_select 'input[name=?]', 'time_entry[hours]', 0
2575 end 2643 end
2576 2644
2577 def test_get_edit_with_params 2645 def test_get_edit_with_params
2578 @request.session[:user_id] = 2 2646 @request.session[:user_id] = 2
2579 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, 2647 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2580 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } 2648 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
2581 assert_response :success 2649 assert_response :success
2582 assert_template 'edit' 2650 assert_template 'edit'
2583 2651
2584 issue = assigns(:issue) 2652 issue = assigns(:issue)
2585 assert_not_nil issue 2653 assert_not_nil issue
2586 2654
2587 assert_equal 5, issue.status_id 2655 assert_equal 5, issue.status_id
2588 assert_tag :select, :attributes => { :name => 'issue[status_id]' }, 2656 assert_select 'select[name=?]', 'issue[status_id]' do
2589 :child => { :tag => 'option', 2657 assert_select 'option[value=5][selected=selected]', :text => 'Closed'
2590 :content => 'Closed', 2658 end
2591 :attributes => { :selected => 'selected' } }
2592 2659
2593 assert_equal 7, issue.priority_id 2660 assert_equal 7, issue.priority_id
2594 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, 2661 assert_select 'select[name=?]', 'issue[priority_id]' do
2595 :child => { :tag => 'option', 2662 assert_select 'option[value=7][selected=selected]', :text => 'Urgent'
2596 :content => 'Urgent', 2663 end
2597 :attributes => { :selected => 'selected' } } 2664
2598 2665 assert_select 'input[name=?][value=2.5]', 'time_entry[hours]'
2599 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } 2666 assert_select 'select[name=?]', 'time_entry[activity_id]' do
2600 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, 2667 assert_select 'option[value=10][selected=selected]', :text => 'Development'
2601 :child => { :tag => 'option', 2668 end
2602 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } 2669 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
2603 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2604 end 2670 end
2605 2671
2606 def test_get_edit_with_multi_custom_field 2672 def test_get_edit_with_multi_custom_field
2607 field = CustomField.find(1) 2673 field = CustomField.find(1)
2608 field.update_attribute :multiple, true 2674 field.update_attribute :multiple, true
2613 @request.session[:user_id] = 2 2679 @request.session[:user_id] = 2
2614 get :edit, :id => 1 2680 get :edit, :id => 1
2615 assert_response :success 2681 assert_response :success
2616 assert_template 'edit' 2682 assert_template 'edit'
2617 2683
2618 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'} 2684 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
2619 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2685 assert_select 'option', 3
2620 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}} 2686 assert_select 'option[value=MySQL][selected=selected]'
2621 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2687 assert_select 'option[value=Oracle][selected=selected]'
2622 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}} 2688 assert_select 'option[value=PostgreSQL]:not([selected])'
2623 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2689 end
2624 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}} 2690 end
2625 end 2691
2626 2692 def test_update_form_for_existing_issue
2627 def test_update_edit_form 2693 @request.session[:user_id] = 2
2628 @request.session[:user_id] = 2 2694 xhr :put, :update_form, :project_id => 1,
2629 xhr :put, :new, :project_id => 1,
2630 :id => 1, 2695 :id => 1,
2631 :issue => {:tracker_id => 2, 2696 :issue => {:tracker_id => 2,
2632 :subject => 'This is the test_new issue', 2697 :subject => 'This is the test_new issue',
2633 :description => 'This is the description', 2698 :description => 'This is the description',
2634 :priority_id => 5} 2699 :priority_id => 5}
2635 assert_response :success 2700 assert_response :success
2636 assert_equal 'text/javascript', response.content_type 2701 assert_equal 'text/javascript', response.content_type
2637 assert_template 'update_form' 2702 assert_template 'update_form'
2638 assert_template 'form' 2703 assert_template :partial => '_form'
2639 2704
2640 issue = assigns(:issue) 2705 issue = assigns(:issue)
2641 assert_kind_of Issue, issue 2706 assert_kind_of Issue, issue
2642 assert_equal 1, issue.id 2707 assert_equal 1, issue.id
2643 assert_equal 1, issue.project_id 2708 assert_equal 1, issue.project_id
2644 assert_equal 2, issue.tracker_id 2709 assert_equal 2, issue.tracker_id
2645 assert_equal 'This is the test_new issue', issue.subject 2710 assert_equal 'This is the test_new issue', issue.subject
2646 end 2711 end
2647 2712
2648 def test_update_edit_form_should_keep_issue_author 2713 def test_update_form_for_existing_issue_should_keep_issue_author
2649 @request.session[:user_id] = 3 2714 @request.session[:user_id] = 3
2650 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} 2715 xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2651 assert_response :success 2716 assert_response :success
2652 assert_equal 'text/javascript', response.content_type 2717 assert_equal 'text/javascript', response.content_type
2653 2718
2654 issue = assigns(:issue) 2719 issue = assigns(:issue)
2655 assert_equal User.find(2), issue.author 2720 assert_equal User.find(2), issue.author
2656 assert_equal 2, issue.author_id 2721 assert_equal 2, issue.author_id
2657 assert_not_equal User.current, issue.author 2722 assert_not_equal User.current, issue.author
2658 end 2723 end
2659 2724
2660 def test_update_edit_form_should_propose_transitions_based_on_initial_status 2725 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
2661 @request.session[:user_id] = 2 2726 @request.session[:user_id] = 2
2662 WorkflowTransition.delete_all 2727 WorkflowTransition.delete_all
2663 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) 2728 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2664 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) 2729 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2665 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) 2730 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2666 2731
2667 xhr :put, :new, :project_id => 1, 2732 xhr :put, :update_form, :project_id => 1,
2668 :id => 2, 2733 :id => 2,
2669 :issue => {:tracker_id => 2, 2734 :issue => {:tracker_id => 2,
2670 :status_id => 5, 2735 :status_id => 5,
2671 :subject => 'This is an issue'} 2736 :subject => 'This is an issue'}
2672 2737
2673 assert_equal 5, assigns(:issue).status_id 2738 assert_equal 5, assigns(:issue).status_id
2674 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort 2739 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2675 end 2740 end
2676 2741
2677 def test_update_edit_form_with_project_change 2742 def test_update_form_for_existing_issue_with_project_change
2678 @request.session[:user_id] = 2 2743 @request.session[:user_id] = 2
2679 xhr :put, :new, :project_id => 1, 2744 xhr :put, :update_form, :project_id => 1,
2680 :id => 1, 2745 :id => 1,
2681 :issue => {:project_id => 2, 2746 :issue => {:project_id => 2,
2682 :tracker_id => 2, 2747 :tracker_id => 2,
2683 :subject => 'This is the test_new issue', 2748 :subject => 'This is the test_new issue',
2684 :description => 'This is the description', 2749 :description => 'This is the description',
2685 :priority_id => 5} 2750 :priority_id => 5}
2686 assert_response :success 2751 assert_response :success
2687 assert_template 'form' 2752 assert_template :partial => '_form'
2688 2753
2689 issue = assigns(:issue) 2754 issue = assigns(:issue)
2690 assert_kind_of Issue, issue 2755 assert_kind_of Issue, issue
2691 assert_equal 1, issue.id 2756 assert_equal 1, issue.id
2692 assert_equal 2, issue.project_id 2757 assert_equal 2, issue.project_id
2693 assert_equal 2, issue.tracker_id 2758 assert_equal 2, issue.tracker_id
2694 assert_equal 'This is the test_new issue', issue.subject 2759 assert_equal 'This is the test_new issue', issue.subject
2760 end
2761
2762 def test_update_form_should_propose_default_status_for_existing_issue
2763 @request.session[:user_id] = 2
2764 WorkflowTransition.delete_all
2765 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2766
2767 xhr :put, :update_form, :project_id => 1, :id => 2
2768 assert_response :success
2769 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
2695 end 2770 end
2696 2771
2697 def test_put_update_without_custom_fields_param 2772 def test_put_update_without_custom_fields_param
2698 @request.session[:user_id] = 2 2773 @request.session[:user_id] = 2
2699 ActionMailer::Base.deliveries.clear 2774 ActionMailer::Base.deliveries.clear
2829 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } 2904 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2830 end 2905 end
2831 assert_redirected_to :action => 'show', :id => '1' 2906 assert_redirected_to :action => 'show', :id => '1'
2832 issue.reload 2907 issue.reload
2833 assert_equal 2, issue.status_id 2908 assert_equal 2, issue.status_id
2834 j = Journal.find(:first, :order => 'id DESC') 2909 j = Journal.order('id DESC').first
2835 assert_equal 'Assigned to dlopper', j.notes 2910 assert_equal 'Assigned to dlopper', j.notes
2836 assert_equal 2, j.details.size 2911 assert_equal 2, j.details.size
2837 2912
2838 mail = ActionMailer::Base.deliveries.last 2913 mail = ActionMailer::Base.deliveries.last
2839 assert_mail_body_match "Status changed from New to Assigned", mail 2914 assert_mail_body_match "Status changed from New to Assigned", mail
2846 # anonymous user 2921 # anonymous user
2847 put :update, 2922 put :update,
2848 :id => 1, 2923 :id => 1,
2849 :issue => { :notes => notes } 2924 :issue => { :notes => notes }
2850 assert_redirected_to :action => 'show', :id => '1' 2925 assert_redirected_to :action => 'show', :id => '1'
2851 j = Journal.find(:first, :order => 'id DESC') 2926 j = Journal.order('id DESC').first
2852 assert_equal notes, j.notes 2927 assert_equal notes, j.notes
2853 assert_equal 0, j.details.size 2928 assert_equal 0, j.details.size
2854 assert_equal User.anonymous, j.user 2929 assert_equal User.anonymous, j.user
2855 2930
2856 mail = ActionMailer::Base.deliveries.last 2931 mail = ActionMailer::Base.deliveries.last
2902 end 2977 end
2903 assert_redirected_to :action => 'show', :id => '1' 2978 assert_redirected_to :action => 'show', :id => '1'
2904 2979
2905 issue = Issue.find(1) 2980 issue = Issue.find(1)
2906 2981
2907 j = Journal.find(:first, :order => 'id DESC') 2982 j = Journal.order('id DESC').first
2908 assert_equal '2.5 hours added', j.notes 2983 assert_equal '2.5 hours added', j.notes
2909 assert_equal 0, j.details.size 2984 assert_equal 0, j.details.size
2910 2985
2911 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') 2986 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2912 assert_not_nil t 2987 assert_not_nil t
2941 :issue => {:notes => ''}, 3016 :issue => {:notes => ''},
2942 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 3017 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2943 end 3018 end
2944 3019
2945 assert_redirected_to :action => 'show', :id => '1' 3020 assert_redirected_to :action => 'show', :id => '1'
2946 j = Issue.find(1).journals.find(:first, :order => 'id DESC') 3021 j = Issue.find(1).journals.reorder('id DESC').first
2947 assert j.notes.blank? 3022 assert j.notes.blank?
2948 assert_equal 1, j.details.size 3023 assert_equal 1, j.details.size
2949 assert_equal 'testfile.txt', j.details.first.value 3024 assert_equal 'testfile.txt', j.details.first.value
2950 assert_equal User.anonymous, j.user 3025 assert_equal User.anonymous, j.user
2951 3026
2952 attachment = Attachment.first(:order => 'id DESC') 3027 attachment = Attachment.order('id DESC').first
2953 assert_equal Issue.find(1), attachment.container 3028 assert_equal Issue.find(1), attachment.container
2954 assert_equal User.anonymous, attachment.author 3029 assert_equal User.anonymous, attachment.author
2955 assert_equal 'testfile.txt', attachment.filename 3030 assert_equal 'testfile.txt', attachment.filename
2956 assert_equal 'text/plain', attachment.content_type 3031 assert_equal 'text/plain', attachment.content_type
2957 assert_equal 'test file', attachment.description 3032 assert_equal 'test file', attachment.description
2975 assert_response :success 3050 assert_response :success
2976 assert_template 'edit' 3051 assert_template 'edit'
2977 end 3052 end
2978 end 3053 end
2979 3054
2980 attachment = Attachment.first(:order => 'id DESC') 3055 attachment = Attachment.order('id DESC').first
2981 assert_equal 'testfile.txt', attachment.filename 3056 assert_equal 'testfile.txt', attachment.filename
2982 assert File.exists?(attachment.diskfile) 3057 assert File.exists?(attachment.diskfile)
2983 assert_nil attachment.container 3058 assert_nil attachment.container
2984 3059
2985 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 3060 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2986 assert_tag 'span', :content => /testfile.txt/ 3061 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2987 end 3062 end
2988 3063
2989 def test_put_update_with_failure_should_keep_saved_attachments 3064 def test_put_update_with_failure_should_keep_saved_attachments
2990 set_tmp_attachments_directory 3065 set_tmp_attachments_directory
2991 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 3066 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2999 assert_response :success 3074 assert_response :success
3000 assert_template 'edit' 3075 assert_template 'edit'
3001 end 3076 end
3002 end 3077 end
3003 3078
3004 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 3079 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3005 assert_tag 'span', :content => /testfile.txt/ 3080 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3006 end 3081 end
3007 3082
3008 def test_put_update_should_attach_saved_attachments 3083 def test_put_update_should_attach_saved_attachments
3009 set_tmp_attachments_directory 3084 set_tmp_attachments_directory
3010 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 3085 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3022 end 3097 end
3023 3098
3024 attachment.reload 3099 attachment.reload
3025 assert_equal Issue.find(1), attachment.container 3100 assert_equal Issue.find(1), attachment.container
3026 3101
3027 journal = Journal.first(:order => 'id DESC') 3102 journal = Journal.order('id DESC').first
3028 assert_equal 1, journal.details.size 3103 assert_equal 1, journal.details.size
3029 assert_equal 'testfile.txt', journal.details.first.value 3104 assert_equal 'testfile.txt', journal.details.first.value
3030 end 3105 end
3031 3106
3032 def test_put_update_with_attachment_that_fails_to_save 3107 def test_put_update_with_attachment_that_fails_to_save
3089 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} 3164 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3090 end 3165 end
3091 assert_response :success 3166 assert_response :success
3092 assert_template 'edit' 3167 assert_template 'edit'
3093 3168
3094 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3169 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
3095 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes 3170 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3096 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } 3171 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3097 end 3172 end
3098 3173
3099 def test_put_update_with_invalid_spent_time_comments_only 3174 def test_put_update_with_invalid_spent_time_comments_only
3100 @request.session[:user_id] = 2 3175 @request.session[:user_id] = 2
3101 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' 3176 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3107 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} 3182 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3108 end 3183 end
3109 assert_response :success 3184 assert_response :success
3110 assert_template 'edit' 3185 assert_template 'edit'
3111 3186
3112 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3187 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
3113 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/} 3188 assert_error_tag :descendant => {:content => /Hours #{ESCAPED_CANT} be blank/}
3114 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes 3189 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3115 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } 3190 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3116 end 3191 end
3117 3192
3118 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject 3193 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3119 issue = Issue.find(2) 3194 issue = Issue.find(2)
3120 @request.session[:user_id] = 2 3195 @request.session[:user_id] = 2
3165 @request.session[:user_id] = 2 3240 @request.session[:user_id] = 2
3166 get :bulk_edit, :ids => [1, 2] 3241 get :bulk_edit, :ids => [1, 2]
3167 assert_response :success 3242 assert_response :success
3168 assert_template 'bulk_edit' 3243 assert_template 'bulk_edit'
3169 3244
3170 assert_tag :select, :attributes => {:name => 'issue[project_id]'} 3245 assert_select 'ul#bulk-selection' do
3171 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} 3246 assert_select 'li', 2
3172 3247 assert_select 'li a', :text => 'Bug #1'
3173 # Project specific custom field, date type 3248 end
3174 field = CustomField.find(9) 3249
3175 assert !field.is_for_all? 3250 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3176 assert_equal 'date', field.field_format 3251 assert_select 'input[name=?]', 'ids[]', 2
3177 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} 3252 assert_select 'input[name=?][value=1][type=hidden]', 'ids[]'
3178 3253
3179 # System wide custom field 3254 assert_select 'select[name=?]', 'issue[project_id]'
3180 assert CustomField.find(1).is_for_all? 3255 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3181 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} 3256
3182 3257 # Project specific custom field, date type
3183 # Be sure we don't display inactive IssuePriorities 3258 field = CustomField.find(9)
3184 assert ! IssuePriority.find(15).active? 3259 assert !field.is_for_all?
3185 assert_no_tag :option, :attributes => {:value => '15'}, 3260 assert_equal 'date', field.field_format
3186 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 3261 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3262
3263 # System wide custom field
3264 assert CustomField.find(1).is_for_all?
3265 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3266
3267 # Be sure we don't display inactive IssuePriorities
3268 assert ! IssuePriority.find(15).active?
3269 assert_select 'select[name=?]', 'issue[priority_id]' do
3270 assert_select 'option[value=15]', 0
3271 end
3272 end
3187 end 3273 end
3188 3274
3189 def test_get_bulk_edit_on_different_projects 3275 def test_get_bulk_edit_on_different_projects
3190 @request.session[:user_id] = 2 3276 @request.session[:user_id] = 2
3191 get :bulk_edit, :ids => [1, 2, 6] 3277 get :bulk_edit, :ids => [1, 2, 6]
3192 assert_response :success 3278 assert_response :success
3193 assert_template 'bulk_edit' 3279 assert_template 'bulk_edit'
3194 3280
3195 # Can not set issues from different projects as children of an issue 3281 # Can not set issues from different projects as children of an issue
3196 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} 3282 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3197 3283
3198 # Project specific custom field, date type 3284 # Project specific custom field, date type
3199 field = CustomField.find(9) 3285 field = CustomField.find(9)
3200 assert !field.is_for_all? 3286 assert !field.is_for_all?
3201 assert !field.project_ids.include?(Issue.find(6).project_id) 3287 assert !field.project_ids.include?(Issue.find(6).project_id)
3202 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} 3288 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3203 end 3289 end
3204 3290
3205 def test_get_bulk_edit_with_user_custom_field 3291 def test_get_bulk_edit_with_user_custom_field
3206 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) 3292 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3207 3293
3208 @request.session[:user_id] = 2 3294 @request.session[:user_id] = 2
3209 get :bulk_edit, :ids => [1, 2] 3295 get :bulk_edit, :ids => [1, 2]
3210 assert_response :success 3296 assert_response :success
3211 assert_template 'bulk_edit' 3297 assert_template 'bulk_edit'
3212 3298
3213 assert_tag :select, 3299 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3214 :attributes => {:name => "issue[custom_field_values][#{field.id}]", :class => 'user_cf'}, 3300 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3215 :children => { 3301 end
3216 :only => {:tag => 'option'},
3217 :count => Project.find(1).users.count + 2 # "no change" + "none" options
3218 }
3219 end 3302 end
3220 3303
3221 def test_get_bulk_edit_with_version_custom_field 3304 def test_get_bulk_edit_with_version_custom_field
3222 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) 3305 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3223 3306
3224 @request.session[:user_id] = 2 3307 @request.session[:user_id] = 2
3225 get :bulk_edit, :ids => [1, 2] 3308 get :bulk_edit, :ids => [1, 2]
3226 assert_response :success 3309 assert_response :success
3227 assert_template 'bulk_edit' 3310 assert_template 'bulk_edit'
3228 3311
3229 assert_tag :select, 3312 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3230 :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, 3313 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3231 :children => { 3314 end
3232 :only => {:tag => 'option'},
3233 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3234 }
3235 end 3315 end
3236 3316
3237 def test_get_bulk_edit_with_multi_custom_field 3317 def test_get_bulk_edit_with_multi_custom_field
3238 field = CustomField.find(1) 3318 field = CustomField.find(1)
3239 field.update_attribute :multiple, true 3319 field.update_attribute :multiple, true
3241 @request.session[:user_id] = 2 3321 @request.session[:user_id] = 2
3242 get :bulk_edit, :ids => [1, 2] 3322 get :bulk_edit, :ids => [1, 2]
3243 assert_response :success 3323 assert_response :success
3244 assert_template 'bulk_edit' 3324 assert_template 'bulk_edit'
3245 3325
3246 assert_tag :select, 3326 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3247 :attributes => {:name => "issue[custom_field_values][1][]"}, 3327 assert_select 'option', field.possible_values.size + 1 # "none" options
3248 :children => { 3328 end
3249 :only => {:tag => 'option'}, 3329 end
3250 :count => field.possible_values.size + 1 # "none" options 3330
3251 } 3331 def test_bulk_edit_should_propose_to_clear_text_custom_fields
3332 @request.session[:user_id] = 2
3333 get :bulk_edit, :ids => [1, 3]
3334 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
3252 end 3335 end
3253 3336
3254 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues 3337 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3255 WorkflowTransition.delete_all 3338 WorkflowTransition.delete_all
3256 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) 3339 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3257 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) 3340 :old_status_id => 1, :new_status_id => 1)
3258 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) 3341 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3259 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) 3342 :old_status_id => 1, :new_status_id => 3)
3260 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3) 3343 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
3261 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) 3344 :old_status_id => 1, :new_status_id => 4)
3345 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3346 :old_status_id => 2, :new_status_id => 1)
3347 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3348 :old_status_id => 2, :new_status_id => 3)
3349 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3350 :old_status_id => 2, :new_status_id => 5)
3262 @request.session[:user_id] = 2 3351 @request.session[:user_id] = 2
3263 get :bulk_edit, :ids => [1, 2] 3352 get :bulk_edit, :ids => [1, 2]
3264 3353
3265 assert_response :success 3354 assert_response :success
3266 statuses = assigns(:available_statuses) 3355 statuses = assigns(:available_statuses)
3267 assert_not_nil statuses 3356 assert_not_nil statuses
3268 assert_equal [1, 3], statuses.map(&:id).sort 3357 assert_equal [1, 3], statuses.map(&:id).sort
3269 3358
3270 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}, 3359 assert_select 'select[name=?]', 'issue[status_id]' do
3271 :children => {:count => 3} # 2 statuses + "no change" option 3360 assert_select 'option', 3 # 2 statuses + "no change" option
3361 end
3272 end 3362 end
3273 3363
3274 def test_bulk_edit_should_propose_target_project_open_shared_versions 3364 def test_bulk_edit_should_propose_target_project_open_shared_versions
3275 @request.session[:user_id] = 2 3365 @request.session[:user_id] = 2
3276 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} 3366 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3277 assert_response :success 3367 assert_response :success
3278 assert_template 'bulk_edit' 3368 assert_template 'bulk_edit'
3279 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort 3369 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3280 assert_tag 'select', 3370
3281 :attributes => {:name => 'issue[fixed_version_id]'}, 3371 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3282 :descendant => {:tag => 'option', :content => '2.0'} 3372 assert_select 'option', :text => '2.0'
3373 end
3283 end 3374 end
3284 3375
3285 def test_bulk_edit_should_propose_target_project_categories 3376 def test_bulk_edit_should_propose_target_project_categories
3286 @request.session[:user_id] = 2 3377 @request.session[:user_id] = 2
3287 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} 3378 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3288 assert_response :success 3379 assert_response :success
3289 assert_template 'bulk_edit' 3380 assert_template 'bulk_edit'
3290 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort 3381 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3291 assert_tag 'select', 3382
3292 :attributes => {:name => 'issue[category_id]'}, 3383 assert_select 'select[name=?]', 'issue[category_id]' do
3293 :descendant => {:tag => 'option', :content => 'Recipes'} 3384 assert_select 'option', :text => 'Recipes'
3385 end
3294 end 3386 end
3295 3387
3296 def test_bulk_update 3388 def test_bulk_update
3297 @request.session[:user_id] = 2 3389 @request.session[:user_id] = 2
3298 # update issues priority 3390 # update issues priority
3301 :assigned_to_id => '', 3393 :assigned_to_id => '',
3302 :custom_field_values => {'2' => ''}} 3394 :custom_field_values => {'2' => ''}}
3303 3395
3304 assert_response 302 3396 assert_response 302
3305 # check that the issues were updated 3397 # check that the issues were updated
3306 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} 3398 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
3307 3399
3308 issue = Issue.find(1) 3400 issue = Issue.find(1)
3309 journal = issue.journals.find(:first, :order => 'created_on DESC') 3401 journal = issue.journals.reorder('created_on DESC').first
3310 assert_equal '125', issue.custom_value_for(2).value 3402 assert_equal '125', issue.custom_value_for(2).value
3311 assert_equal 'Bulk editing', journal.notes 3403 assert_equal 'Bulk editing', journal.notes
3312 assert_equal 1, journal.details.size 3404 assert_equal 1, journal.details.size
3313 end 3405 end
3314 3406
3323 :issue => {:priority_id => '', 3415 :issue => {:priority_id => '',
3324 :assigned_to_id => group.id, 3416 :assigned_to_id => group.id,
3325 :custom_field_values => {'2' => ''}} 3417 :custom_field_values => {'2' => ''}}
3326 3418
3327 assert_response 302 3419 assert_response 302
3328 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} 3420 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
3329 end 3421 end
3330 3422
3331 def test_bulk_update_on_different_projects 3423 def test_bulk_update_on_different_projects
3332 @request.session[:user_id] = 2 3424 @request.session[:user_id] = 2
3333 # update issues priority 3425 # update issues priority
3339 assert_response 302 3431 assert_response 302
3340 # check that the issues were updated 3432 # check that the issues were updated
3341 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) 3433 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3342 3434
3343 issue = Issue.find(1) 3435 issue = Issue.find(1)
3344 journal = issue.journals.find(:first, :order => 'created_on DESC') 3436 journal = issue.journals.reorder('created_on DESC').first
3345 assert_equal '125', issue.custom_value_for(2).value 3437 assert_equal '125', issue.custom_value_for(2).value
3346 assert_equal 'Bulk editing', journal.notes 3438 assert_equal 'Bulk editing', journal.notes
3347 assert_equal 1, journal.details.size 3439 assert_equal 1, journal.details.size
3348 end 3440 end
3349 3441
3441 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes 3533 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3442 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes 3534 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3443 end 3535 end
3444 3536
3445 def test_bulk_update_parent_id 3537 def test_bulk_update_parent_id
3538 IssueRelation.delete_all
3446 @request.session[:user_id] = 2 3539 @request.session[:user_id] = 2
3447 post :bulk_update, :ids => [1, 3], 3540 post :bulk_update, :ids => [1, 3],
3448 :notes => 'Bulk editing parent', 3541 :notes => 'Bulk editing parent',
3449 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} 3542 :issue => {:priority_id => '', :assigned_to_id => '',
3450 3543 :status_id => '', :parent_issue_id => '2'}
3451 assert_response 302 3544 assert_response 302
3452 parent = Issue.find(2) 3545 parent = Issue.find(2)
3453 assert_equal parent.id, Issue.find(1).parent_id 3546 assert_equal parent.id, Issue.find(1).parent_id
3454 assert_equal parent.id, Issue.find(3).parent_id 3547 assert_equal parent.id, Issue.find(3).parent_id
3455 assert_equal [1, 3], parent.children.collect(&:id).sort 3548 assert_equal [1, 3], parent.children.collect(&:id).sort
3464 :custom_field_values => {'2' => '777'}} 3557 :custom_field_values => {'2' => '777'}}
3465 3558
3466 assert_response 302 3559 assert_response 302
3467 3560
3468 issue = Issue.find(1) 3561 issue = Issue.find(1)
3469 journal = issue.journals.find(:first, :order => 'created_on DESC') 3562 journal = issue.journals.reorder('created_on DESC').first
3470 assert_equal '777', issue.custom_value_for(2).value 3563 assert_equal '777', issue.custom_value_for(2).value
3471 assert_equal 1, journal.details.size 3564 assert_equal 1, journal.details.size
3472 assert_equal '125', journal.details.first.old_value 3565 assert_equal '125', journal.details.first.old_value
3473 assert_equal '777', journal.details.first.value 3566 assert_equal '777', journal.details.first.value
3474 end 3567 end
3553 3646
3554 assert_response :redirect 3647 assert_response :redirect
3555 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier 3648 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3556 end 3649 end
3557 3650
3558 def test_bulk_update_with_failure_should_set_flash 3651 def test_bulk_update_with_all_failures_should_show_errors
3559 @request.session[:user_id] = 2 3652 @request.session[:user_id] = 2
3560 Issue.update_all("subject = ''", "id = 2") # Make it invalid 3653 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
3561 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} 3654
3562 3655 assert_response :success
3563 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' 3656 assert_template 'bulk_edit'
3564 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error] 3657 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
3658 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
3659
3660 assert_equal [1, 2], assigns[:issues].map(&:id)
3661 end
3662
3663 def test_bulk_update_with_some_failures_should_show_errors
3664 issue1 = Issue.generate!(:start_date => '2013-05-12')
3665 issue2 = Issue.generate!(:start_date => '2013-05-15')
3666 issue3 = Issue.generate!
3667 @request.session[:user_id] = 2
3668 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
3669 :issue => {:due_date => '2013-05-01'}
3670 assert_response :success
3671 assert_template 'bulk_edit'
3672 assert_select '#errorExplanation span',
3673 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
3674 assert_select '#errorExplanation ul li',
3675 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
3676 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
3677 end
3678
3679 def test_bulk_update_with_failure_should_preserved_form_values
3680 @request.session[:user_id] = 2
3681 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
3682
3683 assert_response :success
3684 assert_template 'bulk_edit'
3685 assert_select 'select[name=?]', 'issue[tracker_id]' do
3686 assert_select 'option[value=2][selected=selected]'
3687 end
3688 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
3565 end 3689 end
3566 3690
3567 def test_get_bulk_copy 3691 def test_get_bulk_copy
3568 @request.session[:user_id] = 2 3692 @request.session[:user_id] = 2
3569 get :bulk_edit, :ids => [1, 2, 3], :copy => '1' 3693 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3584 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' 3708 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3585 end 3709 end
3586 end 3710 end
3587 assert_redirected_to '/projects/ecookbook/issues' 3711 assert_redirected_to '/projects/ecookbook/issues'
3588 3712
3589 copies = Issue.all(:order => 'id DESC', :limit => issues.size) 3713 copies = Issue.order('id DESC').limit(issues.size)
3590 copies.each do |copy| 3714 copies.each do |copy|
3591 assert_equal 2, copy.project_id 3715 assert_equal 2, copy.project_id
3592 end 3716 end
3593 end 3717 end
3594 3718
3595 def test_bulk_copy_should_allow_not_changing_the_issue_attributes 3719 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3596 @request.session[:user_id] = 2 3720 @request.session[:user_id] = 2
3597 issues = [ 3721 issues = [
3598 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil), 3722 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
3599 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3) 3723 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
3724 :assigned_to_id => nil),
3725 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
3726 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
3727 :assigned_to_id => 3)
3600 ] 3728 ]
3601
3602 assert_difference 'Issue.count', issues.size do 3729 assert_difference 'Issue.count', issues.size do
3603 post :bulk_update, :ids => issues.map(&:id), :copy => '1', 3730 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3604 :issue => { 3731 :issue => {
3605 :project_id => '', :tracker_id => '', :assigned_to_id => '', 3732 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3606 :status_id => '', :start_date => '', :due_date => '' 3733 :status_id => '', :start_date => '', :due_date => ''
3607 } 3734 }
3608 end 3735 end
3609 3736
3610 copies = Issue.all(:order => 'id DESC', :limit => issues.size) 3737 copies = Issue.order('id DESC').limit(issues.size)
3611 issues.each do |orig| 3738 issues.each do |orig|
3612 copy = copies.detect {|c| c.subject == orig.subject} 3739 copy = copies.detect {|c| c.subject == orig.subject}
3613 assert_not_nil copy 3740 assert_not_nil copy
3614 assert_equal orig.project_id, copy.project_id 3741 assert_equal orig.project_id, copy.project_id
3615 assert_equal orig.tracker_id, copy.tracker_id 3742 assert_equal orig.tracker_id, copy.tracker_id
3619 end 3746 end
3620 end 3747 end
3621 3748
3622 def test_bulk_copy_should_allow_changing_the_issue_attributes 3749 def test_bulk_copy_should_allow_changing_the_issue_attributes
3623 # Fixes random test failure with Mysql 3750 # Fixes random test failure with Mysql
3624 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) 3751 # where Issue.where(:project_id => 2).limit(2).order('id desc')
3625 # doesn't return the expected results 3752 # doesn't return the expected results
3626 Issue.delete_all("project_id=2") 3753 Issue.delete_all("project_id=2")
3627 3754
3628 @request.session[:user_id] = 2 3755 @request.session[:user_id] = 2
3629 assert_difference 'Issue.count', 2 do 3756 assert_difference 'Issue.count', 2 do
3634 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' 3761 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3635 } 3762 }
3636 end 3763 end
3637 end 3764 end
3638 3765
3639 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) 3766 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
3640 assert_equal 2, copied_issues.size 3767 assert_equal 2, copied_issues.size
3641 copied_issues.each do |issue| 3768 copied_issues.each do |issue|
3642 assert_equal 2, issue.project_id, "Project is incorrect" 3769 assert_equal 2, issue.project_id, "Project is incorrect"
3643 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" 3770 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3644 assert_equal 1, issue.status_id, "Status is incorrect" 3771 assert_equal 1, issue.status_id, "Status is incorrect"
3655 :issue => { 3782 :issue => {
3656 :project_id => '', :tracker_id => '', :assigned_to_id => '4', 3783 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3657 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' 3784 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3658 } 3785 }
3659 end 3786 end
3660 3787 issue = Issue.order('id DESC').first
3661 issue = Issue.first(:order => 'id DESC')
3662 assert_equal 1, issue.journals.size 3788 assert_equal 1, issue.journals.size
3663 journal = issue.journals.first 3789 journal = issue.journals.first
3664 assert_equal 0, journal.details.size 3790 assert_equal 1, journal.details.size
3665 assert_equal 'Copying one issue', journal.notes 3791 assert_equal 'Copying one issue', journal.notes
3666 end 3792 end
3667 3793
3668 def test_bulk_copy_should_allow_not_copying_the_attachments 3794 def test_bulk_copy_should_allow_not_copying_the_attachments
3669 attachment_count = Issue.find(3).attachments.size 3795 attachment_count = Issue.find(3).attachments.size
3751 end 3877 end
3752 3878
3753 def test_bulk_copy_to_another_project_should_follow_when_needed 3879 def test_bulk_copy_to_another_project_should_follow_when_needed
3754 @request.session[:user_id] = 2 3880 @request.session[:user_id] = 2
3755 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' 3881 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3756 issue = Issue.first(:order => 'id DESC') 3882 issue = Issue.order('id DESC').first
3757 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue 3883 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3884 end
3885
3886 def test_bulk_copy_with_all_failures_should_display_errors
3887 @request.session[:user_id] = 2
3888 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
3889
3890 assert_response :success
3758 end 3891 end
3759 3892
3760 def test_destroy_issue_with_no_time_entries 3893 def test_destroy_issue_with_no_time_entries
3761 assert_nil TimeEntry.find_by_issue_id(2) 3894 assert_nil TimeEntry.find_by_issue_id(2)
3762 @request.session[:user_id] = 2 3895 @request.session[:user_id] = 2
3776 end 3909 end
3777 assert_response :success 3910 assert_response :success
3778 assert_template 'destroy' 3911 assert_template 'destroy'
3779 assert_not_nil assigns(:hours) 3912 assert_not_nil assigns(:hours)
3780 assert Issue.find_by_id(1) && Issue.find_by_id(3) 3913 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3781 assert_tag 'form', 3914
3782 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}} 3915 assert_select 'form' do
3916 assert_select 'input[name=_method][value=delete]'
3917 end
3783 end 3918 end
3784 3919
3785 def test_destroy_issues_and_destroy_time_entries 3920 def test_destroy_issues_and_destroy_time_entries
3786 @request.session[:user_id] = 2 3921 @request.session[:user_id] = 2
3787 3922
3843 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' 3978 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3844 end 3979 end
3845 assert_response 302 3980 assert_response 302
3846 end 3981 end
3847 3982
3983 def test_destroy_invalid_should_respond_with_404
3984 @request.session[:user_id] = 2
3985 assert_no_difference 'Issue.count' do
3986 delete :destroy, :id => 999
3987 end
3988 assert_response 404
3989 end
3990
3848 def test_default_search_scope 3991 def test_default_search_scope
3849 get :index 3992 get :index
3850 assert_tag :div, :attributes => {:id => 'quick-search'}, 3993
3851 :child => {:tag => 'form', 3994 assert_select 'div#quick-search form' do
3852 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} 3995 assert_select 'input[name=issues][value=1][type=hidden]'
3996 end
3853 end 3997 end
3854 end 3998 end