From d00ba6d2bb7cd76edf2cd1e75584f9dfd336ea72 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 4 Jul 2012 18:50:09 +0000 Subject: [PATCH] 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 --- app/models/query.rb | 4 ++-- test/unit/query_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/app/models/query.rb b/app/models/query.rb index b66b091f7..de5fa4c16 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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 "=", ">=", "<=", "><" diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index cba83b7c0..61f7a4b01 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -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)