Post deletion now deletes comments

This commit is contained in:
Raphael 2010-07-02 14:34:58 -07:00
parent 469599a4a9
commit f9856517db
2 changed files with 15 additions and 0 deletions

View file

@ -23,6 +23,7 @@ class Post
after_save :notify_friends
before_destroy :propagate_delete
after_destroy :destroy_comments
def self.stream
Post.sort(:created_at.desc).all
@ -43,6 +44,10 @@ class Post
protected
def destroy_comments
comments.each{|c| c.destroy}
end
def propagate_delete
Retraction.for(self).notify_friends
end

View file

@ -83,5 +83,15 @@ describe Post do
(message.to_xml.to_s.include? @user.email).should == true
end
end
describe 'deletion' do
it 'should delete a posts comments on delete' do
post = Factory.create(:status_message, :person => @user)
@user.comment "hey", :on=> post
post.destroy
Post.all(:id => post.id).empty?.should == true
Comment.all(:text => "hey").empty?.should == true
end
end
end