Skip to content

Commit 096ba89

Browse files
committed
Use Addressable::URI's normalize_component to ensure special characters are encoded, improve stubbing for new webmock test, remove .editorconfig in this PR for now
1 parent b38b49f commit 096ba89

File tree

4 files changed

+6
-19
lines changed

4 files changed

+6
-19
lines changed

.editorconfig

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/cortex/connection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'hashie/mash'
44

55
require 'cortex/faraday_middleware/response_failures'
6-
require 'cortex/faraday_middleware/encode_uri_path'
6+
require 'cortex/faraday_middleware/normalize_uri_path'
77

88
module Cortex
99
module Connection
@@ -22,7 +22,7 @@ def connection
2222
Faraday::Utils.default_uri_parser = Addressable::URI
2323
Faraday.new options do |conn|
2424
## Request middleware first:
25-
conn.use Cortex::FaradayMiddleware::EncodeURIPath
25+
conn.use Cortex::FaradayMiddleware::NormalizeURIPath
2626
conn.request :oauth2, access_token.is_a?(OAuth2::AccessToken) ? access_token.token : access_token
2727
conn.request :json
2828

lib/cortex/faraday_middleware/encode_uri_path.rb renamed to lib/cortex/faraday_middleware/normalize_uri_path.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
module Cortex
55
module FaradayMiddleware
6-
class EncodeURIPath < Faraday::Middleware
6+
class NormalizeURIPath < Faraday::Middleware
77
def call(env)
8-
env[:url].path = Addressable::URI.encode(env[:url].path)
8+
env[:url].path = Addressable::URI.normalize_component(env[:url].path)
99

1010
@app.call env
1111
end

spec/posts_spec.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@
1717
end
1818

1919
context 'with special characters' do
20-
before(:all) do
21-
stub_request(:get, 'http://cortex.dev/api/v1/posts/feed/1%20post?access_token=123')
22-
end
20+
let!(:stubbed_request) { stub_request(:get, 'http://cortex.dev/api/v1/posts/feed/1%20post?access_token=123') }
2321

2422
it 'should correctly make the request' do
2523
client.posts.get_published('1 post')
26-
27-
expect(a_request(:get, 'http://cortex.dev/api/v1/posts/feed/1%20post?access_token=123')).
28-
to have_been_made.once
24+
expect(stubbed_request).to have_been_made.once
2925
end
3026

3127
it 'should not be considered an invalid URI' do

0 commit comments

Comments
 (0)