Skip to content

Commit

Permalink
Review + A bunch of tests for good measure
Browse files Browse the repository at this point in the history
  • Loading branch information
ceithir committed Sep 30, 2023
1 parent 008910d commit fbfd646
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,13 @@ def eligible_for_fandom_autocomplete?
end

def was_eligible_for_fandom_autocomplete?
(self.is_a?(Character) || self.is_a?(Relationship))
self.is_a?(Character) || self.is_a?(Relationship) && canonical_before_last_save
end

def remove_stale_from_autocomplete
super
if self.is_a?(Character) || self.is_a?(Relationship)

if was_eligible_for_fandom_autocomplete?
parents.each do |parent|
REDIS_AUTOCOMPLETE.zrem(self.transliterate("autocomplete_fandom_#{parent.name.downcase}_#{type.downcase}"), autocomplete_value_before_last_save) if parent.is_a?(Fandom)
end
Expand Down
34 changes: 34 additions & 0 deletions spec/models/tag_wrangling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,40 @@
character.destroy
expect_autocomplete_to_return(fandom, [])
end

it "adds to autocomplete when a character becomes canonical" do
fandom = create(:canonical_fandom)
character = create(:character)

fandom.add_association(character)
expect_autocomplete_to_return(fandom, [])

character.reload.update! canonical: true
expect_autocomplete_to_return(fandom, [character])
end

it "removes from autocomplete when a character loses its canonicity" do
fandom = create(:canonical_fandom)
character = create(:canonical_character)

fandom.add_association(character)
expect_autocomplete_to_return(fandom, [character])

character.reload.update! canonical: false
expect_autocomplete_to_return(fandom, [])
end

it "updates autocomplete when a character name changes" do
fandom = create(:canonical_fandom)
character = create(:canonical_character)

fandom.add_association(character)
expect_autocomplete_to_return(fandom, [character])

User.current_user = create(:admin)
character.reload.update! name: "Toto"
expect_autocomplete_to_return(fandom, [character])
end
end

def expect_autocomplete_to_return(fandom, characters)
Expand Down

0 comments on commit fbfd646

Please sign in to comment.