FIX: uploading an existing image as a site setting

The previous fix (f43c0a5d857d34) wasn't working for images that were already uploaded.
The "metadata" (eg. 'for_*' and 'secure' attributes) were not added to existing uploads.

Also used 'Upload.get_from_url' is the admin/site_setting controller to properly retrieve
an upload from its URL.

Fixed the Upload::URL_REGEX to use the \h (hexadecimal) for the SHA

Follow-up-to: f43c0a5d857d34
This commit is contained in:
Régis Hanol
2020-07-03 19:16:54 +02:00
parent 4c1e690e32
commit 48b4ed41f5
4 changed files with 22 additions and 22 deletions

View File

@ -17,18 +17,11 @@ describe UploadsController do
end
let(:logo_file) { file_from_fixtures("logo.png") }
let(:logo) do
Rack::Test::UploadedFile.new(logo_file)
end
let(:logo_filename) { File.basename(logo_file) }
let(:fake_jpg) do
Rack::Test::UploadedFile.new(file_from_fixtures("fake.jpg"))
end
let(:text_file) do
Rack::Test::UploadedFile.new(File.new("#{Rails.root}/LICENSE.txt"))
end
let(:logo) { Rack::Test::UploadedFile.new(logo_file) }
let(:fake_jpg) { Rack::Test::UploadedFile.new(file_from_fixtures("fake.jpg")) }
let(:text_file) { Rack::Test::UploadedFile.new(File.new("#{Rails.root}/LICENSE.txt")) }
it 'expects a type' do
post "/uploads.json", params: { file: logo }
@ -44,9 +37,13 @@ describe UploadsController do
it 'returns "raw" url for site settings' do
set_cdn_url "https://awesome.com"
upload = UploadCreator.new(logo_file, "logo.png").create_for(-1)
logo = Rack::Test::UploadedFile.new(file_from_fixtures("logo.png"))
post "/uploads.json", params: { file: logo, type: "site_setting", for_site_setting: "true" }
expect(response.status).to eq 200
expect(response.parsed_body["url"]).to start_with("/uploads/default/")
expect(response.parsed_body["url"]).to eq(upload.url)
end
it 'returns cdn url' do