Skip to content
Extraits de code Groupes Projets
Valider 11a8b8f3 rédigé par ilya's avatar ilya
Parcourir les fichiers

MS IZ testing many the friend request user methods

parent 355aba75
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -23,9 +23,9 @@ class PublicsController < ApplicationController
end
def receive
user = Person.first(:id => params[:id]).owner
@user = Person.first(:id => params[:id]).owner
Rails.logger.debug "PublicsController has received: #{params[:xml]}"
store_objects_from_xml params[:xml], user
store_objects_from_xml params[:xml], @user
render :nothing => true
end
......
......@@ -68,9 +68,10 @@ class User
def ignore_friend_request(friend_request_id)
request = Request.first(:id => friend_request_id)
person = request.person
person.user_refs -= 1
pending_requests.delete(request)
save
person.destroy unless person.user_refs > 0
(person.user_refs > 0 || person.owner.nil? == false) ? person.save : person.destroy
request.destroy
end
......@@ -81,6 +82,8 @@ class User
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
friend_request.destroy
else
friend_request.person.user_refs += 1
friend_request.person.save
pending_requests << friend_request
save
......@@ -98,7 +101,7 @@ class User
if bad_friend
Retraction.for(self).push_to_url(bad_friend.receive_url)
bad_friend.update_attributes(:user_refs => bad_friend.user_refs - 1)
bad_friend.destroy if bad_friend.user_refs == 0
(bad_friend.user_refs > 0 || bad_friend.owner.nil? == false) ? bad_friend.save : bad_friend.destroy
end
end
......
require File.dirname(__FILE__) + '/../spec_helper'
describe PublicsController do
render_views
......@@ -32,26 +31,37 @@ describe PublicsController do
@user2 = Factory.create(:user)
@user2.person.save
req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
@user3 = Factory.create(:user)
@user3.person.save
req = @user2.send_friend_request_to(@user.person.url)
#req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
@xml = Request.build_xml_for [req]
req.delete
@user2.reload
puts @user2.inspect
@user2.pending_requests.count.should be 1
end
it 'should save requests for the specified user (LOCAL)' do
it 'should add the pending request to the right user, person exists locally' do
@user2.delete
post :receive, :id => @user.person.id, :xml => @xml
@user.reload
@user.pending_requests.size.should be 1
assigns(:user).should eq(@user)
end
it 'should save requests for the specified user (REMOTE)' do
it 'should add the pending request to the right user, person does not exist locally' do
@user2.person.delete
@user2.delete
post :receive, :id => @user.person.id, :xml => @xml
@user.reload
@user.pending_requests.size.should be 1
assigns(:user).should eq(@user)
end
......
require File.dirname(__FILE__) + '/../spec_helper'
include Diaspora::Parser
describe User do
before do
@user = Factory.create(:user)
end
it "should be a person" do
n = Person.count
Factory.create(:user)
Person.count.should == n+1
end
it 'should instantiate with a person and be valid' do
user = User.instantiate(:email => "bob@bob.com",
:password => "password",
......@@ -34,7 +30,6 @@ describe User do
Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id)
Request.for_user(@user).all.count.should == 0
#Person.where(:id => friend.id).first.active.should == true
end
it 'should be able to ignore a pending friend request' do
......@@ -43,7 +38,6 @@ describe User do
r.save
Person.count.should == 2
#friend.active.should == false
@user.ignore_friend_request(r.id)
......@@ -67,31 +61,147 @@ describe User do
@user.terse_url.should == 'example.com'
end
it 'should get the pending friends' do
person_one = Factory.create :person
person_two = Factory.create :person
@user.pending_requests.empty?.should be true
@user.friends.empty?.should be true
request = Request.instantiate(:to => @user.receive_url, :from => person_one)
person_one.destroy
@user.receive_friend_request request
@user.pending_requests.size.should be 1
@user.friends.size.should be 0
describe 'multiple users accepting/rejecting the same person' do
before do
@person_one = Factory.create :person
@person_one.save
@user2 = Factory.create :user
@user.pending_requests.empty?.should be true
@user.friends.empty?.should be true
@user2.pending_requests.empty?.should be true
@user2.friends.empty?.should be true
@request = Request.instantiate(:to => @user.receive_url, :from => @person_one)
@request_two = Request.instantiate(:to => @user2.receive_url, :from => @person_one)
@request_three = Request.instantiate(:to => @user2.receive_url, :from => @user.person)
@req_xml = Request.build_xml_for [@request]
@req_two_xml = Request.build_xml_for [@request_two]
@req_three_xml = Request.build_xml_for [@request_three]
@request.destroy
@request_two.destroy
@request_three.destroy
end
it 'should befriend the user other user on the same pod' do
store_objects_from_xml @req_three_xml, @user2
@user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_three.id
@user2.friends.include?(@user.person).should be true
Person.all.count.should be 3
end
it 'should not delete the ignored user on the same pod' do
store_objects_from_xml @req_three_xml, @user2
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_three.id
@user2.friends.include?(@user.person).should be false
Person.all.count.should be 3
end
it 'should both users should befriend the same person' do
store_objects_from_xml @req_xml, @user
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id
@user.friends.include?(@person_one).should be true
store_objects_from_xml @req_two_xml, @user2
@user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_two.id
@user2.friends.include?(@person_one).should be true
Person.all.count.should be 3
end
it 'should keep the person around if one of the users rejects him' do
store_objects_from_xml @req_xml, @user
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id
@user.friends.include?(@person_one).should be true
store_objects_from_xml @req_two_xml, @user2
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_two.id
@user2.friends.include?(@person_one).should be false
Person.all.count.should be 3
end
it 'should not keep the person around if the users ignores them' do
store_objects_from_xml @req_xml, @user
@user.pending_requests.size.should be 1
@user.ignore_friend_request @user.pending_requests.first.id
@user.friends.include?(@person_one).should be false
store_objects_from_xml @req_two_xml, @user2
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @user2.pending_requests.first.id#@request_two.id
@user2.friends.include?(@person_one).should be false
Person.all.count.should be 2
end
end
describe 'a user accepting rejecting multiple people' do
before do
@person_one = Factory.create :person
@person_two = Factory.create :person
@user.pending_requests.empty?.should be true
@user.friends.empty?.should be true
@request = Request.instantiate(:to => @user.receive_url, :from => @person_one)
@request_two = Request.instantiate(:to => @user.receive_url, :from => @person_two)
end
request_two = Request.instantiate(:to => @user.receive_url, :from => person_two)
person_two.destroy
@user.receive_friend_request request_two
@user.pending_requests.size.should be 2
@user.friends.size.should be 0
@user.accept_friend_request request.id
@user.pending_requests.size.should be 1
@user.friends.size.should be 1
after do
@user.receive_friend_request @request
@person_two.destroy
@user.pending_requests.size.should be 1
@user.friends.size.should be 0
@user.receive_friend_request @request_two
@user.pending_requests.size.should be 2
@user.friends.size.should be 0
@user.accept_friend_request @request.id
@user.pending_requests.size.should be 1
@user.friends.size.should be 1
@user.friends.include?(@person_one).should be true
@user.ignore_friend_request @request_two.id
@user.pending_requests.size.should be 0
@user.friends.size.should be 1
@user.friends.include?(@person_two).should be false
end
it 'should do accept reject for people not on the pod' do
@person_one.destroy
@person_two.destroy
end
it 'should do accept reject for people on the pod' do
end
it 'should do accept reject for mixed people on the pod' do
@person_two.destroy
end
@user.ignore_friend_request request_two.id
@user.pending_requests.size.should be 0
@user.friends.size.should be 1
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter