Skip to content

Commit

Permalink
Fix: re-add eager delegation for resource.x._embeddded.x.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Aug 23, 2015
1 parent d494d60 commit 13a62b3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
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 2015-08-15 17:01:12 -0400 using RuboCop version 0.33.0.
# on 2015-08-23 09:45:44 -0400 using RuboCop version 0.33.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 @@ -16,10 +16,10 @@ Metrics/ClassLength:
Metrics/LineLength:
Max: 142

# Offense count: 3
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 14
Max: 25

# Offense count: 3
# Configuration parameters: CountComments.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.7.2 (Next)

* [#95](https://github.com/codegram/hyperclient/issues/95): Fix: re-add eager delegation for `resource.x._embeddded.x` - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.7.1 (August 15, 2015)
Expand Down
4 changes: 4 additions & 0 deletions features/api_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ Feature: API navigation
When I connect to the API
Then I should be able to navigate to next page
Then I should be able to navigate to next page without links

Scenario: Counts
When I connect to the API
Then I should be able to count embedded items
6 changes: 6 additions & 0 deletions features/steps/api_navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ class Spinach::Features::ApiNavigation < Spinach::FeatureSteps
step 'I should be able to navigate to next page without links' do
assert_equal '/posts_of_page2', api.next.posts._url
end

step 'I should be able to count embedded items' do
assert_equal 2, api._links.posts._resource._embedded.posts.count
assert_equal 2, api.posts._embedded.posts.count
assert_equal 2, api.posts.count
end
end
4 changes: 2 additions & 2 deletions features/steps/default_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Spinach::Features::DefaultConfig < Spinach::FeatureSteps
end

step 'it should have been parsed as JSON' do
@posts._attributes.total_posts.to_i.must_equal 9
@posts._attributes['total_posts'].to_i.must_equal 9
@posts._attributes.total_posts.to_i.must_equal 2
@posts._attributes['total_posts'].to_i.must_equal 2
end
end
20 changes: 19 additions & 1 deletion features/support/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,25 @@ def posts_response
"self": { "href": "/posts" },
"last_post": {"href": "/posts/1"}
},
"total_posts": "9"
"total_posts": "2",
"_embedded": {
"posts": [
{
"title": "My first blog post",
"body": "Lorem ipsum dolor sit amet",
"_links": {
"self": { "href": "/posts/1" }
}
},
{
"title": "My second blog post",
"body": "Lorem ipsum dolor sit amet",
"_links": {
"self": { "href": "/posts/2" }
}
}
]
}
}'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hyperclient/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _self_link
def method_missing(method, *args, &block)
if args.any? && args.first.is_a?(Hash)
_links.send(method, [], &block)._expand(*args)
else
elsif !Enumerable.method_defined?(method)
[:_attributes, :_embedded, :_links].each do |target|
target = send(target)
return target.send(method, *args, &block) if target.respond_to?(method.to_s)
Expand Down

0 comments on commit 13a62b3

Please sign in to comment.