fix RequestOptions#merge + test for default options

This commit is contained in:
Ruslan Korolev 2015-08-18 14:13:21 +03:00
parent 8daeb2cc1e
commit f4f8b41017
2 changed files with 10 additions and 2 deletions

View File

@ -44,7 +44,7 @@ module Google
# Request options # Request options
class RequestOptions class RequestOptions
# @!attribute [rw] credentials # @!attribute [rw] authorization
# @return [Signet::OAuth2::Client, #apply(Hash)] OAuth2 credentials # @return [Signet::OAuth2::Client, #apply(Hash)] OAuth2 credentials
# @!attribute [rw] retries # @!attribute [rw] retries
# @return [Fixnum] Number of times to retry requests on server error # @return [Fixnum] Number of times to retry requests on server error
@ -63,7 +63,7 @@ module Google
return self if options.nil? return self if options.nil?
new_options = dup new_options = dup
%w(authorization retries timeout_sec).each do |opt| members.each do |opt|
opt = opt.to_sym opt = opt.to_sym
new_options[opt] = options[opt] unless options[opt].nil? new_options[opt] = options[opt] unless options[opt].nil?
end end

View File

@ -37,4 +37,12 @@ RSpec.describe Google::Apis::RequestOptions do
it 'should allow nil in merge' do it 'should allow nil in merge' do
expect(options.merge(nil)).to be_an_instance_of(Google::Apis::RequestOptions) expect(options.merge(nil)).to be_an_instance_of(Google::Apis::RequestOptions)
end end
it 'should override default options' do
Google::Apis::RequestOptions.default.header = 'Content-Length: 50'
opts = Google::Apis::RequestOptions.new
opts.header = 'Content-Length: 70'
expect(options.merge(opts).header).to eq 'Content-Length: 70'
end
end end