Commit 52de1fb9 authored by Albert Yi's avatar Albert Yi

clear artist urls before saving url string (fixes #3731)

parent dd684891
......@@ -181,11 +181,9 @@ class Artist < ApplicationRecord
def save_urls
if url_string && saved_change_to_url_string?
Artist.transaction do
self.urls.clear
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
self.urls.find_or_create_by(url: url)
end
end
end
......
......@@ -49,6 +49,13 @@ class ArtistTest < ActiveSupport::TestCase
refute(@artist.urls[0].is_active?)
end
should "allow activating 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)
assert(@artist.urls[0].is_active?)
end
should "should have a valid name" do
@artist = Artist.new(:name => "-blah")
@artist.save
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment