no more n-query in the view problem

This commit is contained in:
danielgrippi 2011-05-13 16:49:37 -07:00
parent 402e84708b
commit ee49fb3547
3 changed files with 6 additions and 2 deletions

View file

@ -37,7 +37,7 @@ class ContactsController < ApplicationController
end end
def sharing def sharing
@contacts = current_user.contacts.sharing @contacts = current_user.contacts.sharing.includes(:aspects)
render :layout => false render :layout => false
end end
end end

View file

@ -112,7 +112,6 @@ Feature: sending and receiving requests
And I am on "bob@bob.bob"'s page And I am on "bob@bob.bob"'s page
Then I should not see "Add to aspect"
Then I should see "In 2 aspects" Then I should see "In 2 aspects"
Then I should see "Mention" Then I should see "Mention"
Then I should see "Message" Then I should see "Message"

View file

@ -67,6 +67,11 @@ describe ContactsController do
response.should be_success response.should be_success
end end
it 'eager loads the aspects' do
get :sharing
assigns[:contacts].first.aspects.loaded?.should be_true
end
it "assigns only the people sharing with you with 'share_with' flag" do it "assigns only the people sharing with you with 'share_with' flag" do
get :sharing, :id => 'share_with' get :sharing, :id => 'share_with'
assigns[:contacts].to_set.should == alice.contacts.sharing.to_set assigns[:contacts].to_set.should == alice.contacts.sharing.to_set