Maintain backwards compatibility before `Jobs::MigrateUploadExtensions` runs.

This commit is contained in:
Guo Xiang Tan 2017-08-03 11:56:55 +09:00
parent a47e297508
commit 8cc8010564
2 changed files with 31 additions and 1 deletions

View File

@ -95,7 +95,16 @@ module FileStore
end
def get_path_for_upload(upload)
get_path_for("original".freeze, upload.id, upload.sha1, "." + upload.extension)
extension =
if upload.extension
".#{upload.extension}"
else
# Maintain backward compatibility before Jobs::MigrateUploadExtensions
# runs
File.extname(upload.original_filename)
end
get_path_for("original".freeze, upload.id, upload.sha1, extension)
end
def get_path_for_optimized_image(optimized_image)

View File

@ -0,0 +1,21 @@
require 'rails_helper'
RSpec.describe FileStore::BaseStore do
let(:upload) { Fabricate(:upload, id: 9999, sha1: Digest::SHA1.hexdigest('9999')) }
describe '#get_path_for_upload' do
it 'should return the right path' do
expect(FileStore::BaseStore.new.get_path_for_upload(upload))
.to eq('original/2X/4/4170ac2a2782a1516fe9e13d7322ae482c1bd594.png')
end
describe 'when Upload#extension has not been set' do
it 'should return the right path' do
upload.update!(extension: nil)
expect(FileStore::BaseStore.new.get_path_for_upload(upload))
.to eq('original/2X/4/4170ac2a2782a1516fe9e13d7322ae482c1bd594.png')
end
end
end
end