From 06559c4ae404982a807656b7d85c9c82c049d592 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Fri, 13 Apr 2018 12:25:49 -0700 Subject: [PATCH] fix missing urls in artists (fixes #3632) --- app/models/artist.rb | 12 +++++++----- app/views/artists/_form.html.erb | 2 +- test/unit/artist_test.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index 4f103fe22..bab1e0c39 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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, diff --git a/app/views/artists/_form.html.erb b/app/views/artists/_form.html.erb index 02c48b0c2..b286f8f6e 100644 --- a/app/views/artists/_form.html.erb +++ b/app/views/artists/_form.html.erb @@ -16,7 +16,7 @@ <%= 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" %> diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index f7014255c..85aac6243 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -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