RS, IZ; receiving a request no longer overwrites the group it is destined for, specs pass

This commit is contained in:
ilya 2010-08-13 10:55:18 -07:00
parent 23fc799b4d
commit 1fcb033b68
7 changed files with 54 additions and 34 deletions

View file

@ -45,7 +45,6 @@ class Request
save save
end end
def set_pending_friend def set_pending_friend
p = Person.first(:id => self.person.id) p = Person.first(:id => self.person.id)

View file

@ -85,9 +85,10 @@ class User
end end
def receive_friend_request(friend_request) def receive_friend_request(friend_request)
Rails.logger.debug("receiving friend request #{friend_request.to_json}") Rails.logger.info("receiving friend request #{friend_request.to_json}")
if request_from_me?(friend_request) if request_from_me?(friend_request)
activate_friend(friend_request.person, friend_request.group_id) group = self.groups.first(:id => friend_request.group_id)
activate_friend(friend_request.person, group)
Rails.logger.info("#{self.real_name}'s friend request has been accepted") Rails.logger.info("#{self.real_name}'s friend request has been accepted")
friend_request.destroy friend_request.destroy
@ -136,6 +137,7 @@ class User
group.people << person group.people << person
friends << person friends << person
group.save group.save
save
end end
def request_from_me?(request) def request_from_me?(request)
@ -154,6 +156,8 @@ class User
person.serialized_key ||= object.exported_key person.serialized_key ||= object.exported_key
object.person = person object.person = person
object.person.save object.person.save
old_request = Request.first(:id => object.id)
object.group_id = old_request.group_id if old_request
object.save object.save
receive_friend_request(object) receive_friend_request(object)
elsif object.is_a? Profile elsif object.is_a? Profile

View file

@ -16,9 +16,4 @@ describe ApplicationHelper do
person_url(@user).should == "/users/#{@user.id}" person_url(@user).should == "/users/#{@user.id}"
end end
it 'should be able to give me the terse url for webfinger' do
@user.person.url = "http://example.com/"
terse_url( @user.person.url ).should == 'example.com'
end
end end

View file

@ -0,0 +1,15 @@
require File.dirname(__FILE__) + '/../spec_helper'
include PublicsHelper
describe PublicsHelper do
before do
@user = Factory.create(:user)
@person = Factory.create(:person)
end
it 'should be able to give me the terse url for webfinger' do
@user.person.url = "http://example.com/"
terse_url( @user.person.url ).should == 'example.com'
end
end

View file

@ -10,6 +10,7 @@ describe Diaspora::Parser do
@user = Factory.create(:user, :email => "bob@aol.com") @user = Factory.create(:user, :email => "bob@aol.com")
@group = @user.group(:name => 'spies') @group = @user.group(:name => 'spies')
@person = Factory.create(:person_with_private_key, :email => "bill@gates.com") @person = Factory.create(:person_with_private_key, :email => "bill@gates.com")
@user2 = Factory.create(:user)
end end
describe 'with encryption' do describe 'with encryption' do
before do before do
@ -70,15 +71,16 @@ describe Diaspora::Parser do
end end
it "should create a new person upon getting a person request" do it "should create a new person upon getting a person request" do
person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person) request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id original_person_id = @person.id
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
@person.destroy @person.destroy
Person.all.count.should be 1 Person.all.count.should == person_count -1
@user.receive xml @user.receive xml
Person.all.count.should be 2 Person.all.count.should == person_count
Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true
url = "http://" + request.callback_url.split("/")[2] + "/" url = "http://" + request.callback_url.split("/")[2] + "/"
@ -86,16 +88,16 @@ describe Diaspora::Parser do
end end
it "should not create a new person if the person is already here" do it "should not create a new person if the person is already here" do
@user2 = Factory.create(:user) person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person) request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person)
original_person_id = @user2.person.id original_person_id = @user2.person.id
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
Person.all.count.should be 3 Person.all.count.should be person_count
@user.receive xml @user.receive xml
Person.all.count.should be 3 Person.all.count.should be person_count
@user2.reload @user2.reload
@user2.person.reload @user2.person.reload
@ -106,30 +108,34 @@ describe Diaspora::Parser do
end end
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
request = @user.send_friend_request_to( @person.receive_url, @group.id) request = @user.send_friend_request_to( @user2.receive_url, @group.id)
request.reverse @user request.reverse @user2
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
@person.destroy @user2.person.destroy
@user2.destroy
@user.receive xml @user.receive xml
new_person = Person.first(:url => @person.url) new_person = Person.first(:url => @user2.person.url)
new_person.nil?.should be false new_person.nil?.should be false
@user.reload @user.reload
@group.reload
@group.people.include?(new_person).should be true
@user.friends.include?(new_person).should be true @user.friends.include?(new_person).should be true
end end
it 'should process retraction for a person' do it 'should process retraction for a person' do
person_count = Person.all.count
retraction = Retraction.for(@user) retraction = Retraction.for(@user)
request = retraction.to_diaspora_xml request = retraction.to_diaspora_xml
Person.count.should == 2 Person.count.should == person_count
@user.receive request @user.receive request
Person.count.should == 1 Person.count.should == person_count-1
end end
it 'should marshal a profile for a person' do it 'should marshal a profile for a person' do

