Commit 7ddbc92a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'case_insensitive_user_search' into 'master'

Case insensitive user search

As per implementation by Christopher Arnold.
parents afcaf662 466203eb
v 6.8.0 v 6.8.0
- Ability to at mention users that are participating in issue and merge req. discussion - Ability to at mention users that are participating in issue and merge req. discussion
- 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) - 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)
- Make user search case-insensitive (Christopher Arnold)
v 6.7.2 v 6.7.2
- Fix upgrader script - Fix upgrader script
......
...@@ -204,7 +204,7 @@ class User < ActiveRecord::Base ...@@ -204,7 +204,7 @@ class User < ActiveRecord::Base
end end
def search query def search query
where("name LIKE :query OR email LIKE :query OR username LIKE :query", query: "%#{query}%") where("lower(name) LIKE :query OR lower(email) LIKE :query OR lower(username) LIKE :query", query: "%#{query.downcase}%")
end end
def by_username_or_id(name_or_id) def by_username_or_id(name_or_id)
......
...@@ -292,6 +292,20 @@ describe User do ...@@ -292,6 +292,20 @@ describe User do
end end
end end
describe 'search' do
let(:user1) { create(:user, username: 'James', email: 'james@testing.com') }
let(:user2) { create(:user, username: 'jameson', email: 'jameson@example.com') }
it "should be case insensitive" do
User.search(user1.username.upcase).to_a.should == [user1]
User.search(user1.username.downcase).to_a.should == [user1]
User.search(user2.username.upcase).to_a.should == [user2]
User.search(user2.username.downcase).to_a.should == [user2]
User.search(user1.username.downcase).to_a.count.should == 2
User.search(user2.username.downcase).to_a.count.should == 1
end
end
describe 'by_username_or_id' do describe 'by_username_or_id' do
let(:user1) { create(:user, username: 'foo') } let(:user1) { create(:user, username: 'foo') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment