use tag name validator for artist names #3328
This commit is contained in:
@@ -8,7 +8,7 @@ class Artist < ApplicationRecord
|
|||||||
after_save :categorize_tag
|
after_save :categorize_tag
|
||||||
after_save :update_wiki
|
after_save :update_wiki
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
validate :validate_name
|
validates :name, tag_name: true
|
||||||
validate :validate_wiki, :on => :create
|
validate :validate_wiki, :on => :create
|
||||||
after_validation :merge_validation_errors
|
after_validation :merge_validation_errors
|
||||||
belongs_to :creator, :class_name => "User"
|
belongs_to :creator, :class_name => "User"
|
||||||
@@ -119,18 +119,6 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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
|
def normalize_name
|
||||||
self.name = Artist.normalize_name(name)
|
self.name = Artist.normalize_name(name)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
should "should have a valid name" do
|
should "should have a valid name" do
|
||||||
@artist = Artist.new(:name => "-blah")
|
@artist = Artist.new(:name => "-blah")
|
||||||
@artist.save
|
@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
|
end
|
||||||
|
|
||||||
context "with a matching tag alias" do
|
context "with a matching tag alias" do
|
||||||
|
|||||||
Reference in New Issue
Block a user