artists: prevent creating artist entries for non-artist tags (#4107, 2717).

Validate that artist entries belong to an artist tag. Don't allow
creating artist entries for character/copyright/meta tags, but do allow
entries for general tags (the gentag will be automatically changed to an
artist tag).
This commit is contained in:
evazion
2019-08-01 20:11:27 -05:00
parent bcaefa0a7e
commit 065609ff4f
2 changed files with 37 additions and 17 deletions

View File

@@ -469,20 +469,36 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(%w[yyy], artist.other_names)
end
should "update the category of the tag when created" do
tag = FactoryBot.create(:tag, :name => "abc")
artist = FactoryBot.create(:artist, :name => "abc")
tag.reload
assert_equal(Tag.categories.artist, tag.category)
context "when creating" do
should "create a new artist tag if one does not already exist" do
FactoryBot.create(:artist, name: "bkub")
assert(Tag.exists?(name: "bkub", category: Tag.categories.artist))
end
should "change the tag to an artist tag if it was a gentag" do
tag = FactoryBot.create(:tag, name: "abc", category: Tag.categories.general)
artist = FactoryBot.create(:artist, name: "abc")
assert_equal(Tag.categories.artist, tag.reload.category)
end
should "not allow creating artist entries for non-artist tags" do
tag = FactoryBot.create(:tag, name: "touhou", category: Tag.categories.copyright)
artist = FactoryBot.build(:artist, name: "touhou")
assert(artist.invalid?)
assert_match(/'touhou' is a copyright tag/, artist.errors.full_messages.join)
end
end
should "update the category of the tag when renamed" do
tag = FactoryBot.create(:tag, :name => "def")
artist = FactoryBot.create(:artist, :name => "abc")
artist.name = "def"
artist.save
tag.reload
assert_equal(Tag.categories.artist, tag.category)
context "when renaming" do
should "change the new tag to an artist tag if it was a gentag" do
tag = FactoryBot.create(:tag, name: "def", category: Tag.categories.general)
artist = FactoryBot.create(:artist, name: "abc")
artist.update(name: "def")
assert_equal(Tag.categories.artist, tag.reload.category)
end
end
context "when saving" do