From 0758f9245f6ff9dbf2b2069a2834a09e38ef64ca Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Wed, 20 Oct 2010 10:28:08 -0700 Subject: [PATCH] Clean up specs a little, fix unfriending --- lib/diaspora/user/friending.rb | 5 ++++- spec/lib/diaspora_parser_spec.rb | 2 +- spec/models/user/user_friending_spec.rb | 20 ++++++++------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/diaspora/user/friending.rb b/lib/diaspora/user/friending.rb index db14d329b5..6946910f2a 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 6c3c697dfe..1585d5d750 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 2756c08415..2218878856 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 -- GitLab