annotate .svn/pristine/de/de71f387d0c606eebf684b499bd4901c9d91a85f.svn-base @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 require File.expand_path('../../test_helper', __FILE__)
Chris@909 2
Chris@909 3 class IssueMovesControllerTest < ActionController::TestCase
Chris@909 4 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@909 5 :enumerations, :users, :issue_categories,
Chris@909 6 :projects_trackers,
Chris@909 7 :roles,
Chris@909 8 :member_roles,
Chris@909 9 :members,
Chris@909 10 :enabled_modules,
Chris@909 11 :workflows,
Chris@909 12 :journals, :journal_details
Chris@909 13
Chris@909 14 def setup
Chris@909 15 User.current = nil
Chris@909 16 end
Chris@909 17
Chris@909 18 def test_get_issue_moves_new
Chris@909 19 @request.session[:user_id] = 2
Chris@909 20 get :new, :id => 1
Chris@909 21
Chris@909 22 assert_tag :tag => 'option', :content => 'eCookbook',
Chris@909 23 :attributes => { :value => '1', :selected => 'selected' }
Chris@909 24 %w(new_tracker_id status_id priority_id assigned_to_id).each do |field|
Chris@909 25 assert_tag :tag => 'option', :content => '(No change)', :attributes => { :value => '' },
Chris@909 26 :parent => {:tag => 'select', :attributes => {:id => field}}
Chris@909 27 assert_no_tag :tag => 'option', :attributes => {:selected => 'selected'},
Chris@909 28 :parent => {:tag => 'select', :attributes => {:id => field}}
Chris@909 29 end
Chris@909 30
Chris@909 31 # Be sure we don't include inactive enumerations
Chris@909 32 assert ! IssuePriority.find(15).active?
Chris@909 33 assert_no_tag :option, :attributes => {:value => '15'},
Chris@909 34 :parent => {:tag => 'select', :attributes => {:id => 'priority_id'} }
Chris@909 35 end
Chris@909 36
Chris@909 37 def test_create_one_issue_to_another_project
Chris@909 38 @request.session[:user_id] = 2
Chris@909 39 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
Chris@909 40 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@909 41 assert_equal 2, Issue.find(1).project_id
Chris@909 42 end
Chris@909 43
Chris@909 44 def test_create_one_issue_to_another_project_should_follow_when_needed
Chris@909 45 @request.session[:user_id] = 2
Chris@909 46 post :create, :id => 1, :new_project_id => 2, :follow => '1'
Chris@909 47 assert_redirected_to '/issues/1'
Chris@909 48 end
Chris@909 49
Chris@909 50 def test_bulk_create_to_another_project
Chris@909 51 @request.session[:user_id] = 2
Chris@909 52 post :create, :ids => [1, 2], :new_project_id => 2
Chris@909 53 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@909 54 # Issues moved to project 2
Chris@909 55 assert_equal 2, Issue.find(1).project_id
Chris@909 56 assert_equal 2, Issue.find(2).project_id
Chris@909 57 # No tracker change
Chris@909 58 assert_equal 1, Issue.find(1).tracker_id
Chris@909 59 assert_equal 2, Issue.find(2).tracker_id
Chris@909 60 end
Chris@909 61
Chris@909 62 def test_bulk_create_to_another_tracker
Chris@909 63 @request.session[:user_id] = 2
Chris@909 64 post :create, :ids => [1, 2], :new_tracker_id => 2
Chris@909 65 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@909 66 assert_equal 2, Issue.find(1).tracker_id
Chris@909 67 assert_equal 2, Issue.find(2).tracker_id
Chris@909 68 end
Chris@909 69
Chris@909 70 context "#create via bulk move" do
Chris@909 71 setup do
Chris@909 72 @request.session[:user_id] = 2
Chris@909 73 end
Chris@909 74
Chris@909 75 should "allow changing the issue priority" do
Chris@909 76 post :create, :ids => [1, 2], :priority_id => 6
Chris@909 77
Chris@909 78 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@909 79 assert_equal 6, Issue.find(1).priority_id
Chris@909 80 assert_equal 6, Issue.find(2).priority_id
Chris@909 81
Chris@909 82 end
Chris@909 83
Chris@909 84 should "allow adding a note when moving" do
Chris@909 85 post :create, :ids => [1, 2], :notes => 'Moving two issues'
Chris@909 86
Chris@909 87 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@909 88 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
Chris@909 89 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
Chris@909 90
Chris@909 91 end
Chris@909 92
Chris@909 93 end
Chris@909 94
Chris@909 95 def test_bulk_copy_to_another_project
Chris@909 96 @request.session[:user_id] = 2
Chris@909 97 assert_difference 'Issue.count', 2 do
Chris@909 98 assert_no_difference 'Project.find(1).issues.count' do
Chris@909 99 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
Chris@909 100 end
Chris@909 101 end
Chris@909 102 assert_redirected_to '/projects/ecookbook/issues'
Chris@909 103 end
Chris@909 104
Chris@909 105 context "#create via bulk copy" do
Chris@909 106 should "allow not changing the issue's attributes" do
Chris@909 107 @request.session[:user_id] = 2
Chris@909 108 issue_before_move = Issue.find(1)
Chris@909 109 assert_difference 'Issue.count', 1 do
Chris@909 110 assert_no_difference 'Project.find(1).issues.count' do
Chris@909 111 post :create, :ids => [1], :new_project_id => 2,
Chris@909 112 :copy_options => {:copy => '1'}, :new_tracker_id => '',
Chris@909 113 :assigned_to_id => '', :status_id => '',
Chris@909 114 :start_date => '', :due_date => ''
Chris@909 115 end
Chris@909 116 end
Chris@909 117 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
Chris@909 118 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
Chris@909 119 assert_equal issue_before_move.status_id, issue_after_move.status_id
Chris@909 120 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
Chris@909 121 end
Chris@909 122
Chris@909 123 should "allow changing the issue's attributes" do
Chris@909 124 # Fixes random test failure with Mysql
Chris@909 125 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
Chris@909 126 # doesn't return the expected results
Chris@909 127 Issue.delete_all("project_id=2")
Chris@909 128
Chris@909 129 @request.session[:user_id] = 2
Chris@909 130 assert_difference 'Issue.count', 2 do
Chris@909 131 assert_no_difference 'Project.find(1).issues.count' do
Chris@909 132 post :create, :ids => [1, 2], :new_project_id => 2,
Chris@909 133 :copy_options => {:copy => '1'}, :new_tracker_id => '',
Chris@909 134 :assigned_to_id => 4, :status_id => 3,
Chris@909 135 :start_date => '2009-12-01', :due_date => '2009-12-31'
Chris@909 136 end
Chris@909 137 end
Chris@909 138
Chris@909 139 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
Chris@909 140 assert_equal 2, copied_issues.size
Chris@909 141 copied_issues.each do |issue|
Chris@909 142 assert_equal 2, issue.project_id, "Project is incorrect"
Chris@909 143 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
Chris@909 144 assert_equal 3, issue.status_id, "Status is incorrect"
Chris@909 145 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
Chris@909 146 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
Chris@909 147 end
Chris@909 148 end
Chris@909 149
Chris@909 150 should "allow adding a note when copying" do
Chris@909 151 @request.session[:user_id] = 2
Chris@909 152 assert_difference 'Issue.count', 1 do
Chris@909 153 post :create, :ids => [1], :copy_options => {:copy => '1'},
Chris@909 154 :notes => 'Copying one issue', :new_tracker_id => '',
Chris@909 155 :assigned_to_id => 4, :status_id => 3,
Chris@909 156 :start_date => '2009-12-01', :due_date => '2009-12-31'
Chris@909 157 end
Chris@909 158
Chris@909 159 issue = Issue.first(:order => 'id DESC')
Chris@909 160 assert_equal 1, issue.journals.size
Chris@909 161 journal = issue.journals.first
Chris@909 162 assert_equal 0, journal.details.size
Chris@909 163 assert_equal 'Copying one issue', journal.notes
Chris@909 164 end
Chris@909 165 end
Chris@909 166
Chris@909 167 def test_copy_to_another_project_should_follow_when_needed
Chris@909 168 @request.session[:user_id] = 2
Chris@909 169 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
Chris@909 170 issue = Issue.first(:order => 'id DESC')
Chris@909 171 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
Chris@909 172 end
Chris@909 173
Chris@909 174 end