issues_controller_test.rb.patch

Pavel Rosick√Ĺ, 2015-09-04 23:49

Download (10.2 KB)

View differences:

issues_controller_test.rb (working copy)
530 530
      str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
531 531
      issue = Issue.generate!(:subject => str_utf8)
532 532

  
533
      get :index, :project_id => 1, 
534
                  :f => ['subject'], 
533
      get :index, :project_id => 1,
534
                  :f => ['subject'],
535 535
                  :op => '=', :values => [str_utf8],
536 536
                  :format => 'csv'
537 537
      assert_equal 'text/csv; header=present', @response.content_type
......
549 549
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
550 550
      issue = Issue.generate!(:subject => str_utf8)
551 551

  
552
      get :index, :project_id => 1, 
553
                  :f => ['subject'], 
552
      get :index, :project_id => 1,
553
                  :f => ['subject'],
554 554
                  :op => '=', :values => [str_utf8],
555 555
                  :c => ['status', 'subject'],
556 556
                  :format => 'csv',
......
572 572
      str1  = "test_index_csv_tw"
573 573
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
574 574

  
575
      get :index, :project_id => 1, 
576
                  :f => ['subject'], 
575
      get :index, :project_id => 1,
576
                  :f => ['subject'],
577 577
                  :op => '=', :values => [str1],
578 578
                  :c => ['estimated_hours', 'subject'],
579 579
                  :format => 'csv',
......
589 589
      str1  = "test_index_csv_fr"
590 590
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
591 591

  
592
      get :index, :project_id => 1, 
593
                  :f => ['subject'], 
592
      get :index, :project_id => 1,
593
                  :f => ['subject'],
594 594
                  :op => '=', :values => [str1],
595 595
                  :c => ['estimated_hours', 'subject'],
596 596
                  :format => 'csv',
......
667 667
    Setting.issue_list_default_columns = %w(subject author)
668 668
    get :index, :sort => 'tracker'
669 669
  end
670
  
670

  
671 671
  def test_index_sort_by_assigned_to
672 672
    get :index, :sort => 'assigned_to'
673 673
    assert_response :success
......
675 675
    assert_equal assignees.sort, assignees
676 676
    assert_select 'table.issues.sort-by-assigned-to.sort-asc'
677 677
  end
678
  
678

  
679 679
  def test_index_sort_by_assigned_to_desc
680 680
    get :index, :sort => 'assigned_to:desc'
681 681
    assert_response :success
......
683 683
    assert_equal assignees.sort.reverse, assignees
684 684
    assert_select 'table.issues.sort-by-assigned-to.sort-desc'
685 685
  end
686
  
686

  
687 687
  def test_index_group_by_assigned_to
688 688
    get :index, :group_by => 'assigned_to', :sort => 'priority'
689 689
    assert_response :success
690 690
  end
691
  
691

  
692 692
  def test_index_sort_by_author
693 693
    get :index, :sort => 'author'
694 694
    assert_response :success
695 695
    authors = assigns(:issues).collect(&:author)
696 696
    assert_equal authors.sort, authors
697 697
  end
698
  
698

  
699 699
  def test_index_sort_by_author_desc
700 700
    get :index, :sort => 'author:desc'
701 701
    assert_response :success
702 702
    authors = assigns(:issues).collect(&:author)
703 703
    assert_equal authors.sort.reverse, authors
704 704
  end
705
  
705

  
706 706
  def test_index_group_by_author
707 707
    get :index, :group_by => 'author', :sort => 'priority'
708 708
    assert_response :success
709 709
  end
710
  
710

  
711 711
  def test_index_sort_by_spent_hours
712 712
    get :index, :sort => 'spent_hours:desc'
713 713
    assert_response :success
714 714
    hours = assigns(:issues).collect(&:spent_hours)
715 715
    assert_equal hours.sort.reverse, hours
716 716
  end
717
  
717

  
718 718
  def test_index_sort_by_total_spent_hours
719 719
    get :index, :sort => 'total_spent_hours:desc'
720 720
    assert_response :success
......
1224 1224

  
1225 1225
  def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1226 1226
    @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1227
    
1227

  
1228 1228
    %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1229 1229
      @request.session['issues_index_sort'] = assoc_sort
1230 1230

  
......
1442 1442
  end
1443 1443

  
1444 1444
  def test_show_export_to_pdf
1445
    issue = Issue.find(3) 
1445
    issue = Issue.find(3)
1446 1446
    assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
1447 1447
    get :show, :id => 3, :format => 'pdf'
1448 1448
    assert_response :success
......
2103 2103
    assert_select_error /Bar cannot be blank/i
2104 2104
  end
2105 2105

  
2106
  def test_create_should_validate_required_list_fields
2107
    cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
2108
    cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
2109
    WorkflowPermission.delete_all
2110
    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
2111
    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
2112
    @request.session[:user_id] = 2
2113

  
2114
    assert_no_difference 'Issue.count' do
