Project

General

Profile

Feature #6721 » feature_6721.diff

Sridhar P, 2012-01-05 09:04

View differences:

test/functional/issues_controller_test.rb (working copy)
1437 1437
    assert_equal 59, File.size(attachment.diskfile)
1438 1438
  end
1439 1439

  
1440
  def test_post_create_with_login_name
1441
    @request.session[:user_id] = 2
1442
	user = User.find(4)
1443

  
1444
    assert_difference 'Issue.count' do
1445
      post :create, :project_id => 1,
1446
                 :issue => {:tracker_id => 3,
1447
                            :status_id => 2,
1448
                            :subject => 'This is the test_new_with_login issue',
1449
                            :description => 'This is the description',
1450
							:assigned_to_name => user.login,
1451
                            :priority_id => 5,
1452
                            :start_date => '2010-11-07'
1453
							}
1454
    end
1455
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1456

  
1457
    issue = Issue.find_by_subject('This is the test_new_with_login issue')
1458
    assert_not_nil issue
1459
    assert_equal 2, issue.author_id
1460
    assert_equal 3, issue.tracker_id
1461
    assert_equal 2, issue.status_id
1462
	assert_equal 4, issue.assigned_to_id
1463
    assert_equal Date.parse('2010-11-07'), issue.start_date
1464
  end
1465

  
1440 1466
  context "without workflow privilege" do
1441 1467
    setup do
1442 1468
      Workflow.delete_all(["role_id = ?", Role.anonymous.id])
......
1743 1769
    assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1744 1770
  end
1745 1771

  
1772
  def test_put_update_with_status_and_assignee_change_with_login_name
1773
    issue = Issue.find(1)
1774
    assert_equal 1, issue.status_id
1775
	user = User.find(4)
1776
    @request.session[:user_id] = 2
1777
    assert_difference('TimeEntry.count', 0) do
1778
      put :update,
1779
           :id => 1,
1780
           :issue => { :status_id => 2, :assigned_to_name => user.login },
1781
           :notes => 'Assigned to ' + user.login,
1782
           :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1783
    end
1784
    assert_redirected_to :action => 'show', :id => '1'
1785
    issue.reload
1786
    assert_equal 2, issue.status_id
1787
    j = Journal.find(:first, :order => 'id DESC')
1788
    assert_equal 'Assigned to ' + user.login, j.notes
1789
    assert_equal 2, j.details.size
1790
	assert_equal user.id, issue.assigned_to_id
1791

  
1792
    mail = ActionMailer::Base.deliveries.last
1793
    assert mail.body.include?("Status changed from New to Assigned")
1794
    # subject should contain the new status
1795
    assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
1796
  end
1797

  
1746 1798
  def test_put_update_with_note_only
1747 1799
    notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
1748 1800
    # anonymous user
app/controllers/issues_controller.rb (working copy)
303 303
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
304 304
    @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
305 305
    @time_entry.attributes = params[:time_entry]
306
	
307
	name_from_id_for_create_update()
306 308

  
307 309
    @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
308 310
    @issue.init_journal(User.current, @notes)
......
328 330
      render_error l(:error_no_tracker_in_project)
329 331
      return false
330 332
    end
333

  
334
	name_from_id_for_create_update()
335

  
331 336
    @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
332 337
    @issue.safe_attributes = params[:issue]
333 338

  
......
348 353
    attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
349 354
    attributes
350 355
  end
356

  
357
  def name_from_id_for_create_update
358
    # do nothing if assigned_to_id is set
359
	if params[:issue] && params[:issue][:assigned_to_id].nil? && params[:issue][:assigned_to_name]
360
	  user = User.find_by_login(params[:issue][:assigned_to_name])
361
	  unless user.nil?
362
	    params[:issue][:assigned_to_id] = user.id
363
	  end
364
	end
365
  end
351 366
end
(1-1/4)