vrfs1008: fixed failing test

This commit is contained in:
Jonathan Kolyer 2014-01-14 14:06:43 -06:00
parent a32697b2e4
commit ccdad1c81a
1 changed files with 17 additions and 25 deletions

View File

@ -37,34 +37,26 @@ class ApiInvitationsController < ApiController
sender = current_user
join_request = JoinRequest.find(params[:join_request]) unless params[:join_request].nil?
@invitation = Invitation.limit(1)
.where(:receiver_id => params[:receiver],
:sender_id => current_user.id,
:music_session_id => params[:music_session])
.first
if @invitation
@invitation = Invitation.new
@invitation.music_session = music_session
@invitation.sender = sender
@invitation.receiver = receiver
@invitation.join_request = join_request
@invitation.save
unless @invitation.errors.any?
User.save_session_settings(current_user, music_session)
# send notification
Notification.send_session_invitation(receiver, current_user, music_session.id)
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
else
@invitation = Invitation.new
@invitation.music_session = music_session
@invitation.sender = sender
@invitation.receiver = receiver
@invitation.join_request = join_request
@invitation.save
unless @invitation.errors.any?
User.save_session_settings(current_user, music_session)
# send notification
Notification.send_session_invitation(receiver, current_user, music_session.id)
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
else
# we have to do this because api_invitation_detail_url will fail with a bad @invitation
response.status = :unprocessable_entity
respond_with @invitation
end
# we have to do this because api_invitation_detail_url will fail with a bad @invitation
response.status = :unprocessable_entity
respond_with @invitation
end
end
def show