gamache / hyperresource

A self-inflating Ruby client for hypermedia APIs. Not under active development.
http://hyperresource.com/doc
MIT License
304 stars 29 forks source link

fix attribute_setter in case nil value & do not overwrite resource href with nil #41

Closed pvmeerbe closed 8 years ago

pvmeerbe commented 8 years ago

First case: attribute-setter

Imagine JSON response with an attribute set to nil --> previous code did not allow to modify this attribute in the HyperResource object due to failing method missing call

--> fixed + added test case

Second case: href already set

I encountered this while trying to build a new Hyperresource object from scratch (idea is to mimick Hyperresource::MyObject.new call, populate it with Form field data & then post it to the server)

pseudo code:

my_client = HyperResource.new(root: http://whatever/api) my_client.new_from(resource: my_client, href: 'koekoek', body: {'_data_type' => 'MyObject','koekoek' => nil, 'blabla' => nil})

This will:

  1. create a new HyperResource object HyperResource::MyObject using resource & href
  2. call adapter.apply to populate it with the body data

The current code overwrites the existing href with nil as no self ref is present in body The provided solution avoids this

gamache commented 8 years ago

Thanks Pieter! Good catch.