From 6ce8c720534025fc4b73066d98c001f0fd99ed87 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Mon, 30 Jul 2018 17:39:22 -0700 Subject: [PATCH] assign after source url for uploads --- app/logical/upload_service/utils.rb | 2 ++ test/functional/uploads_controller_test.rb | 23 +++++++++++----------- test/models/upload_service_test.rb | 8 ++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/logical/upload_service/utils.rb b/app/logical/upload_service/utils.rb index 08194d50b..91cac70e6 100644 --- a/app/logical/upload_service/utils.rb +++ b/app/logical/upload_service/utils.rb @@ -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] } diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 4e5593a0e..fdfcf752a 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -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 diff --git a/test/models/upload_service_test.rb b/test/models/upload_service_test.rb index 9e19cd289..fe7985977 100644 --- a/test/models/upload_service_test.rb +++ b/test/models/upload_service_test.rb @@ -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!