A platform for community discussion. Free, open, simple.
FIX: do not validate topic deletions
Arpit Jalanb1082924b9a0
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex 790d8132769..2493ba32407 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -168,12 +168,12 @@ class PostDestroyerdef make_previous_post_the_last_onelast_post = Post.where("topic_id = ? and id <> ?", @post.topic_id, @post.id).order('created_at desc').limit(1).first- if last_post.present?- @post.topic.update!(- last_posted_at: last_post.created_at,- last_post_user_id: last_post.user_id,- highest_post_number: last_post.post_number- )+ if last_post.present? && @post.topic.present?+ topic = @post.topic+ topic.last_posted_at = last_post.created_at+ topic.last_post_user_id = last_post.user_id+ topic.highest_post_number = last_post.post_number+ topic.save!(validate: false)endenddiff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex e46c364ac2b..80c038777a2 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -265,9 +265,10 @@ describe PostDestroyer doendit "when topic is destroyed, it updates user_stats correctly" do- post+ SiteSetting.min_topic_title_length = 5+ post.topic.update_column(:title, "xyz")+user1 = post.user- user1.reloaduser2 = Fabricate(:user)reply = create_post(topic_id: post.topic_id, user: user2)reply2 = create_post(topic_id: post.topic_id, user: user1)@@ -275,6 +276,7 @@ describe PostDestroyer doexpect(user1.user_stat.post_count).to eq(1)expect(user2.user_stat.topic_count).to eq(0)expect(user2.user_stat.post_count).to eq(1)+PostDestroyer.new(Fabricate(:admin), post).destroyuser1.reloaduser2.reload@@ -390,12 +392,13 @@ describe PostDestroyer dolet(:user) { Fabricate(:user) }let!(:post) { create_post(user: user) }- let(:topic) { post.topic.reload }+ let(:topic) { post.topic }let(:second_user) { Fabricate(:coding_horror) }let!(:second_post) { create_post(topic: topic, user: second_user) }before doPostDestroyer.new(moderator, second_post).destroy+ topic.reloadendit 'resets the last_poster_id back to the OP' do@@ -406,6 +409,10 @@ describe PostDestroyer doexpect(topic.last_posted_at.to_i).to eq(post.created_at.to_i)end+ it 'resets the highest_post_number' do+ expect(topic.highest_post_number).to eq(post.post_number)+ end+context 'topic_user' dolet(:topic_user) { second_user.topic_users.find_by(topic_id: topic.id) }@@ -421,9 +428,7 @@ describe PostDestroyer doit "sets the second user's last_read_post_number back to 1" doexpect(topic_user.highest_seen_post_number).to eq(1)end-end-endcontext "deleting a post belonging to a deleted topic" do