fixed the issue of nothing showing up for empty aspects
This commit is contained in:
parent
4a7326e035
commit
70d1c31733
2 changed files with 15 additions and 8 deletions
|
|
@ -101,10 +101,11 @@ class AspectsController < ApplicationController
|
|||
|
||||
@contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
||||
c = Contact.arel_table
|
||||
@contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
||||
|
||||
pp @contacts_not_in_aspect
|
||||
pp @contacts_in_aspect
|
||||
if @contacts_in_aspect.empty?
|
||||
@contacts_not_in_aspect = current_user.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
||||
else
|
||||
@contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }
|
||||
end
|
||||
|
||||
@contacts = @contacts_in_aspect + @contacts_not_in_aspect
|
||||
|
||||
|
|
|
|||
|
|
@ -305,6 +305,9 @@ describe AspectsController do
|
|||
@katz.profile.save
|
||||
@katz.save
|
||||
|
||||
connect_users(@alice, @alices_aspect_2, @eve, @eve.aspects.first)
|
||||
connect_users(@alice, @alices_aspect_2, @zed, @zed.aspects.first)
|
||||
connect_users(@alice, @alices_aspect_1, @katz, @katz.aspects.first)
|
||||
end
|
||||
it 'renders' do
|
||||
get :edit, :id => @alices_aspect_1.id
|
||||
|
|
@ -312,13 +315,16 @@ describe AspectsController do
|
|||
end
|
||||
|
||||
it 'assigns the contacts in alphabetical order with people in aspects first' do
|
||||
connect_users(@alice, @alices_aspect_2, @eve, @eve.aspects.first)
|
||||
connect_users(@alice, @alices_aspect_2, @zed, @zed.aspects.first)
|
||||
connect_users(@alice, @alices_aspect_1, @katz, @katz.aspects.first)
|
||||
|
||||
get :edit, :id => @alices_aspect_2.id
|
||||
assigns[:contacts].map(&:id).should == [@alice.contact_for(@eve.person), @alice.contact_for(@zed.person), @alice.contact_for(@bob.person), @alice.contact_for(@katz.person)].map(&:id)
|
||||
end
|
||||
|
||||
it 'assigns all the contacts if noone is there' do
|
||||
alices_aspect_3 = @alice.aspects.create(:name => "aspect 3")
|
||||
|
||||
get :edit, :id => alices_aspect_3.id
|
||||
assigns[:contacts].map(&:id).should == [@alice.contact_for(@bob.person), @alice.contact_for(@eve.person), @alice.contact_for(@katz.person), @alice.contact_for(@zed.person)].map(&:id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#toggle_contact_visibility" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue