Merge branch 'master' of http://github.com/tristil/diaspora into tristil-merge
This commit is contained in:
commit
f90d38bb9c
5 changed files with 39 additions and 2 deletions
|
|
@ -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"
|
||||
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{
|
||||
|
|
|
|||
25
spec/controllers/requests_controller_spec.rb
Normal file
25
spec/controllers/requests_controller_spec.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe RequestsController do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
|
||||
sign_in :user, @user
|
||||
@user.aspect(:name => "lame-os")
|
||||
end
|
||||
|
||||
it "should not error out when requesting to be friends with yourself" do
|
||||
put("create", "request" => {
|
||||
"destination_url" => @user.diaspora_handle,
|
||||
"aspect_id" => @user.aspects[0].id
|
||||
}
|
||||
)
|
||||
response.should redirect_to aspect_path(@user.aspects[0].id.to_s)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue