]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Tracker reset to default when replying to an issue email (#7197).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 29 Dec 2010 17:36:01 +0000 (17:36 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 29 Dec 2010 17:36:01 +0000 (17:36 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4575 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/fixtures/mail_handler/ticket_reply_with_status.eml
test/unit/mail_handler_test.rb

index 00010059f829a8aa1ee33416ca95947d19dea5c3..4b6b4a4027951aff08eb091b1cf3882b45a60aa1 100644 (file)
@@ -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
index 66ca730acf27a4b7eea7eb3d2bcac6c87869ec0b..52beda37b512c18f4d13972b8d10f3a70a4acdbd 100644 (file)
@@ -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;
index feb09e12e4bc59583133a783ac368834721f8ffb..df22bddc8266d26f9a7bbbe58f80a40e0ae581fd 100644 (file)
@@ -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