FIX: Couldn't move posts with deleted replies

This commit is contained in:
Robin Ward 2016-08-04 11:49:44 -04:00
parent f10c4682cd
commit e5b529f8e1
2 changed files with 15 additions and 4 deletions

View File

@ -78,7 +78,7 @@ class PostMover
end end
PostReply.where("reply_id in (:post_ids) OR post_id in (:post_ids)", post_ids: post_ids).each do |post_reply| PostReply.where("reply_id in (:post_ids) OR post_id in (:post_ids)", post_ids: post_ids).each do |post_reply|
if post_reply.reply.topic_id != post_reply.post.topic_id if post_reply.post && post_reply.reply && post_reply.reply.topic_id != post_reply.post.topic_id
PostReply.delete_all(reply_id: post_reply.reply.id, post_id: post_reply.post.id) PostReply.delete_all(reply_id: post_reply.reply.id, post_id: post_reply.post.id)
end end
end end

View File

@ -80,7 +80,18 @@ describe PostMover do
topic.move_posts( topic.move_posts(
user, user,
[p2.id], [p2.id],
title: 'GOT is a very addictive showw', category_id: category.id title: 'GOT is a very addictive show', category_id: category.id
)
expect(p2.reload.replies).to eq([])
end
it "doesn't raise errors with deleted replies" do
p4.trash!
topic.move_posts(
user,
[p2.id],
title: 'GOT is a very addictive show', category_id: category.id
) )
expect(p2.reload.replies).to eq([]) expect(p2.reload.replies).to eq([])
@ -101,7 +112,7 @@ describe PostMover do
topic.move_posts( topic.move_posts(
user, user,
[p4.id], [p4.id],
title: 'GOT is a very addictive showw', category_id: category.id title: 'GOT is a very addictive show', category_id: category.id
) )
expect(p2.reload.replies).to eq([p5]) expect(p2.reload.replies).to eq([p5])
@ -122,7 +133,7 @@ describe PostMover do
topic.move_posts( topic.move_posts(
user, user,
[p2.id, p4.id], [p2.id, p4.id],
title: 'GOT is a very addictive showw', category_id: category.id title: 'GOT is a very addictive show', category_id: category.id
) )
expect(p2.reload.replies).to eq([p4]) expect(p2.reload.replies).to eq([p4])