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
|
after_save :notify_friends
|
||||||
|
|
||||||
before_destroy :propagate_delete
|
before_destroy :propagate_delete
|
||||||
|
after_destroy :destroy_comments
|
||||||
|
|
||||||
def self.stream
|
def self.stream
|
||||||
Post.sort(:created_at.desc).all
|
Post.sort(:created_at.desc).all
|
||||||
|
|
@ -43,6 +44,10 @@ class Post
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
def destroy_comments
|
||||||
|
comments.each{|c| c.destroy}
|
||||||
|
end
|
||||||
|
|
||||||
def propagate_delete
|
def propagate_delete
|
||||||
Retraction.for(self).notify_friends
|
Retraction.for(self).notify_friends
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -83,5 +83,15 @@ describe Post do
|
||||||
(message.to_xml.to_s.include? @user.email).should == true
|
(message.to_xml.to_s.include? @user.email).should == true
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue