From ab69845ea23e83895cadda3c2e95ebc513d18b5f 2012-11-17 08:50:19 From: Jean-Philippe Lang Date: 2012-11-17 08:50:19 Subject: [PATCH] Merged r10801 from trunk (#12349). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.1-stable@10819 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/principal.rb b/app/models/principal.rb index 2b89e16..90b56b6 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -30,13 +30,13 @@ class Principal < ActiveRecord::Base if q.blank? {} else - q = q.to_s.downcase + q = q.to_s 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} if q =~ /^(.+)\s+(.+)$/ 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) end {:conditions => [sql, params]} diff --git a/test/unit/principal_test.rb b/test/unit/principal_test.rb index 6a4aed7..6d06a31 100644 --- a/test/unit/principal_test.rb +++ b/test/unit/principal_test.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 +# # Redmine - project management software # Copyright (C) 2006-2012 Jean-Philippe Lang # @@ -106,4 +108,11 @@ class PrincipalTest < ActiveSupport::TestCase assert_equal @palmer, results.first 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