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
|
|
@ -33,8 +33,7 @@ class Person
|
||||||
|
|
||||||
after_destroy :remove_all_traces, :remove_key
|
after_destroy :remove_all_traces, :remove_key
|
||||||
|
|
||||||
scope :friends, where(:_type => "Person", :active => true)
|
scope :friends, where(:_type => "Person", :active => true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def real_name
|
def real_name
|
||||||
|
|
|
||||||
|
|
@ -73,18 +73,22 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfriend(friend_id)
|
def unfriend(friend_id)
|
||||||
bad_friend = self.friends.first(:id => friend_id)
|
bad_friend = Person.first(:id => friend_id)
|
||||||
self.friends.detect{|x| x.id == friend_id}.delete
|
|
||||||
|
|
||||||
|
puts bad_friend.users.count
|
||||||
|
|
||||||
|
self.friend_ids.delete( friend_id )
|
||||||
|
self.save
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
puts bad_friend.users.count
|
||||||
|
|
||||||
if bad_friend
|
if bad_friend
|
||||||
|
|
||||||
|
|
||||||
bad
|
|
||||||
|
|
||||||
|
|
||||||
Retraction.for(self).push_to_url(bad_friend.url)
|
Retraction.for(self).push_to_url(bad_friend.url)
|
||||||
bad_friend.destroy if bad_friend.users.count == 0
|
bad_friend.destroy if bad_friend.users.count == 0
|
||||||
end
|
end
|
||||||
self.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_request(rel_hash)
|
def send_request(rel_hash)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Factory.define :user do |u|
|
||||||
u.password "bluepin7"
|
u.password "bluepin7"
|
||||||
u.password_confirmation "bluepin7"
|
u.password_confirmation "bluepin7"
|
||||||
|
|
||||||
u.person Factory.create(:person)
|
u.sequence(:person) {|p| Factory.create(:person, :email => "robert-#{p}@grimm.org")}
|
||||||
end
|
end
|
||||||
|
|
||||||
Factory.define :status_message do |m|
|
Factory.define :status_message do |m|
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,49 @@ describe Person do
|
||||||
s.comments.count.should == 4
|
s.comments.count.should == 4
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should let a user unfriend a person' do
|
describe "unfriending" do
|
||||||
user = Factory.create(:user)
|
it 'should delete an orphaned friend' do
|
||||||
person = Factory.create(:person)
|
user = Factory.create(:user)
|
||||||
|
user.save
|
||||||
|
|
||||||
|
person = Factory.create(:person)
|
||||||
|
|
||||||
user.friends << person
|
person.users << user
|
||||||
|
user.friend_ids << person.id
|
||||||
|
|
||||||
user.friends.count.should == 1
|
Person.all.count.should == 2
|
||||||
user.unfriend(person.id)
|
user.friends.count.should == 1
|
||||||
user.friends.count.should == 0
|
user.unfriend(person.id)
|
||||||
Person.all.count.should == 1
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue