FIX: Converting PNG to JPEG does not set the correct extension.

This commit is contained in:
Guo Xiang Tan
2018-08-17 11:41:30 +08:00
parent 9628c3cf97
commit a9e502936f
3 changed files with 72 additions and 46 deletions

View File

@@ -163,46 +163,6 @@ describe UploadsController do
message = JSON.parse(response.body)["errors"]
expect(message).to contain_exactly(I18n.t("upload.images.size_not_found"))
end
describe 'when upload is not an image' do
before do
SiteSetting.authorized_extensions = 'txt'
end
let(:file) do
Rack::Test::UploadedFile.new(file_from_fixtures("utf-8.txt", "encodings"))
end
it 'should store the upload with the right extension' do
expect do
post "/uploads.json", params: { file: file, type: "composer" }
end.to change { Upload.count }.by(1)
upload = Upload.last
expect(upload.extension).to eq('txt')
expect(File.extname(upload.url)).to eq('.txt')
expect(upload.original_filename).to eq('utf-8.txt')
end
end
describe 'when image has the wrong extension' do
let(:file) do
Rack::Test::UploadedFile.new(file_from_fixtures("png_as.jpg"))
end
it 'should store the upload with the right extension' do
expect do
post "/uploads.json", params: { file: file, type: "avatar" }
end.to change { Upload.count }.by(1)
upload = Upload.last
expect(upload.extension).to eq('png')
expect(File.extname(upload.url)).to eq('.png')
expect(upload.original_filename).to eq('png_as.png')
end
end
end
end