uploaders: remove PieceJustificativeUploader

This commit is contained in:
Pierre de La Morinerie 2019-07-29 10:13:15 +00:00
parent 95e24392f9
commit 65e7489b4f
3 changed files with 0 additions and 66 deletions

View file

@ -1,51 +0,0 @@
class PieceJustificativeUploader < BaseUploader
before :cache, :set_original_filename
# Choose what kind of storage to use for this uploader:
if Flipflop.remote_storage?
storage :fog
else
storage :file
end
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
if !Flipflop.remote_storage?
"./uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_whitelist
['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'ods', 'odp', 'jpg', 'jpeg', 'png']
end
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}"
else
filename = "#{model.class.to_s.underscore}.#{file.extension&.downcase}"
end
end
filename
end
private
def secure_token
model.content_secure_token ||= generate_secure_token
end
def generate_secure_token
SecureRandom.uuid
end
def set_original_filename(file)
if file.respond_to?(:original_filename)
model.original_filename ||= file.original_filename
end
end
end

View file

@ -134,7 +134,6 @@ RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
config.before(:each) do
allow_any_instance_of(PieceJustificativeUploader).to receive(:generate_secure_token).and_return("3dbb3535-5388-4a37-bc2d-778327b9f997")
allow_any_instance_of(ProcedureLogoUploader).to receive(:generate_secure_token).and_return("3dbb3535-5388-4a37-bc2d-778327b9f998")
Flipflop::FeatureSet.current.test!.reset!

View file

@ -1,14 +0,0 @@
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