Post deletion now deletes comments
This commit is contained in:
parent
469599a4a9
commit
f9856517db
2 changed files with 15 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue