Skip to content

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

Closed

Description

@jufemaiz

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

Activity

  1. dblock commented on Aug 16, 2016

    @dblock
    Collaborator

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

  2. jufemaiz commented on Aug 18, 2016

    @jufemaiz
    Author

    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.

  3. dblock commented on Aug 18, 2016

    @dblock
    Collaborator

    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.

  4. jufemaiz commented on Aug 18, 2016

    @jufemaiz
    Author

    03ecf0a

    But before that it was an Enumerable check.

    13a62b3

  5. dblock commented on Aug 19, 2016

    @dblock
    Collaborator

    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.

  6. jufemaiz commented on Aug 19, 2016

    @jufemaiz
    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.

  7. jufemaiz commented on Aug 26, 2026

    @jufemaiz
    Author

    @dblock 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions