issues_controller_test.rb 174 KB
Newer Older
1
# Redmine - project management software
jplang's avatar
jplang committed
2
# Copyright (C) 2006-2016  Jean-Philippe Lang
3 4 5 6 7
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
8
#
9 10 11 12
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
13
#
14 15 16 17
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

18
require File.expand_path('../../test_helper', __FILE__)
19

edavis10's avatar
edavis10 committed
20
class IssuesControllerTest < ActionController::TestCase
21
  fixtures :projects,
22
           :users, :email_addresses, :user_preferences,
23 24
           :roles,
           :members,
25
           :member_roles,
26 27
           :issues,
           :issue_statuses,
28
           :issue_relations,
29
           :versions,
30
           :trackers,
31
           :projects_trackers,
32 33 34
           :issue_categories,
           :enabled_modules,
           :enumerations,
35
           :attachments,
36 37 38
           :workflows,
           :custom_fields,
           :custom_values,
jplang's avatar
jplang committed
39
           :custom_fields_projects,
40
           :custom_fields_trackers,
41 42
           :time_entries,
           :journals,
edavis10's avatar
edavis10 committed
43
           :journal_details,
44 45 46
           :queries,
           :repositories,
           :changesets
47

48 49
  include Redmine::I18n

50 51 52
  def setup
    User.current = nil
  end
53

54
  def test_index
55 56 57 58 59 60
    with_settings :default_language => "en" do
      get :index
      assert_response :success
      assert_template 'index'
      assert_not_nil assigns(:issues)
      assert_nil assigns(:project)
61 62

      # links to visible issues
63
      assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
64
      assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
65
      # private projects hidden
66 67
      assert_select 'a[href="/issues/6"]', 0
      assert_select 'a[href="/issues/4"]', 0
68
      # project column
69
      assert_select 'th', :text => /Project/
70
    end
71
  end
72

73 74
  def test_index_should_not_list_issues_when_module_disabled
    EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 76
    get :index
    assert_response :success
77
    assert_template 'index'
78 79
    assert_not_nil assigns(:issues)
    assert_nil assigns(:project)
80

81 82
    assert_select 'a[href="/issues/1"]', 0
    assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
83
  end
jplang's avatar
jplang committed
84 85 86 87 88 89 90

  def test_index_should_list_visible_issues_only
    get :index, :per_page => 100
    assert_response :success
    assert_not_nil assigns(:issues)
    assert_nil assigns(:issues).detect {|issue| !issue.visible?}
  end
91

92
  def test_index_with_project
93
    Setting.display_subprojects_issues = 0
94 95
    get :index, :project_id => 1
    assert_response :success
96
    assert_template 'index'
97
    assert_not_nil assigns(:issues)
98

99
    assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
100
    assert_select 'a[href="/issues/5"]', 0
101
  end
102

103 104 105 106
  def test_index_with_project_and_subprojects
    Setting.display_subprojects_issues = 1
    get :index, :project_id => 1
    assert_response :success
107
    assert_template 'index'
108
    assert_not_nil assigns(:issues)
109

110
    assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
111 112
    assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
    assert_select 'a[href="/issues/6"]', 0
113
  end
114

115
  def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
116 117 118 119
    @request.session[:user_id] = 2
    Setting.display_subprojects_issues = 1
    get :index, :project_id => 1
    assert_response :success
120
    assert_template 'index'
121
    assert_not_nil assigns(:issues)
122

123
    assert_select 'a[href="/issues/1"]', :text => /Cannot print recipes/
124 125
    assert_select 'a[href="/issues/5"]', :text => /Subproject issue/
    assert_select 'a[href="/issues/6"]', :text => /Issue of a private subproject/
126
  end
127

128
  def test_index_with_project_and_default_filter
129 130
    get :index, :project_id => 1, :set_filter => 1
    assert_response :success
131
    assert_template 'index'
132
    assert_not_nil assigns(:issues)
133

134 135 136 137 138
    query = assigns(:query)
    assert_not_nil query
    # default filter
    assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
  end
139

140
  def test_index_with_project_and_filter
141
    get :index, :project_id => 1, :set_filter => 1,
jplang's avatar
jplang committed
142 143
      :f => ['tracker_id'],
      :op => {'tracker_id' => '='},
144
      :v => {'tracker_id' => ['1']}
145
    assert_response :success
146
    assert_template 'index'
147
    assert_not_nil assigns(:issues)
148

149 150 151 152
    query = assigns(:query)
    assert_not_nil query
    assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
  end
