diff --git a/app/models/request.rb b/app/models/request.rb index f1aae6ea8..99625ad13 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -44,7 +44,6 @@ class Request self.destination_url = self.callback_url save end - def set_pending_friend p = Person.first(:id => self.person.id) diff --git a/app/models/user.rb b/app/models/user.rb index 12bc2c249..0067d6da8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -85,9 +85,10 @@ class User end 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) - 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") friend_request.destroy @@ -136,6 +137,7 @@ class User group.people << person friends << person group.save + save end def request_from_me?(request) @@ -154,6 +156,8 @@ class User person.serialized_key ||= object.exported_key object.person = person object.person.save + old_request = Request.first(:id => object.id) + object.group_id = old_request.group_id if old_request object.save receive_friend_request(object) elsif object.is_a? Profile diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 639eb254a..bb886bd83 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -15,10 +15,5 @@ describe ApplicationHelper do it "should provide a correct show path for a given user" do person_url(@user).should == "/users/#{@user.id}" 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 diff --git a/spec/helpers/publics_helper_spec.rb b/spec/helpers/publics_helper_spec.rb new file mode 100644 index 000000000..bdc9c8250 --- /dev/null +++ b/spec/helpers/publics_helper_spec.rb @@ -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 diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index ec6aa9966..d63acc578 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -10,6 +10,7 @@ describe Diaspora::Parser do @user = Factory.create(:user, :email => "bob@aol.com") @group = @user.group(:name => 'spies') @person = Factory.create(:person_with_private_key, :email => "bill@gates.com") + @user2 = Factory.create(:user) end describe 'with encryption' do before do @@ -70,15 +71,16 @@ describe Diaspora::Parser do end 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) original_person_id = @person.id xml = request.to_diaspora_xml @person.destroy - Person.all.count.should be 1 + Person.all.count.should == person_count -1 @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 url = "http://" + request.callback_url.split("/")[2] + "/" @@ -86,16 +88,16 @@ describe Diaspora::Parser do end 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) original_person_id = @user2.person.id xml = request.to_diaspora_xml - Person.all.count.should be 3 + Person.all.count.should be person_count @user.receive xml - Person.all.count.should be 3 + Person.all.count.should be person_count @user2.reload @user2.person.reload @@ -106,30 +108,34 @@ describe Diaspora::Parser do end 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 - @person.destroy + @user2.person.destroy + @user2.destroy @user.receive xml - new_person = Person.first(:url => @person.url) + new_person = Person.first(:url => @user2.person.url) new_person.nil?.should be false @user.reload + @group.reload + @group.people.include?(new_person).should be true @user.friends.include?(new_person).should be true end it 'should process retraction for a person' do + person_count = Person.all.count retraction = Retraction.for(@user) request = retraction.to_diaspora_xml - Person.count.should == 2 + Person.count.should == person_count @user.receive request - Person.count.should == 1 + Person.count.should == person_count-1 end it 'should marshal a profile for a person' do diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index f3fd9c4a5..c5b49cc64 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -1,7 +1,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Request do - + before do + @user = Factory.create(:user) + @group = @user.group(:name => "dudes") + end it 'should require a destination and callback url' do person_request = Request.new person_request.valid?.should be false @@ -11,28 +14,26 @@ describe Request do end 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.include?(user.person.email).should be true - xml.include?(user.url).should be true - xml.include?(user.profile.first_name).should be true - xml.include?(user.profile.last_name).should be true + xml.include?(@user.person.email).should be true + xml.include?(@user.url).should be true + xml.include?(@user.profile.first_name).should be true + xml.include?(@user.profile.last_name).should be true end 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/") - Request.instantiate(:from => user.person, :to => remote_person.receive_url).save - Request.instantiate(:from => user.person, :to => remote_person.receive_url).save - Request.instantiate(: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 => @user.person, :to => remote_person.receive_url).save + Request.instantiate(:into => @group.id, :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(: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 diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index f03a1edab..fde3cf5a8 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -6,7 +6,7 @@ describe 'user encryption' do before do unstub_mocha_stubs @user = Factory.create(:user) - @user.save + @group = @user.group(:name => 'dudes') @person = Factory.create(:person_with_private_key, :profile => Profile.new(:first_name => 'Remote', :last_name => 'Friend'), @@ -32,7 +32,7 @@ describe 'user encryption' do describe 'key exchange on friending' do it 'should send over a public key' do 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 end