Fixed that Principal#like scope does not work with cyrillic characters and Postgresql (#12349).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10801 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-13 22:01:31 +00:00
parent 37c590bfef
commit ce04c41830
2 changed files with 12 additions and 3 deletions

View File

@ -30,13 +30,13 @@ class Principal < ActiveRecord::Base
if q.blank? if q.blank?
{} {}
else else
q = q.to_s.downcase q = q.to_s
pattern = "%#{q}%" pattern = "%#{q}%"
sql = "LOWER(login) LIKE :p OR LOWER(firstname) LIKE :p OR LOWER(lastname) LIKE :p OR LOWER(mail) LIKE :p" sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)"
params = {:p => pattern} params = {:p => pattern}
if q =~ /^(.+)\s+(.+)$/ if q =~ /^(.+)\s+(.+)$/
a, b = "#{$1}%", "#{$2}%" a, b = "#{$1}%", "#{$2}%"
sql << " OR (LOWER(firstname) LIKE :a AND LOWER(lastname) LIKE :b) OR (LOWER(firstname) LIKE :b AND LOWER(lastname) LIKE :a)" sql << " OR (LOWER(firstname) LIKE LOWER(:a) AND LOWER(lastname) LIKE LOWER(:b)) OR (LOWER(firstname) LIKE LOWER(:b) AND LOWER(lastname) LIKE LOWER(:a))"
params.merge!(:a => a, :b => b) params.merge!(:a => a, :b => b)
end end
{:conditions => [sql, params]} {:conditions => [sql, params]}

View File

@ -1,3 +1,5 @@
# encoding: utf-8
#
# Redmine - project management software # Redmine - project management software
# Copyright (C) 2006-2012 Jean-Philippe Lang # Copyright (C) 2006-2012 Jean-Philippe Lang
# #
@ -106,4 +108,11 @@ class PrincipalTest < ActiveSupport::TestCase
assert_equal @palmer, results.first assert_equal @palmer, results.first
end end
end end
def test_like_scope_with_cyrillic_name
user = User.generate!(:firstname => 'Соболев', :lastname => 'Денис')
results = Principal.like('Собо')
assert_equal 1, results.count
assert_equal user, results.first
end
end end