153

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  def test_index_with_short_filters
    to_test = {
      'status_id' => {
        'o' => { :op => 'o', :values => [''] },
        'c' => { :op => 'c', :values => [''] },
        '7' => { :op => '=', :values => ['7'] },
        '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
        '=7' => { :op => '=', :values => ['7'] },
        '!3' => { :op => '!', :values => ['3'] },
        '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
      'subject' => {
        'This is a subject' => { :op => '=', :values => ['This is a subject'] },
        'o' => { :op => '=', :values => ['o'] },
        '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
        '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
169 170
      'tracker_id' => {
        '3' => { :op => '=', :values => ['3'] },
emassip's avatar
emassip committed
171
        '=3' => { :op => '=', :values => ['3'] }},
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
      'start_date' => {
        '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
        '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
        '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
        '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
        '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
        '<t+2' => { :op => '<t+', :values => ['2'] },
        '>t+2' => { :op => '>t+', :values => ['2'] },
        't+2' => { :op => 't+', :values => ['2'] },
        't' => { :op => 't', :values => [''] },
        'w' => { :op => 'w', :values => [''] },
        '>t-2' => { :op => '>t-', :values => ['2'] },
        '<t-2' => { :op => '<t-', :values => ['2'] },
        't-2' => { :op => 't-', :values => ['2'] }},
      'created_on' => {
        '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
188 189 190
        '<t-2' => { :op => '<t-', :values => ['2'] },
        '>t-2' => { :op => '>t-', :values => ['2'] },
        't-2' => { :op => 't-', :values => ['2'] }},
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
      'cf_1' => {
        'c' => { :op => '=', :values => ['c'] },
        '!c' => { :op => '!', :values => ['c'] },
        '!*' => { :op => '!*', :values => [''] },
        '*' => { :op => '*', :values => [''] }},
      'estimated_hours' => {
        '=13.4' => { :op => '=', :values => ['13.4'] },
        '>=45' => { :op => '>=', :values => ['45'] },
        '<=125' => { :op => '<=', :values => ['125'] },
        '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
        '!*' => { :op => '!*', :values => [''] },
        '*' => { :op => '*', :values => [''] }}
    }

    default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}

    to_test.each do |field, expression_and_expected|
      expression_and_expected.each do |filter_expression, expected|
emassip's avatar
emassip committed
209

210 211 212 213 214 215 216 217 218 219 220 221 222 223
        get :index, :set_filter => 1, field => filter_expression

        assert_response :success
        assert_template 'index'
        assert_not_nil assigns(:issues)

        query = assigns(:query)
        assert_not_nil query
        assert query.has_filter?(field)
        assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
      end
    end
  end

224 225 226
  def test_index_with_project_and_empty_filters
    get :index, :project_id => 1, :set_filter => 1, :fields => ['']
    assert_response :success
227
    assert_template 'index'
228
    assert_not_nil assigns(:issues)
229

230 231 232 233
    query = assigns(:query)
    assert_not_nil query
    # no filter
    assert_equal({}, query.filters)
234
  end
235

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
  def test_index_with_project_custom_field_filter
    field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
    CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
    CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
    filter_name = "project.cf_#{field.id}"
    @request.session[:user_id] = 1

    get :index, :set_filter => 1,
      :f => [filter_name],
      :op => {filter_name => '='},
      :v => {filter_name => ['Foo']}
    assert_response :success
    assert_template 'index'
    assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
  end

jplang's avatar
jplang committed
252 253 254
  def test_index_with_query
    get :index, :project_id => 1, :query_id => 5
    assert_response :success
255
    assert_template 'index'
jplang's avatar
jplang committed
256 257 258
    assert_not_nil assigns(:issues)
    assert_nil assigns(:issue_count_by_group)
  end
259

260
  def test_index_with_query_grouped_by_tracker
jplang's avatar
jplang committed
261 262
    get :index, :project_id => 1, :query_id => 6
    assert_response :success
263
    assert_template 'index'
jplang's avatar
jplang committed
264
    assert_not_nil assigns(:issues)
265
    assert_not_nil assigns(:issue_count_by_group)
266
  end
267

268 269 270 271 272 273 274 275
  def test_index_with_query_grouped_and_sorted_by_category
    get :index, :project_id => 1, :set_filter => 1, :group_by => "category", :sort => "category"
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:issues)
    assert_not_nil assigns(:issue_count_by_group)
  end

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
  def test_index_with_query_grouped_and_sorted_by_fixed_version
    get :index, :project_id => 1, :set_filter => 1, :group_by => "fixed_version", :sort => "fixed_version"
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:issues)
    assert_not_nil assigns(:issue_count_by_group)
  end

  def test_index_with_query_grouped_and_sorted_by_fixed_version_in_reverse_order
    get :index, :project_id => 1, :set_filter => 1, :group_by => "fixed_version", :sort => "fixed_version:desc"
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:issues)
    assert_not_nil assigns(:issue_count_by_group)
  end

292 293 294
  def test_index_with_query_grouped_by_list_custom_field
    get :index, :project_id => 1, :query_id => 9
    assert_response :success
295
    assert_template 'index'
296
    assert_not_nil assigns(:issues)
297
    assert_not_nil assigns(:issue_count_by_group)
jplang's avatar
jplang committed
298
  end
299

300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
  def test_index_with_query_grouped_by_key_value_custom_field
    cf = IssueCustomField.create!(:name => 'Key', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'enumeration')
    cf.enumerations << valueb = CustomFieldEnumeration.new(:name => 'Value B', :position => 1)
    cf.enumerations << valuea = CustomFieldEnumeration.new(:name => 'Value A', :position => 2)
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => valueb.id)
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => valueb.id)
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => valuea.id)
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')

    get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
    assert_response :success
    assert_template 'index'
    assert_not_nil assigns(:issues)
    assert_not_nil assigns(:issue_count_by_group)

    assert_select 'tr.group', 3
    assert_select 'tr.group' do
      assert_select 'span.name', :text => 'Value B'
      assert_select 'span.count', :text => '2'
    end
    assert_select 'tr.group' do
      assert_select 'span.name', :text => 'Value A'
      assert_select 'span.count', :text => '1'
    end
  end

