Fix NoStrategyError during artist url normalization (#3382).
Fixes a bug from 9a3824a. When an artist entry is saved, `ArtistUrl.normalize`
is called on every URL, which calls `Sources::Site.new(url)`. This
raised NoStrategyError when an artist entry contained URLs that weren't
recognized by any strategy.
This also caused `Fetch source data` to fail in certain cases when it
attempted to find the artist.
This commit is contained in:
@@ -18,7 +18,7 @@ class ArtistUrl < ApplicationRecord
|
||||
url = url.sub(%r!^http://pictures.hentai-foundry.com//!, "http://pictures.hentai-foundry.com/")
|
||||
begin
|
||||
url = Sources::Site.new(url).normalize_for_artist_finder!
|
||||
rescue PixivApiClient::Error
|
||||
rescue PixivApiClient::Error, Sources::Site::NoStrategyError
|
||||
end
|
||||
url = url.gsub(/\/+\Z/, "")
|
||||
url + "/"
|
||||
@@ -75,6 +75,8 @@ class ArtistUrl < ApplicationRecord
|
||||
if !Sources::Site.new(normalized_url).normalized_for_artist_finder?
|
||||
self.normalized_url = self.class.normalize(url)
|
||||
end
|
||||
rescue Sources::Site::NoStrategyError
|
||||
self.normalized_url = self.class.normalize(url)
|
||||
end
|
||||
|
||||
def initialize_normalized_url
|
||||
|
||||
@@ -65,6 +65,14 @@ module Sources
|
||||
should "get the image url" do
|
||||
assert_equal("http://data.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_raw.png", @site.image_url)
|
||||
end
|
||||
|
||||
should "get the artist" do
|
||||
CurrentUser.user = FactoryGirl.create(:user)
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
|
||||
@artist = FactoryGirl.create(:artist, name: "noizave", url_string: "https://noizave.tumblr.com/")
|
||||
assert_equal([@artist], @site.artists)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source for a 'http://*.tumblr.com/image/*' image page" do
|
||||
|
||||
Reference in New Issue
Block a user