Skip to content

Commit

Permalink
Merge pull request #3453 from evazion/fix-3450
Browse files Browse the repository at this point in the history
Fix #3450: Aliased tags show up under translated tags.
  • Loading branch information
r888888888 committed Dec 25, 2017
2 parents b2ba0cb + 265377b commit fb0095d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/logical/sources/strategies/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def translated_tags

# Given a tag from the source site, should return an array of corresponding Danbooru tags.
def translate_tag(untranslated_tag)
translated_tags = Tag.where(name: WikiPage.active.other_names_equal(untranslated_tag).uniq.select(:title))
translated_tag_names = WikiPage.active.other_names_equal(untranslated_tag).uniq.pluck(:title)
translated_tag_names = TagAlias.to_aliased(translated_tag_names)
translated_tags = Tag.where(name: translated_tag_names)

if translated_tags.empty?
normalized_name = TagAlias.to_aliased([Tag.normalize_name(untranslated_tag)])
Expand Down
11 changes: 11 additions & 0 deletions test/unit/sources/pixiv_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ def get_source(source)
assert_includes(@translated_tags, "fate/grand_order")
assert_equal(false, @translated_tags.grep("fate").any?)
end

should "apply aliases to translated tags" do
tohsaka_rin = FactoryGirl.create(:tag, name: "tohsaka_rin")
toosaka_rin = FactoryGirl.create(:tag, name: "toosaka_rin")

FactoryGirl.create(:wiki_page, title: "tohsaka_rin", other_names: "遠坂凛")
FactoryGirl.create(:wiki_page, title: "toosaka_rin", other_names: "遠坂凛")
FactoryGirl.create(:tag_alias, antecedent_name: "tohsaka_rin", consequent_name: "toosaka_rin")

assert_equal([toosaka_rin], @site.translate_tag("遠坂凛"))
end
end
end
end
Expand Down

0 comments on commit fb0095d

Please sign in to comment.