Skip to content

A platform for community discussion. Free, open, simple.

FIX: Skip all post validations if necessary (#18625)

Bianca Nenciu6b788d7329c4
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb
index d38cfa3df6b..7a79689566d 100644
--- a/lib/post_revisor.rb
+++ b/lib/post_revisor.rb
@@ -560,7 +560,7 @@ class PostRevisor
@post.last_editor_id = PostRevision.where(post_id: @post.id).order(number: :desc).pluck_first(:user_id) || @post.user_id
@post.version -= 1
@post.public_version -= 1
- @post.save
+ @post.save(validate: @validate_post)
else
revision.save
end
diff --git a/spec/lib/post_revisor_spec.rb b/spec/lib/post_revisor_spec.rb
index 19f40a6b8bd..4d32af66fc1 100644
--- a/spec/lib/post_revisor_spec.rb
+++ b/spec/lib/post_revisor_spec.rb
@@ -1303,6 +1303,20 @@ RSpec.describe PostRevisor do
.and change { DraftSequence.where(user_id: user.id, draft_key: draft_key).first.sequence }.by(1)
end
end
+
+ context 'when skipping validations' do
+ fab!(:post) { Fabricate(:post, raw: 'aaa', skip_validation: true) }
+
+ it 'can revise multiple times and remove unnecessary revisions' do
+ subject.revise!(admin, { raw: 'bbb' }, skip_validations: true)
+ expect(post.errors).to be_empty
+
+ # Revert to old version which was invalid to destroy previously created
+ # post revision and trigger another post save.
+ subject.revise!(admin, { raw: 'aaa' }, skip_validations: true)
+ expect(post.errors).to be_empty
+ end
+ end
end
context 'when the review_every_post setting is enabled' do