diff --git a/app/models/query.rb b/app/models/query.rb index 4e5799fbb..7ce95f0ea 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -424,9 +424,9 @@ class Query < ActiveRecord::Base Time.now.at_beginning_of_week sql = "#{db_table}.#{db_field} BETWEEN '%s' AND '%s'" % [connection.quoted_date(from), connection.quoted_date(from + 7.days)] when "~" - sql = "#{db_table}.#{db_field} LIKE '%#{connection.quote_string(value.first)}%'" + sql = "LOWER(#{db_table}.#{db_field}) LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'" when "!~" - sql = "#{db_table}.#{db_field} NOT LIKE '%#{connection.quote_string(value.first)}%'" + sql = "LOWER(#{db_table}.#{db_field}) NOT LIKE '%#{connection.quote_string(value.first.to_s.downcase)}%'" end return sql diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index e12bac8d7..73efa426f 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -150,15 +150,17 @@ class QueryTest < Test::Unit::TestCase def test_operator_contains query = Query.new(:project => Project.find(1), :name => '_') - query.add_filter('subject', '~', ['string']) - assert query.statement.include?("#{Issue.table_name}.subject LIKE '%string%'") - find_issues_with_query(query) + query.add_filter('subject', '~', ['uNable']) + assert query.statement.include?("LOWER(#{Issue.table_name}.subject) LIKE '%unable%'") + result = find_issues_with_query(query) + assert result.empty? + result.each {|issue| assert issue.subject.downcase.include?('unable') } end def test_operator_does_not_contains query = Query.new(:project => Project.find(1), :name => '_') - query.add_filter('subject', '!~', ['string']) - assert query.statement.include?("#{Issue.table_name}.subject NOT LIKE '%string%'") + query.add_filter('subject', '!~', ['uNable']) + assert query.statement.include?("LOWER(#{Issue.table_name}.subject) NOT LIKE '%unable%'") find_issues_with_query(query) end