Skip to content
Snippets Groups Projects
Commit e3e4a6b3 authored by Joseph Method's avatar Joseph Method
Browse files

Continuation of previous commit

parent b58b6d38
No related branches found
No related tags found
No related merge requests found
......@@ -47,8 +47,13 @@ class RequestsController < ApplicationController
begin
@request = current_user.send_friend_request_to(rel_hash[:friend], aspect)
rescue Exception => e
raise e unless e.message.include? "already"
flash[:notice] = I18n.t 'requests.create.already_friends', :destination_url => params[:request][:destination_url]
if e.message.include? "yourself"
flash[:notice] = I18n.t 'requests.create.yourself', :destination_url => params[:request][:destination_url]
elsif e.message.include? "already"
flash[:notice] = I18n.t 'requests.create.already_friends', :destination_url => params[:request][:destination_url]
else
raise e
end
respond_with :location => aspect
return
end
......
......@@ -225,6 +225,7 @@ en:
ignore: "Ignored friend request."
create:
error: "No diaspora seed found with this email!"
yourself: "You cannot befriend yourself!"
already_friends: "You are already friends with %{destination_url}!"
success: "A friend request was sent to %{destination_url}."
horribly_wrong: "Something went horribly wrong."
......@@ -7,6 +7,7 @@ module Diaspora
module Friending
def send_friend_request_to(desired_friend, aspect)
# should have different exception types for these?
raise "You cannot befriend yourself" if desired_friend.nil?
raise "You have already sent a friend request to that person!" if self.pending_requests.detect{
|x| x.destination_url == desired_friend.receive_url }
raise "You are already friends with that person!" if self.friends.detect{
......
......@@ -54,6 +54,11 @@ describe User do
proc { user.send_friend_request_to(friend, aspect) }.should raise_error
end
it 'should not be able to friend request yourself' do
proc { user.send_friend_request_to(nil, aspect) }.should raise_error(RuntimeError, /befriend yourself/)
end
describe 'multiple users accepting/rejecting the same person' do
before do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment