From 852dee37ec7b32106376bf14b7563983d37d5204 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 26 Dec 2011 13:34:50 +0000 Subject: [PATCH] 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 --- app/models/query.rb | 17 +++++++++++------ test/unit/query_test.rb | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/models/query.rb b/app/models/query.rb index 262a738d1..5d8640199 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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-", " '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 diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 1980018a5..37a8face9 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -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