From 2b5625bbf02d1788110c8c1c36a11cb8995f09c3 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 29 Jul 2021 20:14:25 +0800 Subject: [PATCH] FIX: Avoid creating a post revision when topic tags have not changed. (#13881) Co-authored-by: jmperez127 --- app/controllers/topics_controller.rb | 5 +++++ spec/requests/topics_controller_spec.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 7089f89ee01..150c56e7570 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -372,6 +372,11 @@ class TopicsController < ApplicationController changes.delete(:title) if topic.title == changes[:title] changes.delete(:category_id) if topic.category_id.to_i == changes[:category_id].to_i + if Tag.include_tags? + topic_tags = topic.tags.map(&:name).sort + changes.delete(:tags) if changes[:tags]&.sort == topic_tags + end + success = true if changes.length > 0 diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb index d81b0ed8d37..434d83094a1 100644 --- a/spec/requests/topics_controller_spec.rb +++ b/spec/requests/topics_controller_spec.rb @@ -1470,6 +1470,18 @@ RSpec.describe TopicsController do expect(response.status).to eq(200) expect(topic.tags).to eq([]) end + + it 'does not cause a revision when tags have not changed' do + topic.tags << tag + + expect do + put "/t/#{topic.slug}/#{topic.id}.json", params: { + tags: [tag.name] + } + end.to change { topic.reload.first_post.revisions.count }.by(0) + + expect(response.status).to eq(200) + end end context 'when topic is private' do