@@ -42,6 +42,14 class CustomField < ActiveRecord::Base | |||
|
42 | 42 | errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | if regexp.present? | |
|
46 | begin | |
|
47 | Regexp.new(regexp) | |
|
48 | rescue | |
|
49 | errors.add(:regexp, :invalid) | |
|
50 | end | |
|
51 | end | |
|
52 | ||
|
45 | 53 | # validate default value |
|
46 | 54 | v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil) |
|
47 | 55 | v.custom_field.is_required = false |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -25,6 +25,15 class CustomFieldTest < ActiveSupport::TestCase | |||
|
25 | 25 | assert field.save |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | def test_regexp_validation | |
|
29 | field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9') | |
|
30 | assert !field.save | |
|
31 | assert_equal I18n.t('activerecord.errors.messages.invalid'), field.errors.on(:regexp) | |
|
32 | ||
|
33 | field.regexp = '[a-z0-9]' | |
|
34 | assert field.save | |
|
35 | end | |
|
36 | ||
|
28 | 37 | def test_possible_values_should_accept_an_array |
|
29 | 38 | field = CustomField.new |
|
30 | 39 | field.possible_values = ["One value", ""] |
General Comments 0
You need to be logged in to leave comments.
Login now