MS IZ; querying through for person not in aspect is tested

This commit is contained in:
ilya 2010-10-20 16:39:37 -07:00
parent 6bee872039
commit 554adeae69
4 changed files with 21 additions and 1 deletions

View file

@ -46,7 +46,7 @@ class AspectsController < ApplicationController
def show
@aspect = current_user.aspect_by_id params[:id]
@friends_not_in_aspect = current_user.friends.all(:person_id.nin => @aspect.person_ids )
@friends_not_in_aspect = current_user.friends_not_in_aspect(@aspect)
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else

View file

@ -29,6 +29,10 @@ module Diaspora
result
end
def friends_not_in_aspect( aspect )
Person.all(:id.in => self.friend_ids, :id.nin => aspect.person_ids)
end
def aspect_by_id( id )
id = id.to_id
aspects.detect{|x| x.id == id }

View file

@ -82,6 +82,7 @@ describe Aspect do
describe '#aspects_with_person' do
let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")}
it 'should return the aspects with given friend' do
user.reload
aspects = user.aspects_with_person(friend)
aspects.size.should == 1
aspects.first.id.should == aspect.id

View file

@ -24,6 +24,21 @@ describe User do
before do
friend_users(user, first_aspect, user2, user2.aspects.first)
friend_users(user, second_aspect, user3, user3.aspects.first)
end
describe '#friends_not_in_aspect' do
it 'finds the people who are not in the given aspect' do
friend_users(user, first_aspect, user4, user4.aspects.first)
people = user.friends_not_in_aspect(first_aspect)
people.should == [user3.person]
people2 = user.friends_not_in_aspect(second_aspect)
people2.count.should == 2
people2.include?(user2.person).should be true
people2.include?(user4.person).should be true
end
end
describe "#visible_posts" do