fix: Correctly handle absolute paths for simple commands (#895)

This commit is contained in:
Daniel Azuma 2020-07-31 14:07:23 -07:00 committed by GitHub
parent 72edce10c1
commit d717b3b534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -334,7 +334,13 @@ module Google
# Request-specific options # Request-specific options
# @return [Google::Apis::Core::DownloadCommand] # @return [Google::Apis::Core::DownloadCommand]
def make_simple_command(method, path, options) def make_simple_command(method, path, options)
template = Addressable::Template.new(root_url + base_path + path) full_path =
if path.start_with? "/"
path[1..-1]
else
base_path + path
end
template = Addressable::Template.new(root_url + full_path)
command = ApiCommand.new(method, template) command = ApiCommand.new(method, template)
command.options = request_options.merge(options) command.options = request_options.merge(options)
apply_command_defaults(command) apply_command_defaults(command)

View File

@ -21,6 +21,7 @@ RSpec.describe Google::Apis::Core::BaseService do
include TestHelpers include TestHelpers
let(:service) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', '') } let(:service) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', '') }
let(:service_with_base_path) { Google::Apis::Core::BaseService.new('https://www.googleapis.com/', 'my_service/v1/') }
let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}" } let(:x_goog_api_client_value) { "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}" }
before do before do
@ -133,6 +134,20 @@ RSpec.describe Google::Apis::Core::BaseService do
include_examples 'with options' include_examples 'with options'
end end
context 'when making simple commands with a base path' do
it 'should return the correct URL for a relative path' do
command = service_with_base_path.send(:make_simple_command, :get, 'zoo/animals', authorization: 'foo')
url = command.url.expand({}).to_s
expect(url).to eql 'https://www.googleapis.com/my_service/v1/zoo/animals'
end
it 'should return the correct URL for an absolute path' do
command = service_with_base_path.send(:make_simple_command, :get, '/zoo/animals', authorization: 'foo')
url = command.url.expand({}).to_s
expect(url).to eql 'https://www.googleapis.com/zoo/animals'
end
end
context 'when making download commands' do context 'when making download commands' do
let(:command) { service.send(:make_download_command, :get, 'zoo/animals', authorization: 'foo') } let(:command) { service.send(:make_download_command, :get, 'zoo/animals', authorization: 'foo') }