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

When PostRevisor is called with 'skip_validations: true' it can save
the post twice and one of the calls passes the correct 'validate: false'
argument, but the other one does not.
This commit is contained in:
Bianca Nenciu 2022-10-19 18:54:32 +03:00 committed by GitHub
parent 0af2837b73
commit 6b788d7329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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