@@ -30,13 +30,13 class Principal < ActiveRecord::Base | |||||
30 | if q.blank? |
|
30 | if q.blank? | |
31 | {} |
|
31 | {} | |
32 | else |
|
32 | else | |
33 |
q = q.to_s |
|
33 | q = q.to_s | |
34 | pattern = "%#{q}%" |
|
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 | params = {:p => pattern} |
|
36 | params = {:p => pattern} | |
37 | if q =~ /^(.+)\s+(.+)$/ |
|
37 | if q =~ /^(.+)\s+(.+)$/ | |
38 | a, b = "#{$1}%", "#{$2}%" |
|
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 | params.merge!(:a => a, :b => b) |
|
40 | params.merge!(:a => a, :b => b) | |
41 | end |
|
41 | end | |
42 | {:conditions => [sql, params]} |
|
42 | {:conditions => [sql, params]} |
@@ -1,3 +1,5 | |||||
|
1 | # encoding: utf-8 | |||
|
2 | # | |||
1 | # Redmine - project management software |
|
3 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
4 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
5 | # | |
@@ -106,4 +108,11 class PrincipalTest < ActiveSupport::TestCase | |||||
106 | assert_equal @palmer, results.first |
|
108 | assert_equal @palmer, results.first | |
107 | end |
|
109 | end | |
108 | end |
|
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 | end |
|
118 | end |
General Comments 0
You need to be logged in to leave comments.
Login now