Feature #16549 » 16549.diff
app/models/custom_field.rb | ||
---|---|---|
142 | 142 |
def value_from_keyword(keyword, customized) |
143 | 143 |
possible_values_options = possible_values_options(customized) |
144 | 144 |
if possible_values_options.present? |
145 |
keyword = keyword.to_s.downcase |
|
146 |
if v = possible_values_options.detect {|text, id| text.downcase == keyword} |
|
145 |
keyword = keyword.to_s |
|
146 |
if multiple? |
|
147 |
escaped_possible_values = possible_values_options.collect {|keyword, id| Regexp.escape(keyword)} |
|
148 |
keywords_re = |
|
149 |
/ |
|
150 |
(?:\A|;\s*) # Start of the line or separator (;) and some whitespace |
|
151 |
(#{escaped_possible_values.join("|")}) # one of the possible options |
|
152 |
\s* # some whitespace before either the next separator (;) or the end |
|
153 |
/xi |
|
154 |
result = [] |
|
155 |
keyword.scan(keywords_re) do |match| |
|
156 |
v = possible_values_options.detect {|text, id| text.downcase == match.first.downcase} |
|
157 |
v = v.last if v.is_a?(Array) |
|
158 |
result << v |
|
159 |
end |
|
160 |
result.uniq |
|
161 |
elsif v = possible_values_options.detect {|text, id| text.downcase == keyword.downcase} |
|
147 | 162 |
if v.is_a?(Array) |
148 |
v.last |
|
163 |
result = v.last
|
|
149 | 164 |
else |
150 |
v |
|
165 |
result = v
|
|
151 | 166 |
end |
152 | 167 |
end |
153 | 168 |
else |
154 |
keyword |
|
169 |
result = keyword
|
|
155 | 170 |
end |
171 |
result |
|
156 | 172 |
end |
157 | 173 | |
158 | 174 |
# Returns a ORDER BY clause that can used to sort customized |
test/fixtures/custom_fields.yml | ||
---|---|---|
145 | 145 |
SGXDqWzDp2prc2Tigqw2NTTDuQ== |
146 | 146 |
- Other value |
147 | 147 |
field_format: list |
148 |
custom_fields_012: |
|
149 |
id: 12 |
|
150 |
name: OS |
|
151 |
type: IssueCustomField |
|
152 |
possible_values: |
|
153 |
- Linux |
|
154 |
- Windows |
|
155 |
- Mac OS X |
|
156 |
field_format: list |
|
157 |
multiple: true |
|
158 |
custom_fields_013: |
|
159 |
id: 13 |
|
160 |
name: Tester |
|
161 |
type: IssueCustomField |
|
162 |
field_format: user |
|
163 |
multiple: true |
test/fixtures/custom_fields_projects.yml | ||
---|---|---|
2 | 2 |
custom_fields_projects_001: |
3 | 3 |
custom_field_id: 9 |
4 | 4 |
project_id: 1 |
5 |
custom_fields_projects_002: |
|
6 |
custom_field_id: 12 |
|
7 |
project_id: 2 |
|
8 |
custom_fields_projects_003: |
|
9 |
custom_field_id: 13 |
|
10 |
project_id: 2 |
test/fixtures/custom_fields_trackers.yml | ||
---|---|---|
26 | 26 |
custom_fields_trackers_009: |
27 | 27 |
custom_field_id: 8 |
28 | 28 |
tracker_id: 3 |
29 |
custom_fields_trackers_010: |
|
30 |
custom_field_id: 12 |
|
31 |
tracker_id: 1 |
|
32 |
custom_fields_trackers_011: |
|
33 |
custom_field_id: 13 |
|
34 |
tracker_id: 1 |
test/fixtures/mail_handler/ticket_with_custom_fields.eml | ||
---|---|---|
40 | 40 |
category: Stock management |
41 | 41 |
searchable field: Value for a custom field |
42 | 42 |
Database: postgresql |
43 |
OS: Mac OS X ;windows |
|
44 |
Tester: John Smith; User misc |
test/unit/mail_handler_test.rb | ||
---|---|---|
180 | 180 |
assert_equal 'New ticket with custom field values', issue.subject |
181 | 181 |
assert_equal 'PostgreSQL', issue.custom_field_value(1) |
182 | 182 |
assert_equal 'Value for a custom field', issue.custom_field_value(2) |
183 |
assert_equal ["Mac OS X", "Windows"], issue.custom_field_value(12) |
|
184 |
assert_equal ["2", "8"], issue.custom_field_value(13) |
|
183 | 185 |
assert !issue.description.match(/^searchable field:/i) |
184 | 186 |
end |
185 | 187 |