Fixed: Can't filter for negative numeric custom field (#11307).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9908 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-04 18:50:09 +00:00
parent 86617fc437
commit d00ba6d2bb
2 changed files with 30 additions and 2 deletions

View File

@ -174,9 +174,9 @@ class Query < ActiveRecord::Base
if values_for(field)
case type_for(field)
when :integer
add_filter_error(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
add_filter_error(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 "=", ">=", "<=", "><"

View File

@ -179,6 +179,20 @@ class QueryTest < ActiveSupport::TestCase
assert_equal 2, issues.first.id
end
def test_operator_is_on_integer_custom_field_should_accept_negative_value
f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true)
CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7')
CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12')
CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
query = Query.new(:name => '_')
query.add_filter("cf_#{f.id}", '=', ['-12'])
assert query.valid?
issues = find_issues_with_query(query)
assert_equal 1, issues.size
assert_equal 2, issues.first.id
end
def test_operator_is_on_float_custom_field
f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true)
CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3')
@ -192,6 +206,20 @@ class QueryTest < ActiveSupport::TestCase
assert_equal 2, issues.first.id
end
def test_operator_is_on_float_custom_field_should_accept_negative_value
f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true)
CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3')
CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12.7')
CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
query = Query.new(:name => '_')
query.add_filter("cf_#{f.id}", '=', ['-12.7'])
assert query.valid?
issues = find_issues_with_query(query)
assert_equal 1, issues.size
assert_equal 2, issues.first.id
end
def test_operator_is_on_multi_list_custom_field
f = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true,
:possible_values => ['value1', 'value2', 'value3'], :multiple => true)