Skip to content

Commit

Permalink
Avoid errors due to mutations to options argument in the upload_file …
Browse files Browse the repository at this point in the history
…method (#1416)
  • Loading branch information
markmercedes authored and cjyclaire committed Feb 10, 2017
1 parent edbbb5d commit 4bb69d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions aws-sdk-resources/lib/aws-sdk-resources/services/s3/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ def public_url(options = {})
# without any errors.
#
def upload_file(source, options = {})
uploading_options = options.dup
uploader = FileUploader.new(
multipart_threshold: options.delete(:multipart_threshold),
multipart_threshold: uploading_options.delete(:multipart_threshold),
client: client)
uploader.upload(source, options.merge(bucket: bucket_name, key: key))
uploader.upload(source, uploading_options.merge(bucket: bucket_name, key: key))
true
end

Expand Down
13 changes: 13 additions & 0 deletions aws-sdk-resources/spec/services/s3/object/upload_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ module S3
end
}

describe 'accepts options without mutating them' do

it 'uploads objects with custom options' do
options = {}.freeze
expect(client).to receive(:put_object).with(
bucket: 'bucket',
key: 'key',
body: one_meg_file)
object.upload_file(one_meg_file, options)
end

end

describe 'small objects' do

it 'uploads small objects using Client#put_object' do
Expand Down

0 comments on commit 4bb69d4

Please sign in to comment.