]> source.dussan.org Git - redmine.git/commitdiff
Fix "any" operator for text filters to exclude empty text values (#39991).
authorGo MAEDA <maeda@farend.jp>
Tue, 2 Jan 2024 00:41:00 +0000 (00:41 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 2 Jan 2024 00:41:00 +0000 (00:41 +0000)
Patch by Go MAEDA (@maeda).

git-svn-id: https://svn.redmine.org/redmine/trunk@22583 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index 9f3ce4c086eeef0e7e7e87be98cf17184a56b777..b9a7181fa372c4ef2d3e838af65f3f1a5b021182 100644 (file)
@@ -1276,7 +1276,7 @@ class Query < ActiveRecord::Base
       sql += " OR #{db_table}.#{db_field} = ''" if is_custom_filter || [:text, :string].include?(type_for(field))
     when "*"
       sql = "#{db_table}.#{db_field} IS NOT NULL"
-      sql += " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
+      sql += " AND #{db_table}.#{db_field} <> ''" if is_custom_filter || [:text, :string].include?(type_for(field))
     when ">="
       if [:date, :date_past].include?(type_for(field))
         sql = date_clause(db_table, db_field, parse_date(value.first), nil, is_custom_filter)
index a1c528e26f1c0c344caa40bddfb7da2d1ddb398c..462934f1e37d162992b38518e75ab1e136fe0c8e 100644 (file)
@@ -214,7 +214,7 @@ class QueryTest < ActiveSupport::TestCase
     assert issues.all? {|i| i.custom_field_value(2).blank?}
   end
 
-  def test_operator_none_for_text
+  def test_operator_none_for_blank_text
     query = IssueQuery.new(:name => '_')
     query.add_filter('status_id', '*', [''])
     query.add_filter('description', '!*', [''])
@@ -226,6 +226,19 @@ class QueryTest < ActiveSupport::TestCase
     assert_equal [11, 12], issues.map(&:id).sort
   end
 
+  def test_operator_any_for_blank_text
+    Issue.where(id: [1, 2]).update_all(description: '')
+    query = IssueQuery.new(:name => '_')
+    query.add_filter('status_id', '*', [''])
+    query.add_filter('description', '*', [''])
+    assert query.has_filter?('description')
+    issues = find_issues_with_query(query)
+
+    assert issues.any?
+    assert issues.all? {|i| i.description.present?}
+    assert_empty issues.map(&:id) & [1, 2]
+  end
+
   def test_operator_all
     query = IssueQuery.new(:project => Project.find(1), :name => '_')
     query.add_filter('fixed_version_id', '*', [''])