mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|storage] added tests for metadata class; fixed bug with method missing
This commit is contained in:
parent
abb8b8acda
commit
8adae6d036
2 changed files with 69 additions and 1 deletions
|
@ -48,7 +48,7 @@ module Fog
|
|||
end
|
||||
|
||||
def respond_to?(method_sym, include_private = false)
|
||||
super(method_sym, include_private) || data.method_missing(method_missing, include_private)
|
||||
super(method_sym, include_private) || data.respond_to?(method_sym, include_private)
|
||||
end
|
||||
|
||||
def method_missing(method, *args, &block)
|
||||
|
|
68
tests/rackspace/models/storage/metadata_tests.rb
Normal file
68
tests/rackspace/models/storage/metadata_tests.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require 'fog/rackspace/models/storage/metadata'
|
||||
|
||||
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")
|
||||
end
|
||||
tests('invalid key').returns(nil) do
|
||||
Fog::Storage::Rackspace::Metadata.send(:to_key, "bad-key")
|
||||
end
|
||||
end
|
||||
|
||||
tests('#to_header_key') do
|
||||
metadata = Fog::Storage::Rackspace::Metadata.new
|
||||
|
||||
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
|
||||
|
||||
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\""
|
||||
}
|
||||
|
||||
metadata = Fog::Storage::Rackspace::Metadata.from_headers 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)
|
||||
|
||||
metadata.to_headers
|
||||
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
|
||||
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.methods.all? {|method| metadata.respond_to?(method)}
|
||||
end
|
||||
end
|
||||
|
||||
tests("#method_missing").returns(true) do
|
||||
metadata = Fog::Storage::Rackspace::Metadata.new
|
||||
metadata[:test] = true
|
||||
metadata[:test]
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue