From 21c0b868ae1d7836dcfe34ac0ad740df981e304d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 29 Dec 2010 17:36:01 +0000 Subject: [PATCH] Fixed: Tracker reset to default when replying to an issue email (#7197). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4575 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 10 ++++++++-- .../mail_handler/ticket_reply_with_status.eml | 2 +- test/unit/mail_handler_test.rb | 17 +++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 00010059f..4b6b4a402 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -256,8 +256,8 @@ class MailHandler < ActionMailer::Base assigned_to = (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k) assigned_to = nil if assigned_to && !issue.assignable_users.include?(assigned_to) - { - 'tracker_id' => ((k = get_keyword(:tracker)) && issue.project.trackers.find_by_name(k).try(:id)) || issue.project.trackers.find(:first).try(:id), + attrs = { + 'tracker_id' => (k = get_keyword(:tracker)) && issue.project.trackers.find_by_name(k).try(:id), 'status_id' => (k = get_keyword(:status)) && IssueStatus.find_by_name(k).try(:id), 'priority_id' => (k = get_keyword(:priority)) && IssuePriority.find_by_name(k).try(:id), 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.find_by_name(k).try(:id), @@ -268,6 +268,12 @@ class MailHandler < ActionMailer::Base 'estimated_hours' => get_keyword(:estimated_hours, :override => true), 'done_ratio' => get_keyword(:done_ratio, :override => true, :format => '(\d|10)?0') }.delete_if {|k, v| v.blank? } + + if issue.new_record? && attrs['tracker_id'].nil? + attrs['tracker_id'] = issue.project.trackers.find(:first).try(:id) + end + + attrs end # Returns a Hash of issue custom field values extracted from keywords in the email body diff --git a/test/fixtures/mail_handler/ticket_reply_with_status.eml b/test/fixtures/mail_handler/ticket_reply_with_status.eml index 66ca730ac..52beda37b 100644 --- a/test/fixtures/mail_handler/ticket_reply_with_status.eml +++ b/test/fixtures/mail_handler/ticket_reply_with_status.eml @@ -29,7 +29,7 @@ Status: Resolved due date: 2010-12-31 Start Date:2010-01-01 Assigned to: jsmith@somenet.foo -searchable field: Updated custom value +float field: 52.6 ------=_NextPart_000_0067_01C8D3CE.711F9CC0 Content-Type: text/html; diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index feb09e12e..df22bddc8 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -36,6 +36,7 @@ class MailHandlerTest < ActiveSupport::TestCase :issue_categories, :custom_fields, :custom_fields_trackers, + :custom_fields_projects, :boards, :messages @@ -53,9 +54,10 @@ class MailHandlerTest < ActiveSupport::TestCase assert issue.is_a?(Issue) assert !issue.new_record? issue.reload + assert_equal Project.find(2), issue.project + assert_equal issue.project.trackers.first, issue.tracker assert_equal 'New ticket on a given project', issue.subject assert_equal User.find_by_login('jsmith'), issue.author - assert_equal Project.find(2), issue.project assert_equal IssueStatus.find_by_name('Resolved'), issue.status assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') assert_equal '2010-01-01', issue.start_date.to_s @@ -73,6 +75,15 @@ class MailHandlerTest < ActiveSupport::TestCase assert_not_nil mail assert mail.subject.include?('New ticket on a given project') end + + def test_add_issue_with_default_tracker + # This email contains: 'Project: onlinestore' + issue = submit_email('ticket_on_given_project.eml', :issue => {:tracker => 'Support request'}) + assert issue.is_a?(Issue) + assert !issue.new_record? + issue.reload + assert_equal 'Support request', issue.tracker.name + end def test_add_issue_with_status # This email contains: 'Project: onlinestore' and 'Status: Resolved' @@ -290,6 +301,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal User.find_by_login('jsmith'), journal.user assert_equal Issue.find(2), journal.journalized assert_match /This is reply/, journal.notes + assert_equal 'Feature request', journal.issue.tracker.name end def test_add_issue_note_with_attribute_changes @@ -300,11 +312,12 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal User.find_by_login('jsmith'), journal.user assert_equal Issue.find(2), journal.journalized assert_match /This is reply/, journal.notes + assert_equal 'Feature request', journal.issue.tracker.name assert_equal IssueStatus.find_by_name("Resolved"), issue.status assert_equal '2010-01-01', issue.start_date.to_s assert_equal '2010-12-31', issue.due_date.to_s assert_equal User.find_by_login('jsmith'), issue.assigned_to - assert_equal 'Updated custom value', issue.custom_value_for(CustomField.find_by_name('Searchable field')).value + assert_equal "52.6", issue.custom_value_for(CustomField.find_by_name('Float field')).value end def test_add_issue_note_should_send_email_notification -- 2.39.5