simplify Search.new_musicians api
This commit is contained in:
parent
bf06df36a3
commit
81495315f7
|
|
@ -291,13 +291,16 @@ module JamRuby
|
|||
false
|
||||
end
|
||||
|
||||
def self.new_musicians(usr, since_date=Time.now - 1.week, max_count=50, radius=M_MILES_DEFAULT)
|
||||
def self.new_musicians(usr, since_date)
|
||||
# todo scott turn this into score .within(radius, :origin => [usr.lat, usr.lng])
|
||||
|
||||
rel = User.musicians
|
||||
.where(['created_at >= ? AND users.id != ?', since_date, usr.id])
|
||||
.order('created_at DESC')
|
||||
.limit(max_count)
|
||||
.limit(50)
|
||||
|
||||
objs = rel.all.to_a
|
||||
|
||||
if block_given?
|
||||
yield(objs) if 0 < objs.count
|
||||
else
|
||||
|
|
|
|||
|
|
@ -280,7 +280,7 @@ describe 'Musician search' do
|
|||
# create new user outside 500 from Apex to ensure its excluded from results
|
||||
FactoryGirl.create(:user, {city: "Austin", state: "TX", country: "US"})
|
||||
User.geocoded_users.find_each do |usr|
|
||||
Search.new_musicians(usr) do |new_usrs|
|
||||
Search.new_musicians(usr, Time.now - 1.week) do |new_usrs|
|
||||
# the newly created user is not nearby the existing users (which are in Apex, NC)
|
||||
# and that user is not included in query
|
||||
expect(new_usrs.count).to eq(User.musicians.count - 1)
|
||||
|
|
@ -293,7 +293,7 @@ describe 'Musician search' do
|
|||
# create new user outside 500 from Apex to ensure its excluded from results
|
||||
FactoryGirl.create(:user, {city: "Austin", state: "TX", country: "US"})
|
||||
User.geocoded_users.find_each do |usr|
|
||||
Search.new_musicians(usr) do |new_usrs|
|
||||
Search.new_musicians(usr, Time.now - 1.week) do |new_usrs|
|
||||
# the newly created user is not nearby the existing users (which are in Apex, NC)
|
||||
# and that user is not included in query
|
||||
expect(new_usrs.count).to eq(User.musicians.count - 1)
|
||||
|
|
|
|||
Loading…
Reference in New Issue