annotate test/functional/issues_controller_test.rb @ 1628:9c5f8e24dadc live tip

Quieten this cron script
author Chris Cannam
date Tue, 25 Aug 2020 11:38:49 +0100
parents dffacf8a6908
children
rev   line source
Chris@0 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19
Chris@0 20 class IssuesControllerTest < ActionController::TestCase
Chris@0 21 fixtures :projects,
Chris@0 22 :users,
Chris@0 23 :roles,
Chris@0 24 :members,
Chris@0 25 :member_roles,
Chris@0 26 :issues,
Chris@0 27 :issue_statuses,
Chris@0 28 :versions,
Chris@0 29 :trackers,
Chris@0 30 :projects_trackers,
Chris@0 31 :issue_categories,
Chris@0 32 :enabled_modules,
Chris@0 33 :enumerations,
Chris@0 34 :attachments,
Chris@0 35 :workflows,
Chris@0 36 :custom_fields,
Chris@0 37 :custom_values,
Chris@0 38 :custom_fields_projects,
Chris@0 39 :custom_fields_trackers,
Chris@0 40 :time_entries,
Chris@0 41 :journals,
Chris@0 42 :journal_details,
Chris@1115 43 :queries,
Chris@1115 44 :repositories,
Chris@1115 45 :changesets
Chris@441 46
Chris@909 47 include Redmine::I18n
Chris@909 48
Chris@0 49 def setup
Chris@0 50 User.current = nil
Chris@0 51 end
Chris@441 52
Chris@0 53 def test_index
Chris@1115 54 with_settings :default_language => "en" do
Chris@1115 55 get :index
Chris@1115 56 assert_response :success
Chris@1115 57 assert_template 'index'
Chris@1115 58 assert_not_nil assigns(:issues)
Chris@1115 59 assert_nil assigns(:project)
Chris@1115 60
Chris@1115 61 # links to visible issues
Chris@1517 62 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
Chris@1115 63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
Chris@1115 64 # private projects hidden
Chris@1115 65 assert_select 'a[href=/issues/6]', 0
Chris@1115 66 assert_select 'a[href=/issues/4]', 0
Chris@1115 67 # project column
Chris@1115 68 assert_select 'th', :text => /Project/
Chris@1115 69 end
Chris@0 70 end
Chris@441 71
Chris@0 72 def test_index_should_not_list_issues_when_module_disabled
Chris@0 73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
Chris@0 74 get :index
Chris@0 75 assert_response :success
Chris@909 76 assert_template 'index'
Chris@0 77 assert_not_nil assigns(:issues)
Chris@0 78 assert_nil assigns(:project)
Chris@1115 79
Chris@1115 80 assert_select 'a[href=/issues/1]', 0
Chris@1115 81 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
Chris@0 82 end
Chris@441 83
Chris@441 84 def test_index_should_list_visible_issues_only
Chris@441 85 get :index, :per_page => 100
Chris@441 86 assert_response :success
Chris@441 87 assert_not_nil assigns(:issues)
Chris@441 88 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
Chris@441 89 end
Chris@441 90
Chris@0 91 def test_index_with_project
Chris@0 92 Setting.display_subprojects_issues = 0
Chris@0 93 get :index, :project_id => 1
Chris@0 94 assert_response :success
Chris@909 95 assert_template 'index'
Chris@0 96 assert_not_nil assigns(:issues)
Chris@1115 97
Chris@1517 98 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
Chris@1115 99 assert_select 'a[href=/issues/5]', 0
Chris@0 100 end
Chris@441 101
Chris@0 102 def test_index_with_project_and_subprojects
Chris@0 103 Setting.display_subprojects_issues = 1
Chris@0 104 get :index, :project_id => 1
Chris@0 105 assert_response :success
Chris@909 106 assert_template 'index'
Chris@0 107 assert_not_nil assigns(:issues)
Chris@1115 108
Chris@1517 109 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
Chris@1115 110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
Chris@1115 111 assert_select 'a[href=/issues/6]', 0
Chris@0 112 end
Chris@441 113
Chris@1115 114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
Chris@0 115 @request.session[:user_id] = 2
Chris@0 116 Setting.display_subprojects_issues = 1
Chris@0 117 get :index, :project_id => 1
Chris@0 118 assert_response :success
Chris@909 119 assert_template 'index'
Chris@0 120 assert_not_nil assigns(:issues)
Chris@1115 121
Chris@1517 122 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
Chris@1115 123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
Chris@1115 124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
Chris@0 125 end
Chris@441 126
chris@37 127 def test_index_with_project_and_default_filter
Chris@0 128 get :index, :project_id => 1, :set_filter => 1
Chris@0 129 assert_response :success
Chris@909 130 assert_template 'index'
Chris@0 131 assert_not_nil assigns(:issues)
Chris@441 132
chris@37 133 query = assigns(:query)
chris@37 134 assert_not_nil query
chris@37 135 # default filter
chris@37 136 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
chris@37 137 end
Chris@441 138
chris@37 139 def test_index_with_project_and_filter
Chris@441 140 get :index, :project_id => 1, :set_filter => 1,
Chris@441 141 :f => ['tracker_id'],
Chris@441 142 :op => {'tracker_id' => '='},
Chris@441 143 :v => {'tracker_id' => ['1']}
chris@37 144 assert_response :success
Chris@909 145 assert_template 'index'
chris@37 146 assert_not_nil assigns(:issues)
Chris@441 147
chris@37 148 query = assigns(:query)
chris@37 149 assert_not_nil query
chris@37 150 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
chris@37 151 end
Chris@441 152
Chris@909 153 def test_index_with_short_filters
Chris@909 154 to_test = {
Chris@909 155 'status_id' => {
Chris@909 156 'o' => { :op => 'o', :values => [''] },
Chris@909 157 'c' => { :op => 'c', :values => [''] },
Chris@909 158 '7' => { :op => '=', :values => ['7'] },
Chris@909 159 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
Chris@909 160 '=7' => { :op => '=', :values => ['7'] },
Chris@909 161 '!3' => { :op => '!', :values => ['3'] },
Chris@909 162 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
Chris@909 163 'subject' => {
Chris@909 164 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
Chris@909 165 'o' => { :op => '=', :values => ['o'] },
Chris@909 166 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
Chris@909 167 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
Chris@909 168 'tracker_id' => {
Chris@909 169 '3' => { :op => '=', :values => ['3'] },
Chris@909 170 '=3' => { :op => '=', :values => ['3'] }},
Chris@909 171 'start_date' => {
Chris@909 172 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
Chris@909 173 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
Chris@909 174 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
Chris@909 175 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
Chris@909 176 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
Chris@909 177 '<t+2' => { :op => '<t+', :values => ['2'] },
Chris@909 178 '>t+2' => { :op => '>t+', :values => ['2'] },
Chris@909 179 't+2' => { :op => 't+', :values => ['2'] },
Chris@909 180 't' => { :op => 't', :values => [''] },
Chris@909 181 'w' => { :op => 'w', :values => [''] },
Chris@909 182 '>t-2' => { :op => '>t-', :values => ['2'] },
Chris@909 183 '<t-2' => { :op => '<t-', :values => ['2'] },
Chris@909 184 't-2' => { :op => 't-', :values => ['2'] }},
Chris@909 185 'created_on' => {
Chris@909 186 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
Chris@929 187 '<t-2' => { :op => '<t-', :values => ['2'] },
Chris@929 188 '>t-2' => { :op => '>t-', :values => ['2'] },
Chris@929 189 't-2' => { :op => 't-', :values => ['2'] }},
Chris@909 190 'cf_1' => {
Chris@909 191 'c' => { :op => '=', :values => ['c'] },
Chris@909 192 '!c' => { :op => '!', :values => ['c'] },
Chris@909 193 '!*' => { :op => '!*', :values => [''] },
Chris@909 194 '*' => { :op => '*', :values => [''] }},
Chris@909 195 'estimated_hours' => {
Chris@909 196 '=13.4' => { :op => '=', :values => ['13.4'] },
Chris@909 197 '>=45' => { :op => '>=', :values => ['45'] },
Chris@909 198 '<=125' => { :op => '<=', :values => ['125'] },
Chris@909 199 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
Chris@909 200 '!*' => { :op => '!*', :values => [''] },
Chris@909 201 '*' => { :op => '*', :values => [''] }}
Chris@909 202 }
Chris@909 203
Chris@909 204 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
Chris@909 205
Chris@909 206 to_test.each do |field, expression_and_expected|
Chris@909 207 expression_and_expected.each do |filter_expression, expected|
Chris@909 208
Chris@909 209 get :index, :set_filter => 1, field => filter_expression
Chris@909 210
Chris@909 211 assert_response :success
Chris@909 212 assert_template 'index'
Chris@909 213 assert_not_nil assigns(:issues)
Chris@909 214
Chris@909 215 query = assigns(:query)
Chris@909 216 assert_not_nil query
Chris@909 217 assert query.has_filter?(field)
Chris@909 218 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
Chris@909 219 end
Chris@909 220 end
Chris@909 221 end
Chris@909 222
chris@37 223 def test_index_with_project_and_empty_filters
chris@37 224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
chris@37 225 assert_response :success
Chris@909 226 assert_template 'index'
chris@37 227 assert_not_nil assigns(:issues)
Chris@441 228
chris@37 229 query = assigns(:query)
chris@37 230 assert_not_nil query
chris@37 231 # no filter
chris@37 232 assert_equal({}, query.filters)
Chris@0 233 end
Chris@441 234
Chris@1115 235 def test_index_with_project_custom_field_filter
Chris@1115 236 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
Chris@1115 237 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
Chris@1115 238 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
Chris@1115 239 filter_name = "project.cf_#{field.id}"
Chris@1115 240 @request.session[:user_id] = 1
Chris@1115 241
Chris@1115 242 get :index, :set_filter => 1,
Chris@1115 243 :f => [filter_name],
Chris@1115 244 :op => {filter_name => '='},
Chris@1115 245 :v => {filter_name => ['Foo']}
Chris@1115 246 assert_response :success
Chris@1115 247 assert_template 'index'
Chris@1115 248 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
Chris@1115 249 end
Chris@1115 250
Chris@0 251 def test_index_with_query
Chris@0 252 get :index, :project_id => 1, :query_id => 5
Chris@0 253 assert_response :success
Chris@909 254 assert_template 'index'
Chris@0 255 assert_not_nil assigns(:issues)
Chris@0 256 assert_nil assigns(:issue_count_by_group)
Chris@0 257 end
Chris@441 258
Chris@0 259 def test_index_with_query_grouped_by_tracker
Chris@0 260 get :index, :project_id => 1, :query_id => 6
Chris@0 261 assert_response :success
Chris@909 262 assert_template 'index'
Chris@0 263 assert_not_nil assigns(:issues)
Chris@0 264 assert_not_nil assigns(:issue_count_by_group)
Chris@0 265 end
Chris@441 266
Chris@0 267 def test_index_with_query_grouped_by_list_custom_field
Chris@0 268 get :index, :project_id => 1, :query_id => 9
Chris@0 269 assert_response :success
Chris@909 270 assert_template 'index'
Chris@0 271 assert_not_nil assigns(:issues)
Chris@0 272 assert_not_nil assigns(:issue_count_by_group)
Chris@0 273 end
Chris@909 274
Chris@1115 275 def test_index_with_query_grouped_by_user_custom_field
Chris@1115 276 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
Chris@1115 277 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
Chris@1115 278 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
Chris@1115 279 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
Chris@1115 280 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
Chris@1115 281
Chris@1115 282 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
Chris@1115 283 assert_response :success
Chris@1115 284
Chris@1115 285 assert_select 'tr.group', 3
Chris@1115 286 assert_select 'tr.group' do
Chris@1115 287 assert_select 'a', :text => 'John Smith'
Chris@1115 288 assert_select 'span.count', :text => '1'
Chris@1115 289 end
Chris@1115 290 assert_select 'tr.group' do
Chris@1115 291 assert_select 'a', :text => 'Dave Lopper'
Chris@1115 292 assert_select 'span.count', :text => '2'
Chris@1115 293 end
Chris@1115 294 end
Chris@1115 295
Chris@1464 296 def test_index_with_query_grouped_by_tracker_in_normal_order
Chris@1115 297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
Chris@1115 298
Chris@1115 299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
Chris@1115 300 assert_response :success
Chris@1115 301
Chris@1115 302 trackers = assigns(:issues).map(&:tracker).uniq
Chris@1115 303 assert_equal [1, 2, 3], trackers.map(&:id)
Chris@1115 304 end
Chris@1115 305
Chris@1115 306 def test_index_with_query_grouped_by_tracker_in_reverse_order
Chris@1115 307 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
Chris@1115 308
Chris@1115 309 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
Chris@1115 310 assert_response :success
Chris@1115 311
Chris@1115 312 trackers = assigns(:issues).map(&:tracker).uniq
Chris@1115 313 assert_equal [3, 2, 1], trackers.map(&:id)
Chris@1115 314 end
Chris@1115 315
Chris@909 316 def test_index_with_query_id_and_project_id_should_set_session_query
Chris@909 317 get :index, :project_id => 1, :query_id => 4
Chris@909 318 assert_response :success
Chris@909 319 assert_kind_of Hash, session[:query]
Chris@909 320 assert_equal 4, session[:query][:id]
Chris@909 321 assert_equal 1, session[:query][:project_id]
Chris@909 322 end
Chris@909 323
Chris@1115 324 def test_index_with_invalid_query_id_should_respond_404
Chris@1115 325 get :index, :project_id => 1, :query_id => 999
Chris@1115 326 assert_response 404
Chris@1115 327 end
Chris@1115 328
Chris@909 329 def test_index_with_cross_project_query_in_session_should_show_project_issues
Chris@1464 330 q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
Chris@909 331 @request.session[:query] = {:id => q.id, :project_id => 1}
Chris@909 332
Chris@909 333 with_settings :display_subprojects_issues => '0' do
Chris@909 334 get :index, :project_id => 1
Chris@909 335 end
Chris@909 336 assert_response :success
Chris@909 337 assert_not_nil assigns(:query)
Chris@909 338 assert_equal q.id, assigns(:query).id
Chris@909 339 assert_equal 1, assigns(:query).project_id
Chris@909 340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
Chris@909 341 end
Chris@909 342
Chris@507 343 def test_private_query_should_not_be_available_to_other_users
Chris@1464 344 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
Chris@507 345 @request.session[:user_id] = 3
Chris@909 346
Chris@507 347 get :index, :query_id => q.id
Chris@507 348 assert_response 403
Chris@507 349 end
Chris@909 350
Chris@507 351 def test_private_query_should_be_available_to_its_user
Chris@1464 352 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
Chris@507 353 @request.session[:user_id] = 2
Chris@909 354
Chris@507 355 get :index, :query_id => q.id
Chris@507 356 assert_response :success
Chris@507 357 end
Chris@441 358
Chris@909 359 def test_public_query_should_be_available_to_other_users
Chris@1464 360 q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
Chris@909 361 @request.session[:user_id] = 3
Chris@909 362
Chris@909 363 get :index, :query_id => q.id
Chris@909 364 assert_response :success
Chris@0 365 end
Chris@441 366
Chris@1115 367 def test_index_should_omit_page_param_in_export_links
Chris@1115 368 get :index, :page => 2
Chris@1115 369 assert_response :success
Chris@1115 370 assert_select 'a.atom[href=/issues.atom]'
Chris@1115 371 assert_select 'a.csv[href=/issues.csv]'
Chris@1115 372 assert_select 'a.pdf[href=/issues.pdf]'
Chris@1115 373 assert_select 'form#csv-export-form[action=/issues.csv]'
Chris@1115 374 end
Chris@1115 375
Chris@1517 376 def test_index_should_not_warn_when_not_exceeding_export_limit
Chris@1517 377 with_settings :issues_export_limit => 200 do
Chris@1517 378 get :index
Chris@1517 379 assert_select '#csv-export-options p.icon-warning', 0
Chris@1517 380 end
Chris@1517 381 end
Chris@1517 382
Chris@1517 383 def test_index_should_warn_when_exceeding_export_limit
Chris@1517 384 with_settings :issues_export_limit => 2 do
Chris@1517 385 get :index
Chris@1517 386 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
Chris@1517 387 end
Chris@1517 388 end
Chris@1517 389
Chris@909 390 def test_index_csv
Chris@0 391 get :index, :format => 'csv'
Chris@0 392 assert_response :success
Chris@0 393 assert_not_nil assigns(:issues)
Chris@1115 394 assert_equal 'text/csv; header=present', @response.content_type
Chris@0 395 assert @response.body.starts_with?("#,")
Chris@909 396 lines = @response.body.chomp.split("\n")
Chris@1464 397 assert_equal assigns(:query).columns.size, lines[0].split(',').size
Chris@909 398 end
Chris@0 399
Chris@909 400 def test_index_csv_with_project
Chris@0 401 get :index, :project_id => 1, :format => 'csv'
Chris@0 402 assert_response :success
Chris@0 403 assert_not_nil assigns(:issues)
Chris@1115 404 assert_equal 'text/csv; header=present', @response.content_type
Chris@0 405 end
Chris@441 406
Chris@909 407 def test_index_csv_with_description
Chris@1464 408 Issue.generate!(:description => 'test_index_csv_with_description')
Chris@1464 409
Chris@1464 410 with_settings :default_language => 'en' do
Chris@1464 411 get :index, :format => 'csv', :description => '1'
Chris@1464 412 assert_response :success
Chris@1464 413 assert_not_nil assigns(:issues)
Chris@1464 414 end
Chris@1464 415
Chris@1464 416 assert_equal 'text/csv; header=present', response.content_type
Chris@1464 417 headers = response.body.chomp.split("\n").first.split(',')
Chris@1464 418 assert_include 'Description', headers
Chris@1464 419 assert_include 'test_index_csv_with_description', response.body
Chris@909 420 end
Chris@441 421
Chris@1115 422 def test_index_csv_with_spent_time_column
Chris@1115 423 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
Chris@1115 424 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
Chris@1115 425
Chris@1115 426 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
Chris@1115 427 assert_response :success
Chris@1115 428 assert_equal 'text/csv; header=present', @response.content_type
Chris@1115 429 lines = @response.body.chomp.split("\n")
Chris@1115 430 assert_include "#{issue.id},#{issue.subject},7.33", lines
Chris@1115 431 end
Chris@1115 432
Chris@909 433 def test_index_csv_with_all_columns
Chris@909 434 get :index, :format => 'csv', :columns => 'all'
Chris@0 435 assert_response :success
Chris@0 436 assert_not_nil assigns(:issues)
Chris@1115 437 assert_equal 'text/csv; header=present', @response.content_type
Chris@1464 438 assert_match /\A#,/, response.body
Chris@1464 439 lines = response.body.chomp.split("\n")
Chris@1464 440 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
Chris@1115 441 end
Chris@1115 442
Chris@1115 443 def test_index_csv_with_multi_column_field
Chris@1115 444 CustomField.find(1).update_attribute :multiple, true
Chris@1115 445 issue = Issue.find(1)
Chris@1115 446 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
Chris@1115 447 issue.save!
Chris@1115 448
Chris@1115 449 get :index, :format => 'csv', :columns => 'all'
Chris@1115 450 assert_response :success
Chris@1115 451 lines = @response.body.chomp.split("\n")
Chris@1115 452 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
Chris@909 453 end
Chris@441 454
Chris@1464 455 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
Chris@1464 456 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
Chris@1464 457 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})
Chris@1464 458
Chris@1464 459 with_settings :default_language => 'fr' do
Chris@1464 460 get :index, :format => 'csv', :columns => 'all'
Chris@1464 461 assert_response :success
Chris@1464 462 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
Chris@1464 463 assert_include '185,60', issue_line
Chris@1464 464 end
Chris@1464 465
Chris@1464 466 with_settings :default_language => 'en' do
Chris@1464 467 get :index, :format => 'csv', :columns => 'all'
Chris@1464 468 assert_response :success
Chris@1464 469 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
Chris@1464 470 assert_include '185.60', issue_line
Chris@1464 471 end
Chris@1464 472 end
Chris@1464 473
Chris@909 474 def test_index_csv_big_5
Chris@909 475 with_settings :default_language => "zh-TW" do
Chris@909 476 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
Chris@909 477 str_big5 = "\xa4@\xa4\xeb"
Chris@909 478 if str_utf8.respond_to?(:force_encoding)
Chris@909 479 str_utf8.force_encoding('UTF-8')
Chris@909 480 str_big5.force_encoding('Big5')
Chris@909 481 end
Chris@1115 482 issue = Issue.generate!(:subject => str_utf8)
Chris@909 483
Chris@909 484 get :index, :project_id => 1,
Chris@909 485 :f => ['subject'],
Chris@909 486 :op => '=', :values => [str_utf8],
Chris@909 487 :format => 'csv'
Chris@1115 488 assert_equal 'text/csv; header=present', @response.content_type
Chris@909 489 lines = @response.body.chomp.split("\n")
Chris@909 490 s1 = "\xaa\xac\xbaA"
Chris@909 491 if str_utf8.respond_to?(:force_encoding)
Chris@909 492 s1.force_encoding('Big5')
Chris@909 493 end
Chris@1464 494 assert_include s1, lines[0]
Chris@1464 495 assert_include str_big5, lines[1]
Chris@909 496 end
Chris@909 497 end
Chris@909 498
Chris@909 499 def test_index_csv_cannot_convert_should_be_replaced_big_5
Chris@909 500 with_settings :default_language => "zh-TW" do
Chris@909 501 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
Chris@909 502 if str_utf8.respond_to?(:force_encoding)
Chris@909 503 str_utf8.force_encoding('UTF-8')
Chris@909 504 end
Chris@1115 505 issue = Issue.generate!(:subject => str_utf8)
Chris@909 506
Chris@909 507 get :index, :project_id => 1,
Chris@909 508 :f => ['subject'],
Chris@909 509 :op => '=', :values => [str_utf8],
Chris@909 510 :c => ['status', 'subject'],
Chris@909 511 :format => 'csv',
Chris@909 512 :set_filter => 1
Chris@1115 513 assert_equal 'text/csv; header=present', @response.content_type
Chris@909 514 lines = @response.body.chomp.split("\n")
Chris@909 515 s1 = "\xaa\xac\xbaA" # status
Chris@909 516 if str_utf8.respond_to?(:force_encoding)
Chris@909 517 s1.force_encoding('Big5')
Chris@909 518 end
Chris@909 519 assert lines[0].include?(s1)
Chris@909 520 s2 = lines[1].split(",")[2]
Chris@909 521 if s1.respond_to?(:force_encoding)
Chris@909 522 s3 = "\xa5H?" # subject
Chris@909 523 s3.force_encoding('Big5')
Chris@909 524 assert_equal s3, s2
Chris@909 525 elsif RUBY_PLATFORM == 'java'
Chris@909 526 assert_equal "??", s2
Chris@909 527 else
Chris@909 528 assert_equal "\xa5H???", s2
Chris@909 529 end
Chris@909 530 end
Chris@909 531 end
Chris@909 532
Chris@909 533 def test_index_csv_tw
Chris@909 534 with_settings :default_language => "zh-TW" do
Chris@909 535 str1 = "test_index_csv_tw"
Chris@1115 536 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
Chris@909 537
Chris@909 538 get :index, :project_id => 1,
Chris@909 539 :f => ['subject'],
Chris@909 540 :op => '=', :values => [str1],
Chris@909 541 :c => ['estimated_hours', 'subject'],
Chris@909 542 :format => 'csv',
Chris@909 543 :set_filter => 1
Chris@1115 544 assert_equal 'text/csv; header=present', @response.content_type
Chris@909 545 lines = @response.body.chomp.split("\n")
Chris@1115 546 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
Chris@909 547 end
Chris@909 548 end
Chris@909 549
Chris@909 550 def test_index_csv_fr
Chris@909 551 with_settings :default_language => "fr" do
Chris@909 552 str1 = "test_index_csv_fr"
Chris@1115 553 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
Chris@909 554
Chris@909 555 get :index, :project_id => 1,
Chris@909 556 :f => ['subject'],
Chris@909 557 :op => '=', :values => [str1],
Chris@909 558 :c => ['estimated_hours', 'subject'],
Chris@909 559 :format => 'csv',
Chris@909 560 :set_filter => 1
Chris@1115 561 assert_equal 'text/csv; header=present', @response.content_type
Chris@909 562 lines = @response.body.chomp.split("\n")
Chris@1115 563 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
Chris@909 564 end
Chris@909 565 end
Chris@909 566
Chris@909 567 def test_index_pdf
Chris@909 568 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
Chris@909 569 with_settings :default_language => lang do
Chris@909 570
Chris@909 571 get :index
Chris@909 572 assert_response :success
Chris@909 573 assert_template 'index'
Chris@909 574
Chris@909 575 if lang == "ja"
Chris@909 576 if RUBY_PLATFORM != 'java'
Chris@909 577 assert_equal "CP932", l(:general_pdf_encoding)
Chris@909 578 end
Chris@909 579 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
Chris@909 580 next
Chris@909 581 end
Chris@909 582 end
Chris@909 583
Chris@909 584 get :index, :format => 'pdf'
Chris@909 585 assert_response :success
Chris@909 586 assert_not_nil assigns(:issues)
Chris@909 587 assert_equal 'application/pdf', @response.content_type
Chris@909 588
Chris@909 589 get :index, :project_id => 1, :format => 'pdf'
Chris@909 590 assert_response :success
Chris@909 591 assert_not_nil assigns(:issues)
Chris@909 592 assert_equal 'application/pdf', @response.content_type
Chris@909 593
Chris@909 594 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
Chris@909 595 assert_response :success
Chris@909 596 assert_not_nil assigns(:issues)
Chris@909 597 assert_equal 'application/pdf', @response.content_type
Chris@909 598 end
Chris@909 599 end
Chris@0 600 end
Chris@441 601
Chris@0 602 def test_index_pdf_with_query_grouped_by_list_custom_field
Chris@0 603 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
Chris@0 604 assert_response :success
Chris@0 605 assert_not_nil assigns(:issues)
Chris@0 606 assert_not_nil assigns(:issue_count_by_group)
Chris@0 607 assert_equal 'application/pdf', @response.content_type
Chris@0 608 end
Chris@441 609
Chris@1115 610 def test_index_atom
Chris@1115 611 get :index, :project_id => 'ecookbook', :format => 'atom'
Chris@1115 612 assert_response :success
Chris@1115 613 assert_template 'common/feed'
Chris@1115 614 assert_equal 'application/atom+xml', response.content_type
Chris@1115 615
Chris@1115 616 assert_select 'feed' do
Chris@1115 617 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
Chris@1115 618 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
Chris@1115 619 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
Chris@1115 620 end
Chris@1115 621 end
Chris@1115 622
Chris@0 623 def test_index_sort
Chris@0 624 get :index, :sort => 'tracker,id:desc'
Chris@0 625 assert_response :success
Chris@441 626
Chris@0 627 sort_params = @request.session['issues_index_sort']
Chris@0 628 assert sort_params.is_a?(String)
Chris@0 629 assert_equal 'tracker,id:desc', sort_params
Chris@441 630
Chris@0 631 issues = assigns(:issues)
Chris@0 632 assert_not_nil issues
Chris@0 633 assert !issues.empty?
Chris@0 634 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
Chris@0 635 end
Chris@441 636
Chris@909 637 def test_index_sort_by_field_not_included_in_columns
Chris@909 638 Setting.issue_list_default_columns = %w(subject author)
Chris@909 639 get :index, :sort => 'tracker'
Chris@909 640 end
Chris@909 641
Chris@909 642 def test_index_sort_by_assigned_to
Chris@909 643 get :index, :sort => 'assigned_to'
Chris@909 644 assert_response :success
Chris@909 645 assignees = assigns(:issues).collect(&:assigned_to).compact
Chris@909 646 assert_equal assignees.sort, assignees
Chris@909 647 end
Chris@909 648
Chris@909 649 def test_index_sort_by_assigned_to_desc
Chris@909 650 get :index, :sort => 'assigned_to:desc'
Chris@909 651 assert_response :success
Chris@909 652 assignees = assigns(:issues).collect(&:assigned_to).compact
Chris@909 653 assert_equal assignees.sort.reverse, assignees
Chris@909 654 end
Chris@909 655
Chris@909 656 def test_index_group_by_assigned_to
Chris@909 657 get :index, :group_by => 'assigned_to', :sort => 'priority'
Chris@909 658 assert_response :success
Chris@909 659 end
Chris@909 660
Chris@909 661 def test_index_sort_by_author
Chris@909 662 get :index, :sort => 'author'
Chris@909 663 assert_response :success
Chris@909 664 authors = assigns(:issues).collect(&:author)
Chris@909 665 assert_equal authors.sort, authors
Chris@909 666 end
Chris@909 667
Chris@909 668 def test_index_sort_by_author_desc
Chris@909 669 get :index, :sort => 'author:desc'
Chris@909 670 assert_response :success
Chris@909 671 authors = assigns(:issues).collect(&:author)
Chris@909 672 assert_equal authors.sort.reverse, authors
Chris@909 673 end
Chris@909 674
Chris@909 675 def test_index_group_by_author
Chris@909 676 get :index, :group_by => 'author', :sort => 'priority'
Chris@909 677 assert_response :success
Chris@909 678 end
Chris@1115 679
Chris@1115 680 def test_index_sort_by_spent_hours
Chris@1115 681 get :index, :sort => 'spent_hours:desc'
Chris@1115 682 assert_response :success
Chris@1115 683 hours = assigns(:issues).collect(&:spent_hours)
Chris@1115 684 assert_equal hours.sort.reverse, hours
Chris@1115 685 end
Chris@1115 686
Chris@1115 687 def test_index_sort_by_user_custom_field
Chris@1115 688 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
Chris@1115 689 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
Chris@1115 690 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
Chris@1115 691 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
Chris@1115 692 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
Chris@1115 693
Chris@1115 694 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
Chris@1115 695 assert_response :success
Chris@1115 696
Chris@1115 697 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
Chris@1115 698 end
Chris@909 699
Chris@0 700 def test_index_with_columns
Chris@0 701 columns = ['tracker', 'subject', 'assigned_to']
Chris@441 702 get :index, :set_filter => 1, :c => columns
Chris@0 703 assert_response :success
Chris@441 704
Chris@0 705 # query should use specified columns
Chris@0 706 query = assigns(:query)
Chris@1464 707 assert_kind_of IssueQuery, query
Chris@0 708 assert_equal columns, query.column_names.map(&:to_s)
Chris@441 709
Chris@0 710 # columns should be stored in session
Chris@0 711 assert_kind_of Hash, session[:query]
Chris@0 712 assert_kind_of Array, session[:query][:column_names]
Chris@0 713 assert_equal columns, session[:query][:column_names].map(&:to_s)
Chris@507 714
Chris@507 715 # ensure only these columns are kept in the selected columns list
Chris@1115 716 assert_select 'select#selected_columns option' do
Chris@1115 717 assert_select 'option', 3
Chris@1115 718 assert_select 'option[value=tracker]'
Chris@1115 719 assert_select 'option[value=project]', 0
Chris@1115 720 end
Chris@0 721 end
Chris@0 722
Chris@909 723 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
Chris@909 724 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
Chris@909 725 get :index, :set_filter => 1
Chris@909 726
Chris@909 727 # query should use specified columns
Chris@909 728 query = assigns(:query)
Chris@1464 729 assert_kind_of IssueQuery, query
Chris@1464 730 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
Chris@909 731 end
Chris@909 732
Chris@909 733 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
Chris@909 734 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
Chris@1464 735 columns = ['id', 'tracker', 'subject', 'assigned_to']
Chris@909 736 get :index, :set_filter => 1, :c => columns
Chris@909 737
Chris@909 738 # query should use specified columns
Chris@909 739 query = assigns(:query)
Chris@1464 740 assert_kind_of IssueQuery, query
Chris@909 741 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
Chris@909 742 end
Chris@909 743
Chris@441 744 def test_index_with_custom_field_column
Chris@441 745 columns = %w(tracker subject cf_2)
Chris@441 746 get :index, :set_filter => 1, :c => columns
Chris@441 747 assert_response :success
Chris@441 748
Chris@441 749 # query should use specified columns
Chris@441 750 query = assigns(:query)
Chris@1464 751 assert_kind_of IssueQuery, query
Chris@441 752 assert_equal columns, query.column_names.map(&:to_s)
Chris@441 753
Chris@1115 754 assert_select 'table.issues td.cf_2.string'
Chris@441 755 end
Chris@441 756
Chris@1115 757 def test_index_with_multi_custom_field_column
Chris@1115 758 field = CustomField.find(1)
Chris@1115 759 field.update_attribute :multiple, true
Chris@1115 760 issue = Issue.find(1)
Chris@1115 761 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
Chris@1115 762 issue.save!
Chris@1115 763
Chris@1115 764 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
Chris@1115 765 assert_response :success
Chris@1115 766
Chris@1115 767 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
Chris@1115 768 end
Chris@1115 769
Chris@1115 770 def test_index_with_multi_user_custom_field_column
Chris@1115 771 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
Chris@1115 772 :tracker_ids => [1], :is_for_all => true)
Chris@1115 773 issue = Issue.find(1)
Chris@1115 774 issue.custom_field_values = {field.id => ['2', '3']}
Chris@1115 775 issue.save!
Chris@1115 776
Chris@1115 777 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
Chris@1115 778 assert_response :success
Chris@1115 779
Chris@1115 780 assert_select "table.issues td.cf_#{field.id}" do
Chris@1115 781 assert_select 'a', 2
Chris@1115 782 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
Chris@1115 783 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
Chris@909 784 end
Chris@909 785 end
Chris@909 786
Chris@1115 787 def test_index_with_date_column
Chris@1115 788 with_settings :date_format => '%d/%m/%Y' do
Chris@1115 789 Issue.find(1).update_attribute :start_date, '1987-08-24'
Chris@1115 790 get :index, :set_filter => 1, :c => %w(start_date)
Chris@1115 791 assert_select "table.issues td.start_date", :text => '24/08/1987'
Chris@1115 792 end
Chris@1115 793 end
Chris@1115 794
Chris@1115 795 def test_index_with_done_ratio_column
Chris@909 796 Issue.find(1).update_attribute :done_ratio, 40
Chris@909 797 get :index, :set_filter => 1, :c => %w(done_ratio)
Chris@1115 798 assert_select 'table.issues td.done_ratio' do
Chris@1115 799 assert_select 'table.progress' do
Chris@1115 800 assert_select 'td.closed[style=?]', 'width: 40%;'
Chris@1115 801 end
Chris@1115 802 end
Chris@909 803 end
Chris@909 804
Chris@1115 805 def test_index_with_spent_hours_column
Chris@1115 806 get :index, :set_filter => 1, :c => %w(subject spent_hours)
Chris@1115 807 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
Chris@1115 808 end
Chris@1115 809
Chris@1115 810 def test_index_should_not_show_spent_hours_column_without_permission
Chris@1115 811 Role.anonymous.remove_permission! :view_time_entries
Chris@1115 812 get :index, :set_filter => 1, :c => %w(subject spent_hours)
Chris@1115 813 assert_select 'td.spent_hours', 0
Chris@1115 814 end
Chris@1115 815
Chris@1115 816 def test_index_with_fixed_version_column
Chris@909 817 get :index, :set_filter => 1, :c => %w(fixed_version)
Chris@1115 818 assert_select 'table.issues td.fixed_version' do
Chris@1115 819 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
Chris@1115 820 end
Chris@1115 821 end
Chris@1115 822
Chris@1115 823 def test_index_with_relations_column
Chris@1115 824 IssueRelation.delete_all
Chris@1115 825 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
Chris@1115 826 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
Chris@1115 827 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
Chris@1115 828 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
Chris@1115 829
Chris@1115 830 get :index, :set_filter => 1, :c => %w(subject relations)
Chris@1115 831 assert_response :success
Chris@1115 832 assert_select "tr#issue-1 td.relations" do
Chris@1115 833 assert_select "span", 3
Chris@1115 834 assert_select "span", :text => "Related to #7"
Chris@1115 835 assert_select "span", :text => "Related to #8"
Chris@1115 836 assert_select "span", :text => "Blocks #11"
Chris@1115 837 end
Chris@1115 838 assert_select "tr#issue-2 td.relations" do
Chris@1115 839 assert_select "span", 1
Chris@1115 840 assert_select "span", :text => "Blocked by #12"
Chris@1115 841 end
Chris@1115 842 assert_select "tr#issue-3 td.relations" do
Chris@1115 843 assert_select "span", 0
Chris@1115 844 end
Chris@1115 845
Chris@1115 846 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
Chris@1115 847 assert_response :success
Chris@1115 848 assert_equal 'text/csv; header=present', response.content_type
Chris@1115 849 lines = response.body.chomp.split("\n")
Chris@1115 850 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
Chris@1115 851 assert_include '2,Blocked by #12', lines
Chris@1115 852 assert_include '3,""', lines
Chris@1115 853
Chris@1115 854 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
Chris@1115 855 assert_response :success
Chris@1115 856 assert_equal 'application/pdf', response.content_type
Chris@1115 857 end
Chris@1115 858
Chris@1115 859 def test_index_with_description_column
Chris@1115 860 get :index, :set_filter => 1, :c => %w(subject description)
Chris@1115 861
Chris@1115 862 assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
Chris@1115 863 assert_select 'td.description[colspan=3]', :text => 'Unable to print recipes'
Chris@1115 864
Chris@1115 865 get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
Chris@1115 866 assert_response :success
Chris@1115 867 assert_equal 'application/pdf', response.content_type
Chris@909 868 end
Chris@909 869
Chris@909 870 def test_index_send_html_if_query_is_invalid
Chris@909 871 get :index, :f => ['start_date'], :op => {:start_date => '='}
Chris@909 872 assert_equal 'text/html', @response.content_type
Chris@909 873 assert_template 'index'
Chris@909 874 end
Chris@909 875
Chris@909 876 def test_index_send_nothing_if_query_is_invalid
Chris@909 877 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
Chris@909 878 assert_equal 'text/csv', @response.content_type
Chris@909 879 assert @response.body.blank?
Chris@909 880 end
Chris@909 881
Chris@0 882 def test_show_by_anonymous
Chris@0 883 get :show, :id => 1
Chris@0 884 assert_response :success
Chris@909 885 assert_template 'show'
Chris@0 886 assert_equal Issue.find(1), assigns(:issue)
Chris@1115 887 assert_select 'div.issue div.description', :text => /Unable to print recipes/
Chris@0 888 # anonymous role is allowed to add a note
Chris@1115 889 assert_select 'form#issue-form' do
Chris@1115 890 assert_select 'fieldset' do
Chris@1115 891 assert_select 'legend', :text => 'Notes'
Chris@1115 892 assert_select 'textarea[name=?]', 'issue[notes]'
Chris@1115 893 end
Chris@1115 894 end
Chris@1517 895 assert_select 'title', :text => "Bug #1: #{ESCAPED_UCANT} print recipes - eCookbook - Redmine"
Chris@0 896 end
Chris@441 897
Chris@0 898 def test_show_by_manager
Chris@0 899 @request.session[:user_id] = 2
Chris@0 900 get :show, :id => 1
Chris@0 901 assert_response :success
Chris@1115 902 assert_select 'a', :text => /Quote/
Chris@1115 903 assert_select 'form#issue-form' do
Chris@1115 904 assert_select 'fieldset' do
Chris@1115 905 assert_select 'legend', :text => 'Change properties'
Chris@1115 906 assert_select 'input[name=?]', 'issue[subject]'
Chris@1115 907 end
Chris@1115 908 assert_select 'fieldset' do
Chris@1115 909 assert_select 'legend', :text => 'Log time'
Chris@1115 910 assert_select 'input[name=?]', 'time_entry[hours]'
Chris@1115 911 end
Chris@1115 912 assert_select 'fieldset' do
Chris@1115 913 assert_select 'legend', :text => 'Notes'
Chris@1115 914 assert_select 'textarea[name=?]', 'issue[notes]'
Chris@1115 915 end
Chris@1115 916 end
Chris@0 917 end
Chris@441 918
Chris@1115 919 def test_show_should_display_update_form
Chris@909 920 @request.session[:user_id] = 2
Chris@909 921 get :show, :id => 1
Chris@909 922 assert_response :success
Chris@909 923
Chris@1464 924 assert_select 'form#issue-form' do
Chris@1464 925 assert_select 'input[name=?]', 'issue[is_private]'
Chris@1464 926 assert_select 'select[name=?]', 'issue[project_id]'
Chris@1464 927 assert_select 'select[name=?]', 'issue[tracker_id]'
Chris@1464 928 assert_select 'input[name=?]', 'issue[subject]'
Chris@1464 929 assert_select 'textarea[name=?]', 'issue[description]'
Chris@1464 930 assert_select 'select[name=?]', 'issue[status_id]'
Chris@1464 931 assert_select 'select[name=?]', 'issue[priority_id]'
Chris@1464 932 assert_select 'select[name=?]', 'issue[assigned_to_id]'
Chris@1464 933 assert_select 'select[name=?]', 'issue[category_id]'
Chris@1464 934 assert_select 'select[name=?]', 'issue[fixed_version_id]'
Chris@1464 935 assert_select 'input[name=?]', 'issue[parent_issue_id]'
Chris@1464 936 assert_select 'input[name=?]', 'issue[start_date]'
Chris@1464 937 assert_select 'input[name=?]', 'issue[due_date]'
Chris@1464 938 assert_select 'select[name=?]', 'issue[done_ratio]'
Chris@1464 939 assert_select 'input[name=?]', 'issue[custom_field_values][2]'
Chris@1464 940 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
Chris@1464 941 assert_select 'textarea[name=?]', 'issue[notes]'
Chris@1464 942 end
Chris@1115 943 end
Chris@1115 944
Chris@1115 945 def test_show_should_display_update_form_with_minimal_permissions
Chris@1115 946 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
Chris@1115 947 WorkflowTransition.delete_all :role_id => 1
Chris@1115 948
Chris@1115 949 @request.session[:user_id] = 2
Chris@1115 950 get :show, :id => 1
Chris@1115 951 assert_response :success
Chris@1115 952
Chris@1464 953 assert_select 'form#issue-form' do
Chris@1464 954 assert_select 'input[name=?]', 'issue[is_private]', 0
Chris@1464 955 assert_select 'select[name=?]', 'issue[project_id]', 0
Chris@1464 956 assert_select 'select[name=?]', 'issue[tracker_id]', 0
Chris@1464 957 assert_select 'input[name=?]', 'issue[subject]', 0
Chris@1464 958 assert_select 'textarea[name=?]', 'issue[description]', 0
Chris@1464 959 assert_select 'select[name=?]', 'issue[status_id]', 0
Chris@1464 960 assert_select 'select[name=?]', 'issue[priority_id]', 0
Chris@1464 961 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0
Chris@1464 962 assert_select 'select[name=?]', 'issue[category_id]', 0
Chris@1464 963 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0
Chris@1464 964 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
Chris@1464 965 assert_select 'input[name=?]', 'issue[start_date]', 0
Chris@1464 966 assert_select 'input[name=?]', 'issue[due_date]', 0
Chris@1464 967 assert_select 'select[name=?]', 'issue[done_ratio]', 0
Chris@1464 968 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
Chris@1464 969 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
Chris@1464 970 assert_select 'textarea[name=?]', 'issue[notes]'
Chris@1464 971 end
Chris@1115 972 end
Chris@1115 973
Chris@1115 974 def test_show_should_display_update_form_with_workflow_permissions
Chris@1115 975 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
Chris@1115 976
Chris@1115 977 @request.session[:user_id] = 2
Chris@1115 978 get :show, :id => 1
Chris@1115 979 assert_response :success
Chris@1115 980
Chris@1464 981 assert_select 'form#issue-form' do
Chris@1464 982 assert_select 'input[name=?]', 'issue[is_private]', 0
Chris@1464 983 assert_select 'select[name=?]', 'issue[project_id]', 0
Chris@1464 984 assert_select 'select[name=?]', 'issue[tracker_id]', 0
Chris@1464 985 assert_select 'input[name=?]', 'issue[subject]', 0
Chris@1464 986 assert_select 'textarea[name=?]', 'issue[description]', 0
Chris@1464 987 assert_select 'select[name=?]', 'issue[status_id]'
Chris@1464 988 assert_select 'select[name=?]', 'issue[priority_id]', 0
Chris@1464 989 assert_select 'select[name=?]', 'issue[assigned_to_id]'
Chris@1464 990 assert_select 'select[name=?]', 'issue[category_id]', 0
Chris@1464 991 assert_select 'select[name=?]', 'issue[fixed_version_id]'
Chris@1464 992 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
Chris@1464 993 assert_select 'input[name=?]', 'issue[start_date]', 0
Chris@1464 994 assert_select 'input[name=?]', 'issue[due_date]', 0
Chris@1464 995 assert_select 'select[name=?]', 'issue[done_ratio]'
Chris@1464 996 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0
Chris@1464 997 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
Chris@1464 998 assert_select 'textarea[name=?]', 'issue[notes]'
Chris@1464 999 end
Chris@1115 1000 end
Chris@1115 1001
Chris@1115 1002 def test_show_should_not_display_update_form_without_permissions
Chris@1115 1003 Role.find(1).update_attribute :permissions, [:view_issues]
Chris@1115 1004
Chris@1115 1005 @request.session[:user_id] = 2
Chris@1115 1006 get :show, :id => 1
Chris@1115 1007 assert_response :success
Chris@1115 1008
Chris@1115 1009 assert_select 'form#issue-form', 0
Chris@1115 1010 end
Chris@1115 1011
Chris@1115 1012 def test_update_form_should_not_display_inactive_enumerations
Chris@1115 1013 assert !IssuePriority.find(15).active?
Chris@1115 1014
Chris@1115 1015 @request.session[:user_id] = 2
Chris@1115 1016 get :show, :id => 1
Chris@1115 1017 assert_response :success
Chris@1115 1018
Chris@1115 1019 assert_select 'form#issue-form' do
Chris@1115 1020 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1115 1021 assert_select 'option[value=4]'
Chris@1115 1022 assert_select 'option[value=15]', 0
Chris@1115 1023 end
Chris@1115 1024 end
Chris@909 1025 end
Chris@909 1026
Chris@909 1027 def test_update_form_should_allow_attachment_upload
Chris@909 1028 @request.session[:user_id] = 2
Chris@909 1029 get :show, :id => 1
Chris@909 1030
Chris@1115 1031 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
Chris@1464 1032 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]'
Chris@1115 1033 end
Chris@909 1034 end
Chris@909 1035
Chris@0 1036 def test_show_should_deny_anonymous_access_without_permission
Chris@0 1037 Role.anonymous.remove_permission!(:view_issues)
Chris@0 1038 get :show, :id => 1
Chris@0 1039 assert_response :redirect
Chris@0 1040 end
Chris@441 1041
Chris@441 1042 def test_show_should_deny_anonymous_access_to_private_issue
Chris@1517 1043 Issue.where(:id => 1).update_all(["is_private = ?", true])
Chris@441 1044 get :show, :id => 1
Chris@441 1045 assert_response :redirect
Chris@441 1046 end
Chris@441 1047
Chris@0 1048 def test_show_should_deny_non_member_access_without_permission
Chris@0 1049 Role.non_member.remove_permission!(:view_issues)
Chris@0 1050 @request.session[:user_id] = 9
Chris@0 1051 get :show, :id => 1
Chris@0 1052 assert_response 403
Chris@0 1053 end
Chris@441 1054
Chris@441 1055 def test_show_should_deny_non_member_access_to_private_issue
Chris@1517 1056 Issue.where(:id => 1).update_all(["is_private = ?", true])
Chris@441 1057 @request.session[:user_id] = 9
Chris@441 1058 get :show, :id => 1
Chris@441 1059 assert_response 403
Chris@441 1060 end
Chris@441 1061
Chris@0 1062 def test_show_should_deny_member_access_without_permission
Chris@0 1063 Role.find(1).remove_permission!(:view_issues)
Chris@0 1064 @request.session[:user_id] = 2
Chris@0 1065 get :show, :id => 1
Chris@0 1066 assert_response 403
Chris@0 1067 end
Chris@441 1068
Chris@441 1069 def test_show_should_deny_member_access_to_private_issue_without_permission
Chris@1517 1070 Issue.where(:id => 1).update_all(["is_private = ?", true])
Chris@441 1071 @request.session[:user_id] = 3
Chris@441 1072 get :show, :id => 1
Chris@441 1073 assert_response 403
Chris@441 1074 end
Chris@441 1075
Chris@441 1076 def test_show_should_allow_author_access_to_private_issue
Chris@1517 1077 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
Chris@441 1078 @request.session[:user_id] = 3
Chris@441 1079 get :show, :id => 1
Chris@441 1080 assert_response :success
Chris@441 1081 end
Chris@441 1082
Chris@441 1083 def test_show_should_allow_assignee_access_to_private_issue
Chris@1517 1084 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
Chris@441 1085 @request.session[:user_id] = 3
Chris@441 1086 get :show, :id => 1
Chris@441 1087 assert_response :success
Chris@441 1088 end
Chris@441 1089
Chris@441 1090 def test_show_should_allow_member_access_to_private_issue_with_permission
Chris@1517 1091 Issue.where(:id => 1).update_all(["is_private = ?", true])
Chris@441 1092 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
Chris@441 1093 @request.session[:user_id] = 3
Chris@441 1094 get :show, :id => 1
Chris@441 1095 assert_response :success
Chris@441 1096 end
Chris@441 1097
Chris@0 1098 def test_show_should_not_disclose_relations_to_invisible_issues
Chris@0 1099 Setting.cross_project_issue_relations = '1'
Chris@0 1100 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
Chris@0 1101 # Relation to a private project issue
Chris@0 1102 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
Chris@441 1103
Chris@0 1104 get :show, :id => 1
Chris@0 1105 assert_response :success
Chris@441 1106
Chris@1115 1107 assert_select 'div#relations' do
Chris@1115 1108 assert_select 'a', :text => /#2$/
Chris@1115 1109 assert_select 'a', :text => /#4$/, :count => 0
Chris@1115 1110 end
Chris@1115 1111 end
Chris@1115 1112
Chris@1115 1113 def test_show_should_list_subtasks
Chris@1115 1114 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
Chris@1115 1115
Chris@1115 1116 get :show, :id => 1
Chris@1115 1117 assert_response :success
Chris@1115 1118
Chris@1115 1119 assert_select 'div#issue_tree' do
Chris@1115 1120 assert_select 'td.subject', :text => /Child Issue/
Chris@1115 1121 end
Chris@1115 1122 end
Chris@1115 1123
Chris@1115 1124 def test_show_should_list_parents
Chris@1115 1125 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
Chris@1115 1126
Chris@1115 1127 get :show, :id => issue.id
Chris@1115 1128 assert_response :success
Chris@1115 1129
Chris@1115 1130 assert_select 'div.subject' do
Chris@1115 1131 assert_select 'h3', 'Child Issue'
Chris@1115 1132 assert_select 'a[href=/issues/1]'
Chris@1115 1133 end
Chris@1115 1134 end
Chris@1115 1135
Chris@1115 1136 def test_show_should_not_display_prev_next_links_without_query_in_session
Chris@1115 1137 get :show, :id => 1
Chris@1115 1138 assert_response :success
Chris@1115 1139 assert_nil assigns(:prev_issue_id)
Chris@1115 1140 assert_nil assigns(:next_issue_id)
Chris@1115 1141
Chris@1115 1142 assert_select 'div.next-prev-links', 0
Chris@1115 1143 end
Chris@1115 1144
Chris@1115 1145 def test_show_should_display_prev_next_links_with_query_in_session
Chris@1115 1146 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
Chris@1115 1147 @request.session['issues_index_sort'] = 'id'
Chris@1115 1148
Chris@1115 1149 with_settings :display_subprojects_issues => '0' do
Chris@1115 1150 get :show, :id => 3
Chris@1115 1151 end
Chris@1115 1152
Chris@1115 1153 assert_response :success
Chris@1115 1154 # Previous and next issues for all projects
Chris@1115 1155 assert_equal 2, assigns(:prev_issue_id)
Chris@1115 1156 assert_equal 5, assigns(:next_issue_id)
Chris@1115 1157
Chris@1115 1158 count = Issue.open.visible.count
Chris@1115 1159
Chris@1115 1160 assert_select 'div.next-prev-links' do
Chris@1115 1161 assert_select 'a[href=/issues/2]', :text => /Previous/
Chris@1115 1162 assert_select 'a[href=/issues/5]', :text => /Next/
Chris@1115 1163 assert_select 'span.position', :text => "3 of #{count}"
Chris@1115 1164 end
Chris@1115 1165 end
Chris@1115 1166
Chris@1115 1167 def test_show_should_display_prev_next_links_with_saved_query_in_session
Chris@1464 1168 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1,
Chris@1115 1169 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
Chris@1115 1170 :sort_criteria => [['id', 'asc']])
Chris@1115 1171 @request.session[:query] = {:id => query.id, :project_id => nil}
Chris@1115 1172
Chris@1115 1173 get :show, :id => 11
Chris@1115 1174
Chris@1115 1175 assert_response :success
Chris@1115 1176 assert_equal query, assigns(:query)
Chris@1115 1177 # Previous and next issues for all projects
Chris@1115 1178 assert_equal 8, assigns(:prev_issue_id)
Chris@1115 1179 assert_equal 12, assigns(:next_issue_id)
Chris@1115 1180
Chris@1115 1181 assert_select 'div.next-prev-links' do
Chris@1115 1182 assert_select 'a[href=/issues/8]', :text => /Previous/
Chris@1115 1183 assert_select 'a[href=/issues/12]', :text => /Next/
Chris@1115 1184 end
Chris@1115 1185 end
Chris@1115 1186
Chris@1115 1187 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
Chris@1115 1188 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
Chris@1115 1189
Chris@1115 1190 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
Chris@1115 1191 @request.session['issues_index_sort'] = assoc_sort
Chris@1115 1192
Chris@1115 1193 get :show, :id => 3
Chris@1115 1194 assert_response :success, "Wrong response status for #{assoc_sort} sort"
Chris@1115 1195
Chris@1115 1196 assert_select 'div.next-prev-links' do
Chris@1115 1197 assert_select 'a', :text => /(Previous|Next)/
Chris@1115 1198 end
Chris@1115 1199 end
Chris@1115 1200 end
Chris@1115 1201
Chris@1115 1202 def test_show_should_display_prev_next_links_with_project_query_in_session
Chris@1115 1203 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
Chris@1115 1204 @request.session['issues_index_sort'] = 'id'
Chris@1115 1205
Chris@1115 1206 with_settings :display_subprojects_issues => '0' do
Chris@1115 1207 get :show, :id => 3
Chris@1115 1208 end
Chris@1115 1209
Chris@1115 1210 assert_response :success
Chris@1115 1211 # Previous and next issues inside project
Chris@1115 1212 assert_equal 2, assigns(:prev_issue_id)
Chris@1115 1213 assert_equal 7, assigns(:next_issue_id)
Chris@1115 1214
Chris@1115 1215 assert_select 'div.next-prev-links' do
Chris@1115 1216 assert_select 'a[href=/issues/2]', :text => /Previous/
Chris@1115 1217 assert_select 'a[href=/issues/7]', :text => /Next/
Chris@1115 1218 end
Chris@1115 1219 end
Chris@1115 1220
Chris@1115 1221 def test_show_should_not_display_prev_link_for_first_issue
Chris@1115 1222 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
Chris@1115 1223 @request.session['issues_index_sort'] = 'id'
Chris@1115 1224
Chris@1115 1225 with_settings :display_subprojects_issues => '0' do
Chris@1115 1226 get :show, :id => 1
Chris@1115 1227 end
Chris@1115 1228
Chris@1115 1229 assert_response :success
Chris@1115 1230 assert_nil assigns(:prev_issue_id)
Chris@1115 1231 assert_equal 2, assigns(:next_issue_id)
Chris@1115 1232
Chris@1115 1233 assert_select 'div.next-prev-links' do
Chris@1115 1234 assert_select 'a', :text => /Previous/, :count => 0
Chris@1115 1235 assert_select 'a[href=/issues/2]', :text => /Next/
Chris@1115 1236 end
Chris@1115 1237 end
Chris@1115 1238
Chris@1115 1239 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
Chris@1115 1240 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
Chris@1115 1241 @request.session['issues_index_sort'] = 'id'
Chris@1115 1242
Chris@1115 1243 get :show, :id => 1
Chris@1115 1244
Chris@1115 1245 assert_response :success
Chris@1115 1246 assert_nil assigns(:prev_issue_id)
Chris@1115 1247 assert_nil assigns(:next_issue_id)
Chris@1115 1248
Chris@1115 1249 assert_select 'a', :text => /Previous/, :count => 0
Chris@1115 1250 assert_select 'a', :text => /Next/, :count => 0
Chris@1115 1251 end
Chris@1115 1252
Chris@1115 1253 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
Chris@1115 1254 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
Chris@1115 1255 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
Chris@1115 1256 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
Chris@1115 1257 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
Chris@1115 1258 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
Chris@1115 1259
Chris@1464 1260 query = IssueQuery.create!(:name => 'test', :visibility => IssueQuery::VISIBILITY_PUBLIC, :user_id => 1, :filters => {},
Chris@1115 1261 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
Chris@1115 1262 @request.session[:query] = {:id => query.id, :project_id => nil}
Chris@1115 1263
Chris@1115 1264 get :show, :id => 3
Chris@1115 1265 assert_response :success
Chris@1115 1266
Chris@1115 1267 assert_equal 2, assigns(:prev_issue_id)
Chris@1115 1268 assert_equal 1, assigns(:next_issue_id)
Chris@1115 1269
Chris@1115 1270 assert_select 'div.next-prev-links' do
Chris@1115 1271 assert_select 'a[href=/issues/2]', :text => /Previous/
Chris@1115 1272 assert_select 'a[href=/issues/1]', :text => /Next/
Chris@1115 1273 end
Chris@1115 1274 end
Chris@1115 1275
Chris@1115 1276 def test_show_should_display_link_to_the_assignee
Chris@1115 1277 get :show, :id => 2
Chris@1115 1278 assert_response :success
Chris@1115 1279 assert_select '.assigned-to' do
Chris@1115 1280 assert_select 'a[href=/users/3]'
Chris@1115 1281 end
Chris@1115 1282 end
Chris@1115 1283
Chris@1115 1284 def test_show_should_display_visible_changesets_from_other_projects
Chris@1115 1285 project = Project.find(2)
Chris@1115 1286 issue = project.issues.first
Chris@1115 1287 issue.changeset_ids = [102]
Chris@1115 1288 issue.save!
Chris@1115 1289 # changesets from other projects should be displayed even if repository
Chris@1115 1290 # is disabled on issue's project
Chris@1115 1291 project.disable_module! :repository
Chris@1115 1292
Chris@1115 1293 @request.session[:user_id] = 2
Chris@1115 1294 get :show, :id => issue.id
Chris@1115 1295
Chris@1115 1296 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
Chris@1115 1297 end
Chris@1115 1298
Chris@1115 1299 def test_show_should_display_watchers
Chris@1115 1300 @request.session[:user_id] = 2
Chris@1115 1301 Issue.find(1).add_watcher User.find(2)
Chris@1115 1302
Chris@1115 1303 get :show, :id => 1
Chris@1115 1304 assert_select 'div#watchers ul' do
Chris@1115 1305 assert_select 'li' do
Chris@1115 1306 assert_select 'a[href=/users/2]'
Chris@1115 1307 assert_select 'a img[alt=Delete]'
Chris@1115 1308 end
Chris@1115 1309 end
Chris@1115 1310 end
Chris@1115 1311
Chris@1115 1312 def test_show_should_display_watchers_with_gravatars
Chris@1115 1313 @request.session[:user_id] = 2
Chris@1115 1314 Issue.find(1).add_watcher User.find(2)
Chris@1115 1315
Chris@1115 1316 with_settings :gravatar_enabled => '1' do
Chris@1115 1317 get :show, :id => 1
Chris@1115 1318 end
Chris@1115 1319
Chris@1115 1320 assert_select 'div#watchers ul' do
Chris@1115 1321 assert_select 'li' do
Chris@1115 1322 assert_select 'img.gravatar'
Chris@1115 1323 assert_select 'a[href=/users/2]'
Chris@1115 1324 assert_select 'a img[alt=Delete]'
Chris@1115 1325 end
Chris@1115 1326 end
Chris@1115 1327 end
Chris@1115 1328
Chris@1115 1329 def test_show_with_thumbnails_enabled_should_display_thumbnails
Chris@1115 1330 @request.session[:user_id] = 2
Chris@1115 1331
Chris@1115 1332 with_settings :thumbnails_enabled => '1' do
Chris@1115 1333 get :show, :id => 14
Chris@1115 1334 assert_response :success
Chris@1115 1335 end
Chris@1115 1336
Chris@1115 1337 assert_select 'div.thumbnails' do
Chris@1115 1338 assert_select 'a[href=/attachments/16/testfile.png]' do
Chris@1115 1339 assert_select 'img[src=/attachments/thumbnail/16]'
Chris@1115 1340 end
Chris@1115 1341 end
Chris@1115 1342 end
Chris@1115 1343
Chris@1115 1344 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
Chris@1115 1345 @request.session[:user_id] = 2
Chris@1115 1346
Chris@1115 1347 with_settings :thumbnails_enabled => '0' do
Chris@1115 1348 get :show, :id => 14
Chris@1115 1349 assert_response :success
Chris@1115 1350 end
Chris@1115 1351
Chris@1115 1352 assert_select 'div.thumbnails', 0
Chris@1115 1353 end
Chris@1115 1354
Chris@1115 1355 def test_show_with_multi_custom_field
Chris@1115 1356 field = CustomField.find(1)
Chris@1115 1357 field.update_attribute :multiple, true
Chris@1115 1358 issue = Issue.find(1)
Chris@1115 1359 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
Chris@1115 1360 issue.save!
Chris@1115 1361
Chris@1115 1362 get :show, :id => 1
Chris@1115 1363 assert_response :success
Chris@1115 1364
Chris@1115 1365 assert_select 'td', :text => 'MySQL, Oracle'
Chris@1115 1366 end
Chris@1115 1367
Chris@1115 1368 def test_show_with_multi_user_custom_field
Chris@1115 1369 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
Chris@1115 1370 :tracker_ids => [1], :is_for_all => true)
Chris@1115 1371 issue = Issue.find(1)
Chris@1115 1372 issue.custom_field_values = {field.id => ['2', '3']}
Chris@1115 1373 issue.save!
Chris@1115 1374
Chris@1115 1375 get :show, :id => 1
Chris@1115 1376 assert_response :success
Chris@1115 1377
Chris@1517 1378 assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do
Chris@1517 1379 assert_select 'a', :text => 'Dave Lopper'
Chris@1517 1380 assert_select 'a', :text => 'John Smith'
Chris@1517 1381 end
Chris@1115 1382 end
Chris@1115 1383
Chris@1115 1384 def test_show_should_display_private_notes_with_permission_only
Chris@1115 1385 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
Chris@1115 1386 @request.session[:user_id] = 2
Chris@1115 1387
Chris@1115 1388 get :show, :id => 2
Chris@1115 1389 assert_response :success
Chris@1115 1390 assert_include journal, assigns(:journals)
Chris@1115 1391
Chris@1115 1392 Role.find(1).remove_permission! :view_private_notes
Chris@1115 1393 get :show, :id => 2
Chris@1115 1394 assert_response :success
Chris@1115 1395 assert_not_include journal, assigns(:journals)
Chris@0 1396 end
Chris@441 1397
Chris@0 1398 def test_show_atom
Chris@0 1399 get :show, :id => 2, :format => 'atom'
Chris@0 1400 assert_response :success
Chris@909 1401 assert_template 'journals/index'
Chris@0 1402 # Inline image
Chris@0 1403 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
Chris@0 1404 end
Chris@441 1405
Chris@0 1406 def test_show_export_to_pdf
Chris@0 1407 get :show, :id => 3, :format => 'pdf'
Chris@0 1408 assert_response :success
Chris@0 1409 assert_equal 'application/pdf', @response.content_type
Chris@0 1410 assert @response.body.starts_with?('%PDF')
Chris@0 1411 assert_not_nil assigns(:issue)
Chris@0 1412 end
Chris@0 1413
Chris@1115 1414 def test_show_export_to_pdf_with_ancestors
Chris@1115 1415 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
Chris@1115 1416
Chris@1115 1417 get :show, :id => issue.id, :format => 'pdf'
Chris@1115 1418 assert_response :success
Chris@1115 1419 assert_equal 'application/pdf', @response.content_type
Chris@1115 1420 assert @response.body.starts_with?('%PDF')
Chris@1115 1421 end
Chris@1115 1422
Chris@1115 1423 def test_show_export_to_pdf_with_descendants
Chris@1115 1424 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
Chris@1115 1425 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
Chris@1115 1426 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
Chris@1115 1427
Chris@1115 1428 get :show, :id => 1, :format => 'pdf'
Chris@1115 1429 assert_response :success
Chris@1115 1430 assert_equal 'application/pdf', @response.content_type
Chris@1115 1431 assert @response.body.starts_with?('%PDF')
Chris@1115 1432 end
Chris@1115 1433
Chris@1115 1434 def test_show_export_to_pdf_with_journals
Chris@1115 1435 get :show, :id => 1, :format => 'pdf'
Chris@1115 1436 assert_response :success
Chris@1115 1437 assert_equal 'application/pdf', @response.content_type
Chris@1115 1438 assert @response.body.starts_with?('%PDF')
Chris@1115 1439 end
Chris@1115 1440
Chris@1115 1441 def test_show_export_to_pdf_with_changesets
Chris@1517 1442 [[100], [100, 101], [100, 101, 102]].each do |cs|
Chris@1517 1443 issue1 = Issue.find(3)
Chris@1517 1444 issue1.changesets = Changeset.find(cs)
Chris@1517 1445 issue1.save!
Chris@1517 1446 issue = Issue.find(3)
Chris@1517 1447 assert_equal issue.changesets.count, cs.size
Chris@1517 1448 get :show, :id => 3, :format => 'pdf'
Chris@1517 1449 assert_response :success
Chris@1517 1450 assert_equal 'application/pdf', @response.content_type
Chris@1517 1451 assert @response.body.starts_with?('%PDF')
Chris@1517 1452 end
Chris@1115 1453 end
Chris@1115 1454
Chris@1464 1455 def test_show_invalid_should_respond_with_404
Chris@1464 1456 get :show, :id => 999
Chris@1464 1457 assert_response 404
Chris@1464 1458 end
Chris@1464 1459
Chris@0 1460 def test_get_new
Chris@0 1461 @request.session[:user_id] = 2
Chris@0 1462 get :new, :project_id => 1, :tracker_id => 1
Chris@0 1463 assert_response :success
Chris@0 1464 assert_template 'new'
Chris@441 1465
Chris@1464 1466 assert_select 'form#issue-form' do
Chris@1464 1467 assert_select 'input[name=?]', 'issue[is_private]'
Chris@1464 1468 assert_select 'select[name=?]', 'issue[project_id]', 0
Chris@1464 1469 assert_select 'select[name=?]', 'issue[tracker_id]'
Chris@1464 1470 assert_select 'input[name=?]', 'issue[subject]'
Chris@1464 1471 assert_select 'textarea[name=?]', 'issue[description]'
Chris@1464 1472 assert_select 'select[name=?]', 'issue[status_id]'
Chris@1464 1473 assert_select 'select[name=?]', 'issue[priority_id]'
Chris@1464 1474 assert_select 'select[name=?]', 'issue[assigned_to_id]'
Chris@1464 1475 assert_select 'select[name=?]', 'issue[category_id]'
Chris@1464 1476 assert_select 'select[name=?]', 'issue[fixed_version_id]'
Chris@1464 1477 assert_select 'input[name=?]', 'issue[parent_issue_id]'
Chris@1464 1478 assert_select 'input[name=?]', 'issue[start_date]'
Chris@1464 1479 assert_select 'input[name=?]', 'issue[due_date]'
Chris@1464 1480 assert_select 'select[name=?]', 'issue[done_ratio]'
Chris@1464 1481 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
Chris@1464 1482 assert_select 'input[name=?]', 'issue[watcher_user_ids][]'
Chris@1464 1483 end
Chris@909 1484
Chris@909 1485 # Be sure we don't display inactive IssuePriorities
Chris@909 1486 assert ! IssuePriority.find(15).active?
Chris@1464 1487 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1464 1488 assert_select 'option[value=15]', 0
Chris@1464 1489 end
Chris@909 1490 end
Chris@909 1491
Chris@1115 1492 def test_get_new_with_minimal_permissions
Chris@1115 1493 Role.find(1).update_attribute :permissions, [:add_issues]
Chris@1115 1494 WorkflowTransition.delete_all :role_id => 1
Chris@909 1495
Chris@909 1496 @request.session[:user_id] = 2
Chris@909 1497 get :new, :project_id => 1, :tracker_id => 1
Chris@909 1498 assert_response :success
Chris@909 1499 assert_template 'new'
Chris@909 1500
Chris@1464 1501 assert_select 'form#issue-form' do
Chris@1464 1502 assert_select 'input[name=?]', 'issue[is_private]', 0
Chris@1464 1503 assert_select 'select[name=?]', 'issue[project_id]', 0
Chris@1464 1504 assert_select 'select[name=?]', 'issue[tracker_id]'
Chris@1464 1505 assert_select 'input[name=?]', 'issue[subject]'
Chris@1464 1506 assert_select 'textarea[name=?]', 'issue[description]'
Chris@1464 1507 assert_select 'select[name=?]', 'issue[status_id]'
Chris@1464 1508 assert_select 'select[name=?]', 'issue[priority_id]'
Chris@1464 1509 assert_select 'select[name=?]', 'issue[assigned_to_id]'
Chris@1464 1510 assert_select 'select[name=?]', 'issue[category_id]'
Chris@1464 1511 assert_select 'select[name=?]', 'issue[fixed_version_id]'
Chris@1464 1512 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
Chris@1464 1513 assert_select 'input[name=?]', 'issue[start_date]'
Chris@1464 1514 assert_select 'input[name=?]', 'issue[due_date]'
Chris@1464 1515 assert_select 'select[name=?]', 'issue[done_ratio]'
Chris@1464 1516 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string'
Chris@1464 1517 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0
Chris@1464 1518 end
Chris@909 1519 end
Chris@909 1520
Chris@1115 1521 def test_get_new_with_list_custom_field
Chris@909 1522 @request.session[:user_id] = 2
Chris@909 1523 get :new, :project_id => 1, :tracker_id => 1
Chris@909 1524 assert_response :success
Chris@909 1525 assert_template 'new'
Chris@909 1526
Chris@1115 1527 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
Chris@1115 1528 assert_select 'option', 4
Chris@1115 1529 assert_select 'option[value=MySQL]', :text => 'MySQL'
Chris@1115 1530 end
Chris@1115 1531 end
Chris@1115 1532
Chris@1115 1533 def test_get_new_with_multi_custom_field
Chris@1115 1534 field = IssueCustomField.find(1)
Chris@1115 1535 field.update_attribute :multiple, true
Chris@1115 1536
Chris@1115 1537 @request.session[:user_id] = 2
Chris@1115 1538 get :new, :project_id => 1, :tracker_id => 1
Chris@1115 1539 assert_response :success
Chris@1115 1540 assert_template 'new'
Chris@1115 1541
Chris@1115 1542 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
Chris@1115 1543 assert_select 'option', 3
Chris@1115 1544 assert_select 'option[value=MySQL]', :text => 'MySQL'
Chris@1115 1545 end
Chris@1115 1546 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
Chris@1115 1547 end
Chris@1115 1548
Chris@1115 1549 def test_get_new_with_multi_user_custom_field
Chris@1115 1550 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
Chris@1115 1551 :tracker_ids => [1], :is_for_all => true)
Chris@1115 1552
Chris@1115 1553 @request.session[:user_id] = 2
Chris@1115 1554 get :new, :project_id => 1, :tracker_id => 1
Chris@1115 1555 assert_response :success
Chris@1115 1556 assert_template 'new'
Chris@1115 1557
Chris@1115 1558 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
Chris@1115 1559 assert_select 'option', Project.find(1).users.count
Chris@1115 1560 assert_select 'option[value=2]', :text => 'John Smith'
Chris@1115 1561 end
Chris@1115 1562 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
Chris@1115 1563 end
Chris@1115 1564
Chris@1115 1565 def test_get_new_with_date_custom_field
Chris@1115 1566 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
Chris@1115 1567
Chris@1115 1568 @request.session[:user_id] = 2
Chris@1115 1569 get :new, :project_id => 1, :tracker_id => 1
Chris@1115 1570 assert_response :success
Chris@1115 1571
Chris@1115 1572 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
Chris@1115 1573 end
Chris@1115 1574
Chris@1115 1575 def test_get_new_with_text_custom_field
Chris@1115 1576 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
Chris@1115 1577
Chris@1115 1578 @request.session[:user_id] = 2
Chris@1115 1579 get :new, :project_id => 1, :tracker_id => 1
Chris@1115 1580 assert_response :success
Chris@1115 1581
Chris@1115 1582 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
Chris@1115 1583 end
Chris@1115 1584
Chris@1115 1585 def test_get_new_without_default_start_date_is_creation_date
Chris@1464 1586 with_settings :default_issue_start_date_to_creation_date => 0 do
Chris@1464 1587 @request.session[:user_id] = 2
Chris@1464 1588 get :new, :project_id => 1, :tracker_id => 1
Chris@1464 1589 assert_response :success
Chris@1464 1590 assert_template 'new'
Chris@1464 1591 assert_select 'input[name=?]', 'issue[start_date]'
Chris@1464 1592 assert_select 'input[name=?][value]', 'issue[start_date]', 0
Chris@1464 1593 end
Chris@1115 1594 end
Chris@1115 1595
Chris@1115 1596 def test_get_new_with_default_start_date_is_creation_date
Chris@1464 1597 with_settings :default_issue_start_date_to_creation_date => 1 do
Chris@1464 1598 @request.session[:user_id] = 2
Chris@1464 1599 get :new, :project_id => 1, :tracker_id => 1
Chris@1464 1600 assert_response :success
Chris@1464 1601 assert_template 'new'
Chris@1464 1602 assert_select 'input[name=?][value=?]', 'issue[start_date]',
Chris@1464 1603 Date.today.to_s
Chris@1464 1604 end
Chris@909 1605 end
Chris@909 1606
Chris@909 1607 def test_get_new_form_should_allow_attachment_upload
Chris@909 1608 @request.session[:user_id] = 2
Chris@909 1609 get :new, :project_id => 1, :tracker_id => 1
Chris@909 1610
Chris@1115 1611 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
Chris@1464 1612 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]'
Chris@1115 1613 end
Chris@1115 1614 end
Chris@1115 1615
Chris@1115 1616 def test_get_new_should_prefill_the_form_from_params
Chris@1115 1617 @request.session[:user_id] = 2
Chris@1115 1618 get :new, :project_id => 1,
Chris@1115 1619 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
Chris@1115 1620
Chris@1115 1621 issue = assigns(:issue)
Chris@1115 1622 assert_equal 3, issue.tracker_id
Chris@1115 1623 assert_equal 'Prefilled', issue.description
Chris@1115 1624 assert_equal 'Custom field value', issue.custom_field_value(2)
Chris@1115 1625
Chris@1115 1626 assert_select 'select[name=?]', 'issue[tracker_id]' do
Chris@1115 1627 assert_select 'option[value=3][selected=selected]'
Chris@1115 1628 end
Chris@1115 1629 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
Chris@1115 1630 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
Chris@1115 1631 end
Chris@1115 1632
Chris@1115 1633 def test_get_new_should_mark_required_fields
Chris@1115 1634 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1635 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1636 WorkflowPermission.delete_all
Chris@1115 1637 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
Chris@1115 1638 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
Chris@1115 1639 @request.session[:user_id] = 2
Chris@1115 1640
Chris@1115 1641 get :new, :project_id => 1
Chris@1115 1642 assert_response :success
Chris@1115 1643 assert_template 'new'
Chris@1115 1644
Chris@1115 1645 assert_select 'label[for=issue_start_date]' do
Chris@1115 1646 assert_select 'span[class=required]', 0
Chris@1115 1647 end
Chris@1115 1648 assert_select 'label[for=issue_due_date]' do
Chris@1115 1649 assert_select 'span[class=required]'
Chris@1115 1650 end
Chris@1115 1651 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
Chris@1115 1652 assert_select 'span[class=required]', 0
Chris@1115 1653 end
Chris@1115 1654 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
Chris@1115 1655 assert_select 'span[class=required]'
Chris@1115 1656 end
Chris@1115 1657 end
Chris@1115 1658
Chris@1115 1659 def test_get_new_should_not_display_readonly_fields
Chris@1115 1660 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1661 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1662 WorkflowPermission.delete_all
Chris@1115 1663 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
Chris@1115 1664 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
Chris@1115 1665 @request.session[:user_id] = 2
Chris@1115 1666
Chris@1115 1667 get :new, :project_id => 1
Chris@1115 1668 assert_response :success
Chris@1115 1669 assert_template 'new'
Chris@1115 1670
Chris@1115 1671 assert_select 'input[name=?]', 'issue[start_date]'
Chris@1115 1672 assert_select 'input[name=?]', 'issue[due_date]', 0
Chris@1115 1673 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
Chris@1115 1674 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
Chris@0 1675 end
Chris@0 1676
Chris@0 1677 def test_get_new_without_tracker_id
Chris@0 1678 @request.session[:user_id] = 2
Chris@0 1679 get :new, :project_id => 1
Chris@0 1680 assert_response :success
Chris@0 1681 assert_template 'new'
Chris@441 1682
Chris@0 1683 issue = assigns(:issue)
Chris@0 1684 assert_not_nil issue
Chris@0 1685 assert_equal Project.find(1).trackers.first, issue.tracker
Chris@0 1686 end
Chris@441 1687
Chris@0 1688 def test_get_new_with_no_default_status_should_display_an_error
Chris@0 1689 @request.session[:user_id] = 2
Chris@0 1690 IssueStatus.delete_all
Chris@441 1691
Chris@0 1692 get :new, :project_id => 1
Chris@0 1693 assert_response 500
chris@37 1694 assert_error_tag :content => /No default issue/
Chris@0 1695 end
Chris@441 1696
Chris@0 1697 def test_get_new_with_no_tracker_should_display_an_error
Chris@0 1698 @request.session[:user_id] = 2
Chris@0 1699 Tracker.delete_all
Chris@441 1700
Chris@0 1701 get :new, :project_id => 1
Chris@0 1702 assert_response 500
chris@37 1703 assert_error_tag :content => /No tracker/
Chris@0 1704 end
Chris@441 1705
Chris@1464 1706 def test_update_form_for_new_issue
Chris@0 1707 @request.session[:user_id] = 2
Chris@1464 1708 xhr :post, :update_form, :project_id => 1,
Chris@441 1709 :issue => {:tracker_id => 2,
Chris@0 1710 :subject => 'This is the test_new issue',
Chris@0 1711 :description => 'This is the description',
Chris@0 1712 :priority_id => 5}
Chris@0 1713 assert_response :success
Chris@1115 1714 assert_template 'update_form'
Chris@1517 1715 assert_template :partial => '_form'
Chris@1115 1716 assert_equal 'text/javascript', response.content_type
Chris@441 1717
Chris@0 1718 issue = assigns(:issue)
Chris@0 1719 assert_kind_of Issue, issue
Chris@0 1720 assert_equal 1, issue.project_id
Chris@0 1721 assert_equal 2, issue.tracker_id
Chris@0 1722 assert_equal 'This is the test_new issue', issue.subject
Chris@0 1723 end
Chris@441 1724
Chris@1464 1725 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status
Chris@1115 1726 @request.session[:user_id] = 2
Chris@1115 1727 WorkflowTransition.delete_all
Chris@1115 1728 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
Chris@1115 1729 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
Chris@1115 1730 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
Chris@1115 1731
Chris@1464 1732 xhr :post, :update_form, :project_id => 1,
Chris@1115 1733 :issue => {:tracker_id => 1,
Chris@1115 1734 :status_id => 5,
Chris@1115 1735 :subject => 'This is an issue'}
Chris@1115 1736
Chris@1115 1737 assert_equal 5, assigns(:issue).status_id
Chris@1115 1738 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
Chris@1115 1739 end
Chris@1115 1740
Chris@0 1741 def test_post_create
Chris@0 1742 @request.session[:user_id] = 2
Chris@0 1743 assert_difference 'Issue.count' do
Chris@441 1744 post :create, :project_id => 1,
Chris@0 1745 :issue => {:tracker_id => 3,
Chris@0 1746 :status_id => 2,
Chris@0 1747 :subject => 'This is the test_new issue',
Chris@0 1748 :description => 'This is the description',
Chris@0 1749 :priority_id => 5,
chris@37 1750 :start_date => '2010-11-07',
Chris@0 1751 :estimated_hours => '',
Chris@0 1752 :custom_field_values => {'2' => 'Value for field 2'}}
Chris@0 1753 end
Chris@0 1754 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
Chris@441 1755
Chris@0 1756 issue = Issue.find_by_subject('This is the test_new issue')
Chris@0 1757 assert_not_nil issue
Chris@0 1758 assert_equal 2, issue.author_id
Chris@0 1759 assert_equal 3, issue.tracker_id
Chris@0 1760 assert_equal 2, issue.status_id
chris@37 1761 assert_equal Date.parse('2010-11-07'), issue.start_date
Chris@0 1762 assert_nil issue.estimated_hours
Chris@1464 1763 v = issue.custom_values.where(:custom_field_id => 2).first
Chris@0 1764 assert_not_nil v
Chris@0 1765 assert_equal 'Value for field 2', v.value
Chris@0 1766 end
Chris@441 1767
Chris@909 1768 def test_post_new_with_group_assignment
Chris@909 1769 group = Group.find(11)
Chris@909 1770 project = Project.find(1)
Chris@929 1771 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
Chris@909 1772
Chris@909 1773 with_settings :issue_group_assignment => '1' do
Chris@909 1774 @request.session[:user_id] = 2
Chris@909 1775 assert_difference 'Issue.count' do
Chris@909 1776 post :create, :project_id => project.id,
Chris@909 1777 :issue => {:tracker_id => 3,
Chris@909 1778 :status_id => 1,
Chris@909 1779 :subject => 'This is the test_new_with_group_assignment issue',
Chris@909 1780 :assigned_to_id => group.id}
Chris@909 1781 end
Chris@909 1782 end
Chris@909 1783 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
Chris@909 1784
Chris@909 1785 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
Chris@909 1786 assert_not_nil issue
Chris@909 1787 assert_equal group, issue.assigned_to
Chris@909 1788 end
Chris@909 1789
Chris@909 1790 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
Chris@1464 1791 with_settings :default_issue_start_date_to_creation_date => 0 do
Chris@1464 1792 @request.session[:user_id] = 2
Chris@1464 1793 assert_difference 'Issue.count' do
Chris@1464 1794 post :create, :project_id => 1,
chris@37 1795 :issue => {:tracker_id => 3,
chris@37 1796 :status_id => 2,
chris@37 1797 :subject => 'This is the test_new issue',
chris@37 1798 :description => 'This is the description',
chris@37 1799 :priority_id => 5,
chris@37 1800 :estimated_hours => '',
chris@37 1801 :custom_field_values => {'2' => 'Value for field 2'}}
Chris@1464 1802 end
Chris@1464 1803 assert_redirected_to :controller => 'issues', :action => 'show',
Chris@1464 1804 :id => Issue.last.id
Chris@1464 1805 issue = Issue.find_by_subject('This is the test_new issue')
Chris@1464 1806 assert_not_nil issue
Chris@1464 1807 assert_nil issue.start_date
chris@37 1808 end
chris@37 1809 end
Chris@441 1810
Chris@909 1811 def test_post_create_without_start_date_and_default_start_date_is_creation_date
Chris@1464 1812 with_settings :default_issue_start_date_to_creation_date => 1 do
Chris@1464 1813 @request.session[:user_id] = 2
Chris@1464 1814 assert_difference 'Issue.count' do
Chris@1464 1815 post :create, :project_id => 1,
Chris@909 1816 :issue => {:tracker_id => 3,
Chris@909 1817 :status_id => 2,
Chris@909 1818 :subject => 'This is the test_new issue',
Chris@909 1819 :description => 'This is the description',
Chris@909 1820 :priority_id => 5,
Chris@909 1821 :estimated_hours => '',
Chris@909 1822 :custom_field_values => {'2' => 'Value for field 2'}}
Chris@1464 1823 end
Chris@1464 1824 assert_redirected_to :controller => 'issues', :action => 'show',
Chris@1464 1825 :id => Issue.last.id
Chris@1464 1826 issue = Issue.find_by_subject('This is the test_new issue')
Chris@1464 1827 assert_not_nil issue
Chris@1464 1828 assert_equal Date.today, issue.start_date
Chris@909 1829 end
Chris@909 1830 end
Chris@909 1831
Chris@0 1832 def test_post_create_and_continue
Chris@0 1833 @request.session[:user_id] = 2
Chris@909 1834 assert_difference 'Issue.count' do
Chris@909 1835 post :create, :project_id => 1,
Chris@909 1836 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
Chris@909 1837 :continue => ''
Chris@909 1838 end
Chris@909 1839
Chris@1517 1840 issue = Issue.order('id DESC').first
Chris@909 1841 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
Chris@909 1842 assert_not_nil flash[:notice], "flash was not set"
Chris@1115 1843 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
Chris@0 1844 end
Chris@441 1845
Chris@0 1846 def test_post_create_without_custom_fields_param
Chris@0 1847 @request.session[:user_id] = 2
Chris@0 1848 assert_difference 'Issue.count' do
Chris@441 1849 post :create, :project_id => 1,
Chris@0 1850 :issue => {:tracker_id => 1,
Chris@0 1851 :subject => 'This is the test_new issue',
Chris@0 1852 :description => 'This is the description',
Chris@0 1853 :priority_id => 5}
Chris@0 1854 end
Chris@0 1855 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
Chris@0 1856 end
Chris@0 1857
Chris@1115 1858 def test_post_create_with_multi_custom_field
Chris@1115 1859 field = IssueCustomField.find_by_name('Database')
Chris@1115 1860 field.update_attribute(:multiple, true)
Chris@1115 1861
Chris@1115 1862 @request.session[:user_id] = 2
Chris@1115 1863 assert_difference 'Issue.count' do
Chris@1115 1864 post :create, :project_id => 1,
Chris@1115 1865 :issue => {:tracker_id => 1,
Chris@1115 1866 :subject => 'This is the test_new issue',
Chris@1115 1867 :description => 'This is the description',
Chris@1115 1868 :priority_id => 5,
Chris@1115 1869 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
Chris@1115 1870 end
Chris@1115 1871 assert_response 302
Chris@1517 1872 issue = Issue.order('id DESC').first
Chris@1115 1873 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
Chris@1115 1874 end
Chris@1115 1875
Chris@1115 1876 def test_post_create_with_empty_multi_custom_field
Chris@1115 1877 field = IssueCustomField.find_by_name('Database')
Chris@1115 1878 field.update_attribute(:multiple, true)
Chris@1115 1879
Chris@1115 1880 @request.session[:user_id] = 2
Chris@1115 1881 assert_difference 'Issue.count' do
Chris@1115 1882 post :create, :project_id => 1,
Chris@1115 1883 :issue => {:tracker_id => 1,
Chris@1115 1884 :subject => 'This is the test_new issue',
Chris@1115 1885 :description => 'This is the description',
Chris@1115 1886 :priority_id => 5,
Chris@1115 1887 :custom_field_values => {'1' => ['']}}
Chris@1115 1888 end
Chris@1115 1889 assert_response 302
Chris@1517 1890 issue = Issue.order('id DESC').first
Chris@1115 1891 assert_equal [''], issue.custom_field_value(1).sort
Chris@1115 1892 end
Chris@1115 1893
Chris@1115 1894 def test_post_create_with_multi_user_custom_field
Chris@1115 1895 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
Chris@1115 1896 :tracker_ids => [1], :is_for_all => true)
Chris@1115 1897
Chris@1115 1898 @request.session[:user_id] = 2
Chris@1115 1899 assert_difference 'Issue.count' do
Chris@1115 1900 post :create, :project_id => 1,
Chris@1115 1901 :issue => {:tracker_id => 1,
Chris@1115 1902 :subject => 'This is the test_new issue',
Chris@1115 1903 :description => 'This is the description',
Chris@1115 1904 :priority_id => 5,
Chris@1115 1905 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
Chris@1115 1906 end
Chris@1115 1907 assert_response 302
Chris@1517 1908 issue = Issue.order('id DESC').first
Chris@1115 1909 assert_equal ['2', '3'], issue.custom_field_value(field).sort
Chris@1115 1910 end
Chris@1115 1911
Chris@0 1912 def test_post_create_with_required_custom_field_and_without_custom_fields_param
Chris@0 1913 field = IssueCustomField.find_by_name('Database')
Chris@0 1914 field.update_attribute(:is_required, true)
Chris@0 1915
Chris@0 1916 @request.session[:user_id] = 2
Chris@1115 1917 assert_no_difference 'Issue.count' do
Chris@1115 1918 post :create, :project_id => 1,
Chris@1115 1919 :issue => {:tracker_id => 1,
Chris@1115 1920 :subject => 'This is the test_new issue',
Chris@1115 1921 :description => 'This is the description',
Chris@1115 1922 :priority_id => 5}
Chris@1115 1923 end
Chris@0 1924 assert_response :success
Chris@0 1925 assert_template 'new'
Chris@0 1926 issue = assigns(:issue)
Chris@0 1927 assert_not_nil issue
Chris@1517 1928 assert_error_tag :content => /Database #{ESCAPED_CANT} be blank/
Chris@1115 1929 end
Chris@1115 1930
Chris@1115 1931 def test_create_should_validate_required_fields
Chris@1115 1932 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1933 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1934 WorkflowPermission.delete_all
Chris@1115 1935 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
Chris@1115 1936 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
Chris@1115 1937 @request.session[:user_id] = 2
Chris@1115 1938
Chris@1115 1939 assert_no_difference 'Issue.count' do
Chris@1115 1940 post :create, :project_id => 1, :issue => {
Chris@1115 1941 :tracker_id => 2,
Chris@1115 1942 :status_id => 1,
Chris@1115 1943 :subject => 'Test',
Chris@1115 1944 :start_date => '',
Chris@1115 1945 :due_date => '',
Chris@1115 1946 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
Chris@1115 1947 }
Chris@1115 1948 assert_response :success
Chris@1115 1949 assert_template 'new'
Chris@1115 1950 end
Chris@1115 1951
Chris@1517 1952 assert_error_tag :content => /Due date #{ESCAPED_CANT} be blank/i
Chris@1517 1953 assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i
Chris@1115 1954 end
Chris@1115 1955
Chris@1115 1956 def test_create_should_ignore_readonly_fields
Chris@1115 1957 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1958 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
Chris@1115 1959 WorkflowPermission.delete_all
Chris@1115 1960 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
Chris@1115 1961 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
Chris@1115 1962 @request.session[:user_id] = 2
Chris@1115 1963
Chris@1115 1964 assert_difference 'Issue.count' do
Chris@1115 1965 post :create, :project_id => 1, :issue => {
Chris@1115 1966 :tracker_id => 2,
Chris@1115 1967 :status_id => 1,
Chris@1115 1968 :subject => 'Test',
Chris@1115 1969 :start_date => '2012-07-14',
Chris@1115 1970 :due_date => '2012-07-16',
Chris@1115 1971 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
Chris@1115 1972 }
Chris@1115 1973 assert_response 302
Chris@1115 1974 end
Chris@1115 1975
Chris@1517 1976 issue = Issue.order('id DESC').first
Chris@1115 1977 assert_equal Date.parse('2012-07-14'), issue.start_date
Chris@1115 1978 assert_nil issue.due_date
Chris@1115 1979 assert_equal 'value1', issue.custom_field_value(cf1)
Chris@1115 1980 assert_nil issue.custom_field_value(cf2)
Chris@0 1981 end
Chris@441 1982
Chris@0 1983 def test_post_create_with_watchers
Chris@0 1984 @request.session[:user_id] = 2
Chris@0 1985 ActionMailer::Base.deliveries.clear
Chris@441 1986
Chris@0 1987 assert_difference 'Watcher.count', 2 do
Chris@441 1988 post :create, :project_id => 1,
Chris@0 1989 :issue => {:tracker_id => 1,
Chris@0 1990 :subject => 'This is a new issue with watchers',
Chris@0 1991 :description => 'This is the description',
Chris@0 1992 :priority_id => 5,
Chris@0 1993 :watcher_user_ids => ['2', '3']}
Chris@0 1994 end
Chris@0 1995 issue = Issue.find_by_subject('This is a new issue with watchers')
Chris@0 1996 assert_not_nil issue
Chris@0 1997 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
Chris@441 1998
Chris@0 1999 # Watchers added
Chris@0 2000 assert_equal [2, 3], issue.watcher_user_ids.sort
Chris@0 2001 assert issue.watched_by?(User.find(3))
Chris@0 2002 # Watchers notified
Chris@0 2003 mail = ActionMailer::Base.deliveries.last
Chris@1115 2004 assert_not_nil mail
Chris@0 2005 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
Chris@0 2006 end
Chris@441 2007
Chris@0 2008 def test_post_create_subissue
Chris@0 2009 @request.session[:user_id] = 2
Chris@441 2010
Chris@0 2011 assert_difference 'Issue.count' do
Chris@441 2012 post :create, :project_id => 1,
Chris@0 2013 :issue => {:tracker_id => 1,
Chris@0 2014 :subject => 'This is a child issue',
Chris@1115 2015 :parent_issue_id => '2'}
Chris@1115 2016 assert_response 302
Chris@0 2017 end
Chris@1115 2018 issue = Issue.order('id DESC').first
Chris@0 2019 assert_equal Issue.find(2), issue.parent
Chris@0 2020 end
Chris@119 2021
Chris@1115 2022 def test_post_create_subissue_with_sharp_parent_id
Chris@119 2023 @request.session[:user_id] = 2
Chris@441 2024
Chris@119 2025 assert_difference 'Issue.count' do
Chris@441 2026 post :create, :project_id => 1,
Chris@119 2027 :issue => {:tracker_id => 1,
Chris@119 2028 :subject => 'This is a child issue',
Chris@1115 2029 :parent_issue_id => '#2'}
Chris@1115 2030 assert_response 302
Chris@119 2031 end
Chris@1115 2032 issue = Issue.order('id DESC').first
Chris@1115 2033 assert_equal Issue.find(2), issue.parent
Chris@1115 2034 end
Chris@1115 2035
Chris@1115 2036 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
Chris@1115 2037 @request.session[:user_id] = 2
Chris@1115 2038
Chris@1115 2039 assert_no_difference 'Issue.count' do
Chris@1115 2040 post :create, :project_id => 1,
Chris@1115 2041 :issue => {:tracker_id => 1,
Chris@1115 2042 :subject => 'This is a child issue',
Chris@1115 2043 :parent_issue_id => '4'}
Chris@1115 2044
Chris@1115 2045 assert_response :success
Chris@1115 2046 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
Chris@1115 2047 assert_error_tag :content => /Parent task is invalid/i
Chris@1115 2048 end
Chris@1115 2049 end
Chris@1115 2050
Chris@1115 2051 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
Chris@1115 2052 @request.session[:user_id] = 2
Chris@1115 2053
Chris@1115 2054 assert_no_difference 'Issue.count' do
Chris@1115 2055 post :create, :project_id => 1,
Chris@1115 2056 :issue => {:tracker_id => 1,
Chris@1115 2057 :subject => 'This is a child issue',
Chris@1115 2058 :parent_issue_id => '01ABC'}
Chris@1115 2059
Chris@1115 2060 assert_response :success
Chris@1115 2061 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
Chris@1115 2062 assert_error_tag :content => /Parent task is invalid/i
Chris@1115 2063 end
Chris@119 2064 end
Chris@909 2065
Chris@507 2066 def test_post_create_private
Chris@507 2067 @request.session[:user_id] = 2
Chris@507 2068
Chris@507 2069 assert_difference 'Issue.count' do
Chris@507 2070 post :create, :project_id => 1,
Chris@507 2071 :issue => {:tracker_id => 1,
Chris@507 2072 :subject => 'This is a private issue',
Chris@507 2073 :is_private => '1'}
Chris@507 2074 end
Chris@1517 2075 issue = Issue.order('id DESC').first
Chris@507 2076 assert issue.is_private?
Chris@507 2077 end
Chris@909 2078
Chris@507 2079 def test_post_create_private_with_set_own_issues_private_permission
Chris@507 2080 role = Role.find(1)
Chris@507 2081 role.remove_permission! :set_issues_private
Chris@507 2082 role.add_permission! :set_own_issues_private
Chris@909 2083
Chris@507 2084 @request.session[:user_id] = 2
Chris@507 2085
Chris@507 2086 assert_difference 'Issue.count' do
Chris@507 2087 post :create, :project_id => 1,
Chris@507 2088 :issue => {:tracker_id => 1,
Chris@507 2089 :subject => 'This is a private issue',
Chris@507 2090 :is_private => '1'}
Chris@507 2091 end
Chris@1517 2092 issue = Issue.order('id DESC').first
Chris@507 2093 assert issue.is_private?
Chris@507 2094 end
Chris@441 2095
Chris@0 2096 def test_post_create_should_send_a_notification
Chris@0 2097 ActionMailer::Base.deliveries.clear
Chris@0 2098 @request.session[:user_id] = 2
Chris@0 2099 assert_difference 'Issue.count' do
Chris@441 2100 post :create, :project_id => 1,
Chris@0 2101 :issue => {:tracker_id => 3,
Chris@0 2102 :subject => 'This is the test_new issue',
Chris@0 2103 :description => 'This is the description',
Chris@0 2104 :priority_id => 5,
Chris@0 2105 :estimated_hours => '',
Chris@0 2106 :custom_field_values => {'2' => 'Value for field 2'}}
Chris@0 2107 end
Chris@0 2108 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
Chris@441 2109
Chris@0 2110 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 2111 end
Chris@441 2112
Chris@0 2113 def test_post_create_should_preserve_fields_values_on_validation_failure
Chris@0 2114 @request.session[:user_id] = 2
Chris@441 2115 post :create, :project_id => 1,
Chris@0 2116 :issue => {:tracker_id => 1,
Chris@0 2117 # empty subject
Chris@0 2118 :subject => '',
Chris@0 2119 :description => 'This is a description',
Chris@0 2120 :priority_id => 6,
Chris@0 2121 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
Chris@0 2122 assert_response :success
Chris@0 2123 assert_template 'new'
Chris@441 2124
Chris@1464 2125 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description'
Chris@1464 2126 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1464 2127 assert_select 'option[value=6][selected=selected]', :text => 'High'
Chris@1464 2128 end
Chris@0 2129 # Custom fields
Chris@1464 2130 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do
Chris@1464 2131 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle'
Chris@1464 2132 end
Chris@1464 2133 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2'
Chris@0 2134 end
Chris@441 2135
Chris@1115 2136 def test_post_create_with_failure_should_preserve_watchers
Chris@1115 2137 assert !User.find(8).member_of?(Project.find(1))
Chris@1115 2138
Chris@1115 2139 @request.session[:user_id] = 2
Chris@1115 2140 post :create, :project_id => 1,
Chris@1115 2141 :issue => {:tracker_id => 1,
Chris@1115 2142 :watcher_user_ids => ['3', '8']}
Chris@1115 2143 assert_response :success
Chris@1115 2144 assert_template 'new'
Chris@1115 2145
Chris@1464 2146 assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]'
Chris@1464 2147 assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]'
Chris@1464 2148 assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]'
Chris@1115 2149 end
Chris@1115 2150
Chris@0 2151 def test_post_create_should_ignore_non_safe_attributes
Chris@0 2152 @request.session[:user_id] = 2
Chris@0 2153 assert_nothing_raised do
Chris@0 2154 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
Chris@0 2155 end
Chris@0 2156 end
Chris@441 2157
Chris@909 2158 def test_post_create_with_attachment
Chris@909 2159 set_tmp_attachments_directory
Chris@909 2160 @request.session[:user_id] = 2
Chris@909 2161
Chris@909 2162 assert_difference 'Issue.count' do
Chris@909 2163 assert_difference 'Attachment.count' do
Chris@909 2164 post :create, :project_id => 1,
Chris@909 2165 :issue => { :tracker_id => '1', :subject => 'With attachment' },
Chris@909 2166 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@909 2167 end
Chris@909 2168 end
Chris@909 2169
Chris@1517 2170 issue = Issue.order('id DESC').first
Chris@1517 2171 attachment = Attachment.order('id DESC').first
Chris@909 2172
Chris@909 2173 assert_equal issue, attachment.container
Chris@909 2174 assert_equal 2, attachment.author_id
Chris@909 2175 assert_equal 'testfile.txt', attachment.filename
Chris@909 2176 assert_equal 'text/plain', attachment.content_type
Chris@909 2177 assert_equal 'test file', attachment.description
Chris@909 2178 assert_equal 59, attachment.filesize
Chris@909 2179 assert File.exists?(attachment.diskfile)
Chris@909 2180 assert_equal 59, File.size(attachment.diskfile)
Chris@909 2181 end
Chris@909 2182
Chris@1464 2183 def test_post_create_with_attachment_should_notify_with_attachments
Chris@1464 2184 ActionMailer::Base.deliveries.clear
Chris@1464 2185 set_tmp_attachments_directory
Chris@1464 2186 @request.session[:user_id] = 2
Chris@1464 2187
Chris@1464 2188 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
Chris@1464 2189 assert_difference 'Issue.count' do
Chris@1464 2190 post :create, :project_id => 1,
Chris@1464 2191 :issue => { :tracker_id => '1', :subject => 'With attachment' },
Chris@1464 2192 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@1464 2193 end
Chris@1464 2194 end
Chris@1464 2195
Chris@1464 2196 assert_not_nil ActionMailer::Base.deliveries.last
Chris@1464 2197 assert_select_email do
Chris@1464 2198 assert_select 'a[href^=?]', 'http://mydomain.foo/attachments/download', 'testfile.txt'
Chris@1464 2199 end
Chris@1464 2200 end
Chris@1464 2201
Chris@1115 2202 def test_post_create_with_failure_should_save_attachments
Chris@1115 2203 set_tmp_attachments_directory
Chris@1115 2204 @request.session[:user_id] = 2
Chris@1115 2205
Chris@1115 2206 assert_no_difference 'Issue.count' do
Chris@1115 2207 assert_difference 'Attachment.count' do
Chris@1115 2208 post :create, :project_id => 1,
Chris@1115 2209 :issue => { :tracker_id => '1', :subject => '' },
Chris@1115 2210 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@1115 2211 assert_response :success
Chris@1115 2212 assert_template 'new'
Chris@1115 2213 end
Chris@1115 2214 end
Chris@1115 2215
Chris@1517 2216 attachment = Attachment.order('id DESC').first
Chris@1115 2217 assert_equal 'testfile.txt', attachment.filename
Chris@1115 2218 assert File.exists?(attachment.diskfile)
Chris@1115 2219 assert_nil attachment.container
Chris@1115 2220
Chris@1464 2221 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
Chris@1464 2222 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
Chris@1115 2223 end
Chris@1115 2224
Chris@1115 2225 def test_post_create_with_failure_should_keep_saved_attachments
Chris@1115 2226 set_tmp_attachments_directory
Chris@1115 2227 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
Chris@1115 2228 @request.session[:user_id] = 2
Chris@1115 2229
Chris@1115 2230 assert_no_difference 'Issue.count' do
Chris@1115 2231 assert_no_difference 'Attachment.count' do
Chris@1115 2232 post :create, :project_id => 1,
Chris@1115 2233 :issue => { :tracker_id => '1', :subject => '' },
Chris@1115 2234 :attachments => {'p0' => {'token' => attachment.token}}
Chris@1115 2235 assert_response :success
Chris@1115 2236 assert_template 'new'
Chris@1115 2237 end
Chris@1115 2238 end
Chris@1115 2239
Chris@1464 2240 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
Chris@1464 2241 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
Chris@1115 2242 end
Chris@1115 2243
Chris@1115 2244 def test_post_create_should_attach_saved_attachments
Chris@1115 2245 set_tmp_attachments_directory
Chris@1115 2246 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
Chris@1115 2247 @request.session[:user_id] = 2
Chris@1115 2248
Chris@1115 2249 assert_difference 'Issue.count' do
Chris@1115 2250 assert_no_difference 'Attachment.count' do
Chris@1115 2251 post :create, :project_id => 1,
Chris@1115 2252 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
Chris@1115 2253 :attachments => {'p0' => {'token' => attachment.token}}
Chris@1115 2254 assert_response 302
Chris@1115 2255 end
Chris@1115 2256 end
Chris@1115 2257
Chris@1517 2258 issue = Issue.order('id DESC').first
Chris@1115 2259 assert_equal 1, issue.attachments.count
Chris@1115 2260
Chris@1115 2261 attachment.reload
Chris@1115 2262 assert_equal issue, attachment.container
Chris@1115 2263 end
Chris@1115 2264
Chris@1517 2265 def setup_without_workflow_privilege
Chris@1517 2266 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
Chris@1517 2267 Role.anonymous.add_permission! :add_issues, :add_issue_notes
Chris@1517 2268 end
Chris@1517 2269 private :setup_without_workflow_privilege
Chris@1517 2270
Chris@1517 2271 test "without workflow privilege #new should propose default status only" do
Chris@1517 2272 setup_without_workflow_privilege
Chris@1517 2273 get :new, :project_id => 1
Chris@1517 2274 assert_response :success
Chris@1517 2275 assert_template 'new'
Chris@1517 2276 assert_select 'select[name=?]', 'issue[status_id]' do
Chris@1517 2277 assert_select 'option', 1
Chris@1517 2278 assert_select 'option[value=?]', IssueStatus.default.id.to_s
Chris@0 2279 end
Chris@1517 2280 end
Chris@1517 2281
Chris@1517 2282 test "without workflow privilege #new should accept default status" do
Chris@1517 2283 setup_without_workflow_privilege
Chris@1517 2284 assert_difference 'Issue.count' do
Chris@1517 2285 post :create, :project_id => 1,
Chris@1517 2286 :issue => {:tracker_id => 1,
Chris@0 2287 :subject => 'This is an issue',
Chris@0 2288 :status_id => 1}
Chris@1517 2289 end
Chris@1517 2290 issue = Issue.order('id').last
Chris@1517 2291 assert_equal IssueStatus.default, issue.status
Chris@1517 2292 end
Chris@1517 2293
Chris@1517 2294 test "without workflow privilege #new should ignore unauthorized status" do
Chris@1517 2295 setup_without_workflow_privilege
Chris@1517 2296 assert_difference 'Issue.count' do
Chris@1517 2297 post :create, :project_id => 1,
Chris@0 2298 :issue => {:tracker_id => 1,
Chris@0 2299 :subject => 'This is an issue',
Chris@0 2300 :status_id => 3}
Chris@0 2301 end
Chris@1517 2302 issue = Issue.order('id').last
Chris@1517 2303 assert_equal IssueStatus.default, issue.status
Chris@1517 2304 end
Chris@1517 2305
Chris@1517 2306 test "without workflow privilege #update should ignore status change" do
Chris@1517 2307 setup_without_workflow_privilege
Chris@1517 2308 assert_difference 'Journal.count' do
Chris@1517 2309 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
chris@37 2310 end
Chris@1517 2311 assert_equal 1, Issue.find(1).status_id
Chris@1517 2312 end
Chris@1517 2313
Chris@1517 2314 test "without workflow privilege #update ignore attributes changes" do
Chris@1517 2315 setup_without_workflow_privilege
Chris@1517 2316 assert_difference 'Journal.count' do
Chris@1517 2317 put :update, :id => 1,
Chris@1517 2318 :issue => {:subject => 'changed', :assigned_to_id => 2,
Chris@1517 2319 :notes => 'just trying'}
chris@37 2320 end
Chris@1517 2321 issue = Issue.find(1)
Chris@1517 2322 assert_equal "Can't print recipes", issue.subject
Chris@1517 2323 assert_nil issue.assigned_to
Chris@1517 2324 end
Chris@1517 2325
Chris@1517 2326 def setup_with_workflow_privilege
Chris@1517 2327 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
Chris@1517 2328 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
Chris@1517 2329 :old_status_id => 1, :new_status_id => 3)
Chris@1517 2330 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
Chris@1517 2331 :old_status_id => 1, :new_status_id => 4)
Chris@1517 2332 Role.anonymous.add_permission! :add_issues, :add_issue_notes
Chris@1517 2333 end
Chris@1517 2334 private :setup_with_workflow_privilege
Chris@1517 2335
Chris@1517 2336 test "with workflow privilege #update should accept authorized status" do
Chris@1517 2337 setup_with_workflow_privilege
Chris@1517 2338 assert_difference 'Journal.count' do
Chris@1517 2339 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
chris@37 2340 end
Chris@1517 2341 assert_equal 3, Issue.find(1).status_id
Chris@1517 2342 end
Chris@1517 2343
Chris@1517 2344 test "with workflow privilege #update should ignore unauthorized status" do
Chris@1517 2345 setup_with_workflow_privilege
Chris@1517 2346 assert_difference 'Journal.count' do
Chris@1517 2347 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
chris@37 2348 end
Chris@1517 2349 assert_equal 1, Issue.find(1).status_id
Chris@1517 2350 end
Chris@1517 2351
Chris@1517 2352 test "with workflow privilege #update should accept authorized attributes changes" do
Chris@1517 2353 setup_with_workflow_privilege
Chris@1517 2354 assert_difference 'Journal.count' do
Chris@1517 2355 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
Chris@1517 2356 end
Chris@1517 2357 issue = Issue.find(1)
Chris@1517 2358 assert_equal 2, issue.assigned_to_id
Chris@1517 2359 end
Chris@1517 2360
Chris@1517 2361 test "with workflow privilege #update should ignore unauthorized attributes changes" do
Chris@1517 2362 setup_with_workflow_privilege
Chris@1517 2363 assert_difference 'Journal.count' do
Chris@1517 2364 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
Chris@1517 2365 end
Chris@1517 2366 issue = Issue.find(1)
Chris@1517 2367 assert_equal "Can't print recipes", issue.subject
Chris@1517 2368 end
Chris@1517 2369
Chris@1517 2370 def setup_with_workflow_privilege_and_edit_issues_permission
Chris@1517 2371 setup_with_workflow_privilege
Chris@1517 2372 Role.anonymous.add_permission! :add_issues, :edit_issues
Chris@1517 2373 end
Chris@1517 2374 private :setup_with_workflow_privilege_and_edit_issues_permission
Chris@1517 2375
Chris@1517 2376 test "with workflow privilege and :edit_issues permission should accept authorized status" do
Chris@1517 2377 setup_with_workflow_privilege_and_edit_issues_permission
Chris@1517 2378 assert_difference 'Journal.count' do
Chris@1517 2379 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
Chris@1517 2380 end
Chris@1517 2381 assert_equal 3, Issue.find(1).status_id
Chris@1517 2382 end
Chris@1517 2383
Chris@1517 2384 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
Chris@1517 2385 setup_with_workflow_privilege_and_edit_issues_permission
Chris@1517 2386 assert_difference 'Journal.count' do
Chris@1517 2387 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
Chris@1517 2388 end
Chris@1517 2389 assert_equal 1, Issue.find(1).status_id
Chris@1517 2390 end
Chris@1517 2391
Chris@1517 2392 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
Chris@1517 2393 setup_with_workflow_privilege_and_edit_issues_permission
Chris@1517 2394 assert_difference 'Journal.count' do
Chris@1517 2395 put :update, :id => 1,
Chris@1517 2396 :issue => {:subject => 'changed', :assigned_to_id => 2,
Chris@1517 2397 :notes => 'just trying'}
Chris@1517 2398 end
Chris@1517 2399 issue = Issue.find(1)
Chris@1517 2400 assert_equal "changed", issue.subject
Chris@1517 2401 assert_equal 2, issue.assigned_to_id
Chris@0 2402 end
Chris@441 2403
Chris@1115 2404 def test_new_as_copy
Chris@0 2405 @request.session[:user_id] = 2
Chris@0 2406 get :new, :project_id => 1, :copy_from => 1
Chris@1115 2407
Chris@1115 2408 assert_response :success
Chris@0 2409 assert_template 'new'
Chris@1115 2410
Chris@0 2411 assert_not_nil assigns(:issue)
Chris@0 2412 orig = Issue.find(1)
Chris@1115 2413 assert_equal 1, assigns(:issue).project_id
Chris@0 2414 assert_equal orig.subject, assigns(:issue).subject
Chris@1115 2415 assert assigns(:issue).copy?
Chris@1115 2416
Chris@1464 2417 assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do
Chris@1464 2418 assert_select 'select[name=?]', 'issue[project_id]' do
Chris@1464 2419 assert_select 'option[value=1][selected=selected]', :text => 'eCookbook'
Chris@1464 2420 assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore'
Chris@1464 2421 end
Chris@1464 2422 assert_select 'input[name=copy_from][value=1]'
Chris@1464 2423 end
Chris@1294 2424
Chris@1294 2425 # "New issue" menu item should not link to copy
Chris@1294 2426 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]'
Chris@1115 2427 end
Chris@1115 2428
Chris@1115 2429 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
Chris@1115 2430 @request.session[:user_id] = 2
Chris@1115 2431 issue = Issue.find(3)
Chris@1115 2432 assert issue.attachments.count > 0
Chris@1115 2433 get :new, :project_id => 1, :copy_from => 3
Chris@1115 2434
Chris@1464 2435 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]'
Chris@1115 2436 end
Chris@1115 2437
Chris@1115 2438 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
Chris@1115 2439 @request.session[:user_id] = 2
Chris@1115 2440 issue = Issue.find(3)
Chris@1115 2441 issue.attachments.delete_all
Chris@1115 2442 get :new, :project_id => 1, :copy_from => 3
Chris@1115 2443
Chris@1464 2444 assert_select 'input[name=copy_attachments]', 0
Chris@1115 2445 end
Chris@1115 2446
Chris@1115 2447 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
Chris@1115 2448 @request.session[:user_id] = 2
Chris@1115 2449 issue = Issue.generate_with_descendants!
Chris@1115 2450 get :new, :project_id => 1, :copy_from => issue.id
Chris@1115 2451
Chris@1115 2452 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]'
Chris@1115 2453 end
Chris@1115 2454
Chris@1115 2455 def test_new_as_copy_with_invalid_issue_should_respond_with_404
Chris@1115 2456 @request.session[:user_id] = 2
Chris@1115 2457 get :new, :project_id => 1, :copy_from => 99999
Chris@1115 2458 assert_response 404
Chris@1115 2459 end
Chris@1115 2460
Chris@1115 2461 def test_create_as_copy_on_different_project
Chris@1115 2462 @request.session[:user_id] = 2
Chris@1115 2463 assert_difference 'Issue.count' do
Chris@1115 2464 post :create, :project_id => 1, :copy_from => 1,
Chris@1115 2465 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
Chris@1115 2466
Chris@1115 2467 assert_not_nil assigns(:issue)
Chris@1115 2468 assert assigns(:issue).copy?
Chris@1115 2469 end
Chris@1517 2470 issue = Issue.order('id DESC').first
Chris@1115 2471 assert_redirected_to "/issues/#{issue.id}"
Chris@1115 2472
Chris@1115 2473 assert_equal 2, issue.project_id
Chris@1115 2474 assert_equal 3, issue.tracker_id
Chris@1115 2475 assert_equal 'Copy', issue.subject
Chris@1115 2476 end
Chris@1115 2477
Chris@1115 2478 def test_create_as_copy_should_copy_attachments
Chris@1115 2479 @request.session[:user_id] = 2
Chris@1115 2480 issue = Issue.find(3)
Chris@1115 2481 count = issue.attachments.count
Chris@1115 2482 assert count > 0
Chris@1115 2483 assert_difference 'Issue.count' do
Chris@1115 2484 assert_difference 'Attachment.count', count do
Chris@1464 2485 assert_difference 'Journal.count', 2 do
Chris@1115 2486 post :create, :project_id => 1, :copy_from => 3,
Chris@1464 2487 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2488 :status_id => '1', :subject => 'Copy with attachments'},
Chris@1115 2489 :copy_attachments => '1'
Chris@1115 2490 end
Chris@1115 2491 end
Chris@1115 2492 end
Chris@1517 2493 copy = Issue.order('id DESC').first
Chris@1115 2494 assert_equal count, copy.attachments.count
Chris@1115 2495 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
Chris@1115 2496 end
Chris@1115 2497
Chris@1115 2498 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
Chris@1115 2499 @request.session[:user_id] = 2
Chris@1115 2500 issue = Issue.find(3)
Chris@1115 2501 count = issue.attachments.count
Chris@1115 2502 assert count > 0
Chris@1115 2503 assert_difference 'Issue.count' do
Chris@1115 2504 assert_no_difference 'Attachment.count' do
Chris@1464 2505 assert_difference 'Journal.count', 2 do
Chris@1115 2506 post :create, :project_id => 1, :copy_from => 3,
Chris@1464 2507 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2508 :status_id => '1', :subject => 'Copy with attachments'}
Chris@1115 2509 end
Chris@1115 2510 end
Chris@1115 2511 end
Chris@1517 2512 copy = Issue.order('id DESC').first
Chris@1115 2513 assert_equal 0, copy.attachments.count
Chris@1115 2514 end
Chris@1115 2515
Chris@1115 2516 def test_create_as_copy_with_attachments_should_add_new_files
Chris@1115 2517 @request.session[:user_id] = 2
Chris@1115 2518 issue = Issue.find(3)
Chris@1115 2519 count = issue.attachments.count
Chris@1115 2520 assert count > 0
Chris@1115 2521 assert_difference 'Issue.count' do
Chris@1115 2522 assert_difference 'Attachment.count', count + 1 do
Chris@1464 2523 assert_difference 'Journal.count', 2 do
Chris@1115 2524 post :create, :project_id => 1, :copy_from => 3,
Chris@1464 2525 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2526 :status_id => '1', :subject => 'Copy with attachments'},
Chris@1115 2527 :copy_attachments => '1',
Chris@1464 2528 :attachments => {'1' =>
Chris@1464 2529 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
Chris@1464 2530 'description' => 'test file'}}
Chris@1115 2531 end
Chris@1115 2532 end
Chris@1115 2533 end
Chris@1517 2534 copy = Issue.order('id DESC').first
Chris@1115 2535 assert_equal count + 1, copy.attachments.count
Chris@1115 2536 end
Chris@1115 2537
Chris@1115 2538 def test_create_as_copy_should_add_relation_with_copied_issue
Chris@1115 2539 @request.session[:user_id] = 2
Chris@1115 2540 assert_difference 'Issue.count' do
Chris@1115 2541 assert_difference 'IssueRelation.count' do
Chris@1115 2542 post :create, :project_id => 1, :copy_from => 1,
Chris@1464 2543 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2544 :status_id => '1', :subject => 'Copy'}
Chris@1115 2545 end
Chris@1115 2546 end
Chris@1517 2547 copy = Issue.order('id DESC').first
Chris@1115 2548 assert_equal 1, copy.relations.size
Chris@1115 2549 end
Chris@1115 2550
Chris@1115 2551 def test_create_as_copy_should_copy_subtasks
Chris@1115 2552 @request.session[:user_id] = 2
Chris@1115 2553 issue = Issue.generate_with_descendants!
Chris@1115 2554 count = issue.descendants.count
Chris@1464 2555 assert_difference 'Issue.count', count + 1 do
Chris@1464 2556 assert_difference 'Journal.count', (count + 1) * 2 do
Chris@1115 2557 post :create, :project_id => 1, :copy_from => issue.id,
Chris@1464 2558 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2559 :status_id => '1', :subject => 'Copy with subtasks'},
Chris@1115 2560 :copy_subtasks => '1'
Chris@1115 2561 end
Chris@1115 2562 end
Chris@1517 2563 copy = Issue.where(:parent_id => nil).order('id DESC').first
Chris@1115 2564 assert_equal count, copy.descendants.count
Chris@1115 2565 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
Chris@1115 2566 end
Chris@1115 2567
Chris@1115 2568 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
Chris@1115 2569 @request.session[:user_id] = 2
Chris@1115 2570 issue = Issue.generate_with_descendants!
Chris@1115 2571 assert_difference 'Issue.count', 1 do
Chris@1464 2572 assert_difference 'Journal.count', 2 do
Chris@1115 2573 post :create, :project_id => 1, :copy_from => 3,
Chris@1464 2574 :issue => {:project_id => '1', :tracker_id => '3',
Chris@1464 2575 :status_id => '1', :subject => 'Copy with subtasks'}
Chris@1115 2576 end
Chris@1115 2577 end
Chris@1517 2578 copy = Issue.where(:parent_id => nil).order('id DESC').first
Chris@1115 2579 assert_equal 0, copy.descendants.count
Chris@1115 2580 end
Chris@1115 2581
Chris@1115 2582 def test_create_as_copy_with_failure
Chris@1115 2583 @request.session[:user_id] = 2
Chris@1115 2584 post :create, :project_id => 1, :copy_from => 1,
Chris@1115 2585 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
Chris@1115 2586
Chris@1115 2587 assert_response :success
Chris@1115 2588 assert_template 'new'
Chris@1115 2589
Chris@1115 2590 assert_not_nil assigns(:issue)
Chris@1115 2591 assert assigns(:issue).copy?
Chris@1115 2592
Chris@1464 2593 assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do
Chris@1464 2594 assert_select 'select[name=?]', 'issue[project_id]' do
Chris@1464 2595 assert_select 'option[value=1]:not([selected])', :text => 'eCookbook'
Chris@1464 2596 assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore'
Chris@1464 2597 end
Chris@1464 2598 assert_select 'input[name=copy_from][value=1]'
Chris@1464 2599 end
Chris@1115 2600 end
Chris@1115 2601
Chris@1115 2602 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
Chris@1115 2603 @request.session[:user_id] = 2
Chris@1115 2604 assert !User.find(2).member_of?(Project.find(4))
Chris@1115 2605
Chris@1115 2606 assert_difference 'Issue.count' do
Chris@1115 2607 post :create, :project_id => 1, :copy_from => 1,
Chris@1115 2608 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
Chris@1115 2609 end
Chris@1517 2610 issue = Issue.order('id DESC').first
Chris@1115 2611 assert_equal 1, issue.project_id
Chris@0 2612 end
Chris@441 2613
Chris@0 2614 def test_get_edit
Chris@0 2615 @request.session[:user_id] = 2
Chris@0 2616 get :edit, :id => 1
Chris@0 2617 assert_response :success
Chris@0 2618 assert_template 'edit'
Chris@0 2619 assert_not_nil assigns(:issue)
Chris@0 2620 assert_equal Issue.find(1), assigns(:issue)
Chris@909 2621
Chris@909 2622 # Be sure we don't display inactive IssuePriorities
Chris@909 2623 assert ! IssuePriority.find(15).active?
Chris@1464 2624 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1464 2625 assert_select 'option[value=15]', 0
Chris@1464 2626 end
Chris@909 2627 end
Chris@909 2628
Chris@909 2629 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
Chris@909 2630 @request.session[:user_id] = 2
Chris@909 2631 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
Chris@909 2632
Chris@909 2633 get :edit, :id => 1
Chris@1464 2634 assert_select 'input[name=?]', 'time_entry[hours]'
Chris@909 2635 end
Chris@909 2636
Chris@909 2637 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
Chris@909 2638 @request.session[:user_id] = 2
Chris@909 2639 Role.find_by_name('Manager').remove_permission! :log_time
Chris@909 2640
Chris@909 2641 get :edit, :id => 1
Chris@1464 2642 assert_select 'input[name=?]', 'time_entry[hours]', 0
Chris@0 2643 end
Chris@441 2644
Chris@0 2645 def test_get_edit_with_params
Chris@0 2646 @request.session[:user_id] = 2
chris@37 2647 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
Chris@1464 2648 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 }
Chris@0 2649 assert_response :success
Chris@0 2650 assert_template 'edit'
Chris@441 2651
Chris@0 2652 issue = assigns(:issue)
Chris@0 2653 assert_not_nil issue
Chris@441 2654
Chris@0 2655 assert_equal 5, issue.status_id
Chris@1464 2656 assert_select 'select[name=?]', 'issue[status_id]' do
Chris@1464 2657 assert_select 'option[value=5][selected=selected]', :text => 'Closed'
Chris@1464 2658 end
Chris@441 2659
Chris@0 2660 assert_equal 7, issue.priority_id
Chris@1464 2661 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1464 2662 assert_select 'option[value=7][selected=selected]', :text => 'Urgent'
Chris@1464 2663 end
Chris@1464 2664
Chris@1464 2665 assert_select 'input[name=?][value=2.5]', 'time_entry[hours]'
Chris@1464 2666 assert_select 'select[name=?]', 'time_entry[activity_id]' do
Chris@1464 2667 assert_select 'option[value=10][selected=selected]', :text => 'Development'
Chris@1464 2668 end
Chris@1464 2669 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]'
Chris@0 2670 end
Chris@0 2671
Chris@1115 2672 def test_get_edit_with_multi_custom_field
Chris@1115 2673 field = CustomField.find(1)
Chris@1115 2674 field.update_attribute :multiple, true
Chris@1115 2675 issue = Issue.find(1)
Chris@1115 2676 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
Chris@1115 2677 issue.save!
Chris@1115 2678
Chris@1115 2679 @request.session[:user_id] = 2
Chris@1115 2680 get :edit, :id => 1
Chris@1115 2681 assert_response :success
Chris@1115 2682 assert_template 'edit'
Chris@1115 2683
Chris@1464 2684 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
Chris@1464 2685 assert_select 'option', 3
Chris@1464 2686 assert_select 'option[value=MySQL][selected=selected]'
Chris@1464 2687 assert_select 'option[value=Oracle][selected=selected]'
Chris@1464 2688 assert_select 'option[value=PostgreSQL]:not([selected])'
Chris@1464 2689 end
Chris@1464 2690 end
Chris@1464 2691
Chris@1464 2692 def test_update_form_for_existing_issue
Chris@0 2693 @request.session[:user_id] = 2
Chris@1464 2694 xhr :put, :update_form, :project_id => 1,
Chris@0 2695 :id => 1,
Chris@441 2696 :issue => {:tracker_id => 2,
Chris@0 2697 :subject => 'This is the test_new issue',
Chris@0 2698 :description => 'This is the description',
Chris@0 2699 :priority_id => 5}
Chris@0 2700 assert_response :success
Chris@1115 2701 assert_equal 'text/javascript', response.content_type
Chris@1115 2702 assert_template 'update_form'
Chris@1517 2703 assert_template :partial => '_form'
Chris@441 2704
Chris@0 2705 issue = assigns(:issue)
Chris@0 2706 assert_kind_of Issue, issue
Chris@0 2707 assert_equal 1, issue.id
Chris@0 2708 assert_equal 1, issue.project_id
Chris@0 2709 assert_equal 2, issue.tracker_id
Chris@0 2710 assert_equal 'This is the test_new issue', issue.subject
Chris@0 2711 end
Chris@441 2712
Chris@1464 2713 def test_update_form_for_existing_issue_should_keep_issue_author
Chris@1115 2714 @request.session[:user_id] = 3
Chris@1464 2715 xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
Chris@1115 2716 assert_response :success
Chris@1115 2717 assert_equal 'text/javascript', response.content_type
Chris@1115 2718
Chris@1115 2719 issue = assigns(:issue)
Chris@1115 2720 assert_equal User.find(2), issue.author
Chris@1115 2721 assert_equal 2, issue.author_id
Chris@1115 2722 assert_not_equal User.current, issue.author
Chris@1115 2723 end
Chris@1115 2724
Chris@1464 2725 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status
Chris@0 2726 @request.session[:user_id] = 2
Chris@1115 2727 WorkflowTransition.delete_all
Chris@1115 2728 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
Chris@1115 2729 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
Chris@1115 2730 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
Chris@1115 2731
Chris@1464 2732 xhr :put, :update_form, :project_id => 1,
Chris@1115 2733 :id => 2,
Chris@1115 2734 :issue => {:tracker_id => 2,
Chris@1115 2735 :status_id => 5,
Chris@1115 2736 :subject => 'This is an issue'}
Chris@1115 2737
Chris@1115 2738 assert_equal 5, assigns(:issue).status_id
Chris@1115 2739 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
Chris@1115 2740 end
Chris@1115 2741
Chris@1464 2742 def test_update_form_for_existing_issue_with_project_change
Chris@1115 2743 @request.session[:user_id] = 2
Chris@1464 2744 xhr :put, :update_form, :project_id => 1,
Chris@1115 2745 :id => 1,
Chris@1115 2746 :issue => {:project_id => 2,
Chris@1115 2747 :tracker_id => 2,
Chris@1115 2748 :subject => 'This is the test_new issue',
Chris@1115 2749 :description => 'This is the description',
Chris@1115 2750 :priority_id => 5}
Chris@1115 2751 assert_response :success
Chris@1517 2752 assert_template :partial => '_form'
Chris@1115 2753
Chris@1115 2754 issue = assigns(:issue)
Chris@1115 2755 assert_kind_of Issue, issue
Chris@1115 2756 assert_equal 1, issue.id
Chris@1115 2757 assert_equal 2, issue.project_id
Chris@1115 2758 assert_equal 2, issue.tracker_id
Chris@1115 2759 assert_equal 'This is the test_new issue', issue.subject
Chris@0 2760 end
Chris@0 2761
Chris@1464 2762 def test_update_form_should_propose_default_status_for_existing_issue
Chris@1464 2763 @request.session[:user_id] = 2
Chris@1464 2764 WorkflowTransition.delete_all
Chris@1464 2765 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
Chris@1464 2766
Chris@1464 2767 xhr :put, :update_form, :project_id => 1, :id => 2
Chris@1464 2768 assert_response :success
Chris@1464 2769 assert_equal [2,3], assigns(:allowed_statuses).map(&:id).sort
Chris@1464 2770 end
Chris@1464 2771
Chris@0 2772 def test_put_update_without_custom_fields_param
Chris@0 2773 @request.session[:user_id] = 2
Chris@0 2774 ActionMailer::Base.deliveries.clear
Chris@441 2775
Chris@0 2776 issue = Issue.find(1)
Chris@0 2777 assert_equal '125', issue.custom_value_for(2).value
Chris@0 2778 old_subject = issue.subject
Chris@0 2779 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
Chris@441 2780
Chris@0 2781 assert_difference('Journal.count') do
Chris@0 2782 assert_difference('JournalDetail.count', 2) do
Chris@0 2783 put :update, :id => 1, :issue => {:subject => new_subject,
Chris@0 2784 :priority_id => '6',
Chris@0 2785 :category_id => '1' # no change
Chris@0 2786 }
Chris@0 2787 end
Chris@0 2788 end
Chris@0 2789 assert_redirected_to :action => 'show', :id => '1'
Chris@0 2790 issue.reload
Chris@0 2791 assert_equal new_subject, issue.subject
Chris@0 2792 # Make sure custom fields were not cleared
Chris@0 2793 assert_equal '125', issue.custom_value_for(2).value
Chris@441 2794
Chris@0 2795 mail = ActionMailer::Base.deliveries.last
Chris@1115 2796 assert_not_nil mail
Chris@0 2797 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
Chris@1115 2798 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
Chris@1115 2799 end
Chris@1115 2800
Chris@1115 2801 def test_put_update_with_project_change
Chris@1115 2802 @request.session[:user_id] = 2
Chris@1115 2803 ActionMailer::Base.deliveries.clear
Chris@1115 2804
Chris@1115 2805 assert_difference('Journal.count') do
Chris@1115 2806 assert_difference('JournalDetail.count', 3) do
Chris@1115 2807 put :update, :id => 1, :issue => {:project_id => '2',
Chris@1115 2808 :tracker_id => '1', # no change
Chris@1115 2809 :priority_id => '6',
Chris@1115 2810 :category_id => '3'
Chris@1115 2811 }
Chris@1115 2812 end
Chris@1115 2813 end
Chris@1115 2814 assert_redirected_to :action => 'show', :id => '1'
Chris@1115 2815 issue = Issue.find(1)
Chris@1115 2816 assert_equal 2, issue.project_id
Chris@1115 2817 assert_equal 1, issue.tracker_id
Chris@1115 2818 assert_equal 6, issue.priority_id
Chris@1115 2819 assert_equal 3, issue.category_id
Chris@1115 2820
Chris@1115 2821 mail = ActionMailer::Base.deliveries.last
Chris@1115 2822 assert_not_nil mail
Chris@1115 2823 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
Chris@1115 2824 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
Chris@1115 2825 end
Chris@1115 2826
Chris@1115 2827 def test_put_update_with_tracker_change
Chris@1115 2828 @request.session[:user_id] = 2
Chris@1115 2829 ActionMailer::Base.deliveries.clear
Chris@1115 2830
Chris@1115 2831 assert_difference('Journal.count') do
Chris@1115 2832 assert_difference('JournalDetail.count', 2) do
Chris@1115 2833 put :update, :id => 1, :issue => {:project_id => '1',
Chris@1115 2834 :tracker_id => '2',
Chris@1115 2835 :priority_id => '6'
Chris@1115 2836 }
Chris@1115 2837 end
Chris@1115 2838 end
Chris@1115 2839 assert_redirected_to :action => 'show', :id => '1'
Chris@1115 2840 issue = Issue.find(1)
Chris@1115 2841 assert_equal 1, issue.project_id
Chris@1115 2842 assert_equal 2, issue.tracker_id
Chris@1115 2843 assert_equal 6, issue.priority_id
Chris@1115 2844 assert_equal 1, issue.category_id
Chris@1115 2845
Chris@1115 2846 mail = ActionMailer::Base.deliveries.last
Chris@1115 2847 assert_not_nil mail
Chris@1115 2848 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
Chris@1115 2849 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
Chris@0 2850 end
Chris@441 2851
Chris@0 2852 def test_put_update_with_custom_field_change
Chris@0 2853 @request.session[:user_id] = 2
Chris@0 2854 issue = Issue.find(1)
Chris@0 2855 assert_equal '125', issue.custom_value_for(2).value
Chris@441 2856
Chris@0 2857 assert_difference('Journal.count') do
Chris@0 2858 assert_difference('JournalDetail.count', 3) do
Chris@0 2859 put :update, :id => 1, :issue => {:subject => 'Custom field change',
Chris@0 2860 :priority_id => '6',
Chris@0 2861 :category_id => '1', # no change
Chris@0 2862 :custom_field_values => { '2' => 'New custom value' }
Chris@0 2863 }
Chris@0 2864 end
Chris@0 2865 end
Chris@0 2866 assert_redirected_to :action => 'show', :id => '1'
Chris@0 2867 issue.reload
Chris@0 2868 assert_equal 'New custom value', issue.custom_value_for(2).value
Chris@441 2869
Chris@0 2870 mail = ActionMailer::Base.deliveries.last
Chris@1115 2871 assert_not_nil mail
Chris@1115 2872 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
Chris@1115 2873 end
Chris@1115 2874
Chris@1115 2875 def test_put_update_with_multi_custom_field_change
Chris@1115 2876 field = CustomField.find(1)
Chris@1115 2877 field.update_attribute :multiple, true
Chris@1115 2878 issue = Issue.find(1)
Chris@1115 2879 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
Chris@1115 2880 issue.save!
Chris@1115 2881
Chris@1115 2882 @request.session[:user_id] = 2
Chris@1115 2883 assert_difference('Journal.count') do
Chris@1115 2884 assert_difference('JournalDetail.count', 3) do
Chris@1115 2885 put :update, :id => 1,
Chris@1115 2886 :issue => {
Chris@1115 2887 :subject => 'Custom field change',
Chris@1115 2888 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
Chris@1115 2889 }
Chris@1115 2890 end
Chris@1115 2891 end
Chris@1115 2892 assert_redirected_to :action => 'show', :id => '1'
Chris@1115 2893 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
Chris@0 2894 end
Chris@441 2895
Chris@0 2896 def test_put_update_with_status_and_assignee_change
Chris@0 2897 issue = Issue.find(1)
Chris@0 2898 assert_equal 1, issue.status_id
Chris@0 2899 @request.session[:user_id] = 2
Chris@0 2900 assert_difference('TimeEntry.count', 0) do
Chris@0 2901 put :update,
Chris@0 2902 :id => 1,
Chris@1115 2903 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
Chris@0 2904 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
Chris@0 2905 end
Chris@0 2906 assert_redirected_to :action => 'show', :id => '1'
Chris@0 2907 issue.reload
Chris@0 2908 assert_equal 2, issue.status_id
Chris@1464 2909 j = Journal.order('id DESC').first
Chris@0 2910 assert_equal 'Assigned to dlopper', j.notes
Chris@0 2911 assert_equal 2, j.details.size
Chris@441 2912
Chris@0 2913 mail = ActionMailer::Base.deliveries.last
Chris@1115 2914 assert_mail_body_match "Status changed from New to Assigned", mail
Chris@0 2915 # subject should contain the new status
Chris@0 2916 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
Chris@0 2917 end
Chris@441 2918
Chris@0 2919 def test_put_update_with_note_only
Chris@0 2920 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
Chris@0 2921 # anonymous user
Chris@0 2922 put :update,
Chris@0 2923 :id => 1,
Chris@1115 2924 :issue => { :notes => notes }
Chris@0 2925 assert_redirected_to :action => 'show', :id => '1'
Chris@1464 2926 j = Journal.order('id DESC').first
Chris@0 2927 assert_equal notes, j.notes
Chris@0 2928 assert_equal 0, j.details.size
Chris@0 2929 assert_equal User.anonymous, j.user
Chris@441 2930
Chris@0 2931 mail = ActionMailer::Base.deliveries.last
Chris@1115 2932 assert_mail_body_match notes, mail
Chris@1115 2933 end
Chris@1115 2934
Chris@1115 2935 def test_put_update_with_private_note_only
Chris@1115 2936 notes = 'Private note'
Chris@1115 2937 @request.session[:user_id] = 2
Chris@1115 2938
Chris@1115 2939 assert_difference 'Journal.count' do
Chris@1115 2940 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
Chris@1115 2941 assert_redirected_to :action => 'show', :id => '1'
Chris@1115 2942 end
Chris@1115 2943
Chris@1115 2944 j = Journal.order('id DESC').first
Chris@1115 2945 assert_equal notes, j.notes
Chris@1115 2946 assert_equal true, j.private_notes
Chris@1115 2947 end
Chris@1115 2948
Chris@1115 2949 def test_put_update_with_private_note_and_changes
Chris@1115 2950 notes = 'Private note'
Chris@1115 2951 @request.session[:user_id] = 2
Chris@1115 2952
Chris@1115 2953 assert_difference 'Journal.count', 2 do
Chris@1115 2954 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
Chris@1115 2955 assert_redirected_to :action => 'show', :id => '1'
Chris@1115 2956 end
Chris@1115 2957
Chris@1115 2958 j = Journal.order('id DESC').first
Chris@1115 2959 assert_equal notes, j.notes
Chris@1115 2960 assert_equal true, j.private_notes
Chris@1115 2961 assert_equal 0, j.details.count
Chris@1115 2962
Chris@1115 2963 j = Journal.order('id DESC').offset(1).first
Chris@1115 2964 assert_nil j.notes
Chris@1115 2965 assert_equal false, j.private_notes
Chris@1115 2966 assert_equal 1, j.details.count
Chris@0 2967 end
Chris@441 2968
Chris@0 2969 def test_put_update_with_note_and_spent_time
Chris@0 2970 @request.session[:user_id] = 2
Chris@0 2971 spent_hours_before = Issue.find(1).spent_hours
Chris@0 2972 assert_difference('TimeEntry.count') do
Chris@0 2973 put :update,
Chris@0 2974 :id => 1,
Chris@1115 2975 :issue => { :notes => '2.5 hours added' },
Chris@0 2976 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
Chris@0 2977 end
Chris@0 2978 assert_redirected_to :action => 'show', :id => '1'
Chris@441 2979
Chris@0 2980 issue = Issue.find(1)
Chris@441 2981
Chris@1464 2982 j = Journal.order('id DESC').first
Chris@0 2983 assert_equal '2.5 hours added', j.notes
Chris@0 2984 assert_equal 0, j.details.size
Chris@441 2985
Chris@0 2986 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
Chris@0 2987 assert_not_nil t
Chris@0 2988 assert_equal 2.5, t.hours
Chris@0 2989 assert_equal spent_hours_before + 2.5, issue.spent_hours
Chris@0 2990 end
Chris@441 2991
Chris@1294 2992 def test_put_update_should_preserve_parent_issue_even_if_not_visible
Chris@1294 2993 parent = Issue.generate!(:project_id => 1, :is_private => true)
Chris@1294 2994 issue = Issue.generate!(:parent_issue_id => parent.id)
Chris@1294 2995 assert !parent.visible?(User.find(3))
Chris@1294 2996 @request.session[:user_id] = 3
Chris@1294 2997
Chris@1294 2998 get :edit, :id => issue.id
Chris@1294 2999 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', parent.id.to_s
Chris@1294 3000
Chris@1294 3001 put :update, :id => issue.id, :issue => {:subject => 'New subject', :parent_issue_id => parent.id.to_s}
Chris@1294 3002 assert_response 302
Chris@1294 3003 assert_equal parent, issue.parent
Chris@1294 3004 end
Chris@1294 3005
Chris@0 3006 def test_put_update_with_attachment_only
Chris@0 3007 set_tmp_attachments_directory
Chris@441 3008
Chris@0 3009 # Delete all fixtured journals, a race condition can occur causing the wrong
Chris@0 3010 # journal to get fetched in the next find.
Chris@0 3011 Journal.delete_all
Chris@0 3012
Chris@0 3013 # anonymous user
Chris@909 3014 assert_difference 'Attachment.count' do
Chris@909 3015 put :update, :id => 1,
Chris@1115 3016 :issue => {:notes => ''},
Chris@909 3017 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@909 3018 end
Chris@909 3019
Chris@0 3020 assert_redirected_to :action => 'show', :id => '1'
Chris@1464 3021 j = Issue.find(1).journals.reorder('id DESC').first
Chris@0 3022 assert j.notes.blank?
Chris@0 3023 assert_equal 1, j.details.size
Chris@0 3024 assert_equal 'testfile.txt', j.details.first.value
Chris@0 3025 assert_equal User.anonymous, j.user
Chris@441 3026
Chris@1517 3027 attachment = Attachment.order('id DESC').first
Chris@909 3028 assert_equal Issue.find(1), attachment.container
Chris@909 3029 assert_equal User.anonymous, attachment.author
Chris@909 3030 assert_equal 'testfile.txt', attachment.filename
Chris@909 3031 assert_equal 'text/plain', attachment.content_type
Chris@909 3032 assert_equal 'test file', attachment.description
Chris@909 3033 assert_equal 59, attachment.filesize
Chris@909 3034 assert File.exists?(attachment.diskfile)
Chris@909 3035 assert_equal 59, File.size(attachment.diskfile)
Chris@909 3036
Chris@0 3037 mail = ActionMailer::Base.deliveries.last
Chris@1115 3038 assert_mail_body_match 'testfile.txt', mail
Chris@1115 3039 end
Chris@1115 3040
Chris@1115 3041 def test_put_update_with_failure_should_save_attachments
Chris@1115 3042 set_tmp_attachments_directory
Chris@1115 3043 @request.session[:user_id] = 2
Chris@1115 3044
Chris@1115 3045 assert_no_difference 'Journal.count' do
Chris@1115 3046 assert_difference 'Attachment.count' do
Chris@1115 3047 put :update, :id => 1,
Chris@1115 3048 :issue => { :subject => '' },
Chris@1115 3049 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
Chris@1115 3050 assert_response :success
Chris@1115 3051 assert_template 'edit'
Chris@1115 3052 end
Chris@1115 3053 end
Chris@1115 3054
Chris@1517 3055 attachment = Attachment.order('id DESC').first
Chris@1115 3056 assert_equal 'testfile.txt', attachment.filename
Chris@1115 3057 assert File.exists?(attachment.diskfile)
Chris@1115 3058 assert_nil attachment.container
Chris@1115 3059
Chris@1464 3060 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
Chris@1464 3061 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
Chris@1115 3062 end
Chris@1115 3063
Chris@1115 3064 def test_put_update_with_failure_should_keep_saved_attachments
Chris@1115 3065 set_tmp_attachments_directory
Chris@1115 3066 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
Chris@1115 3067 @request.session[:user_id] = 2
Chris@1115 3068
Chris@1115 3069 assert_no_difference 'Journal.count' do
Chris@1115 3070 assert_no_difference 'Attachment.count' do
Chris@1115 3071 put :update, :id => 1,
Chris@1115 3072 :issue => { :subject => '' },
Chris@1115 3073 :attachments => {'p0' => {'token' => attachment.token}}
Chris@1115 3074 assert_response :success
Chris@1115 3075 assert_template 'edit'
Chris@1115 3076 end
Chris@1115 3077 end
Chris@1115 3078
Chris@1464 3079 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
Chris@1464 3080 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt'
Chris@1115 3081 end
Chris@1115 3082
Chris@1115 3083 def test_put_update_should_attach_saved_attachments
Chris@1115 3084 set_tmp_attachments_directory
Chris@1115 3085 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
Chris@1115 3086 @request.session[:user_id] = 2
Chris@1115 3087
Chris@1115 3088 assert_difference 'Journal.count' do
Chris@1115 3089 assert_difference 'JournalDetail.count' do
Chris@1115 3090 assert_no_difference 'Attachment.count' do
Chris@1115 3091 put :update, :id => 1,
Chris@1115 3092 :issue => {:notes => 'Attachment added'},
Chris@1115 3093 :attachments => {'p0' => {'token' => attachment.token}}
Chris@1115 3094 assert_redirected_to '/issues/1'
Chris@1115 3095 end
Chris@1115 3096 end
Chris@1115 3097 end
Chris@1115 3098
Chris@1115 3099 attachment.reload
Chris@1115 3100 assert_equal Issue.find(1), attachment.container
Chris@1115 3101
Chris@1517 3102 journal = Journal.order('id DESC').first
Chris@1115 3103 assert_equal 1, journal.details.size
Chris@1115 3104 assert_equal 'testfile.txt', journal.details.first.value
Chris@0 3105 end
Chris@0 3106
Chris@0 3107 def test_put_update_with_attachment_that_fails_to_save
Chris@0 3108 set_tmp_attachments_directory
Chris@441 3109
Chris@0 3110 # Delete all fixtured journals, a race condition can occur causing the wrong
Chris@0 3111 # journal to get fetched in the next find.
Chris@0 3112 Journal.delete_all
Chris@0 3113
Chris@0 3114 # Mock out the unsaved attachment
Chris@0 3115 Attachment.any_instance.stubs(:create).returns(Attachment.new)
Chris@441 3116
Chris@0 3117 # anonymous user
Chris@0 3118 put :update,
Chris@0 3119 :id => 1,
Chris@1115 3120 :issue => {:notes => ''},
Chris@0 3121 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
Chris@0 3122 assert_redirected_to :action => 'show', :id => '1'
Chris@0 3123 assert_equal '1 file(s) could not be saved.', flash[:warning]
Chris@1115 3124 end
Chris@0 3125
Chris@0 3126 def test_put_update_with_no_change
Chris@0 3127 issue = Issue.find(1)
Chris@0 3128 issue.journals.clear
Chris@0 3129 ActionMailer::Base.deliveries.clear
Chris@441 3130
Chris@0 3131 put :update,
Chris@0 3132 :id => 1,
Chris@1115 3133 :issue => {:notes => ''}
Chris@0 3134 assert_redirected_to :action => 'show', :id => '1'
Chris@441 3135
Chris@0 3136 issue.reload
Chris@0 3137 assert issue.journals.empty?
Chris@0 3138 # No email should be sent
Chris@0 3139 assert ActionMailer::Base.deliveries.empty?
Chris@0 3140 end
Chris@0 3141
Chris@0 3142 def test_put_update_should_send_a_notification
Chris@0 3143 @request.session[:user_id] = 2
Chris@0 3144 ActionMailer::Base.deliveries.clear
Chris@0 3145 issue = Issue.find(1)
Chris@0 3146 old_subject = issue.subject
Chris@0 3147 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
Chris@441 3148
Chris@0 3149 put :update, :id => 1, :issue => {:subject => new_subject,
Chris@0 3150 :priority_id => '6',
Chris@0 3151 :category_id => '1' # no change
Chris@0 3152 }
Chris@0 3153 assert_equal 1, ActionMailer::Base.deliveries.size
Chris@0 3154 end
Chris@441 3155
Chris@441 3156 def test_put_update_with_invalid_spent_time_hours_only
Chris@0 3157 @request.session[:user_id] = 2
Chris@0 3158 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
Chris@441 3159
Chris@0 3160 assert_no_difference('Journal.count') do
Chris@0 3161 put :update,
Chris@0 3162 :id => 1,
Chris@1115 3163 :issue => {:notes => notes},
Chris@0 3164 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
Chris@0 3165 end
Chris@0 3166 assert_response :success
Chris@0 3167 assert_template 'edit'
Chris@441 3168
Chris@1517 3169 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
Chris@1464 3170 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
Chris@1464 3171 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
Chris@0 3172 end
Chris@441 3173
Chris@441 3174 def test_put_update_with_invalid_spent_time_comments_only
Chris@441 3175 @request.session[:user_id] = 2
Chris@441 3176 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
Chris@441 3177
Chris@441 3178 assert_no_difference('Journal.count') do
Chris@441 3179 put :update,
Chris@441 3180 :id => 1,
Chris@1115 3181 :issue => {:notes => notes},
Chris@441 3182 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
Chris@441 3183 end
Chris@441 3184 assert_response :success
Chris@441 3185 assert_template 'edit'
Chris@441 3186
Chris@1517 3187 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
Chris@1517 3188 assert_error_tag :descendant => {:content => /Hours #{ESCAPED_CANT} be blank/}
Chris@1464 3189 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
Chris@1464 3190 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
Chris@441 3191 end
Chris@441 3192
Chris@0 3193 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
Chris@0 3194 issue = Issue.find(2)
Chris@0 3195 @request.session[:user_id] = 2
Chris@0 3196
Chris@0 3197 put :update,
Chris@0 3198 :id => issue.id,
Chris@0 3199 :issue => {
Chris@0 3200 :fixed_version_id => 4
Chris@0 3201 }
Chris@0 3202
Chris@0 3203 assert_response :redirect
Chris@0 3204 issue.reload
Chris@0 3205 assert_equal 4, issue.fixed_version_id
Chris@0 3206 assert_not_equal issue.project_id, issue.fixed_version.project_id
Chris@0 3207 end
Chris@0 3208
Chris@0 3209 def test_put_update_should_redirect_back_using_the_back_url_parameter
Chris@0 3210 issue = Issue.find(2)
Chris@0 3211 @request.session[:user_id] = 2
Chris@0 3212
Chris@0 3213 put :update,
Chris@0 3214 :id => issue.id,
Chris@0 3215 :issue => {
Chris@0 3216 :fixed_version_id => 4
Chris@0 3217 },
Chris@0 3218 :back_url => '/issues'
Chris@0 3219
Chris@0 3220 assert_response :redirect
Chris@0 3221 assert_redirected_to '/issues'
Chris@0 3222 end
Chris@441 3223
Chris@0 3224 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
Chris@0 3225 issue = Issue.find(2)
Chris@0 3226 @request.session[:user_id] = 2
Chris@0 3227
Chris@0 3228 put :update,
Chris@0 3229 :id => issue.id,
Chris@0 3230 :issue => {
Chris@0 3231 :fixed_version_id => 4
Chris@0 3232 },
Chris@0 3233 :back_url => 'http://google.com'
Chris@0 3234
Chris@0 3235 assert_response :redirect
Chris@0 3236 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
Chris@0 3237 end
Chris@441 3238
Chris@0 3239 def test_get_bulk_edit
Chris@0 3240 @request.session[:user_id] = 2
Chris@0 3241 get :bulk_edit, :ids => [1, 2]
Chris@0 3242 assert_response :success
Chris@0 3243 assert_template 'bulk_edit'
Chris@441 3244
Chris@1464 3245 assert_select 'ul#bulk-selection' do
Chris@1464 3246 assert_select 'li', 2
Chris@1464 3247 assert_select 'li a', :text => 'Bug #1'
Chris@1464 3248 end
Chris@1464 3249
Chris@1464 3250 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do
Chris@1464 3251 assert_select 'input[name=?]', 'ids[]', 2
Chris@1464 3252 assert_select 'input[name=?][value=1][type=hidden]', 'ids[]'
Chris@1464 3253
Chris@1464 3254 assert_select 'select[name=?]', 'issue[project_id]'
Chris@1464 3255 assert_select 'input[name=?]', 'issue[parent_issue_id]'
Chris@1464 3256
Chris@1464 3257 # Project specific custom field, date type
Chris@1464 3258 field = CustomField.find(9)
Chris@1464 3259 assert !field.is_for_all?
Chris@1464 3260 assert_equal 'date', field.field_format
Chris@1464 3261 assert_select 'input[name=?]', 'issue[custom_field_values][9]'
Chris@1464 3262
Chris@1464 3263 # System wide custom field
Chris@1464 3264 assert CustomField.find(1).is_for_all?
Chris@1464 3265 assert_select 'select[name=?]', 'issue[custom_field_values][1]'
Chris@1464 3266
Chris@1464 3267 # Be sure we don't display inactive IssuePriorities
Chris@1464 3268 assert ! IssuePriority.find(15).active?
Chris@1464 3269 assert_select 'select[name=?]', 'issue[priority_id]' do
Chris@1464 3270 assert_select 'option[value=15]', 0
Chris@1464 3271 end
Chris@1464 3272 end
Chris@0 3273 end
Chris@0 3274
chris@37 3275 def test_get_bulk_edit_on_different_projects
chris@37 3276 @request.session[:user_id] = 2
chris@37 3277 get :bulk_edit, :ids => [1, 2, 6]
chris@37 3278 assert_response :success
chris@37 3279 assert_template 'bulk_edit'
Chris@441 3280
Chris@441 3281 # Can not set issues from different projects as children of an issue
Chris@1464 3282 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0
Chris@441 3283
chris@37 3284 # Project specific custom field, date type
chris@37 3285 field = CustomField.find(9)
chris@37 3286 assert !field.is_for_all?
chris@37 3287 assert !field.project_ids.include?(Issue.find(6).project_id)
Chris@1464 3288 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0
chris@37 3289 end
chris@37 3290
Chris@441 3291 def test_get_bulk_edit_with_user_custom_field
Chris@441 3292 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
Chris@441 3293
Chris@441 3294 @request.session[:user_id] = 2
Chris@441 3295 get :bulk_edit, :ids => [1, 2]
Chris@441 3296 assert_response :success
Chris@441 3297 assert_template 'bulk_edit'
Chris@441 3298
Chris@1464 3299 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
Chris@1464 3300 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options
Chris@1464 3301 end
Chris@441 3302 end
Chris@441 3303
Chris@441 3304 def test_get_bulk_edit_with_version_custom_field
Chris@441 3305 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
Chris@441 3306
Chris@441 3307 @request.session[:user_id] = 2
Chris@441 3308 get :bulk_edit, :ids => [1, 2]
Chris@441 3309 assert_response :success
Chris@441 3310 assert_template 'bulk_edit'
Chris@441 3311
Chris@1464 3312 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do
Chris@1464 3313 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options
Chris@1464 3314 end
Chris@441 3315 end
Chris@441 3316
Chris@1115 3317 def test_get_bulk_edit_with_multi_custom_field
Chris@1115 3318 field = CustomField.find(1)
Chris@1115 3319 field.update_attribute :multiple, true
Chris@1115 3320
Chris@1115 3321 @request.session[:user_id] = 2
Chris@1115 3322 get :bulk_edit, :ids => [1, 2]
Chris@1115 3323 assert_response :success
Chris@1115 3324 assert_template 'bulk_edit'
Chris@1115 3325
Chris@1464 3326 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do
Chris@1464 3327 assert_select 'option', field.possible_values.size + 1 # "none" options
Chris@1464 3328 end
Chris@1464 3329 end
Chris@1464 3330
Chris@1464 3331 def test_bulk_edit_should_propose_to_clear_text_custom_fields
Chris@1464 3332 @request.session[:user_id] = 2
Chris@1464 3333 get :bulk_edit, :ids => [1, 3]
Chris@1464 3334 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', '__none__'
Chris@1115 3335 end
Chris@1115 3336
Chris@1115 3337 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
Chris@1115 3338 WorkflowTransition.delete_all
Chris@1464 3339 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
Chris@1464 3340 :old_status_id => 1, :new_status_id => 1)
Chris@1464 3341 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
Chris@1464 3342 :old_status_id => 1, :new_status_id => 3)
Chris@1464 3343 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1,
Chris@1464 3344 :old_status_id => 1, :new_status_id => 4)
Chris@1464 3345 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
Chris@1464 3346 :old_status_id => 2, :new_status_id => 1)
Chris@1464 3347 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
Chris@1464 3348 :old_status_id => 2, :new_status_id => 3)
Chris@1464 3349 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2,
Chris@1464 3350 :old_status_id => 2, :new_status_id => 5)
Chris@1115 3351 @request.session[:user_id] = 2
Chris@1115 3352 get :bulk_edit, :ids => [1, 2]
Chris@1115 3353
Chris@1115 3354 assert_response :success
Chris@1115 3355 statuses = assigns(:available_statuses)
Chris@1115 3356 assert_not_nil statuses
Chris@1115 3357 assert_equal [1, 3], statuses.map(&:id).sort
Chris@1115 3358
Chris@1464 3359 assert_select 'select[name=?]', 'issue[status_id]' do
Chris@1464 3360 assert_select 'option', 3 # 2 statuses + "no change" option
Chris@1464 3361 end
Chris@1115 3362 end
Chris@1115 3363
Chris@1115 3364 def test_bulk_edit_should_propose_target_project_open_shared_versions
Chris@1115 3365 @request.session[:user_id] = 2
Chris@1115 3366 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
Chris@1115 3367 assert_response :success
Chris@1115 3368 assert_template 'bulk_edit'
Chris@1115 3369 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
Chris@1464 3370
Chris@1464 3371 assert_select 'select[name=?]', 'issue[fixed_version_id]' do
Chris@1464 3372 assert_select 'option', :text => '2.0'
Chris@1464 3373 end
Chris@1115 3374 end
Chris@1115 3375
Chris@1115 3376 def test_bulk_edit_should_propose_target_project_categories
Chris@1115 3377 @request.session[:user_id] = 2
Chris@1115 3378 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
Chris@1115 3379 assert_response :success
Chris@1115 3380 assert_template 'bulk_edit'
Chris@1115 3381 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
Chris@1464 3382
Chris@1464 3383 assert_select 'select[name=?]', 'issue[category_id]' do
Chris@1464 3384 assert_select 'option', :text => 'Recipes'
Chris@1464 3385 end
Chris@1115 3386 end
Chris@1115 3387
Chris@14 3388 def test_bulk_update
Chris@0 3389 @request.session[:user_id] = 2
Chris@0 3390 # update issues priority
Chris@14 3391 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
Chris@0 3392 :issue => {:priority_id => 7,
Chris@0 3393 :assigned_to_id => '',
Chris@0 3394 :custom_field_values => {'2' => ''}}
Chris@441 3395
Chris@0 3396 assert_response 302
Chris@0 3397 # check that the issues were updated
Chris@1517 3398 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
Chris@441 3399
Chris@0 3400 issue = Issue.find(1)
Chris@1464 3401 journal = issue.journals.reorder('created_on DESC').first
Chris@0 3402 assert_equal '125', issue.custom_value_for(2).value
Chris@0 3403 assert_equal 'Bulk editing', journal.notes
Chris@0 3404 assert_equal 1, journal.details.size
Chris@0 3405 end
Chris@0 3406
Chris@909 3407 def test_bulk_update_with_group_assignee
Chris@909 3408 group = Group.find(11)
Chris@909 3409 project = Project.find(1)
Chris@929 3410 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
Chris@909 3411
Chris@909 3412 @request.session[:user_id] = 2
Chris@909 3413 # update issues assignee
Chris@909 3414 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
Chris@909 3415 :issue => {:priority_id => '',
Chris@909 3416 :assigned_to_id => group.id,
Chris@909 3417 :custom_field_values => {'2' => ''}}
Chris@909 3418
Chris@909 3419 assert_response 302
Chris@1517 3420 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
Chris@909 3421 end
Chris@909 3422
chris@37 3423 def test_bulk_update_on_different_projects
chris@37 3424 @request.session[:user_id] = 2
chris@37 3425 # update issues priority
chris@37 3426 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
chris@37 3427 :issue => {:priority_id => 7,
chris@37 3428 :assigned_to_id => '',
chris@37 3429 :custom_field_values => {'2' => ''}}
Chris@441 3430
chris@37 3431 assert_response 302
chris@37 3432 # check that the issues were updated
chris@37 3433 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
Chris@441 3434
chris@37 3435 issue = Issue.find(1)
Chris@1464 3436 journal = issue.journals.reorder('created_on DESC').first
chris@37 3437 assert_equal '125', issue.custom_value_for(2).value
chris@37 3438 assert_equal 'Bulk editing', journal.notes
chris@37 3439 assert_equal 1, journal.details.size
chris@37 3440 end
chris@37 3441
chris@37 3442 def test_bulk_update_on_different_projects_without_rights
chris@37 3443 @request.session[:user_id] = 3
chris@37 3444 user = User.find(3)
chris@37 3445 action = { :controller => "issues", :action => "bulk_update" }
chris@37 3446 assert user.allowed_to?(action, Issue.find(1).project)
chris@37 3447 assert ! user.allowed_to?(action, Issue.find(6).project)
chris@37 3448 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
chris@37 3449 :issue => {:priority_id => 7,
chris@37 3450 :assigned_to_id => '',
chris@37 3451 :custom_field_values => {'2' => ''}}
chris@37 3452 assert_response 403
chris@37 3453 assert_not_equal "Bulk should fail", Journal.last.notes
chris@37 3454 end
Chris@441 3455
Chris@14 3456 def test_bullk_update_should_send_a_notification
Chris@0 3457 @request.session[:user_id] = 2
Chris@0 3458 ActionMailer::Base.deliveries.clear
Chris@14 3459 post(:bulk_update,
Chris@0 3460 {
Chris@0 3461 :ids => [1, 2],
Chris@0 3462 :notes => 'Bulk editing',
Chris@0 3463 :issue => {
Chris@0 3464 :priority_id => 7,
Chris@0 3465 :assigned_to_id => '',
Chris@0 3466 :custom_field_values => {'2' => ''}
Chris@0 3467 }
Chris@0 3468 })
Chris@0 3469
Chris@0 3470 assert_response 302
Chris@0 3471 assert_equal 2, ActionMailer::Base.deliveries.size
Chris@0 3472 end
Chris@0 3473
Chris@1115 3474 def test_bulk_update_project
Chris@1115 3475 @request.session[:user_id] = 2
Chris@1115 3476 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
Chris@1115 3477 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@1115 3478 # Issues moved to project 2
Chris@1115 3479 assert_equal 2, Issue.find(1).project_id
Chris@1115 3480 assert_equal 2, Issue.find(2).project_id
Chris@1115 3481 # No tracker change
Chris@1115 3482 assert_equal 1, Issue.find(1).tracker_id
Chris@1115 3483 assert_equal 2, Issue.find(2).tracker_id
Chris@1115 3484 end
Chris@1115 3485
Chris@1115 3486 def test_bulk_update_project_on_single_issue_should_follow_when_needed
Chris@1115 3487 @request.session[:user_id] = 2
Chris@1115 3488 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
Chris@1115 3489 assert_redirected_to '/issues/1'
Chris@1115 3490 end
Chris@1115 3491
Chris@1115 3492 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
Chris@1115 3493 @request.session[:user_id] = 2
Chris@1115 3494 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
Chris@1115 3495 assert_redirected_to '/projects/onlinestore/issues'
Chris@1115 3496 end
Chris@1115 3497
Chris@1115 3498 def test_bulk_update_tracker
Chris@1115 3499 @request.session[:user_id] = 2
Chris@1115 3500 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
Chris@1115 3501 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@1115 3502 assert_equal 2, Issue.find(1).tracker_id
Chris@1115 3503 assert_equal 2, Issue.find(2).tracker_id
Chris@1115 3504 end
Chris@1115 3505
Chris@14 3506 def test_bulk_update_status
Chris@0 3507 @request.session[:user_id] = 2
Chris@0 3508 # update issues priority
Chris@14 3509 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
Chris@0 3510 :issue => {:priority_id => '',
Chris@0 3511 :assigned_to_id => '',
Chris@0 3512 :status_id => '5'}
Chris@441 3513
Chris@0 3514 assert_response 302
Chris@0 3515 issue = Issue.find(1)
Chris@0 3516 assert issue.closed?
Chris@0 3517 end
Chris@0 3518
Chris@1115 3519 def test_bulk_update_priority
Chris@1115 3520 @request.session[:user_id] = 2
Chris@1115 3521 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
Chris@1115 3522
Chris@1115 3523 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@1115 3524 assert_equal 6, Issue.find(1).priority_id
Chris@1115 3525 assert_equal 6, Issue.find(2).priority_id
Chris@1115 3526 end
Chris@1115 3527
Chris@1115 3528 def test_bulk_update_with_notes
Chris@1115 3529 @request.session[:user_id] = 2
Chris@1115 3530 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
Chris@1115 3531
Chris@1115 3532 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
Chris@1115 3533 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
Chris@1115 3534 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
Chris@1115 3535 end
Chris@1115 3536
Chris@441 3537 def test_bulk_update_parent_id
Chris@1464 3538 IssueRelation.delete_all
Chris@441 3539 @request.session[:user_id] = 2
Chris@441 3540 post :bulk_update, :ids => [1, 3],
Chris@441 3541 :notes => 'Bulk editing parent',
Chris@1464 3542 :issue => {:priority_id => '', :assigned_to_id => '',
Chris@1464 3543 :status_id => '', :parent_issue_id => '2'}
Chris@441 3544 assert_response 302
Chris@441 3545 parent = Issue.find(2)
Chris@441 3546 assert_equal parent.id, Issue.find(1).parent_id
Chris@441 3547 assert_equal parent.id, Issue.find(3).parent_id
Chris@441 3548 assert_equal [1, 3], parent.children.collect(&:id).sort
Chris@441 3549 end
Chris@441 3550
Chris@14 3551 def test_bulk_update_custom_field
Chris@0 3552 @request.session[:user_id] = 2
Chris@0 3553 # update issues priority
Chris@14 3554 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
Chris@0 3555 :issue => {:priority_id => '',
Chris@0 3556 :assigned_to_id => '',
Chris@0 3557 :custom_field_values => {'2' => '777'}}
Chris@441 3558
Chris@0 3559 assert_response 302
Chris@441 3560
Chris@0 3561 issue = Issue.find(1)
Chris@1464 3562 journal = issue.journals.reorder('created_on DESC').first
Chris@0 3563 assert_equal '777', issue.custom_value_for(2).value
Chris@0 3564 assert_equal 1, journal.details.size
Chris@0 3565 assert_equal '125', journal.details.first.old_value
Chris@0 3566 assert_equal '777', journal.details.first.value
Chris@0 3567 end
Chris@0 3568
Chris@1115 3569 def test_bulk_update_custom_field_to_blank
Chris@1115 3570 @request.session[:user_id] = 2
Chris@1115 3571 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
Chris@1115 3572 :issue => {:priority_id => '',
Chris@1115 3573 :assigned_to_id => '',
Chris@1115 3574 :custom_field_values => {'1' => '__none__'}}
Chris@1115 3575 assert_response 302
Chris@1115 3576 assert_equal '', Issue.find(1).custom_field_value(1)
Chris@1115 3577 assert_equal '', Issue.find(3).custom_field_value(1)
Chris@1115 3578 end
Chris@1115 3579
Chris@1115 3580 def test_bulk_update_multi_custom_field
Chris@1115 3581 field = CustomField.find(1)
Chris@1115 3582 field.update_attribute :multiple, true
Chris@1115 3583
Chris@1115 3584 @request.session[:user_id] = 2
Chris@1115 3585 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
Chris@1115 3586 :issue => {:priority_id => '',
Chris@1115 3587 :assigned_to_id => '',
Chris@1115 3588 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
Chris@1115 3589
Chris@1115 3590 assert_response 302
Chris@1115 3591
Chris@1115 3592 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
Chris@1115 3593 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
Chris@1115 3594 # the custom field is not associated with the issue tracker
Chris@1115 3595 assert_nil Issue.find(2).custom_field_value(1)
Chris@1115 3596 end
Chris@1115 3597
Chris@1115 3598 def test_bulk_update_multi_custom_field_to_blank
Chris@1115 3599 field = CustomField.find(1)
Chris@1115 3600 field.update_attribute :multiple, true
Chris@1115 3601
Chris@1115 3602 @request.session[:user_id] = 2
Chris@1115 3603 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
Chris@1115 3604 :issue => {:priority_id => '',
Chris@1115 3605 :assigned_to_id => '',
Chris@1115 3606 :custom_field_values => {'1' => ['__none__']}}
Chris@1115 3607 assert_response 302
Chris@1115 3608 assert_equal [''], Issue.find(1).custom_field_value(1)
Chris@1115 3609 assert_equal [''], Issue.find(3).custom_field_value(1)
Chris@1115 3610 end
Chris@1115 3611
Chris@14 3612 def test_bulk_update_unassign
Chris@0 3613 assert_not_nil Issue.find(2).assigned_to
Chris@0 3614 @request.session[:user_id] = 2
Chris@0 3615 # unassign issues
Chris@14 3616 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
Chris@0 3617 assert_response 302
Chris@0 3618 # check that the issues were updated
Chris@0 3619 assert_nil Issue.find(2).assigned_to
Chris@0 3620 end
Chris@441 3621
Chris@14 3622 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
Chris@0 3623 @request.session[:user_id] = 2
Chris@0 3624
Chris@14 3625 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
Chris@0 3626
Chris@0 3627 assert_response :redirect
Chris@0 3628 issues = Issue.find([1,2])
Chris@0 3629 issues.each do |issue|
Chris@0 3630 assert_equal 4, issue.fixed_version_id
Chris@0 3631 assert_not_equal issue.project_id, issue.fixed_version.project_id
Chris@0 3632 end
Chris@0 3633 end
Chris@0 3634
Chris@14 3635 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
Chris@0 3636 @request.session[:user_id] = 2
Chris@14 3637 post :bulk_update, :ids => [1,2], :back_url => '/issues'
Chris@0 3638
Chris@0 3639 assert_response :redirect
Chris@0 3640 assert_redirected_to '/issues'
Chris@0 3641 end
Chris@0 3642
Chris@14 3643 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
Chris@0 3644 @request.session[:user_id] = 2
Chris@14 3645 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
Chris@0 3646
Chris@0 3647 assert_response :redirect
Chris@0 3648 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
Chris@0 3649 end
Chris@441 3650
Chris@1464 3651 def test_bulk_update_with_all_failures_should_show_errors
Chris@1115 3652 @request.session[:user_id] = 2
Chris@1464 3653 post :bulk_update, :ids => [1, 2], :issue => {:start_date => 'foo'}
Chris@1464 3654
Chris@1464 3655 assert_response :success
Chris@1464 3656 assert_template 'bulk_edit'
Chris@1464 3657 assert_select '#errorExplanation span', :text => 'Failed to save 2 issue(s) on 2 selected: #1, #2.'
Chris@1464 3658 assert_select '#errorExplanation ul li', :text => 'Start date is not a valid date: #1, #2'
Chris@1464 3659
Chris@1464 3660 assert_equal [1, 2], assigns[:issues].map(&:id)
Chris@1464 3661 end
Chris@1464 3662
Chris@1464 3663 def test_bulk_update_with_some_failures_should_show_errors
Chris@1464 3664 issue1 = Issue.generate!(:start_date => '2013-05-12')
Chris@1464 3665 issue2 = Issue.generate!(:start_date => '2013-05-15')
Chris@1464 3666 issue3 = Issue.generate!
Chris@1464 3667 @request.session[:user_id] = 2
Chris@1464 3668 post :bulk_update, :ids => [issue1.id, issue2.id, issue3.id],
Chris@1464 3669 :issue => {:due_date => '2013-05-01'}
Chris@1464 3670 assert_response :success
Chris@1464 3671 assert_template 'bulk_edit'
Chris@1464 3672 assert_select '#errorExplanation span',
Chris@1464 3673 :text => "Failed to save 2 issue(s) on 3 selected: ##{issue1.id}, ##{issue2.id}."
Chris@1464 3674 assert_select '#errorExplanation ul li',
Chris@1464 3675 :text => "Due date must be greater than start date: ##{issue1.id}, ##{issue2.id}"
Chris@1464 3676 assert_equal [issue1.id, issue2.id], assigns[:issues].map(&:id)
Chris@1464 3677 end
Chris@1464 3678
Chris@1464 3679 def test_bulk_update_with_failure_should_preserved_form_values
Chris@1464 3680 @request.session[:user_id] = 2
Chris@1464 3681 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2', :start_date => 'foo'}
Chris@1464 3682
Chris@1464 3683 assert_response :success
Chris@1464 3684 assert_template 'bulk_edit'
Chris@1464 3685 assert_select 'select[name=?]', 'issue[tracker_id]' do
Chris@1464 3686 assert_select 'option[value=2][selected=selected]'
Chris@1464 3687 end
Chris@1464 3688 assert_select 'input[name=?][value=?]', 'issue[start_date]', 'foo'
Chris@1115 3689 end
Chris@1115 3690
Chris@1115 3691 def test_get_bulk_copy
Chris@1115 3692 @request.session[:user_id] = 2
Chris@1115 3693 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
Chris@1115 3694 assert_response :success
Chris@1115 3695 assert_template 'bulk_edit'
Chris@1115 3696
Chris@1115 3697 issues = assigns(:issues)
Chris@1115 3698 assert_not_nil issues
Chris@1115 3699 assert_equal [1, 2, 3], issues.map(&:id).sort
Chris@1115 3700
Chris@1115 3701 assert_select 'input[name=copy_attachments]'
Chris@1115 3702 end
Chris@1115 3703
Chris@1115 3704 def test_bulk_copy_to_another_project
Chris@1115 3705 @request.session[:user_id] = 2
Chris@1115 3706 assert_difference 'Issue.count', 2 do
Chris@1115 3707 assert_no_difference 'Project.find(1).issues.count' do
Chris@1115 3708 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
Chris@1115 3709 end
Chris@1115 3710 end
Chris@1115 3711 assert_redirected_to '/projects/ecookbook/issues'
Chris@1115 3712
Chris@1517 3713 copies = Issue.order('id DESC').limit(issues.size)
Chris@1115 3714 copies.each do |copy|
Chris@1115 3715 assert_equal 2, copy.project_id
Chris@1115 3716 end
Chris@1115 3717 end
Chris@1115 3718
Chris@1115 3719 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
Chris@1115 3720 @request.session[:user_id] = 2
Chris@1115 3721 issues = [
Chris@1464 3722 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1,
Chris@1464 3723 :priority_id => 2, :subject => 'issue 1', :author_id => 1,
Chris@1464 3724 :assigned_to_id => nil),
Chris@1464 3725 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2,
Chris@1464 3726 :priority_id => 1, :subject => 'issue 2', :author_id => 2,
Chris@1464 3727 :assigned_to_id => 3)
Chris@1115 3728 ]
Chris@1115 3729 assert_difference 'Issue.count', issues.size do
Chris@1115 3730 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
Chris@1115 3731 :issue => {
Chris@1115 3732 :project_id => '', :tracker_id => '', :assigned_to_id => '',
Chris@1115 3733 :status_id => '', :start_date => '', :due_date => ''
Chris@1115 3734 }
Chris@1115 3735 end
Chris@1115 3736
Chris@1517 3737 copies = Issue.order('id DESC').limit(issues.size)
Chris@1115 3738 issues.each do |orig|
Chris@1115 3739 copy = copies.detect {|c| c.subject == orig.subject}
Chris@1115 3740 assert_not_nil copy
Chris@1115 3741 assert_equal orig.project_id, copy.project_id
Chris@1115 3742 assert_equal orig.tracker_id, copy.tracker_id
Chris@1115 3743 assert_equal orig.status_id, copy.status_id
Chris@1115 3744 assert_equal orig.assigned_to_id, copy.assigned_to_id
Chris@1115 3745 assert_equal orig.priority_id, copy.priority_id
Chris@1115 3746 end
Chris@1115 3747 end
Chris@1115 3748
Chris@1115 3749 def test_bulk_copy_should_allow_changing_the_issue_attributes
Chris@1115 3750 # Fixes random test failure with Mysql
Chris@1464 3751 # where Issue.where(:project_id => 2).limit(2).order('id desc')
Chris@1115 3752 # doesn't return the expected results
Chris@1115 3753 Issue.delete_all("project_id=2")
Chris@1115 3754
Chris@1115 3755 @request.session[:user_id] = 2
Chris@1115 3756 assert_difference 'Issue.count', 2 do
Chris@1115 3757 assert_no_difference 'Project.find(1).issues.count' do
Chris@1115 3758 post :bulk_update, :ids => [1, 2], :copy => '1',
Chris@1115 3759 :issue => {
Chris@1115 3760 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
Chris@1115 3761 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
Chris@1115 3762 }
Chris@1115 3763 end
Chris@1115 3764 end
Chris@1115 3765
Chris@1464 3766 copied_issues = Issue.where(:project_id => 2).limit(2).order('id desc').to_a
Chris@1115 3767 assert_equal 2, copied_issues.size
Chris@1115 3768 copied_issues.each do |issue|
Chris@1115 3769 assert_equal 2, issue.project_id, "Project is incorrect"
Chris@1115 3770 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
Chris@1115 3771 assert_equal 1, issue.status_id, "Status is incorrect"
Chris@1115 3772 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
Chris@1115 3773 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
Chris@1115 3774 end
Chris@1115 3775 end
Chris@1115 3776
Chris@1115 3777 def test_bulk_copy_should_allow_adding_a_note
Chris@1115 3778 @request.session[:user_id] = 2
Chris@1115 3779 assert_difference 'Issue.count', 1 do
Chris@1115 3780 post :bulk_update, :ids => [1], :copy => '1',
Chris@1115 3781 :notes => 'Copying one issue',
Chris@1115 3782 :issue => {
Chris@1115 3783 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
Chris@1115 3784 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
Chris@1115 3785 }
Chris@1115 3786 end
Chris@1517 3787 issue = Issue.order('id DESC').first
Chris@1115 3788 assert_equal 1, issue.journals.size
Chris@1115 3789 journal = issue.journals.first
Chris@1464 3790 assert_equal 1, journal.details.size
Chris@1115 3791 assert_equal 'Copying one issue', journal.notes
Chris@1115 3792 end
Chris@1115 3793
Chris@1115 3794 def test_bulk_copy_should_allow_not_copying_the_attachments
Chris@1115 3795 attachment_count = Issue.find(3).attachments.size
Chris@1115 3796 assert attachment_count > 0
Chris@1115 3797 @request.session[:user_id] = 2
Chris@1115 3798
Chris@1115 3799 assert_difference 'Issue.count', 1 do
Chris@1115 3800 assert_no_difference 'Attachment.count' do
Chris@1115 3801 post :bulk_update, :ids => [3], :copy => '1',
Chris@1115 3802 :issue => {
Chris@1115 3803 :project_id => ''
Chris@1115 3804 }
Chris@1115 3805 end
Chris@1115 3806 end
Chris@1115 3807 end
Chris@1115 3808
Chris@1115 3809 def test_bulk_copy_should_allow_copying_the_attachments
Chris@1115 3810 attachment_count = Issue.find(3).attachments.size
Chris@1115 3811 assert attachment_count > 0
Chris@1115 3812 @request.session[:user_id] = 2
Chris@1115 3813
Chris@1115 3814 assert_difference 'Issue.count', 1 do
Chris@1115 3815 assert_difference 'Attachment.count', attachment_count do
Chris@1115 3816 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
Chris@1115 3817 :issue => {
Chris@1115 3818 :project_id => ''
Chris@1115 3819 }
Chris@1115 3820 end
Chris@1115 3821 end
Chris@1115 3822 end
Chris@1115 3823
Chris@1115 3824 def test_bulk_copy_should_add_relations_with_copied_issues
Chris@1115 3825 @request.session[:user_id] = 2
Chris@1115 3826
Chris@1115 3827 assert_difference 'Issue.count', 2 do
Chris@1115 3828 assert_difference 'IssueRelation.count', 2 do
Chris@1115 3829 post :bulk_update, :ids => [1, 3], :copy => '1',
Chris@1115 3830 :issue => {
Chris@1115 3831 :project_id => '1'
Chris@1115 3832 }
Chris@1115 3833 end
Chris@1115 3834 end
Chris@1115 3835 end
Chris@1115 3836
Chris@1115 3837 def test_bulk_copy_should_allow_not_copying_the_subtasks
Chris@1115 3838 issue = Issue.generate_with_descendants!
Chris@1115 3839 @request.session[:user_id] = 2
Chris@1115 3840
Chris@1115 3841 assert_difference 'Issue.count', 1 do
Chris@1115 3842 post :bulk_update, :ids => [issue.id], :copy => '1',
Chris@1115 3843 :issue => {
Chris@1115 3844 :project_id => ''
Chris@1115 3845 }
Chris@1115 3846 end
Chris@1115 3847 end
Chris@1115 3848
Chris@1115 3849 def test_bulk_copy_should_allow_copying_the_subtasks
Chris@1115 3850 issue = Issue.generate_with_descendants!
Chris@1115 3851 count = issue.descendants.count
Chris@1115 3852 @request.session[:user_id] = 2
Chris@1115 3853
Chris@1115 3854 assert_difference 'Issue.count', count+1 do
Chris@1115 3855 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
Chris@1115 3856 :issue => {
Chris@1115 3857 :project_id => ''
Chris@1115 3858 }
Chris@1115 3859 end
Chris@1115 3860 copy = Issue.where(:parent_id => nil).order("id DESC").first
Chris@1115 3861 assert_equal count, copy.descendants.count
Chris@1115 3862 end
Chris@1115 3863
Chris@1115 3864 def test_bulk_copy_should_not_copy_selected_subtasks_twice
Chris@1115 3865 issue = Issue.generate_with_descendants!
Chris@1115 3866 count = issue.descendants.count
Chris@1115 3867 @request.session[:user_id] = 2
Chris@1115 3868
Chris@1115 3869 assert_difference 'Issue.count', count+1 do
Chris@1115 3870 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
Chris@1115 3871 :issue => {
Chris@1115 3872 :project_id => ''
Chris@1115 3873 }
Chris@1115 3874 end
Chris@1115 3875 copy = Issue.where(:parent_id => nil).order("id DESC").first
Chris@1115 3876 assert_equal count, copy.descendants.count
Chris@1115 3877 end
Chris@1115 3878
Chris@1115 3879 def test_bulk_copy_to_another_project_should_follow_when_needed
Chris@1115 3880 @request.session[:user_id] = 2
Chris@1115 3881 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
Chris@1517 3882 issue = Issue.order('id DESC').first
Chris@1115 3883 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
Chris@1115 3884 end
Chris@1115 3885
Chris@1464 3886 def test_bulk_copy_with_all_failures_should_display_errors
Chris@1464 3887 @request.session[:user_id] = 2
Chris@1464 3888 post :bulk_update, :ids => [1, 2], :copy => '1', :issue => {:start_date => 'foo'}
Chris@1464 3889
Chris@1464 3890 assert_response :success
Chris@1464 3891 end
Chris@1464 3892
Chris@0 3893 def test_destroy_issue_with_no_time_entries
Chris@0 3894 assert_nil TimeEntry.find_by_issue_id(2)
Chris@0 3895 @request.session[:user_id] = 2
Chris@1115 3896
Chris@1115 3897 assert_difference 'Issue.count', -1 do
Chris@1115 3898 delete :destroy, :id => 2
Chris@1115 3899 end
Chris@0 3900 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 3901 assert_nil Issue.find_by_id(2)
Chris@0 3902 end
Chris@0 3903
Chris@0 3904 def test_destroy_issues_with_time_entries
Chris@0 3905 @request.session[:user_id] = 2
Chris@1115 3906
Chris@1115 3907 assert_no_difference 'Issue.count' do
Chris@1115 3908 delete :destroy, :ids => [1, 3]
Chris@1115 3909 end
Chris@0 3910 assert_response :success
Chris@0 3911 assert_template 'destroy'
Chris@0 3912 assert_not_nil assigns(:hours)
Chris@0 3913 assert Issue.find_by_id(1) && Issue.find_by_id(3)
Chris@1464 3914
Chris@1464 3915 assert_select 'form' do
Chris@1464 3916 assert_select 'input[name=_method][value=delete]'
Chris@1464 3917 end
Chris@0 3918 end
Chris@0 3919
Chris@0 3920 def test_destroy_issues_and_destroy_time_entries
Chris@0 3921 @request.session[:user_id] = 2
Chris@1115 3922
Chris@1115 3923 assert_difference 'Issue.count', -2 do
Chris@1115 3924 assert_difference 'TimeEntry.count', -3 do
Chris@1115 3925 delete :destroy, :ids => [1, 3], :todo => 'destroy'
Chris@1115 3926 end
Chris@1115 3927 end
Chris@0 3928 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 3929 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
Chris@0 3930 assert_nil TimeEntry.find_by_id([1, 2])
Chris@0 3931 end
Chris@0 3932
Chris@0 3933 def test_destroy_issues_and_assign_time_entries_to_project
Chris@0 3934 @request.session[:user_id] = 2
Chris@1115 3935
Chris@1115 3936 assert_difference 'Issue.count', -2 do
Chris@1115 3937 assert_no_difference 'TimeEntry.count' do
Chris@1115 3938 delete :destroy, :ids => [1, 3], :todo => 'nullify'
Chris@1115 3939 end
Chris@1115 3940 end
Chris@0 3941 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 3942 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
Chris@0 3943 assert_nil TimeEntry.find(1).issue_id
Chris@0 3944 assert_nil TimeEntry.find(2).issue_id
Chris@0 3945 end
Chris@441 3946
Chris@0 3947 def test_destroy_issues_and_reassign_time_entries_to_another_issue
Chris@0 3948 @request.session[:user_id] = 2
Chris@1115 3949
Chris@1115 3950 assert_difference 'Issue.count', -2 do
Chris@1115 3951 assert_no_difference 'TimeEntry.count' do
Chris@1115 3952 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
Chris@1115 3953 end
Chris@1115 3954 end
Chris@0 3955 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Chris@0 3956 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
Chris@0 3957 assert_equal 2, TimeEntry.find(1).issue_id
Chris@0 3958 assert_equal 2, TimeEntry.find(2).issue_id
Chris@0 3959 end
Chris@441 3960
chris@37 3961 def test_destroy_issues_from_different_projects
chris@37 3962 @request.session[:user_id] = 2
Chris@1115 3963
Chris@1115 3964 assert_difference 'Issue.count', -3 do
Chris@1115 3965 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
Chris@1115 3966 end
chris@37 3967 assert_redirected_to :controller => 'issues', :action => 'index'
chris@37 3968 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
chris@37 3969 end
Chris@441 3970
Chris@441 3971 def test_destroy_parent_and_child_issues
Chris@1115 3972 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
Chris@1115 3973 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
Chris@441 3974 assert child.is_descendant_of?(parent.reload)
Chris@441 3975
Chris@441 3976 @request.session[:user_id] = 2
Chris@441 3977 assert_difference 'Issue.count', -2 do
Chris@1115 3978 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
Chris@441 3979 end
Chris@441 3980 assert_response 302
Chris@441 3981 end
Chris@441 3982
Chris@1464 3983 def test_destroy_invalid_should_respond_with_404
Chris@1464 3984 @request.session[:user_id] = 2
Chris@1464 3985 assert_no_difference 'Issue.count' do
Chris@1464 3986 delete :destroy, :id => 999
Chris@1464 3987 end
Chris@1464 3988 assert_response 404
Chris@1464 3989 end
Chris@1464 3990
Chris@0 3991 def test_default_search_scope
Chris@0 3992 get :index
Chris@1464 3993
Chris@1464 3994 assert_select 'div#quick-search form' do
Chris@1464 3995 assert_select 'input[name=issues][value=1][type=hidden]'
Chris@1464 3996 end
Chris@0 3997 end
Chris@0 3998 end