mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
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:
@ -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 }
|
||||
|
Reference in New Issue
Block a user