326 327 328 329 330 331 332 333 334 335 336 337 338
  def test_index_with_query_grouped_by_user_custom_field
    cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')

    get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
    assert_response :success

    assert_select 'tr.group', 3
    assert_select 'tr.group' do
      assert_select 'a', :text => 'John Smith'
jplang's avatar
jplang committed
339
      assert_select 'span.count', :text => '1'
340 341 342
    end
    assert_select 'tr.group' do
      assert_select 'a', :text => 'Dave Lopper'
jplang's avatar
jplang committed
343
      assert_select 'span.count', :text => '2'
344 345 346
    end
  end

347 348 349 350 351 352 353 354 355 356 357
  def test_index_grouped_by_boolean_custom_field_should_distinguish_blank_and_false_values
    cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '1')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '')

    with_settings :default_language => 'en' do
      get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
      assert_response :success
    end

358
    assert_select 'tr.group', 3
359 360
    assert_select 'tr.group', :text => /Yes/
    assert_select 'tr.group', :text => /No/
jplang's avatar
jplang committed
361
    assert_select 'tr.group', :text => /blank/
362 363
  end

364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  def test_index_grouped_by_boolean_custom_field_with_false_group_in_first_position_should_show_the_group
    cf = IssueCustomField.create!(:name => 'Bool', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'bool', :is_filter => true)
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '0')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '0')

    with_settings :default_language => 'en' do
      get :index, :project_id => 1, :set_filter => 1, "cf_#{cf.id}" => "*", :group_by => "cf_#{cf.id}"
      assert_response :success
      assert_equal [1, 2], assigns(:issues).map(&:id).sort
    end

    assert_select 'tr.group', 1
    assert_select 'tr.group', :text => /No/
  end

379
  def test_index_with_query_grouped_by_tracker_in_normal_order
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
    3.times {|i| Issue.generate!(:tracker_id => (i + 1))}

    get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
    assert_response :success

    trackers = assigns(:issues).map(&:tracker).uniq
    assert_equal [1, 2, 3], trackers.map(&:id)
  end

  def test_index_with_query_grouped_by_tracker_in_reverse_order
    3.times {|i| Issue.generate!(:tracker_id => (i + 1))}

    get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
    assert_response :success

    trackers = assigns(:issues).map(&:tracker).uniq
    assert_equal [3, 2, 1], trackers.map(&:id)
  end

399 400 401 402 403 404 405 406
  def test_index_with_query_id_and_project_id_should_set_session_query
    get :index, :project_id => 1, :query_id => 4
    assert_response :success
    assert_kind_of Hash, session[:query]
    assert_equal 4, session[:query][:id]
    assert_equal 1, session[:query][:project_id]
  end

407 408 409 410 411
  def test_index_with_invalid_query_id_should_respond_404
    get :index, :project_id => 1, :query_id => 999
    assert_response 404
  end

412
  def test_index_with_cross_project_query_in_session_should_show_project_issues
