Skip to content

Commit

Permalink
:create_project_media_tags should be able to ignore tag already added…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
vasconsaurus authored Oct 7, 2024
1 parent 0c1917e commit 303cd92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/annotations/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions test/models/tag_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 303cd92

Please sign in to comment.