diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index f131edfc1..f0a8020f0 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -26,10 +26,9 @@ module Diaspora request end - def accept_friend_request(friend_request_id, aspect_id) - request = pending_requests.find!(friend_request_id) + def accept_friend_request(request, aspect) pending_request_ids.delete(request.id.to_id) - activate_friend(request.from, aspect_by_id(aspect_id)) + activate_friend(request.from, aspect) request.reverse_for(self) end @@ -40,8 +39,9 @@ module Diaspora end def accept_and_respond(friend_request_id, aspect_id) - requester = pending_requests.find!(friend_request_id).from - reversed_request = accept_friend_request(friend_request_id, aspect_id) + request = pending_requests.find!(friend_request_id) + requester = request.from + reversed_request = accept_friend_request(request, aspect_by_id(aspect_id)) dispatch_friend_acceptance reversed_request, requester end diff --git a/spec/models/user/friending_spec.rb b/spec/models/user/friending_spec.rb index 809928352..6203e5f67 100644 --- a/spec/models/user/friending_spec.rb +++ b/spec/models/user/friending_spec.rb @@ -60,7 +60,7 @@ describe Diaspora::UserModules::Friending do end it "should delete an accepted friend request" do - proc { user.accept_friend_request(request2_for_user.id, aspect.id) }.should change( + proc { user.accept_friend_request(request2_for_user, aspect) }.should change( user.reload.pending_requests, :count ).by(-1) end @@ -123,7 +123,7 @@ describe Diaspora::UserModules::Friending do end it 'should befriend the user other user on the same pod' do proc { - user2.accept_friend_request @received_request.id, aspect2.id + user2.accept_friend_request @received_request, aspect2 }.should_not change(Person, :count) user2.contact_for(user.person).should_not be_nil end @@ -149,15 +149,15 @@ describe Diaspora::UserModules::Friending do describe '#accept_friend_request' do it 'should both users should befriend the same person' do - user.accept_friend_request @req_to_user.id, aspect.id + user.accept_friend_request @req_to_user, aspect user.contact_for(person_one).should_not be_nil - user2.accept_friend_request @req_to_user2.id, aspect2.id + user2.accept_friend_request @req_to_user2, aspect2 user2.contact_for(person_one).should_not be_nil end it 'should keep the person around if one of the users rejects him' do - user.accept_friend_request @req_to_user.id, aspect.id + user.accept_friend_request @req_to_user, aspect user.contact_for(person_one).should_not be_nil user2.ignore_friend_request @req_to_user2.id @@ -197,7 +197,7 @@ describe Diaspora::UserModules::Friending do user.reload.pending_requests.size.should == 2 user.friends.size.should be 0 - user.accept_friend_request received_req.id, aspect.id + user.accept_friend_request received_req, aspect user.reload.pending_requests.size.should == 1 user.friends.size.should be 1 user.contact_for(person_one).should_not be_nil