jplang's avatar
jplang committed
413
    q = IssueQuery.create!(:name => "test", :user_id => 2, :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
414 415 416 417 418 419 420 421 422 423 424 425
    @request.session[:query] = {:id => q.id, :project_id => 1}

    with_settings :display_subprojects_issues => '0' do
      get :index, :project_id => 1
    end
    assert_response :success
    assert_not_nil assigns(:query)
    assert_equal q.id, assigns(:query).id
    assert_equal 1, assigns(:query).project_id
    assert_equal [1], assigns(:issues).map(&:project_id).uniq
  end

426
  def test_private_query_should_not_be_available_to_other_users
jplang's avatar
jplang committed
427
    q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
428
    @request.session[:user_id] = 3
429

430 431 432
    get :index, :query_id => q.id
    assert_response 403
  end
433

434
  def test_private_query_should_be_available_to_its_user
jplang's avatar
jplang committed
435
    q = IssueQuery.create!(:name => "private", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PRIVATE, :project => nil)
436
    @request.session[:user_id] = 2
437

438 439 440
    get :index, :query_id => q.id
    assert_response :success
  end
441

442
  def test_public_query_should_be_available_to_other_users
443
    q = IssueQuery.create!(:name => "public", :user => User.find(2), :visibility => IssueQuery::VISIBILITY_PUBLIC, :project => nil)
444
    @request.session[:user_id] = 3
445

446 447 448
    get :index, :query_id => q.id
    assert_response :success
  end
449

450 451 452
  def test_index_should_omit_page_param_in_export_links
    get :index, :page => 2
    assert_response :success
453 454 455
    assert_select 'a.atom[href="/issues.atom"]'
    assert_select 'a.csv[href="/issues.csv"]'
    assert_select 'a.pdf[href="/issues.pdf"]'
jplang's avatar
jplang committed
456
    assert_select 'form#csv-export-form[action="/issues.csv"]'
457 458
  end

459 460 461 462 463 464 465 466 467 468 469 470 471 472
  def test_index_should_not_warn_when_not_exceeding_export_limit
    with_settings :issues_export_limit => 200 do
      get :index
      assert_select '#csv-export-options p.icon-warning', 0
    end
  end

  def test_index_should_warn_when_exceeding_export_limit
    with_settings :issues_export_limit => 2 do
      get :index
      assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
    end
  end

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
  def test_index_should_include_query_params_as_hidden_fields_in_csv_export_form
    get :index, :project_id => 1, :set_filter => "1", :tracker_id => "2", :sort => 'status', :c => ["status", "priority"]

    assert_select '#csv-export-form[action=?]', '/projects/ecookbook/issues.csv'
    assert_select '#csv-export-form[method=?]', 'get'

    assert_select '#csv-export-form' do
      assert_select 'input[name=?][value=?]', 'set_filter', '1'

      assert_select 'input[name=?][value=?]', 'f[]', 'tracker_id'
      assert_select 'input[name=?][value=?]', 'op[tracker_id]', '='
      assert_select 'input[name=?][value=?]', 'v[tracker_id][]', '2'

      assert_select 'input[name=?][value=?]', 'c[]', 'status'
      assert_select 'input[name=?][value=?]', 'c[]', 'priority'

      assert_select 'input[name=?][value=?]', 'sort', 'status'
    end
491 492 493

    get :index, :project_id => 1, :set_filter => "1", :f => []
    assert_select '#csv-export-form input[name=?][value=?]', 'f[]', ''
494 495
  end

496
  def test_index_csv
497 498 499
    get :index, :format => 'csv'
    assert_response :success
    assert_not_nil assigns(:issues)
jplang's avatar
jplang committed
500
    assert_equal 'text/csv; header=present', @response.content_type
501
    assert @response.body.starts_with?("#,")
502
    lines = @response.body.chomp.split("\n")
503
    assert_equal assigns(:query).columns.size, lines[0].split(',').size
504
  end
505

506
  def test_index_csv_with_project
507 508 509
    get :index, :project_id => 1, :format => 'csv'
    assert_response :success
    assert_not_nil assigns(:issues)
jplang's avatar
jplang committed
510
    assert_equal 'text/csv; header=present', @response.content_type
511
  end
512

513 514 515 516 517 518 519 520
  def test_index_csv_without_any_filters
    @request.session[:user_id] = 1
    Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 5, :subject => 'Closed issue', :author_id => 1)
    get :index, :set_filter => 1, :f => [], :format => 'csv'
    assert_response :success
    assert_equal Issue.count, assigns(:issues).count
  end

521
  def test_index_csv_with_description
522 523 524
    Issue.generate!(:description => 'test_index_csv_with_description')

    with_settings :default_language => 'en' do
525
      get :index, :format => 'csv', :csv => {:description => '1'}
526 527 528 529 530 531 532 533
      assert_response :success
      assert_not_nil assigns(:issues)
    end

    assert_equal 'text/csv; header=present', response.content_type
    headers = response.body.chomp.split("\n").first.split(',')
    assert_include 'Description', headers
    assert_include 'test_index_csv_with_description', response.body
534 535
  end

536
  def test_index_csv_with_spent_time_column
jplang's avatar
jplang committed
537 538
    issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
    TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
539 540 541

    get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
    assert_response :success
jplang's avatar
jplang committed
542
    assert_equal 'text/csv; header=present', @response.content_type
543 544 545 546
    lines = @response.body.chomp.split("\n")
    assert_include "#{issue.id},#{issue.subject},7.33", lines
  end

547
  def test_index_csv_with_all_columns
548
    get :index, :format => 'csv', :csv => {:columns => 'all'}
549 550
    assert_response :success
    assert_not_nil assigns(:issues)
jplang's avatar
jplang committed
551
    assert_equal 'text/csv; header=present', @response.content_type
552 553 554
    assert_match /\A#,/, response.body
    lines = response.body.chomp.split("\n")
    assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size
555 556
  end

jplang's avatar
jplang committed
557 558 559 560 561 562
  def test_index_csv_with_multi_column_field
    CustomField.find(1).update_attribute :multiple, true
    issue = Issue.find(1)
    issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
    issue.save!

563
    get :index, :format => 'csv', :csv => {:columns => 'all'}
jplang's avatar
jplang committed
564 565 566 567 568
    assert_response :success
    lines = @response.body.chomp.split("\n")
    assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
  end

569 570 571 572 573
  def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator
    field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float')
    issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'})

    with_settings :default_language => 'fr' do
574
      get :index, :format => 'csv', :csv => {:columns => 'all'}
575 576 577 578 579 580
      assert_response :success
      issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s}
      assert_include '185,60', issue_line
    end

    with_settings :default_language => 'en' do
581
      get :index, :format => 'csv', :csv => {:columns => 'all'}
582 583 584 585 586
      assert_response :success
      issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s}
      assert_include '185.60', issue_line
    end
  end
587 588 589 590 591 592 593 594 595

  def test_index_csv_should_fill_parent_column_with_parent_id
    Issue.delete_all
    parent = Issue.generate!
    child = Issue.generate!(:parent_issue_id => parent.id)

    with_settings :default_language => 'en' do
      get :index, :format => 'csv', :c => %w(parent)
    end
jplang's avatar
Typo.  
jplang committed
596
    lines = response.body.split("\n")
