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

[rackspace|storage] rebased with dir_metadata branch - https://github.com/fog/fog/pull/1563

This commit is contained in:
Kyle Rames 2013-02-14 10:59:25 -06:00
parent db5039d51a
commit d7468d8747
2 changed files with 101 additions and 42 deletions

View file

@ -76,7 +76,7 @@ module Fog
def save
requires :key
headers = @metadata.nil? ? {} : metadata.to_headers
headers = attributes[:metadata].nil? ? {} : metadata.to_headers
service.put_container(key, headers)
if service.cdn && public?

View file

@ -1,67 +1,126 @@
require 'fog/rackspace/models/storage/metadata'
require 'fog/rackspace/models/storage/directory'
require 'fog/rackspace/models/storage/file'
Shindo.tests('Fog::Rackspace::Storage | metadata', ['rackspace']) do
tests('#to_key') do
tests('valid key').returns(:image_size) do
Fog::Storage::Rackspace::Metadata.send(:to_key, "X-Container-Meta-Image-Size")
tests('Directory') do
@directory = Fog::Storage::Rackspace::Directory.new
tests('#to_key') do
tests('valid key').returns(:image_size) do
metadata = Fog::Storage::Rackspace::Metadata.new @directory
metadata.send(:to_key, "X-Container-Meta-Image-Size")
end
tests('invalid key').returns(nil) do
metadata = Fog::Storage::Rackspace::Metadata.new @directory
metadata.send(:to_key, "bad-key")
end
end
tests('invalid key').returns(nil) do
Fog::Storage::Rackspace::Metadata.send(:to_key, "bad-key")
tests('#to_header_key') do
metadata = Fog::Storage::Rackspace::Metadata.new @directory
tests('key to add').returns("X-Container-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, true)
end
tests('key to remove').returns("X-Remove-Container-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, nil)
end
end
end
tests('#to_header_key') do
metadata = Fog::Storage::Rackspace::Metadata.new
tests('#to_headers').returns({"X-Container-Meta-Preview"=>true, "X-Remove-Container-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new @directory
metadata[:preview] = true
metadata[:delete_me] = nil
tests('key to add').returns("X-Container-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, true)
metadata.to_headers
end
tests('key to remove').returns("X-Remove-Container-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, nil)
end
end
tests('#to_headers').returns({"X-Container-Meta-Preview"=>true, "X-Remove-Container-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new
metadata[:preview] = true
metadata[:delete_me] = nil
metadata.to_headers
end
tests("#from_headers").returns({:my_boolean=>true, :my_integer=>42, :my_string=>"I am a string"}) do
headers = {
"X-Container-Meta-My-Integer"=> "42",
"X-Container-Meta-My-Boolean"=> "true",
"X-Container-Meta-My-String"=> "\"I am a string\""
}
tests("#from_headers").returns({:my_boolean=>true, :my_integer=>42, :my_string=>"I am a string"}) do
headers = {
"X-Container-Meta-My-Integer"=> "42",
"X-Container-Meta-My-Boolean"=> "true",
"X-Container-Meta-My-String"=> "\"I am a string\""
}
metadata = Fog::Storage::Rackspace::Metadata.from_headers headers
metadata.data
end
metadata = Fog::Storage::Rackspace::Metadata.from_headers @directory, headers
metadata.data
end
tests("#delete").returns({"X-Remove-Container-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new
metadata.delete(:delete_me)
tests("#delete").returns({"X-Remove-Container-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new @directory
metadata.delete(:delete_me)
metadata.to_headers
metadata.to_headers
end
end
tests('File') do
@file = Fog::Storage::Rackspace::File.new
tests('#to_key') do
tests('valid key').returns(:image_size) do
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata.send(:to_key, "X-Object-Meta-Image-Size")
end
tests('invalid key').returns(nil) do
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata.send(:to_key, "bad-key")
end
end
tests('#to_header_key') do
metadata = Fog::Storage::Rackspace::Metadata.new @file
tests('key to add').returns("X-Object-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, true)
end
tests('key to remove').returns("X-Remove-Object-Meta-Thumbnail-Image") do
metadata.send(:to_header_key, :thumbnail_image, nil)
end
end
tests('#to_headers').returns({"X-Object-Meta-Preview"=>true, "X-Remove-Object-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata[:preview] = true
metadata[:delete_me] = nil
metadata.to_headers
end
tests("#from_headers").returns({:my_boolean=>true, :my_integer=>42, :my_string=>"I am a string"}) do
headers = {
"X-Object-Meta-My-Integer"=> "42",
"X-Object-Meta-My-Boolean"=> "true",
"X-Object-Meta-My-String"=> "\"I am a string\""
}
metadata = Fog::Storage::Rackspace::Metadata.from_headers @file, headers
metadata.data
end
tests("#delete").returns({"X-Remove-Object-Meta-Delete-Me"=>1}) do
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata.delete(:delete_me)
metadata.to_headers
end
end
tests("#respond_to?") do
tests('Should respond to all of the methods in Hash class').returns(true) do
metadata = Fog::Storage::Rackspace::Metadata.new
metadata = Fog::Storage::Rackspace::Metadata.new @file
Hash.instance_methods.all? {|method| metadata.respond_to?(method)}
end
tests('Should respond to all of the methods in the Metadata class').returns(true) do
metadata = Fog::Storage::Rackspace::Metadata.new
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata.methods.all? {|method| metadata.respond_to?(method)}
end
end
tests("#method_missing").returns(true) do
metadata = Fog::Storage::Rackspace::Metadata.new
metadata = Fog::Storage::Rackspace::Metadata.new @file
metadata[:test] = true
metadata[:test]
end