assign after source url for uploads

This commit is contained in:
Albert Yi
2018-07-30 17:39:22 -07:00
parent ad4756b5f2
commit 6ce8c72053
3 changed files with 21 additions and 12 deletions

View File

@@ -201,6 +201,7 @@ class UploadService
def download_from_source(source, referer_url: nil)
download = Downloads::File.new(source, referer_url: referer_url)
file = download.download!
context = {
downloaded_source: download.downloaded_source,
@@ -222,6 +223,7 @@ class UploadService
def download_for_upload(source, upload)
file = download_from_source(source, referer_url: upload.referer_url) do |context|
upload.downloaded_source = context[:downloaded_source]
upload.source = context[:source]
if context[:ugoira]
upload.context = { ugoira: context[:ugoira] }

View File

@@ -68,13 +68,20 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
end
context "for a pixiv post" do
context "for a twitter post" do
setup do
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720"
@source = "https://twitter.com/frappuccino/status/566030116182949888"
end
should "set the correct url" do
get_auth new_upload_path, @user, params: {url: @source}
should "render" do
skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key
get_auth new_upload_path, @user, params: {:url => @source}
assert_response :success
end
should "set the correct source" do
skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key
get_auth new_upload_path, @user, params: {:url => @source}
assert_response :success
Delayed::Worker.new.work_off
upload = Upload.last
@@ -82,14 +89,6 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
end
end
context "for a twitter post" do
should "render" do
skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key
get_auth new_upload_path, @user, params: {:url => "https://twitter.com/frappuccino/status/566030116182949888"}
assert_response :success
end
end
context "for a post that has already been uploaded" do
setup do
as_user do

View File

@@ -353,6 +353,14 @@ class UploadServiceTest < ActiveSupport::TestCase
CurrentUser.ip_addr = nil
end
should "record the correct source when a referer is given" do
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
@ref = "https://twitter.com/nounproject/status/540944400767922176"
@service = subject.new(source: @source, referer_url: @ref)
@upload = @service.start!
assert_equal(@ref, @upload.source)
end
should "work for a jpeg" do
@service = subject.new(source: @jpeg)
@upload = @service.start!