VRFS-2498, VRFS-2618 : API, routes and specs for backing tracks/metronomes.

This commit is contained in:
Steven Miers 2015-01-13 10:15:46 -06:00
parent c6f03a91b8
commit 4f94444429
3 changed files with 125 additions and 2 deletions

View File

@ -4,7 +4,7 @@ class ApiMusicSessionsController < ApiController
# have to be signed in currently to see this screen
before_filter :api_signed_in_user, :except => [ :add_like, :show, :show_history, :add_session_info_comment ]
before_filter :lookup_session, only: [:show, :update, :delete, :claimed_recording_start, :claimed_recording_stop, :track_sync, :jam_track_open, :jam_track_close]
before_filter :lookup_session, only: [:show, :update, :delete, :claimed_recording_start, :claimed_recording_stop, :track_sync, :jam_track_open, :jam_track_close, :backing_track_open, :backing_track_close, :metronome_open, :metronome_close]
skip_before_filter :api_signed_in_user, only: [:perf_upload]
respond_to :json
@ -597,8 +597,44 @@ class ApiMusicSessionsController < ApiController
respond_with_model(@music_session)
end
def backing_track_open
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
private
@backing_track_path = params[:backing_track_path]
@music_session.open_backing_track(current_user, @backing_track_path)
respond_with_model(@music_session)
end
def backing_track_close
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.close_backing_track()
respond_with_model(@music_session)
end
def metronome_open
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.open_metronome(current_user)
respond_with_model(@music_session)
end
def metronome_close
unless @music_session.users.exists?(current_user)
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@music_session.close_metronome()
respond_with_model(@music_session)
end
private
def lookup_session
@music_session = ActiveMusicSession.find(params[:id])

View File

@ -178,6 +178,10 @@ SampleApp::Application.routes.draw do
match '/sessions/:id/details/comments' => 'api_music_sessions#add_session_info_comment', :via => :post
match '/sessions/:id/jam_tracks/:jam_track_id/open' => 'api_music_sessions#jam_track_open', :via => :post
match '/sessions/:id/jam_tracks/close' => 'api_music_sessions#jam_track_close', :via => :post
match '/sessions/:id/backing_tracks/:backing_track_id/open' => 'api_music_sessions#backing_track_open', :via => :post
match '/sessions/:id/backing_tracks/close' => 'api_music_sessions#backing_track_close', :via => :post
match '/sessions/:id/jam_tracks/:metronome_id/open' => 'api_music_sessions#metronome_open', :via => :post
match '/sessions/:id/metronomes/close' => 'api_music_sessions#metronome_close', :via => :post
# music session tracks
match '/sessions/:id/tracks' => 'api_music_sessions#track_create', :via => :post

View File

@ -223,4 +223,87 @@ describe ApiMusicSessionsController do
json[:jam_track][:id].should == jam_track.id
end
end
describe "open_backing_track" do
let(:ams) { FactoryGirl.create(:active_music_session, creator: user) }
let(:backing_track) { "foo.mp3"}
it "does not allow someone to open a track unless they are in the session" do
post :backing_track_open, {:format => 'json', id: ams.id, backing_track_path: backing_track}
response.status.should == 403
end
it "does not allow someone to open a track unless they own the backing track" do
pending "connection with client to determine ownership"
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :backing_track_open, {:format => 'json', id: ams.id, backing_track_path: backing_track}
response.status.should == 403
end
it "allows someone who owns the backing track to open it" do
# put the connection of the user into the session, so th
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :backing_track_open, {:format => 'json', id: ams.id, backing_track_path: backing_track}
response.status.should == 200
end
it "does not allow someone to close a track unless they are in the session" do
post :backing_track_close, {:format => 'json', id: ams.id}
response.status.should == 403
end
it "allows the backing track to be closed" do
# put the connection of the user into the session, so th
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :backing_track_open, {:format => 'json', id: ams.id, backing_track_path: backing_track}
response.status.should == 200
post :backing_track_close, {:format => 'json', id: ams.id}
response.status.should == 200
end
end
describe "open_metronome" do
let(:ams) { FactoryGirl.create(:active_music_session, creator: user) }
let(:metronome) { "foo.mp3"}
it "does not allow someone to open a track unless they are in the session" do
post :metronome_open, {:format => 'json', id: ams.id, metronome_path: metronome}
response.status.should == 403
end
it "can open it" do
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :metronome_open, {:format => 'json', id: ams.id, metronome_path: metronome}
response.status.should == 200
end
it "does not allow someone to close a metronome" do
post :metronome_close, {:format => 'json', id: ams.id}
response.status.should == 403
end
it "does allow someone who joied to close a metronome" do
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :metronome_close, {:format => 'json', id: ams.id}
response.status.should == 200
end
it "allows the metronome to be closed" do
# put the connection of the user into the session, so th
conn.join_the_session(ams.music_session, true, tracks, user, 10)
post :metronome_open, {:format => 'json', id: ams.id, metronome_path: metronome}
response.status.should == 200
post :metronome_close, {:format => 'json', id: ams.id}
response.status.should == 200
end
end
end