Project

General

Profile

Feature #16549 » 16549.diff

Felix Schäfer, 2014-04-07 14:33

View differences:

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? && field_format == 'list'
147
        keywords_re =
148
          /
149
            (?:\A|;\s*)                                                            # Start of the line or separator (;) and some whitespace
150
            (#{possible_values_options.collect {|v| Regexp.escape(v)}.join("|")})  # one of the possible options
151
            \s*                                                                    # some whitespace before either the next separator (;) or the end
152
          /x
153
        result = keyword.scan(keywords_re).flatten.uniq
154
      elsif v = possible_values_options.detect {|text, id| text.downcase == keyword.downcase}
147 155
        if v.is_a?(Array)
148
          v.last
156
          result = v.last
149 157
        else
150
          v
158
          result = v
151 159
        end
152 160
      end
153 161
    else
154
      keyword
162
      result = keyword
155 163
    end
164
    result
156 165
  end
157 166

  
158 167
  # 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
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
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
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
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)
183 184
    assert !issue.description.match(/^searchable field:/i)
184 185
  end
185 186

  
(1-1/5)