From 4b2dcca8a29f7a4760d0288255d5a440b2454065 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 9 Oct 2017 16:24:09 -0700 Subject: [PATCH] use tag name validator for artist names #3328 --- app/models/artist.rb | 14 +------------- test/unit/artist_test.rb | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index 3cf2cbf87..8cde5fe13 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -8,7 +8,7 @@ class Artist < ApplicationRecord after_save :categorize_tag after_save :update_wiki validates_uniqueness_of :name - validate :validate_name + validates :name, tag_name: true validate :validate_wiki, :on => :create after_validation :merge_validation_errors belongs_to :creator, :class_name => "User" @@ -119,18 +119,6 @@ class Artist < ApplicationRecord end end - def validate_name - if name =~ /^[-~]/ - errors[:name] << "cannot begin with - or ~" - false - elsif name =~ /\*/ - errors[:name] << "cannot contain *" - false - else - true - end - end - def normalize_name self.name = Artist.normalize_name(name) end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index afcb9ddfd..92b21e337 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -28,7 +28,7 @@ class ArtistTest < ActiveSupport::TestCase should "should have a valid name" do @artist = Artist.new(:name => "-blah") @artist.save - assert_equal(["Name cannot begin with - or ~"], @artist.errors.full_messages) + assert_equal(["Name '-blah' cannot begin with a dash ('-')"], @artist.errors.full_messages) end context "with a matching tag alias" do