597 598
    assert_include "#{child.id},#{parent.id}", lines
  end
599

600 601
  def test_index_csv_big_5
    with_settings :default_language => "zh-TW" do
jplang's avatar
jplang committed
602 603
      str_utf8  = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8')
      str_big5  = "\xa4@\xa4\xeb".force_encoding('Big5')
jplang's avatar
jplang committed
604
      issue = Issue.generate!(:subject => str_utf8)
605 606 607 608 609

      get :index, :project_id => 1, 
                  :f => ['subject'], 
                  :op => '=', :values => [str_utf8],
                  :format => 'csv'
jplang's avatar
jplang committed
610
      assert_equal 'text/csv; header=present', @response.content_type
611
      lines = @response.body.chomp.split("\n")
612
      header = lines[0]
613
      status = "\xaa\xac\xbaA".force_encoding('Big5')
614
      assert_include status, header
615
      issue_line = lines.find {|l| l =~ /^#{issue.id},/}
616
      assert_include str_big5, issue_line
617 618 619
    end
  end

620 621
  def test_index_csv_cannot_convert_should_be_replaced_big_5
    with_settings :default_language => "zh-TW" do
jplang's avatar
jplang committed
622
      str_utf8  = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
jplang's avatar
jplang committed
623
      issue = Issue.generate!(:subject => str_utf8)
624 625 626 627

      get :index, :project_id => 1, 
                  :f => ['subject'], 
                  :op => '=', :values => [str_utf8],
628 629 630
                  :c => ['status', 'subject'],
                  :format => 'csv',
                  :set_filter => 1
jplang's avatar
jplang committed
631
      assert_equal 'text/csv; header=present', @response.content_type
632
      lines = @response.body.chomp.split("\n")
633 634
      header = lines[0]
      issue_line = lines.find {|l| l =~ /^#{issue.id},/}
jplang's avatar
jplang committed
635
      s1 = "\xaa\xac\xbaA".force_encoding('Big5') # status
636 637
      assert header.include?(s1)
      s2 = issue_line.split(",")[2]
jplang's avatar
jplang committed
638 639
      s3 = "\xa5H?".force_encoding('Big5') # subject
      assert_equal s3, s2
640 641 642
    end
  end

643 644 645
  def test_index_csv_tw
    with_settings :default_language => "zh-TW" do
      str1  = "test_index_csv_tw"
jplang's avatar
jplang committed
646
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
647 648 649 650 651 652 653

      get :index, :project_id => 1, 
                  :f => ['subject'], 
                  :op => '=', :values => [str1],
                  :c => ['estimated_hours', 'subject'],
                  :format => 'csv',
                  :set_filter => 1
jplang's avatar
jplang committed
654
      assert_equal 'text/csv; header=present', @response.content_type
655
      lines = @response.body.chomp.split("\n")
656
      assert_include "#{issue.id},1234.50,#{str1}", lines
657 658 659 660 661 662
    end
  end

  def test_index_csv_fr
    with_settings :default_language => "fr" do
      str1  = "test_index_csv_fr"
jplang's avatar
jplang committed
663
      issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
664 665 666 667 668 669 670

      get :index, :project_id => 1, 
                  :f => ['subject'], 
                  :op => '=', :values => [str1],
                  :c => ['estimated_hours', 'subject'],
                  :format => 'csv',
                  :set_filter => 1
jplang's avatar
jplang committed
671
      assert_equal 'text/csv; header=present', @response.content_type
672
      lines = @response.body.chomp.split("\n")
673
      assert_include "#{issue.id};1234,50;#{str1}", lines
674 675 676
    end
  end

677
  def test_index_pdf
678 679
    ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
      with_settings :default_language => lang do
680

681 682 683
        get :index
        assert_response :success
        assert_template 'index'
684

685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
        get :index, :format => 'pdf'
        assert_response :success
        assert_not_nil assigns(:issues)
        assert_equal 'application/pdf', @response.content_type

        get :index, :project_id => 1, :format => 'pdf'
        assert_response :success
        assert_not_nil assigns(:issues)
        assert_equal 'application/pdf', @response.content_type

        get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
        assert_response :success
        assert_not_nil assigns(:issues)
        assert_equal 'application/pdf', @response.content_type
      end
    end
701
  end
702

703 704 705 706 707 708 709
  def test_index_pdf_with_query_grouped_by_list_custom_field
    get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
    assert_response :success
    assert_not_nil assigns(:issues)
    assert_not_nil assigns(:issue_count_by_group)
    assert_equal 'application/pdf', @response.content_type
  end
710

711 712 713 714
  def test_index_atom
    get :index, :project_id => 'ecookbook', :format => 'atom'
    assert_response :success
    assert_template 'common/feed'
715
    assert_equal 'application/atom+xml', response.content_type
716

717 718 719 720 721
    assert_select 'feed' do
      assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
      assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
      assert_select 'entry link[href=?]', 'http://test.host/issues/1'
    end
722 723
  end

724 725 726 727 728 729
  def test_index_should_include_back_url_input
    get :index, :project_id => 'ecookbook', :foo => 'bar'
    assert_response :success
    assert_select 'input[name=back_url][value=?]', '/projects/ecookbook/issues?foo=bar'
  end

730
  def test_index_sort
jplang's avatar
jplang committed
731
    get :index, :sort => 'tracker,id:desc'
732
    assert_response :success
733

jplang's avatar
jplang committed
734 735 736
    sort_params = @request.session['issues_index_sort']
    assert sort_params.is_a?(String)
    assert_equal 'tracker,id:desc', sort_params
737

jplang's avatar
jplang committed
738 739 740 741
    issues = assigns(:issues)
    assert_not_nil issues
    assert !issues.empty?
    assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
742
    assert_select 'table.issues.sort-by-tracker.sort-asc'
743
  end
744 745 746 747 748 749 750 751 752 753 754

  def test_index_sort_by_field_not_included_in_columns
    Setting.issue_list_default_columns = %w(subject author)
    get :index, :sort => 'tracker'
  end
  
  def test_index_sort_by_assigned_to
    get :index, :sort => 'assigned_to'
    assert_response :success
    assignees = assigns(:issues).collect(&:assigned_to).compact
    assert_equal assignees.sort, assignees
755
    assert_select 'table.issues.sort-by-assigned-to.sort-asc'
756 757 758 759 760 761 762
  end
  
  def test_index_sort_by_assigned_to_desc
    get :index, :sort => 'assigned_to:desc'
    assert_response :success
    assignees = assigns(:issues).collect(&:assigned_to).compact
    assert_equal assignees.sort.reverse, assignees
763
    assert_select 'table.issues.sort-by-assigned-to.sort-desc'
764 765 766 767 768 769
  end
  
  def test_index_group_by_assigned_to
    get :index, :group_by => 'assigned_to', :sort => 'priority'
    assert_response :success
  end
770 771 772 773
  
  def test_index_sort_by_author
    get :index, :sort => 'author'
    assert_response :success
774 775 776 777 778 779 780 781 782
    authors = assigns(:issues).collect(&:author)
    assert_equal authors.sort, authors
  end
  
  def test_index_sort_by_author_desc
    get :index, :sort => 'author:desc'
    assert_response :success
    authors = assigns(:issues).collect(&:author)
    assert_equal authors.sort.reverse, authors
783 784 785 786 787 788
  end
  
  def test_index_group_by_author
    get :index, :group_by => 'author', :sort => 'priority'
    assert_response :success
  end
789
  
jplang's avatar
jplang committed
790 791
  def test_index_sort_by_spent_hours
    get :index, :sort => 'spent_hours:desc'
792 793 794 795
    assert_response :success
    hours = assigns(:issues).collect(&:spent_hours)
    assert_equal hours.sort.reverse, hours
  end
796 797 798 799 800 801 802
  
  def test_index_sort_by_total_spent_hours
    get :index, :sort => 'total_spent_hours:desc'
    assert_response :success
    hours = assigns(:issues).collect(&:total_spent_hours)
    assert_equal hours.sort.reverse, hours
  end
803 804 805 806 807 808 809
  
  def test_index_sort_by_total_estimated_hours
    get :index, :sort => 'total_estimated_hours:desc'
    assert_response :success
    hours = assigns(:issues).collect(&:total_estimated_hours)
    assert_equal hours.sort.reverse, hours
  end
810

811 812 813 814 815 816 817 818 819 820 821 822 823
  def test_index_sort_by_user_custom_field
    cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
    CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')

    get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
    assert_response :success

    assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
  end

824 825
  def test_index_with_columns
    columns = ['tracker', 'subject', 'assigned_to']
826
    get :index, :set_filter => 1, :c => columns
827
    assert_response :success
828

829 830
    # query should use specified columns
    query = assigns(:query)
831
    assert_kind_of IssueQuery, query
832
    assert_equal columns, query.column_names.map(&:to_s)
833

834 835 836 837
    # columns should be stored in session
    assert_kind_of Hash, session[:query]
    assert_kind_of Array, session[:query][:column_names]
    assert_equal columns, session[:query][:column_names].map(&:to_s)
838 839

    # ensure only these columns are kept in the selected columns list
840 841 842 843 844
    assert_select 'select#selected_columns option' do
      assert_select 'option', 3
      assert_select 'option[value=tracker]'
      assert_select 'option[value=project]', 0
    end
845
  end
846

847 848 849 850 851 852
  def test_index_without_project_should_implicitly_add_project_column_to_default_columns
    Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
    get :index, :set_filter => 1

    # query should use specified columns
    query = assigns(:query)
853
    assert_kind_of IssueQuery, query
854
    assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
855 856 857 858
  end

  def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
    Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
859
    columns = ['id', 'tracker', 'subject', 'assigned_to']
860 861 862 863
    get :index, :set_filter => 1, :c => columns

    # query should use specified columns
    query = assigns(:query)
864
    assert_kind_of IssueQuery, query
865 866 867
    assert_equal columns.map(&:to_sym), query.columns.map(&:name)
  end

868 869 870 871 872 873 874 875 876 877
  def test_index_with_default_columns_should_respect_default_columns_order
    columns = ['assigned_to', 'subject', 'status', 'tracker']
    with_settings :issue_list_default_columns => columns do
      get :index, :project_id => 1, :set_filter => 1

      query = assigns(:query)
      assert_equal (['id'] + columns).map(&:to_sym), query.columns.map(&:name)
    end
  end

878 879 880 881
  def test_index_with_custom_field_column
    columns = %w(tracker subject cf_2)
    get :index, :set_filter => 1, :c => columns
    assert_response :success
882

883 884
    # query should use specified columns
    query = assigns(:query)
885
    assert_kind_of IssueQuery, query
886
    assert_equal columns, query.column_names.map(&:to_s)
887

888
    assert_select 'table.issues td.cf_2.string'
889
  end
890

891 892 893 894 895 896 897 898 899 900
  def test_index_with_multi_custom_field_column
    field = CustomField.find(1)
    field.update_attribute :multiple, true
    issue = Issue.find(1)
    issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
    issue.save!

    get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
    assert_response :success

901
    assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
902 903 904 905 906 907 908 909 910 911 912 913
  end

  def test_index_with_multi_user_custom_field_column
    field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
      :tracker_ids => [1], :is_for_all => true)
    issue = Issue.find(1)
    issue.custom_field_values = {field.id => ['2', '3']}
    issue.save!

    get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
    assert_response :success

914 915 916 917 918
    assert_select "table.issues td.cf_#{field.id}" do
      assert_select 'a', 2
      assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
      assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
    end
919 920
  end

921 922
  def test_index_with_date_column
    with_settings :date_format => '%d/%m/%Y' do
923
      Issue.find(1).update_attribute :start_date, '1987-08-24'
924
      get :index, :set_filter => 1, :c => %w(start_date)
925
      assert_select "table.issues td.start_date", :text => '24/08/1987'
926 927 928
    end
  end

929
  def test_index_with_done_ratio_column
930 931
    Issue.find(1).update_attribute :done_ratio, 40
    get :index, :set_filter => 1, :c => %w(done_ratio)
932 933 934 935 936
    assert_select 'table.issues td.done_ratio' do
      assert_select 'table.progress' do
        assert_select 'td.closed[style=?]', 'width: 40%;'
      end
    end
937 938
  end

939
  def test_index_with_spent_hours_column
940
    Issue.expects(:load_visible_spent_hours).once
941
    get :index, :set_filter => 1, :c => %w(subject spent_hours)
942
    assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
943 944
  end

945
  def test_index_with_total_spent_hours_column
946
    Issue.expects(:load_visible_total_spent_hours).once
947 948 949 950
    get :index, :set_filter => 1, :c => %w(subject total_spent_hours)
    assert_select 'table.issues tr#issue-3 td.total_spent_hours', :text => '1.00'
  end

951 952 953 954 955
  def test_index_with_total_estimated_hours_column
    get :index, :set_filter => 1, :c => %w(subject total_estimated_hours)
    assert_select 'table.issues td.total_estimated_hours'
  end

956 957 958
  def test_index_should_not_show_spent_hours_column_without_permission
    Role.anonymous.remove_permission! :view_time_entries
    get :index, :set_filter => 1, :c => %w(subject spent_hours)
959
    assert_select 'td.spent_hours', 0
960 961
  end

962
  def test_index_with_fixed_version_column
963
    get :index, :set_filter => 1, :c => %w(fixed_version)
964
    assert_select 'table.issues td.fixed_version' do
965
      assert_select 'a[href=?]', '/versions/2', :text => 'eCookbook - 1.0'
966
    end
967 968
  end

969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
  def test_index_with_relations_column
    IssueRelation.delete_all
    IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
    IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
    IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
    IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))

    get :index, :set_filter => 1, :c => %w(subject relations)
    assert_response :success
    assert_select "tr#issue-1 td.relations" do
      assert_select "span", 3
      assert_select "span", :text => "Related to #7"
      assert_select "span", :text => "Related to #8"
      assert_select "span", :text => "Blocks #11"
    end
    assert_select "tr#issue-2 td.relations" do
      assert_select "span", 1
      assert_select "span", :text => "Blocked by #12"
    end
    assert_select "tr#issue-3 td.relations" do
      assert_select "span", 0
    end

    get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
    assert_response :success
    assert_equal 'text/csv; header=present', response.content_type
    lines = response.body.chomp.split("\n")
    assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
    assert_include '2,Blocked by #12', lines
    assert_include '3,""', lines

    get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
    assert_response :success
    assert_equal 'application/pdf', response.content_type
  end

