From 709a95b5e3c9028393d744d327ae68caba2c7c9d Mon Sep 17 00:00:00 2001 From: Bilka Date: Sat, 5 Oct 2024 02:06:08 +0200 Subject: [PATCH] AO3-5538 Update tag set nominations with old tagname when renaming tags (#4922) * AO3-5538 Update tag set nominations with old tagname when renaming tags * Attempt to annoy reviewdog * AO3-5538 Rubocop * AO3-5538 Unannoy reviewdog --- app/models/tag.rb | 10 ++++++++++ features/tag_sets/tag_set_nominations.feature | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/models/tag.rb b/app/models/tag.rb index ebbf35987a9..277b58d990a 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1188,6 +1188,16 @@ def update_tag_nominations parent_names << "" if parent_names.present? TagNomination.where(tagname: name, parent_tagname: parent_names).update_all(parented: true) + + return unless saved_change_to_name? && name_before_last_save.present? + + # Act as if the tag with the previous name was deleted and mirror clear_tag_nominations + TagNomination.where(tagname: name_before_last_save).update_all( + canonical: false, + exists: false, + parented: false, + synonym: nil + ) end before_destroy :clear_tag_nominations diff --git a/features/tag_sets/tag_set_nominations.feature b/features/tag_sets/tag_set_nominations.feature index d82f636159b..aee7353548b 100644 --- a/features/tag_sets/tag_set_nominations.feature +++ b/features/tag_sets/tag_set_nominations.feature @@ -322,3 +322,19 @@ Feature: Nominating and reviewing nominations for a tag set And I should not see "Someone else has already nominated the tag for this set but in fandom First." And I should not see "Gold" And I should see "None nominated in this fandom." + + Scenario: A nominated canonical tag can be renamed by a tag wrangling admin without affecting the nomination + Given a canonical character "Before" in fandom "Treasure Chest" + And I am logged in as "tagsetter" + And I set up the nominated tag set "Nominated Tags" with 1 fandom nom and 1 character nom + And I nominate fandom "Treasure Chest" and character "Before" in "Nominated Tags" as "tagsetter" + When I am logged in as an "tag_wrangling" admin + And I edit the tag "Before" + And I fill in "Name" with "After" + And I press "Save changes" + Then I should see "Tag was updated." + When I am logged in as "tagsetter" + And I go to the "Nominated Tags" tag set page + And I follow "My Nominations" + Then I should see "Treasure Chest" + And I should see "Before"