From 85f58bf2f6d46b0f07934eae228223b270079edc Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 24 Jun 2020 00:25:45 -0500 Subject: [PATCH] newgrounds: fix style nitpicks. --- app/logical/sources/strategies/newgrounds.rb | 15 +++++++-------- test/functional/uploads_controller_test.rb | 4 ++++ test/unit/sources/newgrounds_test.rb | 12 ++++++------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/logical/sources/strategies/newgrounds.rb b/app/logical/sources/strategies/newgrounds.rb index 69d5d737a..0fefba41d 100644 --- a/app/logical/sources/strategies/newgrounds.rb +++ b/app/logical/sources/strategies/newgrounds.rb @@ -7,19 +7,18 @@ # * https://www.newgrounds.com/art/view/puddbytes/costanza-at-bat # * https://www.newgrounds.com/art/view/natthelich/fire-emblem-marth-plus-progress-pic (multiple) # -# # Profile URLs # * https://natthelich.newgrounds.com/ module Sources module Strategies class Newgrounds < Base - IMAGE_URL = %r{https?://art\.ngfiles\.com/images/\d+/\d+_(?[0-9a-z-]+)_(?[0-9a-z-]+)\.\w+}i - COMMENT_URL = %r{https?://art\.ngfiles\.com/comments/\d+/\w+\.\w+}i + IMAGE_URL = %r{\Ahttps?://art\.ngfiles\.com/images/\d+/\d+_(?[0-9a-z-]+)_(?[0-9a-z-]+)\.\w+}i + COMMENT_URL = %r{\Ahttps?://art\.ngfiles\.com/comments/\d+/\w+\.\w+}i - PAGE_URL = %r{https?://(?:www\.)?newgrounds\.com/art/view/(?[0-9a-z-]+)/(?[0-9a-z-]+)(?:\?.*)?}i + PAGE_URL = %r{\Ahttps?://(?:www\.)?newgrounds\.com/art/view/(?[0-9a-z-]+)/(?[0-9a-z-]+)(?:\?.*)?}i - PROFILE_URL = %r{https?://(?(?!www)[0-9a-z-]+)\.newgrounds\.com(?:/.*)?}i + PROFILE_URL = %r{\Ahttps?://(?(?!www)[0-9a-z-]+)\.newgrounds\.com(?:/.*)?}i def domains ["newgrounds.com", "ngfiles.com"] @@ -50,11 +49,11 @@ module Sources def page return nil if page_url.blank? - doc = Danbooru::Http.cache(1.minute).get(page_url) - return if doc.code == 404 + response = Danbooru::Http.cache(1.minute).get(page_url) + return nil if response.status == 404 - Nokogiri::HTML(doc.body) + response.parse end memoize :page diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 10fab5471..1464db180 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -344,6 +344,10 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest should_upload_successfully("https://www.weibo.com/5501756072/J2UNKfbqV") should_upload_successfully("https://wx1.sinaimg.cn/mw690/0060kO5aly1gezsyt5xvhj30ok0sgtc9.jpg") + + should_upload_successfully("https://art.ngfiles.com/images/1254000/1254722_natthelich_pandora.jpg") + should_upload_successfully("https://art.ngfiles.com/comments/57000/iu_57615_7115981.jpg") + should_upload_successfully("https://www.newgrounds.com/art/view/puddbytes/costanza-at-bat") end end end diff --git a/test/unit/sources/newgrounds_test.rb b/test/unit/sources/newgrounds_test.rb index 8c7c57fcb..f4195de37 100644 --- a/test/unit/sources/newgrounds_test.rb +++ b/test/unit/sources/newgrounds_test.rb @@ -60,9 +60,9 @@ module Sources end should "find the right artist" do - artist_1 = FactoryBot.create(:artist, name: "natthelich1", url_string: "https://natthelich.newgrounds.com/art") - artist_2 = FactoryBot.create(:artist, name: "natthelich2", url_string: "https://www.newgrounds.com/art/view/natthelich/fire-emblem-marth-plus-progress-pic") - artist_3 = FactoryBot.create(:artist, name: "bad_artist", url_string: "https://www.newgrounds.com/art") + artist_1 = create(:artist, name: "natthelich1", url_string: "https://natthelich.newgrounds.com/art") + artist_2 = create(:artist, name: "natthelich2", url_string: "https://www.newgrounds.com/art/view/natthelich/fire-emblem-marth-plus-progress-pic") + artist_3 = create(:artist, name: "bad_artist", url_string: "https://www.newgrounds.com/art") assert_equal([artist_1, artist_2], @image_1.artists) assert_equal([artist_1, artist_2], @image_2.artists) @@ -75,13 +75,13 @@ module Sources context "A deleted or not existing picture" do setup do @fake_1 = Sources::Strategies.find("https://www.newgrounds.com/art/view/ThisUser/DoesNotExist") - @artist_1 = FactoryBot.create(:artist, name: "thisuser", url_string: "https://thisuser.newgrounds.com") + @artist_1 = create(:artist, name: "thisuser", url_string: "https://thisuser.newgrounds.com") @fake_2 = Sources::Strategies.find("https://www.newgrounds.com/art/view/natthelich/nopicture") - @artist_2 = FactoryBot.create(:artist, name: "natthelich", url_string: "https://natthelich.newgrounds.com") + @artist_2 = create(:artist, name: "natthelich", url_string: "https://natthelich.newgrounds.com") @fake_3 = Sources::Strategies.find("https://www.newgrounds.com/art/view/theolebrave/sensitive-pochaco") - @artist_3 = FactoryBot.create(:artist, name: "taffytoad", url_string: "https://taffytoad.newgrounds.com") + @artist_3 = create(:artist, name: "taffytoad", url_string: "https://taffytoad.newgrounds.com") end should "still find the artist name" do