fix missing urls in artists (fixes #3632)
This commit is contained in:
@@ -2,7 +2,7 @@ class Artist < ApplicationRecord
|
||||
extend Memoist
|
||||
class RevertError < Exception ; end
|
||||
|
||||
attribute :url_string, :string, default: ""
|
||||
attribute :url_string, :string, default: nil
|
||||
before_validation :normalize_name
|
||||
after_save :create_version
|
||||
after_save :categorize_tag
|
||||
@@ -179,8 +179,10 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def save_urls
|
||||
self.urls = url_string.scan(/[^[:space:]]+/).uniq.map do |url|
|
||||
self.urls.find_or_create_by(url: url)
|
||||
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)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -263,7 +265,7 @@ class Artist < ApplicationRecord
|
||||
:name => name,
|
||||
:updater_id => CurrentUser.id,
|
||||
:updater_ip_addr => CurrentUser.ip_addr,
|
||||
:url_string => url_string,
|
||||
:url_string => url_string || url_array.join("\n"),
|
||||
:is_active => is_active,
|
||||
:is_banned => is_banned,
|
||||
:other_names => other_names,
|
||||
@@ -275,7 +277,7 @@ class Artist < ApplicationRecord
|
||||
prev = versions.last
|
||||
prev.update_attributes(
|
||||
:name => name,
|
||||
:url_string => url_string,
|
||||
:url_string => url_string || url_array.join("\n"),
|
||||
:is_active => is_active,
|
||||
:is_banned => is_banned,
|
||||
:other_names => other_names,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
<%= f.input :other_names_comma, :hint => "Separate with commas", :as => :text, :label => "Other names" %>
|
||||
<%= f.input :group_name %>
|
||||
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5"} %>
|
||||
<%= f.input :url_string, :label => "URLs", :as => :text, :input_html => {:size => "50x5", :value => @artist.url_array.join("\n")} %>
|
||||
|
||||
<%= dtext_field "artist", "notes" %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
|
||||
@@ -191,6 +191,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
|
||||
context "when finding deviantart artists" do
|
||||
setup do
|
||||
skip "deviant art is not configured" unless Danbooru.config.deviantart_client_id.present?
|
||||
FactoryBot.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
|
||||
FactoryBot.create(:artist, :name => "trixia", :url_string => "http://trixdraws.deviantart.com/")
|
||||
end
|
||||
@@ -461,5 +462,17 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "that is deleted" do
|
||||
setup do
|
||||
@artist = create(:artist, url_string: "https://google.com")
|
||||
@artist.update_attribute(:is_active, false)
|
||||
@artist.reload
|
||||
end
|
||||
|
||||
should "preserve the url string" do
|
||||
assert_equal(1, @artist.urls.count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user