fix: Correctly handle absolute paths for simple commands (#895)
This commit is contained in:
		
							parent
							
								
									72edce10c1
								
							
						
					
					
						commit
						d717b3b534
					
				|  | @ -334,7 +334,13 @@ module Google | |||
|         #  Request-specific options | ||||
|         # @return [Google::Apis::Core::DownloadCommand] | ||||
|         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.options = request_options.merge(options) | ||||
|           apply_command_defaults(command) | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ RSpec.describe Google::Apis::Core::BaseService do | |||
|   include TestHelpers | ||||
| 
 | ||||
|   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}" } | ||||
| 
 | ||||
|   before do | ||||
|  | @ -133,6 +134,20 @@ RSpec.describe Google::Apis::Core::BaseService do | |||
|     include_examples 'with options' | ||||
|   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 | ||||
|     let(:command) { service.send(:make_download_command, :get, 'zoo/animals', authorization: 'foo') } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue