Commit bff0977bcfaf2b312b3659e6870b4cc06797347b

Authored by AntonioTerceiro
1 parent a5482fa4

ActionItem38: removing friends in model


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1528 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 2 changed files with 15 additions and 0 deletions   Show diff stats
app/models/person.rb
... ... @@ -17,6 +17,10 @@ class Person < Profile
17 17 self.friendships.build(:friend => friend, :group => group).save!
18 18 end
19 19  
  20 + def remove_friend(friend)
  21 + friends.delete(friend)
  22 + end
  23 +
20 24 # has_many :person_friendships
21 25 # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id'
22 26  
... ...
test/unit/person_test.rb
... ... @@ -191,4 +191,15 @@ class PersonTest < Test::Unit::TestCase
191 191 assert_equal p1.suggested_friend_groups, p1.suggested_friend_groups.uniq
192 192 end
193 193  
  194 + should 'remove friend' do
  195 + p1 = create_user('testuser1').person
  196 + p2 = create_user('testuser2').person
  197 + p1.add_friend(p2, 'friends')
  198 +
  199 + assert_difference Friendship, :count, -1 do
  200 + p1.remove_friend(p2)
  201 + end
  202 + assert_not_includes p1.friends(true), p2
  203 + end
  204 +
194 205 end
... ...