vrfs-774: second musician searches working properly (likers)

This commit is contained in:
Jonathan Kolyer 2013-10-28 13:44:56 -05:00
parent 72d6d4e699
commit f6674cfc64
3 changed files with 8 additions and 25 deletions

View File

@ -6,9 +6,9 @@ module JamRuby
LIMIT = 10
ORDER_FOLLOWS = ['Most Followed', :followed]
ORDER_LIKED = ['Most Liked', :liked]
ORDER_LIKED = ['Most Plays', :plays]
ORDER_PLAYING = ['Playing Now', :playing]
ORDERINGS = [ORDER_FOLLOWS, ORDER_LIKED, ORDER_PLAYING]
ORDERINGS = [ORDER_FOLLOWS, ORDER_PLAYS, ORDER_PLAYING]
ORDERING_KEYS = ORDERINGS.collect { |oo| oo[1] }
def self.order_param(params)

View File

@ -924,11 +924,7 @@ module JamRuby
end
case ordering = Search.order_param(params)
when :liked
rel = rel.select("COUNT(likers) AS lcount, users.id")
rel = rel.joins("LEFT JOIN users_likers AS likers ON likers.user_id = users.id")
rel = rel.group("users.id")
rel = rel.order("COUNT(likers) DESC")
when :plays
when :followed
rel = rel.select("COUNT(follows) AS fcount, users.id")
rel = rel.joins("LEFT JOIN users_followers AS follows ON follows.user_id = users.id")

View File

@ -54,23 +54,8 @@ describe User do
results.all.count.should == 2
end
it "should find all musicians sorted by likes with pagination" do
# establish sorting order
[@user2, @user3, @user1].each { |uu| User.create_user_like(@user4.id, uu.id) }
[@user2, @user4].each { |uu| User.create_user_like(@user3.id, uu.id) }
[@user2].each { |uu| User.create_user_like(@user2.id, uu.id) }
# get all the users in correct order
params = { :per_page => @users.size, :orderby => :liked }
results = User.musician_search(params)
results.all.count.should == @users.size
results.each_with_index do |uu, idx|
uu.id.should == @users.reverse[idx].id
end
# refresh the order to ensure it works right
[@user3, @user4, @user1].each { |uu| User.create_user_like(@user2.id, uu.id) }
results = User.musician_search(params)
results[0].id.should == @user2.id
it "should find all musicians sorted by plays with pagination" do
pending
end
it "should find all musicians sorted by now playing" do
@ -78,7 +63,9 @@ describe User do
end
it "should find musicians with an instrument" do
pending
@user1.musician_instruments << FactoryGirl.build(:musician_instrument, user: @user1)
ii = @user1.instruments[0]
ii.should not_be nil
end
it "should find musicians within a given distance of location" do