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:
parent
0af2837b73
commit
6b788d7329
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue