From d6d73404a9e4f2ed455d60f75900b7c00626f55b Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 6 Dec 2017 12:33:06 -0600 Subject: [PATCH] Apply aliases to characters in _(cosplay) tags (#3409). --- app/models/tag_implication.rb | 2 +- test/unit/post_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 9e1b75cde..d50e7df18 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -21,7 +21,7 @@ class TagImplication < TagRelationship end def automatic_tags_for(names) - tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { "char:#{$1}" } + tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { "char:#{TagAlias.to_aliased([$1]).first}" } tags << "cosplay" if tags.present? tags.uniq end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index a076af4e0..ffc3849e1 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -790,6 +790,14 @@ class PostTest < ActiveSupport::TestCase assert(Tag.where(name: "someone_(cosplay)", category: 4).exists?, "expected 'someone_(cosplay)' tag to be created as character") assert(Tag.where(name: "someone", category: 4).exists?, "expected 'someone' tag to be created") end + + should "apply aliases when the character tag is added" do + FactoryGirl.create(:tag_alias, antecedent_name: "jim", consequent_name: "james") + @post.add_tag("jim_(cosplay)") + @post.save + + assert(@post.has_tag?("james"), "expected 'jim' to be aliased to 'james'") + end end context "for a parent" do