Fog::Storage::Local#directories#all: Don't break when :local_root folder is missing

This commit is contained in:
Sjoerd Andringa 2013-10-31 21:26:28 +01:00
parent b53068952e
commit 155c4503ed
2 changed files with 27 additions and 5 deletions

View File

@ -10,12 +10,17 @@ module Fog
model Fog::Storage::Local::Directory
def all
data = Dir.entries(service.local_root).select do |entry|
entry[0...1] != '.' && ::File.directory?(service.path_to(entry))
end.map do |entry|
{:key => entry}
if ::File.directory?(service.local_root)
data = Dir.entries(service.local_root).select do |entry|
entry[0...1] != '.' && ::File.directory?(service.path_to(entry))
end.map do |entry|
{:key => entry}
end
load(data)
else
clear
self
end
load(data)
end
def get(key, options = {})

View File

@ -0,0 +1,17 @@
Shindo.tests('Storage[:local] | directories', ["local"]) do
pending if Fog.mocking?
@options = { :local_root => "/tmp/fogtests" }
@collection = Fog::Storage::Local.new(@options).directories
collection_tests(@collection, {:key => "fogdirtests"}, true)
tests("#all") do
tests("succeeds when :local_root does not exist").succeeds do
FileUtils.rm_rf(@options[:local_root])
@collection.all
end
end
end