posts: factor out post edit logic.

Factor out most of the tag edit logic from the Post class to a new
PostEdit class. The PostEdit class contains the logic for parsing tags
and metatags from the tag edit string, and for determining which tags
were added or removed by the edit.

Fixes various bugs caused by not calculating the set of added or removed
tags correctly, for example when tag category prefixes were used (e.g.
`copy:touhou`) or when the same tag was added and removed in the same
edit (e.g. `touhou -touhou`).

Fixes #5123: Tag categorization prefixes bypass deprecation check
Fixes #5126: Negating a deprecated tag will still cause the warning to show
Fixes #3477: Remove tag validator triggering on tag category changes
Fixes #4848: newpool: metatag doesn't parse correctly
This commit is contained in:
evazion
2022-04-27 19:44:58 -05:00
parent 6ac6f60b1b
commit bbe748bd2b
8 changed files with 374 additions and 235 deletions

View File

@@ -90,7 +90,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
should "render for an artist tag" do
create(:post, tag_string: "artist:bkub", rating: "s")
as(@user) { create(:post, tag_string: "artist:bkub", rating: "s") }
get posts_path, params: { tags: "bkub" }
assert_response :success
assert_select "#show-excerpt-link", count: 1, text: "Artist"
@@ -131,7 +131,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
end
should "render for a tag with a wiki page" do
create(:post, tag_string: "char:fumimi", rating: "s")
as(@user) { create(:post, tag_string: "char:fumimi", rating: "s") }
get posts_path, params: { tags: "fumimi" }
assert_response :success
assert_select "#show-excerpt-link", count: 1, text: "Wiki"

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class RelatedTagsControllerTest < ActionDispatch::IntegrationTest
context "The related tags controller" do
setup do
create(:post, tag_string: "copy:touhou")
as(create(:user)) { create(:post, tag_string: "copy:touhou") }
end
context "show action" do