From 5ddedb965173e60008a4925265618b0185373d56 Mon Sep 17 00:00:00 2001 From: Pablo Monfort Date: Sat, 30 May 2026 19:56:43 -0300 Subject: [PATCH] AO3-6811 Fix tag nomination parented bug --- app/models/tag.rb | 8 +++---- .../tagset_models/tag_nomination_spec.rb | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index 95c7a4aa0e9..5f023af3098 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1248,15 +1248,15 @@ def update_tag_nominations ) if canonical? - # Calculate the fandoms associated with this tag, because we'll set any + # Calculate the parents associated with this tag, because we'll set any # TagNominations with a matching parent_tagname to have parented: true. - parent_names = parents.where(type: "Fandom").pluck(:name) + parent_names = parents.pluck(:name) - # If this tag has any fandoms at all, we also want to count it as parented + # If this tag has any parents at all, we also want to count it as parented # for nominations with a blank parent_tagname. See the set_parented # function in TagNominations for the calculation that we're trying to mimic # here. - parent_names << "" if parent_names.present? + parent_names.push("", nil) if parent_names.present? TagNomination.where(tagname: name, parent_tagname: parent_names).update_all(parented: true) end diff --git a/spec/models/tagset_models/tag_nomination_spec.rb b/spec/models/tagset_models/tag_nomination_spec.rb index 6e680544b16..06d055f6de9 100644 --- a/spec/models/tagset_models/tag_nomination_spec.rb +++ b/spec/models/tagset_models/tag_nomination_spec.rb @@ -62,5 +62,26 @@ end end end + + context "when the nominated tag is a canonical fandom with a media parent" do + let(:media) { create(:media) } + let(:fandom) { create(:canonical_fandom) } + + before do + create(:common_tagging, filterable: media, common_tag: fandom) + end + + let(:nomination) { create(:tag_nomination, tagname: fandom.name, type: "FandomNomination") } + + it "sets parented to true" do + expect(nomination.parented).to be(true) + end + + it "keeps parented true after the tag is re-saved" do + nomination + fandom.save! + expect(nomination.reload.parented).to be(true) + end + end end end