summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-10 18:34:49 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-10 18:34:49 +0000
commitc25a79a61b1ee254bbfea6a55a56ce98c713da81 (patch)
treebb4c7e777cc7ee88ddc3cf326d3bd93e7c52a468
parentbedbb166b7e7c68e40f7e0e23a17ae2dc3783811 (diff)
downloadredmine-c25a79a61b1ee254bbfea6a55a56ce98c713da81.tar.gz
redmine-c25a79a61b1ee254bbfea6a55a56ce98c713da81.zip
Keep invalid values and add validation error message.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6229 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/query.rb10
-rw-r--r--test/unit/query_test.rb1
2 files changed, 5 insertions, 6 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index b9be08519..411f0d235 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -170,6 +170,10 @@ class Query < ActiveRecord::Base
def validate
filters.each_key do |field|
+ if type_for(field) == :integer && values_for(field)
+ errors.add label_for(field), :invalid if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d+)?$/) }
+ end
+
errors.add label_for(field), :blank unless
# filter requires one or more values
(values_for(field) and !values_for(field).first.blank?) or
@@ -278,11 +282,7 @@ class Query < ActiveRecord::Base
# allowed_values = values & ([""] + (filter_options[:values] || []).collect {|val| val[1]})
# filters[field] = {:operator => operator, :values => allowed_values } if (allowed_values.first and !allowed_values.first.empty?) or ["o", "c", "!*", "*", "t"].include? operator
#end
- values ||= ['']
- if filter_options[:type] == :integer
- values = values.select {|v| v.blank? || v.match(/^\d+(\.\d+)?$/) }
- end
- filters[field] = {:operator => operator, :values => values }
+ filters[field] = {:operator => operator, :values => (values || [''])}
end
end
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 95308ee0c..ef48a8ad8 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -106,7 +106,6 @@ class QueryTest < ActiveSupport::TestCase
query.add_filter('estimated_hours', '=', ['a'])
assert query.has_filter?('estimated_hours')
- assert query.values_for('estimated_hours').empty?
assert !query.valid?
end