public
Fork of insoshi/insoshi
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/toim/insoshi.git
Excluding deactivated people from common connections
Michael Hartl (author)
Thu May 08 12:06:54 -0700 2008
commit  0177c8084c6d7da1cec4ecaf6f116c1865caae35
tree    6c059690958a0e582112d43c1905b4ab10e95260
parent  553fb9109f673dd90e2c68ea82bff77f1d703629
...
330
331
332
 
333
334
 
335
336
 
337
338
339
 
340
341
342
...
330
331
332
333
334
335
336
337
 
338
339
340
 
341
342
343
344
0
@@ -330,13 +330,15 @@ class Person < ActiveRecord::Base
0
     not deactivated?
0
   end
0
 
0
+ # Return the common connections with the given person.
0
   def common_connections_with(person, page = 1)
0
     sql = %(SELECT connections.*, COUNT(contact_id) FROM `connections`
0
+ INNER JOIN people contact ON connections.contact_id = contact.id
0
             WHERE ((person_id = ? OR person_id = ?)
0
- AND status=?)
0
+ AND status = ? AND contact.deactivated = ?)
0
             GROUP BY contact_id
0
             HAVING count(contact_id) = 2)
0
- conditions = [sql, id, person.id, Connection::ACCEPTED]
0
+ conditions = [sql, id, person.id, Connection::ACCEPTED, false]
0
     opts = { :page => page, :per_page => RASTER_PER_PAGE }
0
     @common_connections ||= Connection.paginate_by_sql(conditions, opts)
0
   end
...
110
111
112
113
114
 
115
116
117
118
119
120
121
122
123
124
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
129
130
131
132
...
110
111
112
 
 
113
114
115
116
117
 
 
 
 
 
 
 
 
 
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
 
138
139
140
0
@@ -110,23 +110,31 @@ describe Person do
0
     end
0
     
0
     it "should have contacts" do
0
- Connection.request(@person, @contact)
0
- Connection.accept(@person, @contact)
0
+ Connection.connect(@person, @contact)
0
       @person.contacts.should == [@contact]
0
       @contact.contacts.should == [@person]
0
     end
0
     
0
- it "should have common contacts with someone" do
0
- quentin = people(:quentin)
0
- aaron = people(:aaron)
0
- kelly = people(:kelly)
0
- Connection.request(quentin, aaron)
0
- Connection.accept(quentin, aaron)
0
- Connection.request(kelly, aaron)
0
- Connection.accept(kelly, aaron)
0
- quentin.common_connections_with(kelly).size.should == 1
0
+ describe "common contacts" do
0
+
0
+ before(:each) do
0
+ @kelly = people(:kelly)
0
+ Connection.connect(@person, @contact)
0
+ Connection.connect(@kelly, @contact)
0
+ end
0
+
0
+ it "should have common contacts with someone" do
0
+ common_connections = @person.common_connections_with(@kelly)
0
+ common_connections.size.should == 1
0
+ common_connections.map(&:contact).should == [@contact]
0
+ end
0
+
0
+ it "should exclude deactivated people from common contacts" do
0
+ @contact.toggle!(:deactivated)
0
+ common_connections = @person.common_connections_with(@kelly)
0
+ common_connections.should be_empty
0
+ end
0
     end
0
-
0
   end
0
   
0
   describe "photo methods" do

Comments

    No one has commented yet.