FIX: refactor ImageSizer.resize

reverts 140d9c2
This commit is contained in:
Penar Musaraj 2018-11-29 15:28:45 -05:00
parent 140d9c2910
commit 0eacd45ab1
3 changed files with 6 additions and 4 deletions

View File

@ -128,9 +128,7 @@ class Upload < ActiveRecord::Base
end
self.width, self.height = size = FastImage.new(path).size
if !size.blank?
self.thumbnail_width, self.thumbnail_height = ImageSizer.resize(*size)
end
self.thumbnail_width, self.thumbnail_height = ImageSizer.resize(*size)
nil
end

View File

@ -1,7 +1,7 @@
module ImageSizer
# Resize an image to the aspect ratio we want
def self.resize(width, height, opts = {})
def self.resize(width = nil, height = nil, opts = {})
return if width.blank? || height.blank?
max_width = (opts[:max_width] || SiteSetting.max_image_width).to_f

View File

@ -24,6 +24,10 @@ describe ImageSizer do
expect(ImageSizer.resize('100', '101')).to eq([100, 101])
end
it 'returns nil if no width or height are provided' do
expect(ImageSizer.resize).to eq(nil)
end
describe 'when larger than the maximum width' do
before do