Patch #15277 ยป custom_field_format_validation_fix.patch
| test/unit/custom_field_test.rb | ||
|---|---|---|
|
assert_equal [fields[0]], CustomField.visible(User.anonymous).order("id").to_a
|
||
|
end
|
||
|
def test_field_format_validation_includes_formats_added_at_runtime
|
||
|
foobar_field_format_klass = Class.new(Redmine::CustomFieldFormat)
|
||
|
Redmine::CustomFieldFormat.map do |type|
|
||
|
type.register foobar_field_format_klass.new('foobar', :label => 'Foobar', :order => 1.0)
|
||
|
end
|
||
|
field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar')
|
||
|
assert field.valid?, 'field should be valid'
|
||
|
end
|
||
|
end
|
||
|
-
|
||
| app/models/custom_field.rb | ||
|---|---|---|
|
validates_presence_of :name, :field_format
|
||
|
validates_uniqueness_of :name, :scope => :type
|
||
|
validates_length_of :name, :maximum => 30
|
||
|
validates_inclusion_of :field_format, :in => Redmine::CustomFieldFormat.available_formats
|
||
|
validates_inclusion_of :field_format, :in => Proc.new { Redmine::CustomFieldFormat.available_formats }
|
||
|
validate :validate_custom_field
|
||
|
before_validation :set_searchable
|
||