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