Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is necessary. A nomination's parent_tagname should always be the name of a fandom unless the nominated tag itself is a fandom. For fandom nominations, it seems like the parent_tagname is always nil, never the name of a media tag. I took a look at staging to confirm:

3.4.6 :001 > noms = FandomNomination.where("parent_tagname IS NOT NULL") ; nil
 => nil 
3.4.6 :002 > noms.size
 => 0 
3.4.6 :003 > noms = FandomNomination.where(parent_tagname: "") ; nil
 => nil 
3.4.6 :004 > noms.size
 => 0 
3.4.6 :005 > noms = FandomNomination.where(parent_tagname: nil) ; nil
 => nil 
3.4.6 :006 > noms.size
 => 21488 
3.4.6 :007 > FandomNomination.all.count
 => 21488

Can you think of a scenario in which we'd expect to find a tag nomination with a non-fandom, non-blank, and non-nil parent_tagname?


# 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
Expand Down
21 changes: 21 additions & 0 deletions spec/models/tagset_models/tag_nomination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading