Skip to content
3 changes: 2 additions & 1 deletion lib/hyperclient/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ def _self_link
def method_missing(method, *args, &block)
if args.any? && args.first.is_a?(Hash)
_links.send(method, [], &block)._expand(*args)
elsif !Array.method_defined?(method)
else
[:_attributes, :_embedded, :_links].each do |target|
target = send(target)
puts target.inspect
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray puts

return target.send(method, *args, &block) if target.respond_to?(method.to_s)
end
super
Expand Down
6 changes: 6 additions & 0 deletions test/hyperclient/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module Hyperclient
end
end

describe '#to_h' do
it 'returns the wrapped collection as a hash' do
collection.to_h.must_be_kind_of Hash
end
end

describe 'include?' do
it 'returns true for keys that exist' do
collection.include?('_links').must_equal true
Expand Down
12 changes: 12 additions & 0 deletions test/hyperclient/resource_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ module Hyperclient
resource['foo'].must_equal 'bar'
end

describe '#to_h' do
it 'returns the resource attributes as a hash' do
resource.to_h.must_be_kind_of Hash
end
end

describe '#to_hash' do
it 'returns the resource attributes as a hash' do
resource.to_hash.must_be_kind_of Hash
end
end

describe '#fetch' do
it 'returns the value for keys that exist' do
resource._attributes.expects(:foo).returns('bar')
Expand Down