FIX: fallback to local store when uploads are not on S3

This commit is contained in:
Sam 2015-05-26 13:08:31 +10:00
parent eeda367e70
commit e17f614771
2 changed files with 28 additions and 0 deletions

View File

@ -1,6 +1,7 @@
require "file_store/base_store"
require_dependency "s3_helper"
require_dependency "file_helper"
require_dependency "file_store/local_store"
module FileStore
@ -67,6 +68,13 @@ module FileStore
@s3_helper.update_tombstone_lifecycle(grace_period)
end
def path_for(upload)
url = upload.url
if url && url[0] == "/" && url[1] != "/"
FileStore::LocalStore.new.path_for(upload)
end
end
private
def get_path_for_upload(file, upload)

View File

@ -1,5 +1,6 @@
require 'spec_helper'
require 'file_store/s3_store'
require 'file_store/local_store'
describe FileStore::S3Store do
@ -105,4 +106,23 @@ describe FileStore::S3Store do
end
describe ".path_for" do
def assert_path(path, expected)
upload = Upload.new(url: path)
path = store.path_for(upload)
expected = FileStore::LocalStore.new.path_for(upload) if expected
expect(path).to eq(expected)
end
it "correctly falls back to local" do
assert_path("/hello", "/hello")
assert_path("//hello", nil)
assert_path("http://hello", nil)
assert_path("https://hello", nil)
end
end
end