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:
evazion
2022-04-30 19:25:18 -05:00
parent 0920d2ca24
commit ccd0dde081
10 changed files with 66 additions and 31 deletions

View File

@@ -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)