A platform for community discussion. Free, open, simple.
FIX: reset `edit_reason` in posts when creating a new version.
Vinoth Kannana0e0b1ef4bc1
diff --git a/lib/post_revisor.rb b/lib/post_revisor.rbindex 3dd7459b501..c5c61679f62 100644--- a/lib/post_revisor.rb+++ b/lib/post_revisor.rb@@ -359,7 +359,7 @@ class PostRevisorendPOST_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.iddiff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rbindex 228b5fbe0bc..7d4f4fc74a1 100644--- a/spec/components/post_revisor_spec.rb+++ b/spec/components/post_revisor_spec.rb@@ -208,6 +208,19 @@ describe PostRevisor doexpect(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" dopost = Fabricate(:post, raw: 'hello world', edit_reason: 'this is my reason')revisor = PostRevisor.new(post)