1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[rackspace|storage] tweaked directory implementation; added directory model tests

This commit is contained in:
Kyle Rames 2013-02-11 14:39:48 -06:00
parent bff8547e33
commit b2657de41a
3 changed files with 64 additions and 11 deletions

View file

@ -21,24 +21,26 @@ module Fog
!@rackspace_cdn_ssl.nil?
end
def purge(object)
return true if object.is_a? Fog::Storage::Rackspace::File
raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging") if object
def purge(file)
unless file.is_a? Fog::Storage::Rackspace::File
raise Fog::Errors::NotImplemented.new("#{object.class} does not support CDN purging")
end
delete_object file.directory.key, file.key
true
end
def publish_container(container, publish = true)
enabled = publish ? 'True' : 'False'
key = container.is_a?(String) ? key : container.key
response = put_container(key, 'X-CDN-Enabled' => enabled)
response = put_container(container.key, 'X-CDN-Enabled' => enabled)
url_from_headers(response.headers, container.cdn_cname)
end
def public_url(object)
key = object.is_a?(String) ? key : object.key
def public_url(container)
begin
response = head_container(key)
response = head_container(container.key)
if response.headers['X-Cdn-Enabled'] == 'True'
url_from_headers(response.headers, object.cdn_name)
url_from_headers(response.headers, container.cdn_cname)
else
nil
end

View file

@ -34,7 +34,17 @@ module Fog
end
def public?
@public ||= key && !public_url.nil?
if @public.nil?
@public ||= (key && public_url) ? true : false
end
@public
end
def reload
@public = nil
@public_url = nil
@files = nil
super
end
def public_url

View file

@ -0,0 +1,41 @@
Shindo.tests('Fog::Rackspace::Storage | directories', ['rackspace']) do
pending if Fog.mocking?
service = Fog::Storage[:rackspace]
directory_attributes = {
# Add a random suffix to prevent collision
:key => "fog-directory-tests-#{rand(65536)}"
}
model_tests(service.directories, directory_attributes, Fog.mocking?) do
tests('#public?').returns(false) do
@instance.public?
end
tests('#public_url').returns(nil) do
@instance.public_url
end
tests('cdn') do
@instance.public = true
@instance.save
tests('#public?').returns(true) do
@instance.public?
end
tests('#public_url').returns(false) do
@instance.public_url.nil?
end
end
tests("reload") do
@instance.reload
returns(nil) { @instance.instance_variable_get("@public") }
returns(nil) { @instance.instance_variable_get("@public_url") }
returns(nil) { @instance.instance_variable_get("@files") }
end
end
end