From 6410355d7161ada8101392096478022ed9b224f6 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 17 Jan 2011 14:13:17 -0800 Subject: [PATCH] Fix aspect edit page --- app/controllers/aspects_controller.rb | 5 ++--- spec/controllers/aspects_controller_spec.rb | 12 ++++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index e04434760..8c415210e 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -28,8 +28,7 @@ class AspectsController < ApplicationController :page => params[:page], :per_page => 15, :order => 'created_at DESC') @post_hashes = hashes_for_posts @posts - @contacts = Contact.joins(:aspect_memberships).where( - :aspect_memberships => {:aspect_id => @aspect_ids}, :user_id => current_user.id, :pending => false) + @contacts = current_user.contacts.includes(:person).where(:pending => false) @contact_hashes = hashes_for_contacts @contacts @aspect_hashes = hashes_for_aspects @aspects, @contacts, :limit => 16 @@ -84,7 +83,7 @@ class AspectsController < ApplicationController render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 else @aspect_ids = [@aspect.id] - @aspect_contacts = hashes_for_contacts Contact.all(:user_id => current_user.id, :aspect_ids.in => [@aspect.id], :pending => false) + @aspect_contacts = hashes_for_contacts @aspect.contacts.where(:pending => false).all @aspect_contacts_count = @aspect_contacts.count @all_contacts = hashes_for_contacts @contacts diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 685acac04..38ef62c2d 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -227,16 +227,21 @@ describe AspectsController do end describe "#hashes_for_aspects" do before do + @aspect1 = @user.aspects.create(:name => "SecondAspect") @people = [] 10.times {@people << Factory.create(:person)} - @people.each{|p| @user.reload.activate_contact(p, @user.aspects.first.reload)} + + @people.each do |p| + @user.reload.activate_contact(p, @user.aspects.first.reload) + @user.add_contact_to_aspect(@user.contact_for(p), @aspect1) + end @user.reload @hashes = @controller.send(:hashes_for_aspects, @user.aspects, @user.contacts, :limit => 9) @hash = @hashes.first @aspect0 = @user.aspects.first end it 'has aspects' do - @hashes.length.should == 2 + @hashes.length.should == @user.aspects.count @hash[:aspect].should == @aspect0 end it 'has a contact_count' do @@ -255,6 +260,9 @@ describe AspectsController do it 'has a contact in each hash' do @aspect0.contacts.include?(@hash[:contacts].first[:contact]).should be_true end + it 'does not retreive duplicate contacts' do + @hash[:contacts].uniq.count.should == @hash[:contacts].count + end end describe "#update" do