Commit 3ab5b163556c68d1fca4ccfc9fafd318a2062cd9
1 parent
7e3c7bc4
Exists in
master
and in
23 other branches
ActionItem36: relating people through friendships
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1462 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
18 additions
and
2 deletions
Show diff stats
app/models/person.rb
| @@ -2,8 +2,9 @@ | @@ -2,8 +2,9 @@ | ||
| 2 | class Person < Profile | 2 | class Person < Profile |
| 3 | acts_as_accessor | 3 | acts_as_accessor |
| 4 | 4 | ||
| 5 | -# has_many :friendships | ||
| 6 | -# has_many :friends, :class_name => 'Person', :through => :friendships | 5 | + has_many :friendships |
| 6 | + has_many :friends, :class_name => 'Person', :through => :friendships | ||
| 7 | + | ||
| 7 | # has_many :person_friendships | 8 | # has_many :person_friendships |
| 8 | # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' | 9 | # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' |
| 9 | 10 |
test/unit/person_test.rb
| @@ -143,4 +143,19 @@ class PersonTest < Test::Unit::TestCase | @@ -143,4 +143,19 @@ class PersonTest < Test::Unit::TestCase | ||
| 143 | assert_equal 6, p.blocks.size | 143 | assert_equal 6, p.blocks.size |
| 144 | end | 144 | end |
| 145 | 145 | ||
| 146 | + should 'have friends' do | ||
| 147 | + p1 = create_user('testuser1').person | ||
| 148 | + p2 = create_user('testuser2').person | ||
| 149 | + | ||
| 150 | + Friendship.create!(:person => p1, :friend => p2) | ||
| 151 | + | ||
| 152 | + assert_equal [p2], p1.friends | ||
| 153 | + | ||
| 154 | + p3 = create_user('testuser3').person | ||
| 155 | + Friendship.create!(:person => p1, :friend => p3) | ||
| 156 | + | ||
| 157 | + assert_equal [p2,p3], p1.friends(true) # force reload | ||
| 158 | + | ||
| 159 | + end | ||
| 160 | + | ||
| 146 | end | 161 | end |