On Mon, 2012-11-05 at 16:04 +0100, [email protected] wrote:
> From: Michal Fojtik <[email protected]>
> 
> * .to_hash produce Ruby Hash that can be converted to JSON
> * This patch makes 'crack' library obsolete
> * NOTE: This patch might break JSON backward compatibility.

Ronelle actually pointed this out, but:

> diff --git a/server/lib/deltacloud/collections/instances.rb 
> b/server/lib/deltacloud/collections/instances.rb
> index ce536ce..cf6504c 100644
> --- a/server/lib/deltacloud/collections/instances.rb
> +++ b/server/lib/deltacloud/collections/instances.rb
> @@ -60,7 +60,13 @@ module Deltacloud::Collections
>            status 201  # Created
>            respond_to do |format|
>              format.xml  { haml :"instances/#{action_handler}" }
> -            format.json { xml_to_json("instances/#{action_handler}") }
> +            format.json do
> +              if @elements
> +                JSON::dump(:instances => @elements.map { |i| i.to_hash })
> +              elsif @instance and @instance.id
> +                JSON::dump(:instance => @instance.to_hash)

That needs to be @instance.to_hash(self) - a quick grep through this dir
shows there are quite a few more places where to_hash is called without
an argument.

Ronelle's command to reproduce:

        curl -X POST -F "name=myname" -F "r "mockuser:mockpassword" -H 'Accept: 
application/json' http://localhost:3001/api/instances

David


Reply via email to