Do not vacate tags if parameter not passed via API (#20513)

This commit is contained in:
Ben Halpern 2024-01-11 16:25:21 -05:00 committed by GitHub
parent 4be6df8baf
commit 1c25171cc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -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

View file

@ -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(