rm13385-do_not_set_searchable_for_user_and_version_cf-trunk_r12224.diff

Mischa The Evil, 2013-10-18 04:37

Download (1.96 KB)

View differences:

test/unit/custom_field_test.rb (working copy)
227 227
    assert_equal 2, item_with_multiple_values.custom_field_value(other).size
228 228
  end
229 229

  
230
  def test_searchable_should_be_set_for_string_text_list_custom_field_formats_only
231
    Redmine::CustomFieldFormat.available_formats.each do |format|
232
      if format == 'list'
233
        field = CustomField.new(:name => 'test_searchable_list_cf', :field_format => format, :possible_values => ['v1', 'v2'])
234
      else
235
        field = CustomField.new(:name => 'test_searchable_' + format + '_cf', :field_format => format)
236
      end
237
      field.searchable = true
238
      assert field.save
239
      case format
240
        when 'string', 'text', 'list'
241
          assert_equal true, field.searchable, format + " custom field isn't searchable while it should"
242
        when 'int', 'float', 'date', 'bool', 'user', 'version'
243
          assert_equal false, field.searchable, format + " custom field is searchable while it shouldn't"
244
      end
245
    end
246
  end
247

  
230 248
  def test_value_class_should_return_the_class_used_for_fields_values
231 249
    assert_equal User, CustomField.new(:field_format => 'user').value_class
232 250
    assert_equal Version, CustomField.new(:field_format => 'version').value_class
app/models/custom_field.rb (working copy)
64 64

  
65 65
  def set_searchable
66 66
    # make sure these fields are not searchable
67
    self.searchable = false if %w(int float date bool).include?(field_format)
67
    self.searchable = false if %w(int float date bool user version).include?(field_format)
68 68
    # make sure only these fields can have multiple values
69 69
    self.multiple = false unless %w(list user version).include?(field_format)
70 70
    true