1005 1006 1007 1008
  def test_index_with_description_column
    get :index, :set_filter => 1, :c => %w(subject description)

    assert_select 'table.issues thead th', 3 # columns: chekbox + id + subject
jplang's avatar
jplang committed
1009
    assert_select 'td.description[colspan="3"]', :text => 'Unable to print recipes'
1010 1011 1012 1013 1014 1015

    get :index, :set_filter => 1, :c => %w(subject description), :format => 'pdf'
    assert_response :success
    assert_equal 'application/pdf', response.content_type
  end

1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
  def test_index_with_parent_column
    Issue.delete_all
    parent = Issue.generate!
    child = Issue.generate!(:parent_issue_id => parent.id)

    get :index, :c => %w(parent)

    assert_select 'td.parent', :text => "#{parent.tracker} ##{parent.id}"
    assert_select 'td.parent a[title=?]', parent.subject
  end

1027 1028 1029 1030 1031 1032 1033 1034
  def test_index_with_estimated_hours_total
    Issue.delete_all
    Issue.generate!(:estimated_hours => 5.5)
    Issue.generate!(:estimated_hours => 1.1)

    get :index, :t => %w(estimated_hours)
    assert_response :success
    assert_select '.query-totals'
1035
    assert_select '.total-for-estimated-hours span.value', :text => '6.60'
