From c17e0baad016cb5718289a7825b2c46f0c347c8f Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Mon, 25 Jun 2018 13:59:43 -0700 Subject: [PATCH] prefer file over source when both are provided (#3767) --- app/logical/upload_service.rb | 2 +- test/functional/uploads_controller_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/logical/upload_service.rb b/app/logical/upload_service.rb index caad5dcb0..3b0307cf9 100644 --- a/app/logical/upload_service.rb +++ b/app/logical/upload_service.rb @@ -3,7 +3,7 @@ class UploadService def self.prepare(url: nil, file: nil, ref: nil) upload = Upload.new - if url + if Utils.is_downloadable?(url) && file.nil? download = Downloads::File.new(url) normalized_url, _, _ = download.before_download(url, {}) post = if normalized_url.nil? diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 16e5d64c7..b8325e320 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -32,6 +32,16 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest end end + context "preprocess action" do + should "prefer the file over the source when preprocessing" do + file = Rack::Test::UploadedFile.new("#{Rails.root}/test/files/test.jpg", "image/jpeg") + post_auth preprocess_uploads_path, @user, params: {:url => "http://www.google.com/intl/en_ALL/images/logo.gif", :file => file} + assert_response :success + Delayed::Worker.new.work_off + assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", Upload.last.md5) + end + end + context "new action" do should "render" do get_auth new_upload_path, @user