mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: correctly store width and height on uploads
Previously we used width and height for thumbnails, new code ensures 1. We auto correct width and height 2. We added extra columns for thumbnail_width and height, this is determined by actual upload and no longer passed in as a side effect 3. Optimized Image now stores filesize which can be used for analysis, decisions Also - fixes Android image manifest as a side effect - fixes issue where a thumbnail generated that is smaller than the upload is no longer used
This commit is contained in:
@@ -54,22 +54,35 @@ describe OptimizedImage do
|
||||
end
|
||||
|
||||
it 'should work correctly' do
|
||||
tmp_path = "/tmp/resized.png"
|
||||
|
||||
begin
|
||||
OptimizedImage.resize(
|
||||
"#{Rails.root}/spec/fixtures/images/logo.png",
|
||||
tmp_path,
|
||||
5,
|
||||
5
|
||||
)
|
||||
file = File.open("#{Rails.root}/spec/fixtures/images/resized.png")
|
||||
upload = UploadCreator.new(file, "test.bin").create_for(-1)
|
||||
|
||||
expect(File.read(tmp_path)).to eq(
|
||||
File.read("#{Rails.root}/spec/fixtures/images/resized.png")
|
||||
)
|
||||
ensure
|
||||
File.delete(tmp_path) if File.exists?(tmp_path)
|
||||
end
|
||||
expect(upload.filesize).to eq(199)
|
||||
|
||||
expect(upload.width).to eq(5)
|
||||
expect(upload.height).to eq(5)
|
||||
|
||||
upload.create_thumbnail!(10, 10)
|
||||
thumb = upload.thumbnail(10, 10)
|
||||
|
||||
expect(thumb.width).to eq(10)
|
||||
expect(thumb.height).to eq(10)
|
||||
|
||||
# very image magic specific so fudge here
|
||||
expect(thumb.filesize).to be > 200
|
||||
|
||||
# this size is based off original upload
|
||||
# it is the size we render, by default, in the post
|
||||
expect(upload.thumbnail_width).to eq(5)
|
||||
expect(upload.thumbnail_height).to eq(5)
|
||||
|
||||
# lets ensure we can rebuild the filesize
|
||||
thumb.update_columns(filesize: nil)
|
||||
thumb = OptimizedImage.find(thumb.id)
|
||||
|
||||
# attempts to auto correct
|
||||
expect(thumb.filesize).to be > 200
|
||||
end
|
||||
|
||||
describe 'when an svg with a href is masked as a png' do
|
||||
|
||||
Reference in New Issue
Block a user