From 303cd928bda6873cff0d50bfd9cdc0a334d55356 Mon Sep 17 00:00:00 2001 From: Manu Vasconcelos <87862340+vasconsaurus@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:04:36 -0300 Subject: [PATCH] :create_project_media_tags should be able to ignore tag already added to item (#2068) A small fix to how tags are created in the background to make sure :create_project_media_tags is able to ignore tag already added to item. References: 5426, 5120 PR: 2068 --- app/models/annotations/tag.rb | 2 +- test/models/tag_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/annotations/tag.rb b/app/models/annotations/tag.rb index d5ac548f2..bc6a02b9b 100644 --- a/app/models/annotations/tag.rb +++ b/app/models/annotations/tag.rb @@ -97,7 +97,7 @@ def self.create_project_media_tags(project_media_id, tags_json) if !project_media.nil? tags = JSON.parse(tags_json) - clean_tags(tags).each { |tag| Tag.create! annotated: project_media, tag: tag.strip, skip_check_ability: true } + clean_tags(tags).each { |tag| Tag.create annotated: project_media, tag: tag.strip, skip_check_ability: true } else error = StandardError.new("[ProjectMedia] Exception creating project media's tags in background. Project media is nil.") CheckSentry.notify(error, project_media_id: project_media_id) diff --git a/test/models/tag_test.rb b/test/models/tag_test.rb index c1b7e14f5..505cfdf39 100644 --- a/test/models/tag_test.rb +++ b/test/models/tag_test.rb @@ -338,4 +338,16 @@ def setup assert_equal 1, pm2.reload.annotations('tag').count end + + test ":create_project_media_tags should be able to ignore tag already added to item" do + Sidekiq::Testing.fake! + + team = create_team + pm = create_project_media team: team + create_tag tag: 'two', annotated: pm + assert_equal 1, pm.reload.annotations('tag').count + + Tag.create_project_media_tags(pm.id, ['one', 'two', 'three'].to_json) + assert_equal 3, pm.reload.annotations('tag').count + end end