Skip to content
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This version is no longer tested with Ruby < 2.2.

* [#105](https://github.com/codegram/hyperclient/pull/105): Added Danger, PR linter - [@dblock](https://github.com/dblock).
* Your contribution here.
* [#104](https://github.com/codegram/hyperclient/pull/104): fix #to_h and #to_hash on Hyperclient::Resource - [@jufemaiz](https://github.com/jufemaiz)

### 0.8.1 (March 15, 2016)

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)
elsif !Array.method_defined?(method)
else
[:_attributes, :_embedded, :_links].each do |target|
target = send(target)
return target.send(method, *args, &block) if target.respond_to?(method.to_s)
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