1036 1037 1038
    assert_select 'input[type=checkbox][name=?][value=estimated_hours][checked=checked]', 't[]'
  end

1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
  def test_index_with_grouped_query_and_estimated_hours_total
    Issue.delete_all
    Issue.generate!(:estimated_hours => 5.5, :category_id => 1)
    Issue.generate!(:estimated_hours => 2.3, :category_id => 1)
    Issue.generate!(:estimated_hours => 1.1, :category_id => 2)
    Issue.generate!(:estimated_hours => 4.6)

    get :index, :t => %w(estimated_hours), :group_by => 'category'
    assert_response :success
    assert_select '.query-totals'
    assert_select '.query-totals .total-for-estimated-hours span.value', :text => '13.50'
    assert_select 'tr.group', :text => /Printing/ do
      assert_select '.total-for-estimated-hours span.value', :text => '7.80'
    end
    assert_select 'tr.group', :text => /Recipes/ do
      assert_select '.total-for-estimated-hours span.value', :text => '1.10'
    end
    assert_select 'tr.group', :text => /blank/ do
      assert_select '.total-for-estimated-hours span.value', :text => '4.60'
    end
  end

1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
  def test_index_with_int_custom_field_total
    field = IssueCustomField.generate!(:field_format => 'int', :is_for_all => true)
    CustomValue.create!(:customized => Issue.find(1), :custom_field => field, :value => '2')
    CustomValue.create!(:customized => Issue.find(2), :custom_field => field, :value => '7')

    get :index, :t => ["cf_#{field.id}"]
    assert_response :success
    assert_select '.query-totals'
    assert_select ".total-for-cf-#{field.id} span.value", :text => '9'
  end

  def test_index_totals_should_default_to_settings
    with_settings :issue_list_default_totals => ['estimated_hours'] do
      get :index
      assert_response :success
      assert_select '.total-for-estimated-hours span.value'
      assert_select '.query-totals>span', 1
    end
  end

