Accept custom field format added at runtime (#15277).
Patch by Boris Bera. git-svn-id: http://svn.redmine.org/redmine/trunk@12248 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
1871378648
commit
10e29f2223
|
@ -26,7 +26,7 @@ class CustomField < ActiveRecord::Base
|
||||||
validates_presence_of :name, :field_format
|
validates_presence_of :name, :field_format
|
||||||
validates_uniqueness_of :name, :scope => :type
|
validates_uniqueness_of :name, :scope => :type
|
||||||
validates_length_of :name, :maximum => 30
|
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
|
validate :validate_custom_field
|
||||||
|
|
||||||
before_validation :set_searchable
|
before_validation :set_searchable
|
||||||
|
|
|
@ -70,6 +70,13 @@ module Redmine
|
||||||
@@available[custom_field_format.name] = custom_field_format unless @@available.keys.include?(custom_field_format.name)
|
@@available[custom_field_format.name] = custom_field_format unless @@available.keys.include?(custom_field_format.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete(format)
|
||||||
|
if format.is_a?(Redmine::CustomFieldFormat)
|
||||||
|
format = format.name
|
||||||
|
end
|
||||||
|
@@available.delete(format)
|
||||||
|
end
|
||||||
|
|
||||||
def available_formats
|
def available_formats
|
||||||
@@available.keys
|
@@available.keys
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,6 +57,20 @@ class CustomFieldTest < ActiveSupport::TestCase
|
||||||
assert field.valid?
|
assert field.valid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_field_format_should_be_validated
|
||||||
|
field = CustomField.new(:name => 'Test', :field_format => 'foo')
|
||||||
|
assert !field.valid?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_field_format_validation_should_accept_formats_added_at_runtime
|
||||||
|
Redmine::CustomFieldFormat.register 'foobar'
|
||||||
|
|
||||||
|
field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar')
|
||||||
|
assert field.valid?, 'field should be valid'
|
||||||
|
ensure
|
||||||
|
Redmine::CustomFieldFormat.delete 'foobar'
|
||||||
|
end
|
||||||
|
|
||||||
def test_should_not_change_field_format_of_existing_custom_field
|
def test_should_not_change_field_format_of_existing_custom_field
|
||||||
field = CustomField.find(1)
|
field = CustomField.find(1)
|
||||||
field.field_format = 'int'
|
field.field_format = 'int'
|
||||||
|
|
Loading…
Reference in New Issue