MS IZ; querying through for person not in aspect is tested
This commit is contained in:
parent
6bee872039
commit
554adeae69
4 changed files with 21 additions and 1 deletions
|
|
@ -46,7 +46,7 @@ class AspectsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@aspect = current_user.aspect_by_id params[:id]
|
@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
|
unless @aspect
|
||||||
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ module Diaspora
|
||||||
result
|
result
|
||||||
end
|
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 )
|
def aspect_by_id( id )
|
||||||
id = id.to_id
|
id = id.to_id
|
||||||
aspects.detect{|x| x.id == id }
|
aspects.detect{|x| x.id == id }
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ describe Aspect do
|
||||||
describe '#aspects_with_person' do
|
describe '#aspects_with_person' do
|
||||||
let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")}
|
let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")}
|
||||||
it 'should return the aspects with given friend' do
|
it 'should return the aspects with given friend' do
|
||||||
|
user.reload
|
||||||
aspects = user.aspects_with_person(friend)
|
aspects = user.aspects_with_person(friend)
|
||||||
aspects.size.should == 1
|
aspects.size.should == 1
|
||||||
aspects.first.id.should == aspect.id
|
aspects.first.id.should == aspect.id
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,21 @@ describe User do
|
||||||
before do
|
before do
|
||||||
friend_users(user, first_aspect, user2, user2.aspects.first)
|
friend_users(user, first_aspect, user2, user2.aspects.first)
|
||||||
friend_users(user, second_aspect, user3, user3.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
|
end
|
||||||
|
|
||||||
describe "#visible_posts" do
|
describe "#visible_posts" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue