From 3cc0730f54b8ea0af54fd84c0f6c8318cd28d49f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 8 Jul 2012 12:30:57 +0000 Subject: [PATCH] Merged r9908 from trunk. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.0-stable@9954 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 c1eadcf0c..7be1bd855 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -178,6 +178,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') @@ -191,6 +205,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) -- 2.39.5