summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/principal.rb6
-rw-r--r--test/unit/principal_test.rb9
2 files changed, 12 insertions, 3 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 2b89e16a9..90b56b6a1 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 6a4aed700..6d06a3105 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