Allow search User through email with whitespaces
This commit is contained in:
@@ -302,7 +302,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search(term)
|
||||
term.present? ? where("email = ? OR username ILIKE ?", term, "%#{term}%") : none
|
||||
term.present? ? where("email = ? OR username ILIKE ?", term.strip, "%#{term}%") : none
|
||||
end
|
||||
|
||||
def self.username_max_length
|
||||
|
||||
@@ -424,6 +424,14 @@ describe User do
|
||||
expect(search).to eq [user1]
|
||||
end
|
||||
|
||||
it "find users by email with whitespaces" do
|
||||
user1 = create(:user, email: "larry@consul.dev")
|
||||
create(:user, email: "bird@consul.dev")
|
||||
search = User.search(" larry@consul.dev ")
|
||||
|
||||
expect(search).to eq [user1]
|
||||
end
|
||||
|
||||
it "find users by name" do
|
||||
user1 = create(:user, username: "Larry Bird")
|
||||
create(:user, username: "Robert Parish")
|
||||
|
||||
Reference in New Issue
Block a user