From d693f01dde5902a1a78b45afc28dcd3912713380 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 1 Sep 2018 11:48:42 -0500 Subject: [PATCH] Fix #3859: Related tag and find artist don't run when fetch data fails. Fixes an exception in the artist finder caused by searching for a nil profile_url. --- app/logical/sources/strategies/base.rb | 7 +++--- app/logical/sources/strategies/null.rb | 8 ++----- test/unit/sources/null_test.rb | 32 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 test/unit/sources/null_test.rb diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index 2ca5c4796..e2c0f312a 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -71,11 +71,11 @@ module Sources # A link to the artist's profile page on the site. def profile_url - nil + "" end def artist_name - raise NotImplementedError + "" end def artist_commentary_title @@ -129,7 +129,8 @@ module Sources end def artists - Artist.find_artists(profile_url) + url = profile_url.presence || image_url.presence + Artist.find_artists(url) end def file_url diff --git a/app/logical/sources/strategies/null.rb b/app/logical/sources/strategies/null.rb index 3cb56085b..3be9a4035 100644 --- a/app/logical/sources/strategies/null.rb +++ b/app/logical/sources/strategies/null.rb @@ -13,8 +13,8 @@ module Sources url end - def artist_name - nil + def canonical_url + image_url end def normalized_for_artist_finder? @@ -38,10 +38,6 @@ module Sources def unique_id url end - - def rewrite(url, headers, data) - return [url, headers, data] - end end end end diff --git a/test/unit/sources/null_test.rb b/test/unit/sources/null_test.rb new file mode 100644 index 000000000..e575910b3 --- /dev/null +++ b/test/unit/sources/null_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + +module Sources + class NullTest < ActiveSupport::TestCase + context "A source from an unknown site" do + setup do + @site = Sources::Strategies.find("http://oremuhax.x0.com/yoro1603.jpg", "http://oremuhax.x0.com/yo125.htm") + end + + should "be handled by the null strategy" do + assert(@site.is_a?(Sources::Strategies::Null)) + end + + should "find the metadata" do + assert_equal("oremuhax.x0.com", @site.site_name) + assert_equal(["http://oremuhax.x0.com/yoro1603.jpg"], @site.image_urls) + assert_equal("http://oremuhax.x0.com/yoro1603.jpg", @site.image_url) + assert_equal("http://oremuhax.x0.com/yoro1603.jpg", @site.canonical_url) + assert_equal("", @site.artist_name) + assert_equal("", @site.profile_url) + assert_nothing_raised { @site.to_h } + end + + should "find the artist" do + a1 = FactoryBot.create(:artist, name: "test1", url_string: "http://oremuhax.x0.com") + a2 = FactoryBot.create(:artist, name: "test2", url_string: "http://google.com") + + assert_equal([a1], @site.artists) + end + end + end +end