Index: test/functional/issues_controller_test.rb =================================================================== --- test/functional/issues_controller_test.rb (revision 8513) +++ test/functional/issues_controller_test.rb (working copy) @@ -1437,6 +1437,32 @@ assert_equal 59, File.size(attachment.diskfile) end + def test_post_create_with_login_name + @request.session[:user_id] = 2 + user = User.find(4) + + assert_difference 'Issue.count' do + post :create, :project_id => 1, + :issue => {:tracker_id => 3, + :status_id => 2, + :subject => 'This is the test_new_with_login issue', + :description => 'This is the description', + :assigned_to_name => user.login, + :priority_id => 5, + :start_date => '2010-11-07' + } + end + assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id + + issue = Issue.find_by_subject('This is the test_new_with_login issue') + assert_not_nil issue + assert_equal 2, issue.author_id + assert_equal 3, issue.tracker_id + assert_equal 2, issue.status_id + assert_equal 4, issue.assigned_to_id + assert_equal Date.parse('2010-11-07'), issue.start_date + end + context "without workflow privilege" do setup do Workflow.delete_all(["role_id = ?", Role.anonymous.id]) @@ -1743,6 +1769,32 @@ assert mail.subject.include?("(#{ IssueStatus.find(2).name })") end + def test_put_update_with_status_and_assignee_change_with_login_name + issue = Issue.find(1) + assert_equal 1, issue.status_id + user = User.find(4) + @request.session[:user_id] = 2 + assert_difference('TimeEntry.count', 0) do + put :update, + :id => 1, + :issue => { :status_id => 2, :assigned_to_name => user.login }, + :notes => 'Assigned to ' + user.login, + :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } + end + assert_redirected_to :action => 'show', :id => '1' + issue.reload + assert_equal 2, issue.status_id + j = Journal.find(:first, :order => 'id DESC') + assert_equal 'Assigned to ' + user.login, j.notes + assert_equal 2, j.details.size + assert_equal user.id, issue.assigned_to_id + + mail = ActionMailer::Base.deliveries.last + assert mail.body.include?("Status changed from New to Assigned") + # subject should contain the new status + assert mail.subject.include?("(#{ IssueStatus.find(2).name })") + end + def test_put_update_with_note_only notes = 'Note added by IssuesControllerTest#test_update_with_note_only' # anonymous user Index: app/controllers/issues_controller.rb =================================================================== --- app/controllers/issues_controller.rb (revision 8513) +++ app/controllers/issues_controller.rb (working copy) @@ -303,6 +303,8 @@ @edit_allowed = User.current.allowed_to?(:edit_issues, @project) @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) @time_entry.attributes = params[:time_entry] + + name_from_id_for_create_update() @notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil) @issue.init_journal(User.current, @notes) @@ -328,6 +330,9 @@ render_error l(:error_no_tracker_in_project) return false end + + name_from_id_for_create_update() + @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? @issue.safe_attributes = params[:issue] @@ -348,4 +353,14 @@ attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values] attributes end + + def name_from_id_for_create_update + # do nothing if assigned_to_id is set + if params[:issue] && params[:issue][:assigned_to_id].nil? && params[:issue][:assigned_to_name] + user = User.find_by_login(params[:issue][:assigned_to_name]) + unless user.nil? + params[:issue][:assigned_to_id] = user.id + end + end + end end