errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array
end
+ if regexp.present?
+ begin
+ Regexp.new(regexp)
+ rescue
+ errors.add(:regexp, :invalid)
+ end
+ end
+
# validate default value
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil)
v.custom_field.is_required = false
-# redMine - project management software
-# Copyright (C) 2006-2007 Jean-Philippe Lang
+# Redmine - project management software
+# Copyright (C) 2006-2011 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
assert field.save
end
+ def test_regexp_validation
+ field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9')
+ assert !field.save
+ assert_equal I18n.t('activerecord.errors.messages.invalid'), field.errors.on(:regexp)
+
+ field.regexp = '[a-z0-9]'
+ assert field.save
+ end
+
def test_possible_values_should_accept_an_array
field = CustomField.new
field.possible_values = ["One value", ""]