Merge pull request #1401 from xhh/ruby-base-url-slashes

Ruby client: remove trailing slashes from base_url
This commit is contained in:
wing328 2015-10-16 19:32:13 +08:00
commit 90eab19305
3 changed files with 27 additions and 2 deletions

View File

@ -138,7 +138,7 @@ module {{moduleName}}
end
def base_url
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}"
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
URI.encode(url)
end

View File

@ -138,7 +138,7 @@ module Petstore
end
def base_url
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}"
url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
URI.encode(url)
end

View File

@ -0,0 +1,25 @@
require 'spec_helper'
describe Petstore::Configuration do
let(:config) { Petstore::Configuration.instance }
before(:each) do
Petstore.configure do |c|
c.host = 'petstore.swagger.io'
c.base_path = 'v2'
end
end
describe '#base_url' do
it 'should have the default value' do
config.base_url.should == 'http://petstore.swagger.io/v2'
end
it 'should remove trailing slashes' do
[nil, '', '/', '//'].each do |base_path|
config.base_path = base_path
config.base_url.should == 'http://petstore.swagger.io'
end
end
end
end