fixes #3727
This commit is contained in:
@@ -180,8 +180,13 @@ class Artist < ApplicationRecord
|
||||
|
||||
def save_urls
|
||||
if url_string && saved_change_to_url_string?
|
||||
self.urls = url_string.scan(/[^[:space:]]+/).uniq.map do |url|
|
||||
self.urls.find_or_create_by(url: url)
|
||||
Artist.transaction do
|
||||
self.urls = url_string.scan(/[^[:space:]]+/).uniq.map do |url|
|
||||
# need to do these shenanigans to properly handle prefixes
|
||||
aurl = self.urls.find_or_create_by(url: ArtistUrl.strip_prefixes(url))
|
||||
aurl.update(url: url)
|
||||
aurl
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
class ArtistUrl < ApplicationRecord
|
||||
before_validation :parse_prefix
|
||||
before_save :initialize_normalized_url, on: [ :create ]
|
||||
before_save :normalize
|
||||
validates :url, presence: true
|
||||
before_validation :initialize_normalized_url, on: :create
|
||||
before_validation :normalize
|
||||
validates :url, presence: true, uniqueness: { scope: :artist_id }
|
||||
validate :validate_url_format
|
||||
belongs_to :artist, :touch => true
|
||||
|
||||
def self.strip_prefixes(url)
|
||||
url.sub(/^[-]+/, "")
|
||||
end
|
||||
|
||||
def self.is_active?(url)
|
||||
url !~ /^-/
|
||||
end
|
||||
|
||||
def self.normalize(url)
|
||||
if url.nil?
|
||||
nil
|
||||
@@ -60,7 +68,8 @@ class ArtistUrl < ApplicationRecord
|
||||
end
|
||||
|
||||
def parse_prefix
|
||||
if url && url[0] == "-"
|
||||
case url
|
||||
when /^-/
|
||||
self.url = url[1..-1]
|
||||
self.is_active = false
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
var tags = $("#tags").val();
|
||||
$.post("<%= Danbooru.config.reportbooru_server %>/missed_searches", {
|
||||
sig: "<%= sig %>"
|
||||
});
|
||||
|
||||
@@ -42,6 +42,13 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
refute(@artist.urls[0].is_active?)
|
||||
end
|
||||
|
||||
should "allow deactivating a url" do
|
||||
@artist = Artist.create(name: "blah", url_string: "http://monet.com")
|
||||
@artist.update(url_string: "-http://monet.com")
|
||||
assert_equal(1, @artist.urls.count)
|
||||
refute(@artist.urls[0].is_active?)
|
||||
end
|
||||
|
||||
should "should have a valid name" do
|
||||
@artist = Artist.new(:name => "-blah")
|
||||
@artist.save
|
||||
|
||||
Reference in New Issue
Block a user