diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index db14d329b59042a2c5202ea87dcfdc2c75d2bbb2..6946910f2a1c718d5507f57fc5128716acc7945c 100644 --- a/lib/diaspora/user/friending.rb +++ b/lib/diaspora/user/friending.rb @@ -89,7 +89,10 @@ module Diaspora def remove_friend(bad_friend) raise "Friend not deleted" unless self.friend_ids.delete( bad_friend.id ) aspects.each{|aspect| - aspect.person_ids.delete( bad_friend.id )} + if aspect.person_ids.delete( bad_friend.id ) + aspect.posts.delete_if { |post| + post.person_id == bad_friend.id} + end} self.save self.raw_visible_posts.find_all_by_person_id( bad_friend.id ).each{|post| diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 6c3c697dfe4ecc215a9fc8a4b6238521d8549653..1585d5d750865f1c09d30f7cc4f857b592773d59 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -153,7 +153,7 @@ describe Diaspora::Parser do person.save #Cache profile for checking against marshaled profile - old_profile = person.profile + old_profile = person.profile.dup old_profile.first_name.should == 'bob' #Build xml for profile, clear profile diff --git a/spec/models/user/user_friending_spec.rb b/spec/models/user/user_friending_spec.rb index 2756c084158f3148c33f17661646649f5036a212..221887885604f55a83b928d9eb5f1a619c77c30a 100644 --- a/spec/models/user/user_friending_spec.rb +++ b/spec/models/user/user_friending_spec.rb @@ -160,22 +160,18 @@ describe User do describe 'unfriending' do before do friend_users(user,aspect, user2, aspect2) - user.reload - user2.reload end it 'should unfriend the other user on the same seed' do - user.friends.count.should == 1 - user2.friends.count.should == 1 - - user2.unfriend user.person - user2.reload - - user2.friends.count.should == 0 - user.unfriended_by user2.person + lambda {user2.unfriend user.person}.should change{ + user2.friends.count}.by(-1) + aspect2.people.count.should == 0 + end - aspect.reload.people.count.should == 0 - aspect2.reload.people.count.should == 0 + it 'is unfriended by another user' do + lambda {user.unfriended_by user2.person}.should change{ + user.friends.count}.by(-1) + aspect.people.count.should == 0 end context 'with a post' do