sources: factor out Source::URL::Newgrounds.

Also fix it so that the image URL is set as the source for Newgrounds
posts, not the page URL. It's possible to generate the page URL from the
image URL (except for images after the first in multi-image posts).

* Page: https://www.newgrounds.com/art/view/natthelich/weaver
* Image: https://art.ngfiles.com/images/1520000/1520217_natthelich_weaver.jpg?f1606365031
This commit is contained in:
evazion
2022-02-25 22:00:42 -06:00
parent 64472a7b7e
commit f062f2d145
4 changed files with 123 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
require 'test_helper'
module Sources
class NewGroundsTest < ActiveSupport::TestCase
class NewgroundsTest < ActiveSupport::TestCase
context "The source for a newgrounds picture" do
setup do
@url = "https://www.newgrounds.com/art/view/hcnone/sephiroth"
@@ -32,7 +32,7 @@ module Sources
should "get the canonical url" do
assert_equal(@url, @image_1.canonical_url)
assert_equal(@url, @image_2.canonical_url)
assert_equal(@image_url, @image_2.canonical_url)
end
should "download an image" do
@@ -62,6 +62,18 @@ module Sources
end
end
context "A multi-image Newgrounds post" do
should "get all the images" do
source = Sources::Strategies.find("https://www.newgrounds.com/art/view/natthelich/weaver")
image_urls = [
"https://art.ngfiles.com/images/1520000/1520217_natthelich_weaver.jpg?f1606365031",
"https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg",
]
assert_equal(image_urls, source.image_urls)
end
end
context "A deleted or not existing picture" do
setup do
@fake_1 = Sources::Strategies.find("https://www.newgrounds.com/art/view/ThisUser/DoesNotExist")