diff --git a/app/models/post.rb b/app/models/post.rb index 215516afb..2f6bc6653 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1369,18 +1369,15 @@ class Post < ApplicationRecord Post.transaction do flag!(reason, is_deletion: true) - self.is_deleted = true - self.is_pending = false - self.is_flagged = false - self.is_banned = true if options[:ban] || has_tag?("banned_artist") - update_columns( - :is_deleted => is_deleted, - :is_pending => is_pending, - :is_flagged => is_flagged, - :is_banned => is_banned - ) + update({ + is_deleted: true, + is_pending: false, + is_flagged: false, + is_banned: is_banned || options[:ban] || has_tag?("banned_artist") + }, without_protection: true) + + # XXX This must happen *after* the `is_deleted` flag is set to true (issue #3419). give_favorites_to_parent if options[:move_favorites] - update_parent_on_save unless options[:without_mod_action] ModAction.log("deleted post ##{id}, reason: #{reason}") diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 2ce394014..a076af4e0 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -353,6 +353,17 @@ class PostTest < ActiveSupport::TestCase p1.reload assert(p1.has_children?, "Parent should have children") end + + should "clear the has_active_children flag when the 'move favorites' option is set" do + user = FactoryGirl.create(:gold_user) + p1 = FactoryGirl.create(:post) + c1 = FactoryGirl.create(:post, :parent_id => p1.id) + c1.add_favorite!(user) + + assert_equal(true, p1.reload.has_active_children?) + c1.delete!("test", :move_favorites => true) + assert_equal(false, p1.reload.has_active_children?) + end end context "one child" do