diff --git a/.gitignore b/.gitignore index 09fd1db..77a7e23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.byebug_history /.bundle/ /.yardoc /coverage/ diff --git a/lib/hawk/http.rb b/lib/hawk/http.rb index ad6dc50..2143a67 100644 --- a/lib/hawk/http.rb +++ b/lib/hawk/http.rb @@ -116,7 +116,7 @@ def request(method, path, options) private def build_url(path) - base.merge(path.sub(%r{^/}, '')).to_s + base.merge(path.delete_prefix('/').squeeze('/')).to_s end def response_handler(response) diff --git a/lib/hawk/version.rb b/lib/hawk/version.rb index af6773d..930be6b 100644 --- a/lib/hawk/version.rb +++ b/lib/hawk/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Hawk - VERSION = '2.0.0' + VERSION = '3.0.0' end diff --git a/spec/basic_operations_spec.rb b/spec/basic_operations_spec.rb index f2bad1a..bf88011 100644 --- a/spec/basic_operations_spec.rb +++ b/spec/basic_operations_spec.rb @@ -22,6 +22,16 @@ class Person < Hawk::Model::Base } end + describe '.get' do + it 'squeezes multiple slashes' do + stub_request(:GET, 'https://example.org/people/batch/id') + .with(headers: { 'User-Agent' => 'Foobar' }) + .to_return(status: 200, body: [2].to_json, headers: {}) + + expect(Person.get('/batch///id')).to contain_exactly(2) + end + end + describe '.find(id)' do specify do stub_request(:GET, 'https://example.org/people/2')