mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|storage] fixed issue in ruby 1.8.7 where metadata was not being deleted when set to nil
This commit is contained in:
parent
89c2a75e33
commit
f39ecbc35e
2 changed files with 26 additions and 15 deletions
|
@ -120,21 +120,21 @@ module Fog
|
|||
def header_to_key(opt)
|
||||
opt.gsub(metadata_prefix, '').split('-').map {|k| k[0, 1].downcase + k[1..-1]}.join('_').to_sym
|
||||
end
|
||||
|
||||
|
||||
def metadata_to_headers
|
||||
header_map = header_mapping
|
||||
Hash[metadata.map {|k, v| [header_map[k], v] }]
|
||||
end
|
||||
hash = {}
|
||||
metadata.each_pair do |k,v|
|
||||
key = metakey(k,v)
|
||||
hash[key] = v
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
def header_mapping
|
||||
header_map = metadata.dup
|
||||
header_map.each_pair {|k, v| header_map[k] = key_to_header(k)}
|
||||
def metakey(key, value)
|
||||
prefix = value.nil? ? "X-Remove-Object-Meta-" : "X-Object-Meta-"
|
||||
prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
|
||||
end
|
||||
|
||||
def key_to_header(key)
|
||||
metadata_prefix + key.to_s.split(/[-_]/).map(&:capitalize).join('-')
|
||||
end
|
||||
|
||||
|
||||
def metadata_attributes
|
||||
if last_modified
|
||||
headers = service.head_object(directory.key, self.key).headers
|
||||
|
|
|
@ -3,7 +3,7 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
pending if Fog.mocking?
|
||||
|
||||
def object_meta_attributes
|
||||
@instance.connection.head_object(@directory.key, @instance.key).headers.reject {|k, v| !(k =~ /X-Object-Meta-/)}
|
||||
@instance.service.head_object(@directory.key, @instance.key).headers.reject {|k, v| !(k =~ /X-Object-Meta-/)}
|
||||
end
|
||||
|
||||
def clear_metadata
|
||||
|
@ -64,8 +64,20 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
@instance.metadata[:foo] = nil
|
||||
@instance.save
|
||||
object_meta_attributes
|
||||
end
|
||||
end
|
||||
|
||||
tests("removes one key while leaving the other") do
|
||||
@instance.metadata[:color] = "green"
|
||||
@instance.save
|
||||
returns({"X-Object-Meta-Foo"=>"bar", "X-Object-Meta-Color"=>"green"}) { object_meta_attributes }
|
||||
|
||||
tests("set metadata[:color] = nil").returns({"X-Object-Meta-Foo"=>"bar"}) do
|
||||
@instance.metadata[:color] = nil
|
||||
@instance.save
|
||||
|
||||
object_meta_attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('#metadata keys') do
|
||||
|
@ -105,7 +117,6 @@ Shindo.tests('Fog::Rackspace::Storage | file', ['rackspace']) do
|
|||
@instance.save
|
||||
object_meta_attributes['X-Object-Meta-Foo-Bar']
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue