From 52de1fb98109d641897377c4cb3dbfa6cc6997b1 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Mon, 4 Jun 2018 17:37:43 -0700 Subject: [PATCH] clear artist urls before saving url string (fixes #3731) --- app/models/artist.rb | 6 ++---- test/unit/artist_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index a282b2200..012321165 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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 diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 7ca4d023f..f9998aa35 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -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