Refactor UserSearch tests

This commit is contained in:
Mike Moore
2013-02-07 06:50:59 -05:00
parent e41b6537f9
commit d72c26ff92
4 changed files with 142 additions and 127 deletions

View File

@@ -1,19 +1,19 @@
class UserSearch
def self.search term, topic_id
def self.search term, topic_id = nil
User.find_by_sql sql(term, topic_id)
end
private
def self.sql term, topic_id
sql = "select username, name, email from users u "
sql = "select id, username, name, email from users u "
if topic_id
sql << "left join (select distinct p.user_id from posts p where topic_id = :topic_id) s on
s.user_id = u.id "
end
if term.length > 0
if term.present?
sql << "where username ilike :term_like or
to_tsvector('simple', name) @@
to_tsquery('simple',