View file

@ -1,7 +1,10 @@
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
describe Request do describe Request do
before do
@user = Factory.create(:user)
@group = @user.group(:name => "dudes")
end
it 'should require a destination and callback url' do it 'should require a destination and callback url' do
person_request = Request.new person_request = Request.new
person_request.valid?.should be false person_request.valid?.should be false
@ -11,28 +14,26 @@ describe Request do
end end
it 'should generate xml for the User as a Person' do it 'should generate xml for the User as a Person' do
user = Factory.create(:user)
request = user.send_friend_request_to "http://www.google.com/" request = @user.send_friend_request_to "http://www.google.com/", @group.id
xml = request.to_xml.to_s xml = request.to_xml.to_s
xml.include?(user.person.email).should be true xml.include?(@user.person.email).should be true
xml.include?(user.url).should be true xml.include?(@user.url).should be true
xml.include?(user.profile.first_name).should be true xml.include?(@user.profile.first_name).should be true
xml.include?(user.profile.last_name).should be true xml.include?(@user.profile.last_name).should be true
end end
it 'should allow me to see only friend requests sent to me' do it 'should allow me to see only friend requests sent to me' do
user = Factory.create(:user)
remote_person = Factory.build(:person, :email => "robert@grimm.com", :url => "http://king.com/") remote_person = Factory.build(:person, :email => "robert@grimm.com", :url => "http://king.com/")
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save Request.instantiate(:into => @group.id, :from => @user.person, :to => remote_person.receive_url).save
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save Request.instantiate(:into => @group.id, :from => @user.person, :to => remote_person.receive_url).save
Request.instantiate(:from => user.person, :to => remote_person.receive_url).save Request.instantiate(:into => @group.id, :from => @user.person, :to => remote_person.receive_url).save
Request.instantiate(:from => remote_person, :to => user.receive_url).save Request.instantiate(:into => @group.id, :from => remote_person, :to => @user.receive_url).save
Request.for_user(user).all.count.should == 1 Request.for_user(@user).all.count.should == 1
end end
end end

View file

@ -6,7 +6,7 @@ describe 'user encryption' do
before do before do
unstub_mocha_stubs unstub_mocha_stubs
@user = Factory.create(:user) @user = Factory.create(:user)
@user.save @group = @user.group(:name => 'dudes')
@person = Factory.create(:person_with_private_key, @person = Factory.create(:person_with_private_key,
:profile => Profile.new(:first_name => 'Remote', :profile => Profile.new(:first_name => 'Remote',
:last_name => 'Friend'), :last_name => 'Friend'),
@ -32,7 +32,7 @@ describe 'user encryption' do
describe 'key exchange on friending' do describe 'key exchange on friending' do
it 'should send over a public key' do it 'should send over a public key' do
message_queue.stub!(:add_post_request) message_queue.stub!(:add_post_request)
request = @user.send_friend_request_to("http://example.com/") request = @user.send_friend_request_to("http://example.com/", @group.id)
request.to_diaspora_xml.include?( @user.export_key).should be true request.to_diaspora_xml.include?( @user.export_key).should be true
end end