comment old recording code

This commit is contained in:
Brian Smith 2013-02-16 16:19:08 -05:00
parent 69fd8f7cfa
commit 800f4d7de0
3 changed files with 193 additions and 193 deletions

View File

@ -327,56 +327,56 @@ class ApiUsersController < ApiController
end
###################### RECORDINGS #######################
def recording_index
@recordings = User.recording_index(current_user, params[:id])
respond_with @recordings, responder: ApiResponder, :status => 200
end
# def recording_index
# @recordings = User.recording_index(current_user, params[:id])
# respond_with @recordings, responder: ApiResponder, :status => 200
# end
def recording_show
hide_private = false
# def recording_show
# hide_private = false
# hide private recordings from anyone but the current user
if current_user.id != params[:id]
hide_private = true
end
# # hide private recordings from anyone but the current user
# if current_user.id != params[:id]
# hide_private = true
# end
@recording = Recording.find(params[:recording_id])
if !@recording.public && hide_private
render :json => { :message => "You are not allowed to access this recording." }, :status => 403
#respond_with "You are not allowed to access this recording.", responder: ApiResponder, :status => 403
else
respond_with @recording, responder: ApiResponder, :status => 200
end
end
# @recording = Recording.find(params[:recording_id])
# if !@recording.public && hide_private
# render :json => { :message => "You are not allowed to access this recording." }, :status => 403
# #respond_with "You are not allowed to access this recording.", responder: ApiResponder, :status => 403
# else
# respond_with @recording, responder: ApiResponder, :status => 200
# end
# end
def recording_create
@recording = Recording.save(params[:recording_id],
params[:public],
params[:description],
params[:genres],
current_user.id,
params[:id],
false)
# def recording_create
# @recording = Recording.save(params[:recording_id],
# params[:public],
# params[:description],
# params[:genres],
# current_user.id,
# params[:id],
# false)
@user = current_user
respond_with @recording, responder: ApiResponder, :status => 201, :location => api_recording_detail_url(@user, @recording)
end
# @user = current_user
# respond_with @recording, responder: ApiResponder, :status => 201, :location => api_recording_detail_url(@user, @recording)
# end
def recording_update
@recording = Recording.save(params[:recording_id],
params[:public],
params[:description],
params[:genres],
current_user.id,
params[:id],
false)
# def recording_update
# @recording = Recording.save(params[:recording_id],
# params[:public],
# params[:description],
# params[:genres],
# current_user.id,
# params[:id],
# false)
respond_with @recording, responder: ApiResponder, :status => 200
end
# respond_with @recording, responder: ApiResponder, :status => 200
# end
def recording_destroy
@recording = Recording.find(params[:recording_id])
@recording.delete
respond_with responder: ApiResponder, :status => 204
end
# def recording_destroy
# @recording = Recording.find(params[:recording_id])
# @recording.delete
# respond_with responder: ApiResponder, :status => 204
# end
end

View File

@ -122,11 +122,11 @@ SampleApp::Application.routes.draw do
match '/users/:id/band_invitations/:invitation_id' => 'api_users#band_invitation_update', :via => :post
# user recordings
match '/users/:id/recordings' => 'api_users#recording_index', :via => :get
match '/users/:id/recordings/:recording_id' => 'api_users#recording_show', :via => :get, :as => 'api_recording_detail'
match '/users/:id/recordings' => 'api_users#recording_create', :via => :post
match '/users/:id/recordings/:recording_id' => 'api_users#recording_update', :via => :post
match '/users/:id/recordings/:recording_id' => 'api_users#recording_destroy', :via => :delete
# match '/users/:id/recordings' => 'api_users#recording_index', :via => :get
# match '/users/:id/recordings/:recording_id' => 'api_users#recording_show', :via => :get, :as => 'api_recording_detail'
# match '/users/:id/recordings' => 'api_users#recording_create', :via => :post
# match '/users/:id/recordings/:recording_id' => 'api_users#recording_update', :via => :post
# match '/users/:id/recordings/:recording_id' => 'api_users#recording_destroy', :via => :delete
# bands
match '/bands' => 'api_bands#index', :via => :get

View File

