Files
danbooru/test/unit/sources/skeb_test.rb
2021-03-04 21:53:27 +01:00

76 lines
2.4 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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