diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 48ef2c7..31e647e 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -142,17 +142,26 @@ class CustomField < ActiveRecord::Base def value_from_keyword(keyword, customized) possible_values_options = possible_values_options(customized) if possible_values_options.present? - keyword = keyword.to_s.downcase - if v = possible_values_options.detect {|text, id| text.downcase == keyword} + keyword = keyword.to_s + if multiple? && field_format == 'list' + keywords_re = + / + (?:\A|;\s*) # Start of the line or separator (;) and some whitespace + (#{possible_values_options.collect {|v| Regexp.escape(v)}.join("|")}) # one of the possible options + \s* # some whitespace before either the next separator (;) or the end + /x + result = keyword.scan(keywords_re).flatten.uniq + elsif v = possible_values_options.detect {|text, id| text.downcase == keyword.downcase} if v.is_a?(Array) - v.last + result = v.last else - v + result = v end end else - keyword + result = keyword end + result end # Returns a ORDER BY clause that can used to sort customized diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml index 510e3a4..dc65eef 100644 --- a/test/fixtures/custom_fields.yml +++ b/test/fixtures/custom_fields.yml @@ -145,3 +145,13 @@ custom_fields_011: SGXDqWzDp2prc2Tigqw2NTTDuQ== - Other value field_format: list +custom_fields_012: + id: 12 + name: OS + type: IssueCustomField + possible_values: + - Linux + - Windows + - Mac OS X + field_format: list + multiple: true diff --git a/test/fixtures/custom_fields_projects.yml b/test/fixtures/custom_fields_projects.yml index bb9788b..265a360 100644 --- a/test/fixtures/custom_fields_projects.yml +++ b/test/fixtures/custom_fields_projects.yml @@ -2,3 +2,6 @@ custom_fields_projects_001: custom_field_id: 9 project_id: 1 +custom_fields_projects_002: + custom_field_id: 12 + project_id: 2 diff --git a/test/fixtures/custom_fields_trackers.yml b/test/fixtures/custom_fields_trackers.yml index 2a7a073..e2670e7 100644 --- a/test/fixtures/custom_fields_trackers.yml +++ b/test/fixtures/custom_fields_trackers.yml @@ -26,3 +26,6 @@ custom_fields_trackers_008: custom_fields_trackers_009: custom_field_id: 8 tracker_id: 3 +custom_fields_trackers_010: + custom_field_id: 12 + tracker_id: 1 diff --git a/test/fixtures/mail_handler/ticket_with_custom_fields.eml b/test/fixtures/mail_handler/ticket_with_custom_fields.eml index 58dde7e..72aeb56 100644 --- a/test/fixtures/mail_handler/ticket_with_custom_fields.eml +++ b/test/fixtures/mail_handler/ticket_with_custom_fields.eml @@ -40,3 +40,4 @@ pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. category: Stock management searchable field: Value for a custom field Database: postgresql +OS: Mac OS X ;Windows diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 1e0e684..987e120 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -180,6 +180,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal 'New ticket with custom field values', issue.subject assert_equal 'PostgreSQL', issue.custom_field_value(1) assert_equal 'Value for a custom field', issue.custom_field_value(2) + assert_equal ["Mac OS X", "Windows"], issue.custom_field_value(12) assert !issue.description.match(/^searchable field:/i) end