Validate date filters values.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6264 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
db1bfbd018
commit
308a922d80
|
@ -176,6 +176,13 @@ class Query < ActiveRecord::Base
|
|||
errors.add(label_for(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*)?$/) }
|
||||
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}$/) }
|
||||
when ">t-", "<t-", "t-"
|
||||
errors.add(label_for(field), :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -170,6 +170,22 @@ class QueryTest < ActiveSupport::TestCase
|
|||
assert_include "CAST(custom_values.value AS decimal(60,3)) BETWEEN 30.0 AND 40.0", query.statement
|
||||
find_issues_with_query(query)
|
||||
end
|
||||
|
||||
def test_date_filter_should_not_accept_non_date_values
|
||||
query = Query.new(:name => '_')
|
||||
query.add_filter('created_on', '=', ['a'])
|
||||
|
||||
assert query.has_filter?('created_on')
|
||||
assert !query.valid?
|
||||
end
|
||||
|
||||
def test_relative_date_filter_should_not_accept_non_integer_values
|
||||
query = Query.new(:name => '_')
|
||||
query.add_filter('created_on', '>t-', ['a'])
|
||||
|
||||
assert query.has_filter?('created_on')
|
||||
assert !query.valid?
|
||||
end
|
||||
|
||||
def test_operator_date_equals
|
||||
query = Query.new(:name => '_')
|
||||
|
|
Loading…
Reference in New Issue