diff --git a/app/models/artist.rb b/app/models/artist.rb index 3b54ee35d..6af574ac5 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -8,9 +8,8 @@ class Artist < ApplicationRecord after_save :categorize_tag after_save :update_wiki after_save :save_urls - validates_uniqueness_of :name validates_associated :urls - validates :name, tag_name: true + validates :name, tag_name: true, uniqueness: true validate :validate_wiki, :on => :create after_validation :merge_validation_errors belongs_to_creator diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index a6df35c0a..a8aeb0b35 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -56,10 +56,12 @@ class ArtistTest < ActiveSupport::TestCase assert(@artist.urls[0].is_active?) end - should "should have a valid name" do - @artist = Artist.new(:name => "-blah") - @artist.save - assert_equal(["Name '-blah' cannot begin with a dash ('-')"], @artist.errors.full_messages) + context "with an invalid name" do + subject { FactoryBot.build(:artist) } + + should_not allow_value("-blah").for(:name) + should_not allow_value("_").for(:name) + should_not allow_value("").for(:name) end context "with a matching tag alias" do