From f135a7c064e5338d2b72eb9770c30d1701a1ef02 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 16 Sep 2018 14:48:36 -0500 Subject: [PATCH] twitter: normalize canonical urls. Normalize http://mobile.twitter.com to http://twitter.com in canonical urls. --- app/logical/sources/strategies/twitter.rb | 9 ++------- test/unit/sources/twitter_test.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/logical/sources/strategies/twitter.rb b/app/logical/sources/strategies/twitter.rb index 9139b6005..7d4919a8b 100644 --- a/app/logical/sources/strategies/twitter.rb +++ b/app/logical/sources/strategies/twitter.rb @@ -61,13 +61,8 @@ module Sources::Strategies end def page_url - [url, referer_url].each do |x| - if self.class.status_id_from_url(x).present? - return x - end - end - - return super + return "" if status_id.blank? || artist_name.blank? + "https://twitter.com/#{artist_name}/status/#{status_id}" end def profile_url diff --git a/test/unit/sources/twitter_test.rb b/test/unit/sources/twitter_test.rb index 078bae6a8..62a59484f 100644 --- a/test/unit/sources/twitter_test.rb +++ b/test/unit/sources/twitter_test.rb @@ -89,8 +89,10 @@ module Sources @site = Sources::Strategies.find("https://mobile.twitter.com/Strangestone/status/556440271961858051") end - should "get the image url" do + should "get the urls" do assert_equal("https://pbs.twimg.com/media/B7jfc1JCcAEyeJh.png:orig", @site.image_url) + assert_equal("https://twitter.com/Strangestone/status/556440271961858051", @site.page_url) + assert_equal("https://twitter.com/Strangestone/status/556440271961858051", @site.canonical_url) end end @@ -111,6 +113,10 @@ module Sources assert_equal("https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig", @site.image_url) end + should "get the canonical url" do + assert_equal("https://twitter.com/nounproject/status/540944400767922176", @site.canonical_url) + end + should "get the tags" do assert_equal([], @site.tags) end @@ -166,6 +172,10 @@ module Sources should "fetch the source data" do assert_equal("https://twitter.com/motty08111213", @site.profile_url) end + + should "get the canonical url" do + assert_equal("https://twitter.com/motty08111213/status/943446161586733056", @site.canonical_url) + end end context "A deleted tweet" do