mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2165 from dgutov/open_stack_put_object_with_block
Fog::Storage::OpenStack::Real#put_object: Don't use data when block is provided
This commit is contained in:
commit
8747cbb166
3 changed files with 23 additions and 5 deletions
|
@ -5,17 +5,26 @@ module Fog
|
|||
|
||||
# Create a new object
|
||||
#
|
||||
# When passed a block, it will make a chunked request, calling
|
||||
# the block for chunks until it returns an empty string.
|
||||
# In this case the data parameter is ignored.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
|
||||
# * object<~String> - Name for object
|
||||
# * data<~String|File> - data to upload
|
||||
# * options<~Hash> - config headers for object. Defaults to {}.
|
||||
# * block<~Proc> - chunker
|
||||
#
|
||||
def put_object(container, object, data, options = {}, &block)
|
||||
data = Fog::Storage.parse_data(data)
|
||||
headers = data[:headers].merge!(options)
|
||||
|
||||
params = block_given? ? { :request_block => block } : { :body => data[:body] }
|
||||
if block_given?
|
||||
params = { :request_block => block }
|
||||
headers = options
|
||||
else
|
||||
data = Fog::Storage.parse_data(data)
|
||||
headers = data[:headers].merge!(options)
|
||||
params = { :body => data[:body] }
|
||||
end
|
||||
|
||||
params.merge!(
|
||||
:expects => 201,
|
||||
|
|
|
@ -5,11 +5,16 @@ module Fog
|
|||
|
||||
# Create a new object
|
||||
#
|
||||
# When passed a block, it will make a chunked request, calling
|
||||
# the block for chunks until it returns an empty string.
|
||||
# In this case the data parameter is ignored.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * container<~String> - Name for container, should be < 256 bytes and must not contain '/'
|
||||
# * object<~String> - Name for object
|
||||
# * data<~String|File> - data to upload
|
||||
# * options<~Hash> - config headers for object. Defaults to {}.
|
||||
# * options<~Hash> - config headers for object. Defaults to #{}.
|
||||
# * block<~Proc> - chunker
|
||||
# @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404
|
||||
# @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400
|
||||
# @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500
|
||||
|
|
|
@ -44,6 +44,8 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
|
|||
tests("put_object with block") do
|
||||
pending if Fog.mocking?
|
||||
|
||||
WebMock.disable! # https://github.com/bblimke/webmock/issues/307
|
||||
|
||||
tests("#put_object('fogobjecttests', 'fog_object', &block)").succeeds do
|
||||
begin
|
||||
file = lorem_file
|
||||
|
@ -56,6 +58,8 @@ Shindo.tests('Fog::Storage[:openstack] | object requests', ["openstack"]) do
|
|||
end
|
||||
end
|
||||
|
||||
WebMock.enable!
|
||||
|
||||
tests('#get_object').succeeds do
|
||||
Fog::Storage[:openstack].get_object('fogobjecttests', 'fog_block_object').body == lorem_file.read
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue