FIX: trim leading & trailing whitespaces in admin user search

This commit is contained in:
Régis Hanol 2016-10-10 16:18:57 +02:00
parent 41ce205733
commit 8f68a95e56
2 changed files with 7 additions and 6 deletions

View File

@ -79,6 +79,7 @@ class AdminUserIndexQuery
def filter_by_search
if params[:filter].present?
params[:filter].strip!
if ip = IPAddr.new(params[:filter]) rescue nil
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
else
@ -89,7 +90,7 @@ class AdminUserIndexQuery
def filter_by_ip
if params[:ip].present?
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip])
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip].strip)
end
end

View File

@ -110,12 +110,12 @@ describe AdminUserIndexQuery do
before(:each) { Fabricate(:user, email: "test1@example.com") }
it "matches the email" do
query = ::AdminUserIndexQuery.new({ filter: "est1" })
query = ::AdminUserIndexQuery.new({ filter: " est1" })
expect(query.find_users.count()).to eq(1)
end
it "matches the email using any case" do
query = ::AdminUserIndexQuery.new({ filter: "Test1" })
query = ::AdminUserIndexQuery.new({ filter: "Test1\t" })
expect(query.find_users.count()).to eq(1)
end
@ -126,12 +126,12 @@ describe AdminUserIndexQuery do
before(:each) { Fabricate(:user, username: "test_user_1") }
it "matches the username" do
query = ::AdminUserIndexQuery.new({ filter: "user" })
query = ::AdminUserIndexQuery.new({ filter: "user\n" })
expect(query.find_users.count).to eq(1)
end
it "matches the username using any case" do
query = ::AdminUserIndexQuery.new({ filter: "User" })
query = ::AdminUserIndexQuery.new({ filter: "\r\nUser" })
expect(query.find_users.count).to eq(1)
end
end
@ -141,7 +141,7 @@ describe AdminUserIndexQuery do
let!(:user) { Fabricate(:user, ip_address: "117.207.94.9") }
it "matches the ip address" do
query = ::AdminUserIndexQuery.new({ filter: "117.207.94.9" })
query = ::AdminUserIndexQuery.new({ filter: " 117.207.94.9 " })
expect(query.find_users.count()).to eq(1)
end