From 1c25171cc693e67612bc22e704bc66b6daf8e1ef Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Thu, 11 Jan 2024 16:25:21 -0500 Subject: [PATCH] Do not vacate tags if parameter not passed via API (#20513) --- app/services/articles/attributes.rb | 2 +- spec/requests/api/v1/articles_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/services/articles/attributes.rb b/app/services/articles/attributes.rb index fc3e888b7..07dff2edd 100644 --- a/app/services/articles/attributes.rb +++ b/app/services/articles/attributes.rb @@ -15,7 +15,7 @@ module Articles hash = attributes.slice(*ATTRIBUTES) # don't reset the collection when no series was passed hash[:collection] = collection if attributes.key?(:series) - hash[:tag_list] = tag_list + hash[:tag_list] = tag_list if !attributes[:tag_list].nil? || !attributes[:tags].nil? hash[:edited_at] = Time.current if update_edited_at hash[:published_at] = hash[:published_at].to_datetime if hash[:published_at] hash diff --git a/spec/requests/api/v1/articles_spec.rb b/spec/requests/api/v1/articles_spec.rb index abee27188..54becd2cc 100644 --- a/spec/requests/api/v1/articles_spec.rb +++ b/spec/requests/api/v1/articles_spec.rb @@ -1051,6 +1051,27 @@ RSpec.describe "Api::V1::Articles" do end.to change(article, :body_markdown) && change(article, :cached_tag_list) end + it "does not update the tags if not included in the request" do + article.update_column(:cached_tag_list, "meta, discussion") + expect do + put_article( + body_markdown: "something here", + ) + article.reload + end.not_to change(article, :cached_tag_list) + end + + it "does update the tags if empty string is provided" do + article.update_column(:cached_tag_list, "meta, discussion") + expect do + put_article( + body_markdown: "something here", + tags: %w[], + ) + article.reload + end.to change(article, :cached_tag_list) + end + it "assigns the article to a new series belonging to the user" do expect do put_article(