comparison test/functional/issues_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 3e4c3460b6ca
children e248c7af89ec
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang 2 # Copyright (C) 2006-2013 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
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
382 assert_response :success 378 assert_response :success
383 assert_not_nil assigns(:issues) 379 assert_not_nil assigns(:issues)
384 assert_equal 'text/csv; header=present', @response.content_type 380 assert_equal 'text/csv; header=present', @response.content_type
385 assert @response.body.starts_with?("#,") 381 assert @response.body.starts_with?("#,")
386 lines = @response.body.chomp.split("\n") 382 lines = @response.body.chomp.split("\n")
387 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size 383 assert_equal assigns(:query).columns.size, lines[0].split(',').size
388 end 384 end
389 385
390 def test_index_csv_with_project 386 def test_index_csv_with_project
391 get :index, :project_id => 1, :format => 'csv' 387 get :index, :project_id => 1, :format => 'csv'
392 assert_response :success 388 assert_response :success
393 assert_not_nil assigns(:issues) 389 assert_not_nil assigns(:issues)
394 assert_equal 'text/csv; header=present', @response.content_type 390 assert_equal 'text/csv; header=present', @response.content_type
395 end 391 end
396 392
397 def test_index_csv_with_description 393 def test_index_csv_with_description
398 get :index, :format => 'csv', :description => '1' 394 Issue.generate!(:description => 'test_index_csv_with_description')
399 assert_response :success 395
400 assert_not_nil assigns(:issues) 396 with_settings :default_language => 'en' do
401 assert_equal 'text/csv; header=present', @response.content_type 397 get :index, :format => 'csv', :description => '1'
402 assert @response.body.starts_with?("#,") 398 assert_response :success
403 lines = @response.body.chomp.split("\n") 399 assert_not_nil assigns(:issues)
404 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size 400 end
401
402 assert_equal 'text/csv; header=present', response.content_type
403 headers = response.body.chomp.split("\n").first.split(',')
404 assert_include 'Description', headers
405 assert_include 'test_index_csv_with_description', response.body
405 end 406 end
406 407
407 def test_index_csv_with_spent_time_column 408 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) 409 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) 410 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 419 def test_index_csv_with_all_columns
419 get :index, :format => 'csv', :columns => 'all' 420 get :index, :format => 'csv', :columns => 'all'
420 assert_response :success 421 assert_response :success
421 assert_not_nil assigns(:issues) 422 assert_not_nil assigns(:issues)
422 assert_equal 'text/csv; header=present', @response.content_type 423 assert_equal 'text/csv; header=present', @response.content_type
423 assert @response.body.starts_with?("#,") 424 assert_match /\A#,/, response.body
424 lines = @response.body.chomp.split("\n") 425 lines = response.body.chomp.split("\n")
425 assert_equal assigns(:query).available_inline_columns.size + 1, lines[0].split(',').size 426 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
426 end 427 end
427 428
428 def test_index_csv_with_multi_column_field 429 def test_index_csv_with_multi_column_field
429 CustomField.find(1).update_attribute :multiple, true 430 CustomField.find(1).update_attribute :multiple, true
430 issue = Issue.find(1) 431 issue = Issue.find(1)
433 434
434 get :index, :format => 'csv', :columns => 'all' 435 get :index, :format => 'csv', :columns => 'all'
435 assert_response :success 436 assert_response :success
436 lines = @response.body.chomp.split("\n") 437 lines = @response.body.chomp.split("\n")
437 assert lines.detect {|line| line.include?('"MySQL, Oracle"')} 438 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
439 end
440
441 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
442 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
443 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
444
445 with_settings :default_language => 'fr' do
446 get :index, :format => 'csv', :columns => 'all'
447 assert_response :success
448 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
449 assert_include '185,60', issue_line
450 end
451
452 with_settings :default_language => 'en' do
453 get :index, :format => 'csv', :columns => 'all'
454 assert_response :success
455 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
456 assert_include '185.60', issue_line
457 end
438 end 458 end
439 459
440 def test_index_csv_big_5 460 def test_index_csv_big_5
441 with_settings :default_language => "zh-TW" do 461 with_settings :default_language => "zh-TW" do
442 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" 462 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
455 lines = @response.body.chomp.split("\n") 475 lines = @response.body.chomp.split("\n")
456 s1 = "\xaa\xac\xbaA" 476 s1 = "\xaa\xac\xbaA"
457 if str_utf8.respond_to?(:force_encoding) 477 if str_utf8.respond_to?(:force_encoding)
458 s1.force_encoding('Big5') 478 s1.force_encoding('Big5')
459 end 479 end
460 assert lines[0].include?(s1) 480 assert_include s1, lines[0]
461 assert lines[1].include?(str_big5) 481 assert_include str_big5, lines[1]
462 end 482 end
463 end 483 end
464 484
465 def test_index_csv_cannot_convert_should_be_replaced_big_5 485 def test_index_csv_cannot_convert_should_be_replaced_big_5
466 with_settings :default_language => "zh-TW" do 486 with_settings :default_language => "zh-TW" do
668 get :index, :set_filter => 1, :c => columns 688 get :index, :set_filter => 1, :c => columns
669 assert_response :success 689 assert_response :success
670 690
671 # query should use specified columns 691 # query should use specified columns
672 query = assigns(:query) 692 query = assigns(:query)
673 assert_kind_of Query, query 693 assert_kind_of IssueQuery, query
674 assert_equal columns, query.column_names.map(&:to_s) 694 assert_equal columns, query.column_names.map(&:to_s)
675 695
676 # columns should be stored in session 696 # columns should be stored in session
677 assert_kind_of Hash, session[:query] 697 assert_kind_of Hash, session[:query]
678 assert_kind_of Array, session[:query][:column_names] 698 assert_kind_of Array, session[:query][:column_names]
690 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] 710 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
691 get :index, :set_filter => 1 711 get :index, :set_filter => 1
692 712
693 # query should use specified columns 713 # query should use specified columns
694 query = assigns(:query) 714 query = assigns(:query)
695 assert_kind_of Query, query 715 assert_kind_of IssueQuery, query
696 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) 716 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
697 end 717 end
698 718
699 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column 719 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
700 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] 720 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
701 columns = ['tracker', 'subject', 'assigned_to'] 721 columns = ['id', 'tracker', 'subject', 'assigned_to']
702 get :index, :set_filter => 1, :c => columns 722 get :index, :set_filter => 1, :c => columns
703 723
704 # query should use specified columns 724 # query should use specified columns
705 query = assigns(:query) 725 query = assigns(:query)
706 assert_kind_of Query, query 726 assert_kind_of IssueQuery, query
707 assert_equal columns.map(&:to_sym), query.columns.map(&:name) 727 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
708 end 728 end
709 729
710 def test_index_with_custom_field_column 730 def test_index_with_custom_field_column
711 columns = %w(tracker subject cf_2) 731 columns = %w(tracker subject cf_2)
712 get :index, :set_filter => 1, :c => columns 732 get :index, :set_filter => 1, :c => columns
713 assert_response :success 733 assert_response :success
714 734
715 # query should use specified columns 735 # query should use specified columns
716 query = assigns(:query) 736 query = assigns(:query)
717 assert_kind_of Query, query 737 assert_kind_of IssueQuery, query
718 assert_equal columns, query.column_names.map(&:to_s) 738 assert_equal columns, query.column_names.map(&:to_s)
719 739
720 assert_select 'table.issues td.cf_2.string' 740 assert_select 'table.issues td.cf_2.string'
721 end 741 end
722 742
751 end 771 end
752 772
753 def test_index_with_date_column 773 def test_index_with_date_column
754 with_settings :date_format => '%d/%m/%Y' do 774 with_settings :date_format => '%d/%m/%Y' do
755 Issue.find(1).update_attribute :start_date, '1987-08-24' 775 Issue.find(1).update_attribute :start_date, '1987-08-24'
756
757 get :index, :set_filter => 1, :c => %w(start_date) 776 get :index, :set_filter => 1, :c => %w(start_date)
758
759 assert_select "table.issues td.start_date", :text => '24/08/1987' 777 assert_select "table.issues td.start_date", :text => '24/08/1987'
760 end 778 end
761 end 779 end
762 780
763 def test_index_with_done_ratio_column 781 def test_index_with_done_ratio_column
764 Issue.find(1).update_attribute :done_ratio, 40 782 Issue.find(1).update_attribute :done_ratio, 40
765
766 get :index, :set_filter => 1, :c => %w(done_ratio) 783 get :index, :set_filter => 1, :c => %w(done_ratio)
767
768 assert_select 'table.issues td.done_ratio' do 784 assert_select 'table.issues td.done_ratio' do
769 assert_select 'table.progress' do 785 assert_select 'table.progress' do
770 assert_select 'td.closed[style=?]', 'width: 40%;' 786 assert_select 'td.closed[style=?]', 'width: 40%;'
771 end 787 end
772 end 788 end
773 end 789 end
774 790
775 def test_index_with_spent_hours_column 791 def test_index_with_spent_hours_column
776 get :index, :set_filter => 1, :c => %w(subject spent_hours) 792 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' 793 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
779 end 794 end
780 795
781 def test_index_should_not_show_spent_hours_column_without_permission 796 def test_index_should_not_show_spent_hours_column_without_permission
782 Role.anonymous.remove_permission! :view_time_entries 797 Role.anonymous.remove_permission! :view_time_entries
783 get :index, :set_filter => 1, :c => %w(subject spent_hours) 798 get :index, :set_filter => 1, :c => %w(subject spent_hours)
784
785 assert_select 'td.spent_hours', 0 799 assert_select 'td.spent_hours', 0
786 end 800 end
787 801
788 def test_index_with_fixed_version_column 802 def test_index_with_fixed_version_column
789 get :index, :set_filter => 1, :c => %w(fixed_version) 803 get :index, :set_filter => 1, :c => %w(fixed_version)
790
791 assert_select 'table.issues td.fixed_version' do 804 assert_select 'table.issues td.fixed_version' do
792 assert_select 'a[href=?]', '/versions/2', :text => '1.0' 805 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
793 end 806 end
794 end 807 end
795 808
855 def test_show_by_anonymous 868 def test_show_by_anonymous
856 get :show, :id => 1 869 get :show, :id => 1
857 assert_response :success 870 assert_response :success
858 assert_template 'show' 871 assert_template 'show'
859 assert_equal Issue.find(1), assigns(:issue) 872 assert_equal Issue.find(1), assigns(:issue)
860
861 assert_select 'div.issue div.description', :text => /Unable to print recipes/ 873 assert_select 'div.issue div.description', :text => /Unable to print recipes/
862
863 # anonymous role is allowed to add a note 874 # anonymous role is allowed to add a note
864 assert_select 'form#issue-form' do 875 assert_select 'form#issue-form' do
865 assert_select 'fieldset' do 876 assert_select 'fieldset' do
866 assert_select 'legend', :text => 'Notes' 877 assert_select 'legend', :text => 'Notes'
867 assert_select 'textarea[name=?]', 'issue[notes]' 878 assert_select 'textarea[name=?]', 'issue[notes]'
868 end 879 end
869 end 880 end
870
871 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine" 881 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
872 end 882 end
873 883
874 def test_show_by_manager 884 def test_show_by_manager
875 @request.session[:user_id] = 2 885 @request.session[:user_id] = 2
876 get :show, :id => 1 886 get :show, :id => 1
877 assert_response :success 887 assert_response :success
878
879 assert_select 'a', :text => /Quote/ 888 assert_select 'a', :text => /Quote/
880
881 assert_select 'form#issue-form' do 889 assert_select 'form#issue-form' do
882 assert_select 'fieldset' do 890 assert_select 'fieldset' do
883 assert_select 'legend', :text => 'Change properties' 891 assert_select 'legend', :text => 'Change properties'
884 assert_select 'input[name=?]', 'issue[subject]' 892 assert_select 'input[name=?]', 'issue[subject]'
885 end 893 end
897 def test_show_should_display_update_form 905 def test_show_should_display_update_form
898 @request.session[:user_id] = 2 906 @request.session[:user_id] = 2
899 get :show, :id => 1 907 get :show, :id => 1
900 assert_response :success 908 assert_response :success
901 909
902 assert_tag 'form', :attributes => {:id => 'issue-form'} 910 assert_select 'form#issue-form' do
903 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} 911 assert_select 'input[name=?]', 'issue[is_private]'
904 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 912 assert_select 'select[name=?]', 'issue[project_id]'
905 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 913 assert_select 'select[name=?]', 'issue[tracker_id]'
906 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 914 assert_select 'input[name=?]', 'issue[subject]'
907 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 915 assert_select 'textarea[name=?]', 'issue[description]'
908 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 916 assert_select 'select[name=?]', 'issue[status_id]'
909 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 917 assert_select 'select[name=?]', 'issue[priority_id]'
910 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 918 assert_select 'select[name=?]', 'issue[assigned_to_id]'
911 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 919 assert_select 'select[name=?]', 'issue[category_id]'
912 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 920 assert_select 'select[name=?]', 'issue[fixed_version_id]'
913 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 921 assert_select 'input[name=?]', 'issue[parent_issue_id]'
914 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 922 assert_select 'input[name=?]', 'issue[start_date]'
915 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 923 assert_select 'input[name=?]', 'issue[due_date]'
916 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 924 assert_select 'select[name=?]', 'issue[done_ratio]'
917 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 925 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
918 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 926 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
919 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 927 assert_select 'textarea[name=?]', 'issue[notes]'
928 end
920 end 929 end
921 930
922 def test_show_should_display_update_form_with_minimal_permissions 931 def test_show_should_display_update_form_with_minimal_permissions
923 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] 932 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
924 WorkflowTransition.delete_all :role_id => 1 933 WorkflowTransition.delete_all :role_id => 1
925 934
926 @request.session[:user_id] = 2 935 @request.session[:user_id] = 2
927 get :show, :id => 1 936 get :show, :id => 1
928 assert_response :success 937 assert_response :success
929 938
930 assert_tag 'form', :attributes => {:id => 'issue-form'} 939 assert_select 'form#issue-form' do
931 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 940 assert_select 'input[name=?]', 'issue[is_private]', 0
932 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 941 assert_select 'select[name=?]', 'issue[project_id]', 0
933 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 942 assert_select 'select[name=?]', 'issue[tracker_id]', 0
934 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} 943 assert_select 'input[name=?]', 'issue[subject]', 0
935 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} 944 assert_select 'textarea[name=?]', 'issue[description]', 0
936 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'} 945 assert_select 'select[name=?]', 'issue[status_id]', 0
937 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} 946 assert_select 'select[name=?]', 'issue[priority_id]', 0
938 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 947 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
939 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} 948 assert_select 'select[name=?]', 'issue[category_id]', 0
940 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 949 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
941 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 950 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
942 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} 951 assert_select 'input[name=?]', 'issue[start_date]', 0
943 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} 952 assert_select 'input[name=?]', 'issue[due_date]', 0
944 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 953 assert_select 'select[name=?]', 'issue[done_ratio]', 0
945 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 954 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
946 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 955 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
947 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 956 assert_select 'textarea[name=?]', 'issue[notes]'
957 end
948 end 958 end
949 959
950 def test_show_should_display_update_form_with_workflow_permissions 960 def test_show_should_display_update_form_with_workflow_permissions
951 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] 961 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
952 962
953 @request.session[:user_id] = 2 963 @request.session[:user_id] = 2
954 get :show, :id => 1 964 get :show, :id => 1
955 assert_response :success 965 assert_response :success
956 966
957 assert_tag 'form', :attributes => {:id => 'issue-form'} 967 assert_select 'form#issue-form' do
958 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 968 assert_select 'input[name=?]', 'issue[is_private]', 0
959 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 969 assert_select 'select[name=?]', 'issue[project_id]', 0
960 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 970 assert_select 'select[name=?]', 'issue[tracker_id]', 0
961 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} 971 assert_select 'input[name=?]', 'issue[subject]', 0
962 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} 972 assert_select 'textarea[name=?]', 'issue[description]', 0
963 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 973 assert_select 'select[name=?]', 'issue[status_id]'
964 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} 974 assert_select 'select[name=?]', 'issue[priority_id]', 0
965 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 975 assert_select 'select[name=?]', 'issue[assigned_to_id]'
966 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} 976 assert_select 'select[name=?]', 'issue[category_id]', 0
967 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 977 assert_select 'select[name=?]', 'issue[fixed_version_id]'
968 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 978 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
969 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} 979 assert_select 'input[name=?]', 'issue[start_date]', 0
970 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} 980 assert_select 'input[name=?]', 'issue[due_date]', 0
971 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 981 assert_select 'select[name=?]', 'issue[done_ratio]'
972 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } 982 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
973 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 983 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
974 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} 984 assert_select 'textarea[name=?]', 'issue[notes]'
985 end
975 end 986 end
976 987
977 def test_show_should_not_display_update_form_without_permissions 988 def test_show_should_not_display_update_form_without_permissions
978 Role.find(1).update_attribute :permissions, [:view_issues] 989 Role.find(1).update_attribute :permissions, [:view_issues]
979 990
1002 def test_update_form_should_allow_attachment_upload 1013 def test_update_form_should_allow_attachment_upload
1003 @request.session[:user_id] = 2 1014 @request.session[:user_id] = 2
1004 get :show, :id => 1 1015 get :show, :id => 1
1005 1016
1006 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do 1017 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
1007 assert_select 'input[type=file][name=?]', 'attachments[1][file]' 1018 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
1008 end 1019 end
1009 end 1020 end
1010 1021
1011 def test_show_should_deny_anonymous_access_without_permission 1022 def test_show_should_deny_anonymous_access_without_permission
1012 Role.anonymous.remove_permission!(:view_issues) 1023 Role.anonymous.remove_permission!(:view_issues)
1138 assert_select 'span.position', :text => "3 of #{count}" 1149 assert_select 'span.position', :text => "3 of #{count}"
1139 end 1150 end
1140 end 1151 end
1141 1152
1142 def test_show_should_display_prev_next_links_with_saved_query_in_session 1153 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, 1154 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
1144 :filters => {'status_id' => {:values => ['5'], :operator => '='}}, 1155 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1145 :sort_criteria => [['id', 'asc']]) 1156 :sort_criteria => [['id', 'asc']])
1146 @request.session[:query] = {:id => query.id, :project_id => nil} 1157 @request.session[:query] = {:id => query.id, :project_id => nil}
1147 1158
1148 get :show, :id => 11 1159 get :show, :id => 11
1230 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') 1241 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1231 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') 1242 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1232 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') 1243 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1233 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') 1244 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1234 1245
1235 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {}, 1246 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
1236 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) 1247 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1237 @request.session[:query] = {:id => query.id, :project_id => nil} 1248 @request.session[:query] = {:id => query.id, :project_id => nil}
1238 1249
1239 get :show, :id => 3 1250 get :show, :id => 3
1240 assert_response :success 1251 assert_response :success
1418 assert_response :success 1429 assert_response :success
1419 assert_equal 'application/pdf', @response.content_type 1430 assert_equal 'application/pdf', @response.content_type
1420 assert @response.body.starts_with?('%PDF') 1431 assert @response.body.starts_with?('%PDF')
1421 end 1432 end
1422 1433
1434 def test_show_invalid_should_respond_with_404
1435 get :show, :id => 999
1436 assert_response 404
1437 end
1438
1423 def test_get_new 1439 def test_get_new
1424 @request.session[:user_id] = 2 1440 @request.session[:user_id] = 2
1425 get :new, :project_id => 1, :tracker_id => 1 1441 get :new, :project_id => 1, :tracker_id => 1
1426 assert_response :success 1442 assert_response :success
1427 assert_template 'new' 1443 assert_template 'new'
1428 1444
1429 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} 1445 assert_select 'form#issue-form' do
1430 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 1446 assert_select 'input[name=?]', 'issue[is_private]'
1431 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 1447 assert_select 'select[name=?]', 'issue[project_id]', 0
1432 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 1448 assert_select 'select[name=?]', 'issue[tracker_id]'
1433 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 1449 assert_select 'input[name=?]', 'issue[subject]'
1434 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 1450 assert_select 'textarea[name=?]', 'issue[description]'
1435 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 1451 assert_select 'select[name=?]', 'issue[status_id]'
1436 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 1452 assert_select 'select[name=?]', 'issue[priority_id]'
1437 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 1453 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1438 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 1454 assert_select 'select[name=?]', 'issue[category_id]'
1439 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 1455 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1440 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 1456 assert_select 'input[name=?]', 'issue[parent_issue_id]'
1441 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 1457 assert_select 'input[name=?]', 'issue[start_date]'
1442 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 1458 assert_select 'input[name=?]', 'issue[due_date]'
1443 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } 1459 assert_select 'select[name=?]', 'issue[done_ratio]'
1444 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 1460 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1461 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
1462 end
1445 1463
1446 # Be sure we don't display inactive IssuePriorities 1464 # Be sure we don't display inactive IssuePriorities
1447 assert ! IssuePriority.find(15).active? 1465 assert ! IssuePriority.find(15).active?
1448 assert_no_tag :option, :attributes => {:value => '15'}, 1466 assert_select 'select[name=?]', 'issue[priority_id]' do
1449 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 1467 assert_select 'option[value=15]', 0
1468 end
1450 end 1469 end
1451 1470
1452 def test_get_new_with_minimal_permissions 1471 def test_get_new_with_minimal_permissions
1453 Role.find(1).update_attribute :permissions, [:add_issues] 1472 Role.find(1).update_attribute :permissions, [:add_issues]
1454 WorkflowTransition.delete_all :role_id => 1 1473 WorkflowTransition.delete_all :role_id => 1
1456 @request.session[:user_id] = 2 1475 @request.session[:user_id] = 2
1457 get :new, :project_id => 1, :tracker_id => 1 1476 get :new, :project_id => 1, :tracker_id => 1
1458 assert_response :success 1477 assert_response :success
1459 assert_template 'new' 1478 assert_template 'new'
1460 1479
1461 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} 1480 assert_select 'form#issue-form' do
1462 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} 1481 assert_select 'input[name=?]', 'issue[is_private]', 0
1463 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} 1482 assert_select 'select[name=?]', 'issue[project_id]', 0
1464 assert_tag 'input', :attributes => {:name => 'issue[subject]'} 1483 assert_select 'select[name=?]', 'issue[tracker_id]'
1465 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} 1484 assert_select 'input[name=?]', 'issue[subject]'
1466 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} 1485 assert_select 'textarea[name=?]', 'issue[description]'
1467 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} 1486 assert_select 'select[name=?]', 'issue[status_id]'
1468 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} 1487 assert_select 'select[name=?]', 'issue[priority_id]'
1469 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} 1488 assert_select 'select[name=?]', 'issue[assigned_to_id]'
1470 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} 1489 assert_select 'select[name=?]', 'issue[category_id]'
1471 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} 1490 assert_select 'select[name=?]', 'issue[fixed_version_id]'
1472 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} 1491 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
1473 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} 1492 assert_select 'input[name=?]', 'issue[start_date]'
1474 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} 1493 assert_select 'input[name=?]', 'issue[due_date]'
1475 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } 1494 assert_select 'select[name=?]', 'issue[done_ratio]'
1476 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} 1495 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
1496 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
1497 end
1477 end 1498 end
1478 1499
1479 def test_get_new_with_list_custom_field 1500 def test_get_new_with_list_custom_field
1480 @request.session[:user_id] = 2 1501 @request.session[:user_id] = 2
1481 get :new, :project_id => 1, :tracker_id => 1 1502 get :new, :project_id => 1, :tracker_id => 1
1539 1560
1540 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]" 1561 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1541 end 1562 end
1542 1563
1543 def test_get_new_without_default_start_date_is_creation_date 1564 def test_get_new_without_default_start_date_is_creation_date
1544 Setting.default_issue_start_date_to_creation_date = 0 1565 with_settings :default_issue_start_date_to_creation_date => 0 do
1545 1566 @request.session[:user_id] = 2
1567 get :new, :project_id => 1, :tracker_id => 1
1568 assert_response :success
1569 assert_template 'new'
1570 assert_select 'input[name=?]', 'issue[start_date]'
1571 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1572 end
1573 end
1574
1575 def test_get_new_with_default_start_date_is_creation_date
1576 with_settings :default_issue_start_date_to_creation_date => 1 do
1577 @request.session[:user_id] = 2
1578 get :new, :project_id => 1, :tracker_id => 1
1579 assert_response :success
1580 assert_template 'new'
1581 assert_select 'input[name=?][value=?]', 'issue[start_date]',
1582 Date.today.to_s
1583 end
1584 end
1585
1586 def test_get_new_form_should_allow_attachment_upload
1546 @request.session[:user_id] = 2 1587 @request.session[:user_id] = 2
1547 get :new, :project_id => 1, :tracker_id => 1 1588 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 1589
1570 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do 1590 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1571 assert_select 'input[name=?][type=file]', 'attachments[1][file]' 1591 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
1572 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
1573 end 1592 end
1574 end 1593 end
1575 1594
1576 def test_get_new_should_prefill_the_form_from_params 1595 def test_get_new_should_prefill_the_form_from_params
1577 @request.session[:user_id] = 2 1596 @request.session[:user_id] = 2
1661 get :new, :project_id => 1 1680 get :new, :project_id => 1
1662 assert_response 500 1681 assert_response 500
1663 assert_error_tag :content => /No tracker/ 1682 assert_error_tag :content => /No tracker/
1664 end 1683 end
1665 1684
1666 def test_update_new_form 1685 def test_update_form_for_new_issue
1667 @request.session[:user_id] = 2 1686 @request.session[:user_id] = 2
1668 xhr :post, :new, :project_id => 1, 1687 xhr :post, :update_form, :project_id => 1,
1669 :issue => {:tracker_id => 2, 1688 :issue => {:tracker_id => 2,
1670 :subject => 'This is the test_new issue', 1689 :subject => 'This is the test_new issue',
1671 :description => 'This is the description', 1690 :description => 'This is the description',
1672 :priority_id => 5} 1691 :priority_id => 5}
1673 assert_response :success 1692 assert_response :success
1680 assert_equal 1, issue.project_id 1699 assert_equal 1, issue.project_id
1681 assert_equal 2, issue.tracker_id 1700 assert_equal 2, issue.tracker_id
1682 assert_equal 'This is the test_new issue', issue.subject 1701 assert_equal 'This is the test_new issue', issue.subject
1683 end 1702 end
1684 1703
1685 def test_update_new_form_should_propose_transitions_based_on_initial_status 1704 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
1686 @request.session[:user_id] = 2 1705 @request.session[:user_id] = 2
1687 WorkflowTransition.delete_all 1706 WorkflowTransition.delete_all
1688 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) 1707 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) 1708 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) 1709 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1691 1710
1692 xhr :post, :new, :project_id => 1, 1711 xhr :post, :update_form, :project_id => 1,
1693 :issue => {:tracker_id => 1, 1712 :issue => {:tracker_id => 1,
1694 :status_id => 5, 1713 :status_id => 5,
1695 :subject => 'This is an issue'} 1714 :subject => 'This is an issue'}
1696 1715
1697 assert_equal 5, assigns(:issue).status_id 1716 assert_equal 5, assigns(:issue).status_id
1718 assert_equal 2, issue.author_id 1737 assert_equal 2, issue.author_id
1719 assert_equal 3, issue.tracker_id 1738 assert_equal 3, issue.tracker_id
1720 assert_equal 2, issue.status_id 1739 assert_equal 2, issue.status_id
1721 assert_equal Date.parse('2010-11-07'), issue.start_date 1740 assert_equal Date.parse('2010-11-07'), issue.start_date
1722 assert_nil issue.estimated_hours 1741 assert_nil issue.estimated_hours
1723 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) 1742 v = issue.custom_values.where(:custom_field_id => 2).first
1724 assert_not_nil v 1743 assert_not_nil v
1725 assert_equal 'Value for field 2', v.value 1744 assert_equal 'Value for field 2', v.value
1726 end 1745 end
1727 1746
1728 def test_post_new_with_group_assignment 1747 def test_post_new_with_group_assignment
1746 assert_not_nil issue 1765 assert_not_nil issue
1747 assert_equal group, issue.assigned_to 1766 assert_equal group, issue.assigned_to
1748 end 1767 end
1749 1768
1750 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date 1769 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 1770 with_settings :default_issue_start_date_to_creation_date => 0 do
1752 1771 @request.session[:user_id] = 2
1753 @request.session[:user_id] = 2 1772 assert_difference 'Issue.count' do
1754 assert_difference 'Issue.count' do 1773 post :create, :project_id => 1,
1755 post :create, :project_id => 1,
1756 :issue => {:tracker_id => 3, 1774 :issue => {:tracker_id => 3,
1757 :status_id => 2, 1775 :status_id => 2,
1758 :subject => 'This is the test_new issue', 1776 :subject => 'This is the test_new issue',
1759 :description => 'This is the description', 1777 :description => 'This is the description',
1760 :priority_id => 5, 1778 :priority_id => 5,
1761 :estimated_hours => '', 1779 :estimated_hours => '',
1762 :custom_field_values => {'2' => 'Value for field 2'}} 1780 :custom_field_values => {'2' => 'Value for field 2'}}
1763 end 1781 end
1764 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id 1782 assert_redirected_to :controller => 'issues', :action => 'show',
1765 1783 :id => Issue.last.id
1766 issue = Issue.find_by_subject('This is the test_new issue') 1784 issue = Issue.find_by_subject('This is the test_new issue')
1767 assert_not_nil issue 1785 assert_not_nil issue
1768 assert_nil issue.start_date 1786 assert_nil issue.start_date
1787 end
1769 end 1788 end
1770 1789
1771 def test_post_create_without_start_date_and_default_start_date_is_creation_date 1790 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1772 Setting.default_issue_start_date_to_creation_date = 1 1791 with_settings :default_issue_start_date_to_creation_date => 1 do
1773 1792 @request.session[:user_id] = 2
1774 @request.session[:user_id] = 2 1793 assert_difference 'Issue.count' do
1775 assert_difference 'Issue.count' do 1794 post :create, :project_id => 1,
1776 post :create, :project_id => 1,
1777 :issue => {:tracker_id => 3, 1795 :issue => {:tracker_id => 3,
1778 :status_id => 2, 1796 :status_id => 2,
1779 :subject => 'This is the test_new issue', 1797 :subject => 'This is the test_new issue',
1780 :description => 'This is the description', 1798 :description => 'This is the description',
1781 :priority_id => 5, 1799 :priority_id => 5,
1782 :estimated_hours => '', 1800 :estimated_hours => '',
1783 :custom_field_values => {'2' => 'Value for field 2'}} 1801 :custom_field_values => {'2' => 'Value for field 2'}}
1784 end 1802 end
1785 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id 1803 assert_redirected_to :controller => 'issues', :action => 'show',
1786 1804 :id => Issue.last.id
1787 issue = Issue.find_by_subject('This is the test_new issue') 1805 issue = Issue.find_by_subject('This is the test_new issue')
1788 assert_not_nil issue 1806 assert_not_nil issue
1789 assert_equal Date.today, issue.start_date 1807 assert_equal Date.today, issue.start_date
1808 end
1790 end 1809 end
1791 1810
1792 def test_post_create_and_continue 1811 def test_post_create_and_continue
1793 @request.session[:user_id] = 2 1812 @request.session[:user_id] = 2
1794 assert_difference 'Issue.count' do 1813 assert_difference 'Issue.count' do
2080 :priority_id => 6, 2099 :priority_id => 6,
2081 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} 2100 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2082 assert_response :success 2101 assert_response :success
2083 assert_template 'new' 2102 assert_template 'new'
2084 2103
2085 assert_tag :textarea, :attributes => { :name => 'issue[description]' }, 2104 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
2086 :content => "\nThis is a description" 2105 assert_select 'select[name=?]', 'issue[priority_id]' do
2087 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, 2106 assert_select 'option[value=6][selected=selected]', :text => 'High'
2088 :child => { :tag => 'option', :attributes => { :selected => 'selected', 2107 end
2089 :value => '6' },
2090 :content => 'High' }
2091 # Custom fields 2108 # Custom fields
2092 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, 2109 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
2093 :child => { :tag => 'option', :attributes => { :selected => 'selected', 2110 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
2094 :value => 'Oracle' }, 2111 end
2095 :content => 'Oracle' } 2112 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 2113 end
2099 2114
2100 def test_post_create_with_failure_should_preserve_watchers 2115 def test_post_create_with_failure_should_preserve_watchers
2101 assert !User.find(8).member_of?(Project.find(1)) 2116 assert !User.find(8).member_of?(Project.find(1))
2102 2117
2105 :issue => {:tracker_id => 1, 2120 :issue => {:tracker_id => 1,
2106 :watcher_user_ids => ['3', '8']} 2121 :watcher_user_ids => ['3', '8']}
2107 assert_response :success 2122 assert_response :success
2108 assert_template 'new' 2123 assert_template 'new'
2109 2124
2110 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil} 2125 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'} 2126 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'} 2127 assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]'
2113 end 2128 end
2114 2129
2115 def test_post_create_should_ignore_non_safe_attributes 2130 def test_post_create_should_ignore_non_safe_attributes
2116 @request.session[:user_id] = 2 2131 @request.session[:user_id] = 2
2117 assert_nothing_raised do 2132 assert_nothing_raised do
2142 assert_equal 59, attachment.filesize 2157 assert_equal 59, attachment.filesize
2143 assert File.exists?(attachment.diskfile) 2158 assert File.exists?(attachment.diskfile)
2144 assert_equal 59, File.size(attachment.diskfile) 2159 assert_equal 59, File.size(attachment.diskfile)
2145 end 2160 end
2146 2161
2162 def test_post_create_with_attachment_should_notify_with_attachments
2163 ActionMailer::Base.deliveries.clear
2164 set_tmp_attachments_directory
2165 @request.session[:user_id] = 2
2166
2167 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
2168 assert_difference 'Issue.count' do
2169 post :create, :project_id => 1,
2170 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2171 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2172 end
2173 end
2174
2175 assert_not_nil ActionMailer::Base.deliveries.last
2176 assert_select_email do
2177 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
2178 end
2179 end
2180
2147 def test_post_create_with_failure_should_save_attachments 2181 def test_post_create_with_failure_should_save_attachments
2148 set_tmp_attachments_directory 2182 set_tmp_attachments_directory
2149 @request.session[:user_id] = 2 2183 @request.session[:user_id] = 2
2150 2184
2151 assert_no_difference 'Issue.count' do 2185 assert_no_difference 'Issue.count' do
2161 attachment = Attachment.first(:order => 'id DESC') 2195 attachment = Attachment.first(:order => 'id DESC')
2162 assert_equal 'testfile.txt', attachment.filename 2196 assert_equal 'testfile.txt', attachment.filename
2163 assert File.exists?(attachment.diskfile) 2197 assert File.exists?(attachment.diskfile)
2164 assert_nil attachment.container 2198 assert_nil attachment.container
2165 2199
2166 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 2200 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2167 assert_tag 'span', :content => /testfile.txt/ 2201 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2168 end 2202 end
2169 2203
2170 def test_post_create_with_failure_should_keep_saved_attachments 2204 def test_post_create_with_failure_should_keep_saved_attachments
2171 set_tmp_attachments_directory 2205 set_tmp_attachments_directory
2172 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 2206 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2180 assert_response :success 2214 assert_response :success
2181 assert_template 'new' 2215 assert_template 'new'
2182 end 2216 end
2183 end 2217 end
2184 2218
2185 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 2219 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2186 assert_tag 'span', :content => /testfile.txt/ 2220 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2187 end 2221 end
2188 2222
2189 def test_post_create_should_attach_saved_attachments 2223 def test_post_create_should_attach_saved_attachments
2190 set_tmp_attachments_directory 2224 set_tmp_attachments_directory
2191 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 2225 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2216 context "#new" do 2250 context "#new" do
2217 should "propose default status only" do 2251 should "propose default status only" do
2218 get :new, :project_id => 1 2252 get :new, :project_id => 1
2219 assert_response :success 2253 assert_response :success
2220 assert_template 'new' 2254 assert_template 'new'
2221 assert_tag :tag => 'select', 2255 assert_select 'select[name=?]', 'issue[status_id]' do
2222 :attributes => {:name => 'issue[status_id]'}, 2256 assert_select 'option', 1
2223 :children => {:count => 1}, 2257 assert_select 'option[value=?]', IssueStatus.default.id.to_s
2224 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} 2258 end
2225 end 2259 end
2226 2260
2227 should "accept default status" do 2261 should "accept default status" do
2228 assert_difference 'Issue.count' do 2262 assert_difference 'Issue.count' do
2229 post :create, :project_id => 1, 2263 post :create, :project_id => 1,
2347 orig = Issue.find(1) 2381 orig = Issue.find(1)
2348 assert_equal 1, assigns(:issue).project_id 2382 assert_equal 1, assigns(:issue).project_id
2349 assert_equal orig.subject, assigns(:issue).subject 2383 assert_equal orig.subject, assigns(:issue).subject
2350 assert assigns(:issue).copy? 2384 assert assigns(:issue).copy?
2351 2385
2352 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} 2386 assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do
2353 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 2387 assert_select 'select[name=?]', 'issue[project_id]' do
2354 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2388 assert_select 'option[value=1][selected=selected]', :text => 'eCookbook'
2355 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'} 2389 assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore'
2356 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2390 end
2357 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'} 2391 assert_select 'input[name=copy_from][value=1]'
2358 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} 2392 end
2359 2393
2360 # "New issue" menu item should not link to copy 2394 # "New issue" menu item should not link to copy
2361 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' 2395 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]'
2362 end 2396 end
2363 2397
2365 @request.session[:user_id] = 2 2399 @request.session[:user_id] = 2
2366 issue = Issue.find(3) 2400 issue = Issue.find(3)
2367 assert issue.attachments.count > 0 2401 assert issue.attachments.count > 0
2368 get :new, :project_id => 1, :copy_from => 3 2402 get :new, :project_id => 1, :copy_from => 3
2369 2403
2370 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} 2404 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]'
2371 end 2405 end
2372 2406
2373 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox 2407 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2374 @request.session[:user_id] = 2 2408 @request.session[:user_id] = 2
2375 issue = Issue.find(3) 2409 issue = Issue.find(3)
2376 issue.attachments.delete_all 2410 issue.attachments.delete_all
2377 get :new, :project_id => 1, :copy_from => 3 2411 get :new, :project_id => 1, :copy_from => 3
2378 2412
2379 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} 2413 assert_select 'input[name=copy_attachments]', 0
2380 end 2414 end
2381 2415
2382 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox 2416 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2383 @request.session[:user_id] = 2 2417 @request.session[:user_id] = 2
2384 issue = Issue.generate_with_descendants! 2418 issue = Issue.generate_with_descendants!
2413 def test_create_as_copy_should_copy_attachments 2447 def test_create_as_copy_should_copy_attachments
2414 @request.session[:user_id] = 2 2448 @request.session[:user_id] = 2
2415 issue = Issue.find(3) 2449 issue = Issue.find(3)
2416 count = issue.attachments.count 2450 count = issue.attachments.count
2417 assert count > 0 2451 assert count > 0
2418
2419 assert_difference 'Issue.count' do 2452 assert_difference 'Issue.count' do
2420 assert_difference 'Attachment.count', count do 2453 assert_difference 'Attachment.count', count do
2421 assert_no_difference 'Journal.count' do 2454 assert_difference 'Journal.count', 2 do
2422 post :create, :project_id => 1, :copy_from => 3, 2455 post :create, :project_id => 1, :copy_from => 3,
2423 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, 2456 :issue => {:project_id => '1', :tracker_id => '3',
2457 :status_id => '1', :subject => 'Copy with attachments'},
2424 :copy_attachments => '1' 2458 :copy_attachments => '1'
2425 end 2459 end
2426 end 2460 end
2427 end 2461 end
2428 copy = Issue.first(:order => 'id DESC') 2462 copy = Issue.first(:order => 'id DESC')
2433 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments 2467 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2434 @request.session[:user_id] = 2 2468 @request.session[:user_id] = 2
2435 issue = Issue.find(3) 2469 issue = Issue.find(3)
2436 count = issue.attachments.count 2470 count = issue.attachments.count
2437 assert count > 0 2471 assert count > 0
2438
2439 assert_difference 'Issue.count' do 2472 assert_difference 'Issue.count' do
2440 assert_no_difference 'Attachment.count' do 2473 assert_no_difference 'Attachment.count' do
2441 assert_no_difference 'Journal.count' do 2474 assert_difference 'Journal.count', 2 do
2442 post :create, :project_id => 1, :copy_from => 3, 2475 post :create, :project_id => 1, :copy_from => 3,
2443 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'} 2476 :issue => {:project_id => '1', :tracker_id => '3',
2477 :status_id => '1', :subject => 'Copy with attachments'}
2444 end 2478 end
2445 end 2479 end
2446 end 2480 end
2447 copy = Issue.first(:order => 'id DESC') 2481 copy = Issue.first(:order => 'id DESC')
2448 assert_equal 0, copy.attachments.count 2482 assert_equal 0, copy.attachments.count
2451 def test_create_as_copy_with_attachments_should_add_new_files 2485 def test_create_as_copy_with_attachments_should_add_new_files
2452 @request.session[:user_id] = 2 2486 @request.session[:user_id] = 2
2453 issue = Issue.find(3) 2487 issue = Issue.find(3)
2454 count = issue.attachments.count 2488 count = issue.attachments.count
2455 assert count > 0 2489 assert count > 0
2456
2457 assert_difference 'Issue.count' do 2490 assert_difference 'Issue.count' do
2458 assert_difference 'Attachment.count', count + 1 do 2491 assert_difference 'Attachment.count', count + 1 do
2459 assert_no_difference 'Journal.count' do 2492 assert_difference 'Journal.count', 2 do
2460 post :create, :project_id => 1, :copy_from => 3, 2493 post :create, :project_id => 1, :copy_from => 3,
2461 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}, 2494 :issue => {:project_id => '1', :tracker_id => '3',
2495 :status_id => '1', :subject => 'Copy with attachments'},
2462 :copy_attachments => '1', 2496 :copy_attachments => '1',
2463 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 2497 :attachments => {'1' =>
2498 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2499 'description' => 'test file'}}
2464 end 2500 end
2465 end 2501 end
2466 end 2502 end
2467 copy = Issue.first(:order => 'id DESC') 2503 copy = Issue.first(:order => 'id DESC')
2468 assert_equal count + 1, copy.attachments.count 2504 assert_equal count + 1, copy.attachments.count
2469 end 2505 end
2470 2506
2471 def test_create_as_copy_should_add_relation_with_copied_issue 2507 def test_create_as_copy_should_add_relation_with_copied_issue
2472 @request.session[:user_id] = 2 2508 @request.session[:user_id] = 2
2473
2474 assert_difference 'Issue.count' do 2509 assert_difference 'Issue.count' do
2475 assert_difference 'IssueRelation.count' do 2510 assert_difference 'IssueRelation.count' do
2476 post :create, :project_id => 1, :copy_from => 1, 2511 post :create, :project_id => 1, :copy_from => 1,
2477 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2512 :issue => {:project_id => '1', :tracker_id => '3',
2513 :status_id => '1', :subject => 'Copy'}
2478 end 2514 end
2479 end 2515 end
2480 copy = Issue.first(:order => 'id DESC') 2516 copy = Issue.first(:order => 'id DESC')
2481 assert_equal 1, copy.relations.size 2517 assert_equal 1, copy.relations.size
2482 end 2518 end
2483 2519
2484 def test_create_as_copy_should_copy_subtasks 2520 def test_create_as_copy_should_copy_subtasks
2485 @request.session[:user_id] = 2 2521 @request.session[:user_id] = 2
2486 issue = Issue.generate_with_descendants! 2522 issue = Issue.generate_with_descendants!
2487 count = issue.descendants.count 2523 count = issue.descendants.count
2488 2524 assert_difference 'Issue.count', count + 1 do
2489 assert_difference 'Issue.count', count+1 do 2525 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, 2526 post :create, :project_id => 1, :copy_from => issue.id,
2492 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}, 2527 :issue => {:project_id => '1', :tracker_id => '3',
2528 :status_id => '1', :subject => 'Copy with subtasks'},
2493 :copy_subtasks => '1' 2529 :copy_subtasks => '1'
2494 end 2530 end
2495 end 2531 end
2496 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2532 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2497 assert_equal count, copy.descendants.count 2533 assert_equal count, copy.descendants.count
2499 end 2535 end
2500 2536
2501 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks 2537 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2502 @request.session[:user_id] = 2 2538 @request.session[:user_id] = 2
2503 issue = Issue.generate_with_descendants! 2539 issue = Issue.generate_with_descendants!
2504
2505 assert_difference 'Issue.count', 1 do 2540 assert_difference 'Issue.count', 1 do
2506 assert_no_difference 'Journal.count' do 2541 assert_difference 'Journal.count', 2 do
2507 post :create, :project_id => 1, :copy_from => 3, 2542 post :create, :project_id => 1, :copy_from => 3,
2508 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'} 2543 :issue => {:project_id => '1', :tracker_id => '3',
2544 :status_id => '1', :subject => 'Copy with subtasks'}
2509 end 2545 end
2510 end 2546 end
2511 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2547 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2512 assert_equal 0, copy.descendants.count 2548 assert_equal 0, copy.descendants.count
2513 end 2549 end
2521 assert_template 'new' 2557 assert_template 'new'
2522 2558
2523 assert_not_nil assigns(:issue) 2559 assert_not_nil assigns(:issue)
2524 assert assigns(:issue).copy? 2560 assert assigns(:issue).copy?
2525 2561
2526 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} 2562 assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do
2527 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} 2563 assert_select 'select[name=?]', 'issue[project_id]' do
2528 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2564 assert_select 'option[value=1]:not([selected])', :text => 'eCookbook'
2529 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'} 2565 assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore'
2530 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, 2566 end
2531 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'} 2567 assert_select 'input[name=copy_from][value=1]'
2532 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} 2568 end
2533 end 2569 end
2534 2570
2535 def test_create_as_copy_on_project_without_permission_should_ignore_target_project 2571 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2536 @request.session[:user_id] = 2 2572 @request.session[:user_id] = 2
2537 assert !User.find(2).member_of?(Project.find(4)) 2573 assert !User.find(2).member_of?(Project.find(4))
2552 assert_not_nil assigns(:issue) 2588 assert_not_nil assigns(:issue)
2553 assert_equal Issue.find(1), assigns(:issue) 2589 assert_equal Issue.find(1), assigns(:issue)
2554 2590
2555 # Be sure we don't display inactive IssuePriorities 2591 # Be sure we don't display inactive IssuePriorities
2556 assert ! IssuePriority.find(15).active? 2592 assert ! IssuePriority.find(15).active?
2557 assert_no_tag :option, :attributes => {:value => '15'}, 2593 assert_select 'select[name=?]', 'issue[priority_id]' do
2558 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 2594 assert_select 'option[value=15]', 0
2595 end
2559 end 2596 end
2560 2597
2561 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission 2598 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2562 @request.session[:user_id] = 2 2599 @request.session[:user_id] = 2
2563 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] 2600 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2564 2601
2565 get :edit, :id => 1 2602 get :edit, :id => 1
2566 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'} 2603 assert_select 'input[name=?]', 'time_entry[hours]'
2567 end 2604 end
2568 2605
2569 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission 2606 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2570 @request.session[:user_id] = 2 2607 @request.session[:user_id] = 2
2571 Role.find_by_name('Manager').remove_permission! :log_time 2608 Role.find_by_name('Manager').remove_permission! :log_time
2572 2609
2573 get :edit, :id => 1 2610 get :edit, :id => 1
2574 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'} 2611 assert_select 'input[name=?]', 'time_entry[hours]', 0
2575 end 2612 end
2576 2613
2577 def test_get_edit_with_params 2614 def test_get_edit_with_params
2578 @request.session[:user_id] = 2 2615 @request.session[:user_id] = 2
2579 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, 2616 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 } 2617 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
2581 assert_response :success 2618 assert_response :success
2582 assert_template 'edit' 2619 assert_template 'edit'
2583 2620
2584 issue = assigns(:issue) 2621 issue = assigns(:issue)
2585 assert_not_nil issue 2622 assert_not_nil issue
2586 2623
2587 assert_equal 5, issue.status_id 2624 assert_equal 5, issue.status_id
2588 assert_tag :select, :attributes => { :name => 'issue[status_id]' }, 2625 assert_select 'select[name=?]', 'issue[status_id]' do
2589 :child => { :tag => 'option', 2626 assert_select 'option[value=5][selected=selected]', :text => 'Closed'
2590 :content => 'Closed', 2627 end
2591 :attributes => { :selected => 'selected' } }
2592 2628
2593 assert_equal 7, issue.priority_id 2629 assert_equal 7, issue.priority_id
2594 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, 2630 assert_select 'select[name=?]', 'issue[priority_id]' do
2595 :child => { :tag => 'option', 2631 assert_select 'option[value=7][selected=selected]', :text => 'Urgent'
2596 :content => 'Urgent', 2632 end
2597 :attributes => { :selected => 'selected' } } 2633
2598 2634 assert_select 'input[name=?][value=2.5]', 'time_entry[hours]'
2599 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } 2635 assert_select 'select[name=?]', 'time_entry[activity_id]' do
2600 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, 2636 assert_select 'option[value=10][selected=selected]', :text => 'Development'
2601 :child => { :tag => 'option', 2637 end
2602 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } 2638 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 2639 end
2605 2640
2606 def test_get_edit_with_multi_custom_field 2641 def test_get_edit_with_multi_custom_field
2607 field = CustomField.find(1) 2642 field = CustomField.find(1)
2608 field.update_attribute :multiple, true 2643 field.update_attribute :multiple, true
2613 @request.session[:user_id] = 2 2648 @request.session[:user_id] = 2
2614 get :edit, :id => 1 2649 get :edit, :id => 1
2615 assert_response :success 2650 assert_response :success
2616 assert_template 'edit' 2651 assert_template 'edit'
2617 2652
2618 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'} 2653 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
2619 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2654 assert_select 'option', 3
2620 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}} 2655 assert_select 'option[value=MySQL][selected=selected]'
2621 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2656 assert_select 'option[value=Oracle][selected=selected]'
2622 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}} 2657 assert_select 'option[value=PostgreSQL]:not([selected])'
2623 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, 2658 end
2624 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}} 2659 end
2625 end 2660
2626 2661 def test_update_form_for_existing_issue
2627 def test_update_edit_form 2662 @request.session[:user_id] = 2
2628 @request.session[:user_id] = 2 2663 xhr :put, :update_form, :project_id => 1,
2629 xhr :put, :new, :project_id => 1,
2630 :id => 1, 2664 :id => 1,
2631 :issue => {:tracker_id => 2, 2665 :issue => {:tracker_id => 2,
2632 :subject => 'This is the test_new issue', 2666 :subject => 'This is the test_new issue',
2633 :description => 'This is the description', 2667 :description => 'This is the description',
2634 :priority_id => 5} 2668 :priority_id => 5}
2643 assert_equal 1, issue.project_id 2677 assert_equal 1, issue.project_id
2644 assert_equal 2, issue.tracker_id 2678 assert_equal 2, issue.tracker_id
2645 assert_equal 'This is the test_new issue', issue.subject 2679 assert_equal 'This is the test_new issue', issue.subject
2646 end 2680 end
2647 2681
2648 def test_update_edit_form_should_keep_issue_author 2682 def test_update_form_for_existing_issue_should_keep_issue_author
2649 @request.session[:user_id] = 3 2683 @request.session[:user_id] = 3
2650 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} 2684 xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2651 assert_response :success 2685 assert_response :success
2652 assert_equal 'text/javascript', response.content_type 2686 assert_equal 'text/javascript', response.content_type
2653 2687
2654 issue = assigns(:issue) 2688 issue = assigns(:issue)
2655 assert_equal User.find(2), issue.author 2689 assert_equal User.find(2), issue.author
2656 assert_equal 2, issue.author_id 2690 assert_equal 2, issue.author_id
2657 assert_not_equal User.current, issue.author 2691 assert_not_equal User.current, issue.author
2658 end 2692 end
2659 2693
2660 def test_update_edit_form_should_propose_transitions_based_on_initial_status 2694 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
2661 @request.session[:user_id] = 2 2695 @request.session[:user_id] = 2
2662 WorkflowTransition.delete_all 2696 WorkflowTransition.delete_all
2663 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) 2697 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) 2698 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) 2699 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2666 2700
2667 xhr :put, :new, :project_id => 1, 2701 xhr :put, :update_form, :project_id => 1,
2668 :id => 2, 2702 :id => 2,
2669 :issue => {:tracker_id => 2, 2703 :issue => {:tracker_id => 2,
2670 :status_id => 5, 2704 :status_id => 5,
2671 :subject => 'This is an issue'} 2705 :subject => 'This is an issue'}
2672 2706
2673 assert_equal 5, assigns(:issue).status_id 2707 assert_equal 5, assigns(:issue).status_id
2674 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort 2708 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2675 end 2709 end
2676 2710
2677 def test_update_edit_form_with_project_change 2711 def test_update_form_for_existing_issue_with_project_change
2678 @request.session[:user_id] = 2 2712 @request.session[:user_id] = 2
2679 xhr :put, :new, :project_id => 1, 2713 xhr :put, :update_form, :project_id => 1,
2680 :id => 1, 2714 :id => 1,
2681 :issue => {:project_id => 2, 2715 :issue => {:project_id => 2,
2682 :tracker_id => 2, 2716 :tracker_id => 2,
2683 :subject => 'This is the test_new issue', 2717 :subject => 'This is the test_new issue',
2684 :description => 'This is the description', 2718 :description => 'This is the description',
2690 assert_kind_of Issue, issue 2724 assert_kind_of Issue, issue
2691 assert_equal 1, issue.id 2725 assert_equal 1, issue.id
2692 assert_equal 2, issue.project_id 2726 assert_equal 2, issue.project_id
2693 assert_equal 2, issue.tracker_id 2727 assert_equal 2, issue.tracker_id
2694 assert_equal 'This is the test_new issue', issue.subject 2728 assert_equal 'This is the test_new issue', issue.subject
2729 end
2730
2731 def test_update_form_should_propose_default_status_for_existing_issue
2732 @request.session[:user_id] = 2
2733 WorkflowTransition.delete_all
2734 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
2735
2736 xhr :put, :update_form, :project_id => 1, :id => 2
2737 assert_response :success
2738 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
2695 end 2739 end
2696 2740
2697 def test_put_update_without_custom_fields_param 2741 def test_put_update_without_custom_fields_param
2698 @request.session[:user_id] = 2 2742 @request.session[:user_id] = 2
2699 ActionMailer::Base.deliveries.clear 2743 ActionMailer::Base.deliveries.clear
2829 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } 2873 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2830 end 2874 end
2831 assert_redirected_to :action => 'show', :id => '1' 2875 assert_redirected_to :action => 'show', :id => '1'
2832 issue.reload 2876 issue.reload
2833 assert_equal 2, issue.status_id 2877 assert_equal 2, issue.status_id
2834 j = Journal.find(:first, :order => 'id DESC') 2878 j = Journal.order('id DESC').first
2835 assert_equal 'Assigned to dlopper', j.notes 2879 assert_equal 'Assigned to dlopper', j.notes
2836 assert_equal 2, j.details.size 2880 assert_equal 2, j.details.size
2837 2881
2838 mail = ActionMailer::Base.deliveries.last 2882 mail = ActionMailer::Base.deliveries.last
2839 assert_mail_body_match "Status changed from New to Assigned", mail 2883 assert_mail_body_match "Status changed from New to Assigned", mail
2846 # anonymous user 2890 # anonymous user
2847 put :update, 2891 put :update,
2848 :id => 1, 2892 :id => 1,
2849 :issue => { :notes => notes } 2893 :issue => { :notes => notes }
2850 assert_redirected_to :action => 'show', :id => '1' 2894 assert_redirected_to :action => 'show', :id => '1'
2851 j = Journal.find(:first, :order => 'id DESC') 2895 j = Journal.order('id DESC').first
2852 assert_equal notes, j.notes 2896 assert_equal notes, j.notes
2853 assert_equal 0, j.details.size 2897 assert_equal 0, j.details.size
2854 assert_equal User.anonymous, j.user 2898 assert_equal User.anonymous, j.user
2855 2899
2856 mail = ActionMailer::Base.deliveries.last 2900 mail = ActionMailer::Base.deliveries.last
2902 end 2946 end
2903 assert_redirected_to :action => 'show', :id => '1' 2947 assert_redirected_to :action => 'show', :id => '1'
2904 2948
2905 issue = Issue.find(1) 2949 issue = Issue.find(1)
2906 2950
2907 j = Journal.find(:first, :order => 'id DESC') 2951 j = Journal.order('id DESC').first
2908 assert_equal '2.5 hours added', j.notes 2952 assert_equal '2.5 hours added', j.notes
2909 assert_equal 0, j.details.size 2953 assert_equal 0, j.details.size
2910 2954
2911 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') 2955 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2912 assert_not_nil t 2956 assert_not_nil t
2941 :issue => {:notes => ''}, 2985 :issue => {:notes => ''},
2942 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 2986 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2943 end 2987 end
2944 2988
2945 assert_redirected_to :action => 'show', :id => '1' 2989 assert_redirected_to :action => 'show', :id => '1'
2946 j = Issue.find(1).journals.find(:first, :order => 'id DESC') 2990 j = Issue.find(1).journals.reorder('id DESC').first
2947 assert j.notes.blank? 2991 assert j.notes.blank?
2948 assert_equal 1, j.details.size 2992 assert_equal 1, j.details.size
2949 assert_equal 'testfile.txt', j.details.first.value 2993 assert_equal 'testfile.txt', j.details.first.value
2950 assert_equal User.anonymous, j.user 2994 assert_equal User.anonymous, j.user
2951 2995
2980 attachment = Attachment.first(:order => 'id DESC') 3024 attachment = Attachment.first(:order => 'id DESC')
2981 assert_equal 'testfile.txt', attachment.filename 3025 assert_equal 'testfile.txt', attachment.filename
2982 assert File.exists?(attachment.diskfile) 3026 assert File.exists?(attachment.diskfile)
2983 assert_nil attachment.container 3027 assert_nil attachment.container
2984 3028
2985 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 3029 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2986 assert_tag 'span', :content => /testfile.txt/ 3030 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
2987 end 3031 end
2988 3032
2989 def test_put_update_with_failure_should_keep_saved_attachments 3033 def test_put_update_with_failure_should_keep_saved_attachments
2990 set_tmp_attachments_directory 3034 set_tmp_attachments_directory
2991 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 3035 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2999 assert_response :success 3043 assert_response :success
3000 assert_template 'edit' 3044 assert_template 'edit'
3001 end 3045 end
3002 end 3046 end
3003 3047
3004 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} 3048 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3005 assert_tag 'span', :content => /testfile.txt/ 3049 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
3006 end 3050 end
3007 3051
3008 def test_put_update_should_attach_saved_attachments 3052 def test_put_update_should_attach_saved_attachments
3009 set_tmp_attachments_directory 3053 set_tmp_attachments_directory
3010 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) 3054 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
3090 end 3134 end
3091 assert_response :success 3135 assert_response :success
3092 assert_template 'edit' 3136 assert_template 'edit'
3093 3137
3094 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3138 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3095 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes 3139 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3096 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } 3140 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3097 end 3141 end
3098 3142
3099 def test_put_update_with_invalid_spent_time_comments_only 3143 def test_put_update_with_invalid_spent_time_comments_only
3100 @request.session[:user_id] = 2 3144 @request.session[:user_id] = 2
3101 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' 3145 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3109 assert_response :success 3153 assert_response :success
3110 assert_template 'edit' 3154 assert_template 'edit'
3111 3155
3112 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3156 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3113 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/} 3157 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/}
3114 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes 3158 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3115 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } 3159 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3116 end 3160 end
3117 3161
3118 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject 3162 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3119 issue = Issue.find(2) 3163 issue = Issue.find(2)
3120 @request.session[:user_id] = 2 3164 @request.session[:user_id] = 2
3165 @request.session[:user_id] = 2 3209 @request.session[:user_id] = 2
3166 get :bulk_edit, :ids => [1, 2] 3210 get :bulk_edit, :ids => [1, 2]
3167 assert_response :success 3211 assert_response :success
3168 assert_template 'bulk_edit' 3212 assert_template 'bulk_edit'
3169 3213
3170 assert_tag :select, :attributes => {:name => 'issue[project_id]'} 3214 assert_select 'ul#bulk-selection' do
3171 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} 3215 assert_select 'li', 2
3172 3216 assert_select 'li a', :text => 'Bug #1'
3173 # Project specific custom field, date type 3217 end
3174 field = CustomField.find(9) 3218
3175 assert !field.is_for_all? 3219 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
3176 assert_equal 'date', field.field_format 3220 assert_select 'input[name=?]', 'ids[]', 2
3177 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} 3221 assert_select 'input[name=?][value=1][type=hidden]', 'ids[]'
3178 3222
3179 # System wide custom field 3223 assert_select 'select[name=?]', 'issue[project_id]'
3180 assert CustomField.find(1).is_for_all? 3224 assert_select 'input[name=?]', 'issue[parent_issue_id]'
3181 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} 3225
3182 3226 # Project specific custom field, date type
3183 # Be sure we don't display inactive IssuePriorities 3227 field = CustomField.find(9)
3184 assert ! IssuePriority.find(15).active? 3228 assert !field.is_for_all?
3185 assert_no_tag :option, :attributes => {:value => '15'}, 3229 assert_equal 'date', field.field_format
3186 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } 3230 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3231
3232 # System wide custom field
3233 assert CustomField.find(1).is_for_all?
3234 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3235
3236 # Be sure we don't display inactive IssuePriorities
3237 assert ! IssuePriority.find(15).active?
3238 assert_select 'select[name=?]', 'issue[priority_id]' do
3239 assert_select 'option[value=15]', 0
3240 end
3241 end
3187 end 3242 end
3188 3243
3189 def test_get_bulk_edit_on_different_projects 3244 def test_get_bulk_edit_on_different_projects
3190 @request.session[:user_id] = 2 3245 @request.session[:user_id] = 2
3191 get :bulk_edit, :ids => [1, 2, 6] 3246 get :bulk_edit, :ids => [1, 2, 6]
3192 assert_response :success 3247 assert_response :success
3193 assert_template 'bulk_edit' 3248 assert_template 'bulk_edit'
3194 3249
3195 # Can not set issues from different projects as children of an issue 3250 # Can not set issues from different projects as children of an issue
3196 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} 3251 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
3197 3252
3198 # Project specific custom field, date type 3253 # Project specific custom field, date type
3199 field = CustomField.find(9) 3254 field = CustomField.find(9)
3200 assert !field.is_for_all? 3255 assert !field.is_for_all?
3201 assert !field.project_ids.include?(Issue.find(6).project_id) 3256 assert !field.project_ids.include?(Issue.find(6).project_id)
3202 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} 3257 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
3203 end 3258 end
3204 3259
3205 def test_get_bulk_edit_with_user_custom_field 3260 def test_get_bulk_edit_with_user_custom_field
3206 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) 3261 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3207 3262
3208 @request.session[:user_id] = 2 3263 @request.session[:user_id] = 2
3209 get :bulk_edit, :ids => [1, 2] 3264 get :bulk_edit, :ids => [1, 2]
3210 assert_response :success 3265 assert_response :success
3211 assert_template 'bulk_edit' 3266 assert_template 'bulk_edit'
3212 3267
3213 assert_tag :select, 3268 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'}, 3269 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
3215 :children => { 3270 end
3216 :only => {:tag => 'option'},
3217 :count => Project.find(1).users.count + 2 # "no change" + "none" options
3218 }
3219 end 3271 end
3220 3272
3221 def test_get_bulk_edit_with_version_custom_field 3273 def test_get_bulk_edit_with_version_custom_field
3222 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) 3274 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3223 3275
3224 @request.session[:user_id] = 2 3276 @request.session[:user_id] = 2
3225 get :bulk_edit, :ids => [1, 2] 3277 get :bulk_edit, :ids => [1, 2]
3226 assert_response :success 3278 assert_response :success
3227 assert_template 'bulk_edit' 3279 assert_template 'bulk_edit'
3228 3280
3229 assert_tag :select, 3281 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
3230 :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, 3282 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3231 :children => { 3283 end
3232 :only => {:tag => 'option'},
3233 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3234 }
3235 end 3284 end
3236 3285
3237 def test_get_bulk_edit_with_multi_custom_field 3286 def test_get_bulk_edit_with_multi_custom_field
3238 field = CustomField.find(1) 3287 field = CustomField.find(1)
3239 field.update_attribute :multiple, true 3288 field.update_attribute :multiple, true
3241 @request.session[:user_id] = 2 3290 @request.session[:user_id] = 2
3242 get :bulk_edit, :ids => [1, 2] 3291 get :bulk_edit, :ids => [1, 2]
3243 assert_response :success 3292 assert_response :success
3244 assert_template 'bulk_edit' 3293 assert_template 'bulk_edit'
3245 3294
3246 assert_tag :select, 3295 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
3247 :attributes => {:name => "issue[custom_field_values][1][]"}, 3296 assert_select 'option', field.possible_values.size + 1 # "none" options
3248 :children => { 3297 end
3249 :only => {:tag => 'option'}, 3298 end
3250 :count => field.possible_values.size + 1 # "none" options 3299
3251 } 3300 def test_bulk_edit_should_propose_to_clear_text_custom_fields
3301 @request.session[:user_id] = 2
3302 get :bulk_edit, :ids => [1, 3]
3303 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
3252 end 3304 end
3253 3305
3254 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues 3306 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3255 WorkflowTransition.delete_all 3307 WorkflowTransition.delete_all
3256 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) 3308 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) 3309 :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) 3310 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) 3311 :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) 3312 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) 3313 :old_status_id => 1, :new_status_id => 4)
3314 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3315 :old_status_id => 2, :new_status_id => 1)
3316 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3317 :old_status_id => 2, :new_status_id => 3)
3318 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
3319 :old_status_id => 2, :new_status_id => 5)
3262 @request.session[:user_id] = 2 3320 @request.session[:user_id] = 2
3263 get :bulk_edit, :ids => [1, 2] 3321 get :bulk_edit, :ids => [1, 2]
3264 3322
3265 assert_response :success 3323 assert_response :success
3266 statuses = assigns(:available_statuses) 3324 statuses = assigns(:available_statuses)
3267 assert_not_nil statuses 3325 assert_not_nil statuses
3268 assert_equal [1, 3], statuses.map(&:id).sort 3326 assert_equal [1, 3], statuses.map(&:id).sort
3269 3327
3270 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}, 3328 assert_select 'select[name=?]', 'issue[status_id]' do
3271 :children => {:count => 3} # 2 statuses + "no change" option 3329 assert_select 'option', 3 # 2 statuses + "no change" option
3330 end
3272 end 3331 end
3273 3332
3274 def test_bulk_edit_should_propose_target_project_open_shared_versions 3333 def test_bulk_edit_should_propose_target_project_open_shared_versions
3275 @request.session[:user_id] = 2 3334 @request.session[:user_id] = 2
3276 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} 3335 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3277 assert_response :success 3336 assert_response :success
3278 assert_template 'bulk_edit' 3337 assert_template 'bulk_edit'
3279 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort 3338 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3280 assert_tag 'select', 3339
3281 :attributes => {:name => 'issue[fixed_version_id]'}, 3340 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
3282 :descendant => {:tag => 'option', :content => '2.0'} 3341 assert_select 'option', :text => '2.0'
3342 end
3283 end 3343 end
3284 3344
3285 def test_bulk_edit_should_propose_target_project_categories 3345 def test_bulk_edit_should_propose_target_project_categories
3286 @request.session[:user_id] = 2 3346 @request.session[:user_id] = 2
3287 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} 3347 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3288 assert_response :success 3348 assert_response :success
3289 assert_template 'bulk_edit' 3349 assert_template 'bulk_edit'
3290 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort 3350 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3291 assert_tag 'select', 3351
3292 :attributes => {:name => 'issue[category_id]'}, 3352 assert_select 'select[name=?]', 'issue[category_id]' do
3293 :descendant => {:tag => 'option', :content => 'Recipes'} 3353 assert_select 'option', :text => 'Recipes'
3354 end
3294 end 3355 end
3295 3356
3296 def test_bulk_update 3357 def test_bulk_update
3297 @request.session[:user_id] = 2 3358 @request.session[:user_id] = 2
3298 # update issues priority 3359 # update issues priority
3304 assert_response 302 3365 assert_response 302
3305 # check that the issues were updated 3366 # check that the issues were updated
3306 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} 3367 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
3307 3368
3308 issue = Issue.find(1) 3369 issue = Issue.find(1)
3309 journal = issue.journals.find(:first, :order => 'created_on DESC') 3370 journal = issue.journals.reorder('created_on DESC').first
3310 assert_equal '125', issue.custom_value_for(2).value 3371 assert_equal '125', issue.custom_value_for(2).value
3311 assert_equal 'Bulk editing', journal.notes 3372 assert_equal 'Bulk editing', journal.notes
3312 assert_equal 1, journal.details.size 3373 assert_equal 1, journal.details.size
3313 end 3374 end
3314 3375
3339 assert_response 302 3400 assert_response 302
3340 # check that the issues were updated 3401 # check that the issues were updated
3341 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) 3402 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3342 3403
3343 issue = Issue.find(1) 3404 issue = Issue.find(1)
3344 journal = issue.journals.find(:first, :order => 'created_on DESC') 3405 journal = issue.journals.reorder('created_on DESC').first
3345 assert_equal '125', issue.custom_value_for(2).value 3406 assert_equal '125', issue.custom_value_for(2).value
3346 assert_equal 'Bulk editing', journal.notes 3407 assert_equal 'Bulk editing', journal.notes
3347 assert_equal 1, journal.details.size 3408 assert_equal 1, journal.details.size
3348 end 3409 end
3349 3410
3441 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes 3502 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 3503 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3443 end 3504 end
3444 3505
3445 def test_bulk_update_parent_id 3506 def test_bulk_update_parent_id
3507 IssueRelation.delete_all
3446 @request.session[:user_id] = 2 3508 @request.session[:user_id] = 2
3447 post :bulk_update, :ids => [1, 3], 3509 post :bulk_update, :ids => [1, 3],
3448 :notes => 'Bulk editing parent', 3510 :notes => 'Bulk editing parent',
3449 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} 3511 :issue => {:priority_id => '', :assigned_to_id => '',
3450 3512 :status_id => '', :parent_issue_id => '2'}
3451 assert_response 302 3513 assert_response 302
3452 parent = Issue.find(2) 3514 parent = Issue.find(2)
3453 assert_equal parent.id, Issue.find(1).parent_id 3515 assert_equal parent.id, Issue.find(1).parent_id
3454 assert_equal parent.id, Issue.find(3).parent_id 3516 assert_equal parent.id, Issue.find(3).parent_id
3455 assert_equal [1, 3], parent.children.collect(&:id).sort 3517 assert_equal [1, 3], parent.children.collect(&:id).sort
3464 :custom_field_values => {'2' => '777'}} 3526 :custom_field_values => {'2' => '777'}}
3465 3527
3466 assert_response 302 3528 assert_response 302
3467 3529
3468 issue = Issue.find(1) 3530 issue = Issue.find(1)
3469 journal = issue.journals.find(:first, :order => 'created_on DESC') 3531 journal = issue.journals.reorder('created_on DESC').first
3470 assert_equal '777', issue.custom_value_for(2).value 3532 assert_equal '777', issue.custom_value_for(2).value
3471 assert_equal 1, journal.details.size 3533 assert_equal 1, journal.details.size
3472 assert_equal '125', journal.details.first.old_value 3534 assert_equal '125', journal.details.first.old_value
3473 assert_equal '777', journal.details.first.value 3535 assert_equal '777', journal.details.first.value
3474 end 3536 end
3553 3615
3554 assert_response :redirect 3616 assert_response :redirect
3555 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier 3617 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3556 end 3618 end
3557 3619
3558 def test_bulk_update_with_failure_should_set_flash 3620 def test_bulk_update_with_all_failures_should_show_errors
3559 @request.session[:user_id] = 2 3621 @request.session[:user_id] = 2
3560 Issue.update_all("subject = ''", "id = 2") # Make it invalid 3622 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
3561 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6} 3623
3562 3624 assert_response :success
3563 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook' 3625 assert_template 'bulk_edit'
3564 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error] 3626 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
3627 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
3628
3629 assert_equal [1, 2], assigns[:issues].map(&:id)
3630 end
3631
3632 def test_bulk_update_with_some_failures_should_show_errors
3633 issue1 = Issue.generate!(:start_date => '2013-05-12')
3634 issue2 = Issue.generate!(:start_date => '2013-05-15')
3635 issue3 = Issue.generate!
3636 @request.session[:user_id] = 2
3637 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
3638 :issue => {:due_date => '2013-05-01'}
3639 assert_response :success
3640 assert_template 'bulk_edit'
3641 assert_select '#errorExplanation span',
3642 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
3643 assert_select '#errorExplanation ul li',
3644 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
3645 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
3646 end
3647
3648 def test_bulk_update_with_failure_should_preserved_form_values
3649 @request.session[:user_id] = 2
3650 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
3651
3652 assert_response :success
3653 assert_template 'bulk_edit'
3654 assert_select 'select[name=?]', 'issue[tracker_id]' do
3655 assert_select 'option[value=2][selected=selected]'
3656 end
3657 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
3565 end 3658 end
3566 3659
3567 def test_get_bulk_copy 3660 def test_get_bulk_copy
3568 @request.session[:user_id] = 2 3661 @request.session[:user_id] = 2
3569 get :bulk_edit, :ids => [1, 2, 3], :copy => '1' 3662 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3593 end 3686 end
3594 3687
3595 def test_bulk_copy_should_allow_not_changing_the_issue_attributes 3688 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3596 @request.session[:user_id] = 2 3689 @request.session[:user_id] = 2
3597 issues = [ 3690 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), 3691 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) 3692 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
3693 :assigned_to_id => nil),
3694 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
3695 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
3696 :assigned_to_id => 3)
3600 ] 3697 ]
3601
3602 assert_difference 'Issue.count', issues.size do 3698 assert_difference 'Issue.count', issues.size do
3603 post :bulk_update, :ids => issues.map(&:id), :copy => '1', 3699 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3604 :issue => { 3700 :issue => {
3605 :project_id => '', :tracker_id => '', :assigned_to_id => '', 3701 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3606 :status_id => '', :start_date => '', :due_date => '' 3702 :status_id => '', :start_date => '', :due_date => ''
3619 end 3715 end
3620 end 3716 end
3621 3717
3622 def test_bulk_copy_should_allow_changing_the_issue_attributes 3718 def test_bulk_copy_should_allow_changing_the_issue_attributes
3623 # Fixes random test failure with Mysql 3719 # Fixes random test failure with Mysql
3624 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) 3720 # where Issue.where(:project_id => 2).limit(2).order('id desc')
3625 # doesn't return the expected results 3721 # doesn't return the expected results
3626 Issue.delete_all("project_id=2") 3722 Issue.delete_all("project_id=2")
3627 3723
3628 @request.session[:user_id] = 2 3724 @request.session[:user_id] = 2
3629 assert_difference 'Issue.count', 2 do 3725 assert_difference 'Issue.count', 2 do
3634 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31' 3730 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3635 } 3731 }
3636 end 3732 end
3637 end 3733 end
3638 3734
3639 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) 3735 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
3640 assert_equal 2, copied_issues.size 3736 assert_equal 2, copied_issues.size
3641 copied_issues.each do |issue| 3737 copied_issues.each do |issue|
3642 assert_equal 2, issue.project_id, "Project is incorrect" 3738 assert_equal 2, issue.project_id, "Project is incorrect"
3643 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect" 3739 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3644 assert_equal 1, issue.status_id, "Status is incorrect" 3740 assert_equal 1, issue.status_id, "Status is incorrect"
3655 :issue => { 3751 :issue => {
3656 :project_id => '', :tracker_id => '', :assigned_to_id => '4', 3752 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3657 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' 3753 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3658 } 3754 }
3659 end 3755 end
3660
3661 issue = Issue.first(:order => 'id DESC') 3756 issue = Issue.first(:order => 'id DESC')
3662 assert_equal 1, issue.journals.size 3757 assert_equal 1, issue.journals.size
3663 journal = issue.journals.first 3758 journal = issue.journals.first
3664 assert_equal 0, journal.details.size 3759 assert_equal 1, journal.details.size
3665 assert_equal 'Copying one issue', journal.notes 3760 assert_equal 'Copying one issue', journal.notes
3666 end 3761 end
3667 3762
3668 def test_bulk_copy_should_allow_not_copying_the_attachments 3763 def test_bulk_copy_should_allow_not_copying_the_attachments
3669 attachment_count = Issue.find(3).attachments.size 3764 attachment_count = Issue.find(3).attachments.size
3755 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' 3850 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3756 issue = Issue.first(:order => 'id DESC') 3851 issue = Issue.first(:order => 'id DESC')
3757 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue 3852 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3758 end 3853 end
3759 3854
3855 def test_bulk_copy_with_all_failures_should_display_errors
3856 @request.session[:user_id] = 2
3857 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
3858
3859 assert_response :success
3860 end
3861
3760 def test_destroy_issue_with_no_time_entries 3862 def test_destroy_issue_with_no_time_entries
3761 assert_nil TimeEntry.find_by_issue_id(2) 3863 assert_nil TimeEntry.find_by_issue_id(2)
3762 @request.session[:user_id] = 2 3864 @request.session[:user_id] = 2
3763 3865
3764 assert_difference 'Issue.count', -1 do 3866 assert_difference 'Issue.count', -1 do
3776 end 3878 end
3777 assert_response :success 3879 assert_response :success
3778 assert_template 'destroy' 3880 assert_template 'destroy'
3779 assert_not_nil assigns(:hours) 3881 assert_not_nil assigns(:hours)
3780 assert Issue.find_by_id(1) && Issue.find_by_id(3) 3882 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3781 assert_tag 'form', 3883
3782 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}} 3884 assert_select 'form' do
3885 assert_select 'input[name=_method][value=delete]'
3886 end
3783 end 3887 end
3784 3888
3785 def test_destroy_issues_and_destroy_time_entries 3889 def test_destroy_issues_and_destroy_time_entries
3786 @request.session[:user_id] = 2 3890 @request.session[:user_id] = 2
3787 3891
3843 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' 3947 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3844 end 3948 end
3845 assert_response 302 3949 assert_response 302
3846 end 3950 end
3847 3951
3952 def test_destroy_invalid_should_respond_with_404
3953 @request.session[:user_id] = 2
3954 assert_no_difference 'Issue.count' do
3955 delete :destroy, :id => 999
3956 end
3957 assert_response 404
3958 end
3959
3848 def test_default_search_scope 3960 def test_default_search_scope
3849 get :index 3961 get :index
3850 assert_tag :div, :attributes => {:id => 'quick-search'}, 3962
3851 :child => {:tag => 'form', 3963 assert_select 'div#quick-search form' do
3852 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} 3964 assert_select 'input[name=issues][value=1][type=hidden]'
3965 end
3853 end 3966 end
3854 end 3967 end