removing the posts from the aspect on unfriending

This commit is contained in:
zhitomirskiyi 2010-11-08 15:35:37 -08:00
parent cbabc547a2
commit a6dff4f78e
2 changed files with 12 additions and 5 deletions

View file

@ -95,8 +95,8 @@ module Diaspora
raise "Friend not deleted" unless self.friend_ids.delete(contact.id) raise "Friend not deleted" unless self.friend_ids.delete(contact.id)
contact.aspects.each{|aspect| contact.aspects.each{|aspect|
contact.aspects.delete(aspect) contact.aspects.delete(aspect)
aspect.posts.delete_if { |post| aspect.posts.each { |post|
post.person_id == bad_friend.id aspect.post_ids.delete(post.id) if post.person == bad_friend
} }
aspect.save aspect.save
} }

View file

@ -238,13 +238,20 @@ describe Diaspora::UserModules::Friending do
context 'with a post' do context 'with a post' do
before do before do
@message = user.post(:status_message, :message => "hi", :to => aspect.id) @message = user.post(:status_message, :message => "hi", :to => aspect.id)
user2.unfriend user.person
end end
it "deletes the unfriended user's posts from visible_posts" do it "deletes the unfriended user's posts from visible_posts" do
user.reload.raw_visible_posts.include?(@message.id).should be_false user2.reload.raw_visible_posts.include?(@message).should be_true
user2.unfriend user.person
user2.reload.raw_visible_posts.include?(@message).should be_false
end end
it "deletes the unfriended user's posts from the aspect's posts" do it "deletes the unfriended user's posts from the aspect's posts" do
aspect2.posts.include?(@message).should be_false Post.count.should == 1
aspect2.reload.posts.include?(@message).should be_true
user2.unfriend user.person
aspect2.reload.posts.include?(@message).should be_false
Post.count.should == 1
end end
end end
end end