Patch #15277 ยป custom_field_format_validation_fix.patch
test/unit/custom_field_test.rb | ||
---|---|---|
279 | 279 | |
280 | 280 |
assert_equal [fields[0]], CustomField.visible(User.anonymous).order("id").to_a |
281 | 281 |
end |
282 | ||
283 |
def test_field_format_validation_includes_formats_added_at_runtime |
|
284 |
foobar_field_format_klass = Class.new(Redmine::CustomFieldFormat) |
|
285 |
Redmine::CustomFieldFormat.map do |type| |
|
286 |
type.register foobar_field_format_klass.new('foobar', :label => 'Foobar', :order => 1.0) |
|
287 |
end |
|
288 | ||
289 |
field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar') |
|
290 | ||
291 |
assert field.valid?, 'field should be valid' |
|
292 |
end |
|
282 | 293 |
end |
283 |
- |
app/models/custom_field.rb | ||
---|---|---|
26 | 26 |
validates_presence_of :name, :field_format |
27 | 27 |
validates_uniqueness_of :name, :scope => :type |
28 | 28 |
validates_length_of :name, :maximum => 30 |
29 |
validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
|
29 |
validates_inclusion_of :field_format, :in => Proc.new { Redmine::CustomFieldFormat.available_formats }
|
|
30 | 30 |
validate :validate_custom_field |
31 | 31 | |
32 | 32 |
before_validation :set_searchable |