default scope on contact

This commit is contained in:
zhitomirskiyi 2011-02-18 17:24:01 -08:00
parent 43f17b3ed8
commit 61dd5a835a
16 changed files with 22 additions and 19 deletions

View file

@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
if current_user
str << "uid=#{current_user.id} "
str << "user_created_at='#{current_user.created_at.to_date.to_s}' user_created_at_unix=#{current_user.created_at.to_i} " if current_user.created_at
str << "user_contact_count=#{current_user.contacts.size} "
str << "user_non_pending_contact_count=#{current_user.contacts.size} user_contact_count=#{Contact.unscoped.where(:user_id => current_user.id).size} "
else
str << 'uid=nil'
end

View file

@ -31,7 +31,7 @@ class AspectsController < ApplicationController
:page => params[:page], :per_page => 15, :order => sort_order + ' DESC')
@fakes = PostsFake.new(@posts)
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
@contacts = current_user.contacts.includes(:person => :profile)
@aspect = :all unless params[:a_ids]
@aspect ||= @aspects.first #used in mobile
@ -100,7 +100,7 @@ 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).where(:pending => false)
@contacts = current_user.contacts.includes(:person => :profile)
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@ -112,7 +112,7 @@ class AspectsController < ApplicationController
def manage
@aspect = :manage
@contacts = current_user.contacts.includes(:person => :profile).where(:pending => false)
@contacts = current_user.contacts.includes(:person => :profile)
@remote_requests = Request.where(:recipient_id => current_user.person.id).includes(:sender => :profile)
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
end

View file

@ -40,7 +40,7 @@ class ContactsController < ApplicationController
end
def edit
@contact = current_user.contacts.find(params[:id])
@contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first
@person = @contact.person
@aspects_with_person = []
@ -55,7 +55,7 @@ class ContactsController < ApplicationController
end
def destroy
contact = current_user.contacts.where(:id => params[:id]).first
contact = Contact.unscoped.where(:id => params[:id], :user_id => current_user.id).first
if current_user.disconnect(contact)
flash[:notice] = I18n.t('contacts.destroy.success', :name => contact.person.name)
else

View file

@ -30,7 +30,7 @@ class PeopleController < ApplicationController
requests[r.id] = r
end
contacts = {}
Contact.where(:user_id => current_user.id, :person_id => ids).each do |contact|
Contact.unscoped.where(:user_id => current_user.id, :person_id => ids).each do |contact|
contacts[contact.person_id] = contact
end

View file

@ -3,6 +3,8 @@
# the COPYRIGHT file.
class Contact < ActiveRecord::Base
default_scope where(:pending => false)
belongs_to :user
validates_presence_of :user

View file

@ -32,7 +32,7 @@ class Profile < ActiveRecord::Base
belongs_to :person
def subscribers(user)
Person.joins(:contacts).where(:contacts => {:user_id => user.id, :pending => false})
Person.joins(:contacts).where(:contacts => {:user_id => user.id})
end
def receive(user, person)

View file

@ -49,7 +49,7 @@ class Services::Facebook < Service
requests.each{|r| data_h[person_ids_and_uids[r.sender_id]][:request] = r}
contact_objects = self.user.contacts.where(:person_id => person_ids_and_uids.keys)
contact_objects = Contact.unscoped.where(:user_id => self.user.id, :person_id => person_ids_and_uids.keys)
contact_objects.each{|c| data_h[person_ids_and_uids[c.person_id]][:contact] = c}
if opts[:local]

View file

@ -284,7 +284,7 @@ class User < ActiveRecord::Base
end
def disconnect_everyone
contacts.each { |contact|
Contact.unscoped.where(:user_id => self.id).each { |contact|
if contact.person.owner_id
contact.person.owner.disconnected_by self.person
else

View file

@ -1,7 +1,7 @@
%li{:data=>{:guid=>aspect.id}, :class => ("dull" if contacts.length == 0)}
%li{:data=>{:guid=>aspect.id}, :class => ("dull" if contacts.size == 0)}
.right
%b
= link_to t('contacts', :count => contacts.count), edit_aspect_path(aspect), :rel => 'facebox'
= link_to t('contacts', :count => contacts.size), edit_aspect_path(aspect), :rel => 'facebox'
%b
= link_to aspect.name, edit_aspect_path(aspect), :rel => 'facebox'
%br

1
false Normal file
View file

@ -0,0 +1 @@
ack: =: No such file or directory

View file

@ -42,7 +42,7 @@ module Diaspora
end
def contact_for_person_id(person_id)
Contact.where(:user_id => self.id, :person_id => person_id).first if person_id
Contact.unscoped.where(:user_id => self.id, :person_id => person_id).first if person_id
end
def people_in_aspects(aspects, opts={})

View file

@ -198,9 +198,9 @@ describe AspectsController do
assigns(:remote_requests).should be_empty
end
it "assigns contacts to only non-pending" do
@user.contacts.count.should == 1
Contact.unscoped.where(:user_id => @user.id).count.should == 1
@user.send_contact_request_to(Factory(:user).person, @aspect0)
@user.contacts.count.should == 2
Contact.unscoped.where(:user_id => @user.id).count.should == 2
get :manage
contacts = assigns(:contacts)

View file

@ -75,7 +75,7 @@ describe RequestsController do
@user.contact_for(@other_user).should be_nil
lambda {
post :create, @params
}.should change(Contact,:count).by(1)
}.should change(Contact.unscoped,:count).by(1)
new_contact = @user.reload.contact_for(@other_user.person)
new_contact.should_not be_nil
new_contact.should be_pending

View file

@ -338,7 +338,7 @@ describe Invitation do
it 'creates a pending contact for the inviter' do
lambda {
@invitation.to_request!
}.should change(Contact, :count).by(1)
}.should change(Contact.unscoped, :count).by(1)
@invitation.sender.contact_for(@new_user.person).should be_pending
end
describe 'return values' do

View file

@ -34,7 +34,7 @@ describe Diaspora::UserModules::Connecting do
it 'creates a pending contact' do
proc {
user.send_contact_request_to(user2.person, aspect1)
}.should change(Contact, :count).by(1)
}.should change(Contact.unscoped, :count).by(1)
user.contact_for(user2.person).pending.should == true
user.contact_for(user2.person).should be_pending
end

View file

@ -268,7 +268,7 @@ describe User do
connect_users(user, aspect, user2, aspect2)
lambda {
user.send_contact_request_to(Factory(:user).person, aspect)
}.should change(user.contacts, :count).by(1)
}.should change(Contact.unscoped.where(:user_id => user.id), :count).by(1)
m = mock()
m.should_receive(:post)