Commit 7ddbc92abcade8e5b1810f7d4a2b863e7ce74e94
Exists in
spb-stable
and in
3 other branches
Merge branch 'case_insensitive_user_search' into 'master'
Case insensitive user search As per implementation by Christopher Arnold.
Showing
3 changed files
with
16 additions
and
1 deletions
Show diff stats
CHANGELOG
1 | v 6.8.0 | 1 | v 6.8.0 |
2 | - Ability to at mention users that are participating in issue and merge req. discussion | 2 | - Ability to at mention users that are participating in issue and merge req. discussion |
3 | - Enabled GZip Compression for assets in example Nginx, make sure that Nginx is compiled with --with-http_gzip_static_module flag (this is default in Ubuntu) | 3 | - Enabled GZip Compression for assets in example Nginx, make sure that Nginx is compiled with --with-http_gzip_static_module flag (this is default in Ubuntu) |
4 | + - Make user search case-insensitive (Christopher Arnold) | ||
4 | 5 | ||
5 | v 6.7.2 | 6 | v 6.7.2 |
6 | - Fix upgrader script | 7 | - Fix upgrader script |
app/models/user.rb
@@ -204,7 +204,7 @@ class User < ActiveRecord::Base | @@ -204,7 +204,7 @@ class User < ActiveRecord::Base | ||
204 | end | 204 | end |
205 | 205 | ||
206 | def search query | 206 | def search query |
207 | - where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%") | 207 | + where("lower(name) LIKE :query OR lower(email) LIKE :query OR lower(username) LIKE :query", query: "%#{query.downcase}%") |
208 | end | 208 | end |
209 | 209 | ||
210 | def by_username_or_id(name_or_id) | 210 | def by_username_or_id(name_or_id) |
spec/models/user_spec.rb
@@ -292,6 +292,20 @@ describe User do | @@ -292,6 +292,20 @@ describe User do | ||
292 | end | 292 | end |
293 | end | 293 | end |
294 | 294 | ||
295 | + describe 'search' do | ||
296 | + let(:user1) { create(:user, username: 'James', email: 'james@testing.com') } | ||
297 | + let(:user2) { create(:user, username: 'jameson', email: 'jameson@example.com') } | ||
298 | + | ||
299 | + it "should be case insensitive" do | ||
300 | + User.search(user1.username.upcase).to_a.should == [user1] | ||
301 | + User.search(user1.username.downcase).to_a.should == [user1] | ||
302 | + User.search(user2.username.upcase).to_a.should == [user2] | ||
303 | + User.search(user2.username.downcase).to_a.should == [user2] | ||
304 | + User.search(user1.username.downcase).to_a.count.should == 2 | ||
305 | + User.search(user2.username.downcase).to_a.count.should == 1 | ||
306 | + end | ||
307 | + end | ||
308 | + | ||
295 | describe 'by_username_or_id' do | 309 | describe 'by_username_or_id' do |
296 | let(:user1) { create(:user, username: 'foo') } | 310 | let(:user1) { create(:user, username: 'foo') } |
297 | 311 |