From f02a31a447f12b07510fbeac30f000521d02d05e Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 4 Nov 2016 23:13:35 -0500 Subject: [PATCH] Autotag character_(cosplay) -> character, cosplay. Make e.g. hatsune_miku_(cosplay) automatically add hatsune_miku and cosplay. Perform autotagging after aliasing so that *_(cosplay) aliases (e.g. hestia_(dungeon)_(cosplay) -> hestia_(danmachi)_(cosplay)) can take effect first. --- app/models/post.rb | 6 +++++- test/unit/post_test.rb | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index aeee5aa19..cd5ff25ea 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -608,8 +608,8 @@ class Post < ActiveRecord::Base normalized_tags = remove_negated_tags(normalized_tags) normalized_tags = normalized_tags.map {|x| Tag.find_or_create_by_name(x).name} normalized_tags = %w(tagme) if normalized_tags.empty? - normalized_tags = add_automatic_tags(normalized_tags) normalized_tags = TagAlias.to_aliased(normalized_tags) + normalized_tags = add_automatic_tags(normalized_tags) normalized_tags = TagImplication.with_descendants(normalized_tags) normalized_tags.sort! set_tag_string(normalized_tags.uniq.sort.join(" ")) @@ -678,6 +678,10 @@ class Post < ActiveRecord::Base tags << "ugoira" end + characters = tags.grep(/\A(.+)_\(cosplay\)\Z/) { $1 } + tags += characters + tags << "cosplay" if characters.present? + return tags end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 994bd563f..ca385ece3 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -932,6 +932,20 @@ class PostTest < ActiveSupport::TestCase end end + context "with *_(cosplay) tags" do + setup do + @post.add_tag("hakurei_reimu_(cosplay)") + @post.add_tag("hatsune_miku_(cosplay)") + @post.save + end + + should "add the character tags and the cosplay tag" do + assert(@post.has_tag?("hakurei_reimu")) + assert(@post.has_tag?("hatsune_miku")) + assert(@post.has_tag?("cosplay")) + end + end + context "that has been updated" do should "create a new version if it's the first version" do assert_difference("PostVersion.count", 1) do