From a67edb8783ed3ed7ff2a87714ddfcb591fad0a39 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 7 Sep 2018 12:23:48 -0500 Subject: [PATCH] deviantart: fix artist finder for artist names with underscores. Fix the artist finder for urls like this: https://orig00.deviantart.net/4274/f/2010/230/8/a/pkmn_king_and_queen_by_mikoto_chan.jpg that don't contain a deviantart id but do contain the artist name. --- app/logical/sources/strategies/deviant_art.rb | 2 +- test/unit/sources/deviantart_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index 2f1d7952c..6fd513a0f 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -182,7 +182,7 @@ module Sources def self.artist_name_from_url(url) if url =~ ASSET || url =~ PATH_ART || url =~ PATH_PROFILE - $~[:artist] + $~[:artist].try(:dasherize) elsif url !~ RESERVED_SUBDOMAINS && (url =~ SUBDOMAIN_ART || url =~ SUBDOMAIN_PROFILE) $~[:artist] else diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index 88cc4bd27..2065ea3f5 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -82,6 +82,16 @@ module Sources end end + context "A source for a *.deviantart.net/*/:title_by_:artist.jpg url artist name containing underscores" do + should "find the correct artist" do + @site = Sources::Strategies.find("https://orig00.deviantart.net/4274/f/2010/230/8/a/pkmn_king_and_queen_by_mikoto_chan.jpg") + @artist = FactoryBot.create(:artist, name: "mikoto-chan", url_string: "https://www.deviantart.com/mikoto-chan") + + assert_equal("mikoto-chan", @site.artist_name) + assert_equal([@artist], @site.artists) + end + end + context "The source for a *.deviantart.net/*/:title_by_:artist.jpg url" do setup do @url = "http://fc08.deviantart.net/files/f/2007/120/c/9/cool_like_me_by_47ness.jpg"