unfriend still not removing association from bad_friend
This commit is contained in:
parent
7a556e1b3c
commit
f2d7f35b84
4 changed files with 55 additions and 19 deletions
|
|
@ -36,7 +36,6 @@ class Person
|
|||
scope :friends, where(:_type => "Person", :active => true)
|
||||
|
||||
|
||||
|
||||
def real_name
|
||||
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,18 +73,22 @@ class User
|
|||
end
|
||||
|
||||
def unfriend(friend_id)
|
||||
bad_friend = self.friends.first(:id => friend_id)
|
||||
self.friends.detect{|x| x.id == friend_id}.delete
|
||||
bad_friend = Person.first(:id => friend_id)
|
||||
|
||||
|
||||
puts bad_friend.users.count
|
||||
|
||||
self.friend_ids.delete( friend_id )
|
||||
self.save
|
||||
|
||||
|
||||
|
||||
puts bad_friend.users.count
|
||||
|
||||
if bad_friend
|
||||
|
||||
|
||||
bad
|
||||
|
||||
|
||||
Retraction.for(self).push_to_url(bad_friend.url)
|
||||
bad_friend.destroy if bad_friend.users.count == 0
|
||||
end
|
||||
self.save
|
||||
end
|
||||
|
||||
def send_request(rel_hash)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ Factory.define :user do |u|
|
|||
u.password "bluepin7"
|
||||
u.password_confirmation "bluepin7"
|
||||
|
||||
u.person Factory.create(:person)
|
||||
u.sequence(:person) {|p| Factory.create(:person, :email => "robert-#{p}@grimm.org")}
|
||||
end
|
||||
|
||||
Factory.define :status_message do |m|
|
||||
|
|
|
|||
|
|
@ -42,16 +42,49 @@ describe Person do
|
|||
s.comments.count.should == 4
|
||||
end
|
||||
|
||||
it 'should let a user unfriend a person' do
|
||||
describe "unfriending" do
|
||||
it 'should delete an orphaned friend' do
|
||||
user = Factory.create(:user)
|
||||
user.save
|
||||
|
||||
person = Factory.create(:person)
|
||||
|
||||
user.friends << person
|
||||
person.users << user
|
||||
user.friend_ids << person.id
|
||||
|
||||
Person.all.count.should == 2
|
||||
user.friends.count.should == 1
|
||||
user.unfriend(person.id)
|
||||
user.friends.count.should == 0
|
||||
Person.all.count.should == 1
|
||||
end
|
||||
|
||||
it 'should not delete an un-orphaned friend' do
|
||||
user_one = Factory.create(:user)
|
||||
user_two = Factory.create(:user)
|
||||
|
||||
user_one.save
|
||||
user_two.save
|
||||
|
||||
person = Factory.create(:person)
|
||||
|
||||
person.users << user_one
|
||||
person.users << user_two
|
||||
|
||||
user_one.friend_ids << person.id
|
||||
user_two.friend_ids << person.id
|
||||
|
||||
Person.all.count.should == 3
|
||||
user_one.friends.count.should == 1
|
||||
user_two.friends.count.should == 1
|
||||
|
||||
user_one.unfriend(person.id)
|
||||
|
||||
user_one.friends.count.should == 0
|
||||
user_two.friends.count.should == 1
|
||||
|
||||
Person.all.count.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue