]> source.dussan.org Git - redmine.git/commitdiff
Fixed: Custom fields of type version not proper handled in receiving e-mails (#11571).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 6 Aug 2012 21:16:19 +0000 (21:16 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 6 Aug 2012 21:16:19 +0000 (21:16 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10157 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_field.rb
app/models/mail_handler.rb
test/unit/mail_handler_test.rb

index 3373fb8d89f87db57c51be295422584f48bf9ff8..83e0fa254981bc2e7bbfc459c507e2d4dcacf0a2 100644 (file)
@@ -126,6 +126,16 @@ class CustomField < ActiveRecord::Base
     casted
   end
 
+  def value_from_keyword(keyword, customized)
+    possible_values_options = possible_values_options(customized)
+    if possible_values_options.present?
+      keyword = keyword.to_s.downcase
+      possible_values_options.detect {|text, id| text.downcase == keyword}.try(:last)
+    else
+      keyword
+    end
+  end
   # Returns a ORDER BY clause that can used to sort customized
   # objects by their value of the custom field.
   # Returns nil if the custom field can not be used for sorting.
index 4b86221f6f5b08a9c2fea721139e45992b01776b..01cf8d74f4dd522a8739c73d70d5a4fb857ee499 100644 (file)
@@ -342,8 +342,8 @@ class MailHandler < ActionMailer::Base
   # Returns a Hash of issue custom field values extracted from keywords in the email body
   def custom_field_values_from_keywords(customized)
     customized.custom_field_values.inject({}) do |h, v|
-      if value = get_keyword(v.custom_field.name, :override => true)
-        h[v.custom_field.id.to_s] = value
+      if keyword = get_keyword(v.custom_field.name, :override => true)
+        h[v.custom_field.id.to_s] = v.custom_field.value_from_keyword(keyword, customized)
       end
       h
     end
index ce21f3ceadca1d7fc02f116c1150953f422bc8ec..32646fcdddfa146ab17ff300046a96f85cf383ec 100644 (file)
@@ -182,6 +182,18 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert !issue.description.match(/^searchable field:/i)
   end
 
+  def test_add_issue_with_version_custom_fields
+    field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
+
+    issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'ecookbook'}) do |email|
+      email << "Affected version: 1.0\n"
+    end
+    assert issue.is_a?(Issue)
+    assert !issue.new_record?
+    issue.reload
+    assert_equal '2', issue.custom_field_value(field)
+  end
+
   def test_add_issue_with_cc
     issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
     assert issue.is_a?(Issue)