ability to get an image's alternative version

This commit is contained in:
Alexis Reigel 2018-04-12 14:11:21 +02:00 committed by Alexis Reigel
parent 46328b1242
commit 256d959729
No known key found for this signature in database
GPG key ID: C728AF10972E97C0
2 changed files with 29 additions and 1 deletions

View file

@ -31,7 +31,13 @@ module UploadsActions
disposition = uploader.image_or_video? ? 'inline' : 'attachment'
send_upload(uploader, attachment: uploader.filename, disposition: disposition)
uploader_version = uploader.versions.values.find { |version| version.filename == params[:filename] }
if uploader_version
return send_upload(uploader_version, attachment: uploader_version.filename, disposition: disposition)
end
return send_upload(uploader, attachment: uploader.filename, disposition: disposition)
end
private

View file

@ -560,5 +560,27 @@ describe UploadsController do
end
end
end
context 'the version filename must match' do
let!(:appearance) { create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'), 'image/png') }
context 'has a valid filename on the version file' do
it 'successfully returns the file' do
get :show, model: 'appearance', mounted_as: 'favicon', id: appearance.id, filename: 'favicon_main_dk.png'
expect(response).to have_gitlab_http_status(200)
expect(response.header['Content-Disposition']).to eq 'inline; filename="favicon_main_dk.png"'
end
end
context 'has an invalid filename on the version file' do
it 'returns the original file' do
get :show, model: 'appearance', mounted_as: 'favicon', id: appearance.id, filename: 'favicon_bogusversion_dk.png'
expect(response).to have_gitlab_http_status(200)
expect(response.header['Content-Disposition']).to eq 'inline; filename="dk.png"'
end
end
end
end
end