summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-04-05 13:52:53 +0000
committerGo MAEDA <maeda@farend.jp>2023-04-05 13:52:53 +0000
commit27b8f57fd8c7e8b1279b483128edbdcc9723be49 (patch)
tree1dceb10173d766593a52494dd502dd9ba8e43b4d
parent5e1b7b027fe5000f92b0daa3e40f76b05ad042c6 (diff)
downloadredmine-27b8f57fd8c7e8b1279b483128edbdcc9723be49.tar.gz
redmine-27b8f57fd8c7e8b1279b483128edbdcc9723be49.zip
Fix a bug the "doesn't contain" operator returns no issues if the search finds no issues (#38402).
Patch by Holger Just. git-svn-id: https://svn.redmine.org/redmine/trunk@22168 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue_query.rb2
-rw-r--r--test/unit/query_test.rb49
2 files changed, 48 insertions, 3 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index 1c60c6b61..e45548121 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -799,7 +799,7 @@ class IssueQuery < Query
sw = operator == '!~' ? 'NOT' : ''
"#{Issue.table_name}.id #{sw} IN (#{ids.join(',')})"
else
- '1=0'
+ operator == '!~' ? '1=1' : '1=0'
end
end
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 2b02a1e07..2bbf91198 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -844,7 +844,7 @@ class QueryTest < ActiveSupport::TestCase
assert_equal [1, 3], find_issues_with_query(query).map(&:id).sort
end
- def test_fileter_any_searchable
+ def test_filter_any_searchable
User.current = User.find(1)
query = IssueQuery.new(
:name => '_',
@@ -859,7 +859,52 @@ class QueryTest < ActiveSupport::TestCase
assert_equal [1, 2, 3], result.map(&:id).sort
end
- def test_fileter_any_searchable_should_search_searchable_custom_fields
+ def test_filter_any_searchable_no_matches
+ User.current = User.find(1)
+ query = IssueQuery.new(
+ :name => '_',
+ :filters => {
+ 'any_searchable' => {
+ :operator => '~',
+ :values => ['SomethingThatDoesNotExist']
+ }
+ }
+ )
+ result = find_issues_with_query(query)
+ assert_empty result.map(&:id)
+ end
+
+ def test_filter_any_searchable_negative
+ User.current = User.find(1)
+ query = IssueQuery.new(
+ :name => '_',
+ :filters => {
+ 'any_searchable' => {
+ :operator => '!~',
+ :values => ['recipe']
+ }
+ }
+ )
+ result = find_issues_with_query(query)
+ assert_not_includes [1, 2, 3], result.map(&:id)
+ end
+
+ def test_filter_any_searchable_negative_no_matches
+ User.current = User.find(1)
+ query = IssueQuery.new(
+ :name => '_',
+ :filters => {
+ 'any_searchable' => {
+ :operator => '!~',
+ :values => ['SomethingThatDoesNotExist']
+ }
+ }
+ )
+ result = find_issues_with_query(query)
+ assert_not_empty result.map(&:id)
+ end
+
+ def test_filter_any_searchable_should_search_searchable_custom_fields
User.current = User.find(1)
query = IssueQuery.new(
:name => '_',