sources: remove canonical_url method.
Refactor source strategies to remove the `canonical_url` method. `canonical_url` returned the URL that should be used as the source of the post after upload. Now we simply use `Source::URL#page_url` to determine the source after upload. If the source is an image URL that is convertible to a page URL, then the image URL is used as the source. If the source is an image URL that is not convertible to a page URL, then the page URL is used as the source. This simplifies source strategies so that all they have to care about is implementing the `Source::URL#page_url` and `Sources::Strategies#page_url` methods, and the preferred source will be chosen for posts automatically.
This commit is contained in:
@@ -53,10 +53,10 @@ module Sources
|
||||
9.times { |n| assert_match(expected[n], @site_3.image_urls[n]) }
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
assert_equal("https://seiga.nicovideo.jp/image/source/4937663", @site_1.canonical_url)
|
||||
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", @site_2.canonical_url)
|
||||
assert_equal("https://seiga.nicovideo.jp/watch/mg470189", @site_3.canonical_url)
|
||||
should "get the page url" do
|
||||
assert_equal("https://seiga.nicovideo.jp/image/source/4937663", @site_1.page_url)
|
||||
assert_equal("https://seiga.nicovideo.jp/seiga/im4937663", @site_2.page_url)
|
||||
assert_equal("https://seiga.nicovideo.jp/watch/mg470189", @site_3.page_url)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
@@ -83,7 +83,7 @@ module Sources
|
||||
site = Sources::Strategies.find("https://lohas.nicoseiga.jp/thumb/6844226i")
|
||||
|
||||
assert_match(%r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/6844226!, site.image_urls.sole)
|
||||
assert_match("https://seiga.nicovideo.jp/seiga/im6844226", site.canonical_url)
|
||||
assert_match("https://seiga.nicovideo.jp/seiga/im6844226", site.page_url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -98,8 +98,8 @@ module Sources
|
||||
assert_match(%r!https?://lohas.nicoseiga.jp/priv/[a-f0-9]{40}/[0-9]+/9146749!, @site.image_urls.sole)
|
||||
end
|
||||
|
||||
should "set the correct source" do
|
||||
assert_equal(@ref, @site.canonical_url)
|
||||
should "get the page url" do
|
||||
assert_equal(@ref, @site.page_url)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user