diff --git a/app/models/artist.rb b/app/models/artist.rb index ab533b37b..cc604789c 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -192,6 +192,7 @@ class Artist < ApplicationRecord # potential race condition but unlikely unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists? + Tag.find_or_create_by_name("artist:banned_artist") # ensure the banned_artist exists and is an artist tag. TagImplication.approve!(antecedent_name: name, consequent_name: "banned_artist", approver: banner) end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index aa583c87d..f84320636 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -7,6 +7,7 @@ class TagImplication < TagRelationship validate :absence_of_transitive_relation validate :antecedent_is_not_aliased validate :consequent_is_not_aliased + validate :tag_categories_are_compatible validate :has_wiki_page, on: :request concerning :HierarchyMethods do @@ -93,6 +94,12 @@ class TagImplication < TagRelationship end end + def tag_categories_are_compatible + if antecedent_tag.category != consequent_tag.category + errors[:base] << "Can't imply a #{antecedent_tag.category_name.downcase} tag to a #{consequent_tag.category_name.downcase} tag" + end + end + def has_wiki_page if !antecedent_tag.empty? && antecedent_wiki.blank? errors[:base] << "'#{antecedent_name}' must have a wiki page" diff --git a/test/unit/bulk_update_request_test.rb b/test/unit/bulk_update_request_test.rb index 4bcba51a1..204fdc048 100644 --- a/test/unit/bulk_update_request_test.rb +++ b/test/unit/bulk_update_request_test.rb @@ -140,6 +140,18 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase assert_equal(false, @bur.valid?) assert_equal(["Can't create implication a -> c (a already implies c through another implication)"], @bur.errors.full_messages) end + + should "fail for an implication between tags of different categories" do + create(:tag, name: "hatsune_miku", category: Tag.categories.character) + create(:tag, name: "vocaloid", category: Tag.categories.copyright) + create(:wiki_page, title: "hatsune_miku") + create(:wiki_page, title: "vocaloid") + + @bur = build(:bulk_update_request, script: "imply hatsune_miku -> vocaloid") + + assert_equal(false, @bur.valid?) + assert_equal(["Can't create implication hatsune_miku -> vocaloid (Can't imply a character tag to a copyright tag)"], @bur.errors.full_messages) + end end context "the remove alias command" do