Merge pull request #3019 from betagouv/fix-3016
[Fix #3016] Do not crash if PJ has no extension
This commit is contained in:
commit
4c1388ef81
2 changed files with 16 additions and 2 deletions
|
@ -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
|
||||
|
|
14
spec/uploaders/piece_justificative_uploader_spec.rb
Normal file
14
spec/uploaders/piece_justificative_uploader_spec.rb
Normal 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
|
Loading…
Reference in a new issue