2115
      post :create, :project_id => 1, :issue => {
2116
        :tracker_id => 2,
2117
        :status_id => 1,
2118
        :subject => 'Test',
2119
        :start_date => '',
2120
        :due_date => '',
2121
        :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
2122
      }
2123
      assert_response :success
2124
      assert_template 'new'
2125
    end
2126

  
2127
    assert_select_error /Foo cannot be blank/i
2128
    assert_select_error /Bar cannot be blank/i
2129
  end
2130

  
2106 2131
  def test_create_should_ignore_readonly_fields
2107 2132
    cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
2108 2133
    cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
......
2130 2155
    assert_nil issue.custom_field_value(cf2)
2131 2156
  end
2132 2157

  
2158
  def test_create_should_ignore_readonly_list_fields
2159
    cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
2160
    cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
2161
    WorkflowPermission.delete_all
2162
    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'readonly')
2163
    WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
2164
    @request.session[:user_id] = 2
2165

  
2166
    assert_difference 'Issue.count' do
2167
      post :create, :project_id => 1, :issue => {
2168
        :tracker_id => 2,
2169
        :status_id => 1,
2170
        :subject => 'Test',
2171
        :start_date => '2012-07-14',
2172
        :due_date => '2012-07-16',
2173
        :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => ['value2']}
2174
      }
2175
      assert_response 302
2176
    end
2177

  
2178
    issue = Issue.order('id DESC').first
2179
    assert_equal nil, issue.custom_field_value(cf1)
2180
    assert_equal [nil], issue.custom_field_value(cf2)
2181
  end
2182

  
2133 2183
  def test_post_create_with_watchers
2134 2184
    @request.session[:user_id] = 2
2135 2185
    ActionMailer::Base.deliveries.clear
......
2312 2362
                              :custom_field_values => {'2' => 'Value for field 2'}}
2313 2363
      end
2314 2364
      assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2315
  
2365

  
2316 2366
      assert_equal 1, ActionMailer::Base.deliveries.size
2317 2367
    end
2318 2368
  end
......
2482 2532
    get :new, :project_id => 1
2483 2533
    assert_response :success
2484 2534
    assert_template 'new'
2485
    
2535

  
2486 2536
    issue = assigns(:issue)
2487 2537
    assert_not_nil issue.default_status
2488 2538

  
......
2862 2912
  def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2863 2913
    @request.session[:user_id] = 2
2864 2914
    Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2865
    
2915

  
2866 2916
    get :edit, :id => 1
2867 2917
    assert_select 'input[name=?]', 'time_entry[hours]'
2868 2918
  end
......
2870 2920
  def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2871 2921
    @request.session[:user_id] = 2
2872 2922
    Role.find_by_name('Manager').remove_permission! :log_time
2873
    
2923

  
2874 2924
    get :edit, :id => 1
2875 2925
    assert_select 'input[name=?]', 'time_entry[hours]', 0
2876 2926
  end
......
3483 3533

  
3484 3534
      assert_select 'select[name=?]', 'issue[project_id]'
3485 3535
      assert_select 'input[name=?]', 'issue[parent_issue_id]'
3486
  
3536

  
3487 3537
      # Project specific custom field, date type
3488 3538
      field = CustomField.find(9)
3489 3539
      assert !field.is_for_all?
3490 3540
      assert_equal 'date', field.field_format
3491 3541
      assert_select 'input[name=?]', 'issue[custom_field_values][9]'
3492
  
3542

  
3493 3543
      # System wide custom field
3494 3544
      assert CustomField.find(1).is_for_all?
3495 3545
      assert_select 'select[name=?]', 'issue[custom_field_values][1]'
3496
  
3546

  
3497 3547
      # Be sure we don't display inactive IssuePriorities
3498 3548
      assert ! IssuePriority.find(15).active?
3499 3549
      assert_select 'select[name=?]', 'issue[priority_id]' do
......
3959 4009
      assert_select 'option[value="2"]'
3960 4010
    end
3961 4011
  end
3962
  
4012

  
3963 4013
  def test_bulk_copy_to_another_project
3964 4014
    @request.session[:user_id] = 2
3965 4015
    assert_difference 'Issue.count', 2 do
......
4012 4062
                    :assigned_to_id => 3)
4013 4063
    ]
4014 4064
    assert_difference 'Issue.count', issues.size do
4015
      post :bulk_update, :ids => issues.map(&:id), :copy => '1', 
4065
      post :bulk_update, :ids => issues.map(&:id), :copy => '1',
4016 4066
           :issue => {
4017 4067
             :project_id => '', :tracker_id => '', :assigned_to_id => '',
4018 4068
             :status_id => '', :start_date => '', :due_date => ''
......
4040 4090
    @request.session[:user_id] = 2
4041 4091
    assert_difference 'Issue.count', 2 do
4042 4092
      assert_no_difference 'Project.find(1).issues.count' do
4043
        post :bulk_update, :ids => [1, 2], :copy => '1', 
4093
        post :bulk_update, :ids => [1, 2], :copy => '1',
4044 4094
             :issue => {
4045 4095
               :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
4046 4096
               :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'