##// END OF EJS Templates
Merged r10801 from trunk (#12349)....
Jean-Philippe Lang -
r10592:ab69845ea23e
parent child
Show More
@@ -30,13 +30,13 class Principal < ActiveRecord::Base
30 30 if q.blank?
31 31 {}
32 32 else
33 q = q.to_s.downcase
33 q = q.to_s
34 34 pattern = "%#{q}%"
35 sql = "LOWER(login) LIKE :p OR LOWER(firstname) LIKE :p OR LOWER(lastname) LIKE :p OR LOWER(mail) LIKE :p"
35 sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)"
36 36 params = {:p => pattern}
37 37 if q =~ /^(.+)\s+(.+)$/
38 38 a, b = "#{$1}%", "#{$2}%"
39 sql << " OR (LOWER(firstname) LIKE :a AND LOWER(lastname) LIKE :b) OR (LOWER(firstname) LIKE :b AND LOWER(lastname) LIKE :a)"
39 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))"
40 40 params.merge!(:a => a, :b => b)
41 41 end
42 42 {:conditions => [sql, params]}
@@ -1,3 +1,5
1 # encoding: utf-8
2 #
1 3 # Redmine - project management software
2 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 5 #
@@ -106,4 +108,11 class PrincipalTest < ActiveSupport::TestCase
106 108 assert_equal @palmer, results.first
107 109 end
108 110 end
111
112 def test_like_scope_with_cyrillic_name
113 user = User.generate!(:firstname => 'Соболев', :lastname => 'Денис')
114 results = Principal.like('Собо')
115 assert_equal 1, results.count
116 assert_equal user, results.first
117 end
109 118 end
General Comments 0
You need to be logged in to leave comments. Login now