summaryrefslogtreecommitdiffstats
path: root/app/models/custom_value.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-28 11:16:58 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-28 11:16:58 +0000
commit83e7ee6729cd0207219719556b3e2aed0a33f360 (patch)
tree8fa089641bcaa6baec5aee080431e4e38c731a51 /app/models/custom_value.rb
parentd4d27bd2d8b57e5d2597b75fbb7b963b6c3e37f7 (diff)
downloadredmine-83e7ee6729cd0207219719556b3e2aed0a33f360.tar.gz
redmine-83e7ee6729cd0207219719556b3e2aed0a33f360.zip
Extracts custom field values validation from CustomValue so that they can be validated globally from the customized object (#1189).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8717 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/custom_value.rb')
-rw-r--r--app/models/custom_value.rb27
1 files changed, 1 insertions, 26 deletions
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 6cb4853f9..89d3709cc 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -1,5 +1,5 @@
# Redmine - project management software
-# Copyright (C) 2006-2011 Jean-Philippe Lang
+# Copyright (C) 2006-2012 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
@@ -19,8 +19,6 @@ class CustomValue < ActiveRecord::Base
belongs_to :custom_field
belongs_to :customized, :polymorphic => true
- validate :validate_custom_value
-
def initialize(attributes=nil, *args)
super
if new_record? && custom_field && (customized_type.blank? || (customized && customized.new_record?))
@@ -48,27 +46,4 @@ class CustomValue < ActiveRecord::Base
def to_s
value.to_s
end
-
-protected
- def validate_custom_value
- if value.blank?
- errors.add(:value, :blank) if custom_field.is_required? and value.blank?
- else
- errors.add(:value, :invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
- errors.add(:value, :too_short, :count => custom_field.min_length) if custom_field.min_length > 0 and value.length < custom_field.min_length
- errors.add(:value, :too_long, :count => custom_field.max_length) if custom_field.max_length > 0 and value.length > custom_field.max_length
-
- # Format specific validations
- case custom_field.field_format
- when 'int'
- errors.add(:value, :not_a_number) unless value =~ /^[+-]?\d+$/
- when 'float'
- begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end
- when 'date'
- errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ && begin; value.to_date; rescue; false end
- when 'list'
- errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value)
- end
- end
- end
end