Convert to an autosave association on urls. This ensures that when we save the artist we only validate the added urls, not bad urls that we're trying to remove, and that url validation errors are propagated up to the artist object. This also fixes invalid urls being saved in the artist history despite validation failing (#3720).
This commit is contained in:
@@ -166,9 +166,19 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not allow invalid urls" do
|
||||
artist = FactoryBot.create(:artist, :url_string => "blah")
|
||||
artist = FactoryBot.build(:artist, :url_string => "blah")
|
||||
assert_equal(false, artist.valid?)
|
||||
assert_equal([" blah must begin with http:// or https://"], artist.errors[:url])
|
||||
assert_equal(["'blah' must begin with http:// or https:// "], artist.errors["urls.url"])
|
||||
end
|
||||
|
||||
should "allow fixing invalid urls" do
|
||||
artist = FactoryBot.build(:artist)
|
||||
artist.urls << FactoryBot.build(:artist_url, url: "www.example.com", normalized_url: "www.example.com")
|
||||
artist.save(validate: false)
|
||||
|
||||
artist.update(url_string: "http://www.example.com")
|
||||
assert_equal(true, artist.valid?)
|
||||
assert_equal("http://www.example.com", artist.urls.map(&:to_s).join)
|
||||
end
|
||||
|
||||
should "make sure old urls are deleted" do
|
||||
|
||||
@@ -17,10 +17,17 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "allow urls to be marked as inactive" do
|
||||
url = FactoryBot.create(:artist_url, :url => "-http://monet.com")
|
||||
url = FactoryBot.create(:artist_url, url: "http://monet.com", is_active: false)
|
||||
assert_equal("http://monet.com", url.url)
|
||||
assert_equal("http://monet.com/", url.normalized_url)
|
||||
refute(url.is_active?)
|
||||
assert_equal("-http://monet.com", url.to_s)
|
||||
end
|
||||
|
||||
should "disallow invalid urls" do
|
||||
url = FactoryBot.build(:artist_url, url: "www.example.com")
|
||||
|
||||
assert_equal(false, url.valid?)
|
||||
assert_match(/must begin with http/, url.errors.full_messages.join)
|
||||
end
|
||||
|
||||
should "always add a trailing slash when normalized" do
|
||||
|
||||
Reference in New Issue
Block a user