Continuation of previous commit

This commit is contained in:
Joseph Method 2010-10-17 19:07:54 -04:00
parent b58b6d380b
commit e3e4a6b319
4 changed files with 14 additions and 2 deletions

View file

@ -47,8 +47,13 @@ class RequestsController < ApplicationController
begin begin
@request = current_user.send_friend_request_to(rel_hash[:friend], aspect) @request = current_user.send_friend_request_to(rel_hash[:friend], aspect)
rescue Exception => e rescue Exception => e
raise e unless e.message.include? "already" if e.message.include? "yourself"
flash[:notice] = I18n.t 'requests.create.already_friends', :destination_url => params[:request][:destination_url] 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 respond_with :location => aspect
return return
end end

View file

@ -225,6 +225,7 @@ en:
ignore: "Ignored friend request." ignore: "Ignored friend request."
create: create:
error: "No diaspora seed found with this email!" error: "No diaspora seed found with this email!"
yourself: "You cannot befriend yourself!"
already_friends: "You are already friends with %{destination_url}!" already_friends: "You are already friends with %{destination_url}!"
success: "A friend request was sent to %{destination_url}." success: "A friend request was sent to %{destination_url}."
horribly_wrong: "Something went horribly wrong." horribly_wrong: "Something went horribly wrong."

View file

@ -7,6 +7,7 @@ module Diaspora
module Friending module Friending
def send_friend_request_to(desired_friend, aspect) def send_friend_request_to(desired_friend, aspect)
# should have different exception types for these? # 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{ raise "You have already sent a friend request to that person!" if self.pending_requests.detect{
|x| x.destination_url == desired_friend.receive_url } |x| x.destination_url == desired_friend.receive_url }
raise "You are already friends with that person!" if self.friends.detect{ raise "You are already friends with that person!" if self.friends.detect{

View file

@ -54,6 +54,11 @@ describe User do
proc { user.send_friend_request_to(friend, aspect) }.should raise_error proc { user.send_friend_request_to(friend, aspect) }.should raise_error
end 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 describe 'multiple users accepting/rejecting the same person' do
before do before do