FIX: reset `edit_reason` in posts when creating a new version.

This commit is contained in:
Vinoth Kannan 2020-02-07 09:40:16 +05:30
parent 5eb3255b02
commit a0e0b1ef4b
2 changed files with 14 additions and 1 deletions

View File

@ -359,7 +359,7 @@ class PostRevisor
end
POST_TRACKED_FIELDS.each do |field|
@post.public_send("#{field}=", @fields[field]) if @fields.has_key?(field)
@post.public_send("#{field}=", @fields[field]) if @fields.has_key?(field) || (should_create_new_version? && field == "edit_reason")
end
@post.last_editor_id = @editor.id

View File

@ -208,6 +208,19 @@ describe PostRevisor do
expect(post.revisions.count).to eq(1)
end
it "resets the edit_reason attribute in post model" do
SiteSetting.editing_grace_period = 5
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.edit_reason).to eq('this is my reason')
revisor.revise!(post.user, { raw: 'hello world4321' }, revised_at: post.updated_at + 6.second)
post.reload
expect(post.edit_reason).not_to be_present
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)