Project

General

Profile

Defect #25077 » rm_25077_fix_query_filter_after_none_for_text_and_string_column.patch

Marius BĂLTEANU, 2017-03-06 08:35

View differences:

app/models/query.rb
984 984
      "  SELECT customized_id FROM #{CustomValue.table_name}" +
985 985
      "  WHERE customized_type='#{target_class}' AND custom_field_id=#{chained_custom_field_id}" +
986 986
      "  AND #{sql_for_field(field, operator, value, CustomValue.table_name, 'value')}))"
987
    
987

  
988 988
  end
989 989

  
990 990
  def sql_for_custom_field_attribute(field, operator, value, custom_field_id, attribute)
......
1048 1048
      end
1049 1049
    when "!*"
1050 1050
      sql = "#{db_table}.#{db_field} IS NULL"
1051
      sql << " OR #{db_table}.#{db_field} = ''" if is_custom_filter
1051
      sql << " OR #{db_table}.#{db_field} = ''" if (is_custom_filter || [:text, :string].include?(type_for(field)))
1052 1052
    when "*"
1053 1053
      sql = "#{db_table}.#{db_field} IS NOT NULL"
1054 1054
      sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
test/unit/query_test.rb
217 217
    assert issues.all? {|i| i.custom_field_value(2).blank?}
218 218
  end
219 219

  
220
  def test_operator_none_for_text
221
    query = IssueQuery.new(:name => '_')
222
    query.add_filter('status_id', '*', [''])
223
    query.add_filter('description', '!*', [''])
224
    assert query.has_filter?('description')
225
    issues = find_issues_with_query(query)
226

  
227
    assert issues.any?
228
    assert issues.all? {|i| i.description.blank?}
229
    assert_equal [11, 12], issues.map(&:id).sort
230
  end
231

  
220 232
  def test_operator_all
221 233
    query = IssueQuery.new(:project => Project.find(1), :name => '_')
222 234
    query.add_filter('fixed_version_id', '*', [''])
(2-2/2)