0001-Allow-to-specify-projects_id-as-identifier-in-issue-creation.diff

Holger Just, 2016-09-06 12:00

Download (1.67 KB)

View differences:

app/models/issue.rb
502 502
    # Project and Tracker must be set before since new_statuses_allowed_to depends on it.
503 503
    if (p = attrs.delete('project_id')) && safe_attribute?('project_id')
504
      if allowed_target_projects(user).where(:id => p.to_i).exists?
505
        self.project_id = p
504
      if p.is_a?(String) && !p.match(/^\d*$/)
505
        p_id = Project.find_by_identifier(p).try(:id)
506
      else
507
        p_id = p.to_i
508
      end
509
      if allowed_target_projects(user).where(:id => p_id).exists?
510
        self.project_id = p_id
506 511
      end
507 512
      if project_id_changed? && attrs['category_id'].to_s == category_id_was.to_s
test/functional/issues_controller_test.rb
2535 2535
    assert_equal 2, issue.tracker_id
2536 2536
  end
2537
  def test_create_with_project_identifier
2538
    @request.session[:user_id] = 2
2539

  
2540
    assert_difference 'Issue.count' do
2541
      post :create,
2542
           :issue => {:project_id => 'subproject1',
2543
                      :tracker_id => 2,
2544
                      :subject => 'Foo'}
2545
      assert_response 302
2546
    end
2547
    issue = Issue.order('id DESC').first
2548
    assert_equal 3, issue.project_id
2549
    assert_equal 2, issue.tracker_id
2550
  end
2551

  
2537 2552
  def test_create_without_project_id_and_continue_should_redirect_without_project_id
2538 2553
    @request.session[:user_id] = 2