Commit 802fc44cfa10cf46bc02a7304a77013ac9add25e

Authored by Daniela Feitosa
1 parent 4226f0e2

ActionItem298: not adding a friend twice

Showing 2 changed files with 11 additions and 1 deletions   Show diff stats
app/models/person.rb
@@ -30,7 +30,9 @@ class Person < Profile @@ -30,7 +30,9 @@ class Person < Profile
30 end 30 end
31 31
32 def add_friend(friend, group = nil) 32 def add_friend(friend, group = nil)
33 - self.friendships.build(:friend => friend, :group => group).save! 33 + unless self.is_a_friend?(friend)
  34 + self.friendships.build(:friend => friend, :group => group).save!
  35 + end
34 end 36 end
35 37
36 def already_request_friendship?(person) 38 def already_request_friendship?(person)
test/unit/person_test.rb
@@ -555,4 +555,12 @@ class PersonTest < Test::Unit::TestCase @@ -555,4 +555,12 @@ class PersonTest < Test::Unit::TestCase
555 assert_equal 'http://website.with.http', p.organization_website 555 assert_equal 'http://website.with.http', p.organization_website
556 end 556 end
557 557
  558 + should 'not add a friend if already is a friend' do
  559 + p1 = create_user('testuser1').person
  560 + p2 = create_user('testuser2').person
  561 + assert p1.add_friend(p2)
  562 + assert Profile['testuser1'].is_a_friend?(p2)
  563 + assert !Profile['testuser1'].add_friend(p2)
  564 + end
  565 +
558 end 566 end