Merge pull request #3019 from betagouv/fix-3016

[Fix #3016] Do not crash if PJ has no extension
This commit is contained in:
gregoirenovel 2018-11-21 14:23:34 +01:00 committed by GitHub
commit 4c1388ef81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -25,9 +25,9 @@ class PieceJustificativeUploader < BaseUploader
def filename
if original_filename.present? || model.content_secure_token
if Flipflop.remote_storage?
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}"
filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension&.downcase}"
else
filename = "#{model.class.to_s.underscore}.#{file.extension.downcase}"
filename = "#{model.class.to_s.underscore}.#{file.extension&.downcase}"
end
end
filename

View file

@ -0,0 +1,14 @@
require 'spec_helper'
describe PieceJustificativeUploader do
let(:pj) { create(:piece_justificative, :rib) }
it { expect(pj.content.filename).to eq 'piece_justificative.pdf' }
context 'when extension is nil' do
it do
expect(pj.content.file).to receive(:extension).and_return(nil)
expect(pj.content.filename).to eq 'piece_justificative.'
end
end
end