Skip to content
Snippets Groups Projects
Commit 554adeae authored by ilya's avatar ilya
Browse files

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

parent 6bee8720
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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 }
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment