you can no longer send a request to yourself at the Request model level
This commit is contained in:
parent
ef083c6770
commit
7fc9d239b9
3 changed files with 14 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ class Request
|
|||
validate :not_already_connected_if_sent
|
||||
validate :not_already_connected_if_not_sent
|
||||
validate :no_pending_request, :if => :sent
|
||||
validate :not_friending_yourself
|
||||
|
||||
#before_validation :clean_link
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ class Request
|
|||
def not_already_connected_if_sent
|
||||
if self.sent
|
||||
if Contact.first(:user_id => self.from.owner_id, :person_id => self.to.id)
|
||||
errors[:base] << 'You have already connected to this person!'
|
||||
errors[:base] << 'You have already connected to this person'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -103,8 +104,14 @@ class Request
|
|||
def not_already_connected_if_not_sent
|
||||
unless self.sent
|
||||
if Contact.first(:user_id => self.to.owner_id, :person_id => self.from.id)
|
||||
errors[:base] << 'You have already connected to this person!'
|
||||
errors[:base] << 'You have already connected to this person'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def not_friending_yourself
|
||||
if self.to == self.from
|
||||
errors[:base] << 'You can not friend yourself'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ describe RequestsController do
|
|||
|
||||
describe '#destroy' do
|
||||
before do
|
||||
|
||||
|
||||
@other_user.send_contact_request_to(@user.person, @other_user.aspects.first)
|
||||
@user.reload # so it can find its pending requests.
|
||||
@friend_request = @user.pending_requests.first
|
||||
|
|
|
|||
|
|
@ -41,6 +41,11 @@ describe Request do
|
|||
connect_users(user, aspect, user2, user2.aspects.create(:name => 'new aspect'))
|
||||
@request.should_not be_valid
|
||||
end
|
||||
|
||||
it 'is not to yourself' do
|
||||
@request = Request.instantiate(:from => user.person, :to => user.person, :into => aspect)
|
||||
@request.should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe 'scopes' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue