Skip to content

Commit 4441cf2

Browse files
authored
Merge pull request #115 from Talkdesk/fix-faraday-encoder
Fix dropped values from queries by using FlatParamsEncoder
2 parents bfe62cd + 7cecb97 commit 4441cf2

File tree

9 files changed

+32
-2
lines changed

9 files changed

+32
-2
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Metrics/MethodLength:
2525
# Offense count: 3
2626
# Configuration parameters: CountComments.
2727
Metrics/ModuleLength:
28-
Max: 391
28+
Max: 398
2929

3030
# Offense count: 1
3131
Style/AsciiComments:

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ matrix:
1010
- rvm: 2.3.1
1111
- rvm: 2.3.0
1212
- rvm: 2.2.5
13+
- rvm: 2.4.0
1314
- rvm: rbx-2
1415
- rvm: ruby-head
1516
- rvm: jruby-head
16-
- rvm: jruby-9.1.6.0
17+
- rvm: jruby-9.1.7.0
1718
allow_failures:
1819
- rvm: ruby-head
1920
- rvm: jruby-head
2021
- rvm: rbx-2
2122

23+
before_install:
24+
- gem update --system
25+
- gem install bundler
26+
2227
bundler_args: --without development

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 0.8.3 (Next)
22

3+
* [#115](https://github.com/codegram/hyperclient/pull/115): Fix dropped values from queries by using FlatParamsEncoder - [@ivoanjo](https://github.com/ivoanjo).
34
* Your contribution here.
45

56
### 0.8.2 (December 31, 2016)

features/api_navigation.feature

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Feature: API navigation
1212
When I search for a post with a templated link
1313
Then the API should receive the request with all the params
1414

15+
Scenario: Templated links with multiple values
16+
Given I connect to the API
17+
When I search for posts by tag with a templated link
18+
Then the API should receive the request for posts by tag with all the params
19+
1520
Scenario: Attributes
1621
Given I connect to the API
1722
When I load a single post

features/steps/api_navigation.rb

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
1717
assert_requested :get, 'http://api.example.org/search?q=something'
1818
end
1919

20+
step 'I search for posts by tag with a templated link' do
21+
api._links.tagged._expand(tags: %w(foo bar))._resource
22+
end
23+
24+
step 'the API should receive the request for posts by tag with all the params' do
25+
assert_requested :get, 'http://api.example.org/search?tags=foo&tags=bar'
26+
end
27+
2028
step 'I load a single post' do
2129
@post = api._links.posts._links.last_post
2230
end

features/support/api.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module API
55
include Spinach::Fixtures
66

77
before do
8+
WebMock::Config.instance.query_values_notation = :flat_array
9+
810
stub_request(:any, %r{api.example.org*}).to_return(body: root_response, headers: { 'Content-Type' => 'application/hal+json' })
911
stub_request(:get, 'api.example.org/posts').to_return(body: posts_response, headers: { 'Content-Type' => 'application/hal+json' })
1012
stub_request(:get, 'api.example.org/posts/1').to_return(body: post_response, headers: { 'Content-Type' => 'application/hal+json' })

features/support/fixtures.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def root_response
88
"self": { "href": "/" },
99
"posts": { "href": "/posts" },
1010
"search": { "href": "/search{?q}", "templated": true },
11+
"tagged": { "href": "/search{?tags*}", "templated": true },
1112
"api:authors": { "href": "/authors" },
1213
"next": { "href": "/page2" }
1314
}

lib/hyperclient/entry_point.rb

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def initialize(url, &_block)
4040
@entry_point = self
4141
@options = { async: true }
4242
@connection = nil
43+
@resource = nil
4344
yield self if block_given?
4445
end
4546

@@ -138,6 +139,7 @@ def default_faraday_block
138139
connection.request :hal_json
139140
connection.response :hal_json, content_type: /\bjson$/
140141
connection.adapter :net_http
142+
connection.options.params_encoder = Faraday::FlatParamsEncoder
141143
end
142144
end
143145

test/hyperclient/entry_point_test.rb

+6
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ module Hyperclient
3333

3434
it 'creates a Faraday connection with the default block' do
3535
handlers = entry_point.connection.builder.handlers
36+
3637
handlers.must_include Faraday::Response::RaiseError
3738
handlers.must_include FaradayMiddleware::FollowRedirects
3839
handlers.must_include FaradayMiddleware::EncodeHalJson
3940
handlers.must_include FaradayMiddleware::ParseHalJson
4041
handlers.must_include Faraday::Adapter::NetHttp
42+
43+
entry_point.connection.options.params_encoder.must_equal Faraday::FlatParamsEncoder
4144
end
4245

4346
it 'raises a ConnectionAlreadyInitializedError if attempting to modify headers' do
@@ -172,12 +175,15 @@ module Hyperclient
172175

173176
it 'creates a Faraday connection with the default block plus any additional handlers' do
174177
handlers = entry_point.connection.builder.handlers
178+
175179
handlers.must_include Faraday::Request::OAuth
176180
handlers.must_include Faraday::Response::RaiseError
177181
handlers.must_include FaradayMiddleware::FollowRedirects
178182
handlers.must_include FaradayMiddleware::EncodeHalJson
179183
handlers.must_include FaradayMiddleware::ParseHalJson
180184
handlers.must_include Faraday::Adapter::NetHttp
185+
186+
entry_point.connection.options.params_encoder.must_equal Faraday::FlatParamsEncoder
181187
end
182188
end
183189
end

0 commit comments

Comments
 (0)