Commit 267d8d1865635629860461572265f1dbdfcddac3
1 parent
f6369843
Exists in
master
and in
29 other branches
ActionItem36: listing friend groups
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1497 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
17 additions
and
0 deletions
Show diff stats
app/models/person.rb
@@ -5,6 +5,10 @@ class Person < Profile | @@ -5,6 +5,10 @@ class Person < Profile | ||
5 | has_many :friendships | 5 | has_many :friendships |
6 | has_many :friends, :class_name => 'Person', :through => :friendships | 6 | has_many :friends, :class_name => 'Person', :through => :friendships |
7 | 7 | ||
8 | + def friend_groups | ||
9 | + friendships.map {|item| item.group}.uniq | ||
10 | + end | ||
11 | + | ||
8 | # has_many :person_friendships | 12 | # has_many :person_friendships |
9 | # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' | 13 | # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' |
10 | 14 |
test/unit/person_test.rb
@@ -158,4 +158,17 @@ class PersonTest < Test::Unit::TestCase | @@ -158,4 +158,17 @@ class PersonTest < Test::Unit::TestCase | ||
158 | 158 | ||
159 | end | 159 | end |
160 | 160 | ||
161 | + should 'list friend groups' do | ||
162 | + p1 = create_user('testuser1').person | ||
163 | + p2 = create_user('testuser2').person | ||
164 | + p3 = create_user('testuser3').person | ||
165 | + p4 = create_user('testuser4').person | ||
166 | + | ||
167 | + Friendship.create!(:person => p1, :friend => p2, :group => 'family') | ||
168 | + Friendship.create!(:person => p1, :friend => p3, :group => 'school') | ||
169 | + Friendship.create!(:person => p1, :friend => p4, :group => 'school') | ||
170 | + | ||
171 | + assert_equivalent ['family', 'school'], p1.friend_groups | ||
172 | + end | ||
173 | + | ||
161 | end | 174 | end |