require 'test_helper' module Sources class TumblrTest < ActiveSupport::TestCase def setup skip "Tumblr key is not configured" unless Sources::Strategies::Tumblr.enabled? end context "The source for a 'http://*.tumblr.com/post/*' photo post with a single image" do setup do @site = Sources::Strategies.find("https://noizave.tumblr.com/post/162206271767") end should "get the artist name" do assert_equal("noizave", @site.artist_name) end should "get the profile" do assert_equal("https://noizave.tumblr.com", @site.profile_url) end should "get the tags" do tags = ["tag", "red hair", "red-hair", "red_hair"] assert_equal(tags, @site.tags.map(&:first)) assert_equal(["red_hair", "tag"], @site.normalized_tags) end should "get the commentary" do desc = <<~EOS.chomp
plain bold italics strike
EOS assert_nil(@site.artist_commentary_title) assert_equal(desc, @site.artist_commentary_desc) end should "get the dtext-ified commentary" do desc = <<~EOS.chomp h2. header plain [b]bold[/b] [i]italics[/i] [s]strike[/s] * one * two * one * two [quote]quote[/quote] "link":[http://www.google.com] EOS assert_equal(desc, @site.dtext_artist_commentary_desc) end should "get the image url" do assert_equal("https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_1280.png", @site.image_url) end should "get the preview url" do assert_equal("https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_250.png", @site.preview_url) end should "get the canonical url" do assert_equal("https://noizave.tumblr.com/post/162206271767", @site.canonical_url) end should "get the artist" do CurrentUser.user = FactoryBot.create(:user) CurrentUser.ip_addr = "127.0.0.1" @artist = FactoryBot.create(:artist, name: "noizave", url_string: "https://noizave.tumblr.com/") assert_equal([@artist], @site.artists) end end context "The source for a 'http://*.tumblr.com/image/*' image page" do setup do @site = Sources::Strategies.find("https://noizave.tumblr.com/image/162206271767") end should "get the image url" do assert_equal("https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_os2buiIOt51wsfqepo1_1280.png", @site.image_url) end should "get the canonical url" do assert_equal("https://noizave.tumblr.com/post/162206271767", @site.canonical_url) end should "get the tags" do tags = ["tag", "red hair", "red-hair", "red_hair"] assert_equal(tags, @site.tags.map(&:first)) assert_equal(["red_hair", "tag"], @site.normalized_tags) end end context "The source for a 'http://*.media.tumblr.com/$hash/tumblr_$id_540.jpg' image" do setup do @url = "https://78.media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_540.jpg" @ref = "https://noizave.tumblr.com/post/162094447052" end context "with a referer" do should "get all the images and metadata" do site = Sources::Strategies.find(@url, @ref) assert_equal("noizave", site.artist_name) assert_equal("https://noizave.tumblr.com", site.profile_url) assert_equal(["tag1", "tag2"], site.tags.map(&:first)) assert_equal(@ref, site.canonical_url) assert_equal("https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg", site.image_url) assert_equal(%w[ https://media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_orwwptNBCE1wsfqepo1_1280.png https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg https://media.tumblr.com/d2ed224f135b0c81f812df81a0a8692d/tumblr_orwwptNBCE1wsfqepo3_640.gif https://media.tumblr.com/3bbfcbf075ddf969c996641b264086fd/tumblr_inline_os3134mABB1v11u29_1280.png https://media.tumblr.com/34ed9d0ff4a21625981372291cb53040/tumblr_nv3hwpsZQY1uft51jo1_1280.gif ], site.image_urls) end end context "without a referer" do should "get the original image" do site = Sources::Strategies.find(@url) assert_nil(site.artist_name) assert_nil(site.profile_url) assert_nil(site.canonical_url) assert_equal([], site.tags) assert_equal("https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg", site.image_url) assert_equal(["https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg"], site.image_urls) end end end context "The source for a 'http://*.tumblr.com/post/*' text post with inline images" do setup do @site = Sources::Strategies.find("https://noizave.tumblr.com/post/162221502947") end should "get the image urls" do urls = %w[ https://media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os2zhkfhY01v11u29_1280.png https://media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_inline_os2zkg02xH1v11u29_1280.jpg ] assert_equal(urls.sort, @site.image_urls.sort) end should "get the commentary" do desc = %r!quote
description

