added asm_index method to controller and fix a few issues with asm_index and included a simple test

This commit is contained in:
Scott Comer 2014-06-13 23:51:54 -05:00
parent b918d24d32
commit 2799a6443e
3 changed files with 52 additions and 2 deletions

View File

@ -330,7 +330,7 @@ module JamRuby
my_audio_latency = connection.last_jam_audio_latency
query = MusicSession
.select('music_sessions.*')
.select('music_sessions.*')
# TODO this is not really needed when ams_music_session_tmp is joined
# unless there is something specific we need out of active_music_sessions
@ -358,7 +358,12 @@ module JamRuby
query = query.order(
%Q{
tag, latency
tag, latency, music_sessions.id
}
)
.group(
%Q{
tag, latency, music_sessions.id
}
)

View File

@ -332,6 +332,36 @@ describe ActiveMusicSession do
end
end
describe "ams_index" do
it "does not crash" do
creator = FactoryGirl.create(:user)
creator2 = FactoryGirl.create(:user)
earlier_session = FactoryGirl.create(:active_music_session, :creator => creator, :description => "Earlier Session")
c1 = FactoryGirl.create(:connection, user: creator, music_session: earlier_session, addr: 0x01020304, locidispid: 1)
later_session = FactoryGirl.create(:active_music_session, :creator => creator2, :description => "Later Session")
c2 = FactoryGirl.create(:connection, user: creator2, music_session: later_session, addr: 0x21020304, locidispid: 2)
user = FactoryGirl.create(:user)
c3 = FactoryGirl.create(:connection, user: user, locidispid: 3)
Score.createx(c1.locidispid, c1.client_id, c1.addr, c3.locidispid, c3.client_id, c3.addr, 20, nil);
Score.createx(c2.locidispid, c2.client_id, c2.addr, c3.locidispid, c3.client_id, c3.addr, 30, nil);
music_sessions = ActiveMusicSession.ams_index(user, client_id: c3.client_id).take(100)
music_sessions.should_not be_nil
music_sessions.length.should == 2
end
# todo we need more tests:
# rsvp'd user (chosen and not chosen)
# invited user
# creator (who should be automatically rsvp'd)
# musician_access and not
end
it 'uninvited users cant join approval-required sessions without invitation' do
user1 = FactoryGirl.create(:user) # in the jam session

View File

@ -60,6 +60,21 @@ class ApiMusicSessionsController < ApiController
limit: params[:limit])
end
def ams_index
# returns a relation which will produce a list of music_sessions which are active and augmented with attributes
# tag and latency, then sorted by tag, latency, and finally music_sessions.id (for stability). the list is
# filtered by genre, lang, and keyword, then paged by offset and limit (those are record numbers not page numbers).
# tag is 1 for chosen rsvp'd sessions, 2 for invited sessions, 3 for all others (musician_access). if you're the
# creator of a session it will be treated the same as if you had rsvp'd and been accepted.
@music_sessions = ActiveMusicSession.ams_index(current_user,
client_id: params[:client_id],
genre: params[:genre],
lang: params[:lang],
keyword: params[:keyword],
offset: params[:offset],
limit: params[:limit])
end
def scheduled
@music_sessions = MusicSession.scheduled(current_user)
end