annotate .svn/pristine/37/37daad43f5c4a3d690d4d19284c0c5d27ead44dc.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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