FIX: `FileHelper#download` should return nil if max size is exceeded.
This commit is contained in:
parent
be89f593f9
commit
a26ef7738f
|
@ -67,7 +67,11 @@ class FileHelper
|
|||
|
||||
tmp.write(chunk)
|
||||
|
||||
throw :done if tmp.size > max_file_size
|
||||
if tmp.size > max_file_size
|
||||
tmp.close
|
||||
tmp = nil
|
||||
throw :done
|
||||
end
|
||||
end
|
||||
|
||||
tmp&.rewind
|
||||
|
|
|
@ -71,6 +71,18 @@ describe FileHelper do
|
|||
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
||||
end
|
||||
|
||||
describe 'when max_file_size is exceeded' do
|
||||
it 'should return nil' do
|
||||
tmpfile = FileHelper.download(
|
||||
"//eviltrout.com/trout.png",
|
||||
max_file_size: 1,
|
||||
tmp_file_name: 'trouttmp'
|
||||
)
|
||||
|
||||
expect(tmpfile).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when url is a jpeg' do
|
||||
let(:url) { "https://eviltrout.com/trout.jpg" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue