1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
20 class CustomValueTest < ActiveSupport::TestCase
21 fixtures :custom_fields, :custom_values, :users
23 def test_string_field_validation_with_blank_value
24 f = CustomField.new(:field_format => 'string')
25 v = CustomValue.new(:custom_field => f)
39 def test_string_field_validation_with_min_and_max_lengths
40 f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
41 v = CustomValue.new(:custom_field => f, :value => '')
51 def test_string_field_validation_with_regexp
52 f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
53 v = CustomValue.new(:custom_field => f, :value => '')
61 def test_date_field_validation
62 f = CustomField.new(:field_format => 'date')
63 v = CustomValue.new(:custom_field => f, :value => '')
67 v.value = '1975-07-14'
71 def test_list_field_validation
72 f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
73 v = CustomValue.new(:custom_field => f, :value => '')
81 def test_int_field_validation
82 f = CustomField.new(:field_format => 'int')
83 v = CustomValue.new(:custom_field => f, :value => '')
95 def test_float_field_validation
96 v = CustomValue.new(:customized => User.find(:first), :custom_field => UserCustomField.find_by_name('Money'))
107 def test_default_value
108 field = CustomField.find_by_default_value('Default string')
111 v = CustomValue.new(:custom_field => field)
112 assert_equal 'Default string', v.value
114 v = CustomValue.new(:custom_field => field, :value => 'Not empty')
115 assert_equal 'Not empty', v.value
118 def test_sti_polymorphic_association
119 # Rails uses top level sti class for polymorphic association. See #3978.
120 assert !User.find(4).custom_values.empty?
121 assert !CustomValue.find(2).customized.nil?