require 'spec_helper' describe ServiceUser do describe '#finder' do before do @user = alice @post = @user.post(:status_message, :text => "hello", :to =>@user.aspects.first.id) @service = Services::Facebook.new(:access_token => "yeah") @user.services << @service @user2 = Factory.create(:user_with_aspect) @user2_fb_id = '820651' @user2_fb_name = 'Maxwell Salzberg' @user2_service = Services::Facebook.new(:uid => @user2_fb_id, :access_token => "yo") @user2.services << @user2_service @fb_list_hash = < @service.id, :uid => @user2_fb_id) su.save su.name.should == @user2_fb_name end it 'contains a photo url' do pending end it 'contains a FB id' do @service.finder.include?(@user2_fb_id).should be_true end it 'contains a diaspora person object' do @service.finder["#{@user2_fb_id}"][:person].should == @user2.person end it 'caches the profile' do @service.finder["#{@user2_fb_id}"][:person].profile.loaded?.should be_true end it 'does not include the person if the search is disabled' do p = @user2.person.profile p.searchable = false p.save @service.finder["#{@user2_fb_id}"][:person].should be_nil end context "request" do before do @request = Request.diaspora_initialize(:from => @user2.person, :to => @user.person, :into => @user2.aspects.first) Postzord::Receiver.new(@user, :object => @request, :person => @user2.person).receive_object Request.count.should == 1 end it 'contains a request object if one has been sent' do @service.finder["#{@user2_fb_id}"][:request].should == @request end it 'caches the profile' do @service.finder["#{@user2_fb_id}"][:request].sender.profile.loaded?.should be_true end it 'caches the sender' do @service.finder["#{@user2_fb_id}"][:request].sender.loaded?.should be_true end end it 'contains a contact object if connected' do connect_users(@user, @user.aspects.first, @user2, @user2.aspects.first) @service.finder["#{@user2_fb_id}"][:contact].should == @user.reload.contact_for(@user2.person) end context 'only local' do it 'does not return people who are remote' do @service.finder(:local => true)['abc123'].should be nil @service.finder(:local => true)["#{@user2_fb_id}"].should_not be_nil end end context 'only remote' do it 'does not return people who are remote' do @service.finder(:remote => true)['abc123'].should_not be nil @service.finder(:remote => true)["#{@user2_fb_id}"].should be_nil end end context 'already invited' do before do @user2.invitation_service = 'facebook' @user2.invitation_identifier = @user2_fb_id @user2.save! end it 'contains an invitation if invited' do @inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first) @service.finder["#{@user2_fb_id}"][:invitation_id].should == @inv.id end it 'does not find the user with a wrong identifier' do @user2.invitation_identifier = 'dsaofhnadsoifnsdanf' @user2.save @inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first) @service.finder["#{@user2_fb_id}"][:invitation_id].should be_nil end end end end end