This commit is contained in:
zhitomirskiyi 2011-03-29 19:35:37 -07:00
parent c4295a7693
commit 4a7326e035
2 changed files with 27 additions and 6 deletions

View file

@ -98,12 +98,21 @@ class AspectsController < ApplicationController
def edit
@aspect = current_user.aspects.where(:id => params[:id]).includes(:contacts => {:person => :profile}).first
@contacts = current_user.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name }.reverse!
@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
@contacts = @contacts_in_aspect + @contacts_not_in_aspect
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@aspect_ids = [@aspect.id]
@aspect_contacts_count = @aspect.contacts.length
@aspect_contacts_count = @aspect.contacts.size
render :layout => false
end
end

View file

@ -295,17 +295,29 @@ describe AspectsController do
@eve.profile.first_name = nil
@eve.profile.save
@eve.save
@zed = Factory(:user_with_aspect, :username => "zed")
@zed.profile.first_name = "zed"
@zed.profile.save
@zed.save
@katz = Factory(:user_with_aspect, :username => "katz")
@katz.profile.first_name = "katz"
@katz.profile.save
@katz.save
end
it 'renders' do
get :edit, :id => @alices_aspect_1.id
response.should be_success
end
it 'assigns the contacts in alphabetical order' do
connect_users(@alice, @alices_aspect_1, @eve, @eve.aspects.first)
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_1.id
assigns[:contacts].should == [@alice.contact_for(@eve.person), @alice.contact_for(@bob.person)]
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
end