FIX: Ensure revisions are made to store edit reasons and no reasons get wiped (#8363)

* Fix an issue where if an edit was made to a post with a reason provided, and then another edit was made with no reason, the original edit reason got wiped out
* We now always make a post revision (even with ninja edits) if an edit reason has been provided and it is different from the current edit reason

Co-Authored-By: Sam <sam.saffron@gmail.com>
This commit is contained in:
Martin Brennan
2019-11-18 13:08:54 +10:00
committed by GitHub
parent 102909edb3
commit af091c49e9
2 changed files with 37 additions and 3 deletions

View File

@ -198,6 +198,35 @@ describe PostRevisor do
end
end
describe 'edit reasons' do
it "does create a new version if an edit reason is provided" do
post = Fabricate(:post, raw: 'hello world')
revisor = PostRevisor.new(post)
revisor.revise!(post.user, { raw: 'hello world123456789', edit_reason: 'this is my reason' }, revised_at: post.updated_at + 1.second)
post.reload
expect(post.version).to eq(2)
expect(post.revisions.count).to eq(1)
end
it "does not create a new version if an edit reason is provided and its the same as the current edit reason" do
post = Fabricate(:post, raw: 'hello world', edit_reason: 'this is my reason')
revisor = PostRevisor.new(post)
revisor.revise!(post.user, { raw: 'hello world123456789', edit_reason: 'this is my reason' }, revised_at: post.updated_at + 1.second)
post.reload
expect(post.version).to eq(1)
expect(post.revisions.count).to eq(0)
end
it "does not clobber the existing edit reason for a revision if it is not provided in a subsequent revision" do
post = Fabricate(:post, raw: 'hello world')
revisor = PostRevisor.new(post)
revisor.revise!(post.user, { raw: 'hello world123456789', edit_reason: 'this is my reason' }, revised_at: post.updated_at + 1.second)
post.reload
revisor.revise!(post.user, { raw: 'hello some other thing' }, revised_at: post.updated_at + 1.second)
expect(post.revisions.first.modifications[:edit_reason]).to eq([nil, 'this is my reason'])
end
end
describe 'revision much later' do
let!(:revised_at) { post.updated_at + 2.minutes }