Do not add errors on attributes on fake attributes.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8388 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-26 13:34:50 +00:00
parent a76045d792
commit 852dee37ec
2 changed files with 12 additions and 7 deletions

View File

@ -174,20 +174,20 @@ class Query < ActiveRecord::Base
if values_for(field)
case type_for(field)
when :integer
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
when :float
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) }
when :date, :date_past
case operator_for(field)
when "=", ">=", "<=", "><"
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && (!v.match(/^\d{4}-\d{2}-\d{2}$/) || (Date.parse(v) rescue nil).nil?) }
when ">t-", "<t-", "t-"
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
end
end
end
errors.add label_for(field), :blank unless
add_filter_error(field, :blank) unless
# filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or
# filter doesn't require any value
@ -195,6 +195,11 @@ class Query < ActiveRecord::Base
end if filters
end
def add_filter_error(field, message)
m = label_for(field) + " " + l(message, :scope => 'activerecord.errors.messages')
errors.add(:base, m)
end
# Returns true if the query is visible to +user+ or the current user.
def visible?(user=User.current)
(project.nil? || user.allowed_to?(:view_issues, project)) && (self.is_public? || self.user_id == user.id)
@ -347,7 +352,7 @@ class Query < ActiveRecord::Base
def label_for(field)
label = available_filters[field][:name] if available_filters.has_key?(field)
label ||= field.gsub(/\_id$/, "")
label ||= l("field_#{field.to_s.gsub(/_id$/, '')}", :default => field)
end
def available_columns

View File

@ -614,7 +614,7 @@ class QueryTest < ActiveSupport::TestCase
def test_label_for
q = Query.new
assert_equal 'assigned_to', q.label_for('assigned_to_id')
assert_equal 'Assignee', q.label_for('assigned_to_id')
end
def test_editable_by