Fix #3996: Some direct artstation urls cause the bookmarklet to fail.
* Don't fail on urls that don't contain the project id (direct image urls). * Don't fail when the work is deleted. * Parse artist name from url when possible. This way the artist finder works on bad_artstation_id posts. * Set canonical source url to `https://artist.artstation.com/projects/12345` instead of `https://www.artstation.com/artwork/1235` (this way we preserve the artist name). * Cache api call. * Include api call results in /source.json.
This commit is contained in:
@@ -11,6 +11,10 @@ module Sources
|
||||
assert_equal("https://cdna.artstation.com/p/assets/images/images/000/705/368/large/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
assert_equal("https://jeyrain.artstation.com/projects/04XA4", @site.canonical_url)
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("https://www.artstation.com/jeyrain", @site.profile_url)
|
||||
end
|
||||
@@ -25,7 +29,7 @@ module Sources
|
||||
|
||||
should "get the artist commentary" do
|
||||
assert_equal("pink", @site.artist_commentary_title)
|
||||
assert_equal("", @site.artist_commentary_desc)
|
||||
assert_equal("", @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,6 +43,10 @@ module Sources
|
||||
assert_equal(url, @site.image_url)
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
assert_equal("https://dantewontdie.artstation.com/projects/YZK5q", @site.canonical_url)
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("https://www.artstation.com/dantewontdie", @site.profile_url)
|
||||
end
|
||||
@@ -53,7 +61,7 @@ module Sources
|
||||
|
||||
should "get the artist commentary" do
|
||||
assert_equal("Reika ", @site.artist_commentary_title)
|
||||
assert_equal("From Gantz.", @site.artist_commentary_desc)
|
||||
assert_equal("From Gantz.", @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -72,11 +80,32 @@ module Sources
|
||||
setup do
|
||||
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg"
|
||||
@ref = "https://www.artstation.com/artwork/4BWW2"
|
||||
@site = Sources::Strategies.find(@url, @ref)
|
||||
end
|
||||
|
||||
should "fetch the source data" do
|
||||
assert_equal("amama", @site.artist_name)
|
||||
context "with a referer" do
|
||||
should "work" do
|
||||
site = Sources::Strategies.find(@url, @ref)
|
||||
|
||||
assert_equal(@url, site.image_url)
|
||||
assert_equal("https://amama.artstation.com/projects/4BWW2", site.page_url)
|
||||
assert_equal("https://amama.artstation.com/projects/4BWW2", site.canonical_url)
|
||||
assert_equal("https://www.artstation.com/amama", site.profile_url)
|
||||
assert_equal("amama", site.artist_name)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
|
||||
context "without a referer" do
|
||||
should "work" do
|
||||
site = Sources::Strategies.find(@url)
|
||||
|
||||
assert_equal(@url, site.image_url)
|
||||
assert_nil(site.page_url)
|
||||
assert_nil(site.profile_url)
|
||||
assert_nil(site.artist_name)
|
||||
assert_equal([], site.tags)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -90,5 +119,19 @@ module Sources
|
||||
assert_equal(urls, @site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "A work that has been deleted" do
|
||||
should "work" do
|
||||
url = "https://fiship.artstation.com/projects/x8n8XT"
|
||||
site = Sources::Strategies.find(url)
|
||||
|
||||
assert_equal("fiship", site.artist_name)
|
||||
assert_equal("https://www.artstation.com/fiship", site.profile_url)
|
||||
assert_equal(url, site.page_url)
|
||||
assert_equal(url, site.canonical_url)
|
||||
assert_nil(site.image_url)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user