Fix #5013: BUR model doesn't validate tags.
Don't allow users to request aliases, implications, or renames for invalid tag names. As a side effect, it's no longer possible to request shortcut aliases like `/hr -> hakurei_reimu` (slash abbreviations still exist, but they can't be overridden with aliases). Tests involving these types of aliases are removed.
This commit is contained in:
@@ -102,14 +102,6 @@ class AutocompleteServiceTest < ActiveSupport::TestCase
|
||||
assert_autocomplete_equals([], "/xxxxxxxxxx", :tag_query)
|
||||
assert_autocomplete_equals([], "/_", :tag_query)
|
||||
end
|
||||
|
||||
should "list aliases before abbreviations" do
|
||||
create(:tag, name: "hair_ribbon", post_count: 300_000)
|
||||
create(:tag, name: "hakurei_reimu", post_count: 50_000)
|
||||
create(:tag_alias, antecedent_name: "/hr", consequent_name: "hakurei_reimu")
|
||||
|
||||
assert_autocomplete_equals(%w[hakurei_reimu hair_ribbon], "/hr", :tag_query)
|
||||
end
|
||||
end
|
||||
|
||||
should "autocomplete tags from wiki and artist other names" do
|
||||
|
||||
@@ -151,6 +151,20 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
assert_equal(["Can't create alias aaa -> bbb (bbb is already aliased to ccc)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "fail if the antecedent name is invalid" do
|
||||
@bur = build(:bulk_update_request, script: "create alias tag_ -> tag")
|
||||
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't create alias tag_ -> tag ('tag_' cannot end with an underscore)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "fail if the consequent name is invalid" do
|
||||
@bur = build(:bulk_update_request, script: "create alias tag -> tag_")
|
||||
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't create alias tag -> tag_ ('tag_' cannot end with an underscore)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "be case-insensitive" do
|
||||
@bur = create_bur!("CREATE ALIAS AAA -> BBB", @admin)
|
||||
|
||||
@@ -221,6 +235,20 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't create implication white_shirt -> shirt ('white_shirt' must have at least 100 posts)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "fail if the antecedent name is invalid" do
|
||||
@bur = build(:bulk_update_request, script: "imply tag_ -> tag")
|
||||
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't create implication tag_ -> tag ('tag_' cannot end with an underscore)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "fail if the consequent name is invalid" do
|
||||
@bur = build(:bulk_update_request, script: "imply tag -> tag_")
|
||||
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't create implication tag -> tag_ ('tag_' cannot end with an underscore)"], @bur.errors.full_messages)
|
||||
end
|
||||
end
|
||||
|
||||
context "the remove alias command" do
|
||||
@@ -382,6 +410,14 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
assert_equal(["Can't rename aaa -> bbb ('aaa' has more than 200 posts, use an alias instead)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
should "fail if the consequent name is invalid" do
|
||||
create(:tag, name: "tag")
|
||||
@bur = build(:bulk_update_request, script: "rename tag -> tag_")
|
||||
|
||||
assert_equal(false, @bur.valid?)
|
||||
assert_equal(["Can't rename tag -> tag_ ('tag_' cannot end with an underscore)"], @bur.errors.full_messages)
|
||||
end
|
||||
|
||||
context "when moving an artist" do
|
||||
should "add the artist's old tag name to their other names" do
|
||||
assert_equal(["foo"], @artist.reload.other_names)
|
||||
|
||||
@@ -1276,12 +1276,11 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
should "resolve abbreviations to the actual tag" do
|
||||
tag1 = create(:tag, name: "hair_ribbon", post_count: 300_000)
|
||||
tag2 = create(:tag, name: "hakurei_reimu", post_count: 50_000)
|
||||
ta1 = create(:tag_alias, antecedent_name: "/hr", consequent_name: "hakurei_reimu")
|
||||
post1 = create(:post, tag_string: "hair_ribbon")
|
||||
post2 = create(:post, tag_string: "hakurei_reimu")
|
||||
|
||||
assert_tag_match([post2], "/hr")
|
||||
assert_tag_match([post1], "-/hr")
|
||||
assert_tag_match([post1], "/hr")
|
||||
assert_tag_match([post2], "-/hr")
|
||||
end
|
||||
|
||||
should "fail if the search exceeds the tag limit" do
|
||||
|
||||
@@ -1005,13 +1005,6 @@ class PostTest < ActiveSupport::TestCase
|
||||
assert_equal("aaa ccc", @post.tag_string)
|
||||
end
|
||||
|
||||
should "resolve aliases" do
|
||||
FactoryBot.create(:tag_alias, :antecedent_name => "/tr", :consequent_name => "translation_request")
|
||||
@post.update(:tag_string => "aaa translation_request -/tr")
|
||||
|
||||
assert_equal("aaa", @post.tag_string)
|
||||
end
|
||||
|
||||
should "resolve aliases before removing negated tags" do
|
||||
create(:tag_alias, antecedent_name: "female_focus", consequent_name: "female")
|
||||
|
||||
|
||||
@@ -83,11 +83,10 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
create(:tag, name: "hakurei_reimu", post_count: 50_000)
|
||||
create(:tag, name: "kirisama_marisa", post_count: 50_000)
|
||||
create(:tag, name: "kaname_madoka", post_count: 20_000)
|
||||
create(:tag_alias, antecedent_name: "/hr", consequent_name: "hakurei_reimu")
|
||||
|
||||
assert_equal(["hakurei_reimu"], TagAlias.to_aliased(["/hr"]))
|
||||
assert_equal(["hair_ribbon"], TagAlias.to_aliased(["/hr"]))
|
||||
assert_equal(["kirisama_marisa"], TagAlias.to_aliased(["/km"]))
|
||||
assert_equal(["hakurei_reimu", "kirisama_marisa"], TagAlias.to_aliased(["/hr", "/km"]))
|
||||
assert_equal(["hair_ribbon", "kirisama_marisa"], TagAlias.to_aliased(["/hr", "/km"]))
|
||||
end
|
||||
|
||||
context "saved searches" do
|
||||
|
||||
Reference in New Issue
Block a user