2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-02 22:56:55 -04:00
|
|
|
require 'rails_helper'
|
2018-06-05 03:29:17 -04:00
|
|
|
require_dependency 'file_store/base_store'
|
2017-08-02 22:56:55 -04:00
|
|
|
|
|
|
|
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
|
2019-01-02 02:29:17 -05:00
|
|
|
|
|
|
|
describe 'when id is negative' do
|
|
|
|
it 'should return the right depth' do
|
|
|
|
upload.update!(id: -999)
|
|
|
|
|
|
|
|
expect(FileStore::BaseStore.new.get_path_for_upload(upload))
|
|
|
|
.to eq('original/1X/4170ac2a2782a1516fe9e13d7322ae482c1bd594.png')
|
|
|
|
end
|
|
|
|
end
|
2017-08-02 22:56:55 -04:00
|
|
|
end
|
2019-01-11 08:05:38 -05:00
|
|
|
|
|
|
|
describe '#get_path_for_optimized_image' do
|
2019-01-16 15:01:50 -05:00
|
|
|
let(:upload) { Fabricate.build(:upload, id: 100) }
|
2019-01-11 08:05:38 -05:00
|
|
|
let(:optimized_path) { "optimized/1X/#{upload.sha1}_1_100x200.png" }
|
|
|
|
|
|
|
|
it 'should return the right path' do
|
2019-01-16 15:01:50 -05:00
|
|
|
optimized = Fabricate.build(:optimized_image, upload: upload, version: 1)
|
2019-01-11 08:05:38 -05:00
|
|
|
expect(FileStore::BaseStore.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return the right path for `nil` version' do
|
2019-01-16 15:01:50 -05:00
|
|
|
optimized = Fabricate.build(:optimized_image, upload: upload, version: nil)
|
2019-01-11 08:05:38 -05:00
|
|
|
expect(FileStore::BaseStore.new.get_path_for_optimized_image(optimized)).to eq(optimized_path)
|
|
|
|
end
|
|
|
|
end
|
2017-08-02 22:56:55 -04:00
|
|
|
end
|