annotate test/functional/issue_moves_controller_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children
rev   line source
Chris@119 1 require File.expand_path('../../test_helper', __FILE__)
Chris@14 2
Chris@14 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@14 13
Chris@14 14 def setup
Chris@14 15 User.current = nil
Chris@14 16 end
Chris@14 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@14 37 def test_create_one_issue_to_another_project
Chris@14 38 @request.session[:user_id] = 2
Chris@14 39 post :create, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
Chris@14 40 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@14 41 assert_equal 2, Issue.find(1).project_id
Chris@14 42 end
Chris@14 43
Chris@14 44 def test_create_one_issue_to_another_project_should_follow_when_needed
Chris@14 45 @request.session[:user_id] = 2
Chris@14 46 post :create, :id => 1, :new_project_id => 2, :follow => '1'
Chris@14 47 assert_redirected_to '/issues/1'
Chris@14 48 end
Chris@14 49
Chris@14 50 def test_bulk_create_to_another_project
Chris@14 51 @request.session[:user_id] = 2
Chris@14 52 post :create, :ids => [1, 2], :new_project_id => 2
Chris@14 53 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@14 54 # Issues moved to project 2
Chris@14 55 assert_equal 2, Issue.find(1).project_id
Chris@14 56 assert_equal 2, Issue.find(2).project_id
Chris@14 57 # No tracker change
Chris@14 58 assert_equal 1, Issue.find(1).tracker_id
Chris@14 59 assert_equal 2, Issue.find(2).tracker_id
Chris@14 60 end
Chris@909 61
Chris@14 62 def test_bulk_create_to_another_tracker
Chris@14 63 @request.session[:user_id] = 2
Chris@14 64 post :create, :ids => [1, 2], :new_tracker_id => 2
Chris@14 65 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@14 66 assert_equal 2, Issue.find(1).tracker_id
Chris@14 67 assert_equal 2, Issue.find(2).tracker_id
Chris@14 68 end
Chris@14 69
chris@37 70 context "#create via bulk move" do
chris@37 71 setup do
chris@37 72 @request.session[:user_id] = 2
chris@37 73 end
Chris@909 74
chris@37 75 should "allow changing the issue priority" do
chris@37 76 post :create, :ids => [1, 2], :priority_id => 6
chris@37 77
chris@37 78 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
chris@37 79 assert_equal 6, Issue.find(1).priority_id
chris@37 80 assert_equal 6, Issue.find(2).priority_id
chris@37 81
chris@37 82 end
chris@37 83
chris@37 84 should "allow adding a note when moving" do
chris@37 85 post :create, :ids => [1, 2], :notes => 'Moving two issues'
chris@37 86
chris@37 87 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@119 88 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
Chris@119 89 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
chris@37 90
chris@37 91 end
Chris@909 92
chris@37 93 end
chris@37 94
Chris@14 95 def test_bulk_copy_to_another_project
Chris@14 96 @request.session[:user_id] = 2
Chris@14 97 assert_difference 'Issue.count', 2 do
Chris@14 98 assert_no_difference 'Project.find(1).issues.count' do
Chris@14 99 post :create, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
Chris@14 100 end
Chris@14 101 end
chris@37 102 assert_redirected_to '/projects/ecookbook/issues'
Chris@14 103 end
Chris@14 104
Chris@14 105 context "#create via bulk copy" do
Chris@14 106 should "allow not changing the issue's attributes" do
Chris@14 107 @request.session[:user_id] = 2
Chris@14 108 issue_before_move = Issue.find(1)
Chris@14 109 assert_difference 'Issue.count', 1 do
Chris@14 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@14 115 end
Chris@14 116 end
Chris@14 117 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
Chris@14 118 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
Chris@14 119 assert_equal issue_before_move.status_id, issue_after_move.status_id
Chris@14 120 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
Chris@14 121 end
Chris@909 122
Chris@14 123 should "allow changing the issue's attributes" do
Chris@14 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@14 127 Issue.delete_all("project_id=2")
Chris@909 128
Chris@14 129 @request.session[:user_id] = 2
Chris@14 130 assert_difference 'Issue.count', 2 do
Chris@14 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@14 136 end
Chris@14 137 end
Chris@14 138
Chris@14 139 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
Chris@14 140 assert_equal 2, copied_issues.size
Chris@14 141 copied_issues.each do |issue|
Chris@14 142 assert_equal 2, issue.project_id, "Project is incorrect"
Chris@14 143 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
Chris@14 144 assert_equal 3, issue.status_id, "Status is incorrect"
Chris@14 145 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
Chris@14 146 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
Chris@14 147 end
Chris@14 148 end
Chris@441 149
Chris@441 150 should "allow adding a note when copying" do
Chris@441 151 @request.session[:user_id] = 2
Chris@441 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@441 157 end
Chris@909 158
Chris@441 159 issue = Issue.first(:order => 'id DESC')
Chris@441 160 assert_equal 1, issue.journals.size
Chris@441 161 journal = issue.journals.first
Chris@441 162 assert_equal 0, journal.details.size
Chris@441 163 assert_equal 'Copying one issue', journal.notes
Chris@441 164 end
Chris@14 165 end
Chris@909 166
Chris@14 167 def test_copy_to_another_project_should_follow_when_needed
Chris@14 168 @request.session[:user_id] = 2
Chris@14 169 post :create, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
Chris@14 170 issue = Issue.first(:order => 'id DESC')
Chris@14 171 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
Chris@14 172 end
Chris@14 173
Chris@14 174 end