VRFS-117 - added recording genre support
This commit is contained in:
parent
35a9597060
commit
ae2097e9ff
|
|
@ -64,17 +64,12 @@ class ApiBandsController < ApiController
|
|||
end
|
||||
|
||||
if hide_private
|
||||
@recordings = Recording.find(:all,
|
||||
:joins => :musician_recordings,
|
||||
:select => "recordings.id, recordings.description, recordings.public",
|
||||
:conditions => ["bands_recordings.band_id='#{params[:id]}' AND public=true"])
|
||||
@recordings = Recording.joins(:band_recordings)
|
||||
.where(:bands_recordings => {:band_id => "#{params[:id]}"}, :public => true)
|
||||
|
||||
#.paginate(page: params[:page])
|
||||
else
|
||||
@recordings = Recording.find(:all,
|
||||
:joins => :musician_recordings,
|
||||
:select => "recordings.id, recordings.description, recordings.public",
|
||||
:conditions => ["bands_recordings.band_id='#{params[:id]}'"])
|
||||
@recordings = Recording.joins(:band_recordings)
|
||||
.where(:bands_recordings => {:band_id => "#{params[:id]}"})
|
||||
end
|
||||
|
||||
respond_with @recordings, responder: ApiResponder, :status => 200
|
||||
|
|
@ -105,7 +100,8 @@ class ApiBandsController < ApiController
|
|||
@recording = Recording.save(params[:recording_id],
|
||||
params[:public],
|
||||
params[:description],
|
||||
params[:id],
|
||||
params[:genres],
|
||||
current_user.id,
|
||||
params[:id],
|
||||
true)
|
||||
|
||||
|
|
@ -116,6 +112,7 @@ class ApiBandsController < ApiController
|
|||
@recording = Recording.save(params[:recording_id],
|
||||
params[:public],
|
||||
params[:description],
|
||||
params[:genres],
|
||||
current_user.id,
|
||||
params[:id],
|
||||
false)
|
||||
|
|
@ -124,7 +121,7 @@ class ApiBandsController < ApiController
|
|||
end
|
||||
|
||||
def recording_destroy
|
||||
@band = Band.find_by_id(params[:id])
|
||||
@band = Band.find(params[:id])
|
||||
auth_band_member(@band, current_user)
|
||||
|
||||
@recording = Recording.find(params[:recording_id])
|
||||
|
|
|
|||
|
|
@ -126,19 +126,15 @@ class ApiUsersController < ApiController
|
|||
hide_private = true
|
||||
end
|
||||
|
||||
select_list = "recordings.id, recordings.description, recordings.public, genres.id, genres.description"
|
||||
|
||||
if hide_private
|
||||
@recordings = Recording.find(:all,
|
||||
:joins => :musician_recordings,
|
||||
:select => "recordings.id, recordings.description, recordings.public",
|
||||
:conditions => ["musicians_recordings.user_id='#{params[:id]}' AND public=true"])
|
||||
@recordings = Recording.joins(:musician_recordings)
|
||||
.where(:musicians_recordings => {:user_id => "#{params[:id]}"}, :public => true)
|
||||
|
||||
#.paginate(page: params[:page])
|
||||
else
|
||||
@recordings = Recording.find(:all,
|
||||
:joins => :musician_recordings,
|
||||
:select => "recordings.id, recordings.description, recordings.public",
|
||||
:conditions => ["musicians_recordings.user_id='#{params[:id]}'"])
|
||||
@recordings = Recording.joins(:musician_recordings)
|
||||
.where(:musicians_recordings => {:user_id => "#{params[:id]}"})
|
||||
end
|
||||
|
||||
respond_with @recordings, responder: ApiResponder, :status => 200
|
||||
|
|
@ -165,6 +161,7 @@ class ApiUsersController < ApiController
|
|||
@recording = Recording.save(params[:recording_id],
|
||||
params[:public],
|
||||
params[:description],
|
||||
params[:genres],
|
||||
current_user.id,
|
||||
params[:id],
|
||||
false)
|
||||
|
|
@ -177,6 +174,7 @@ class ApiUsersController < ApiController
|
|||
@recording = Recording.save(params[:recording_id],
|
||||
params[:public],
|
||||
params[:description],
|
||||
params[:genres],
|
||||
current_user.id,
|
||||
params[:id],
|
||||
false)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
object @recordings
|
||||
collection @recordings
|
||||
|
||||
extends "api_bands/recording_show"
|
||||
attributes :id, :description, :public
|
||||
|
||||
node :genres do |recording|
|
||||
unless recording.genres.nil? || recording.genres.size == 0
|
||||
child :genres => :genres do
|
||||
attributes :id, :description
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
object @recording
|
||||
|
||||
attributes :id, :description, :public
|
||||
attributes :id, :description, :public
|
||||
|
||||
unless @recording.genres.nil? || @recording.genres.size == 0
|
||||
child :genres => :genres do
|
||||
attributes :id, :description
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@ unless @band.users.nil? || @band.users.size == 0
|
|||
node :instruments do |user|
|
||||
unless user.instruments.nil? || user.instruments.size == 0
|
||||
child :musician_instruments => :instruments do
|
||||
attributes :id, :description, :proficiency_level, :priority
|
||||
attributes :instrument_id, :description, :proficiency_level, :priority
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
object @recordings
|
||||
collection @recordings
|
||||
|
||||
extends "api_users/recording_show"
|
||||
attributes :id, :description, :public
|
||||
|
||||
node :genres do |recording|
|
||||
unless recording.genres.nil? || recording.genres.size == 0
|
||||
child :genres => :genres do
|
||||
attributes :id, :description
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,3 +1,9 @@
|
|||
object @recording
|
||||
|
||||
attributes :id, :description, :public
|
||||
attributes :id, :description, :public
|
||||
|
||||
unless @recording.genres.nil? || @recording.genres.size == 0
|
||||
child :genres => :genres do
|
||||
attributes :id, :description
|
||||
end
|
||||
end
|
||||
|
|
@ -82,5 +82,8 @@ module SampleApp
|
|||
# if an inconsistency is detected'
|
||||
config.elasticsearch_verify_mode = "autorepair"
|
||||
|
||||
# API key for filepicker.io gem
|
||||
config.filepicker_rails.api_key = "AhUoVoBZSLirP3esyCl7Zz"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ describe "Band API", :type => :api do
|
|||
end
|
||||
|
||||
########################## RECORDINGS #########################
|
||||
def create_band_recording(authenticated_user, band_id, description, public)
|
||||
post "/api/bands/#{band_id}/recordings.json", { :description => description, :public => public }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
def create_band_recording(authenticated_user, band_id, description, public, genres)
|
||||
post "/api/bands/#{band_id}/recordings.json", { :description => description, :public => public, :genres => genres }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
return last_response
|
||||
end
|
||||
|
||||
|
|
@ -246,6 +246,8 @@ describe "Band API", :type => :api do
|
|||
recipient = FactoryGirl.create(:fan)
|
||||
last_response = create_band_invitation(band.id, recipient.id)
|
||||
last_response.status.should == 400
|
||||
error_msg = JSON.parse(last_response.body)
|
||||
error_msg["message"].should == BandInvitation::BAND_INVITATION_FAN_RECIPIENT_ERROR
|
||||
|
||||
# test receiver relationships
|
||||
recipient.received_band_invitations.size.should == 0
|
||||
|
|
@ -277,6 +279,13 @@ describe "Band API", :type => :api do
|
|||
end
|
||||
|
||||
context "when logged in as user who is not in band A" do
|
||||
before(:each) do
|
||||
login(user.email, user.password, 200, true)
|
||||
band.genres << Genre.find("hip hop")
|
||||
band.genres << Genre.find("african")
|
||||
band.genres << Genre.find("country")
|
||||
end
|
||||
|
||||
it "should not allow user to update attributes of band A" do
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -66,15 +66,15 @@ describe "User API", :type => :api do
|
|||
end
|
||||
|
||||
########################## RECORDINGS #########################
|
||||
def create_user_recording(authenticated_user, source_user, description, public)
|
||||
def create_user_recording(authenticated_user, source_user, description, public, genres)
|
||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||
post "/api/users/#{source_user.id}/recordings.json", { :description => description, :public => public }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
post "/api/users/#{source_user.id}/recordings.json", { :description => description, :public => public, :genres => genres }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
return last_response
|
||||
end
|
||||
|
||||
def update_user_recording(authenticated_user, source_user, recording_id, description, public)
|
||||
def update_user_recording(authenticated_user, source_user, recording_id, description, public, genres)
|
||||
login(authenticated_user.email, authenticated_user.password, 200, true)
|
||||
post "/api/users/#{source_user.id}/recordings/#{recording_id}.json", { :description => description, :public => public }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
post "/api/users/#{source_user.id}/recordings/#{recording_id}.json", { :description => description, :public => public, :genres => genres }.to_json, "CONTENT_TYPE" => 'application/json'
|
||||
return last_response
|
||||
end
|
||||
|
||||
|
|
@ -294,7 +294,7 @@ describe "User API", :type => :api do
|
|||
it "should allow musician to create recordings" do
|
||||
# create public recording
|
||||
public_description = "My Public Recording"
|
||||
last_response = create_user_recording(user, user, public_description, true)
|
||||
last_response = create_user_recording(user, user, public_description, true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
recording = JSON.parse(last_response.body)
|
||||
recording["description"].should == public_description
|
||||
|
|
@ -302,14 +302,16 @@ describe "User API", :type => :api do
|
|||
|
||||
# create private recording
|
||||
private_description = "My Private Recording"
|
||||
last_response = create_user_recording(user, user, private_description, false)
|
||||
last_response = create_user_recording(user, user, private_description, false, ["rock"])
|
||||
last_response.status.should == 201
|
||||
private_recording = JSON.parse(last_response.body)
|
||||
private_recording["description"].should == private_description
|
||||
private_recording["public"].should == false
|
||||
private_recording["genres"].size.should == 1
|
||||
private_recording["genres"][0]["id"].should == "rock"
|
||||
|
||||
# update the second recording's description and public flag
|
||||
last_response = update_user_recording(user, user, private_recording["id"], "My Recording 3", true)
|
||||
# update the second recording's description, public flag, and genre
|
||||
last_response = update_user_recording(user, user, private_recording["id"], "My Recording 3", true, ["country", "hip hop"])
|
||||
last_response.status.should == 200
|
||||
recording = JSON.parse(last_response.body)
|
||||
recording["description"].should == "My Recording 3"
|
||||
|
|
@ -321,22 +323,24 @@ describe "User API", :type => :api do
|
|||
recording = JSON.parse(last_response.body)
|
||||
recording["description"].should == "My Recording 3"
|
||||
recording["public"].should == true
|
||||
recording["genres"].size.should == 2
|
||||
|
||||
end
|
||||
|
||||
it "should not allow fan to create recordings" do
|
||||
last_response = create_user_recording(fan, fan, "Fan Recording", true)
|
||||
last_response = create_user_recording(fan, fan, "Fan Recording", true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 403
|
||||
end
|
||||
|
||||
it "should allow creator to see public and private recordings in list" do
|
||||
# create public recording
|
||||
public_description = "My Public Recording"
|
||||
last_response = create_user_recording(user, user, public_description, true)
|
||||
last_response = create_user_recording(user, user, public_description, true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
|
||||
# create private recording
|
||||
private_description = "My Private Recording"
|
||||
last_response = create_user_recording(user, user, private_description, false)
|
||||
last_response = create_user_recording(user, user, private_description, false, ["african", "hip hop"])
|
||||
last_response.status.should == 201
|
||||
|
||||
# get all recordings as creator
|
||||
|
|
@ -348,7 +352,7 @@ describe "User API", :type => :api do
|
|||
it "should allow creator to see private recording details" do
|
||||
# create private recording
|
||||
private_description = "My Private Recording"
|
||||
last_response = create_user_recording(user, user, private_description, false)
|
||||
last_response = create_user_recording(user, user, private_description, false, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
private_recording = JSON.parse(last_response.body)
|
||||
private_recording["description"].should == private_description
|
||||
|
|
@ -362,12 +366,12 @@ describe "User API", :type => :api do
|
|||
it "should not allow non-creator to see private recordings in list" do
|
||||
# create public recording
|
||||
public_description = "My Public Recording"
|
||||
last_response = create_user_recording(user, user, public_description, true)
|
||||
last_response = create_user_recording(user, user, public_description, true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
|
||||
# create private recording
|
||||
private_description = "My Private Recording"
|
||||
last_response = create_user_recording(user, user, private_description, false)
|
||||
last_response = create_user_recording(user, user, private_description, false, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
|
||||
# get all recordings as non-creator
|
||||
|
|
@ -383,7 +387,7 @@ describe "User API", :type => :api do
|
|||
it "should not allow non-creator to see private recording details" do
|
||||
# create private recording
|
||||
private_description = "My Private Recording"
|
||||
last_response = create_user_recording(user, user, private_description, false)
|
||||
last_response = create_user_recording(user, user, private_description, false, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
private_recording = JSON.parse(last_response.body)
|
||||
private_recording["description"].should == private_description
|
||||
|
|
@ -396,7 +400,7 @@ describe "User API", :type => :api do
|
|||
|
||||
it "should allow user to create favorites" do
|
||||
# create recording first
|
||||
last_response = create_user_recording(user, user, "My Recording", true)
|
||||
last_response = create_user_recording(user, user, "My Recording", true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
recording = JSON.parse(last_response.body)
|
||||
|
||||
|
|
@ -416,7 +420,7 @@ describe "User API", :type => :api do
|
|||
|
||||
it "should not allow user to create favorite for another user" do
|
||||
# create recording first
|
||||
last_response = create_user_recording(user, user, "My Recording", true)
|
||||
last_response = create_user_recording(user, user, "My Recording", true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
recording = JSON.parse(last_response.body)
|
||||
|
||||
|
|
@ -427,7 +431,7 @@ describe "User API", :type => :api do
|
|||
|
||||
it "should allow user to delete favorites" do
|
||||
# create recording first
|
||||
last_response = create_user_recording(user, user, "My Recording", true)
|
||||
last_response = create_user_recording(user, user, "My Recording", true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
recording = JSON.parse(last_response.body)
|
||||
|
||||
|
|
@ -444,7 +448,7 @@ describe "User API", :type => :api do
|
|||
|
||||
it "should not allow user to delete another user's favorites" do
|
||||
# create recording first
|
||||
last_response = create_user_recording(user, user, "My Recording", true)
|
||||
last_response = create_user_recording(user, user, "My Recording", true, ["african", "hip hop", "country"])
|
||||
last_response.status.should == 201
|
||||
recording = JSON.parse(last_response.body)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue