From 554adeae69fb96839c770bb46fbae97e4226d14e Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 20 Oct 2010 16:39:37 -0700 Subject: [PATCH] MS IZ; querying through for person not in aspect is tested --- app/controllers/aspects_controller.rb | 2 +- lib/diaspora/user/querying.rb | 4 ++++ spec/models/aspect_spec.rb | 1 + spec/models/user/visible_posts_spec.rb | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 016037ee1..c87220ce2 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -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 diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 63cbfba17..b22c8b73e 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -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 } diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index e52a42e7d..92800c3d8 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -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 diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/visible_posts_spec.rb index 4c06643c1..1eaf17dde 100644 --- a/spec/models/user/visible_posts_spec.rb +++ b/spec/models/user/visible_posts_spec.rb @@ -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