Skip to content

Fix link delegation returning nil for field with value false #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2016-12-21 20:00:37 +0000 using RuboCop version 0.42.0.
# on 2017-08-26 18:01:43 +0100 using RuboCop version 0.42.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -9,9 +9,9 @@
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 109
Max: 110

# Offense count: 89
# Offense count: 97
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [#122](https://github.com/codegram/hyperclient/pull/122): Improve error message when server returns invalid data - [@ivoanjo](https://github.com/ivoanjo).
* [#125](https://github.com/codegram/hyperclient/pull/125): Add table of contents to readme and add note asking users to add their projects to the wiki - [@ivoanjo](https://github.com/ivoanjo).
* [#127](https://github.com/codegram/hyperclient/pull/127): Minor fixes: Fix warnings, and pry-byebug to dev Gemfile and tweak rubocop execution - [@ivoanjo](https://github.com/ivoanjo).
* [#128](https://github.com/codegram/hyperclient/pull/128): Fix link delegation returning nil for field with value false - [@ivoanjo](https://github.com/ivoanjo).
* Your contribution here.

### 0.8.5 (July 5, 2017)
Expand Down
3 changes: 2 additions & 1 deletion lib/hyperclient/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def to_s
# Internal: Delegate the method further down the API if the resource cannot serve it.
def method_missing(method, *args, &block)
if _resource.respond_to?(method.to_s)
_resource.send(method, *args, &block) || delegate_method(method, *args, &block)
result = _resource.send(method, *args, &block)
result.nil? ? delegate_method(method, *args, &block) : result
else
super
end
Expand Down
10 changes: 10 additions & 0 deletions test/hyperclient/link_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,16 @@ module Hyperclient
resource.orders.first.id.must_equal 1
end

it 'can handle false values in the response' do
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders' } } }, entry_point)

stub_request(entry_point.connection) do |stub|
stub.get('http://api.example.org/orders') { [200, {}, { 'any' => false }] }
end

resource.orders.any.must_equal false
end

it "doesn't delegate when link key doesn't match" do
resource = Resource.new({ '_links' => { 'foos' => { 'href' => '/orders' } } }, entry_point)

Expand Down