1081 1082 1083 1084 1085 1086
  def test_index_send_html_if_query_is_invalid
    get :index, :f => ['start_date'], :op => {:start_date => '='}
    assert_equal 'text/html', @response.content_type
    assert_template 'index'
  end

1087 1088 1089 1090 1091 1092
  def test_index_send_nothing_if_query_is_invalid
    get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
    assert_equal 'text/csv', @response.content_type
    assert @response.body.blank?
  end

1093 1094 1095
  def test_index_should_include_new_issue_link
    @request.session[:user_id] = 2
    get :index, :project_id => 1
1096
    assert_select '#content a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue'
1097 1098 1099 1100 1101 1102 1103
  end

  def test_index_should_not_include_new_issue_link_for_project_without_trackers
    Project.find(1).trackers.clear

    @request.session[:user_id] = 2
    get :index, :project_id => 1
1104
    assert_select '#content a.new-issue', 0
1105 1106 1107 1108 1109 1110 1111 1112 1113
  end

  def test_index_should_not_include_new_issue_link_for_users_with_copy_issues_permission_only
    role = Role.find(1)
    role.remove_permission! :add_issues
    role.add_permission! :copy_issues

    @request.session[:user_id] = 2
    get :index, :project_id => 1
1114
    assert_select '#content a.new-issue', 0
1115 1116
  end

1117 1118 1119
  def test_index_without_project_should_include_new_issue_link
    @request.session[:user_id] = 2
    get :index
1120 1121 1122 1123
    assert_select '#content a.new-issue[href="/issues/new"]', :text => 'New issue'
  end

  def test_index_should_not_include_new_issue_tab_when_disabled
1124
    with_settings :new_item_menu_tab => '0' do
1125 1126 1127 1128 1129 1130 1131
      @request.session[:user_id] = 2
      get :index, :project_id => 1
      assert_select '#main-menu a.new-issue', 0
    end
  end

  def test_index_should_include_new_issue_tab_when_enabled
1132
    with_settings :new_item_menu_tab => '1' do
1133 1134 1135 1136 1137 1138 1139
      @request.session[:user_id] = 2
      get :index, :project_id => 1
      assert_select '#main-menu a.new-issue[href="/projects/ecookbook/issues/new"]', :text => 'New issue'
    end
  end

  def test_new_should_have_new_issue_tab_as_current_menu_item
1140
    with_settings :new_item_menu_tab => '1' do
1141 1142 1143 1144 1145 1146 1147
      @request.session[:user_id] = 2
      get :new, :project_id => 1
      assert_select '#main-menu a.new-issue.selected'
    end
  end

  def test_index_should_not_include_new_issue_tab_for_project_without_trackers
1148
    with_settings :new_item_menu_tab => '1' do
1149 1150 1151 1152 1153 1154 1155 1156 1157
      Project.find(1).trackers.clear
  
      @request.session[:user_id] = 2
      get :index, :project_id => 1
      assert_select '#main-menu a.new-issue', 0
    end
  end