Skip to content
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

Hyperclient::Resource#to_h != Hyperclient::Resource#to_hash #103

Open
jufemaiz opened this issue Aug 16, 2016 · 7 comments
Open

Hyperclient::Resource#to_h != Hyperclient::Resource#to_hash #103

jufemaiz opened this issue Aug 16, 2016 · 7 comments
Labels

Comments

@jufemaiz
Copy link

Hi guys, I'm using v0.8.1 and am having a discrepancy when using #to_h in place of #to_hash on a Hyperclient::Resource.

cluster_meters = Source.clusters._get.by_id(id: id)._get.meters._embedded
meter = gateway_meters.all.first
expect(meter.to_h).to eq(meter.to_hash)

However the call to #to_h returns nil, while the call to #to_hash returns the expected hash

@dblock
Copy link
Collaborator

dblock commented Aug 16, 2016

Interesting, probably just a bug, feel free to write a spec/PR a fix.

@dblock dblock added the bug? label Aug 16, 2016
@jufemaiz
Copy link
Author

jufemaiz commented Aug 18, 2016

Ok, a bit of poking and I've discovered it.

Array#to_h exists
Array#to_hash doesn't exist

elsif !Array.method_defined?(method)

Given that Hyperclient::Resource#to_hash has no arguments passed, we don't actually get to do anything with the to_h method on the Hyperclient::Resource, and there's nothing returned, hence "nil" is the result.

Dumb question, why is the !Array.method_defined?(method) used there? If I change it to a simple "else" all tests still pass.

@dblock
Copy link
Collaborator

dblock commented Aug 18, 2016

Honestly I don't remember the reason for that Array.defined, git blame should surface it. There was definitely a test for this that was failing at some point.

@jufemaiz
Copy link
Author

03ecf0a

But before that it was an Enumerable check.

13a62b3

@dblock
Copy link
Collaborator

dblock commented Aug 19, 2016

Are you running rake with all the tests? I think you're missing the feature scenarios. That commit has a test with each that otherwise fails.

@jufemaiz
Copy link
Author

rake spinache output:

Feature: API navigation

  Scenario: Links
    !  When I connect to the API                                   # features/support/api.rb:19
    ~  Then I should be able to navigate to posts and authors

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

  Scenario: Templated links
    !  Given I connect to the API                                       # features/support/api.rb:19
    ~  When I search for a post with a templated link
    ~  Then the API should receive the request with all the params

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

  Scenario: Attributes
    !  Given I connect to the API                               # features/support/api.rb:19
    ~  When I load a single post
    ~  Then I should be able to access it's title and body

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

  Scenario: Embedded resources
    !  Given I connect to the API                                       # features/support/api.rb:19
    ~  When I load a single post
    ~  Then I should also be able to access it's embedded comments

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

  Scenario: Navigation links
    !  When I connect to the API                                         # features/support/api.rb:19
    ~  Then I should be able to navigate to next page
    ~  Then I should be able to navigate to next page without links

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

  Scenario: Counts
    !  When I connect to the API                                 # features/support/api.rb:19
    ~  Then I should be able to count embedded items
    ~  Then I should be able to iterate over embedded items

        getaddrinfo: nodename nor servname provided, or not known
        /Users/joelcourtney/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/net/http.rb:879:in `initialize'

This continues all the way through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@jufemaiz @dblock and others