##// END OF EJS Templates
Accept custom field format added at runtime (#15277)....
Jean-Philippe Lang -
r12018:10e29f22239e
parent child
Show More
@@ -26,7 +26,7 class CustomField < ActiveRecord::Base
26 validates_presence_of :name, :field_format
26 validates_presence_of :name, :field_format
27 validates_uniqueness_of :name, :scope => :type
27 validates_uniqueness_of :name, :scope => :type
28 validates_length_of :name, :maximum => 30
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 validate :validate_custom_field
30 validate :validate_custom_field
31
31
32 before_validation :set_searchable
32 before_validation :set_searchable
@@ -70,6 +70,13 module Redmine
70 @@available[custom_field_format.name] = custom_field_format unless @@available.keys.include?(custom_field_format.name)
70 @@available[custom_field_format.name] = custom_field_format unless @@available.keys.include?(custom_field_format.name)
71 end
71 end
72
72
73 def delete(format)
74 if format.is_a?(Redmine::CustomFieldFormat)
75 format = format.name
76 end
77 @@available.delete(format)
78 end
79
73 def available_formats
80 def available_formats
74 @@available.keys
81 @@available.keys
75 end
82 end
@@ -57,6 +57,20 class CustomFieldTest < ActiveSupport::TestCase
57 assert field.valid?
57 assert field.valid?
58 end
58 end
59
59
60 def test_field_format_should_be_validated
61 field = CustomField.new(:name => 'Test', :field_format => 'foo')
62 assert !field.valid?
63 end
64
65 def test_field_format_validation_should_accept_formats_added_at_runtime
66 Redmine::CustomFieldFormat.register 'foobar'
67
68 field = CustomField.new(:name => 'Some Custom Field', :field_format => 'foobar')
69 assert field.valid?, 'field should be valid'
70 ensure
71 Redmine::CustomFieldFormat.delete 'foobar'
72 end
73
60 def test_should_not_change_field_format_of_existing_custom_field
74 def test_should_not_change_field_format_of_existing_custom_field
61 field = CustomField.find(1)
75 field = CustomField.find(1)
62 field.field_format = 'int'
76 field.field_format = 'int'
General Comments 0
You need to be logged in to leave comments. Login now