VRFS-2029 : Update REST API ApiRecordingsController#claim

to accept and distribute upload_to_youtube flag as appropriate.  Spec
to verify.
This commit is contained in:
Steven Miers 2014-10-15 13:54:10 -05:00
parent d95a063648
commit c1f2a2083f
3 changed files with 28 additions and 2 deletions

View File

@ -180,7 +180,7 @@ module JamRuby
# Called when a user wants to "claim" a recording. To do this, the user must have been one of the tracks in the recording.
def claim(user, name, description, genre, is_public)
def claim(user, name, description, genre, is_public, upload_to_youtube=false)
unless self.users.exists?(user)
raise PermissionError, "user was not in this session"
@ -193,6 +193,7 @@ module JamRuby
claimed_recording.description = description
claimed_recording.genre = genre
claimed_recording.is_public = is_public
claimed_recording.upload_to_youtube = upload_to_youtube
self.claimed_recordings << claimed_recording
if claimed_recording.save

View File

@ -126,6 +126,7 @@ describe Recording do
@claimed_recording.description.should == "description"
@claimed_recording.genre.should == @genre
@claimed_recording.is_public.should == true
@claimed_recording.upload_to_youtube.should == false
end
it "should fail if a user who was not in the session claims a recording" do
@ -149,6 +150,7 @@ describe Recording do
@claimed_recording.description.should == "description2"
@claimed_recording.genre.should == @genre2
@claimed_recording.is_public.should == false
@claimed_recording.upload_to_youtube.should == false
end
it "should only allow the owner to edit a claimed recording" do
@ -195,6 +197,29 @@ describe Recording do
@recording.all_discarded.should == false
end
it "should set youtube flag" do
@connection.join_the_session(@music_session, true, nil, @user, 10)
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "name", "description", @genre, true, true)
@recording.reload
@recording.users.length.should == 1
@recording.users.first.should == @user
@user.recordings.length.should == 1
@user.recordings.first.should == @recording
@recording.claimed_recordings.length.should == 1
@claimed_recording = @recording.claimed_recordings.first
@claimed_recording.name.should == "name"
@claimed_recording.description.should == "description"
@claimed_recording.genre.should == @genre
@claimed_recording.is_public.should == true
@claimed_recording.upload_to_youtube.should == true
end
it "should destroy the entire recording if there was only one claimed_recording which is discarded" do
@recording = Recording.start(@music_session, @user)
@recording.stop

View File

@ -79,7 +79,7 @@ class ApiRecordingsController < ApiController
# claim will create a claimed recording for the creator
def claim
claim = @recording.claim(current_user, params[:name], params[:description], Genre.find_by_id(params[:genre]), params[:is_public])
claim = @recording.claim(current_user, params[:name], params[:description], Genre.find_by_id(params[:genre]), params[:is_public], params[:upload_to_youtube])
if claim.errors.any?
response.status = :unprocessable_entity