Project

General

Profile

Feature #16549 » 16549.diff

Felix Schäfer, 2014-04-07 22:24

View differences:

app/models/custom_field.rb
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?
escaped_possible_values = possible_values_options.collect {|keyword, id| Regexp.escape(keyword)}
keywords_re =
/
(?:\A|;\s*) # Start of the line or separator (;) and some whitespace
(#{escaped_possible_values.join("|")}) # one of the possible options
\s* # some whitespace before either the next separator (;) or the end
/xi
result = []
keyword.scan(keywords_re) do |match|
v = possible_values_options.detect {|text, id| text.downcase == match.first.downcase}
v = v.last if v.is_a?(Array)
result << v
end
result.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
test/fixtures/custom_fields.yml
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
custom_fields_013:
id: 13
name: Tester
type: IssueCustomField
field_format: user
multiple: true
test/fixtures/custom_fields_projects.yml
custom_fields_projects_001:
custom_field_id: 9
project_id: 1
custom_fields_projects_002:
custom_field_id: 12
project_id: 2
custom_fields_projects_003:
custom_field_id: 13
project_id: 2
test/fixtures/custom_fields_trackers.yml
custom_fields_trackers_009:
custom_field_id: 8
tracker_id: 3
custom_fields_trackers_010:
custom_field_id: 12
tracker_id: 1
custom_fields_trackers_011:
custom_field_id: 13
tracker_id: 1
test/fixtures/mail_handler/ticket_with_custom_fields.eml
category: Stock management
searchable field: Value for a custom field
Database: postgresql
OS: Mac OS X ;windows
Tester: John Smith; User misc
test/unit/mail_handler_test.rb
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_equal ["2", "8"], issue.custom_field_value(13)
assert !issue.description.match(/^searchable field:/i)
end
(2-2/5)