Add skeb support

This commit is contained in:
nonamethanks
2021-03-04 21:48:47 +01:00
parent 52adf87489
commit dc97f4483b
4 changed files with 184 additions and 3 deletions

View File

@@ -0,0 +1,75 @@
require 'test_helper'
module Sources
class SkebTest < ActiveSupport::TestCase
context "The source for a skeb picture" do
setup do
@site = Sources::Strategies.find("https://skeb.jp/@kai_chiisame/works/6")
end
should "get the artist name" do
assert_equal("kai_chiisame", @site.artist_name)
end
should "get the artist commentary" do
commentary = <<~COMM.chomp
 
 
 NSFW指定にしましたがエロでなくていいです
COMM
assert_equal(commentary, @site.artist_commentary_desc)
end
should "get profile url" do
assert_equal("https://skeb.jp/@kai_chiisame", @site.profile_url)
end
should "get the image url" do
assert_equal("https://skeb.imgix.net/requests/229088_2?bg=%23fff&auto=format&w=800&s=9cac8b76c0838f2df4f19ebc41c1ae0a", @site.image_url)
end
should "get the canonical url" do
assert_equal("https://skeb.jp/@kai_chiisame/works/6", @site.canonical_url)
end
should "find the correct artist" do
artist = FactoryBot.create(:artist, name: "kai_chiisame", url_string: @site.url)
assert_equal([artist], @site.artists)
end
should "not fail" do
assert_nothing_raised { @site.to_h }
end
end
context "A private or non-existent skeb url" do
setup do
@site = Sources::Strategies.find("https://skeb.jp/@kai_chiisame/works/2")
end
should "not raise anything" do
assert_nothing_raised { @site.to_h }
end
should "still find the right artist" do
artist = FactoryBot.create(:artist, name: "kai_chiisame", url_string: @site.url)
assert_equal([artist], @site.artists)
end
end
context "normalizing for source" do
should "avoid normalizing unnormalizable urls" do
bad_source = "https://skeb.imgix.net/requests/229088_2?bg=%23fff&auto=format&w=800&s=9cac8b76c0838f2df4f19ebc41c1ae0a"
assert_equal(bad_source, Sources::Strategies.normalize_source(bad_source))
end
end
end
end