diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index fca269bba1dcbefef0ba7ab4054b12d3093c2104..d61321d0903c5144db1911385805104f639ca35d 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -45,8 +45,9 @@ module Diaspora Contact.unscoped.where(:user_id => self.id, :person_id => person_id).first if person_id end - def people_in_aspects(aspects, opts={}) - person_ids = contacts_in_aspects(aspects).collect{|contact| contact.person_id} + def people_in_aspects(requested_aspects, opts={}) + allowed_aspects = self.aspects & requested_aspects + person_ids = contacts_in_aspects(allowed_aspects).collect{|contact| contact.person_id} people = Person.where(:id => person_ids) if opts[:type] == 'remote' diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index ce1de1c383c8c82e0efc9b8c1164f030623ddb87..2ee1c72c17c875fcaf2aff27ade4045f4944f6e6 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -96,22 +96,9 @@ describe User do end context 'with two users' do - let!(:user) {Factory(:user)} - let!(:first_aspect) {user.aspects.create(:name => 'bruisers')} - let!(:second_aspect) {user.aspects.create(:name => 'losers')} - let!(:user4) { Factory.create(:user_with_aspect)} - - before do - connect_users(user, first_aspect, user4, user4.aspects.first) - connect_users(user, second_aspect, @eve, @eve.aspects.first) - end - describe '#people_in_aspects' do it 'returns people objects for a users contact in each aspect' do - people = @alice.people_in_aspects([first_aspect]) - people.should == [user4.person] - people = @alice.people_in_aspects([second_aspect]) - people.should == [@eve.person] + @alice.people_in_aspects([@alices_aspect]).should == [bob.person] end it 'returns local/remote people objects for a users contact in each aspect' do @@ -123,27 +110,37 @@ describe User do asp2 = local_user2.aspects.create(:name => "brb") asp3 = remote_user.aspects.create(:name => "ttyl") - connect_users(user, first_aspect, local_user1, asp1) - connect_users(user, first_aspect, local_user2, asp2) - connect_users(user, first_aspect, remote_user, asp3) + connect_users(@alice, @alices_aspect, local_user1, asp1) + connect_users(@alice, @alices_aspect, local_user2, asp2) + connect_users(@alice, @alices_aspect, remote_user, asp3) local_person = remote_user.person local_person.owner_id = nil local_person.save local_person.reload - @alice.people_in_aspects([first_aspect]).count.should == 4 - @alice.people_in_aspects([first_aspect], :type => 'remote').count.should == 1 - q = @alice.people_in_aspects([first_aspect], :type => 'local') - q.count.should == 3 + @alice.people_in_aspects([@alices_aspect]).count.should == 4 + @alice.people_in_aspects([@alices_aspect], :type => 'remote').count.should == 1 + @alice.people_in_aspects([@alices_aspect], :type => 'local').count.should == 3 end it 'does not return people not connected to user on same pod' do - local_user1 = Factory(:user) - local_user2 = Factory(:user) - local_user3 = Factory(:user) + 3.times { Factory(:user) } + @alice.people_in_aspects([@alices_aspect]).count.should == 1 + end + + it "only returns non-pending contacts" do + @alice.send_contact_request_to(Factory(:user).person, @alices_aspect) + @alices_aspect.reload + @alice.reload + + @alice.people_in_aspects([@alices_aspect]).should == [bob.person] + end - @alice.people_in_aspects([first_aspect]).count.should == 1 + it "returns an empty array when passed an aspect the user doesn't own" do + other_user = Factory(:user_with_aspect) + connect_users(@eve, @eve.aspects.first, other_user, other_user.aspects.first) + @alice.people_in_aspects([other_user.aspects.first]).should == [] end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 836b32d27cc3c9d64f768d6ad71141a58d639411..95fd1d6bf65356e2d9c23e6ff75d756063d3aa42 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -276,33 +276,22 @@ describe User do alice.update_profile(params).should be_true alice.reload.profile.image_url.should == "http://clown.com" end - - it "only pushes to non-pending contacts" do - pending "this test doesn't really test what it says it tests" - lambda { - alice.send_contact_request_to(Factory(:user).person, alice.aspects.first) - }.should change(Contact.unscoped.where(:user_id => alice.id), :count).by(1) - - m = mock() - m.should_receive(:post) - Postzord::Dispatch.should_receive(:new).and_return(m) - alice.update_profile(@params).should be_true - end context 'passing in a photo' do before do fixture_filename = 'button.png' fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) image = File.open(fixture_name) - @photo = Photo.diaspora_initialize( - :author => alice.person, :user_file => image) + @photo = Photo.diaspora_initialize(:author => alice.person, :user_file => image) @photo.save! @params = {:photo => @photo} end it 'updates image_url' do alice.update_profile(@params).should be_true - alice.reload.profile.image_url.should == @photo.url(:thumb_large) - alice.profile.image_url_medium.should == @photo.url(:thumb_medium) - alice.profile.image_url_small.should == @photo.url(:thumb_small) + alice.reload + + alice.profile.image_url.should =~ Regexp.new(@photo.url(:thumb_large)) + alice.profile.image_url_medium.should =~ Regexp.new(@photo.url(:thumb_medium)) + alice.profile.image_url_small.should =~ Regexp.new(@photo.url(:thumb_small)) end it 'unpends the photo' do @photo.pending = true