Feature #16549 » set_multiple_values_via_email.diff
lib/redmine/field_format.rb | ||
---|---|---|
144 | 144 |
possible_values_options = possible_values_options(custom_field, object) |
145 | 145 |
if possible_values_options.present? |
146 | 146 |
keyword = keyword.to_s |
147 |
if v = possible_values_options.detect {|text, id| keyword.casecmp(text) == 0} |
|
147 |
if custom_field.multiple? |
|
148 |
possible_options = possible_values_options.collect {|option, value| option} |
|
149 |
keywords_re = |
|
150 |
/ |
|
151 |
(?:\A|,\s*) # Start of the line or separator (,) and some whitespace |
|
152 |
(#{Regexp.union(possible_options).source}) # one of the possible options |
|
153 |
\s* # some whitespace before either the next separator (,) or the end |
|
154 |
/xi |
|
155 |
result = [] |
|
156 |
keyword.scan(keywords_re) do |match| |
|
157 |
v = possible_values_options.detect {|text, id| match.first.casecmp(text) == 0} |
|
158 |
v = v.last if v.is_a?(Array) |
|
159 |
result << v |
|
160 |
end |
|
161 |
result = result.uniq |
|
162 |
elsif v = possible_values_options.detect {|text, id| keyword.casecmp(text) == 0} |
|
148 | 163 |
if v.is_a?(Array) |
149 |
v.last |
|
164 |
result = v.last
|
|
150 | 165 |
else |
151 |
v |
|
166 |
result = v
|
|
152 | 167 |
end |
153 | 168 |
end |
154 | 169 |
else |
155 |
keyword |
|
170 |
result = keyword
|
|
156 | 171 |
end |
172 |
result |
|
157 | 173 |
end |
158 | 174 | |
159 | 175 |
# Returns the validation errors for custom_field |
test/fixtures/custom_fields.yml | ||
---|---|---|
146 | 146 |
- Other value |
147 | 147 |
field_format: list |
148 | 148 |
position: 1 |
149 |
custom_fields_012: |
|
150 |
id: 12 |
|
151 |
name: OS |
|
152 |
type: IssueCustomField |
|
153 |
possible_values: |
|
154 |
- Linux |
|
155 |
- Windows |
|
156 |
- Mac OS X |
|
157 |
field_format: list |
|
158 |
multiple: true |
|
159 |
position: 1 |
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 |
test/fixtures/custom_fields_trackers.yml | ||
---|---|---|
29 | 29 |
custom_fields_trackers_010: |
30 | 30 |
custom_field_id: 9 |
31 | 31 |
tracker_id: 1 |
32 |
custom_fields_trackers_011: |
|
33 |
custom_field_id: 12 |
|
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 |
test/unit/mail_handler_test.rb | ||
---|---|---|
233 | 233 | |
234 | 234 |
def test_add_issue_with_custom_fields |
235 | 235 |
issue = submit_email('ticket_with_custom_fields.eml', |
236 |
:issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable_field'] |
|
236 |
:issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable_field', 'OS']
|
|
237 | 237 |
) |
238 | 238 |
assert issue.is_a?(Issue) |
239 | 239 |
assert !issue.new_record? |
... | ... | |
241 | 241 |
assert_equal 'New ticket with custom field values', issue.subject |
242 | 242 |
assert_equal 'PostgreSQL', issue.custom_field_value(1) |
243 | 243 |
assert_equal 'Value for a custom field', issue.custom_field_value(2) |
244 |
assert_equal ["Mac OS X", "Windows"], issue.custom_field_value(12).sort |
|
244 | 245 |
assert !issue.description.match(/^searchable field:/i) |
245 | 246 |
end |
246 | 247 |
- « Previous
- 1
- …
- 3
- 4
- 5
- Next »