diff --git a/app/models/request.rb b/app/models/request.rb index dbf9a62fb..3fce59fa9 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -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 diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index 5074d38d6..f5c9a5233 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -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 diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index aa975a9f0..2762bf2ee 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -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