Revision 2395
Added by Jean-Philippe Lang over 16 years ago
sandbox/rails-2.2/app/models/custom_field.rb | ||
---|---|---|
48 | 48 |
|
49 | 49 |
def validate |
50 | 50 |
if self.field_format == "list" |
51 |
errors.add(:possible_values, :activerecord_error_blank) if self.possible_values.nil? || self.possible_values.empty?
|
|
52 |
errors.add(:possible_values, :activerecord_error_invalid) unless self.possible_values.is_a? Array
|
|
51 |
errors.add(:possible_values, :blank) if self.possible_values.nil? || self.possible_values.empty? |
|
52 |
errors.add(:possible_values, :invalid) unless self.possible_values.is_a? Array |
|
53 | 53 |
end |
54 | 54 |
|
55 | 55 |
# validate default value |
56 | 56 |
v = CustomValue.new(:custom_field => self.clone, :value => default_value, :customized => nil) |
57 | 57 |
v.custom_field.is_required = false |
58 |
errors.add(:default_value, :activerecord_error_invalid) unless v.valid?
|
|
58 |
errors.add(:default_value, :invalid) unless v.valid? |
|
59 | 59 |
end |
60 | 60 |
|
61 | 61 |
# Makes possible_values accept a multiline string |
sandbox/rails-2.2/app/models/custom_value.rb | ||
---|---|---|
45 | 45 |
protected |
46 | 46 |
def validate |
47 | 47 |
if value.blank? |
48 |
errors.add(:value, :activerecord_error_blank) if custom_field.is_required? and value.blank?
|
|
48 |
errors.add(:value, :blank) if custom_field.is_required? and value.blank? |
|
49 | 49 |
else |
50 |
errors.add(:value, :activerecord_error_invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp)
|
|
51 |
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length
|
|
52 |
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
|
|
50 |
errors.add(:value, :invalid) unless custom_field.regexp.blank? or value =~ Regexp.new(custom_field.regexp) |
|
51 |
errors.add(:value, :too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length |
|
52 |
errors.add(:value, :too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length |
|
53 | 53 |
|
54 | 54 |
# Format specific validations |
55 | 55 |
case custom_field.field_format |
56 | 56 |
when 'int' |
57 |
errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[+-]?\d+$/
|
|
57 |
errors.add(:value, :not_a_number) unless value =~ /^[+-]?\d+$/ |
|
58 | 58 |
when 'float' |
59 |
begin; Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
|
|
59 |
begin; Kernel.Float(value); rescue; errors.add(:value, :invalid) end |
|
60 | 60 |
when 'date' |
61 |
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/
|
|
61 |
errors.add(:value, :not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ |
|
62 | 62 |
when 'list' |
63 |
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include?(value)
|
|
63 |
errors.add(:value, :inclusion) unless custom_field.possible_values.include?(value) |
|
64 | 64 |
end |
65 | 65 |
end |
66 | 66 |
end |
sandbox/rails-2.2/app/models/issue.rb | ||
---|---|---|
129 | 129 |
|
130 | 130 |
def validate |
131 | 131 |
if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? |
132 |
errors.add :due_date, :activerecord_error_not_a_date
|
|
132 |
errors.add :due_date, :not_a_date |
|
133 | 133 |
end |
134 | 134 |
|
135 | 135 |
if self.due_date and self.start_date and self.due_date < self.start_date |
136 |
errors.add :due_date, :activerecord_error_greater_than_start_date
|
|
136 |
errors.add :due_date, :greater_than_start_date |
|
137 | 137 |
end |
138 | 138 |
|
139 | 139 |
if start_date && soonest_start && start_date < soonest_start |
140 |
errors.add :start_date, :activerecord_error_invalid
|
|
140 |
errors.add :start_date, :invalid |
|
141 | 141 |
end |
142 | 142 |
end |
143 | 143 |
|
144 | 144 |
def validate_on_create |
145 |
errors.add :tracker_id, :activerecord_error_invalid unless project.trackers.include?(tracker)
|
|
145 |
errors.add :tracker_id, :invalid unless project.trackers.include?(tracker) |
|
146 | 146 |
end |
147 | 147 |
|
148 | 148 |
def before_create |
sandbox/rails-2.2/app/models/issue_relation.rb | ||
---|---|---|
39 | 39 |
|
40 | 40 |
def validate |
41 | 41 |
if issue_from && issue_to |
42 |
errors.add :issue_to_id, :activerecord_error_invalid if issue_from_id == issue_to_id
|
|
43 |
errors.add :issue_to_id, :activerecord_error_not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations?
|
|
44 |
errors.add_to_base :activerecord_error_circular_dependency if issue_to.all_dependent_issues.include? issue_from
|
|
42 |
errors.add :issue_to_id, :invalid if issue_from_id == issue_to_id |
|
43 |
errors.add :issue_to_id, :not_same_project unless issue_from.project_id == issue_to.project_id || Setting.cross_project_issue_relations? |
|
44 |
errors.add_to_base :circular_dependency if issue_to.all_dependent_issues.include? issue_from |
|
45 | 45 |
end |
46 | 46 |
end |
47 | 47 |
|
sandbox/rails-2.2/app/models/member.rb | ||
---|---|---|
24 | 24 |
validates_uniqueness_of :user_id, :scope => :project_id |
25 | 25 |
|
26 | 26 |
def validate |
27 |
errors.add :role_id, :activerecord_error_invalid if role && !role.member?
|
|
27 |
errors.add :role_id, :invalid if role && !role.member? |
|
28 | 28 |
end |
29 | 29 |
|
30 | 30 |
def name |
sandbox/rails-2.2/app/models/project.rb | ||
---|---|---|
302 | 302 |
|
303 | 303 |
protected |
304 | 304 |
def validate |
305 |
errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
|
|
305 |
errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/) |
|
306 | 306 |
end |
307 | 307 |
|
308 | 308 |
private |
sandbox/rails-2.2/app/models/query.rb | ||
---|---|---|
123 | 123 |
|
124 | 124 |
def validate |
125 | 125 |
filters.each_key do |field| |
126 |
errors.add label_for(field), :activerecord_error_blank unless
|
|
126 |
errors.add label_for(field), :blank unless |
|
127 | 127 |
# filter requires one or more values |
128 | 128 |
(values_for(field) and !values_for(field).first.blank?) or |
129 | 129 |
# filter doesn't require any value |
sandbox/rails-2.2/app/models/time_entry.rb | ||
---|---|---|
32 | 32 |
:description => :comments |
33 | 33 |
|
34 | 34 |
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
35 |
validates_numericality_of :hours, :allow_nil => true, :message => :activerecord_error_invalid
|
|
35 |
validates_numericality_of :hours, :allow_nil => true, :message => :invalid |
|
36 | 36 |
validates_length_of :comments, :maximum => 255, :allow_nil => true |
37 | 37 |
|
38 | 38 |
def after_initialize |
sandbox/rails-2.2/app/models/version.rb | ||
---|---|---|
25 | 25 |
validates_presence_of :name |
26 | 26 |
validates_uniqueness_of :name, :scope => [:project_id] |
27 | 27 |
validates_length_of :name, :maximum => 60 |
28 |
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => 'activerecord_error_not_a_date', :allow_nil => true
|
|
28 |
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
|
|
29 | 29 |
|
30 | 30 |
def start_date |
31 | 31 |
effective_date |
sandbox/rails-2.2/app/models/watcher.rb | ||
---|---|---|
25 | 25 |
protected |
26 | 26 |
|
27 | 27 |
def validate |
28 |
errors.add :user_id, :activerecord_error_invalid unless user.nil? || user.active?
|
|
28 |
errors.add :user_id, :invalid unless user.nil? || user.active? |
|
29 | 29 |
end |
30 | 30 |
end |
sandbox/rails-2.2/test/functional/issues_controller_test.rb | ||
---|---|---|
445 | 445 |
assert_template 'new' |
446 | 446 |
issue = assigns(:issue) |
447 | 447 |
assert_not_nil issue |
448 |
assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
|
|
448 |
assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
|
|
449 | 449 |
end |
450 | 450 |
|
451 | 451 |
def test_post_new_with_watchers |
sandbox/rails-2.2/test/unit/version_test.rb | ||
---|---|---|
31 | 31 |
def test_invalid_effective_date_validation |
32 | 32 |
v = Version.new(:project => Project.find(1), :name => '1.1', :effective_date => '99999-01-01') |
33 | 33 |
assert !v.save |
34 |
assert_equal 'activerecord_error_not_a_date', v.errors.on(:effective_date)
|
|
34 |
assert_equal I18n.translate('activerecord.errors.messages.not_a_date'), v.errors.on(:effective_date)
|
|
35 | 35 |
end |
36 | 36 |
|
37 | 37 |
def test_progress_should_be_0_with_no_assigned_issues |
Also available in: Unified diff
Fixes error messages translation.