@ -465,177 +465,177 @@ describe "User API", :type => :api do
end
######################### RECORDINGS ########################
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, ["african"])
last_response.status.should == 201
recording = JSON.parse(last_response.body)
recording["description"].should == public_description
recording["public"].should == true
# 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, ["african"])
# last_response.status.should == 201
# recording = JSON.parse(last_response.body)
# recording["description"].should == public_description
# recording["public"].should == true
# create private recording
private_description = "My Private Recording"
last_response = create_user_recording(user, user, private_description, false, ["rock"])
last_response.status.should == 201
# # create private recording
# private_description = "My Private Recording"
# 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"
# 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, public flag, and genre
last_response = update_user_recording(user, user, private_recording["id"], "My Recording 3", true, ["country"])
last_response.status.should == 200
recording = JSON.parse(last_response.body)
recording["description"].should == "My Recording 3"
recording["public"].should == 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"])
# last_response.status.should == 200
# recording = JSON.parse(last_response.body)
# recording["description"].should == "My Recording 3"
# recording["public"].should == true
# retrieve the recording details again to ensure the change took effect
last_response = get_user_recording(user, user, recording["id"])
last_response.status.should == 200
recording = JSON.parse(last_response.body)
recording["description"].should == "My Recording 3"
recording["public"].should == true
recording["genres"].size.should == 1
end
# # retrieve the recording details again to ensure the change took effect
# last_response = get_user_recording(user, user, recording["id"])
# last_response.status.should == 200
# recording = JSON.parse(last_response.body)
# recording["description"].should == "My Recording 3"
# recording["public"].should == true
# recording["genres"].size.should == 1
# end
it "should not allow fan to create recordings" do
last_response = create_user_recording(fan, fan, "Fan Recording", true, ["african"])
last_response.status.should == 403
end
# it "should not allow fan to create recordings" do
# last_response = create_user_recording(fan, fan, "Fan Recording", true, ["african"])
# 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, ["african"])
last_response.status.should == 201
# 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, ["african"])
# last_response.status.should == 201
# create private recording
private_description = "My Private Recording"
last_response = create_user_recording(user, user, private_description, false, ["african"])
last_response.status.should == 201
# # create private recording
# private_description = "My Private Recording"
# last_response = create_user_recording(user, user, private_description, false, ["african"])
# last_response.status.should == 201
# get all recordings as creator
last_response = get_user_recordings(user, user)
recordings = JSON.parse(last_response.body)
recordings.size.should == 2
end
# # get all recordings as creator
# last_response = get_user_recordings(user, user)
# recordings = JSON.parse(last_response.body)
# recordings.size.should == 2
# end
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, ["african"])
last_response.status.should == 201
private_recording = JSON.parse(last_response.body)
private_recording["description"].should == private_description
private_recording["public"].should == false
# 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, ["african"])
# last_response.status.should == 201
# private_recording = JSON.parse(last_response.body)
# private_recording["description"].should == private_description
# private_recording["public"].should == false
# attempt to get the private recording as non-creator
last_response = get_user_recording(user, user, private_recording["id"])
last_response.status.should == 200
end
# # attempt to get the private recording as non-creator
# last_response = get_user_recording(user, user, private_recording["id"])
# last_response.status.should == 200
# end
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, ["country"])
last_response.status.should == 201
# 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, ["country"])
# last_response.status.should == 201
# create private recording
private_description = "My Private Recording"
last_response = create_user_recording(user, user, private_description, false, ["country"])
last_response.status.should == 201
# # create private recording
# private_description = "My Private Recording"
# last_response = create_user_recording(user, user, private_description, false, ["country"])
# last_response.status.should == 201
# get all recordings as non-creator
last_response = get_user_recordings(fan, user)
last_response.status.should == 200
# # get all recordings as non-creator
# last_response = get_user_recordings(fan, user)
# last_response.status.should == 200
recordings = JSON.parse(last_response.body)
recordings.size.should == 1
recordings[0]["description"].should == public_description
recordings[0]["public"].should == true
end
# recordings = JSON.parse(last_response.body)
# recordings.size.should == 1
# recordings[0]["description"].should == public_description
# recordings[0]["public"].should == true
# end
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, ["country"])
last_response.status.should == 201
private_recording = JSON.parse(last_response.body)
private_recording["description"].should == private_description
private_recording["public"].should == false
# 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, ["country"])
# last_response.status.should == 201
# private_recording = JSON.parse(last_response.body)
# private_recording["description"].should == private_description
# private_recording["public"].should == false
# attempt to get the private recording as non-creator
last_response = get_user_recording(fan, user, private_recording["id"])
last_response.status.should == 403
end
# # attempt to get the private recording as non-creator
# last_response = get_user_recording(fan, user, private_recording["id"])
# last_response.status.should == 403
# end
it "should allow user to create favorites" do
# create recording first
last_response = create_user_recording(user, user, "My Recording", true, ["country"])
last_response.status.should == 201
recording = JSON.parse(last_response.body)
# it "should allow user to create favorites" do
# # create recording first
# last_response = create_user_recording(user, user, "My Recording", true, ["country"])
# last_response.status.should == 201
# recording = JSON.parse(last_response.body)
# add favorite
last_response = create_favorite(fan, fan, recording["id"])
last_response.status.should == 201
# # add favorite
# last_response = create_favorite(fan, fan, recording["id"])
# last_response.status.should == 201
# get favorites
last_response = get_favorites(fan, fan)
last_response.status.should == 200
favorites = JSON.parse(last_response.body)
favorites.size.should == 1
favorites[0]["recording_id"].should == recording["id"]
favorites[0]["description"].should == "My Recording"
favorites[0]["public"].should == true
# # get favorites
# last_response = get_favorites(fan, fan)
# last_response.status.should == 200
# favorites = JSON.parse(last_response.body)
# favorites.size.should == 1
# favorites[0]["recording_id"].should == recording["id"]
# favorites[0]["description"].should == "My Recording"
# favorites[0]["public"].should == true
# get recording
last_response = get_user_recording(user, user, recording["id"])
last_response.status.should == 200
recording_with_favorite = JSON.parse(last_response.body)
recording_with_favorite["favorite_count"].should == 1
end
# # get recording
# last_response = get_user_recording(user, user, recording["id"])
# last_response.status.should == 200
# recording_with_favorite = JSON.parse(last_response.body)
# recording_with_favorite["favorite_count"].should == 1
# end
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, ["country"])
last_response.status.should == 201
recording = JSON.parse(last_response.body)
# 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, ["country"])
# last_response.status.should == 201
# recording = JSON.parse(last_response.body)
# attempt to add favorite for another user
last_response = create_favorite(fan, user, recording["id"])
last_response.status.should == 403
end
# # attempt to add favorite for another user
# last_response = create_favorite(fan, user, recording["id"])
# last_response.status.should == 403
# end
it "should allow user to delete favorites" do
# create recording first
last_response = create_user_recording(user, user, "My Recording", true, ["country"])
last_response.status.should == 201
recording = JSON.parse(last_response.body)
# it "should allow user to delete favorites" do
# # create recording first
# last_response = create_user_recording(user, user, "My Recording", true, ["country"])
# last_response.status.should == 201
# recording = JSON.parse(last_response.body)
# delete favorite
last_response = delete_favorite(user, user, recording["id"])
last_response.status.should == 204
# # delete favorite
# last_response = delete_favorite(user, user, recording["id"])
# last_response.status.should == 204
# get favorites
last_response = get_favorites(user, user)
last_response.status.should == 200
favorites = JSON.parse(last_response.body)
favorites.size.should == 0
end
# # get favorites
# last_response = get_favorites(user, user)
# last_response.status.should == 200
# favorites = JSON.parse(last_response.body)
# favorites.size.should == 0
# end
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, ["country"])
last_response.status.should == 201
recording = JSON.parse(last_response.body)
# 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, ["country"])
# last_response.status.should == 201
# recording = JSON.parse(last_response.body)
# attempt to delete favorite as non-creator
last_response = delete_favorite(fan, user, recording["id"])
last_response.status.should == 403
end
# # attempt to delete favorite as non-creator
# last_response = delete_favorite(fan, user, recording["id"])
# last_response.status.should == 403
# end
######################### FRIENDS ########################
it "should allow user to send friend request" do