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(