Allow search User through email with whitespaces

This commit is contained in:
taitus
2021-03-25 10:41:27 +01:00
parent e371ad1f80
commit 3796ccc874
2 changed files with 9 additions and 1 deletions

View File

@@ -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

View File

@@ -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")