From 62f9b56c1e6973f204ed289f96136db6a74b8b5b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 31 Aug 2016 16:55:53 +0000 Subject: [PATCH] Merged r15751 (#23596). git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15770 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue_query.rb | 13 +++++++++---- test/unit/query_test.rb | 10 +++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index c4ab37d59..01302cfb0 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -512,11 +512,16 @@ class IssueQuery < Query end def sql_for_issue_id_field(field, operator, value) - ids = value.first.to_s.scan(/\d+/).map(&:to_i).join(",") - if ids.present? - "#{Issue.table_name}.id IN (#{ids})" + if operator == "=" + # accepts a comma separated list of ids + ids = value.first.to_s.scan(/\d+/).map(&:to_i) + if ids.present? + "#{Issue.table_name}.id IN (#{ids.join(",")})" + else + "1=0" + end else - "1=0" + sql_for_field("id", operator, value, Issue.table_name, "id") end end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 2515624d8..206677c26 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -235,7 +235,7 @@ class QueryTest < ActiveSupport::TestCase assert_equal 2, issues.first.id end - def test_operator_is_on_integer_should_accept_comma_separated_values + def test_operator_is_on_issue_id_should_accept_comma_separated_values query = IssueQuery.new(:name => '_') query.add_filter("issue_id", '=', ['1,3']) issues = find_issues_with_query(query) @@ -243,6 +243,14 @@ class QueryTest < ActiveSupport::TestCase assert_equal [1,3], issues.map(&:id).sort end + def test_operator_between_on_issue_id_should_return_range + query = IssueQuery.new(:name => '_') + query.add_filter("issue_id", '><', ['2','3']) + issues = find_issues_with_query(query) + assert_equal 2, issues.size + assert_equal [2,3], issues.map(&:id).sort + end + def test_operator_is_on_integer_custom_field f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true, :trackers => Tracker.all) CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7') -- 2.39.5