1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-01-06 07:31:31 +00:00

Restore accent insensitive search with mysql (#18537).

git-svn-id: http://svn.redmine.org/redmine/trunk@13767 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2014-12-15 19:22:13 +00:00
parent 15bb695bbb
commit 30175bf85e
3 changed files with 23 additions and 12 deletions

View File

@ -121,8 +121,6 @@ module Redmine
case connection.adapter_name case connection.adapter_name
when /postgresql/i when /postgresql/i
"#{column} ILIKE #{value}" "#{column} ILIKE #{value}"
when /mysql/i
"LOWER(#{column}) COLLATE utf8_bin LIKE LOWER(#{value})"
else else
"#{column} LIKE #{value}" "#{column} LIKE #{value}"
end end

View File

@ -167,6 +167,10 @@ class ActiveSupport::TestCase
ActiveRecord::Base.connection.adapter_name =~ /sqlite/i ActiveRecord::Base.connection.adapter_name =~ /sqlite/i
end end
def mysql?
ActiveRecord::Base.connection.adapter_name =~ /mysql/i
end
def assert_save(object) def assert_save(object)
saved = object.save saved = object.save
message = "#{object.class} could not be saved" message = "#{object.class} could not be saved"

View File

@ -149,17 +149,26 @@ class SearchTest < ActiveSupport::TestCase
assert_include issue, r assert_include issue, r
end end
def test_search_should_not_use_ruby_downcase def test_search_should_be_case_insensitive_with_accented_characters
skip "SQLite does not support case insensitive match for non-ASCII characters" if sqlite? unless sqlite?
issue1 = Issue.generate!(:subject => "Special chars: ÖÖ") issue1 = Issue.generate!(:subject => "Special chars: ÖÖ")
issue2 = Issue.generate!(:subject => "Special chars: Öö") issue2 = Issue.generate!(:subject => "Special chars: Öö")
Issue.generate!(:subject => "Special chars: oo")
Issue.generate!(:subject => "Special chars: OO") r = Issue.search_results('ÖÖ')
assert_include issue1, r
assert_include issue2, r
end
end
r = Issue.search_results('ÖÖ') def test_search_should_be_case_and_accent_insensitive_with_mysql
assert_include issue1, r if mysql?
assert_include issue2, r issue1 = Issue.generate!(:subject => "OO")
assert_equal 2, r.size issue2 = Issue.generate!(:subject => "oo")
r = Issue.search_results('ÖÖ')
assert_include issue1, r
assert_include issue2, r
end
end end
private private