diff --git a/lib/fog/local/models/storage/directories.rb b/lib/fog/local/models/storage/directories.rb index db4c33cda..3ed4316c8 100644 --- a/lib/fog/local/models/storage/directories.rb +++ b/lib/fog/local/models/storage/directories.rb @@ -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 = {}) diff --git a/tests/local/models/directories_tests.rb b/tests/local/models/directories_tests.rb new file mode 100644 index 000000000..a9ab6ec5d --- /dev/null +++ b/tests/local/models/directories_tests.rb @@ -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